annotate src/tmp/wokkel/mam.py @ 2134:f45250052846

primitivus: fixed display of error if a message can't be sent
author Goffi <goffi@goffi.org>
date Sun, 05 Feb 2017 14:55:21 +0100
parents 3b75ab26f09b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1424
2d8fccec84e8 core (tests): test fixes
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
1 # -*- coding: utf-8 -*-
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- test-case-name: wokkel.test.test_mam -*-
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
3 #
1422
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
4 # SàT Wokkel extension for Message Archive Management (XEP-0313)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
5 # Copyright (C) 2015 Jérôme Poisson (goffi@goffi.org)
1422
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
6 # Copyright (C) 2015 Adien Cossa (souliane@mailoo.org)
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
7
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
8 # This program is free software: you can redistribute it and/or modify
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
11 # (at your option) any later version.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
12
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
13 # This program is distributed in the hope that it will be useful,
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
16 # GNU Affero General Public License for more details.
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
17
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
be1fccf4854d tmp (wokkel): licenses fixes:
Goffi <goffi@goffi.org>
parents: 1413
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
20
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
22 XMPP Message Archive Management protocol.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
23
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
24 This protocol is specified in
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
25 U{XEP-0313<http://xmpp.org/extensions/xep-0313.html>}.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
26 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
27
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
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
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
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
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.
1911
3b75ab26f09b tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents: 1785
diff changeset
91 @itype node: C{unicode}
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
92
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
93 @ivar query_id: id to use to track the query
1911
3b75ab26f09b tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents: 1785
diff changeset
94 @itype query_id: 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
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
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
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
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
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
143 if self.query_id is not None:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
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
1911
3b75ab26f09b tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents: 1785
diff changeset
181 def __init__(self, default=None, always=None, never=None):
3b75ab26f09b tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents: 1785
diff changeset
182 if default is not None:
3b75ab26f09b tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents: 1785
diff changeset
183 # default must be defined in response, but can be empty in request (see http://xmpp.org/extensions/xep-0313.html#config)
3b75ab26f09b tmp (wokkel/mam): restore MAMPrefs being callable without argument when constructing a query:
souliane <souliane@mailoo.org>
parents: 1785
diff changeset
184 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
185 self.default = default
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
186 if always is not None:
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
187 assert isinstance(always, list)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
188 else:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
189 always = []
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
190 self.always = always
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
191 if never is not None:
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
192 assert isinstance(never, list)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
193 else:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
194 never = []
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
195 self.never = never
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
196
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
197 @classmethod
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
198 def fromElement(cls, prefs_elt):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
199 """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
200
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
201 @param prefs_elt: MAM <prefs/> request element.
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
202 @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
203
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
204 @return: MAMPrefs instance.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
205 @rtype: L{MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
206 """
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
207 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
208 raise MAMError('Element provided is not a MAM <prefs/> request')
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
209 try:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
210 default = prefs_elt['default']
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
211 except KeyError:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
212 # FIXME: return proper error here
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
213 raise MAMError('Element provided is not a valid MAM <prefs/> request')
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
214
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
215 prefs = {}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
216 for attr in ('always', 'never'):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
217 prefs[attr] = []
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
218 try:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
219 pref = prefs_elt.elements(NS_MAM, attr).next()
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
220 except StopIteration:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
221 # FIXME: return proper error here
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
222 raise MAMError('Element provided is not a valid MAM <prefs/> request')
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
223 else:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
224 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
225 prefs[attr].append(jid.JID(jid_s))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
226 return MAMPrefs(default, **prefs)
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 def toElement(self):
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 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
231
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
232 @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
233 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
234 mam_elt = domish.Element((NS_MAM, 'prefs'))
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
235 if self.default:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
236 mam_elt['default'] = self.default
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
237 for attr in ('always', 'never'):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
238 attr_elt = mam_elt.addElement(attr)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
239 jids = getattr(self, attr)
1413
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
240 for jid_ in jids:
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
241 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
242 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
243
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
244 def render(self, parent):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
245 """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
246
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
247 @param parent: parent IQ element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
248 @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
249
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
250 @return: MAM request element.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
251 @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
252 """
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1422
diff changeset
253 assert parent.name == 'iq'
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
254 mam_elt = self.toElement()
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
255 parent.addChild(mam_elt)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
256 return mam_elt
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
257
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
258
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
259 class MAMClient(subprotocols.XMPPHandler):
1283
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 MAM client.
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 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
264 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
265
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
266 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
267 """Query a user, MUC or pubsub archive.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
268
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
269 @param mam_query: query to use
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
270 @type form: L{MAMRequest}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
271
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
272 @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
273 @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
274
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
275 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
276 @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
277
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
278 @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
279 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
280 """
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
281 iq = xmlstream.IQ(self.xmlstream, 'set')
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
282 mam_query.render(iq)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
283 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
284 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
285 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
286
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
287 def queryFields(self, service=None, sender=None):
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
288 """Ask the server about supported fields.
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
289
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
290 @param 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
291 @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
292
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
293 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
294 @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
295
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
296 @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
297 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
298 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
299 # 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
300 iq = xmlstream.IQ(self.xmlstream, 'get')
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
301 MAMRequest().render(iq)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
302 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
303 iq['from'] = unicode(sender)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
304 d = iq.send(to=service.full() if service else None)
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
305 d.addCallback(lambda iq_result: iq_result.elements(NS_MAM, 'query').next())
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
306 d.addCallback(data_form.findForm, NS_MAM)
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
307 return d
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
308
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
309 def queryPrefs(self, service=None, sender=None):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
310 """Retrieve the current user preferences.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
311
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
312 @param 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
313 @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
314
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
315 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
316 @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
317
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
318 @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
319 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
320 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
321 # 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
322 iq = xmlstream.IQ(self.xmlstream, 'get')
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
323 MAMPrefs().render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
324 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
325 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
326 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
327
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
328 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
329 """Set new user preferences.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
330
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
331 @param 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
332 @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
333
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
334 @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
335 @type : C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
336
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
337 @param always (list): A list of JID instances.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
338 @type always: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
339
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
340 @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
341 @type never: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
342
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
343 @param sender: Optional sender address.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
344 @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
345
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
346 @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
347 @rtype: L{Deferred<twisted.internet.defer.Deferred>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
348 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
349 # 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
350 assert default is not None
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
351 iq = xmlstream.IQ(self.xmlstream, 'set')
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
352 MAMPrefs(default, always, never).render(iq)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
353 if sender is not None:
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
354 iq['from'] = unicode(sender)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
355 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
356
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
357
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
358 class IMAMResource(Interface):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
359
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
360 def onArchiveRequest(self, mam):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
361 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
362
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
363 @param mam: The MAM <query/> request.
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
364 @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
365
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
366 @return: The RSM answer.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
367 @rtype: L{RSMResponse<wokkel.rsm.RSMResponse>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
368 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
369
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
370 def onPrefsGetRequest(self, requestor):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
371 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
372
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
373 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
374 @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
375
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
376 @return: The current settings.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
377 @rtype: L{wokkel.mam.MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
378 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
379
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
380 def onPrefsSetRequest(self, prefs, requestor):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
381 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
382
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
383 @param prefs: The new settings to set.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
384 @type prefs: L{wokkel.mam.MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
385
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
386 @param requestor: JID of the requestor.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
387 @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
388
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
389 @return: The new current settings.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
390 @rtype: L{wokkel.mam.MAMPrefs}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
391 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
392
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
393 class IMAMService(Interface):
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
394 """
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
395 Interface for XMPP MAM service.
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
396 """
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
397
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
398 def addFilter(self, field):
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 Add a new filter for querying MAM archive.
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
401
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
402 @param field: data form field of the filter
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
403 @type field: L{Form<wokkel.data_form.Field>}
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
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
406
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
407 class MAMService(subprotocols.XMPPHandler, subprotocols.IQHandlerMixin):
1283
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 Protocol implementation for a MAM service.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
410
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
411 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
412 """
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
413 implements(IMAMService, disco.IDisco)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
414
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
415 _request_class = MAMRequest
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
416
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
417 iqHandlers = {FIELDS_REQUEST: '_onFieldsRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
418 ARCHIVE_REQUEST: '_onArchiveRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
419 PREFS_GET_REQUEST: '_onPrefsGetRequest',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
420 PREFS_SET_REQUEST: '_onPrefsSetRequest'
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
421 }
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
422
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
423 _legacyFilters = {'start': {'fieldType': 'text-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
424 'var': 'start',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
425 'label': 'Starting time',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
426 'desc': 'Starting time a the result period.',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
427 },
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
428 'end': {'fieldType': 'text-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
429 'var': 'end',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
430 'label': 'Ending time',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
431 'desc': 'Ending time of the result period.',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
432 },
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
433 'with': {'fieldType': 'jid-single',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
434 'var': 'with',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
435 'label': 'Entity',
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
436 'desc': 'Entity against which to match message.',
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 }
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 def __init__(self, resource):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
441 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
442 @param resource: instance implementing IMAMResource
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
443 @type resource: L{object}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
444 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
445 self.resource = resource
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
446 self.extra_fields = {}
1283
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 def connectionInitialized(self):
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 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
451
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
452 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
453 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
454 self.xmlstream.addObserver(FIELDS_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
455 self.xmlstream.addObserver(ARCHIVE_REQUEST, self.handleRequest)
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
456 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
457 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
458
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
459 def addFilter(self, field):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
460 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
461 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
462
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
463 @param field: data form field of the filter
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
464 @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
465 """
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
466 self.extra_fields[field.var] = field
1283
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 def _onFieldsRequest(self, iq):
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 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
471
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
472 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
473 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
474 iq.handled = True
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
475 query = domish.Element((NS_MAM, 'query'))
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
476 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
477 return query
1283
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 def _onArchiveRequest(self, iq):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
480 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
481 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
482
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
483 This replies with the list of archived message and the <iq> result
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
484 @return: A tuple with list of message data (id, element, data) and RSM element
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
485 @rtype: C{tuple}
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
486 """
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
487 iq.handled = True
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
488 mam_ = self._request_class.fromElement(iq)
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
489
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
490 # remove unsupported filters
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
491 unsupported_fields = []
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
492 if mam_.form:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
493 for key, field in mam_.form.fields.iteritems():
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
494 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
495 log.msg('Ignored unsupported MAM filter: %s' % field)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
496 unsupported_fields.append(key)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
497 for key in unsupported_fields:
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
498 del mam_.form.fields[key]
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
499
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
500 def forwardMessage(id_, elt, date):
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
501 msg = domish.Element((None, 'message'))
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
502 msg['to'] = iq['from']
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
503 result = msg.addElement((NS_MAM, 'result'))
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
504 if mam_.query_id is not None:
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
505 result['queryid'] = mam_.query_id
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
506 result['id'] = id_
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
507 forward = result.addElement((NS_FORWARD, 'forwarded'))
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
508 forward.addChild(delay.Delay(date).toElement())
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
509 forward.addChild(elt)
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
510 self.xmlstream.send(msg)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
511
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
512 def cb(result):
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
513 msg_data, rsm_elt = result
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
514 for data in msg_data:
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
515 forwardMessage(*data)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
516
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
517 fin_elt = domish.Element((NS_MAM, 'fin'))
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
518
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
519 if rsm_elt is not None:
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
520 fin_elt.addChild(rsm_elt)
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
521 return fin_elt
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
522
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
523 d = defer.maybeDeferred(self.resource.onArchiveRequest, mam_)
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
524 d.addCallback(cb)
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
525 return d
1283
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 def _onPrefsGetRequest(self, iq):
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 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
530
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
531 This immediately replies with a result response.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
532 """
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
533 iq.handled = True
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
534 requestor = jid.JID(iq['from'])
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
535
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
536 def cb(prefs):
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
537 return prefs.toElement()
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
538
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
539 d = self.resource.onPrefsGetRequest(requestor).addCallback(cb)
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
540 return d
1283
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 def _onPrefsSetRequest(self, iq):
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 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
545
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
546 This immediately replies with a result response.
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 iq.handled = True
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
549
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
550 prefs = MAMPrefs.fromElement(iq.prefs)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
551 requestor = jid.JID(iq['from'])
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
552
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
553 def cb(prefs):
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
554 return prefs.toElement()
1286
d9939b476526 tmp: update wokkel MAM implementation
souliane <souliane@mailoo.org>
parents: 1285
diff changeset
555
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
556 d = self.resource.onPrefsSetRequest(prefs, requestor).addCallback(cb)
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
557 return d
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
558
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
559 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
560 if nodeIdentifier:
e5393b12dd0f tmp (mam): fixed name shadowing + getDiscoInfo for mam fix:
Goffi <goffi@goffi.org>
parents: 1286
diff changeset
561 return []
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
562 return [disco.DiscoFeature(NS_MAM)]
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
563
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
564 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
565 return []
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
566
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
567
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
568 def datetime2utc(datetime_obj):
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
569 """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
570
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
571 @param datetime_obj: Offset-aware timestamp to convert.
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
572 @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
573
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
574 @return: The datetime converted to UTC.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
575 @rtype: C{unicode}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
576 """
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
577 stampFormat = '%Y-%m-%dT%H:%M:%SZ'
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
578 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
579
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
580
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
581 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
582 """Prepare a Data Form for MAM.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
583
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
584 @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
585 @type start: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
586
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
587 @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
588 @type end: L{datetime<datetime.datetime>}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
589
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
590 @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
591 @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
592
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
593 @param extra_fields: list of extra data form fields that are not defined by the
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
594 specification.
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
595 @type: C{list}
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
596
1774
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
597 @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
598 @type formType: C{unicode}
0c21dafedd22 tmp (wokkel.mam): cleaning and bug fix:
Goffi <goffi@goffi.org>
parents: 1770
diff changeset
599
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
600 @return: XEP-0004 Data Form object.
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
601 @rtype: L{Form<wokkel.data_form.Form>}
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 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
604
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
605 if formType == 'form':
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
606 for kwargs in MAMService._legacyFilters.values():
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
607 form.addField(data_form.Field(**kwargs))
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
608 elif formType == 'submit':
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
609 if start:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
610 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
611 if end:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
612 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
613 if with_jid:
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
614 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
615
1770
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
616 if extra_fields is not None:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
617 for field in extra_fields:
f525c272fd6d tmp (mam): various improvments:
Goffi <goffi@goffi.org>
parents: 1424
diff changeset
618 form.addField(field)
1283
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
619
7d9ff14a2d9d tmp: update tmp.wokkel.rsm, add tmp.wokkel.mam
souliane <souliane@mailoo.org>
parents:
diff changeset
620 return form