Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 1451:9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
serItemsData is used for normal callbacks, and serItemsDataD for callbacks which return deferred. These methods simplifly the code by making the re-use of getItems more easy.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 15 Aug 2015 22:20:56 +0200 |
parents | 7797dda847ae |
children | 5116d70ddd1c |
comparison
equal
deleted
inserted
replaced
1450:7797dda847ae | 1451:9b88b19b1ca8 |
---|---|
59 class XEP_0277(object): | 59 class XEP_0277(object): |
60 | 60 |
61 def __init__(self, host): | 61 def __init__(self, host): |
62 log.info(_("Microblogging plugin initialization")) | 62 log.info(_("Microblogging plugin initialization")) |
63 self.host = host | 63 self.host = host |
64 self._p = self.host.plugins["XEP-0060"] # this facilitate the access to pubsub plugin | |
64 self.host.plugins["XEP-0163"].addPEPEvent("MICROBLOG", NS_MICROBLOG, self.microblogCB, self.sendMicroblog, notify=False) | 65 self.host.plugins["XEP-0163"].addPEPEvent("MICROBLOG", NS_MICROBLOG, self.microblogCB, self.sendMicroblog, notify=False) |
65 host.bridge.addMethod("getLastMicroblogs", ".plugin", | 66 host.bridge.addMethod("getLastMicroblogs", ".plugin", |
66 in_sign='sis', out_sign='(aa{ss}a{ss})', | 67 in_sign='sis', out_sign='(aa{ss}a{ss})', |
67 method=self._getLastMicroblogs, | 68 method=self._getLastMicroblogs, |
68 async=True, | 69 async=True, |
308 content = data['content'] | 309 content = data['content'] |
309 if not content: | 310 if not content: |
310 log.error("Microblog data's content value must not be empty") | 311 log.error("Microblog data's content value must not be empty") |
311 raise failure.Failure(exceptions.DataError('empty content')) | 312 raise failure.Failure(exceptions.DataError('empty content')) |
312 item = yield self.data2entry(data, profile) | 313 item = yield self.data2entry(data, profile) |
313 ret = yield self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile) | 314 ret = yield self._p.publish(None, NS_MICROBLOG, [item], profile_key=profile) |
314 defer.returnValue(ret) | 315 defer.returnValue(ret) |
315 | 316 |
316 ## get ## | 317 ## get ## |
317 | 318 |
318 def _getLastMicroblogs(self, pub_jid_s, max_items=10, profile_key=C.PROF_KEY_NONE): | 319 def _getLastMicroblogs(self, pub_jid_s, max_items=10, profile_key=C.PROF_KEY_NONE): |
371 | 372 |
372 _jid, xmlstream = self.host.getJidNStream(profile_key) | 373 _jid, xmlstream = self.host.getJidNStream(profile_key) |
373 if not _jid: | 374 if not _jid: |
374 log.error(_("Can't find profile's jid")) | 375 log.error(_("Can't find profile's jid")) |
375 return | 376 return |
376 C = self.host.plugins["XEP-0060"] | 377 _options = {self._p.OPT_ACCESS_MODEL: access, self._p.OPT_PERSIST_ITEMS: 1, self._p.OPT_MAX_ITEMS: -1, self._p.OPT_DELIVER_PAYLOADS: 1, self._p.OPT_SEND_ITEM_SUBSCRIBE: 1} |
377 _options = {C.OPT_ACCESS_MODEL: access, C.OPT_PERSIST_ITEMS: 1, C.OPT_MAX_ITEMS: -1, C.OPT_DELIVER_PAYLOADS: 1, C.OPT_SEND_ITEM_SUBSCRIBE: 1} | |
378 | 378 |
379 def cb(result): | 379 def cb(result): |
380 #Node is created with right permission | 380 #Node is created with right permission |
381 log.debug(_(u"Microblog node has now access %s") % access) | 381 log.debug(_(u"Microblog node has now access %s") % access) |
382 | 382 |
394 change_node_options().addCallback(cb).addErrback(fatal_err) | 394 change_node_options().addCallback(cb).addErrback(fatal_err) |
395 else: | 395 else: |
396 fatal_err(s_error) | 396 fatal_err(s_error) |
397 | 397 |
398 def create_node(): | 398 def create_node(): |
399 return self.host.plugins["XEP-0060"].createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key) | 399 return self._p.createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key) |
400 | 400 |
401 def change_node_options(): | 401 def change_node_options(): |
402 return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key) | 402 return self._p.setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key) |
403 | 403 |
404 create_node().addCallback(cb).addErrback(err_cb) | 404 create_node().addCallback(cb).addErrback(err_cb) |
405 | 405 |
406 ## methods to manage several stanzas/jids at once ## | 406 ## methods to manage several stanzas/jids at once ## |
407 | 407 |
464 @param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids) | 464 @param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids) |
465 @param profile: %(doc_profile)s | 465 @param profile: %(doc_profile)s |
466 @return (str): session id | 466 @return (str): session id |
467 """ | 467 """ |
468 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key) | 468 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key) |
469 return self.host.plugins["XEP-0060"].subscribeToMany(node_data, client.jid.userhostJID(), profile_key=profile_key) | 469 return self._p.subscribeToMany(node_data, client.jid.userhostJID(), profile_key=profile_key) |
470 | 470 |