From 1fafe3b08c3f807f3bba4078f39052e41c154d53 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sat, 25 Mar 2006 17:05:54 +0000 Subject: [PATCH] handle correctly resources in queue of events. Fixes #1706 --- src/chat_control.py | 2 +- src/common/helpers.py | 3 +++ src/gajim.py | 36 ++++++++++++++++++++++-------------- src/roster_window.py | 24 +++++++++++++++++++++--- 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index c4b6d396b..515da2153 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -1473,7 +1473,7 @@ class ChatControl(ChatControlBase): # Redraw parent too gajim.interface.roster.draw_parent_contact(jid, self.account) if gajim.interface.systray_enabled: - gajim.interface.systray.remove_jid(jid, self.account, typ) + gajim.interface.systray.remove_jid(fjid, self.account, typ) if (self.contact.show == 'offline' or self.contact.show == 'error'): showOffline = gajim.config.get('showoffline') if not showOffline and typ == 'chat' and \ diff --git a/src/common/helpers.py b/src/common/helpers.py index 7ec6c63c9..d284b52c2 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -506,6 +506,9 @@ def get_icon_name_to_show(contact, account = None): '''Get the icon name to show in online, away, requested, ...''' if account and gajim.awaiting_events[account].has_key(contact.jid): return 'message' + if account and gajim.awaiting_events[account].has_key( + contact.get_full_jid()): + return 'message' if contact.jid.find('@') <= 0: # if not '@' or '@' starts the jid ==> agent return contact.show if contact.sub in ('both', 'to'): diff --git a/src/gajim.py b/src/gajim.py index 159b38d4b..6c0d9c5e5 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -484,9 +484,9 @@ class Interface: show_notification = True chat_control = self.msg_win_mgr.get_control(jid, account) + jid_of_control = jid if chat_control and chat_control.type_id == message_control.TYPE_GC: # it's a Private Message - fjid = array[0] room_jid, nick = gajim.get_room_and_nick_from_fjid(fjid) if not self.msg_win_mgr.has_window(fjid, account) and \ not gajim.awaiting_events[account].has_key(fjid): @@ -503,16 +503,20 @@ class Interface: chat_control.on_private_message(nick, array[1], array[2]) return - # FIXME: This should happen first if gajim.config.get('ignore_unknown_contacts') and \ not gajim.contacts.get_contact(account, jid): return + highest_contact = gajim.contacts.get_contact_with_highest_priority( + account, jid) # Look for a chat control that has the given resource, or default to one # without resource ctrl = self.msg_win_mgr.get_control(fjid, account) if ctrl: chat_control = ctrl + elif resource != highest_contact.resource: + chat_control = None + jid_of_control = fjid # Handle chat states contact = gajim.contacts.get_first_contact_from_jid(account, jid) if contact: @@ -553,14 +557,14 @@ class Interface: img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'single_msg_recv.png') path = gtkgui_helpers.get_path_to_generic_or_avatar(img) - notify.notify(_('New Single Message'), jid, account, msg_type, - path_to_image = path, text = txt) + notify.notify(_('New Single Message'), jid_of_control, + account, msg_type, path_to_image = path, text = txt) else: # chat message img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'chat_msg_recv.png') path = gtkgui_helpers.get_path_to_generic_or_avatar(img) - notify.notify(_('New Message'), jid, account, msg_type, - path_to_image = path, text = txt) + notify.notify(_('New Message'), jid_of_control, account, + msg_type, path_to_image = path, text = txt) # array : (contact, msg, time, encrypted, msg_type, subject) self.roster.on_message(jid, array[1], array[2], account, array[3], @@ -1523,16 +1527,20 @@ class Interface: def handle_event(self, account, jid, typ): w = None + fjid = jid + resource = gajim.get_resource_from_jid(jid) + jid = gajim.get_jid_without_resource(jid) if typ == message_control.TYPE_GC: w = self.msg_win_mgr.get_window(jid, account) elif typ == message_control.TYPE_CHAT: - if self.msg_win_mgr.has_window(jid, account): - w = self.msg_win_mgr.get_window(jid, account) + if self.msg_win_mgr.has_window(fjid, account): + w = self.msg_win_mgr.get_window(fjid, account) else: - contact = gajim.contacts.get_first_contact_from_jid(account, jid) - self.roster.new_chat(contact, account) - w = self.msg_win_mgr.get_window(jid, account) - ctrl = w.get_control + contact = gajim.contacts.get_contact(account, jid, resource) + if isinstance(contact, list): + contact = gajim.contacts.get_first_contact_from_jid(account, jid) + self.roster.new_chat(contact, account, resource = resource) + w = self.msg_win_mgr.get_window(fjid, account) gajim.last_message_time[account][jid] = 0 # long time ago elif typ == message_control.TYPE_PM: if self.msg_win_mgr.has_window(jid, account): @@ -1569,10 +1577,10 @@ class Interface: data[1]) self.remove_first_event(account, jid, typ) if w: - w.set_active_tab(jid, account) + w.set_active_tab(fjid, account) w.window.present() w.window.window.focus() - ctrl = w.get_control(jid, account) + ctrl = w.get_control(fjid, account) # Using isinstance here because we want to catch all derived types if isinstance(ctrl, ChatControlBase): tv = ctrl.conv_textview diff --git a/src/roster_window.py b/src/roster_window.py index bd260896a..66cdb16aa 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -432,6 +432,12 @@ class RosterWindow: iter = iters[0] # choose the icon with the first iter icon_name = helpers.get_icon_name_to_show(contact, account) + # look if anotherresource has awaiting events + for c in contact_instances: + c_icon_name = helpers.get_icon_name_to_show(c, account) + if c_icon_name == 'message': + icon_name = c_icon_name + break path = model.get_path(iter) if model.iter_has_child(iter): if not self.tree.row_expanded(path) and icon_name != 'message': @@ -2082,7 +2088,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid) # Redraw parent too self.draw_parent_contact(jid, account) if gajim.interface.systray_enabled: - gajim.interface.systray.add_jid(jid, account, kind) + gajim.interface.systray.add_jid(fjid, account, kind) self.show_title() # we show the * or [n] if not path: self.add_contact_to_roster(jid, account) @@ -2336,6 +2342,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid) account = model[path][C_ACCOUNT].decode('utf-8') type = model[path][C_TYPE] jid = model[path][C_JID].decode('utf-8') + resource = None iter = model.get_iter(path) if type in ('group', 'account'): if self.tree.row_expanded(path): @@ -2344,6 +2351,14 @@ _('If "%s" accepts this request you will know his or her status.') % jid) self.tree.expand_row(path, False) else: first_ev = gajim.get_first_event(account, jid) + if not first_ev: + # look in other resources + for c in gajim.contacts.get_contact(account, jid): + fjid = c.get_full_jid() + first_ev = gajim.get_first_event(account, fjid) + if first_ev: + resource = c.resource + break if not first_ev and model.iter_has_child(iter): child_iter = model.iter_children(iter) while not first_ev and child_iter: @@ -2354,10 +2369,13 @@ _('If "%s" accepts this request you will know his or her status.') % jid) else: child_iter = model.iter_next(child_iter) if first_ev: - if self.open_event(account, jid, first_ev): + fjid = jid + if resource: + fjid += '/' + resource + if self.open_event(account, fjid, first_ev): return c = gajim.contacts.get_contact_with_highest_priority(account, jid) - self.on_open_chat_window(widget, c, account) + self.on_open_chat_window(widget, c, account, resource = resource) def on_roster_treeview_row_expanded(self, widget, iter, path): '''When a row is expanded change the icon of the arrow'''