示例#1
0
 def __init__(self):
     super(PersonalInvitationsListener, self).__init__()
     self.__filter = SquadInvitationsFilter()
示例#2
0
class PersonalInvitationsListener(_Listener):
    __slots__ = ('__filter', )

    def __init__(self):
        super(PersonalInvitationsListener, self).__init__()
        self.__filter = SquadInvitationsFilter()

    @prbInvitesProperty
    def prbInvites(self):
        return None

    def start(self, setup):
        super(PersonalInvitationsListener, self).start(setup)
        self.__filter.setArenaUniqueID(self._visitor.getArenaUniqueID())
        invitesManager = self.prbInvites
        invitesManager.onReceivedInviteListModified += self.__im_onReceivedInviteModified
        invitesManager.onSentInviteListModified += self.__im_onSentInviteListModified

    def stop(self):
        invitesManager = self.prbInvites
        invitesManager.onReceivedInviteListModified -= self.__im_onReceivedInviteModified
        invitesManager.onSentInviteListModified -= self.__im_onSentInviteListModified
        super(PersonalInvitationsListener, self).stop()

    def addController(self, controller):
        result = super(PersonalInvitationsListener,
                       self).addController(controller)
        if result:
            self.__updateInvitationsStatuses()
        return result

    def __updateFilteredStatuses(self, filtered):
        update = self._arenaDP.updateInvitationStatus
        vos = []
        for dbID, include, exclude in filtered:
            flags, vo = update(dbID, include=include, exclude=exclude)
            if vo is not None and flags != INVALIDATE_OP.NONE:
                LOG_DEBUG('Invitation status has been changed', dbID,
                          vo.invitationDeliveryStatus)
                vos.append(vo)

        if vos:
            self._invokeListenersMethod('invalidateInvitationsStatuses', vos,
                                        self._arenaDP)
        return

    def __updateInvitationsStatuses(self):
        update = self._arenaDP.updateInvitationStatus
        vos = []
        for invite in self.prbInvites.getInvites(incoming=True):
            accountDBID, include = self.__filter.addReceivedInvite(invite)
            flags, vo = update(accountDBID, include=include)
            if vo is not None and flags != INVALIDATE_OP.NONE:
                vos.append(vo)

        for invite in self.prbInvites.getInvites(incoming=False):
            accountDBID, include = self.__filter.addSentInvite(invite)
            flags, vo = update(accountDBID, include=include)
            if vo is not None and flags != INVALIDATE_OP.NONE:
                vos.append(vo)

        if vos:
            self._invokeListenersMethod('invalidateInvitationsStatuses', vos,
                                        self._arenaDP)
        return

    def __im_onReceivedInviteModified(self, added, changed, deleted):
        filtered = self.__filter.filterReceivedInvites(
            self.prbInvites.getInvite, added, changed, deleted)
        self.__updateFilteredStatuses(filtered)

    def __im_onSentInviteListModified(self, added, changed, deleted):
        filtered = self.__filter.filterSentInvites(self.prbInvites.getInvite,
                                                   added, changed, deleted)
        self.__updateFilteredStatuses(filtered)
示例#3
0
class PersonalInvitationsListener(_Listener):
    __slots__ = ('__filter', '__arenaDP')

    def __init__(self):
        super(PersonalInvitationsListener, self).__init__()
        self.__filter = SquadInvitationsFilter()
        self.__arenaDP = None
        return

    @prbInvitesProperty
    def prbInvites(self):
        return None

    def start(self, arena, arenaDP = None, **kwargs):
        super(PersonalInvitationsListener, self).start(arena)
        if arenaDP is None:
            LOG_ERROR('Arena data provider is None')
            return
        else:
            self.__filter.setArenaUniqueID(self._arena().arenaUniqueID)
            self.__arenaDP = arenaDP
            invitesManager = self.prbInvites
            invitesManager.onReceivedInviteListModified += self.__im_onReceivedInviteModified
            invitesManager.onSentInviteListModified += self.__im_onSentInviteListModified
            return

    def stop(self):
        invitesManager = self.prbInvites
        invitesManager.onReceivedInviteListModified -= self.__im_onReceivedInviteModified
        invitesManager.onSentInviteListModified -= self.__im_onSentInviteListModified
        super(PersonalInvitationsListener, self).stop()

    def addController(self, battleCtx, controller):
        result = super(PersonalInvitationsListener, self).addController(battleCtx, controller)
        if result:
            self.__updateInvitationsStatuses()
        return result

    def __updateFilteredStatuses(self, filtered):
        update = self.__arenaDP.updateInvitationStatus
        vos = []
        for dbID, status in filtered:
            flags, vo = update(dbID, status)
            if vo is not None and flags != INVALIDATE_OP.NONE:
                vos.append(vo)

        if vos:
            self._invokeListenersMethod('invalidateInvitationsStatuses', vos, self.__arenaDP)
        return

    def __updateInvitationsStatuses(self):
        update = self.__arenaDP.updateInvitationStatus
        vos = []
        for invites in self.prbInvites.getInvites(incoming=True):
            flags, vo = update(*self.__filter.addReceivedInvite(invites))
            if vo is not None and flags != INVALIDATE_OP.NONE:
                vos.append(vo)

        for invites in self.prbInvites.getInvites(incoming=False):
            flags, vo = update(*self.__filter.addSentInvite(invites))
            if vo is not None and flags != INVALIDATE_OP.NONE:
                vos.append(vo)

        if vos:
            self._invokeListenersMethod('invalidateInvitationsStatuses', vos, self.__arenaDP)
        return

    def __im_onReceivedInviteModified(self, added, changed, deleted):
        filtered = self.__filter.filterReceivedInvites(self.prbInvites.getInvite, added, changed, deleted)
        self.__updateFilteredStatuses(filtered)

    def __im_onSentInviteListModified(self, added, changed, deleted):
        filtered = self.__filter.filterSentInvites(self.prbInvites.getInvite, added, changed, deleted)
        self.__updateFilteredStatuses(filtered)
示例#4
0
 def __init__(self):
     super(PersonalInvitationsListener, self).__init__()
     self.__filter = SquadInvitationsFilter()
     self.__arenaDP = None
     return
示例#5
0
class PersonalInvitationsListener(_Listener):
    __slots__ = ('__filter',)

    def __init__(self):
        super(PersonalInvitationsListener, self).__init__()
        self.__filter = SquadInvitationsFilter()

    @prbInvitesProperty
    def prbInvites(self):
        return None

    def start(self, setup):
        super(PersonalInvitationsListener, self).start(setup)
        self.__filter.setArenaUniqueID(self._visitor.getArenaUniqueID())
        invitesManager = self.prbInvites
        invitesManager.onReceivedInviteListModified += self.__im_onReceivedInviteModified
        invitesManager.onSentInviteListModified += self.__im_onSentInviteListModified

    def stop(self):
        invitesManager = self.prbInvites
        invitesManager.onReceivedInviteListModified -= self.__im_onReceivedInviteModified
        invitesManager.onSentInviteListModified -= self.__im_onSentInviteListModified
        super(PersonalInvitationsListener, self).stop()

    def addController(self, controller):
        result = super(PersonalInvitationsListener, self).addController(controller)
        if result:
            self.__updateInvitationsStatuses()
        return result

    def __updateFilteredStatuses(self, filtered):
        update = self._arenaDP.updateInvitationStatus
        vos = []
        for dbID, include, exclude in filtered:
            flags, vo = update(dbID, include=include, exclude=exclude)
            if vo is not None and flags != INVALIDATE_OP.NONE:
                LOG_DEBUG('Invitation status has been changed', dbID, vo.invitationDeliveryStatus)
                vos.append(vo)

        if vos:
            self._invokeListenersMethod('invalidateInvitationsStatuses', vos, self._arenaDP)
        return

    def __updateInvitationsStatuses(self):
        update = self._arenaDP.updateInvitationStatus
        vos = []
        for invite in self.prbInvites.getInvites(incoming=True):
            accountDBID, include = self.__filter.addReceivedInvite(invite)
            flags, vo = update(accountDBID, include=include)
            if vo is not None and flags != INVALIDATE_OP.NONE:
                vos.append(vo)

        for invite in self.prbInvites.getInvites(incoming=False):
            accountDBID, include = self.__filter.addSentInvite(invite)
            flags, vo = update(accountDBID, include=include)
            if vo is not None and flags != INVALIDATE_OP.NONE:
                vos.append(vo)

        if vos:
            self._invokeListenersMethod('invalidateInvitationsStatuses', vos, self._arenaDP)
        return

    def __im_onReceivedInviteModified(self, added, changed, deleted):
        filtered = self.__filter.filterReceivedInvites(self.prbInvites.getInvite, added, changed, deleted)
        self.__updateFilteredStatuses(filtered)

    def __im_onSentInviteListModified(self, added, changed, deleted):
        filtered = self.__filter.filterSentInvites(self.prbInvites.getInvite, added, changed, deleted)
        self.__updateFilteredStatuses(filtered)