From d25d056677c272fa6529f19ae7910e182b190797 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 1 May 2006 18:29:12 +0000 Subject: [PATCH] be sure that transport is really removed before we start to remove its contacts. --- src/common/connection.py | 3 +++ src/common/connection_handlers.py | 4 ++++ src/gajim.py | 18 ++++++++++++++++++ src/roster_window.py | 12 ------------ 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 2d7e430d3..928eaa473 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -744,6 +744,9 @@ class Connection(ConnectionHandlers): return iq = common.xmpp.Iq('set', common.xmpp.NS_REGISTER, to = agent) iq.getTag('query').setTag('remove') + id = self.connection.getAnID() + iq.setID(id) + self.awaiting_answers[id] = (AGENT_REMOVED, agent) self.connection.send(iq) self.connection.getRoster().delItem(agent) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 2419882a7..8c01da290 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -40,6 +40,7 @@ STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd', # kind of events we can wait for an answer VCARD_PUBLISHED = 'vcard_published' VCARD_ARRIVED = 'vcard_arrived' +AGENT_REMOVED = 'agent_removed' HAS_IDLE = True try: import common.idle as idle # when we launch gajim from sources @@ -947,6 +948,9 @@ class ConnectionVcard: self.dispatch('VCARD', {'jid': jid}) elif jid == our_jid: self.dispatch('MYVCARD', {'jid': jid}) + elif self.awaiting_answers[id][0] == AGENT_REMOVED: + jid = self.awaiting_answers[id][1] + self.dispatch('AGENT_REMOVED', jid) del self.awaiting_answers[id] def _vCardCB(self, con, vc): diff --git a/src/gajim.py b/src/gajim.py index b05af51f4..432a23177 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -729,6 +729,23 @@ class Interface: except AttributeError: return + def handle_event_agent_removed(self, account, agent): + # remove transport's contacts from treeview + jid_list = gajim.contacts.get_jid_list(account) + for jid in jid_list: + if jid.endswith('@' + agent): + c = gajim.contacts.get_first_contact_from_jid(account, jid) + gajim.log.debug( + 'Removing contact %s due to unregistered transport %s'\ + % (jid, agent)) + gajim.connections[account].unsubscribe(c.jid) + # Transport contacts can't have 2 resources + if c.jid in gajim.to_be_removed[account]: + # This way we'll really remove it + gajim.to_be_removed[account].remove(c.jid) + gajim.contacts.remove_jid(account, c.jid) + self.roster.remove_contact(c, account) + def handle_event_register_agent_info(self, account, array): #('REGISTER_AGENT_INFO', account, (agent, infos, is_form)) if array[1].has_key('instructions'): @@ -1623,6 +1640,7 @@ class Interface: 'SUBSCRIBE': self.handle_event_subscribe, 'AGENT_ERROR_INFO': self.handle_event_agent_info_error, 'AGENT_ERROR_ITEMS': self.handle_event_agent_items_error, + 'AGENT_REMOVED': self.handle_event_agent_removed, 'REGISTER_AGENT_INFO': self.handle_event_register_agent_info, 'AGENT_INFO_ITEMS': self.handle_event_agent_info_items, 'AGENT_INFO_INFO': self.handle_event_agent_info_info, diff --git a/src/roster_window.py b/src/roster_window.py index e2c1a5d8f..7c10e83e6 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1142,18 +1142,6 @@ class RosterWindow: gajim.connections[account].unsubscribe_agent(full_jid) # remove transport from treeview self.remove_contact(contact, account) - # remove transport's contacts from treeview - jid_list = gajim.contacts.get_jid_list(account) - for jid in jid_list: - if jid.endswith('@' + contact.jid): - c = gajim.contacts.get_first_contact_from_jid(account, jid) - gajim.log.debug( - 'Removing contact %s due to unregistered transport %s'\ - % (jid, contact.jid)) - gajim.connections[account].unsubscribe(c.jid) - # Transport contacts can't have 2 resources - gajim.contacts.remove_jid(account, c.jid) - self.remove_contact(c, account) gajim.contacts.remove_jid(account, contact.jid) gajim.contacts.remove_contact(account, contact)