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