Mercurial > libervia-backend
changeset 2760:3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
new "order_by" key can be used in extra data, value can be, for now, "creation" or "modification".
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 06 Jan 2019 17:36:51 +0100 |
parents | 607cfc79e40f |
children | 4b693ea24d5f |
files | sat/core/constants.py sat/plugins/plugin_exp_pubsub_schema.py sat/plugins/plugin_xep_0060.py sat/plugins/plugin_xep_0277.py sat/plugins/plugin_xep_0313.py |
diffstat | 5 files changed, 44 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/core/constants.py Sun Jan 06 17:34:56 2019 +0100 +++ b/sat/core/constants.py Sun Jan 06 17:36:51 2019 +0100 @@ -396,6 +396,12 @@ KEY_THUMBNAILS = u"thumbnails" KEY_PROGRESS_ID = u"progress_id" + ## Common extra keys/values ## + KEY_ORDER_BY = u"order_by" + + ORDER_BY_CREATION = u'creation' + ORDER_BY_MODIFICATION = u'modification' + # internationalisation DEFAULT_LOCALE = u"en_GB"
--- a/sat/plugins/plugin_exp_pubsub_schema.py Sun Jan 06 17:34:56 2019 +0100 +++ b/sat/plugins/plugin_exp_pubsub_schema.py Sun Jan 06 17:36:51 2019 +0100 @@ -272,21 +272,9 @@ return d @defer.inlineCallbacks - def getDataFormItems( - self, - client, - service, - nodeIdentifier, - schema=None, - max_items=None, - item_ids=None, - sub_id=None, - rsm_request=None, - extra=None, - default_node=None, - form_ns=None, - filters=None, - ): + def getDataFormItems(self, client, service, nodeIdentifier, schema=None, + max_items=None, item_ids=None, sub_id=None, rsm_request=None, + extra=None, default_node=None, form_ns=None, filters=None): """Get items known as being data forms, and convert them to XMLUI @param schema(domish.Element, data_form.Form, None): schema of the node if known @@ -499,19 +487,9 @@ return client, service, node, max_items, extra, sub_id - def _get( - self, - service="", - node="", - max_items=10, - item_ids=None, - sub_id=None, - extra=None, - default_node=None, - form_ns=None, - filters=None, - profile_key=C.PROF_KEY_NONE, - ): + def _get(self, service="", node="", max_items=10, item_ids=None, sub_id=None, + extra=None, default_node=None, form_ns=None, filters=None, + profile_key=C.PROF_KEY_NONE): """Bridge method to retrieve data from node with schema this method is a helper so dependant plugins can use it directly
--- a/sat/plugins/plugin_xep_0060.py Sun Jan 06 17:34:56 2019 +0100 +++ b/sat/plugins/plugin_xep_0060.py Sun Jan 06 17:36:51 2019 +0100 @@ -82,8 +82,8 @@ def __init__(self, host): log.info(_(u"PubSub plugin initialization")) self.host = host - self._rsm = host.plugins.get("XEP-0059") - self._mam = host.plugins.get("XEP-0313") + self._rsm = host.plugins.get(u"XEP-0059") + self._mam = host.plugins.get(u"XEP-0313") self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks) self.rt_sessions = sat_defer.RTDeferredSessions() host.bridge.addMethod( @@ -321,6 +321,13 @@ rsm_request = None extra = {} else: + # order-by + if C.KEY_ORDER_BY in extra: + # FIXME: we temporarily manage only one level of ordering + # we need to switch to a fully serialised extra data + # to be able to encode a whole ordered list + extra[C.KEY_ORDER_BY] = [extra.pop(C.KEY_ORDER_BY)] + # rsm if self._rsm is None: rsm_request = None @@ -336,6 +343,7 @@ if mam_request is not None: assert u"mam" not in extra extra[u"mam"] = mam_request + return Extra(rsm_request, extra) def addManagedNode(self, node, **kwargs): @@ -537,7 +545,14 @@ mam_query = extra["mam"] except KeyError: d = client.pubsub_client.items( - service, node, max_items, item_ids, sub_id, None, rsm_request + service = service, + nodeIdentifier = node, + maxItems = max_items, + subscriptionIdentifier = sub_id, + sender = None, + itemIdentifiers = item_ids, + orderBy = extra.get(C.KEY_ORDER_BY), + rsm_request = rsm_request ) # we have no MAM data here, so we add None d.addCallback(lambda data: data + (None,)) @@ -577,11 +592,11 @@ ) ) - def doSubscribe(items): + def doSubscribe(data): self.subscribe(service, node, profile_key=client.profile).addErrback( subscribeEb, service, node ) - return items + return data if subscribe: d.addCallback(doSubscribe) @@ -1324,6 +1339,7 @@ except KeyError: continue + def itemsReceived(self, event): log.debug(u"Pubsub items received") for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS):
--- a/sat/plugins/plugin_xep_0277.py Sun Jan 06 17:34:56 2019 +0100 +++ b/sat/plugins/plugin_xep_0277.py Sun Jan 06 17:36:51 2019 +0100 @@ -788,15 +788,8 @@ ## get ## - def _mbGet( - self, - service="", - node="", - max_items=10, - item_ids=None, - extra_dict=None, - profile_key=C.PROF_KEY_NONE, - ): + def _mbGet(self, service="", node="", max_items=10, item_ids=None, extra_dict=None, + profile_key=C.PROF_KEY_NONE): """ @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit @param item_ids (list[unicode]): list of item IDs @@ -816,16 +809,8 @@ ) @defer.inlineCallbacks - def mbGet( - self, - client, - service=None, - node=None, - max_items=10, - item_ids=None, - rsm_request=None, - extra=None, - ): + def mbGet(self, client, service=None, node=None, max_items=10, item_ids=None, + rsm_request=None, extra=None): """Get some microblogs @param service(jid.JID, None): jid of the publisher
--- a/sat/plugins/plugin_xep_0313.py Sun Jan 06 17:34:56 2019 +0100 +++ b/sat/plugins/plugin_xep_0313.py Sun Jan 06 17:36:51 2019 +0100 @@ -162,6 +162,13 @@ if form_args: mam_args["form"] = mam.buildForm(**form_args) + # we only set orderBy if we have other MAM args + # else we would make a MAM query while it's not expected + if u"order_by" in extra and mam_args: + order_by = extra.pop(u"order_by") + assert isinstance(order_by, list) + mam_args["orderBy"] = order_by + return mam.MAMRequest(**mam_args) if mam_args else None def serialise(self, mam_response, data=None):