From 651e801334da40bd947006b9542529e21d24a56f Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 15 Sep 2009 17:41:47 +0200 Subject: [PATCH] correctly change the resource of a control. Fixes #5261 --- src/chat_control.py | 13 +++++++++++++ src/message_window.py | 9 +++++++++ src/session.py | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 4d2a8806f..e5886c2be 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -1433,6 +1433,19 @@ class ChatControl(ChatControlBase): else: self._tune_image.hide() + def change_resource(self, resource): + old_full_jid = self.get_full_jid() + self.resource = resource + new_full_jid = self.get_full_jid() + # update gajim.last_message_time + if old_full_jid in gajim.last_message_time[self.account]: + gajim.last_message_time[self.account][new_full_jid] = \ + gajim.last_message_time[self.account][old_full_jid] + # update events + gajim.events.change_jid(self.account, old_full_jid, new_full_jid) + # update MessageWindow._controls + self.parent_win.change_jid(self.account, old_full_jid, new_full_jid) + def on_avatar_eventbox_enter_notify_event(self, widget, event): ''' we enter the eventbox area so we under conditions add a timeout diff --git a/src/message_window.py b/src/message_window.py index 7d227206c..5b27ee421 100644 --- a/src/message_window.py +++ b/src/message_window.py @@ -158,6 +158,15 @@ class MessageWindow(object): if self.account == old_name: self.account = new_name + def change_jid(self, account, old_jid, new_jid): + ''' call then when the full jid of a contral change''' + if account not in self._controls: + return + if old_jid not in self._controls[account]: + return + self._controls[account][new_jid] = self._controls[account][old_jid] + del self._controls[account][old_jid] + def get_num_controls(self): return sum(len(d) for d in self._controls.values()) diff --git a/src/session.py b/src/session.py index f68d7c2dc..f23f3fe9f 100644 --- a/src/session.py +++ b/src/session.py @@ -88,8 +88,8 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): subject = msg.getSubject() if self.jid != full_jid_with_resource: self.resource = gajim.get_nick_from_fjid(full_jid_with_resource) - if self.control: - self.control.resource = self.resource + if self.control and self.control.resource: + self.control.change_resource(self.resource) if not msg_type or msg_type not in ('chat', 'groupchat', 'error'): msg_type = 'normal'