comparison src/plugins/plugin_xep_0054.py @ 560:7ffae708b176

plugin XEP-0054: added profile own jid to _fillCachedValues (needed to have its own avatar)
author Goffi <goffi@goffi.org>
date Tue, 18 Dec 2012 00:02:28 +0100
parents dcec4ba8e72c
children 0bb2e0d1c878
comparison
equal deleted inserted replaced
559:bdcd8c6c4ed4 560:7ffae708b176
83 def _fillCachedValues(self, result, client): 83 def _fillCachedValues(self, result, client):
84 #FIXME: this is really suboptimal, need to be reworked 84 #FIXME: this is really suboptimal, need to be reworked
85 # the current naive approach keeps a map between all jids of all profiles 85 # the current naive approach keeps a map between all jids of all profiles
86 # in persistent cache, and check if cached jid are in roster, then put avatar 86 # in persistent cache, and check if cached jid are in roster, then put avatar
87 # hashs in memory. 87 # hashs in memory.
88 for _jid in client.roster.getBareJids(): 88 for _jid in client.roster.getBareJids() + [client.jid.userhost()]:
89 if _jid in self.avatars_cache: 89 if _jid in self.avatars_cache:
90 self.host.memory.updateEntityData(jid.JID(_jid), "avatar", self.avatars_cache[_jid], client.profile) 90 self.host.memory.updateEntityData(jid.JID(_jid), "avatar", self.avatars_cache[_jid], client.profile)
91 91
92 def profileConnected(self, profile): 92 def profileConnected(self, profile):
93 client = self.host.getClient(profile) 93 client = self.host.getClient(profile)
183 def vcard_err(self, failure, profile): 183 def vcard_err(self, failure, profile):
184 """Called when something is wrong with registration""" 184 """Called when something is wrong with registration"""
185 error (_("Can't find VCard of %s") % failure.value.stanza['from']) 185 error (_("Can't find VCard of %s") % failure.value.stanza['from'])
186 self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, profile) #FIXME: maybe an error message would be better 186 self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, profile) #FIXME: maybe an error message would be better
187 187
188 def getCard(self, target, profile_key='@DEFAULT@'): 188 def getCard(self, target_s, profile_key='@DEFAULT@'):
189 """Ask server for VCard 189 """Ask server for VCard
190 @param target: jid from which we want the VCard 190 @param target_s: jid from which we want the VCard
191 @result: id to retrieve the profile""" 191 @result: id to retrieve the profile"""
192 current_jid, xmlstream = self.host.getJidNStream(profile_key) 192 current_jid, xmlstream = self.host.getJidNStream(profile_key)
193 if not xmlstream: 193 if not xmlstream:
194 error (_('Asking vcard for an non-existant or not connected profile')) 194 error (_('Asking vcard for an non-existant or not connected profile'))
195 return "" 195 return ""
196 profile = self.host.memory.getProfileName(profile_key) 196 profile = self.host.memory.getProfileName(profile_key)
197 to_jid = jid.JID(target) 197 to_jid = jid.JID(target_s)
198 debug(_("Asking for %s's VCard") % to_jid.userhost()) 198 debug(_("Asking for %s's VCard") % to_jid.userhost())
199 reg_request=IQ(xmlstream,'get') 199 reg_request=IQ(xmlstream,'get')
200 reg_request["from"]=current_jid.full() 200 reg_request["from"]=current_jid.full()
201 reg_request["to"] = to_jid.userhost() 201 reg_request["to"] = to_jid.userhost()
202 reg_request.addElement('vCard', NS_VCARD) 202 reg_request.addElement('vCard', NS_VCARD)