From 2720f1ce7c6dfdab1fb1a4710d8796317ca9cb73 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 2 Nov 2005 08:12:54 +0000 Subject: [PATCH] move function to get real_jid to gajim.py --- src/common/gajim.py | 14 +++++++++++++- src/tabbed_chat_window.py | 33 +++++++-------------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/common/gajim.py b/src/common/gajim.py index c813d0849..3396fe522 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -125,7 +125,19 @@ def get_room_and_nick_from_fjid(jid): if len(l) == 1: # No nick l.append('') return l - + +def get_real_jid_from_fjid(account, fjid): + room_jid, nick = get_room_and_nick_from_fjid(fjid) + if not nick: # It's not a fake_jid, so it's not pm + return fjid + real_jid = fjid + gcs = interface.windows[account]['gc'] + if gcs.has_key(room_jid): + # It's a pm, so if we have real jid it's in contact.jid + contact = gc_contacts[account][room_jid][nick] + real_jid = contact.jid + return real_jid + def get_room_from_fjid(jid): return get_room_and_nick_from_fjid(jid)[0] diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index a25504b69..859eace3a 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -132,14 +132,8 @@ class TabbedChatWindow(chat.Chat): '''we enter the eventbox area so we under conditions add a timeout to show a bigger avatar after 0.5 sec''' jid = self.get_active_jid() - real_jid = jid - # Is it a pm ? if it is we get the real jid - room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) - gcs = gajim.interface.windows[self.account]['gc'] - if gcs.has_key(room_jid): - contact = gajim.gc_contacts[self.account][room_jid][nick] - real_jid = contact.jid - if not real_jid: + real_jid = gajim.get_real_jid_from_fjid(self.account, jid) + if not real_jid: # this can happend if we're in a moderate room return avatar_pixbuf = gajim.interface.get_avatar_pixbuf_from_cache(real_jid) avatar_w = avatar_pixbuf.get_width() @@ -165,14 +159,8 @@ class TabbedChatWindow(chat.Chat): '''resizes the avatar, if needed, so it has at max half the screen size and shows it''' jid = self.get_active_jid() - real_jid = jid - # Is it a pm ? if it is we get the real jid - room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) - gcs = gajim.interface.windows[self.account]['gc'] - if gcs.has_key(room_jid): - contact = gajim.gc_contacts[self.account][room_jid][nick] - real_jid = contact.jid - if not real_jid: + real_jid = gajim.get_real_jid_from_fjid(self.account, jid) + if not real_jid: # this can happend if we're in a moderate room return avatar_pixbuf = gajim.interface.get_avatar_pixbuf_from_cache(real_jid) screen_w = gtk.gdk.screen_width() @@ -315,19 +303,12 @@ class TabbedChatWindow(chat.Chat): # we assume contact has no avatar scaled_buf = None - real_jid = jid - # Is it a pm ? if it is we get the real jid - room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) - if nick: - gcs = gajim.interface.windows[self.account]['gc'] - if gcs.has_key(room_jid): - contact = gajim.gc_contacts[self.account][room_jid][nick] - real_jid = contact.jid - + real_jid = gajim.get_real_jid_from_fjid(self.account, jid) pixbuf = None if real_jid: pixbuf = gajim.interface.get_avatar_pixbuf_from_cache(real_jid) - if not real_jid or pixbuf == 'ask': # we don't have the vcard or it's too old + if not real_jid or pixbuf == 'ask': + # we don't have the vcard or it's pm and we don't have the real jid gajim.connections[self.account].request_vcard(jid_with_resource) return if pixbuf is not None: