diff --git a/src/common/connection.py b/src/common/connection.py index 67c7cf3b3..ed63952e2 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1706,7 +1706,6 @@ class Connection(CommonConnection, ConnectionHandlers): 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 @@ -1731,7 +1730,6 @@ class Connection(CommonConnection, ConnectionHandlers): 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 diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index ad98f51c3..0376bd341 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -574,9 +574,9 @@ class ConnectionVcard: 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, ) + id2_ = self.connection.getAnID() + iq.setID(id2_) + self.awaiting_answers[id2_] = (BLOCKING_ARRIVED, ) self.connection.send(iq) if self.continue_connect_info and self.continue_connect_info[0]\ @@ -1521,6 +1521,8 @@ ConnectionJingle, ConnectionIBBytestream): self._nec_agent_removed) gajim.ged.register_event_handler('stream-other-host-received', ged.CORE, self._nec_stream_other_host_received) + gajim.ged.register_event_handler('blocking', ged.CORE, + self._nec_blocking) def cleanup(self): ConnectionHandlersBase.cleanup(self) @@ -1565,6 +1567,7 @@ ConnectionJingle, ConnectionIBBytestream): self._nec_agent_removed) gajim.ged.remove_event_handler('stream-other-host-received', ged.CORE, self._nec_stream_other_host_received) + gajim.ged.remove_event_handler('blocking', ged.CORE, self._nec_blocking) def build_http_auth_answer(self, iq_obj, answer): if not self.connection or self.connected < 2: @@ -2254,6 +2257,25 @@ ConnectionJingle, ConnectionIBBytestream): jid_from = helpers.get_full_jid_from_iq(iq_obj) jingle_xtls.handle_new_cert(con, iq_obj, jid_from) + def _BlockingSetCB(self, con, iq_obj): + log.debug('_BlockingSetCB') + gajim.nec.push_incoming_event(BlockingEvent(None, conn=self, + stanza=iq_obj)) + raise nbxmpp.NodeProcessed + + def _nec_blocking(self, obj): + if obj.conn.name != self.name: + return + if obj.unblock_all: + self.blocked_contacts = [] + else: + for jid in obj.blocked_jids: + if jid not in self.blocked_contacts: + self.blocked_contacts.append(jid) + for jid in obj.unblocked_jids: + if jid in self.blocked_contacts: + self.blocked_contacts.remove(jid) + def _nec_stream_other_host_received(self, obj): if obj.conn.name != self.name: return @@ -2348,3 +2370,5 @@ ConnectionJingle, ConnectionIBBytestream): nbxmpp.NS_PUBKEY_PUBKEY) con.RegisterHandler('iq', self._PubkeyResultCB, 'result', nbxmpp.NS_PUBKEY_PUBKEY) + con.RegisterHandler('iq', self._BlockingSetCB, 'set', + nbxmpp.NS_BLOCKING) diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 57eaa9d83..90b0f13d3 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -2552,3 +2552,26 @@ class InformationEvent(nec.NetworkIncomingEvent): def init(self): self.popup = True + +class BlockingEvent(nec.NetworkIncomingEvent): + name = 'blocking' + base_network_events = [] + + def init(self): + self.blocked_jids = [] + self.unblocked_jids = [] + self.unblock_all = False + + def generate(self): + block_tag = self.stanza.getTag('block', namespace=nbxmpp.NS_BLOCKING) + if block_tag: + for item in block_tag.getTags('item'): + self.blocked_jids.append(item.getAttr('jid')) + unblock_tag = self.stanza.getTag('unblock', + namespace=nbxmpp.NS_BLOCKING) + if unblock_tag: + if not unblock_tag.getTags('item'): # unblock all + self.unblock_all = True + for item in unblock_tag.getTags('item'): + self.unblocked_jids.append(item.getAttr('jid')) + return True diff --git a/src/roster_window.py b/src/roster_window.py index 682ffc65e..102b8fefb 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -3035,6 +3035,14 @@ class RosterWindow: dialogs.ConfirmationDialog(pritext, sectext, on_response_ok = (remove, list_)) + def _nec_blocking(self, obj): + if obj.unblock_all: + jids = gajim.contacts.get_jid_list(obj.conn.name) + self._idle_draw_jids_of_account(jids, obj.conn.name) + else: + for jid in obj.blocked_jids + obj.unblocked_jids: + self.draw_contact(jid, obj.conn.name) + def on_block(self, widget, list_, group=None): """ When clicked on the 'block' button in context menu. list_ is a list of @@ -3044,9 +3052,9 @@ class RosterWindow: if msg is None: # user pressed Cancel to change status message dialog return - accounts = [] - accounts = set(i[1] for i in list_ if gajim.connections[i[1]].\ - privacy_rules_supported) + accounts = set(i[1] for i in list_ if (gajim.connections[i[1]].\ + privacy_rules_supported or (group is None and gajim.\ + connections[i[1]].blocking_supported))) if group is None: for acct in accounts: l_ = [i[0] for i in list_ if i[1] == acct] @@ -3084,8 +3092,9 @@ class RosterWindow: """ When clicked on the 'unblock' button in context menu. """ - accounts = set(i[1] for i in list_ if gajim.connections[i[1]].\ - privacy_rules_supported) + accounts = set(i[1] for i in list_ if (gajim.connections[i[1]].\ + privacy_rules_supported or (group is None and gajim.\ + connections[i[1]].blocking_supported))) if group is None: for acct in accounts: l_ = [i[0] for i in list_ if i[1] == acct] @@ -6547,3 +6556,5 @@ class RosterWindow: self._nec_signed_in) gajim.ged.register_event_handler('decrypted-message-received', ged.GUI2, self._nec_decrypted_message_received) + gajim.ged.register_event_handler('blocking', ged.GUI1, + self._nec_blocking)