room_contacts vcards are now saved in room_jid folder. Fixes #1105
This commit is contained in:
parent
9d045fc69b
commit
3355cf4ea3
4 changed files with 82 additions and 54 deletions
|
@ -1309,13 +1309,16 @@ class ChatControl(ChatControlBase):
|
||||||
# we assume contact has no avatar
|
# we assume contact has no avatar
|
||||||
scaled_pixbuf = None
|
scaled_pixbuf = None
|
||||||
|
|
||||||
real_jid = gajim.get_real_jid_from_fjid(self.account, jid)
|
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
if real_jid:
|
is_fake = False
|
||||||
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(real_jid)
|
if gajim.contacts.is_pm_from_jid(self.account, jid):
|
||||||
if not real_jid or pixbuf == 'ask':
|
is_fake = True
|
||||||
# we don't have the vcard or it's pm and we don't have the real jid
|
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid_with_resource,
|
||||||
gajim.connections[self.account].request_vcard(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)
|
||||||
return
|
return
|
||||||
if pixbuf is not None:
|
if pixbuf is not None:
|
||||||
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'chat')
|
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'chat')
|
||||||
|
|
|
@ -205,6 +205,7 @@ class Connection:
|
||||||
self.on_connect_success = None
|
self.on_connect_success = None
|
||||||
self.retrycount = 0
|
self.retrycount = 0
|
||||||
self.jids_for_auto_auth = [] # list of jid to auto-authorize
|
self.jids_for_auto_auth = [] # list of jid to auto-authorize
|
||||||
|
self.room_jids = [] # list of gc jids so that vcard are saved in a folder
|
||||||
# END __init__
|
# END __init__
|
||||||
|
|
||||||
def get_full_jid(self, iq_obj):
|
def get_full_jid(self, iq_obj):
|
||||||
|
@ -269,6 +270,23 @@ class Connection:
|
||||||
dict[name][c.getName()] = c.getData()
|
dict[name][c.getName()] = c.getData()
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
|
def save_vcard_to_hd(self, full_jid, card):
|
||||||
|
jid, nick = gajim.get_room_and_nick_from_fjid(full_jid)
|
||||||
|
path = os.path.join(gajim.VCARD_PATH, jid)
|
||||||
|
if jid in self.room_jids:
|
||||||
|
# remove room_jid file if needed
|
||||||
|
if os.path.isfile(path):
|
||||||
|
os.remove(path)
|
||||||
|
# create folder if needed
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
os.mkdir(path, 0700)
|
||||||
|
path_to_file = os.path.join(gajim.VCARD_PATH, jid, nick)
|
||||||
|
else:
|
||||||
|
path_to_file = path
|
||||||
|
fil = open(path_to_file, 'w')
|
||||||
|
fil.write(str(card))
|
||||||
|
fil.close()
|
||||||
|
|
||||||
def _vCardCB(self, con, vc):
|
def _vCardCB(self, con, vc):
|
||||||
'''Called when we receive a vCard
|
'''Called when we receive a vCard
|
||||||
Parse the vCard and send it to plugins'''
|
Parse the vCard and send it to plugins'''
|
||||||
|
@ -281,7 +299,7 @@ class Connection:
|
||||||
who = self.get_full_jid(vc)
|
who = self.get_full_jid(vc)
|
||||||
frm, resource = gajim.get_room_and_nick_from_fjid(who)
|
frm, resource = gajim.get_room_and_nick_from_fjid(who)
|
||||||
else:
|
else:
|
||||||
frm = our_jid
|
who = frm = our_jid
|
||||||
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
|
if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD:
|
||||||
card = vc.getChildren()[0]
|
card = vc.getChildren()[0]
|
||||||
vcard = self.node_to_dict(card)
|
vcard = self.node_to_dict(card)
|
||||||
|
@ -301,10 +319,7 @@ class Connection:
|
||||||
card.getTag('PHOTO').setTagData('SHA', avatar_sha)
|
card.getTag('PHOTO').setTagData('SHA', avatar_sha)
|
||||||
|
|
||||||
# Save it to file
|
# Save it to file
|
||||||
path_to_file = os.path.join(gajim.VCARD_PATH, frm)
|
self.save_vcard_to_hd(who, card)
|
||||||
fil = open(path_to_file, 'w')
|
|
||||||
fil.write(str(card))
|
|
||||||
fil.close()
|
|
||||||
# Save the decoded avatar to a separate file too, and generate files for dbus notifications
|
# Save the decoded avatar to a separate file too, and generate files for dbus notifications
|
||||||
if photo_decoded:
|
if photo_decoded:
|
||||||
avatar_file = os.path.join(gajim.AVATAR_PATH, frm + '_notif_size_colored.png')
|
avatar_file = os.path.join(gajim.AVATAR_PATH, frm + '_notif_size_colored.png')
|
||||||
|
@ -1613,10 +1628,7 @@ class Connection:
|
||||||
|
|
||||||
# Save it to file
|
# Save it to file
|
||||||
our_jid = gajim.get_jid_from_account(self.name)
|
our_jid = gajim.get_jid_from_account(self.name)
|
||||||
path_to_file = os.path.join(gajim.VCARD_PATH, our_jid)
|
self.save_vcard_to_hd(our_jid, vcard_iq)
|
||||||
fil = open(path_to_file, 'w')
|
|
||||||
fil.write(str(vcard_iq))
|
|
||||||
fil.close()
|
|
||||||
|
|
||||||
# Send new presence if sha changed and we are not invisible
|
# Send new presence if sha changed and we are not invisible
|
||||||
if self.vcard_sha != new_sha and STATUS_LIST[self.connected] != \
|
if self.vcard_sha != new_sha and STATUS_LIST[self.connected] != \
|
||||||
|
@ -1638,12 +1650,9 @@ class Connection:
|
||||||
jid = self.awaiting_answers[id][1]
|
jid = self.awaiting_answers[id][1]
|
||||||
our_jid = gajim.get_jid_from_account(self.name)
|
our_jid = gajim.get_jid_from_account(self.name)
|
||||||
if jid and jid != our_jid:
|
if jid and jid != our_jid:
|
||||||
self.dispatch('VCARD', {'jid': jid})
|
|
||||||
jid = gajim.get_jid_without_resource(jid)
|
|
||||||
# Write an empty file
|
# Write an empty file
|
||||||
path_to_file = os.path.join(gajim.VCARD_PATH, jid)
|
self.save_vcard_to_hd(jid, '')
|
||||||
fil = open(path_to_file, 'w')
|
self.dispatch('VCARD', {'jid': jid})
|
||||||
fil.close()
|
|
||||||
elif jid == our_jid:
|
elif jid == our_jid:
|
||||||
self.dispatch('MYVCARD', {'jid': jid})
|
self.dispatch('MYVCARD', {'jid': jid})
|
||||||
del self.awaiting_answers[id]
|
del self.awaiting_answers[id]
|
||||||
|
@ -2342,35 +2351,39 @@ class Connection:
|
||||||
common.xmpp.NS_VERSION)
|
common.xmpp.NS_VERSION)
|
||||||
self.connection.send(iq)
|
self.connection.send(iq)
|
||||||
|
|
||||||
def get_cached_vcard(self, fjid):
|
def get_cached_vcard(self, fjid, is_fake_jid = False):
|
||||||
'''return the vcard as a dict
|
'''return the vcard as a dict
|
||||||
return {} if vcard was too old
|
return {} if vcard was too old
|
||||||
return None if we don't have cached vcard'''
|
return None if we don't have cached vcard'''
|
||||||
jid = gajim.get_jid_without_resource(fjid)
|
jid, nick = gajim.get_room_and_nick_from_fjid(fjid)
|
||||||
path_to_file = os.path.join(gajim.VCARD_PATH, jid)
|
if is_fake_jid:
|
||||||
if os.path.isfile(path_to_file):
|
path_to_file = os.path.join(gajim.VCARD_PATH, jid, nick)
|
||||||
# We have the vcard cached
|
else:
|
||||||
f = open(path_to_file)
|
path_to_file = os.path.join(gajim.VCARD_PATH, jid)
|
||||||
c = f.read()
|
if not os.path.isfile(path_to_file):
|
||||||
f.close()
|
return None
|
||||||
card = common.xmpp.Node(node = c)
|
# We have the vcard cached
|
||||||
vcard = self.node_to_dict(card)
|
f = open(path_to_file)
|
||||||
if vcard.has_key('PHOTO'):
|
c = f.read()
|
||||||
if not isinstance(vcard['PHOTO'], dict):
|
f.close()
|
||||||
del vcard['PHOTO']
|
card = common.xmpp.Node(node = c)
|
||||||
elif vcard['PHOTO'].has_key('SHA'):
|
vcard = self.node_to_dict(card)
|
||||||
cached_sha = vcard['PHOTO']['SHA']
|
if vcard.has_key('PHOTO'):
|
||||||
if self.vcard_shas.has_key(jid) and self.vcard_shas[jid] != \
|
if not isinstance(vcard['PHOTO'], dict):
|
||||||
cached_sha:
|
del vcard['PHOTO']
|
||||||
# user change his vcard so don't use the cached one
|
elif vcard['PHOTO'].has_key('SHA'):
|
||||||
return {}
|
cached_sha = vcard['PHOTO']['SHA']
|
||||||
vcard['jid'] = jid
|
if self.vcard_shas.has_key(jid) and self.vcard_shas[jid] != \
|
||||||
vcard['resource'] = gajim.get_resource_from_jid(fjid)
|
cached_sha:
|
||||||
return vcard
|
# user change his vcard so don't use the cached one
|
||||||
return None
|
return {}
|
||||||
|
vcard['jid'] = jid
|
||||||
|
vcard['resource'] = gajim.get_resource_from_jid(fjid)
|
||||||
|
return vcard
|
||||||
|
|
||||||
def request_vcard(self, jid = None):
|
def request_vcard(self, jid = None, is_fake_jid = False):
|
||||||
'''request the VCARD'''
|
'''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'''
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
iq = common.xmpp.Iq(typ = 'get')
|
iq = common.xmpp.Iq(typ = 'get')
|
||||||
|
@ -2381,10 +2394,14 @@ class Connection:
|
||||||
id = self.connection.getAnID()
|
id = self.connection.getAnID()
|
||||||
iq.setID(id)
|
iq.setID(id)
|
||||||
self.awaiting_answers[id] = (VCARD_ARRIVED, jid)
|
self.awaiting_answers[id] = (VCARD_ARRIVED, jid)
|
||||||
|
if is_fake_jid:
|
||||||
|
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
|
||||||
|
if not room_jid in self.room_jids:
|
||||||
|
self.room_jids.append(room_jid)
|
||||||
self.connection.send(iq)
|
self.connection.send(iq)
|
||||||
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
||||||
|
|
||||||
def send_vcard(self, vcard):
|
def send_vcard(self, vcard, is_fake_jid):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
iq = common.xmpp.Iq(typ = 'set')
|
iq = common.xmpp.Iq(typ = 'set')
|
||||||
|
|
10
src/gajim.py
10
src/gajim.py
|
@ -752,12 +752,14 @@ class Interface:
|
||||||
# show avatar in chat
|
# show avatar in chat
|
||||||
win = None
|
win = None
|
||||||
ctrl = None
|
ctrl = None
|
||||||
if gajim.interface.msg_win_mgr.has_window(jid, account):
|
if resource and gajim.interface.msg_win_mgr.has_window(
|
||||||
|
jid + '/' + resource, account):
|
||||||
|
win = gajim.interface.msg_win_mgr.get_window(jid + '/' + resource,
|
||||||
|
account)
|
||||||
|
ctrl = win.get_control(jid + '/' + resource, account)
|
||||||
|
elif gajim.interface.msg_win_mgr.has_window(jid, account):
|
||||||
win = gajim.interface.msg_win_mgr.get_window(jid, account)
|
win = gajim.interface.msg_win_mgr.get_window(jid, account)
|
||||||
ctrl = win.get_control(jid, account)
|
ctrl = win.get_control(jid, account)
|
||||||
elif resource and gajim.interface.msg_win_mgr.has_window(jid + '/' + resource, account):
|
|
||||||
win = gajim.interface.msg_win_mgr.get_window(jid + '/' + resource, account)
|
|
||||||
ctrl = win.get_control(jid + '/' + resource, account)
|
|
||||||
if win and ctrl.type_id != message_control.TYPE_GC:
|
if win and ctrl.type_id != message_control.TYPE_GC:
|
||||||
ctrl.show_avatar()
|
ctrl.show_avatar()
|
||||||
|
|
||||||
|
|
|
@ -430,22 +430,28 @@ def get_scaled_pixbuf(pixbuf, kind):
|
||||||
scaled_buf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_HYPER)
|
scaled_buf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_HYPER)
|
||||||
return scaled_buf
|
return scaled_buf
|
||||||
|
|
||||||
def get_avatar_pixbuf_from_cache(jid):
|
def get_avatar_pixbuf_from_cache(fjid, is_fake_jid = False):
|
||||||
'''checks if jid has cached avatar and if that avatar is valid image
|
'''checks if jid has cached avatar and if that avatar is valid image
|
||||||
(can be shown)
|
(can be shown)
|
||||||
returns None if there is no image in vcard
|
returns None if there is no image in vcard
|
||||||
returns 'ask' if cached vcard should not be used (user changed his vcard,
|
returns 'ask' if cached vcard should not be used (user changed his vcard,
|
||||||
so we have new sha) or if we don't have the vcard'''
|
so we have new sha) or if we don't have the vcard'''
|
||||||
|
|
||||||
|
jid, nick = gajim.get_room_and_nick_from_fjid(fjid)
|
||||||
if gajim.config.get('hide_avatar_of_transport') and\
|
if gajim.config.get('hide_avatar_of_transport') and\
|
||||||
gajim.jid_is_transport(jid):
|
gajim.jid_is_transport(jid):
|
||||||
# don't show avatar for the transport itself
|
# don't show avatar for the transport itself
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if jid not in os.listdir(gajim.VCARD_PATH):
|
if is_fake_jid:
|
||||||
|
path = os.path.join(gajim.VCARD_PATH, jid, nick)
|
||||||
|
else:
|
||||||
|
path = os.path.join(gajim.VCARD_PATH, jid)
|
||||||
|
if not os.path.isfile(path):
|
||||||
return 'ask'
|
return 'ask'
|
||||||
|
|
||||||
vcard_dict = gajim.connections.values()[0].get_cached_vcard(jid)
|
vcard_dict = gajim.connections.values()[0].get_cached_vcard(fjid,
|
||||||
|
is_fake_jid)
|
||||||
if not vcard_dict: # This can happen if cached vcard is too old
|
if not vcard_dict: # This can happen if cached vcard is too old
|
||||||
return 'ask'
|
return 'ask'
|
||||||
if not vcard_dict.has_key('PHOTO'):
|
if not vcard_dict.has_key('PHOTO'):
|
||||||
|
|
Loading…
Add table
Reference in a new issue