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