Skip to content
Snippets Groups Projects
Commit e9db2051 authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

remove avatar files when we publish a vcard without an avatar. see #2718

parent adff0490
No related branches found
No related tags found
No related merge requests found
......@@ -940,15 +940,17 @@ class ConnectionVcard:
iq.setID(id)
self.connection.send(iq)
our_jid = gajim.get_jid_from_account(self.name)
# Add the sha of the avatar
if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \
vcard['PHOTO'].has_key('BINVAL'):
photo = vcard['PHOTO']['BINVAL']
photo_decoded = base64.decodestring(photo)
our_jid = gajim.get_jid_from_account(self.name)
gajim.interface.save_avatar_files(our_jid, photo_decoded)
avatar_sha = sha.sha(photo_decoded).hexdigest()
iq2.getTag('PHOTO').setTagData('SHA', avatar_sha)
else:
gajim.interface.remove_avatar_files(our_jid)
self.awaiting_answers[id] = (VCARD_PUBLISHED, iq2)
......
......@@ -1196,6 +1196,16 @@ class Interface:
path_to_bw_file = path_to_file + '_notif_size_bw.png'
bwbuf.save(path_to_bw_file, 'png')
def remove_avatar_files(self, jid):
'''remove avatar files of a jid'''
puny_jid = helpers.sanitize_filename(jid)
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid)
for ext in ('.jpeg', '.png', '_notif_size_colored.png',
'_notif_size_bw.png'):
path_to_original_file = path_to_file + ext
if os.path.isfile(path_to_original_file):
os.remove(path_to_original_file)
def add_event(self, account, jid, type_, event_args):
'''add an event to the gajim.events var'''
# We add it to the gajim.events queue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment