diff plugins/plugin_xep_0054.py @ 43:8a438a6ff587

Wix: added avatar in profile - plugin XEP-0054: added getProfileFile bridge method
author Goffi <goffi@goffi.org>
date Mon, 21 Dec 2009 15:11:50 +1100
parents 874de3020e1c
children bfa7086d26d6
line wrap: on
line diff
--- a/plugins/plugin_xep_0054.py	Mon Dec 21 13:22:11 2009 +1100
+++ b/plugins/plugin_xep_0054.py	Mon Dec 21 15:11:50 2009 +1100
@@ -61,6 +61,7 @@
         if not os.path.exists(self.avatar_path):
             os.makedirs(self.avatar_path)
         host.bridge.addMethod("getProfile", ".communication", in_sign='s', out_sign='s', method=self.getProfile)
+        host.bridge.addMethod("getAvatarFile", ".communication", in_sign='s', out_sign='s', method=self.getAvatarFile)
     
     def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
         return [disco.DiscoFeature(NS_VCARD)]
@@ -110,7 +111,7 @@
                 d2 = defer.waitForDeferred(
                             threads.deferToThread(self.save_photo, elem))
                 yield d2
-                dictionary["photo"] = d2.getResult()
+                dictionary["avatar"] = d2.getResult()
             else:
                 info ('FIXME: [%s] VCard tag is not managed yet' % elem.name)
 
@@ -145,3 +146,14 @@
         reg_request.send(to_jid.full()).addCallbacks(self.vcard_ok, self.vcard_err)
         return reg_request["id"] 
 
+    def getAvatarFile(self, hash):
+        """Give the full path of avatar from hash
+        @param hash: SHA1 hash
+        @return full_path
+        """
+        filename = self.avatar_path+'/'+hash
+        if not os.path.exists(filename):
+            error ("Asking for an uncached avatar [%s]" %  hash)
+            return ""
+        return filename
+