Group chat avatars fixs :

- Stop saving avatars of participants without their resource.
- Complement of [7927], don't save sha before avatar. Really fix #2956
- Don't save sha if avatar not readable.
This commit is contained in:
Jean-Marie Traissard 2007-02-03 23:56:40 +00:00
parent 736007f704
commit 3f16220afb
1 changed files with 13 additions and 14 deletions

View File

@ -1109,20 +1109,26 @@ class ConnectionVcard:
puny_jid = helpers.sanitize_filename(frm) puny_jid = helpers.sanitize_filename(frm)
puny_nick = None puny_nick = None
begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid) begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid)
frm_jid = frm
if frm in self.room_jids: if frm in self.room_jids:
puny_nick = helpers.sanitize_filename(resource) puny_nick = helpers.sanitize_filename(resource)
# create folder if needed # create folder if needed
if not os.path.isdir(begin_path): if not os.path.isdir(begin_path):
os.mkdir(begin_path, 0700) os.mkdir(begin_path, 0700)
begin_path = os.path.join(begin_path, puny_nick) begin_path = os.path.join(begin_path, puny_nick)
frm_jid += '/' + resource
if photo_decoded: if photo_decoded:
avatar_file = begin_path + '_notif_size_colored.png' avatar_file = begin_path + '_notif_size_colored.png'
if frm == our_jid and avatar_sha != self.vcard_sha: if frm_jid == our_jid and avatar_sha != self.vcard_sha:
gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick)
elif frm != our_jid and (not os.path.exists(avatar_file) or \ elif frm_jid != our_jid and (not os.path.exists(avatar_file) or \
not self.vcard_shas.has_key(frm) or \ not self.vcard_shas.has_key(frm_jid) or \
avatar_sha != self.vcard_shas[frm]): avatar_sha != self.vcard_shas[frm_jid]):
gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick)
if avatar_sha:
self.vcard_shas[frm_jid] = avatar_sha
elif self.vcard_shas.has_key(frm):
del self.vcard_shas[frm]
else: else:
for ext in ('.jpeg', '.png', '_notif_size_bw.png', for ext in ('.jpeg', '.png', '_notif_size_bw.png',
'_notif_size_colored.png'): '_notif_size_colored.png'):
@ -1130,15 +1136,9 @@ class ConnectionVcard:
if os.path.isfile(path): if os.path.isfile(path):
os.remove(path) os.remove(path)
if frm != our_jid:
if avatar_sha:
self.vcard_shas[frm] = avatar_sha
elif self.vcard_shas.has_key(frm):
del self.vcard_shas[frm]
vcard['jid'] = frm vcard['jid'] = frm
vcard['resource'] = resource vcard['resource'] = resource
if frm == our_jid: if frm_jid == our_jid:
self.dispatch('MYVCARD', vcard) self.dispatch('MYVCARD', vcard)
# we re-send our presence with sha if has changed and if we are # we re-send our presence with sha if has changed and if we are
# not invisible # not invisible
@ -1675,16 +1675,15 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
# avatar has been updated # avatar has been updated
self.request_vcard(who, True) self.request_vcard(who, True)
else: # Verify sha cached in hdd else: # Verify sha cached in hdd
self.vcard_shas[who] = avatar_sha
cached_vcard = self.get_cached_vcard(who, True) cached_vcard = self.get_cached_vcard(who, True)
if cached_vcard and cached_vcard.has_key('PHOTO') and \ if cached_vcard and cached_vcard.has_key('PHOTO') and \
cached_vcard['PHOTO'].has_key('SHA'): cached_vcard['PHOTO'].has_key('SHA'):
cached_sha = cached_vcard['PHOTO']['SHA'] cached_sha = cached_vcard['PHOTO']['SHA']
else: else:
cached_sha = '' cached_sha = ''
if cached_sha != self.vcard_shas[who]: if cached_sha != avatar_sha:
# avatar has been updated # avatar has been updated
self.request_vcard(who) self.request_vcard(who, True)
self.dispatch('GC_NOTIFY', (jid_stripped, show, status, resource, self.dispatch('GC_NOTIFY', (jid_stripped, show, status, resource,
prs.getRole(), prs.getAffiliation(), prs.getJid(), prs.getRole(), prs.getAffiliation(), prs.getJid(),
prs.getReason(), prs.getActor(), prs.getStatusCode(), prs.getReason(), prs.getActor(), prs.getStatusCode(),