From 8f2120371b27575bec6979e0a1345ef3fa55de15 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sat, 7 Nov 2009 12:37:16 +0100 Subject: [PATCH] update correctly self_contact Contact instance and roster row when we use an anonymous account (our jid changes in this case). Fixes #5370 --- src/common/connection.py | 3 +++ src/common/contacts.py | 11 +++++++++++ src/gui_interface.py | 10 ++++++++++ src/roster_window.py | 15 +++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/common/connection.py b/src/common/connection.py index 9a02ce4e1..717684a6b 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -777,7 +777,10 @@ class Connection(ConnectionHandlers): self.server_resource = con.Resource if gajim.config.get_per('accounts', self.name, 'anonymous_auth'): # Get jid given by server + old_jid = gajim.get_jid_from_account(self.name) gajim.config.set_per('accounts', self.name, 'name', con.User) + new_jid = gajim.get_jid_from_account(self.name) + self.dispatch('NEW_JID', (old_jid, new_jid)) if auth: self.last_io = gajim.idlequeue.current_time() self.connected = 2 diff --git a/src/common/contacts.py b/src/common/contacts.py index b50f80d70..e35f41eba 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -219,6 +219,17 @@ class Contacts: del self._gc_contacts[old_name] del self._metacontacts_tags[old_name] + def change_contact_jid(self, old_jid, new_jid, account): + if account not in self._contacts: + return + if old_jid not in self._contacts[account]: + return + self._contacts[account][new_jid] = [] + for _contact in self._contacts[account][old_jid]: + _contact.jid = new_jid + self._contacts[account][new_jid].append(_contact) + del self._contacts[account][old_jid] + def add_account(self, account): self._contacts[account] = {} self._gc_contacts[account] = {} diff --git a/src/gui_interface.py b/src/gui_interface.py index 3f8a50036..99733ff92 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -263,6 +263,14 @@ class Interface: if self.remote_ctrl: self.remote_ctrl.raise_signal('AccountPresence', (show, account)) + def handle_event_new_jid(self, account, data): + #('NEW_JID', account, (old_jid, new_jid)) + ''' + This event is raised when our JID changed (most probably because we use + anonymous account. We update contact and roster entry in this case. + ''' + self.roster.rename_self_contact(data[0], data[1], account) + def edit_own_details(self, account): jid = gajim.get_jid_from_account(account) if 'profile' not in self.instances[account]: @@ -1515,6 +1523,7 @@ class Interface: def handle_event_signed_in(self, account, empty): '''SIGNED_IN event is emitted when we sign in, so handle it''' + # ('SIGNED_IN', account, ()) # block signed in notifications for 30 seconds gajim.block_signed_in_notifications[account] = True self.roster.set_actions_menu_needs_rebuild() @@ -2001,6 +2010,7 @@ class Interface: 'INFORMATION': [self.handle_event_information], 'ERROR_ANSWER': [self.handle_event_error_answer], 'STATUS': [self.handle_event_status], + 'NEW_JID': [self.handle_event_new_jid], 'NOTIFY': [self.handle_event_notify], 'MSGERROR': [self.handle_event_msgerror], 'MSGSENT': [self.handle_event_msgsent], diff --git a/src/roster_window.py b/src/roster_window.py index 9e1d81a9f..ce8c41261 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -784,6 +784,21 @@ class RosterWindow: return True + def rename_self_contact(self, old_jid, new_jid, account): + '''Rename the self_contact jid + + Keyword arguments: + old_jid -- our old jid + new_jid -- our new jid + account -- the corresponding account. + ''' + gajim.contacts.change_contact_jid(old_jid, new_jid, account) + self_iter = self._get_self_contact_iter(account, model=self.model) + if not self_iter: + return + self.model[self_iter][C_JID] = new_jid + self.draw_contact(new_jid, account) + def add_groupchat(self, jid, account, status=''): '''Add groupchat to roster and draw it. Return the added contact instance.