Support unpublishing avatars (with XEP-0084)

- Add more logging
This commit is contained in:
Philipp Hörist 2017-11-17 19:19:59 +01:00
parent 9f0154ef84
commit a80f41e2bf
2 changed files with 35 additions and 11 deletions

View File

@ -277,13 +277,17 @@ class ConnectionVcard:
if self.get_own_jid().bareMatch(obj.jid):
app.log('avatar').info('Update (vCard): %s %s',
obj.jid, obj.avatar_sha)
obj.jid, obj.avatar_sha)
current_sha = app.config.get_per(
'accounts', self.name, 'avatar_sha')
if obj.avatar_sha != current_sha:
app.log('avatar').info(
'Request (vCard): %s', obj.jid)
self.request_vcard(self._on_own_avatar_received)
else:
app.log('avatar').info(
'Avatar already known (vCard): %s %s',
obj.jid, obj.avatar_sha)
return
if obj.avatar_sha == '':
@ -305,6 +309,10 @@ class ConnectionVcard:
app.log('avatar').info(
'Request (vCard): %s', obj.jid)
self.request_vcard(self._on_avatar_received, obj.jid)
else:
app.log('avatar').info(
'Avatar already known (vCard): %s %s',
obj.jid, obj.avatar_sha)
def _vcard_gc_presence_received(self, obj):
if obj.conn.name != self.name:
@ -348,6 +356,9 @@ class ConnectionVcard:
obj.nick, obj.avatar_sha)
gc_contact.avatar_sha = obj.avatar_sha
app.interface.update_avatar(contact=gc_contact)
else:
app.log('avatar').info(
'Avatar already known (vCard): %s', obj.nick)
def send_avatar_presence(self):
show = helpers.get_xmpp_show(app.SHOW_LIST[self.connected])

View File

@ -481,23 +481,36 @@ class AvatarNotificationPEP(AbstractPEP):
namespace = 'urn:xmpp:avatar:metadata'
def _extract_info(self, items):
avatar = None
self.avatar = None
for item in items.getTags('item'):
info = item.getTag('metadata').getTag('info')
self.avatar = info.getAttrs()
if info is not None:
self.avatar = info.getAttrs()
break
return (avatar, False)
return (None, False)
def _on_receive(self, jid, account):
sha = app.contacts.get_avatar_sha(account, jid)
app.log('avatar').info(
'Update (Pubsub): %s %s', jid, self.avatar['id'])
if sha == self.avatar['id']:
return
con = app.connections[account]
app.log('avatar').info('Request (Pubsub): %s', jid)
con.send_pb_retrieve(jid, 'urn:xmpp:avatar:data', self.avatar['id'])
if self.avatar is None:
# Remove avatar
app.log('avatar').debug('Remove (Pubsub): %s', jid)
app.contacts.set_avatar(account, jid, None)
own_jid = con.get_own_jid().getStripped()
app.logger.set_avatar_sha(own_jid, jid, None)
app.interface.update_avatar(account, jid)
else:
sha = app.contacts.get_avatar_sha(account, jid)
app.log('avatar').info(
'Update (Pubsub): %s %s', jid, self.avatar['id'])
if sha == self.avatar['id']:
app.log('avatar').info(
'Avatar already known (Pubsub): %s %s',
jid, self.avatar['id'])
return
app.log('avatar').info('Request (Pubsub): %s', jid)
con.send_pb_retrieve(jid, 'urn:xmpp:avatar:data',
self.avatar['id'])
SUPPORTED_PERSONAL_USER_EVENTS = [