annotate wokkel/mam.py @ 32:cfee3d472359

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