diff src/plugins/plugin_misc_invitations.py @ 2230:ebc0c1701811

plugin invitations: added invitationList command
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 00:53:23 +0200
parents c6c9a97ffebf
children f87b673c7d17
line wrap: on
line diff
--- a/src/plugins/plugin_misc_invitations.py	Thu Apr 20 17:20:44 2017 +0200
+++ b/src/plugins/plugin_misc_invitations.py	Thu Apr 27 00:53:23 2017 +0200
@@ -80,6 +80,9 @@
         host.bridge.addMethod("invitationModify", ".plugin", in_sign='sa{ss}b', out_sign='',
                               method=self._modify,
                               async=True)
+        host.bridge.addMethod("invitationList", ".plugin", in_sign='s', out_sign='a{sa{ss}}',
+                              method=self._list,
+                              async=True)
 
     def checkExtra(self, extra):
         if EXTRA_RESERVED.intersection(extra):
@@ -103,6 +106,7 @@
         d = self.create(**kwargs)
         def serialize(data):
             data[KEY_JID] = data[KEY_JID].full()
+            return data
         d.addCallback(serialize)
         return d
 
@@ -270,7 +274,7 @@
             log.warning(_(u"Not all arguments have been consumed: {}").format(kwargs))
 
         extra[KEY_ID] = id_
-        extra[KEY_JID] = jid
+        extra[KEY_JID] = jid_
         defer.returnValue(extra)
 
     def get(self, id_):
@@ -313,3 +317,20 @@
         d = self.invitations[id_]
         d.addCallback(gotCurrentData)
         return d
+
+    def _list(self, profile=C.PROF_KEY_NONE):
+        return self.list(profile)
+
+    @defer.inlineCallbacks
+    def list(self, profile=C.PROF_KEY_NONE):
+        """List invitations
+
+        @param profile(unicode): return invitation linked to this profile only
+            C.PROF_KEY_NONE: don't filter invitations
+        @return list(unicode): invitations uids
+        """
+        invitations = yield self.invitations.items()
+        if profile != C.PROF_KEY_NONE:
+            invitations = {id_:data for id_, data in invitations.iteritems() if data.get(u'profile') == profile}
+
+        defer.returnValue(invitations)