diff sat_pubsub/mam.py @ 316:cca47e9977a5

mam: minor improvments (module import and some checks)
author Goffi <goffi@goffi.org>
date Sun, 03 Jan 2016 18:33:22 +0100
parents a776544d84e5
children 54d90c73b8b5
line wrap: on
line diff
--- a/sat_pubsub/mam.py	Sun Jan 03 18:33:22 2016 +0100
+++ b/sat_pubsub/mam.py	Sun Jan 03 18:33:22 2016 +0100
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 #-*- coding: utf-8 -*-
 
+# Copyright (c) 2016 Jérôme Poisson
 # Copyright (c) 2015-2016 Adrien Cossa
 #
 # This program is free software: you can redistribute it and/or modify
@@ -35,15 +36,15 @@
 from dateutil import parser
 
 # TODO: change this when RSM and MAM are in wokkel
-from sat.tmp.wokkel.rsm import RSMRequest
-from sat.tmp.wokkel.mam import MAMPrefs, IMAMResource
+from sat.tmp.wokkel import rsm
+from sat.tmp.wokkel import mam
 
 NS_CLIENT = 'jabber:client'
 
 
 class MAMResource(object):
 
-    implements(IMAMResource)
+    implements(mam.IMAMResource)
 
     def __init__(self, backend):
         self.backend = backend
@@ -57,14 +58,15 @@
         @param requestor: JID of the requestor.
         @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
 
-        @return: The RSM answer.
-        @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>}
+        @return: A tuple with list of message data (id, element, data) and RSM element
+        @rtype: C{tuple}
         """
+        # FIXME: bad result ordering
         ext_data = {}
         if mam.form:
             ext_data['filters'] = mam.form.fields.values()
         if mam.rsm is None:
-            mam.rsm = RSMRequest(const.VAL_RSM_MAX_DEFAULT)
+            mam.rsm = rsm.RSMRequest(const.VAL_RSM_MAX_DEFAULT)
         ext_data['rsm'] = mam.rsm
 
         d = self.backend.getItems(mam.node, requestor, mam.rsm.max, None, ext_data)
@@ -82,15 +84,19 @@
             msg_data = []
             rsm_elt = None
             for elt in elts:
-                if elt.name == 'set':
+                if elt.name == 'set' and elt.uri == rsm.NS_RSM:
+                    assert rsm_elt is None
                     rsm_elt = elt
                 elif elt.name == 'item':
+                    # FIXME: this is not good as it is dependant on payload
+                    # TODO: remove this and use date field in database
                     date = parser.parse(''.join(elt.entry.published.children))
                     msg_data.append([elt['id'], make_message(elt), date])
             return (msg_data, rsm_elt)
 
         d.addErrback(PubSubResourceFromBackend._mapErrors)
-        return d.addCallback(cb)
+        d.addCallback(cb)
+        return d
 
     def onPrefsGetRequest(self, requestor):
         """
@@ -102,7 +108,7 @@
         @rtype: L{wokkel.mam.MAMPrefs}
         """
         # TODO: return the actual current settings
-        return MAMPrefs()
+        return mam.MAMPrefs()
 
     def onPrefsSetRequest(self, prefs, requestor):
         """
@@ -117,4 +123,4 @@
         @rtype: L{wokkel.mam.MAMPrefs}
         """
         # TODO: set the new settings and return them
-        return MAMPrefs()
+        return mam.MAMPrefs()