comparison 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
comparison
equal deleted inserted replaced
2229:761fa220a717 2230:ebc0c1701811
78 method=self.get, 78 method=self.get,
79 async=True) 79 async=True)
80 host.bridge.addMethod("invitationModify", ".plugin", in_sign='sa{ss}b', out_sign='', 80 host.bridge.addMethod("invitationModify", ".plugin", in_sign='sa{ss}b', out_sign='',
81 method=self._modify, 81 method=self._modify,
82 async=True) 82 async=True)
83 host.bridge.addMethod("invitationList", ".plugin", in_sign='s', out_sign='a{sa{ss}}',
84 method=self._list,
85 async=True)
83 86
84 def checkExtra(self, extra): 87 def checkExtra(self, extra):
85 if EXTRA_RESERVED.intersection(extra): 88 if EXTRA_RESERVED.intersection(extra):
86 raise ValueError(_(u"You can't use following key(s) in extra, they are reserved: {}").format( 89 raise ValueError(_(u"You can't use following key(s) in extra, they are reserved: {}").format(
87 u', '.join(EXTRA_RESERVED.intersection(extra)))) 90 u', '.join(EXTRA_RESERVED.intersection(extra))))
101 if value: 104 if value:
102 kwargs[key] = unicode(value) 105 kwargs[key] = unicode(value)
103 d = self.create(**kwargs) 106 d = self.create(**kwargs)
104 def serialize(data): 107 def serialize(data):
105 data[KEY_JID] = data[KEY_JID].full() 108 data[KEY_JID] = data[KEY_JID].full()
109 return data
106 d.addCallback(serialize) 110 d.addCallback(serialize)
107 return d 111 return d
108 112
109 @defer.inlineCallbacks 113 @defer.inlineCallbacks
110 def create(self, **kwargs): 114 def create(self, **kwargs):
268 272
269 if kwargs: 273 if kwargs:
270 log.warning(_(u"Not all arguments have been consumed: {}").format(kwargs)) 274 log.warning(_(u"Not all arguments have been consumed: {}").format(kwargs))
271 275
272 extra[KEY_ID] = id_ 276 extra[KEY_ID] = id_
273 extra[KEY_JID] = jid 277 extra[KEY_JID] = jid_
274 defer.returnValue(extra) 278 defer.returnValue(extra)
275 279
276 def get(self, id_): 280 def get(self, id_):
277 """Retrieve invitation linked to uuid if it exists 281 """Retrieve invitation linked to uuid if it exists
278 282
311 self.invitations[id_] = new_data 315 self.invitations[id_] = new_data
312 316
313 d = self.invitations[id_] 317 d = self.invitations[id_]
314 d.addCallback(gotCurrentData) 318 d.addCallback(gotCurrentData)
315 return d 319 return d
320
321 def _list(self, profile=C.PROF_KEY_NONE):
322 return self.list(profile)
323
324 @defer.inlineCallbacks
325 def list(self, profile=C.PROF_KEY_NONE):
326 """List invitations
327
328 @param profile(unicode): return invitation linked to this profile only
329 C.PROF_KEY_NONE: don't filter invitations
330 @return list(unicode): invitations uids
331 """
332 invitations = yield self.invitations.items()
333 if profile != C.PROF_KEY_NONE:
334 invitations = {id_:data for id_, data in invitations.iteritems() if data.get(u'profile') == profile}
335
336 defer.returnValue(invitations)