summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0313/mam.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-09-25 20:20:43 -0700
committerLance Stout <lancestout@gmail.com>2012-09-25 20:20:43 -0700
commitef974114ea375729a01553cb18dc30aa9d6531c9 (patch)
tree944f4a2d76b324f37fe268bf026dd45a9077eb96 /sleekxmpp/plugins/xep_0313/mam.py
parentf6e1fecdf8e173e9eade7ade1e6b397cf4b8635d (diff)
downloadslixmpp-ef974114ea375729a01553cb18dc30aa9d6531c9.tar.gz
slixmpp-ef974114ea375729a01553cb18dc30aa9d6531c9.tar.bz2
slixmpp-ef974114ea375729a01553cb18dc30aa9d6531c9.tar.xz
slixmpp-ef974114ea375729a01553cb18dc30aa9d6531c9.zip
Add support for XEP-0313: Message Archive Management
NOTE: XEP-0313 is still very experimental, and there will likely be API changes in the future.
Diffstat (limited to 'sleekxmpp/plugins/xep_0313/mam.py')
-rw-r--r--sleekxmpp/plugins/xep_0313/mam.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/xep_0313/mam.py b/sleekxmpp/plugins/xep_0313/mam.py
new file mode 100644
index 00000000..15aee828
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0313/mam.py
@@ -0,0 +1,92 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permissio
+"""
+
+import logging
+
+import sleekxmpp
+from sleekxmpp.stanza import Message, Iq
+from sleekxmpp.exceptions import XMPPError
+from sleekxmpp.xmlstream.handler import Collector
+from sleekxmpp.xmlstream.matcher import StanzaPath
+from sleekxmpp.xmlstream import register_stanza_plugin
+from sleekxmpp.plugins import BasePlugin
+from sleekxmpp.plugins.xep_0313 import stanza
+
+
+log = logging.getLogger(__name__)
+
+
+class XEP_0313(BasePlugin):
+
+ """
+ XEP-0313 Message Archive Management
+ """
+
+ name = 'xep_0313'
+ description = 'XEP-0313: Message Archive Management'
+ dependencies = set(['xep_0030', 'xep_0050', 'xep_0059', 'xep_0297'])
+ stanza = stanza
+
+ def plugin_init(self):
+ register_stanza_plugin(Iq, stanza.MAM)
+ register_stanza_plugin(Iq, stanza.Preferences)
+ register_stanza_plugin(Message, stanza.Result)
+ register_stanza_plugin(stanza.MAM, self.xmpp['xep_0059'].stanza.Set)
+
+ def retrieve(self, jid=None, start=None, end=None, with_jid=None, ifrom=None,
+ block=True, timeout=None, callback=None, iterator=False):
+ iq = self.xmpp.Iq()
+ query_id = iq['id']
+
+ iq['to'] = jid
+ iq['from'] = ifrom
+ iq['type'] = 'get'
+ iq['mam']['queryid'] = query_id
+ iq['mam']['start'] = start
+ iq['mam']['end'] = end
+ iq['mam']['with'] = with_jid
+
+ collector = Collector(
+ 'MAM_Results_%s' % query_id,
+ StanzaPath('message/mam_result@queryid=%s' % query_id))
+ self.xmpp.register_handler(collector)
+
+ if iterator:
+ return self.xmpp['xep_0059'].iterate(iq, 'mam', 'results')
+ elif not block and callback is not None:
+ def wrapped_cb(iq):
+ results = collector.stop()
+ if iq['type'] == 'result':
+ iq['mam']['results'] = results
+ callback(iq)
+ return iq.send(block=block, timeout=timeout, callback=wrapped_cb)
+ else:
+ try:
+ resp = iq.send(block=block, timeout=timeout, callback=callback)
+ resp['mam']['results'] = collector.stop()
+ return resp
+ except XMPPError as e:
+ collector.stop()
+ raise e
+
+ def set_preferences(self, jid=None, default=None, always=None, never=None,
+ ifrom=None, block=True, timeout=None, callback=None):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'set'
+ iq['to'] = jid
+ iq['from'] = ifrom
+ iq['mam_prefs']['default'] = default
+ iq['mam_prefs']['always'] = always
+ iq['mam_prefs']['never'] = never
+ return iq.send(block=block, timeout=timeout, callback=callback)
+
+ def get_configuration_commands(self, jid, **kwargs):
+ return self.xmpp['xep_0030'].get_items(
+ jid=jid,
+ node='urn:xmpp:mam#configure',
+ **kwargs)