annotate src/tmp/wokkel/mam.py @ 1650:b08b828a87c9

quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
author Goffi <goffi@goffi.org>
date Mon, 23 Nov 2015 16:21:32 +0100
parents 2d8fccec84e8
children f525c272fd6d
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)
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
5 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org)
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
6
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
7 # 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
8 # 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
9 # the Free Software Foundation, either version 3 of the License, or
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
10 # (at your option) any later version.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
11
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
12 # 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
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
15 # GNU Affero General Public License for more details.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
16
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
17 # 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
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
19 #
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
20 # Copyright (c) Adrien Cossa.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
21 # See LICENSE for details.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
22
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 XMPP Message Archive Management protocol.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
25
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
26 This protocol is specified in
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
27 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
28 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
29
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from dateutil.tz import tzutc
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 zope.interface import Interface, implements
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
33
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
34 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
35 from twisted.words.xish import domish
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
36 from twisted.words.protocols.jabber import jid
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
37 from twisted.python import log
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
38
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
39 from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
40 from wokkel import disco, data_form, delay
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
41
1285
ed2c718bfe03 tmp, plugins: fixes the imports fron sat.tmp
souliane <souliane@mailoo.org>
parents: 1283
diff changeset
42 import rsm
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
43
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
44 NS_MAM = 'urn:xmpp:mam:0'
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
45 NS_FORWARD = 'urn:xmpp:forward:0'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
46
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
47 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
48 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
49 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
50 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
51
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
52 # TODO: add the tests!
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
55 class MAMError(Exception):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
56 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
57 MAM error.
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
61 class Unsupported(MAMError):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
62 def __init__(self, feature, text=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
63 self.feature = feature
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
64 MAMError.__init__(self, 'feature-not-implemented',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
65 'unsupported',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
66 feature,
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
67 text)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
68
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
69 def __str__(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
70 message = MAMError.__str__(self)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
71 message += ', feature %r' % self.feature
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
72 return message
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
75 class MAMQueryRequest():
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
76 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
77 A Message Archive Management <query/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
78
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
79 @ivar form: Data Form specifing the filters.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
80 @itype form: L{data_form.Form}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
81
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
82 @ivar rsm: RSM request instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
83 @itype rsm: L{rsm.RSMRequest}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
84
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
85 @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
86 @itype form: C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
87 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
88
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
89 def __init__(self, form=None, rsm_=None, node=None):
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
90 if form is not None:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
91 assert form.formType == 'submit'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
92 self.form = form
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
93 self.rsm = rsm_
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
94 self.node = node
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
95
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
96 @classmethod
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
97 def parse(cls, element):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
98 """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
99
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
100 @param element: MAM <query/> request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
101 @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
102
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
103 @return: MAMQueryRequest instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
104 @rtype: L{MAMQueryRequest}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
105 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
106 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
107 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
108 form = data_form.findForm(element, NS_MAM)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
109 try:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
110 rsm_request = rsm.RSMRequest.parse(element)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
111 except rsm.RSMNotFoundError:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
112 rsm_request = None
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
113 node = element['node'] if element.hasAttribute('node') else None
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
114 return MAMQueryRequest(form, rsm_request, node)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
115
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
116 def toElement(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
117 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
118 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
119
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
120 @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
121 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
122 mam_elt = domish.Element((NS_MAM, 'query'))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
123 if self.node is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
124 mam_elt['node'] = self.node
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
125 if self.form is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
126 mam_elt.addChild(self.form.toElement())
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
127 if self.rsm is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
128 mam_elt.addChild(self.rsm.toElement())
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
129
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
130 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
131
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
132 def render(self, parent):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
133 """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
134
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
135 @param parent: parent IQ element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
136 @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
137
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
138 @return: MAM request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
139 @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
140 """
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
141 assert parent.name == 'iq'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
142 mam_elt = self.toElement()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
143 parent.addChild(mam_elt)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
144 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
145
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
146
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
147 class MAMPrefs():
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
148 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
149 A Message Archive Management <prefs/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
150
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
151 @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
152 @type : C{unicode} or C{None}
1283
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 @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
155 @type always: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
156
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
157 @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
158 @type never: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
159 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
160
1424
2d8fccec84e8 core (tests): test fixes
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
161 def __init__(self, default=None, always=None, never=None):
2d8fccec84e8 core (tests): test fixes
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
162 if default is not None:
2d8fccec84e8 core (tests): test fixes
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
163 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
164 self.default = default
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
165 if always is not None:
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
166 assert isinstance(always, list)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
167 else:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
168 always = []
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
169 self.always = always
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
170 if never is not None:
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
171 assert isinstance(never, list)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
172 else:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
173 never = []
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
174 self.never = never
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
175
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
176 @classmethod
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
177 def parse(cls, element):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
178 """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
179
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
180 @param element: MAM <prefs/> request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
181 @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
182
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
183 @return: MAMPrefs instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
184 @rtype: L{MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
185 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
186 if element.uri != NS_MAM or element.name != 'prefs':
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
187 raise MAMError('Element provided is not a MAM <prefs/> request')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
188 default = element['default'] if element.hasAttribute('default') else None
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
189 prefs = {}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
190 for attr in ('always', 'never'):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
191 prefs[attr] = []
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
192 try:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
193 pref = domish.generateElementsNamed(element.elements(), attr).next()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
194 for jid_s in domish.generateElementsNamed(pref.elements(), 'jid'):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
195 prefs[attr].append(jid.JID(jid_s))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
196 except StopIteration:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
197 pass
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
198 return MAMPrefs(default, **prefs)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
199
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
200 def toElement(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
201 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
202 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
203
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
204 @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
205 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
206 mam_elt = domish.Element((NS_MAM, 'prefs'))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
207 if self.default:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
208 mam_elt['default'] = self.default
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
209 for attr in ('always', 'never'):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
210 attr_elt = mam_elt.addElement(attr)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
211 jids = getattr(self, attr)
1413
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
212 for jid_ in jids:
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
213 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
214 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
215
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
216 def render(self, parent):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
217 """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
218
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
219 @param parent: parent IQ element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
220 @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
221
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
222 @return: MAM request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
223 @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
224 """
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
225 assert parent.name == 'iq'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
226 mam_elt = self.toElement()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
227 parent.addChild(mam_elt)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
228 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
229
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
230
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
231 class MAMClient(XMPPHandler):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
232 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
233 MAM client.
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 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
236 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
237
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
238 def queryArchive(self, service=None, form=None, rsm=None, node=None, sender=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
239 """Query a user, MUC or pubsub archive.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
240
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
241 @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
242 @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
243
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
244 @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
245 @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
246
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
247 @param rsm: RSM request instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
248 @type rsm: L{RSMRequest<wokkel.rsm.RSMRequest>}
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 @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
251 @type node: C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
252
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
253 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
254 @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
255
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
256 @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
257 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
258 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
259 iq = IQ(self.xmlstream, 'set')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
260 MAMQueryRequest(form, rsm, node).render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
261 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
262 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
263 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
264
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
265 def queryFields(self, service=None, sender=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
266 """Ask the server about additional supported fields.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
267
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
268 @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
269 @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
270
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
271 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
272 @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
273
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
274 @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
275 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
276 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
277 # 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
278 iq = IQ(self.xmlstream, 'get')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
279 MAMQueryRequest().render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
280 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
281 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
282 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
283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
284 def queryPrefs(self, service=None, sender=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
285 """Retrieve the current user preferences.
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 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
288 @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
289
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
290 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
291 @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
292
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
293 @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
294 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
295 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
296 # 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
297 iq = IQ(self.xmlstream, 'get')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
298 MAMPrefs().render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
299 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
300 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
301 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
302
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
303 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
304 """Set new 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 default: A value in ('always', 'never', 'roster').
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
310 @type : C{unicode}
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 @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
313 @type always: C{list}
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 @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
316 @type never: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
317
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
318 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
319 @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
320
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
321 @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
322 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
323 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
324 # 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
325 assert default is not None
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
326 iq = IQ(self.xmlstream, 'set')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
327 MAMPrefs(default, always, never).render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
328 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
329 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
330 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
331
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
332
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
333 class IMAMResource(Interface):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
334
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
335 def onArchiveRequest(self, mam, requestor):
1283
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
338 @param mam: The MAM <query/> request.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
339 @type mam: L{MAMQueryReques<wokkel.mam.MAMQueryRequest>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
340
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
341 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
342 @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
343
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
344 @return: The RSM answer.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
345 @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
346 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
347
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
348 def onPrefsGetRequest(self, requestor):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
349 """
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 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
352 @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
353
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
354 @return: The current settings.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
355 @rtype: L{wokkel.mam.MAMPrefs}
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
358 def onPrefsSetRequest(self, prefs, requestor):
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
361 @param prefs: The new settings to set.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
362 @type prefs: L{wokkel.mam.MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
363
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
364 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
365 @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
366
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
367 @return: The new current settings.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
368 @rtype: L{wokkel.mam.MAMPrefs}
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
371
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
372 class MAMService(XMPPHandler, IQHandlerMixin):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
373 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
374 Protocol implementation for a MAM service.
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 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
377 """
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 implements(disco.IDisco)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
380
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
381 iqHandlers = {FIELDS_REQUEST: '_onFieldsRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
382 ARCHIVE_REQUEST: '_onArchiveRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
383 PREFS_GET_REQUEST: '_onPrefsGetRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
384 PREFS_SET_REQUEST: '_onPrefsSetRequest'
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
387 _legacyFilters = {'start': {'fieldType': 'text-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
388 'var': 'start',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
389 'label': 'Starting time',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
390 'desc': 'Starting time a the result period.',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
391 },
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
392 'end': {'fieldType': 'text-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
393 'var': 'end',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
394 'label': 'Ending time',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
395 'desc': 'Ending time of the result period.',
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 'with': {'fieldType': 'jid-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
398 'var': 'with',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
399 'label': 'Entity',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
400 'desc': 'Entity against which to match message.',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
401 },
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
402 }
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
403
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
404 def __init__(self, resource):
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 @param resource: instance implementing IMAMResource
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
407 @type resource: L{object}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
408 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
409 self.resource = resource
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
410 self.extra_filters = {}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
411
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
412 def connectionInitialized(self):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
413 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
414 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
415
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
416 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
417 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
418 self.xmlstream.addObserver(FIELDS_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
419 self.xmlstream.addObserver(ARCHIVE_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
420 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
421 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
422
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
423 def addFilter(self, field):
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 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
426
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
427 @param field: dictionary specifying the attributes to build a
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
428 wokkel.data_form.Field.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
429 @type field: C{dict}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
430 """
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
431 self.extra_filters[field.var] = field
1283
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 def _onFieldsRequest(self, iq):
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 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
436
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
437 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
438 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
439 response = toResponse(iq, 'result')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
440 query = response.addElement((NS_MAM, 'query'))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
441 query.addChild(buildForm('form', extra=self.extra_filters).toElement())
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
442 self.xmlstream.send(response)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
443 iq.handled = True
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
444
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
445 def _onArchiveRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
446 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
447 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
448
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
449 This immediately replies with a result response, followed by the
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
450 list of archived message and the finally the <fin/> message.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
451 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
452 response = toResponse(iq, 'result')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
453 self.xmlstream.send(response)
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 mam_ = MAMQueryRequest.parse(iq.query)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
456 requestor = jid.JID(iq['from'])
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
457
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
458 # remove unsupported filters
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
459 unsupported_fields = []
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
460 if mam_.form:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
461 for key, field in mam_.form.fields.iteritems():
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
462 if key not in self._legacyFilters and key not in self.extra_filters:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
463 log.msg('Ignored unsupported MAM filter: %s' % field)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
464 unsupported_fields.append(key)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
465 for key in unsupported_fields:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
466 del mam_.form.fields[key]
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
467
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
468 def forward_message(id_, elt, date):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
469 msg = domish.Element((None, 'message'))
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
470 msg['to'] = iq['from']
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
471 result = msg.addElement('result', NS_MAM)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
472 if iq.hasAttribute('queryid'):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
473 result['queryid'] = iq.query['queryid']
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
474 result['id'] = id_
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
475 forward = result.addElement('forwarded', NS_FORWARD)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
476 forward.addChild(delay.Delay(date).toElement())
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
477 forward.addChild(elt)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
478 self.xmlstream.send(msg)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
479
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
480 def cb(result):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
481 msg_data, rsm_elt = result
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
482 for data in msg_data:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
483 forward_message(*data)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
484 msg = domish.Element((None, 'message'))
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
485 msg['to'] = iq['from']
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
486 fin = msg.addElement('fin', NS_MAM)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
487 if iq.hasAttribute('queryid'):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
488 fin['queryid'] = iq.query['queryid']
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
489 if rsm_elt is not None:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
490 fin.addChild(rsm_elt)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
491 self.xmlstream.send(msg)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
492
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
493 self.resource.onArchiveRequest(mam_, requestor).addCallback(cb)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
494 iq.handled = True
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
495
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
496 def _onPrefsGetRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
497 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
498 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
499
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
500 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
501 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
502 response = toResponse(iq, 'result')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
503
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
504 requestor = jid.JID(iq['from'])
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
505
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
506 def cb(prefs):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
507 response.addChild(prefs.toElement())
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
508 self.xmlstream.send(response)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
509
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
510 self.resource.onPrefsGetRequest(requestor).addCallback(cb)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
511 iq.handled = True
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
512
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
513 def _onPrefsSetRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
514 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
515 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
516
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
517 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
518 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
519 response = toResponse(iq, 'result')
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
520
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
521 prefs = MAMPrefs.parse(iq.prefs)
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.onPrefsSetRequest(prefs, 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 getDiscoInfo(self, requestor, target, nodeIdentifier=''):
1413
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
532 if nodeIdentifier:
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
533 return []
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
534 return [disco.DiscoFeature(NS_MAM)]
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
535
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
536 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
537 return []
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
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
540 def datetime2utc(datetime):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
541 """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
542
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
543 @param datetime: Offset-aware timestamp to convert.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
544 @type datetime: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
545
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
546 @return: The datetime converted to UTC.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
547 @rtype: C{unicode}
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 stampFormat = '%Y-%m-%dT%H:%M:%SZ'
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
550 return datetime.astimezone(tzutc()).strftime(stampFormat)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
551
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
552
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
553 def buildForm(formType='submit', start=None, end=None, with_jid=None, extra=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
554 """Prepare a Data Form for MAM.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
555
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
556 @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
557 @type formType: C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
558
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
559 @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
560 @type start: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
561
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
562 @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
563 @type end: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
564
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
565 @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
566 @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
567
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
568 @param extra: list of extra fields that are not defined by the
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
569 specification. Each element of the list must be a dictionary
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
570 specifying the attributes to build a wokkel.data_form.Field.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
571 @type: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
572
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
573 @return: XEP-0004 Data Form object.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
574 @rtype: L{Form<wokkel.data_form.Form>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
575 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
576 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
577 filters = []
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
578
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
579 if formType == 'form':
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
580 filters.extend(MAMService._legacyFilters.values())
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
581 elif formType == 'submit':
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
582 if start:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
583 filters.append({'var': 'start', 'value': datetime2utc(start)})
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
584 if end:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
585 filters.append({'var': 'end', 'value': datetime2utc(end)})
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
586 if with_jid:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
587 # must specify the field type to overwrite default value in Field.__init__
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
588 filters.append({'fieldType': 'jid-single', 'var': 'with', 'value': with_jid.full()})
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 if extra is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
591 filters.extend(extra)
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 for field in filters:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
594 form.addField(data_form.Field(**field))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
595
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
596 return form