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 logging
import threading import threading
from sleekxmpp import JID
from sleekxmpp.stanza import Presence from sleekxmpp.stanza import Presence
from sleekxmpp.exceptions import XMPPError from sleekxmpp.exceptions import XMPPError
from sleekxmpp.xmlstream import register_stanza_plugin 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.base import BasePlugin
from sleekxmpp.plugins.xep_0153 import stanza, VCardTempUpdate from sleekxmpp.plugins.xep_0153 import stanza, VCardTempUpdate
@ -86,11 +83,10 @@ class XEP_0153(BasePlugin):
else: else:
new_hash = hashlib.sha1(data).hexdigest() new_hash = hashlib.sha1(data).hexdigest()
self.api['set_hash'](self.xmpp.boundjid, args=new_hash) self.api['set_hash'](self.xmpp.boundjid, args=new_hash)
self._allow_advertising.set()
except XMPPError: except XMPPError:
log.debug('Could not retrieve vCard for %s' % self.xmpp.boundjid.bare) log.debug('Could not retrieve vCard for %s' % self.xmpp.boundjid.bare)
self._allow_advertising.set()
def _end(self, event): def _end(self, event):
self._allow_advertising.clear() self._allow_advertising.clear()
@ -128,6 +124,11 @@ class XEP_0153(BasePlugin):
log.debug('Could not retrieve vCard for %s' % jid) log.debug('Could not retrieve vCard for %s' % jid)
def _recv_presence(self, pres): 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'): if not pres.match('presence/vcard_temp_update'):
self.api['set_hash'](pres['from'], args=None) self.api['set_hash'](pres['from'], args=None)
return return
@ -135,7 +136,7 @@ class XEP_0153(BasePlugin):
data = pres['vcard_temp_update']['photo'] data = pres['vcard_temp_update']['photo']
if data is None: if data is None:
return 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 ifrom = pres['to'] if self.xmpp.is_component else None
self.api['reset_hash'](pres['from'], ifrom=ifrom) self.api['reset_hash'](pres['from'], ifrom=ifrom)
self.xmpp.event('vcard_avatar_update', pres) self.xmpp.event('vcard_avatar_update', pres)