summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0184/reciept.py
blob: d5815981a16e567f4f5e3651fcdc1b253de584b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Erik Reuterborg Larsson
    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()