Fixes for vCard avatar hash calculations and MUC considerations.

This commit is contained in:
Lance Stout 2013-01-24 02:44:27 -08:00
parent 403b1802ec
commit 751628401e

View file

@ -10,12 +10,9 @@ import hashlib
import logging
import threading
from sleekxmpp import JID
from sleekxmpp.stanza import Presence
from sleekxmpp.exceptions import XMPPError
from sleekxmpp.xmlstream import register_stanza_plugin
from sleekxmpp.xmlstream.matcher import StanzaPath
from sleekxmpp.xmlstream.handler import Callback
from sleekxmpp.plugins.base import BasePlugin
from sleekxmpp.plugins.xep_0153 import stanza, VCardTempUpdate
@ -86,11 +83,10 @@ class XEP_0153(BasePlugin):
else:
new_hash = hashlib.sha1(data).hexdigest()
self.api['set_hash'](self.xmpp.boundjid, args=new_hash)
self._allow_advertising.set()
except XMPPError:
log.debug('Could not retrieve vCard for %s' % self.xmpp.boundjid.bare)
self._allow_advertising.set()
def _end(self, event):
self._allow_advertising.clear()
@ -128,6 +124,11 @@ class XEP_0153(BasePlugin):
log.debug('Could not retrieve vCard for %s' % jid)
def _recv_presence(self, pres):
if pres['muc']['affiliation']:
# Don't process vCard avatars for MUC occupants
# since they all share the same bare JID.
return
if not pres.match('presence/vcard_temp_update'):
self.api['set_hash'](pres['from'], args=None)
return
@ -135,7 +136,7 @@ class XEP_0153(BasePlugin):
data = pres['vcard_temp_update']['photo']
if data is None:
return
elif data == '' or data != self.api['get_hash'](pres['to']):
elif data == '' or data != self.api['get_hash'](pres['from']):
ifrom = pres['to'] if self.xmpp.is_component else None
self.api['reset_hash'](pres['from'], ifrom=ifrom)
self.xmpp.event('vcard_avatar_update', pres)