core: plugins refactored according to bridge + updatedValue now use profile

This commit is contained in:
Goffi 2011-07-06 01:06:18 +02:00
commit ad29111416

View file

@ -71,17 +71,21 @@ class XEP_0054():
self.vcard_cache = host.memory.getPrivate("vcard_cache") or {} #used to store nicknames and avatar, key = jid
if not os.path.exists(self.avatar_path):
os.makedirs(self.avatar_path)
host.bridge.addMethod("getCard", ".communication", in_sign='ss', out_sign='s', method=self.getCard)
host.bridge.addMethod("getAvatarFile", ".communication", in_sign='s', out_sign='s', method=self.getAvatarFile)
host.bridge.addMethod("getCardCache", ".communication", in_sign='s', out_sign='a{ss}', method=self.getCardCache)
host.bridge.addMethod("getCard", ".plugin", in_sign='ss', out_sign='s', method=self.getCard)
host.bridge.addMethod("getAvatarFile", ".plugin", in_sign='s', out_sign='s', method=self.getAvatarFile)
host.bridge.addMethod("getCardCache", ".plugin", in_sign='s', out_sign='a{ss}', method=self.getCardCache)
def getHandler(self, profile):
return XEP_0054_handler(self)
def update_cache(self, jid, name, value):
def update_cache(self, jid, name, value, profile):
"""update cache value
- save value in memory in case of change
- send updatedValue signal if the value is new or updated
@param jid: jid of the owner of the vcard
@param name: name of the item which changed
@param value: new value of the item
@param profile: profile which received the update
"""
if not self.vcard_cache.has_key(jid.userhost()):
self.vcard_cache[jid.userhost()] = {}
@ -91,7 +95,7 @@ class XEP_0054():
if not old_value or value != old_value:
cache[name] = value
self.host.memory.setPrivate("vcard_cache", self.vcard_cache)
self.host.bridge.updatedValue('card_'+name, {'jid':jid.userhost(), name:value})
self.host.bridge.updatedValue('card_'+name, {'jid':jid.userhost(), name:value}, profile)
def get_cache(self, jid, name):
"""return cached value for jid
@ -123,7 +127,7 @@ class XEP_0054():
return hash
@defer.deferredGenerator
def vCard2Dict(self, vcard, target):
def vCard2Dict(self, vcard, target, profile):
"""Convert a VCard to a dict, and save binaries"""
debug (_("parsing vcard"))
dictionary = {}
@ -134,7 +138,7 @@ class XEP_0054():
dictionary['fullname'] = unicode(elem)
elif elem.name == 'NICKNAME':
dictionary['nick'] = unicode(elem)
self.update_cache(target, 'nick', dictionary['nick'])
self.update_cache(target, 'nick', dictionary['nick'], profile)
elif elem.name == 'URL':
dictionary['website'] = unicode(elem)
elif elem.name == 'EMAIL':
@ -149,18 +153,18 @@ class XEP_0054():
if not dictionary["avatar"]: #can happen in case of e.g. empty photo elem
del dictionary['avatar']
else:
self.update_cache(target, 'avatar', dictionary['avatar'])
self.update_cache(target, 'avatar', dictionary['avatar'], profile)
else:
info (_('FIXME: [%s] VCard tag is not managed yet') % elem.name)
yield dictionary
def vcard_ok(self, answer):
def vcard_ok(self, answer, profile):
"""Called after the first get IQ"""
debug (_("VCard found"))
if answer.firstChildElement().name == "vCard":
d = self.vCard2Dict(answer.firstChildElement(), jid.JID(answer["from"]))
d = self.vCard2Dict(answer.firstChildElement(), jid.JID(answer["from"]), profile)
d.addCallback(lambda data: self.host.bridge.actionResult("RESULT", answer['id'], data))
else:
error (_("FIXME: vCard not found as first child element"))
@ -179,13 +183,14 @@ class XEP_0054():
if not xmlstream:
error (_('Asking vcard for an non-existant or not connected profile'))
return ""
profile = self.host.memory.getProfileName(profile_key)
to_jid = jid.JID(target)
debug(_("Asking for %s's VCard") % to_jid.userhost())
reg_request=IQ(xmlstream,'get')
reg_request["from"]=current_jid.full()
reg_request["to"] = to_jid.userhost()
query=reg_request.addElement('vCard', NS_VCARD)
reg_request.send(to_jid.userhost()).addCallbacks(self.vcard_ok, self.vcard_err)
reg_request.send(to_jid.userhost()).addCallbacks(self.vcard_ok, self.vcard_err, [profile])
return reg_request["id"]
def getAvatarFile(self, hash):