changeset 1785:ac73d7456abc

tmp (wokkel.mam): recipient and sender are handled in MAM Request. TODO: MAMRequest should inherit from generic.Stanza, the same way as for PubSubRequest
author Goffi <goffi@goffi.org>
date Fri, 08 Jan 2016 18:54:23 +0100
parents 21f0bcd3b637
children 104874018ab0
files src/tmp/wokkel/mam.py
diffstat 1 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/tmp/wokkel/mam.py	Fri Jan 08 18:52:28 2016 +0100
+++ b/src/tmp/wokkel/mam.py	Fri Jan 08 18:54:23 2016 +0100
@@ -93,8 +93,9 @@
     @ivar query_id: id to use to track the query
     @itype form: C{unicode}
     """
+    # FIXME: should be based on generic.Stanza
 
-    def __init__(self, form=None, rsm_=None, node=None, query_id=None):
+    def __init__(self, form=None, rsm_=None, node=None, query_id=None, sender=None, recipient=None):
         if form is not None:
             assert form.formType == 'submit'
             assert form.formNamespace == NS_MAM
@@ -102,19 +103,23 @@
         self.rsm = rsm_
         self.node = node
         self.query_id = query_id
+        self.sender = sender
+        self.recipient = recipient
 
     @classmethod
-    def fromElement(cls, element):
+    def fromElement(cls, iq):
         """Parse the DOM representation of a MAM <query/> request.
 
-        @param element: element containing a MAM <query/>.
-        @type element: L{Element<twisted.words.xish.domish.Element>}
+        @param iq: <iq/> element containing a MAM <query/>.
+        @type iq: L{Element<twisted.words.xish.domish.Element>}
 
         @return: MAMRequest instance.
         @rtype: L{MAMRequest}
         """
+        sender = jid.JID(iq.getAttribute('from'))
+        recipient = jid.JID(iq.getAttribute('to'))
         try:
-            query = element.elements(NS_MAM, 'query').next()
+            query = iq.elements(NS_MAM, 'query').next()
         except StopIteration:
             raise MAMError("Can't find MAM <query/> in element")
         form = data_form.findForm(query, NS_MAM)
@@ -124,7 +129,7 @@
             rsm_request = None
         node = query.getAttribute('node')
         query_id = query.getAttribute('queryid')
-        return MAMRequest(form, rsm_request, node, query_id)
+        return MAMRequest(form, rsm_request, node, query_id, sender, recipient)
 
     def toElement(self):
         """
@@ -350,15 +355,12 @@
 
 class IMAMResource(Interface):
 
-    def onArchiveRequest(self, mam, requestor):
+    def onArchiveRequest(self, mam):
         """
 
         @param mam: The MAM <query/> request.
         @type mam: L{MAMQueryReques<wokkel.mam.MAMRequest>}
 
-        @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>}
         """
@@ -482,7 +484,6 @@
         """
         iq.handled = True
         mam_ = self._request_class.fromElement(iq)
-        requestor = jid.JID(iq['from'])
 
         # remove unsupported filters
         unsupported_fields = []
@@ -517,7 +518,7 @@
                 fin_elt.addChild(rsm_elt)
             return fin_elt
 
-        d = defer.maybeDeferred(self.resource.onArchiveRequest, mam_, requestor)
+        d = defer.maybeDeferred(self.resource.onArchiveRequest, mam_)
         d.addCallback(cb)
         return d