Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0054.py @ 1710:7226280e70da
plugin XEP-0054: use full jid to manage the card/avatar if the bare jid correspond to a MUC room
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 01 Dec 2015 17:17:09 +0100 |
parents | 9bf1262297f2 |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1709:c47ba491a85a | 1710:7226280e70da |
---|---|
65 "name": "XEP 0054 Plugin", | 65 "name": "XEP 0054 Plugin", |
66 "import_name": "XEP-0054", | 66 "import_name": "XEP-0054", |
67 "type": "XEP", | 67 "type": "XEP", |
68 "protocols": ["XEP-0054", "XEP-0153"], | 68 "protocols": ["XEP-0054", "XEP-0153"], |
69 "dependencies": [], | 69 "dependencies": [], |
70 "recommendations": ["XEP-0045"], | |
70 "main": "XEP_0054", | 71 "main": "XEP_0054", |
71 "handler": "yes", | 72 "handler": "yes", |
72 "description": _("""Implementation of vcard-temp""") | 73 "description": _("""Implementation of vcard-temp""") |
73 } | 74 } |
74 | 75 |
106 x_elt.addElement('photo', content=avatar_hash) | 107 x_elt.addElement('photo', content=avatar_hash) |
107 presence_elt.addChild(x_elt) | 108 presence_elt.addChild(x_elt) |
108 | 109 |
109 return True | 110 return True |
110 | 111 |
112 def isInRoom(self, entity_jid, profile): | |
113 """Tell if an full jid is a member of a room | |
114 | |
115 @param entity_jid(jid.JID): full jid of the entity | |
116 @return (bool): True if the bare jid of the entity is a room jid | |
117 """ | |
118 try: | |
119 return self.host.plugins['XEP-0045'].isRoom(entity_jid.userhostJID(), profile_key=profile) | |
120 except KeyError: | |
121 return False | |
122 | |
111 def _fillCachedValues(self, profile): | 123 def _fillCachedValues(self, profile): |
112 #FIXME: this is really suboptimal, need to be reworked | 124 #FIXME: this is really suboptimal, need to be reworked |
113 # the current naive approach keeps a map between all jids of all profiles | 125 # the current naive approach keeps a map between all jids of all profiles |
114 # in persistent cache, then put avatar hashs in memory. | 126 # in persistent cache, then put avatar hashs in memory. |
115 # Hashes should be shared between profiles | 127 # Hashes should be shared between profiles |
138 @param jid_(jid.JID): jid of the owner of the vcard | 150 @param jid_(jid.JID): jid of the owner of the vcard |
139 @param name(str): name of the item which changed | 151 @param name(str): name of the item which changed |
140 @param value(unicode): new value of the item | 152 @param value(unicode): new value of the item |
141 @param profile(unicode): profile which received the update | 153 @param profile(unicode): profile which received the update |
142 """ | 154 """ |
143 assert not jid_.resource # VCard are retrieved with bare jid | 155 if jid_.resource: |
156 if not self.isInRoom(jid_, profile): | |
157 # VCard are retrieved with bare jid | |
158 # but MUC room is a special case | |
159 jid_ = jid.userhostJID() | |
160 | |
144 self.host.memory.updateEntityData(jid_, name, value, profile_key=profile) | 161 self.host.memory.updateEntityData(jid_, name, value, profile_key=profile) |
145 if name in CACHED_DATA: | 162 if name in CACHED_DATA: |
146 jid_s = jid_.userhost() | 163 jid_s = jid_.userhost() |
147 self.cache[profile].setdefault(jid_s, {})[name] = value | 164 self.cache[profile].setdefault(jid_s, {})[name] = value |
148 self.cache[profile].force(jid_s) | 165 self.cache[profile].force(jid_s) |
152 | 169 |
153 @param entity_jid: target contact | 170 @param entity_jid: target contact |
154 @param name: name of the value ('nick' or 'avatar') | 171 @param name: name of the value ('nick' or 'avatar') |
155 @param profile: %(doc_profile)s | 172 @param profile: %(doc_profile)s |
156 @return: wanted value or None""" | 173 @return: wanted value or None""" |
157 assert not entity_jid.resource # VCard are retrieved with bare jid | 174 if entity_jid.resource: |
175 if not self.isInRoom(entity_jid, profile): | |
176 # VCard are retrieved with bare jid | |
177 # but MUC room is a special case | |
178 entity_jid = jid.userhostJID() | |
158 try: | 179 try: |
159 data = self.host.memory.getEntityData(entity_jid, [name], profile) | 180 data = self.host.memory.getEntityData(entity_jid, [name], profile) |
160 except exceptions.UnknownEntityError: | 181 except exceptions.UnknownEntityError: |
161 return None | 182 return None |
162 return data.get(name) | 183 return data.get(name) |
361 """Called on <presence/> stanza with vcard data | 382 """Called on <presence/> stanza with vcard data |
362 | 383 |
363 Check for avatar information, and get VCard if needed | 384 Check for avatar information, and get VCard if needed |
364 @param presend(domish.Element): <presence/> stanza | 385 @param presend(domish.Element): <presence/> stanza |
365 """ | 386 """ |
366 # FIXME: doesn't manage MUC correctly | 387 from_jid = jid.JID(presence['from']) |
367 from_jid = jid.JID(presence['from']).userhostJID() | 388 if from_jid.resource and not self.plugin_parent.isInRoom(from_jid, self.parent.profile): |
389 from_jid = from_jid.userhostJID() | |
368 #FIXME: wokkel's data_form should be used here | 390 #FIXME: wokkel's data_form should be used here |
369 try: | 391 try: |
370 x_elt = presence.elements(NS_VCARD_UPDATE, 'x').next() | 392 x_elt = presence.elements(NS_VCARD_UPDATE, 'x').next() |
371 except StopIteration: | 393 except StopIteration: |
372 return | 394 return |