diff --git a/src/common/connection.py b/src/common/connection.py index 3dcf2ec48..e1551299d 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -159,6 +159,7 @@ class CommonConnection: self.archiving_supported = False self.archive_pref_supported = False self.roster_supported = True + self.blocking_supported = False self.muc_jid = {} # jid of muc server for each transport type self._stun_servers = [] # STUN servers of our jabber server @@ -1576,11 +1577,20 @@ class Connection(CommonConnection, ConnectionHandlers): def block_contacts(self, contact_list, message): if not self.privacy_rules_supported: + if self.blocking_supported: #XEP-0191 + iq = nbxmpp.Iq('set', xmlns='') + query = iq.setQuery(name='block') + query.setNamespace(nbxmpp.NS_BLOCKING) + for contact in contact_list: + self.blocked_contacts.append(contact.jid) + query.addChild(name='item', attrs={'jid': contact.jid}) + self.connection.send(iq) return for contact in contact_list: self.send_custom_status('offline', message, contact.jid) new_rule = {'order': '1', 'type': 'jid', 'action': 'deny', - 'value' : contact.jid, 'child': ['message', 'iq', 'presence-out']} + 'value' : contact.jid, 'child': ['message', 'iq', + 'presence-out']} self.blocked_list.append(new_rule) self.blocked_contacts.append(contact.jid) self.set_privacy_list('block', self.blocked_list) @@ -1591,6 +1601,14 @@ class Connection(CommonConnection, ConnectionHandlers): def unblock_contacts(self, contact_list): if not self.privacy_rules_supported: + if self.blocking_supported: #XEP-0191 + iq = nbxmpp.Iq('set', xmlns='') + query = iq.setQuery(name='unblock') + query.setNamespace(nbxmpp.NS_BLOCKING) + for contact in contact_list: + self.blocked_contacts.append(contact.jid) + query.addChild(name='item', attrs={'jid': contact.jid}) + self.connection.send(iq) return self.new_blocked_list = [] self.to_unblock = [] @@ -1831,6 +1849,8 @@ class Connection(CommonConnection, ConnectionHandlers): self.archive_manual_supported = True if nbxmpp.NS_ARCHIVE_PREF in obj.features: self.archive_pref_supported = True + if nbxmpp.NS_BLOCKING in obj.features: + self.blocking_supported = True if nbxmpp.NS_CARBONS in obj.features and gajim.config.get_per( 'accounts', self.name, 'enable_message_carbons'): # Server supports carbons, activate it diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 298b2be05..80c82731f 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -80,6 +80,7 @@ METACONTACTS_ARRIVED = 'metacontacts_arrived' ROSTER_ARRIVED = 'roster_arrived' DELIMITER_ARRIVED = 'delimiter_arrived' PRIVACY_ARRIVED = 'privacy_arrived' +BLOCKING_ARRIVED = 'blocking_arrived' PEP_CONFIG = 'pep_config' HAS_IDLE = True try: @@ -562,8 +563,18 @@ class ConnectionVcard: if iq_obj.getType() != 'error': self.privacy_rules_supported = True self.get_privacy_list('block') - elif self.continue_connect_info: - if self.continue_connect_info[0] == 'invisible': + else: + if self.blocking_supported: + iq = nbxmpp.Iq('get', xmlns='') + query = iq.setQuery(name='blocklist') + query.setNamespace(nbxmpp.NS_BLOCKING) + id_ = self.connection.getAnID() + iq.setID(id_) + self.awaiting_answers[id_] = (BLOCKING_ARRIVED, ) + self.connection.send(iq) + + if self.continue_connect_info and self.continue_connect_info[0]\ + == 'invisible': # Trying to login as invisible but privacy list not # supported self.disconnect(on_purpose=True) @@ -576,6 +587,14 @@ class ConnectionVcard: return # Ask metacontacts before roster self.get_metacontacts() + elif self.awaiting_answers[id_][0] == BLOCKING_ARRIVED: + if iq_obj.getType() == 'result': + list_node = iq_obj.getTag('blocklist') + if not list_node: + return + self.blocked_contacts = [] + for i in list_node.iterTags('item'): + self.blocked_contacts.append(i.getAttr('jid')) elif self.awaiting_answers[id_][0] == PEP_CONFIG: if iq_obj.getType() == 'error': return