summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0184/stanza.py
blob: a7607035be0d86a758dbc0159ad8c05009a7960c (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
    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_receipt'
    interfaces = set(('request_receipt',))
    sub_interfaces = interfaces
    is_extension = True

    def setup(self, xml=None):
        self.xml = ET.Element('')
        return True

    def set_request_receipt(self, val):
        self.del_request_receipt()
        if val:
            parent = self.parent()
            parent._set_sub_text("{%s}request" % self.namespace, keep=True)
            if not parent['id']:
                if parent.stream:
                    parent['id'] = parent.stream.new_id()

    def get_request_receipt(self):
        parent = self.parent()
        if parent.find("{%s}request" % self.namespace) is not None:
            return True
        else:
            return False

    def del_request_receipt(self):
        self.parent()._del_sub("{%s}request" % self.namespace)


class Received(ElementBase):
    namespace = 'urn:xmpp:receipts'
    name = 'received'
    plugin_attrib = 'receipt'
    interfaces = set(['receipt'])
    sub_interfaces = interfaces
    is_extension = True

    def setup(self, xml=None):
        self.xml = ET.Element('')
        return True

    def set_receipt(self, value):
        self.del_receipt()
        if value:
            parent = self.parent()
            xml = ET.Element("{%s}received" % self.namespace)
            xml.attrib['id'] = value
            parent.append(xml)

    def get_receipt(self):
        parent = self.parent()
        xml = parent.find("{%s}received" % self.namespace)
        if xml is not None:
            return xml.attrib.get('id', '')
        return ''

    def del_receipt(self):
        self.parent()._del_sub('{%s}received' % self.namespace)