plugin XEP-0054: use full jid to manage the card/avatar if the bare jid correspond to a MUC room
This commit is contained in:
parent
2a015e3bec
commit
5f680931df
1 changed files with 26 additions and 4 deletions
|
|
@ -67,6 +67,7 @@ PLUGIN_INFO = {
|
|||
"type": "XEP",
|
||||
"protocols": ["XEP-0054", "XEP-0153"],
|
||||
"dependencies": [],
|
||||
"recommendations": ["XEP-0045"],
|
||||
"main": "XEP_0054",
|
||||
"handler": "yes",
|
||||
"description": _("""Implementation of vcard-temp""")
|
||||
|
|
@ -108,6 +109,17 @@ class XEP_0054(object):
|
|||
|
||||
return True
|
||||
|
||||
def isInRoom(self, entity_jid, profile):
|
||||
"""Tell if an full jid is a member of a room
|
||||
|
||||
@param entity_jid(jid.JID): full jid of the entity
|
||||
@return (bool): True if the bare jid of the entity is a room jid
|
||||
"""
|
||||
try:
|
||||
return self.host.plugins['XEP-0045'].isRoom(entity_jid.userhostJID(), profile_key=profile)
|
||||
except KeyError:
|
||||
return False
|
||||
|
||||
def _fillCachedValues(self, profile):
|
||||
#FIXME: this is really suboptimal, need to be reworked
|
||||
# the current naive approach keeps a map between all jids of all profiles
|
||||
|
|
@ -140,7 +152,12 @@ class XEP_0054(object):
|
|||
@param value(unicode): new value of the item
|
||||
@param profile(unicode): profile which received the update
|
||||
"""
|
||||
assert not jid_.resource # VCard are retrieved with bare jid
|
||||
if jid_.resource:
|
||||
if not self.isInRoom(jid_, profile):
|
||||
# VCard are retrieved with bare jid
|
||||
# but MUC room is a special case
|
||||
jid_ = jid.userhostJID()
|
||||
|
||||
self.host.memory.updateEntityData(jid_, name, value, profile_key=profile)
|
||||
if name in CACHED_DATA:
|
||||
jid_s = jid_.userhost()
|
||||
|
|
@ -154,7 +171,11 @@ class XEP_0054(object):
|
|||
@param name: name of the value ('nick' or 'avatar')
|
||||
@param profile: %(doc_profile)s
|
||||
@return: wanted value or None"""
|
||||
assert not entity_jid.resource # VCard are retrieved with bare jid
|
||||
if entity_jid.resource:
|
||||
if not self.isInRoom(entity_jid, profile):
|
||||
# VCard are retrieved with bare jid
|
||||
# but MUC room is a special case
|
||||
entity_jid = jid.userhostJID()
|
||||
try:
|
||||
data = self.host.memory.getEntityData(entity_jid, [name], profile)
|
||||
except exceptions.UnknownEntityError:
|
||||
|
|
@ -363,8 +384,9 @@ class XEP_0054_handler(XMPPHandler):
|
|||
Check for avatar information, and get VCard if needed
|
||||
@param presend(domish.Element): <presence/> stanza
|
||||
"""
|
||||
# FIXME: doesn't manage MUC correctly
|
||||
from_jid = jid.JID(presence['from']).userhostJID()
|
||||
from_jid = jid.JID(presence['from'])
|
||||
if from_jid.resource and not self.plugin_parent.isInRoom(from_jid, self.parent.profile):
|
||||
from_jid = from_jid.userhostJID()
|
||||
#FIXME: wokkel's data_form should be used here
|
||||
try:
|
||||
x_elt = presence.elements(NS_VCARD_UPDATE, 'x').next()
|
||||
|
|
|
|||
Loading…
Reference in a new issue