2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permissio
12 from slixmpp
.stanza
import Message
, Iq
13 from slixmpp
.exceptions
import XMPPError
14 from slixmpp
.xmlstream
.handler
import Collector
15 from slixmpp
.xmlstream
.matcher
import StanzaPath
16 from slixmpp
.xmlstream
import register_stanza_plugin
17 from slixmpp
.plugins
import BasePlugin
18 from slixmpp
.plugins
.xep_0013
import stanza
21 log
= logging
.getLogger(__name__
)
24 class XEP_0013(BasePlugin
):
27 XEP-0013 Flexible Offline Message Retrieval
31 description
= 'XEP-0013: Flexible Offline Message Retrieval'
32 dependencies
= set(['xep_0030'])
35 def plugin_init(self
):
36 register_stanza_plugin(Iq
, stanza
.Offline
)
37 register_stanza_plugin(Message
, stanza
.Offline
)
39 def get_count(self
, **kwargs
):
40 return self
.xmpp
['xep_0030'].get_info(
41 node
='http://jabber.org/protocol/offline',
45 def get_headers(self
, **kwargs
):
46 return self
.xmpp
['xep_0030'].get_items(
47 node
='http://jabber.org/protocol/offline',
51 def view(self
, nodes
, ifrom
=None, timeout
=None, callback
=None,
52 timeout_callback
=None):
53 if not isinstance(nodes
, (list, set)):
59 offline
= iq
['offline']
63 item
['action'] = 'view'
66 collector
= Collector(
67 'Offline_Results_%s' % iq
['id'],
68 StanzaPath('message/offline'))
69 self
.xmpp
.register_handler(collector
)
72 results
= collector
.stop()
73 if iq
['type'] == 'result':
74 iq
['offline']['results'] = results
76 iq
.send(timeout
=timeout
, callback
=wrapped_cb
,
77 timeout_callback
=timeout_callback
)
79 def remove(self
, nodes
, ifrom
=None, timeout
=None, callback
=None,
80 timeout_callback
=None):
81 if not isinstance(nodes
, (list, set)):
87 offline
= iq
['offline']
91 item
['action'] = 'remove'
94 iq
.send(timeout
=timeout
, callback
=callback
,
95 timeout_callback
=timeout_callback
)
97 def fetch(self
, ifrom
=None, timeout
=None, callback
=None,
98 timeout_callback
=None):
102 iq
['offline']['fetch'] = True
104 collector
= Collector(
105 'Offline_Results_%s' % iq
['id'],
106 StanzaPath('message/offline'))
107 self
.xmpp
.register_handler(collector
)
110 results
= collector
.stop()
111 if iq
['type'] == 'result':
112 iq
['offline']['results'] = results
114 iq
.send(timeout
=timeout
, callback
=wrapped_cb
,
115 timeout_callback
=timeout_callback
)
117 def purge(self
, ifrom
=None, timeout
=None, callback
=None,
118 timeout_callback
=None):
122 iq
['offline']['purge'] = True
123 iq
.send(timeout
=timeout
, callback
=callback
,
124 timeout_callback
=timeout_callback
)