Mercurial > libervia-backend
annotate src/tmp/wokkel/mam.py @ 1423:882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
- renamed variables nammed after reserved word/module
- removed class variables which are not needed
- removed external parenthesis from asserts
- in mam.MAMPrefs, removed default value for default argument, as None can't be used
- (groupblog) extended docstring for DeferredItems and DeferredItemsFromMany
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 23 Apr 2015 13:35:21 +0200 |
parents | be1fccf4854d |
children | 2d8fccec84e8 |
rev | line source |
---|---|
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 # -*- test-case-name: wokkel.test.test_mam -*- |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # |
1422 | 3 # SàT Wokkel extension for Message Archive Management (XEP-0313) |
4 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 # | |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 # Copyright (c) Adrien Cossa. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 # See LICENSE for details. |
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 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 XMPP Message Archive Management protocol. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 This protocol is specified in |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 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
|
27 """ |
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 from dateutil.tz import tzutc |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
30 |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 from zope.interface import Interface, implements |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
32 |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 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
|
34 from twisted.words.xish import domish |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 from twisted.words.protocols.jabber import jid |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 NS_MAM = 'urn:xmpp:mam:0' |
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} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
88 def __init__(self, form=None, rsm_=None, node=None): |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
89 if form is not None: |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
90 assert form.formType == 'submit' |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 self.form = form |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
92 self.rsm = rsm_ |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 self.node = node |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 @classmethod |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 def parse(cls, element): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 """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
|
98 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 @param element: MAM <query/> request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 @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
|
101 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 @return: MAMQueryRequest instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 @rtype: L{MAMQueryRequest} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 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
|
106 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
|
107 form = data_form.findForm(element, NS_MAM) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 try: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 rsm_request = rsm.RSMRequest.parse(element) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 except rsm.RSMNotFoundError: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 rsm_request = None |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 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
|
113 return MAMQueryRequest(form, rsm_request, node) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
114 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 def toElement(self): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
116 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
117 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
|
118 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
119 @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
|
120 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 mam_elt = domish.Element((NS_MAM, 'query')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 if self.node is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 mam_elt['node'] = self.node |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 if self.form is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 mam_elt.addChild(self.form.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 if self.rsm is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 mam_elt.addChild(self.rsm.toElement()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 def render(self, parent): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 """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
|
133 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 @param parent: parent IQ element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 @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
|
136 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 @return: MAM request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 @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
|
139 """ |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
140 assert parent.name == 'iq' |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 mam_elt = self.toElement() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 parent.addChild(mam_elt) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 return mam_elt |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 class MAMPrefs(): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 A Message Archive Management <prefs/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 @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
|
151 @type : C{unicode} or C{None} |
1283
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 @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
|
154 @type always: C{list} |
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 @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
|
157 @type never: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
160 def __init__(self, default, always=None, never=None): |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
161 assert default in ('always', 'never', 'roster') |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
162 self.default = default |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
163 if always is not None: |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
164 assert isinstance(always, list) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 else: |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
166 always = [] |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
167 self.always = always |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
168 if never is not None: |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
169 assert isinstance(never, list) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 else: |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
171 never = [] |
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
172 self.never = never |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 @classmethod |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 def parse(cls, element): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 """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
|
177 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
178 @param element: MAM <prefs/> request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 @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
|
180 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 @return: MAMPrefs instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 @rtype: L{MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 prefs = {} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 for attr in ('always', 'never'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
189 prefs[attr] = [] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 try: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
191 pref = domish.generateElementsNamed(element.elements(), attr).next() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 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
|
193 prefs[attr].append(jid.JID(jid_s)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 except StopIteration: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 pass |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 return MAMPrefs(default, **prefs) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 def toElement(self): |
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 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
|
201 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 @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
|
203 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 mam_elt = domish.Element((NS_MAM, 'prefs')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 if self.default: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 mam_elt['default'] = self.default |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 for attr in ('always', 'never'): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 attr_elt = mam_elt.addElement(attr) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
209 jids = getattr(self, attr) |
1413
e5393b12dd0f
tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents:
1286
diff
changeset
|
210 for jid_ in jids: |
e5393b12dd0f
tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents:
1286
diff
changeset
|
211 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
|
212 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 def render(self, parent): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 """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
|
216 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 @param parent: parent IQ element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 @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
|
219 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 @return: MAM request element. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 @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
|
222 """ |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
223 assert parent.name == 'iq' |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 mam_elt = self.toElement() |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 parent.addChild(mam_elt) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 return mam_elt |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 |
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 class MAMClient(XMPPHandler): |
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 MAM client. |
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 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
|
234 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 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
|
237 """Query a user, MUC or pubsub archive. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
238 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 @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
|
240 @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
|
241 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 @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
|
243 @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
|
244 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 @param rsm: RSM request instance. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 @type rsm: L{RSMRequest<wokkel.rsm.RSMRequest>} |
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 @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
|
249 @type node: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 @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
|
253 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 @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
|
255 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
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 iq = IQ(self.xmlstream, 'set') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
258 MAMQueryRequest(form, rsm, node).render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 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
|
262 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 def queryFields(self, service=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 """Ask the server about additional supported fields. |
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 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
|
267 @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
|
268 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 @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
|
271 |
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 # 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
|
276 iq = IQ(self.xmlstream, 'get') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 MAMQueryRequest().render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 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
|
281 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 def queryPrefs(self, service=None, sender=None): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 """Retrieve the current user preferences. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 @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
|
286 @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
|
287 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 @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
|
290 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
291 @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
|
292 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
293 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 # 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
|
295 iq = IQ(self.xmlstream, 'get') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 MAMPrefs().render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 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
|
300 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 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
|
302 """Set new user preferences. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 @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
|
305 @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
|
306 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 @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
|
308 @type : C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 @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
|
311 @type always: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 @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
|
314 @type never: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 @param sender: Optional sender address. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 @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
|
318 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 @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
|
320 @rtype: L{Deferred<twisted.internet.defer.Deferred>} |
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 # 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
|
323 assert default is not None |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
324 iq = IQ(self.xmlstream, 'set') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 MAMPrefs(default, always, never).render(iq) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
326 if sender is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 iq['from'] = unicode(sender) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 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
|
329 |
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 class IMAMResource(Interface): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
333 def onArchiveRequest(self, mam, requestor): |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 @param mam: The MAM <query/> request. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 @type mam: L{MAMQueryReques<wokkel.mam.MAMQueryRequest>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
339 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 @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
|
341 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 @return: The RSM answer. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 def onPrefsGetRequest(self, requestor): |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 @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
|
351 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
352 @return: The current settings. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 @rtype: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 """ |
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 def onPrefsSetRequest(self, prefs, requestor): |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 @param prefs: The new settings to set. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
360 @type prefs: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 @param requestor: JID of the requestor. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 @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
|
364 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 @return: The new current settings. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 @rtype: L{wokkel.mam.MAMPrefs} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 """ |
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 class MAMService(XMPPHandler, IQHandlerMixin): |
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 Protocol implementation for a MAM service. |
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 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
|
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 implements(disco.IDisco) |
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 iqHandlers = {FIELDS_REQUEST: '_onFieldsRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 ARCHIVE_REQUEST: '_onArchiveRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 PREFS_GET_REQUEST: '_onPrefsGetRequest', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
382 PREFS_SET_REQUEST: '_onPrefsSetRequest' |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
383 } |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 _legacyFilters = {'start': {'fieldType': 'text-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 'var': 'start', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
387 'label': 'Starting time', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
388 'desc': 'Starting time a the result period.', |
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 'end': {'fieldType': 'text-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
391 'var': 'end', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
392 'label': 'Ending time', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
393 'desc': 'Ending time of the result period.', |
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 'with': {'fieldType': 'jid-single', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
396 'var': 'with', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
397 'label': 'Entity', |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
398 'desc': 'Entity against which to match message.', |
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 } |
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 def __init__(self, resource): |
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 @param resource: instance implementing IMAMResource |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
405 @type resource: L{object} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
406 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 self.resource = resource |
1423
882e5fabf68c
plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents:
1422
diff
changeset
|
408 self.extra_filters = {} |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
409 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
410 def connectionInitialized(self): |
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 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
|
413 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
414 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
|
415 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
416 self.xmlstream.addObserver(FIELDS_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 self.xmlstream.addObserver(ARCHIVE_REQUEST, self.handleRequest) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 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
|
419 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
|
420 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
421 def addFilter(self, field): |
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 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
|
424 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 @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
|
426 wokkel.data_form.Field. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
427 @type field: C{dict} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 """ |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
429 self.extra_filters[field.var] = field |
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 _onFieldsRequest(self, iq): |
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 a fields request has been received. |
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 immediately replies with a result response. |
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 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
438 query = response.addElement((NS_MAM, 'query')) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 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
|
440 self.xmlstream.send(response) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
441 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
442 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
443 def _onArchiveRequest(self, iq): |
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 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
|
446 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 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
|
448 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
|
449 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
450 response = toResponse(iq, 'result') |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
451 self.xmlstream.send(response) |
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 mam_ = MAMQueryRequest.parse(iq.query) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
454 requestor = jid.JID(iq['from']) |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
455 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
456 # remove unsupported filters |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
457 unsupported_fields = [] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
458 if mam_.form: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
459 for key, field in mam_.form.fields.iteritems(): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
460 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
|
461 log.msg('Ignored unsupported MAM filter: %s' % field) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
462 unsupported_fields.append(key) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
463 for key in unsupported_fields: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
464 del mam_.form.fields[key] |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
465 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
466 def forward_message(id_, elt, date): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
467 msg = domish.Element((None, 'message')) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
468 msg['to'] = iq['from'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
469 result = msg.addElement('result', NS_MAM) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
470 if iq.hasAttribute('queryid'): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
471 result['queryid'] = iq.query['queryid'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
472 result['id'] = id_ |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
473 forward = result.addElement('forwarded', NS_FORWARD) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
474 forward.addChild(delay.Delay(date).toElement()) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
475 forward.addChild(elt) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
476 self.xmlstream.send(msg) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
477 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
478 def cb(result): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
479 msg_data, rsm_elt = result |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
480 for data in msg_data: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
481 forward_message(*data) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
482 msg = domish.Element((None, 'message')) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
483 msg['to'] = iq['from'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
484 fin = msg.addElement('fin', NS_MAM) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
485 if iq.hasAttribute('queryid'): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
486 fin['queryid'] = iq.query['queryid'] |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
487 if rsm_elt is not None: |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
488 fin.addChild(rsm_elt) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
489 self.xmlstream.send(msg) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
490 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
491 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
|
492 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
493 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
494 def _onPrefsGetRequest(self, iq): |
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 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
|
497 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
498 This immediately replies with a result response. |
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 response = toResponse(iq, 'result') |
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 requestor = jid.JID(iq['from']) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
503 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
504 def cb(prefs): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
505 response.addChild(prefs.toElement()) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
506 self.xmlstream.send(response) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
507 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
508 self.resource.onPrefsGetRequest(requestor).addCallback(cb) |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
509 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
510 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
511 def _onPrefsSetRequest(self, iq): |
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 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
|
514 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
515 This immediately replies with a result response. |
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 response = toResponse(iq, 'result') |
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 prefs = MAMPrefs.parse(iq.prefs) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
520 requestor = jid.JID(iq['from']) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
521 |
1286
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
522 def cb(prefs): |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
523 response.addChild(prefs.toElement()) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
524 self.xmlstream.send(response) |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
525 |
d9939b476526
tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents:
1285
diff
changeset
|
526 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
|
527 iq.handled = True |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
528 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
529 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
|
530 if nodeIdentifier: |
e5393b12dd0f
tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents:
1286
diff
changeset
|
531 return [] |
1283
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
532 return [disco.DiscoFeature(NS_MAM)] |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
533 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
534 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
535 return [] |
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 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
538 def datetime2utc(datetime): |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
539 """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
|
540 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
541 @param datetime: Offset-aware timestamp to convert. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
542 @type datetime: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
543 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
544 @return: The datetime converted to UTC. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
545 @rtype: C{unicode} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
546 """ |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
547 stampFormat = '%Y-%m-%dT%H:%M:%SZ' |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
548 return datetime.astimezone(tzutc()).strftime(stampFormat) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
549 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
550 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
551 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
|
552 """Prepare a Data Form for 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 @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
|
555 @type formType: C{unicode} |
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 @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
|
558 @type start: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
559 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
560 @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
|
561 @type end: L{datetime<datetime.datetime>} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
562 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
563 @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
|
564 @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
|
565 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
566 @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
|
567 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
|
568 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
|
569 @type: C{list} |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
570 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
571 @return: XEP-0004 Data Form object. |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
572 @rtype: L{Form<wokkel.data_form.Form>} |
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 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
|
575 filters = [] |
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 if formType == 'form': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
578 filters.extend(MAMService._legacyFilters.values()) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
579 elif formType == 'submit': |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
580 if start: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
581 filters.append({'var': 'start', 'value': datetime2utc(start)}) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
582 if end: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
583 filters.append({'var': 'end', 'value': datetime2utc(end)}) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
584 if with_jid: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
585 # 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
|
586 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
|
587 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
588 if extra is not None: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
589 filters.extend(extra) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
590 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
591 for field in filters: |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
592 form.addField(data_form.Field(**field)) |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
593 |
7d9ff14a2d9d
tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
594 return form |