Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0060.py @ 3100:cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
- publishing options (XEP-0060 ยง7.1.5) implementation.
- jp pubsub/set can specify publish-options using `-f` and `-F`
- doc has been updated to explain that
- psItemSend and psItemsSend now use serialisation for "extra"
- publish-options can be specified in extra['publish-options'] with those methods
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Dec 2019 20:02:18 +0100 |
parents | 73db9db8b9e1 |
children | 9d0df638c8b4 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py Fri Dec 27 13:30:20 2019 +0100 +++ b/sat/plugins/plugin_xep_0060.py Sat Dec 28 20:02:18 2019 +0100 @@ -201,7 +201,7 @@ host.bridge.addMethod( "psItemSend", ".plugin", - in_sign="ssssa{ss}s", + in_sign="ssssss", out_sign="s", method=self._sendItem, async_=True, @@ -209,7 +209,7 @@ host.bridge.addMethod( "psItemsSend", ".plugin", - in_sign="ssasa{ss}s", + in_sign="ssasss", out_sign="as", method=self._sendItems, async_=True, @@ -453,17 +453,18 @@ # d.addCallback(lambda subs: [sub.getAttribute('node') for sub in subs if sub.getAttribute('subscription') == filter_]) # return d - def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra=None, + def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra_ser="", profile_key=C.PROF_KEY_NONE): client = self.host.getClient(profile_key) service = None if not service else jid.JID(service) + extra = data_format.deserialise(extra_ser) d = self.sendItem( client, service, nodeIdentifier, payload, item_id or None, extra ) d.addCallback(lambda ret: ret or "") return d - def _sendItems(self, service, nodeIdentifier, items, extra=None, + def _sendItems(self, service, nodeIdentifier, items, extra_ser=None, profile_key=C.PROF_KEY_NONE): client = self.host.getClient(profile_key) service = None if not service else jid.JID(service) @@ -472,6 +473,7 @@ except Exception as e: raise exceptions.DataError(_("Can't parse items: {msg}").format( msg=e)) + extra = data_format.deserialise(extra_ser) d = self.sendItems( client, service, nodeIdentifier, items, extra ) @@ -501,8 +503,12 @@ @param extra(dict, None): extra option, not used yet @return (unicode, None): id of the created item """ + if extra is None: + extra = {} + publish_options = extra.get('publish_options') item_elt = pubsub.Item(id=item_id, payload=payload) - d = self.publish(client, service, nodeIdentifier, [item_elt]) + d = self.publish( + client, service, nodeIdentifier, [item_elt], options=publish_options) d.addCallback(self._getPublishedItemId, item_id) return d @@ -523,22 +529,28 @@ @param NodeIdentifier(unicode): PubSub node to use @param items(list[domish.Element]): whole item elements to send, "id" will be used if set - @param extra(dict, None): extra option, not used yet + @param extra(dict, None): extra options. Key can be: + - publish_options: dict of publish-options @return (list[unicode]): ids of the created items """ + if extra is None: + extra = {} parsed_items = [] for item in items: if item.name != 'item': raise exceptions.DataError(_("Invalid item: {xml}").format(item.toXml())) item_id = item.getAttribute("id") parsed_items.append(pubsub.Item(id=item_id, payload=item.firstChildElement())) - d = self.publish(client, service, nodeIdentifier, parsed_items) + publish_options = extra.get('publish_options') + d = self.publish( + client, service, nodeIdentifier, parsed_items, options=publish_options) d.addCallback(self._publishCb) return d - def publish(self, client, service, nodeIdentifier, items=None): + def publish(self, client, service, nodeIdentifier, items=None, options=None): return client.pubsub_client.publish( - service, nodeIdentifier, items, client.pubsub_client.parent.jid + service, nodeIdentifier, items, client.pubsub_client.parent.jid, + options=options ) def _unwrapMAMMessage(self, message_elt):