diff src/plugins/plugin_misc_invitations.py @ 2211:df115e4a36c7

plugin invitations: invitation id and invitee jid are now added to return dict in invitationCreate, bridge signature has changed too
author Goffi <goffi@goffi.org>
date Wed, 29 Mar 2017 19:35:55 +0200
parents f8d61592f1fc
children eaf2467d19ce
line wrap: on
line diff
--- a/src/plugins/plugin_misc_invitations.py	Wed Mar 29 19:30:29 2017 +0200
+++ b/src/plugins/plugin_misc_invitations.py	Wed Mar 29 19:35:55 2017 +0200
@@ -44,9 +44,11 @@
 
 SUFFIX_MAX = 5
 INVITEE_PROFILE_TPL = u"guest@@{uuid}"
+KEY_ID = u'id'
+KEY_JID = u'jid'
 KEY_CREATED = u'created'
 KEY_LAST_CONNECTION = u'last_connection'
-EXTRA_RESERVED = {KEY_CREATED, u'jid_', u'jid', KEY_LAST_CONNECTION}
+EXTRA_RESERVED = {KEY_ID, KEY_JID, KEY_CREATED, u'jid_', u'jid', KEY_LAST_CONNECTION}
 DEFAULT_SUBJECT = D_(u"You have been invited by {host_name} to {app_name}")
 DEFAULT_BODY = D_(u"""Hello {name}!
 
@@ -67,7 +69,7 @@
         log.info(_(u"plugin Invitations initialization"))
         self.host = host
         self.invitations = persistent.LazyPersistentBinaryDict(u'invitations')
-        host.bridge.addMethod("invitationCreate", ".plugin", in_sign='sssssssssa{ss}s', out_sign='(sa{ss})',
+        host.bridge.addMethod("invitationCreate", ".plugin", in_sign='sssssssssa{ss}s', out_sign='a{ss}',
                               method=self._createInvitation,
                               async=True)
     def _createInvitation(self, jid_=u'', password=u'', name=u'', host_name=u'', email=u'', language=u'', url_template=u'', message_subject=u'', message_body=u'', extra=None, profile=u''):
@@ -84,7 +86,11 @@
             value = locals()[key]
             if value:
                 kwargs[key] = unicode(value)
-        return self.createInvitation(**kwargs)
+        d = self.createInvitation(**kwargs)
+        def serialize(data):
+            data[KEY_JID] = data[KEY_JID].full()
+        d.addCallback(serialize)
+        return d
 
     @defer.inlineCallbacks
     def createInvitation(self, **kwargs):
@@ -129,8 +135,8 @@
                     - created (creation date)
                 if email argument is used, "email" key can't be used
             profile(unicode, None): profile of the host (person who is inviting)
-        @return (unicode, dict[unicode, unicode]): tuple with:
-            - UUID associated with the invitee
+        @return (dict[unicode, unicode]): dictionary with:
+            - UUID associated with the invitee (key: id)
             - filled extra dictionary, as saved in the databae
         """
         ## initial checks
@@ -250,4 +256,6 @@
         if kwargs:
             log.warning(_(u"Not all arguments have been consumed: {}").format(kwargs))
 
-        defer.returnValue((id_, extra))
+        extra[KEY_ID] = id_
+        extra[KEY_JID] = jid
+        defer.returnValue(extra)