Author: asterix
Date: 2007-09-04 20:32:31 +0200 (Tue, 04 Sep 2007)
New Revision: 8709
Modified:
branches/gajim_0.11.1/src/chat_control.py
branches/gajim_0.11.1/src/common/connection_handlers.py
branches/gajim_0.11.1/src/gajim.py
branches/gajim_0.11.1/src/groupchat_control.py
branches/gajim_0.11.1/src/roster_window.py
branches/gajim_0.11.1/src/vcard.py
Log:
ask vcard to rela jid in muc if we knows it
Modified: branches/gajim_0.11.1/src/chat_control.py
===================================================================
--- branches/gajim_0.11.1/src/chat_control.py 2007-09-04 17:45:42 UTC (rev 8708)
+++ branches/gajim_0.11.1/src/chat_control.py 2007-09-04 18:32:31 UTC (rev 8709)
@@ -1588,24 +1588,34 @@
if not gajim.config.get('show_avatar_in_chat'):
return
- jid = self.contact.jid
- jid_with_resource = jid
- if resource:
- jid_with_resource += '/' + resource
+ is_fake = False
+ if self.TYPE_ID == message_control.TYPE_PM:
+ is_fake = True
+ jid_with_resource = self.contact.jid # fake jid
+ else:
+ jid_with_resource = self.contact.jid
+ if resource:
+ jid_with_resource += '/' + resource
# we assume contact has no avatar
scaled_pixbuf = None
- pixbuf = None
- is_fake = False
- if gajim.contacts.is_pm_from_jid(self.account, jid):
- is_fake = True
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid_with_resource,
is_fake)
if pixbuf == 'ask':
# we don't have the vcard
- gajim.connections[self.account].request_vcard(jid_with_resource,
- is_fake)
+ if self.TYPE_ID == message_control.TYPE_PM:
+ if self.gc_contact.jid:
+ # We know the real jid of this contact
+ real_jid = self.gc_contact.jid
+ if self.gc_contact.resource:
+ real_jid += '/' + self.gc_contact.resource
+ else:
+ real_jid = jid_with_resource
+ gajim.connections[self.account].request_vcard(real_jid,
+ jid_with_resource)
+ else:
+ gajim.connections[self.account].request_vcard(jid_with_resource)
return
if pixbuf is not None:
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'chat')
Modified: branches/gajim_0.11.1/src/common/connection_handlers.py
===================================================================
--- branches/gajim_0.11.1/src/common/connection_handlers.py 2007-09-04 17:45:42 UTC (rev 8708)
+++ branches/gajim_0.11.1/src/common/connection_handlers.py 2007-09-04 18:32:31 UTC (rev 8709)
@@ -796,6 +796,7 @@
self.vcard_sha = None
self.vcard_shas = {} # sha of contacts
self.room_jids = [] # list of gc jids so that vcard are saved in a folder
+ self.groupchat_jids = {} # {ID : groupchat_jid}
def add_sha(self, p, send_caps = True):
c = p.setTag('x', namespace = common.xmpp.NS_VCARD_UPDATE)
@@ -894,9 +895,10 @@
vcard['resource'] = gajim.get_resource_from_jid(fjid)
return vcard
- def request_vcard(self, jid = None, is_fake_jid = False):
- '''request the VCARD. If is_fake_jid is True, it means we request a vcard
- to a fake jid, like in private messages in groupchat'''
+ def request_vcard(self, jid = None, groupchat_jid = None):
+ '''request the VCARD. If groupchat_jid is not nul, it means we request a vcard
+ to a fake jid, like in private messages in groupchat. jid can be the
+ real jid of the contact, but we want to consider it comes from a fake jid'''
if not self.connection:
return
iq = common.xmpp.Iq(typ = 'get')
@@ -909,13 +911,13 @@
j = jid
if not j:
j = gajim.get_jid_from_account(self.name)
- self.awaiting_answers[id] = (VCARD_ARRIVED, j)
- if is_fake_jid:
- room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
+ self.awaiting_answers[id] = (VCARD_ARRIVED, j, groupchat_jid)
+ if groupchat_jid:
+ room_jid, nick = gajim.get_room_and_nick_from_fjid(groupchat_jid)
if not room_jid in self.room_jids:
self.room_jids.append(room_jid)
+ self.groupchat_jids[id] = groupchat_jid
self.connection.send(iq)
- #('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
def send_vcard(self, vcard):
if not self.connection:
@@ -998,17 +1000,22 @@
# If vcard is empty, we send to the interface an empty vcard so that
# it knows it arrived
jid = self.awaiting_answers[id][1]
+ groupchat_jid = self.awaiting_answers[id][2]
+ frm = jid
+ if groupchat_jid:
+ # We do as if it comes from the fake_jid
+ frm = groupchat_jid
our_jid = gajim.get_jid_from_account(self.name)
if iq_obj.getType() == 'error' and jid == our_jid:
# our server doesn't support vcard
self.vcard_supported = False
if not iq_obj.getTag('vCard') or iq_obj.getType() == 'error':
- if jid and jid != our_jid:
+ if frm and frm != our_jid:
# Write an empty file
- self.save_vcard_to_hd(jid, '')
- self.dispatch('VCARD', {'jid': jid})
- elif jid == our_jid:
- self.dispatch('MYVCARD', {'jid': jid})
+ self.save_vcard_to_hd(frm, '')
+ self.dispatch('VCARD', {'jid': frm})
+ elif frm == our_jid:
+ self.dispatch('MYVCARD', {'jid': frm})
elif self.awaiting_answers[id][0] == AGENT_REMOVED:
jid = self.awaiting_answers[id][1]
self.dispatch('AGENT_REMOVED', jid)
@@ -1051,10 +1058,15 @@
return
if not vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
return
+ id = vc.getID()
frm_iq = vc.getFrom()
our_jid = gajim.get_jid_from_account(self.name)
resource = ''
- if frm_iq:
+ if id in self.groupchat_jids:
+ who = self.groupchat_jids[id]
+ frm, resource = gajim.get_room_and_nick_from_fjid(who)
+ del self.groupchat_jids[id]
+ elif frm_iq:
who = helpers.get_full_jid_from_iq(vc)
frm, resource = gajim.get_room_and_nick_from_fjid(who)
else:
@@ -1126,6 +1138,7 @@
p = self.add_sha(p)
self.connection.send(p)
else:
+ #('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
self.dispatch('VCARD', vcard)
class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub):
@@ -1654,7 +1667,8 @@
if not ptype or ptype == 'unavailable':
if gajim.config.get('log_contact_status_changes') and self.name\
not in no_log_for and jid_stripped not in no_log_for:
- gc_c = gajim.contacts.get_gc_contact(self.name, jid_stripped, resource)
+ gc_c = gajim.contacts.get_gc_contact(self.name, jid_stripped,
+ resource)
st = status or ''
if gc_c:
jid = gc_c.jid
@@ -1672,28 +1686,12 @@
# contact has no avatar
puny_nick = helpers.sanitize_filename(resource)
gajim.interface.remove_avatar_files(jid_stripped, puny_nick)
- if self.vcard_shas.has_key(who): # Verify sha cached in mem
- if avatar_sha != self.vcard_shas[who]:
- # avatar has been updated
- self.request_vcard(who, True)
- else: # Verify sha cached in hdd
- cached_vcard = self.get_cached_vcard(who, True)
- if cached_vcard and cached_vcard.has_key('PHOTO') and \
- cached_vcard['PHOTO'].has_key('SHA'):
- cached_sha = cached_vcard['PHOTO']['SHA']
- else:
- cached_sha = ''
- if cached_sha != avatar_sha:
- # avatar has been updated
- # sha in mem will be updated later
- self.request_vcard(who, True)
- else:
- # save sha in mem NOW
- self.vcard_shas[who] = avatar_sha
+ # if it's a gc presence, don't ask vcard here. We may ask it to
+ # real jid in gui part.
self.dispatch('GC_NOTIFY', (jid_stripped, show, status, resource,
prs.getRole(), prs.getAffiliation(), prs.getJid(),
prs.getReason(), prs.getActor(), prs.getStatusCode(),
- prs.getNewNick()))
+ prs.getNewNick(), avatar_sha))
return
if ptype == 'subscribe':
Modified: branches/gajim_0.11.1/src/gajim.py
===================================================================
--- branches/gajim_0.11.1/src/gajim.py 2007-09-04 17:45:42 UTC (rev 8708)
+++ branches/gajim_0.11.1/src/gajim.py 2007-09-04 18:32:31 UTC (rev 8709)
@@ -758,8 +758,7 @@
show = 'offline'
gc_c = gajim.contacts.create_gc_contact(room_jid = jid,
name = nick, show = show)
- c = gajim.contacts.contact_from_gc_contact(gc_c)
- self.roster.new_chat(c, account, private_chat = True)
+ self.roster.new_private_chat(gc_c, account)
ctrl = self.msg_win_mgr.get_control(full_jid_with_resource, account)
ctrl.print_conversation('Error %s: %s' % (array[1], array[2]),
'status')
@@ -1000,7 +999,7 @@
def handle_event_gc_notify(self, account, array):
#'GC_NOTIFY' (account, (room_jid, show, status, nick,
- # role, affiliation, jid, reason, actor, statusCode, newNick))
+ # role, affiliation, jid, reason, actor, statusCode, newNick, avatar_sha))
nick = array[3]
if not nick:
return
@@ -1016,7 +1015,7 @@
return
if control:
control.chg_contact_status(nick, show, status, array[4], array[5],
- array[6], array[7], array[8], array[9], array[10])
+ array[6], array[7], array[8], array[9], array[10], array[11])
# print status in chat window and update status/GPG image
if self.msg_win_mgr.has_window(fjid, account):
Modified: branches/gajim_0.11.1/src/groupchat_control.py
===================================================================
--- branches/gajim_0.11.1/src/groupchat_control.py 2007-09-04 17:45:42 UTC (rev 8708)
+++ branches/gajim_0.11.1/src/groupchat_control.py 2007-09-04 18:32:31 UTC (rev 8709)
@@ -103,10 +103,11 @@
class PrivateChatControl(ChatControl):
TYPE_ID = message_control.TYPE_PM
- def __init__(self, parent_win, contact, acct):
+ def __init__(self, parent_win, gc_contact, contact, acct):
room_jid = contact.jid.split('/')[0]
room_ctrl = gajim.interface.msg_win_mgr.get_control(room_jid, acct)
self.room_name = room_ctrl.name
+ self.gc_contact = gc_contact
ChatControl.__init__(self, parent_win, contact, acct)
self.TYPE_ID = 'pm'
@@ -825,7 +826,7 @@
model[iter][C_AVATAR] = scaled_pixbuf
def chg_contact_status(self, nick, show, status, role, affiliation, jid,
- reason, actor, statusCode, new_nick):
+ reason, actor, statusCode, new_nick, avatar_sha, tim = None):
'''When an occupant changes his or her status'''
if show == 'invisible':
return
@@ -834,7 +835,7 @@
role = 'visitor'
if not affiliation:
affiliation = 'none'
-
+ fake_jid = self.room_jid + '/' + nick
newly_created = False
if show in ('offline', 'error'):
if statusCode == '307':
@@ -895,8 +896,7 @@
os.rename(old_file, files[old_file])
self.print_conversation(s, 'info')
- if len(gajim.events.get_events(self.account,
- self.room_jid + '/' + nick)) == 0:
+ if len(gajim.events.get_events(self.account, fake_jid)) == 0:
self.remove_contact(nick)
else:
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
@@ -954,14 +954,12 @@
self.add_contact_to_roster(nick, show, role,
affiliation, status, jid)
else:
- c = gajim.contacts.get_gc_contact(self.account, self.room_jid,
- nick)
- if c.show == show and c.status == status and \
- c.affiliation == affiliation: #no change
+ if gc_c.show == show and gc_c.status == status and \
+ gc_c.affiliation == affiliation: # no change
return
- c.show = show
- c.affiliation = affiliation
- c.status = status
+ gc_c.show = show
+ gc_c.affiliation = affiliation
+ gc_c.status = status
self.draw_contact(nick)
self.parent_win.redraw_tab(self)
@@ -1028,10 +1026,16 @@
server = gajim.get_server_from_jid(self.room_jid)
if gajim.config.get('ask_avatars_on_startup') and \
not server.startswith('irc'):
- fjid = self.room_jid + '/' + nick
- pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fjid, True)
+ fake_jid = self.room_jid + '/' + nick
+ pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid, True)
if pixbuf == 'ask':
- gajim.connections[self.account].request_vcard(fjid, True)
+ if j:
+ fjid = j
+ if resource:
+ fjid += '/' + resource
+ gajim.connections[self.account].request_vcard(fjid, fake_jid)
+ else:
+ gajim.connections[self.account].request_vcard(fake_jid, fake_jid)
if nick == self.nick: # we became online
self.got_connected()
self.list_treeview.expand_row((model.get_path(role_iter)), False)
@@ -1747,12 +1751,11 @@
def _start_private_message(self, nick):
gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
- c = gajim.contacts.contact_from_gc_contact(gc_c)
- nick_jid = c.jid
+ nick_jid = gc_c.get_full_jid()
win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account)
if not win:
- gajim.interface.roster.new_chat(c, self.account, private_chat = True)
+ gajim.interface.roster.new_private_chat(gc_c, self.account)
win = gajim.interface.msg_win_mgr.get_window(nick_jid, self.account)
win.set_active_tab(nick_jid, self.account)
win.window.present()
Modified: branches/gajim_0.11.1/src/roster_window.py
===================================================================
--- branches/gajim_0.11.1/src/roster_window.py 2007-09-04 17:45:42 UTC (rev 8708)
+++ branches/gajim_0.11.1/src/roster_window.py 2007-09-04 18:32:31 UTC (rev 8709)
@@ -3055,12 +3055,23 @@
self.actions_menu_needs_rebuild = True
self.update_status_combobox()
- def new_chat(self, contact, account, private_chat = False, resource = None):
+ def new_private_chat(self, gc_contact, account):
+ contact = gajim.contacts.contact_from_gc_contact(gc_contact)
+ type_ = message_control.TYPE_PM
+ fjid = gc_contact.room_jid + '/' + gc_contact.name
+ mw = gajim.interface.msg_win_mgr.get_window(fjid, account)
+ if not mw:
+ mw = gajim.interface.msg_win_mgr.create_window(contact, account, type_)
+
+ chat_control = PrivateChatControl(mw, gc_contact, contact, account)
+ mw.new_tab(chat_control)
+ if len(gajim.events.get_events(account, fjid)):
+ # We call this here to avoid race conditions with widget validation
+ chat_control.read_queue()
+
+ def new_chat(self, contact, account, resource = None):
# Get target window, create a control, and associate it with the window
- if not private_chat:
- type_ = message_control.TYPE_CHAT
- else:
- type_ = message_control.TYPE_PM
+ type_ = message_control.TYPE_CHAT
fjid = contact.jid
if resource:
@@ -3069,10 +3080,7 @@
if not mw:
mw = gajim.interface.msg_win_mgr.create_window(contact, account, type_)
- if not private_chat:
- chat_control = ChatControl(mw, contact, account, resource)
- else:
- chat_control = PrivateChatControl(mw, contact, account)
+ chat_control = ChatControl(mw, contact, account, resource)
mw.new_tab(chat_control)
Modified: branches/gajim_0.11.1/src/vcard.py
===================================================================
--- branches/gajim_0.11.1/src/vcard.py 2007-09-04 17:45:42 UTC (rev 8708)
+++ branches/gajim_0.11.1/src/vcard.py 2007-09-04 18:32:31 UTC (rev 8709)
@@ -358,8 +358,11 @@
self.fill_status_label()
- gajim.connections[self.account].request_vcard(self.contact.jid,
- self.gc_contact is not None)
+ if self.gc_contact:
+ gajim.connections[self.account].request_vcard(self.contact.jid,
+ self.gc_contact.get_full_jid())
+ else:
+ gajim.connections[self.account].request_vcard(self.contact.jid)
def on_close_button_clicked(self, widget):
self.window.destroy()