Exemplo n.º 1
0
 def addIgnored(self, dbID, name):
     error = self._checkCooldown(CLIENT_ACTION_ID.ADD_IGNORED)
     if error:
         return (False, error)
     tasks, itemType = [], XMPP_ITEM_TYPE.EMPTY_ITEM
     contact = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP)
     if contact:
         if contact.isCurrentPlayer():
             return (False,
                     ClientActionError(CLIENT_ACTION_ID.ADD_IGNORED,
                                       CLIENT_ERROR_ID.GENERIC))
         itemType = contact.getItemType()
         if itemType in XMPP_ITEM_TYPE.BLOCK_ITEMS:
             return (False,
                     ClientContactError(CONTACT_ERROR_ID.BLOCK_ITEM_EXISTS,
                                        contact.getFullName()))
     length = self.usersStorage.getCount(
         ItemsFindCriteria(XMPP_ITEM_TYPE.PERSISTENT_BLOCKING_LIST))
     if length >= CONTACT_LIMIT.BLOCK_MAX_COUNT:
         return (False,
                 ClientIntLimitError(LIMIT_ERROR_ID.MAX_BLOCK_ITEMS,
                                     CONTACT_LIMIT.BLOCK_MAX_COUNT))
     if contact:
         jid = contact.getJID()
         if itemType in XMPP_ITEM_TYPE.SUB_PENDING_ITEMS:
             tasks.append(sub_tasks.CancelSubscriptionTask(jid))
     else:
         jid = makeContactJID(dbID)
     tasks.append(block_tasks.AddBlockItemTask(jid, name))
     if itemType in XMPP_ITEM_TYPE.ROSTER_ITEMS:
         groups = contact.getGroups()
         if groups:
             tasks.append(roster_tasks.EmptyGroupsTask(jid, groups=groups))
     self.__cooldown.process(CLIENT_ACTION_ID.ADD_IGNORED)
     return self.__addTasks(CLIENT_ACTION_ID.ADD_IGNORED, jid, *tasks)
Exemplo n.º 2
0
 def cancelFriendship(self, dbID):
     contact = self.usersStorage.getUser(dbID, PROTO_TYPE.XMPP)
     result, error = self.canCancelFriendship(contact)
     if not result:
         return (result, error)
     jid = contact.getJID()
     tasks = [sub_tasks.CancelSubscriptionTask(jid)]
     if note_tasks.canNoteAutoDelete(contact):
         tasks.append(note_tasks.RemoveNoteTask(jid))
     return self.__addTasks(CLIENT_ACTION_ID.CANCEL_FRIENDSHIP, jid, *tasks)