annotate src/tmp/wokkel/mam.py @ 1770:f525c272fd6d

tmp (mam): various improvments: - updated behaviour and namespace to new urn:xmpp:mam:1 - fixed use of query_id in MAMQueryRequest/MAMClient - added a couple of assertions/checks - use try/except instead of hasAttribute - do not use generateElementsNamed (use elements method instead) - do not ignore missing elements - queryFields return a data form instead of a raw element - fixed bad use of namespace in several addElement - IMAMResource.onArchiveRequest doesn't have to return a Deferred anymore (but may do) - buildForm use data_form.Field class directly and doesn't use intermediate list anymore - /!\ XEP-0313 plugin is temporarly broken
author Goffi <goffi@goffi.org>
date Sun, 03 Jan 2016 18:36:41 +0100
parents 2d8fccec84e8
children 0c21dafedd22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1424
2d8fccec84e8 core (tests): test fixes
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
1 # -*- coding: utf-8 -*-
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- test-case-name: wokkel.test.test_mam -*-
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
3 #
1422
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
4 # SàT Wokkel extension for Message Archive Management (XEP-0313)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
5 # Copyright (C) 2015 Jérôme Poisson (goffi@goffi.org)
1422
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
6 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org)
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
7
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
8 # This program is free software: you can redistribute it and/or modify
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
11 # (at your option) any later version.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
12
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
13 # This program is distributed in the hope that it will be useful,
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
16 # GNU Affero General Public License for more details.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
17
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
20
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
22 XMPP Message Archive Management protocol.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
23
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
24 This protocol is specified in
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
25 U{XEP-0313<http://xmpp.org/extensions/xep-0313.html>}.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
26 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
27
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from dateutil.tz import tzutc
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
29
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from zope.interface import Interface, implements
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
31
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
32 from twisted.words.protocols.jabber.xmlstream import IQ, toResponse
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
33 from twisted.words.xish import domish
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
34 from twisted.words.protocols.jabber import jid
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
35 from twisted.internet import defer
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
36 from twisted.python import log
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
37
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
38 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
39 from wokkel import disco, data_form, delay
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
40
1285
ed2c718bfe03 tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents: 1283
diff changeset
41 import rsm
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
42
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
43 NS_MAM = 'urn:xmpp:mam:1'
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
44 NS_FORWARD = 'urn:xmpp:forward:0'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
45
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
46 FIELDS_REQUEST = "/iq[@type='get']/query[@xmlns='%s']" % NS_MAM
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
47 ARCHIVE_REQUEST = "/iq[@type='set']/query[@xmlns='%s']" % NS_MAM
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
48 PREFS_GET_REQUEST = "/iq[@type='get']/prefs[@xmlns='%s']" % NS_MAM
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
49 PREFS_SET_REQUEST = "/iq[@type='set']/prefs[@xmlns='%s']" % NS_MAM
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
50
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
51 # TODO: add the tests!
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
52
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
53
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
54 class MAMError(Exception):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
55 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
56 MAM error.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
57 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
58
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
59
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
60 class Unsupported(MAMError):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
61 def __init__(self, feature, text=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
62 self.feature = feature
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
63 MAMError.__init__(self, 'feature-not-implemented',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
64 'unsupported',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
65 feature,
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
66 text)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
67
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
68 def __str__(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
69 message = MAMError.__str__(self)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
70 message += ', feature %r' % self.feature
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
71 return message
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
72
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
73
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
74 class MAMQueryRequest():
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
75 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
76 A Message Archive Management <query/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
77
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
78 @ivar form: Data Form specifing the filters.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
79 @itype form: L{data_form.Form}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
80
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
81 @ivar rsm: RSM request instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
82 @itype rsm: L{rsm.RSMRequest}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
83
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
84 @ivar node: pubsub node id if querying a pubsub node, else None.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
85 @itype form: C{unicode}
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
86
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
87 @ivar query_id: id to use to track the query
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
88 @itype form: C{unicode}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
89 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
90
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
91 def __init__(self, form=None, rsm_=None, node=None, query_id=None):
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
92 if form is not None:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
93 assert form.formType == 'submit'
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
94 assert form.formNamespace == NS_MAM
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
95 self.form = form
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
96 self.rsm = rsm_
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
97 self.node = node
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
98 self.query_id = query_id
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
99
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
100 @classmethod
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
101 def parse(cls, element):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
102 """Parse the DOM representation of a MAM <query/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
103
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
104 @param element: MAM <query/> request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
105 @type element: L{Element<twisted.words.xish.domish.Element>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
106
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
107 @return: MAMQueryRequest instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
108 @rtype: L{MAMQueryRequest}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
109 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
110 if element.uri != NS_MAM or element.name != 'query':
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
111 raise MAMError('Element provided is not a MAM <query/> request')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
112 form = data_form.findForm(element, NS_MAM)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
113 try:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
114 rsm_request = rsm.RSMRequest.parse(element)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
115 except rsm.RSMNotFoundError:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
116 rsm_request = None
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
117 node = element.getAttribute('node')
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
118 query_id = element.getAttribute('queryid')
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
119 return MAMQueryRequest(form, rsm_request, node, query_id)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
120
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
121 def toElement(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
122 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
123 Return the DOM representation of this RSM <query/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
124
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
125 @rtype: L{Element<twisted.words.xish.domish.Element>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
126 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
127 mam_elt = domish.Element((NS_MAM, 'query'))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
128 if self.node is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
129 mam_elt['node'] = self.node
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
130 if self.query_id is not None:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
131 mam_elt['queryid'] = self.query_id
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
132 if self.form is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
133 mam_elt.addChild(self.form.toElement())
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
134 if self.rsm is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
135 mam_elt.addChild(self.rsm.toElement())
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
136
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
137 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
138
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
139 def render(self, parent):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
140 """Embed the DOM representation of this MAM request in the given element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
141
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
142 @param parent: parent IQ element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
143 @type parent: L{Element<twisted.words.xish.domish.Element>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
144
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
145 @return: MAM request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
146 @rtype: L{Element<twisted.words.xish.domish.Element>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
147 """
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
148 assert parent.name == 'iq'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
149 mam_elt = self.toElement()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
150 parent.addChild(mam_elt)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
151 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
152
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
153
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
154 class MAMPrefs():
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
155 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
156 A Message Archive Management <prefs/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
157
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
158 @param default: A value in ('always', 'never', 'roster').
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
159 @type : C{unicode} or C{None}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
160
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
161 @param always (list): A list of JID instances.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
162 @type always: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
163
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
164 @param never (list): A list of JID instances.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
165 @type never: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
166 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
167
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
168 def __init__(self, default, always=None, never=None):
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
169 assert default in ('always', 'never', 'roster')
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
170 self.default = default
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
171 if always is not None:
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
172 assert isinstance(always, list)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
173 else:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
174 always = []
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
175 self.always = always
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
176 if never is not None:
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
177 assert isinstance(never, list)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
178 else:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
179 never = []
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
180 self.never = never
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
181
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
182 @classmethod
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
183 def parse(cls, prefs_elt):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
184 """Parse the DOM representation of a MAM <prefs/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
185
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
186 @param prefs_elt: MAM <prefs/> request element.
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
187 @type prefs_elt: L{Element<twisted.words.xish.domish.Element>}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
188
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
189 @return: MAMPrefs instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
190 @rtype: L{MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
191 """
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
192 if prefs_elt.uri != NS_MAM or prefs_elt.name != 'prefs':
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
193 raise MAMError('Element provided is not a MAM <prefs/> request')
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
194 try:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
195 default = prefs_elt['default']
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
196 except KeyError:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
197 # FIXME: return proper error here
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
198 raise MAMError('Element provided is not a valid MAM <prefs/> request')
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
199
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
200 prefs = {}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
201 for attr in ('always', 'never'):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
202 prefs[attr] = []
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
203 try:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
204 pref = prefs_elt.elements(NS_MAM, attr).next()
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
205 except StopIteration:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
206 # FIXME: return proper error here
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
207 raise MAMError('Element provided is not a valid MAM <prefs/> request')
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
208 else:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
209 for jid_s in pref.elements(NS_MAM, 'jid'):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
210 prefs[attr].append(jid.JID(jid_s))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
211 return MAMPrefs(default, **prefs)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
212
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
213 def toElement(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
214 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
215 Return the DOM representation of this RSM <prefs/>request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
216
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
217 @rtype: L{Element<twisted.words.xish.domish.Element>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
218 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
219 mam_elt = domish.Element((NS_MAM, 'prefs'))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
220 if self.default:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
221 mam_elt['default'] = self.default
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
222 for attr in ('always', 'never'):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
223 attr_elt = mam_elt.addElement(attr)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
224 jids = getattr(self, attr)
1413
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
225 for jid_ in jids:
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
226 attr_elt.addElement('jid', content=jid_.full())
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
227 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
228
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
229 def render(self, parent):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
230 """Embed the DOM representation of this MAM request in the given element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
231
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
232 @param parent: parent IQ element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
233 @type parent: L{Element<twisted.words.xish.domish.Element>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
234
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
235 @return: MAM request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
236 @rtype: L{Element<twisted.words.xish.domish.Element>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
237 """
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
238 assert parent.name == 'iq'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
239 mam_elt = self.toElement()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
240 parent.addChild(mam_elt)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
241 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
242
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
243
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
244 class MAMClient(XMPPHandler):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
245 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
246 MAM client.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
247
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
248 This handler implements the protocol for sending out MAM requests.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
249 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
250
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
251 def queryArchive(self, service=None, form=None, rsm=None, node=None, sender=None, query_id=None):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
252 """Query a user, MUC or pubsub archive.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
253
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
254 @param service: Entity offering the MAM service (None for user archives).
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
255 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
256
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
257 @param form: Data Form to filter the request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
258 @type form: L{Form<wokkel.data_form.Form>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
259
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
260 @param rsm: RSM request instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
261 @type rsm: L{RSMRequest<wokkel.rsm.RSMRequest>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
262
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
263 @param node: Pubsub node to query, or None if inappropriate.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
264 @type node: C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
265
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
266 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
267 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
268
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
269 @param query_id: Optional query id
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
270 @type query_id: C{unicode}
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
271
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
272 @return: A deferred that fires upon receiving a response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
273 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
274 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
275 iq = IQ(self.xmlstream, 'set')
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
276 MAMQueryRequest(form, rsm, node, query_id).render(iq)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
277 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
278 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
279 return iq.send(to=service.full() if service else None)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
280
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
281 def queryFields(self, service=None, sender=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
282 """Ask the server about additional supported fields.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
284 @param service: Entity offering the MAM service (None for user archives).
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
285 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
286
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
287 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
288 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
289
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
290 @return: data Form with the fields, or None if not found
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
291 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
292 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
293 # http://xmpp.org/extensions/xep-0313.html#query-form
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
294 iq = IQ(self.xmlstream, 'get')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
295 MAMQueryRequest().render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
296 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
297 iq['from'] = unicode(sender)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
298 d = iq.send(to=service.full() if service else None)
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
299 d.addCallback(lambda iq_result: iq_result.elements(NS_MAM, 'query').next())
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
300 d.addCallback(data_form.findForm, NS_MAM)
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
301 return d
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
302
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
303 def queryPrefs(self, service=None, sender=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
304 """Retrieve the current user preferences.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
305
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
306 @param service: Entity offering the MAM service (None for user archives).
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
307 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
308
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
309 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
310 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
311
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
312 @return: A deferred that fires upon receiving a response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
313 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
314 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
315 # http://xmpp.org/extensions/xep-0313.html#prefs
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
316 iq = IQ(self.xmlstream, 'get')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
317 MAMPrefs().render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
318 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
319 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
320 return iq.send(to=service.full() if service else None)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
321
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
322 def setPrefs(self, service=None, default='roster', always=None, never=None, sender=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
323 """Set new user preferences.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
324
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
325 @param service: Entity offering the MAM service (None for user archives).
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
326 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
327
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
328 @param default: A value in ('always', 'never', 'roster').
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
329 @type : C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
330
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
331 @param always (list): A list of JID instances.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
332 @type always: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
333
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
334 @param never (list): A list of JID instances.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
335 @type never: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
336
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
337 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
338 @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
339
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
340 @return: A deferred that fires upon receiving a response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
341 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
342 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
343 # http://xmpp.org/extensions/xep-0313.html#prefs
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
344 assert default is not None
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
345 iq = IQ(self.xmlstream, 'set')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
346 MAMPrefs(default, always, never).render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
347 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
348 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
349 return iq.send(to=service.full() if service else None)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
350
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
351
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
352 class IMAMResource(Interface):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
353
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
354 def onArchiveRequest(self, mam, requestor):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
355 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
356
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
357 @param mam: The MAM <query/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
358 @type mam: L{MAMQueryReques<wokkel.mam.MAMQueryRequest>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
359
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
360 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
361 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
362
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
363 @return: The RSM answer.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
364 @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
365 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
366
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
367 def onPrefsGetRequest(self, requestor):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
368 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
369
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
370 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
371 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
372
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
373 @return: The current settings.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
374 @rtype: L{wokkel.mam.MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
375 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
376
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
377 def onPrefsSetRequest(self, prefs, requestor):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
378 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
379
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
380 @param prefs: The new settings to set.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
381 @type prefs: L{wokkel.mam.MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
382
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
383 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
384 @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
385
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
386 @return: The new current settings.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
387 @rtype: L{wokkel.mam.MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
388 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
389
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
390
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
391 class MAMService(XMPPHandler, IQHandlerMixin):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
392 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
393 Protocol implementation for a MAM service.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
394
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
395 This handler waits for XMPP Ping requests and sends a response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
396 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
397
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
398 implements(disco.IDisco)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
399
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
400 iqHandlers = {FIELDS_REQUEST: '_onFieldsRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
401 ARCHIVE_REQUEST: '_onArchiveRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
402 PREFS_GET_REQUEST: '_onPrefsGetRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
403 PREFS_SET_REQUEST: '_onPrefsSetRequest'
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
404 }
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
405
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
406 _legacyFilters = {'start': {'fieldType': 'text-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
407 'var': 'start',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
408 'label': 'Starting time',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
409 'desc': 'Starting time a the result period.',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
410 },
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
411 'end': {'fieldType': 'text-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
412 'var': 'end',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
413 'label': 'Ending time',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
414 'desc': 'Ending time of the result period.',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
415 },
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
416 'with': {'fieldType': 'jid-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
417 'var': 'with',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
418 'label': 'Entity',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
419 'desc': 'Entity against which to match message.',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
420 },
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
421 }
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
422
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
423 def __init__(self, resource):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
424 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
425 @param resource: instance implementing IMAMResource
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
426 @type resource: L{object}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
427 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
428 self.resource = resource
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
429 self.extra_fields = {}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
430
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
431 def connectionInitialized(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
432 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
433 Called when the XML stream has been initialized.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
434
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
435 This sets up an observer for incoming ping requests.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
436 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
437 self.xmlstream.addObserver(FIELDS_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
438 self.xmlstream.addObserver(ARCHIVE_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
439 self.xmlstream.addObserver(PREFS_GET_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
440 self.xmlstream.addObserver(PREFS_SET_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
441
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
442 def addFilter(self, field):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
443 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
444 Add a new filter for querying MAM archive.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
445
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
446 @param field: data form field of the filter
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
447 @type field: L{Form<wokkel.data_form.Field>}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
448 """
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
449 self.extra_fields[field.var] = field
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
450
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
451 def _onFieldsRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
452 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
453 Called when a fields request has been received.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
454
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
455 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
456 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
457 response = toResponse(iq, 'result')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
458 query = response.addElement((NS_MAM, 'query'))
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
459 query.addChild(buildForm('form', extra=self.extra_fields).toElement())
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
460 self.xmlstream.send(response)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
461 iq.handled = True
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
462
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
463 def _onArchiveRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
464 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
465 Called when a message archive request has been received.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
466
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
467 This replies with the list of archived message and the <iq> result
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
468 @return: A tuple with list of message data (id, element, data) and RSM element
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
469 @rtype: C{tuple}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
470 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
471 mam_ = MAMQueryRequest.parse(iq.query)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
472 requestor = jid.JID(iq['from'])
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
473
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
474 # remove unsupported filters
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
475 unsupported_fields = []
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
476 if mam_.form:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
477 for key, field in mam_.form.fields.iteritems():
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
478 if key not in self._legacyFilters and key not in self.extra_fields:
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
479 log.msg('Ignored unsupported MAM filter: %s' % field)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
480 unsupported_fields.append(key)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
481 for key in unsupported_fields:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
482 del mam_.form.fields[key]
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
483
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
484 def forward_message(id_, elt, date):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
485 msg = domish.Element((None, 'message'))
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
486 msg['to'] = iq['from']
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
487 result = msg.addElement((NS_MAM, 'result'))
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
488 try:
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
489 result['queryid'] = iq.query['queryid']
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
490 except KeyError:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
491 pass
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
492 result['id'] = id_
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
493 forward = result.addElement((NS_FORWARD, 'forwarded'))
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
494 forward.addChild(delay.Delay(date).toElement())
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
495 forward.addChild(elt)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
496 self.xmlstream.send(msg)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
497
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
498 def cb(result):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
499 msg_data, rsm_elt = result
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
500 for data in msg_data:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
501 forward_message(*data)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
502
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
503 response = toResponse(iq, 'result')
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
504 fin = response.addElement((NS_MAM, 'fin'))
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
505
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
506 if rsm_elt is not None:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
507 fin.addChild(rsm_elt)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
508 self.xmlstream.send(response)
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
509
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
510 d = defer.maybeDeferred(self.resource.onArchiveRequest, mam_, requestor)
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
511 d.addCallback(cb)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
512 iq.handled = True
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
513
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
514 def _onPrefsGetRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
515 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
516 Called when a prefs get request has been received.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
517
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
518 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
519 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
520 response = toResponse(iq, 'result')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
521
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
522 requestor = jid.JID(iq['from'])
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
523
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
524 def cb(prefs):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
525 response.addChild(prefs.toElement())
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
526 self.xmlstream.send(response)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
527
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
528 self.resource.onPrefsGetRequest(requestor).addCallback(cb)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
529 iq.handled = True
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
530
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
531 def _onPrefsSetRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
532 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
533 Called when a prefs get request has been received.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
534
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
535 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
536 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
537 response = toResponse(iq, 'result')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
538
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
539 prefs = MAMPrefs.parse(iq.prefs)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
540 requestor = jid.JID(iq['from'])
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
541
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
542 def cb(prefs):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
543 response.addChild(prefs.toElement())
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
544 self.xmlstream.send(response)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
545
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
546 self.resource.onPrefsSetRequest(prefs, requestor).addCallback(cb)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
547 iq.handled = True
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
548
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
549 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
1413
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
550 if nodeIdentifier:
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
551 return []
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
552 return [disco.DiscoFeature(NS_MAM)]
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
553
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
554 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
555 return []
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
556
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
557
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
558 def datetime2utc(datetime):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
559 """Convert a datetime to a XEP-0082 compliant UTC datetime.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
560
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
561 @param datetime: Offset-aware timestamp to convert.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
562 @type datetime: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
563
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
564 @return: The datetime converted to UTC.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
565 @rtype: C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
566 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
567 stampFormat = '%Y-%m-%dT%H:%M:%SZ'
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
568 return datetime.astimezone(tzutc()).strftime(stampFormat)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
569
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
570
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
571 def buildForm(formType='submit', start=None, end=None, with_jid=None, extra_fields=None):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
572 """Prepare a Data Form for MAM.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
573
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
574 @param formType: The type of the Data Form ('submit' or 'form').
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
575 @type formType: C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
576
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
577 @param start: Offset-aware timestamp to filter out older messages.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
578 @type start: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
579
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
580 @param end: Offset-aware timestamp to filter out later messages.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
581 @type end: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
582
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
583 @param with_jid: JID against which to match messages.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
584 @type with_jid: L{JID<twisted.words.protocols.jabber.jid.JID>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
585
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
586 @param extra_fields: list of extra data form fields that are not defined by the
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
587 specification.
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
588 @type: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
589
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
590 @return: XEP-0004 Data Form object.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
591 @rtype: L{Form<wokkel.data_form.Form>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
592 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
593 form = data_form.Form(formType, formNamespace=NS_MAM)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
594
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
595 if formType == 'form':
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
596 for kwargs in MAMService._legacyFilters.values():
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
597 form.addField(data_form.Field(**kwargs))
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
598 elif formType == 'submit':
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
599 if start:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
600 form.addField(data_form.Field(var='start', value=datetime2utc(start)))
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
601 if end:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
602 form.addField(data_form.Field(var='end', value=datetime2utc(end)))
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
603 if with_jid:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
604 form.addField(data_form.Field(fieldType='jid-single', var='with', value=with_jid.full()))
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
605
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
606 if extra_fields is not None:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
607 for field in extra_fields:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
608 form.addField(field)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
609
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
610 return form