diff --git a/setup.py b/setup.py index dbdc943b..902c957e 100755 --- a/setup.py +++ b/setup.py @@ -72,6 +72,7 @@ packages = [ 'sleekxmpp', 'sleekxmpp/plugins/xep_0092', 'sleekxmpp/plugins/xep_0115', 'sleekxmpp/plugins/xep_0128', + 'sleekxmpp/plugins/xep_0184', 'sleekxmpp/plugins/xep_0199', 'sleekxmpp/plugins/xep_0202', 'sleekxmpp/plugins/xep_0203', diff --git a/sleekxmpp/plugins/xep_0184/__init__.py b/sleekxmpp/plugins/xep_0184/__init__.py new file mode 100644 index 00000000..15670562 --- /dev/null +++ b/sleekxmpp/plugins/xep_0184/__init__.py @@ -0,0 +1,10 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2012 Erik Reuterborg Larsson, Nathanael C. Fritz + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.xep_0184.reciept import xep_0184 +from sleekxmpp.plugins.xep_0184.stanza import Request, Received diff --git a/sleekxmpp/plugins/xep_0184/reciept.py b/sleekxmpp/plugins/xep_0184/reciept.py new file mode 100644 index 00000000..36105fd4 --- /dev/null +++ b/sleekxmpp/plugins/xep_0184/reciept.py @@ -0,0 +1,43 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2012 Erik Reuterborg Larsson, Nathanael C. Fritz + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.stanza import Message +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.plugins.base import base_plugin +from stanza import Request, Received + + +class xep_0184(base_plugin): + """ + XEP-0184: Message Delivery Receipts + """ + + def plugin_init(self): + self.xep = '0184' + self.description = 'Message Delivery Receipts' + register_stanza_plugin(Message, Request) + register_stanza_plugin(Message, Received) + + def post_init(self): + base_plugin.post_init(self) + self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:receipts') + + def ack(self, message): + """ + Acknowledges a message + + Arguments: + message -- The message to acknowledge. + """ + mto = message['to'] + mfrom = message['from'] + mid = message['id'] + msg = self.xmpp.make_message(mto=mfrom, mfrom=mto) + msg['reciept_received']['id'] = mid + msg['id'] = self.xmpp.new_id() + msg.send() diff --git a/sleekxmpp/plugins/xep_0184/stanza.py b/sleekxmpp/plugins/xep_0184/stanza.py new file mode 100644 index 00000000..42ba8c3f --- /dev/null +++ b/sleekxmpp/plugins/xep_0184/stanza.py @@ -0,0 +1,45 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2012 Erik Reuterborg Larsson, Nathanael C. Fritz + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream.stanzabase import ElementBase, ET + + +class Request(ElementBase): + namespace = 'urn:xmpp:receipts' + name = 'request' + plugin_attrib = 'request_reciept' + interfaces = set(('request_reciept',)) + is_extension = True + + def setup(self, xml=None): + self.xml = ET.Element('') + return True + + def set_request_reciept(self, val): + self.del_request_reciept() + parent = self.parent() + if val: + self.xml = ET.Element("{%s}%s" % (self.namespace, self.name)) + parent.append(self.xml) + + def get_request_reciept(self): + parent = self.parent() + if parent.find("{%s}%s" % (self.namespace, self.name)) is not None: + return True + else: + return False + + def del_request_reciept(self): + self.xml = ET.Element('') + + +class Received(ElementBase): + namespace = 'urn:xmpp:receipts' + name = 'received' + plugin_attrib = 'reciept_received' + interfaces = set(('id',)) diff --git a/tests/test_stanza_xep_0184.py b/tests/test_stanza_xep_0184.py new file mode 100644 index 00000000..e3668d3a --- /dev/null +++ b/tests/test_stanza_xep_0184.py @@ -0,0 +1,29 @@ +from sleekxmpp.test import * +import sleekxmpp.plugins.xep_0184 as xep_0184 + + +class TestReciept(SleekTest): + + def setUp(self): + register_stanza_plugin(Message, xep_0184.Request) + register_stanza_plugin(Message, xep_0184.Received) + + def testCreateRequest(self): + request = """""" + + msg = self.Message() + + self.assertEqual(msg['request_reciept'], False) + + msg['request_reciept'] = True + self.check(msg, request, use_values=False) + + def testCreateReceived(self): + received = """""" + + msg = self.Message() + msg['reciept_received']['id'] = '1' + + self.check(msg, received) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestReciept)