diff sat/plugins/plugin_xep_0060.py @ 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 f4070693814a
children 9282b289b964
line wrap: on
line diff
--- 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):