changeset c588b95587c5 in /home/hg/repos/gajim
author: Yann Leboulanger asterix@lagaule.org branches: details:http://hg.gajim.org/gajim?cmd=changeset;node=c588b95587c5 description: handle XEP-191 (blocking command) in a better way: hability to block a contact when server doesn't support privacy lists, add / remove jid to blocked list only when we get the result from server, handle blocked / unblocked contacts by other resources
diffstat:
src/common/connection.py | 2 -- src/common/connection_handlers.py | 30 +++++++++++++++++++++++++++--- src/common/connection_handlers_events.py | 23 +++++++++++++++++++++++ src/roster_window.py | 21 ++++++++++++++++----- 4 files changed, 66 insertions(+), 10 deletions(-)
diffs (163 lines):
diff -r 4754b56ec030 -r c588b95587c5 src/common/connection.py --- a/src/common/connection.py Mon Aug 11 22:16:11 2014 +0200 +++ b/src/common/connection.py Wed Aug 13 22:46:18 2014 +0200 @@ -1706,7 +1706,6 @@ 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 @@ 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 -r 4754b56ec030 -r c588b95587c5 src/common/connection_handlers.py --- a/src/common/connection_handlers.py Mon Aug 11 22:16:11 2014 +0200 +++ b/src/common/connection_handlers.py Wed Aug 13 22:46:18 2014 +0200 @@ -574,9 +574,9 @@ 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 @@ 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 @@ 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 @@ 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 @@ nbxmpp.NS_PUBKEY_PUBKEY) con.RegisterHandler('iq', self._PubkeyResultCB, 'result', nbxmpp.NS_PUBKEY_PUBKEY) + con.RegisterHandler('iq', self._BlockingSetCB, 'set', + nbxmpp.NS_BLOCKING) diff -r 4754b56ec030 -r c588b95587c5 src/common/connection_handlers_events.py --- a/src/common/connection_handlers_events.py Mon Aug 11 22:16:11 2014 +0200 +++ b/src/common/connection_handlers_events.py Wed Aug 13 22:46:18 2014 +0200 @@ -2552,3 +2552,26 @@
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 -r 4754b56ec030 -r c588b95587c5 src/roster_window.py --- a/src/roster_window.py Mon Aug 11 22:16:11 2014 +0200 +++ b/src/roster_window.py Wed Aug 13 22:46:18 2014 +0200 @@ -3035,6 +3035,14 @@ 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 @@ 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 @@ """ 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 @@ 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)