From 964cb10163ed9c19c3c53af4ee4295a0ef503e03 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sat, 14 Jun 2008 08:43:20 +0000 Subject: [PATCH] hopefully fix the last of the get_control calls (fixes #4018) --- src/common/helpers.py | 15 ++++++++++----- src/gajim.py | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/common/helpers.py b/src/common/helpers.py index bcf3acaa9..cf794003e 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -960,17 +960,22 @@ def get_chat_control(account, contact): account, contact.jid) # Look for a chat control that has the given resource, or default to # one without resource - ctrl = gajim.interface.msg_win_mgr.get_control(full_jid_with_resource, + ctrls = gajim.interface.msg_win_mgr.get_chat_controls(full_jid_with_resource, account) - if ctrl: - return ctrl + if ctrls: + return ctrls[0] elif not highest_contact or not highest_contact.resource: # unknow contact or offline message - return gajim.interface.msg_win_mgr.get_control(contact.jid, account) + pass # fall through, handle this at the end elif highest_contact and contact.resource != \ highest_contact.resource: return None - return gajim.interface.msg_win_mgr.get_control(contact.jid, account) + + ctrls = gajim.interface.msg_win_mgr.get_chat_controls(contact.jid, account) + if ctrls: + return ctrls[0] + else: + return None def reduce_chars_newlines(text, max_chars = 0, max_lines = 0): '''Cut the chars after 'max_chars' on each line diff --git a/src/gajim.py b/src/gajim.py index 4d4562852..8a546c62e 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -798,6 +798,11 @@ class Interface: full_jid_with_resource = array[0] jids = full_jid_with_resource.split('/', 1) jid = jids[0] + + session = None + if len(array) > 5: + session = array[5] + gc_control = self.msg_win_mgr.get_gc_control(jid, account) if not gc_control and \ jid in self.minimized_controls[account]: @@ -807,8 +812,17 @@ class Interface: if gc_control: if len(jids) > 1: # it's a pm nick = jids[1] - if not self.msg_win_mgr.get_control(full_jid_with_resource, - account): + + ctrl = None + if session: + ctrl = session.control + + if not ctrl: + ctrls = self.msg_win_mgr.get_chat_controls(full_jid_with_resource, account) + if ctrls: + ctrl = ctrls[0] + + if not ctrl: tv = gc_control.list_treeview model = tv.get_model() iter = gc_control.get_contact_iter(nick) @@ -818,8 +832,8 @@ class Interface: show = 'offline' gc_c = gajim.contacts.create_gc_contact(room_jid = jid, name = nick, show = show) - self.new_private_chat(gc_c, account) - ctrl = self.msg_win_mgr.get_control(full_jid_with_resource, account) + ctrl = self.new_private_chat(gc_c, account, session) + ctrl.print_conversation('Error %s: %s' % (array[1], array[2]), 'status') return @@ -2673,6 +2687,8 @@ class Interface: # We call this here to avoid race conditions with widget validation session.control.read_queue() + return session.control + def new_chat(self, contact, account, resource = None, session = None): # Get target window, create a control, and associate it with the window type_ = message_control.TYPE_CHAT