print 'Loading mod: quiet_clan_channel v2016-05-25'

import BigWorld
from PlayerEvents import g_playerEvents
from gui.shared.ClanCache import g_clanCache
from messenger.gui.Scaleform.data.ChannelsCarouselHandler import ChannelsCarouselHandler

clanName = ''
retries = 30

def MyNotifyChannel(self, channel, isNotified = True):
    global retries
    global clanName
    if not (channel.isBattle() == False and
            (hasattr(channel, '_nameToInvalidate') and (channel._nameToInvalidate == clanName or retries > 0) or
            channel.__class__.__name__ == "BWClubChannelEntity")):
        clientID = channel.getClientID()
        self._ChannelsCarouselHandler__setItemField(clientID, 'isNotified', isNotified)


ChannelsCarouselHandler.notifyChannel = MyNotifyChannel

def myOnAccountShowGUI(*args):
    global retries
    global clanName
    retries -= 1
    if g_clanCache.clanInfo[1] is None:
        if retries > 0:
            BigWorld.callback(1, myOnAccountShowGUI)
    else:
        clanName = '[%s]' % g_clanCache.clanInfo[1]
        #print 'Ignoring %s notifications' % clanName
        g_playerEvents.onAccountShowGUI -= myOnAccountShowGUI
        retries = 0
    return


g_playerEvents.onAccountShowGUI += myOnAccountShowGUI
