annotate sat/plugins/plugin_xep_0184.py @ 3320:bb92085720c8

plugin XEP-0329: implemented ways to get/set affiliations: PubSub-like affiliations can now be get/set using non standard methods. This has been done to prepare the move to a pubsub based file sharing system.
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:12:44 +0200
parents 559a625a236b
children 31628770a15a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3129
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3129
diff changeset
2
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
3
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
4 # SAT plugin for managing xep-0184
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
5 # Copyright (C) 2009-2016 Geoffrey POUZET (chteufleur@kingpenguin.tk)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
6
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
10 # (at your option) any later version.
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
11
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
16
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
19 from sat.core.i18n import _
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
20 from sat.core.constants import Const as C
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
21 from sat.core.log import getLogger
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
22 from twisted.internet import reactor
2140
f79935f41125 plugin XEP-0184: check if entity is allowed to see our presence before returning receipt
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
23 from twisted.words.protocols.jabber import xmlstream, jid
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
24 from twisted.words.xish import domish
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
25
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
26 log = getLogger(__name__)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
27
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
28 from wokkel import disco, iwokkel
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
29 from zope.interface import implementer
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
30
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
31 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
32 from twisted.words.protocols.xmlstream import XMPPHandler
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
33 except ImportError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
34 from wokkel.subprotocols import XMPPHandler
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
35
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
36
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 NS_MESSAGE_DELIVERY_RECEIPTS = "urn:xmpp:receipts"
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
38
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 MSG = "message"
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
40
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 MSG_CHAT = "/" + MSG + '[@type="chat"]'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_REQUEST = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 MSG_CHAT + '/request[@xmlns="' + NS_MESSAGE_DELIVERY_RECEIPTS + '"]'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
44 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_RECEIVED = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 MSG_CHAT + '/received[@xmlns="' + NS_MESSAGE_DELIVERY_RECEIPTS + '"]'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 )
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
48
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 MSG_NORMAL = "/" + MSG + '[@type="normal"]'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_REQUEST = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 MSG_NORMAL + '/request[@xmlns="' + NS_MESSAGE_DELIVERY_RECEIPTS + '"]'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_RECEIVED = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 MSG_NORMAL + '/received[@xmlns="' + NS_MESSAGE_DELIVERY_RECEIPTS + '"]'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 )
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
56
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
57
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
58 PARAM_KEY = "Privacy"
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
59 PARAM_NAME = "Enable message delivery receipts"
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
60 ENTITY_KEY = PARAM_KEY + "_" + PARAM_NAME
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
61
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
62
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
63 PLUGIN_INFO = {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 C.PI_NAME: "XEP-0184 Plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 C.PI_IMPORT_NAME: "XEP-0184",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 C.PI_TYPE: "XEP",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 C.PI_PROTOCOLS: ["XEP-0184"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 C.PI_DEPENDENCIES: [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 C.PI_MAIN: "XEP_0184",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 C.PI_HANDLER: "yes",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 C.PI_DESCRIPTION: _("""Implementation of Message Delivery Receipts"""),
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
72 }
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
73
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
74
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
75 STATUS_MESSAGE_DELIVERY_RECEIVED = "delivered"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 TEMPO_DELETE_WAITING_ACK_S = 300 # 5 min
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
77
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
78
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
79 class XEP_0184(object):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
80 """
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
81 Implementation for XEP 0184.
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
82 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
84 params = """
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
85 <params>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
86 <individual>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
87 <category name="%(category_name)s" label="%(category_label)s">
2095
522c4c8903f9 xep-0184: delivery receipts are now activated by default
Goffi <goffi@goffi.org>
parents: 2023
diff changeset
88 <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" security="0"/>
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
89 </category>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
90 </individual>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
91 </params>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
92 """ % {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 "category_name": PARAM_KEY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 "category_label": _(PARAM_KEY),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 "param_name": PARAM_NAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 "param_label": _("Enable message delivery receipts"),
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
97 }
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
98
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
99 def __init__(self, host):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
100 log.info(_("Plugin XEP_0184 (message delivery receipts) initialization"))
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
101 self.host = host
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
102 self._dictRequest = dict()
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
103
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
104 # parameter value is retrieved before each use
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
105 host.memory.updateParams(self.params)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
106
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2140
diff changeset
107 host.trigger.add("sendMessage", self.sendMessageTrigger)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 host.bridge.addSignal(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 "messageState", ".plugin", signature="sss"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 ) # message_uid, status, profile
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
111
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2140
diff changeset
112 def getHandler(self, client):
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2140
diff changeset
113 return XEP_0184_handler(self, client.profile)
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
114
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 def sendMessageTrigger(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 self, client, mess_data, pre_xml_treatments, post_xml_treatments
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 ):
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
118 """Install SendMessage command hook """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
120 def treatment(mess_data):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 message = mess_data["xml"]
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
122 message_type = message.getAttribute("type")
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
123
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 if self._isActif(client.profile) and (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 message_type == "chat" or message_type == "normal"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 message.addElement("request", NS_MESSAGE_DELIVERY_RECEIPTS)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 uid = mess_data["uid"]
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
129 msg_id = message.getAttribute("id")
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
130 self._dictRequest[msg_id] = uid
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 reactor.callLater(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 TEMPO_DELETE_WAITING_ACK_S, self._clearDictRequest, msg_id
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 "[XEP-0184] Request acknowledgment for message id {}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 msg_id
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 )
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
141
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
142 return mess_data
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
143
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
144 post_xml_treatments.addCallback(treatment)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
145 return True
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
146
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
147 def onMessageDeliveryReceiptsRequest(self, msg_elt, client):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
148 """This method is called on message delivery receipts **request** (XEP-0184 #7)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
149 @param msg_elt: message element
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
150 @param client: %(doc_client)s"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 from_jid = jid.JID(msg_elt["from"])
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
152
2140
f79935f41125 plugin XEP-0184: check if entity is allowed to see our presence before returning receipt
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
153 if self._isActif(client.profile) and client.roster.isPresenceAuthorised(from_jid):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 received_elt_ret = domish.Element((NS_MESSAGE_DELIVERY_RECEIPTS, "received"))
3129
95befc85e816 plugin XEP-0184: show a warning and the message XML on missing `id`
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
155 try:
95befc85e816 plugin XEP-0184: show a warning and the message XML on missing `id`
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
156 received_elt_ret["id"] = msg_elt["id"]
95befc85e816 plugin XEP-0184: show a warning and the message XML on missing `id`
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
157 except KeyError:
95befc85e816 plugin XEP-0184: show a warning and the message XML on missing `id`
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
158 log.warning(f"missing id for message element: {msg_elt.toXml}")
95befc85e816 plugin XEP-0184: show a warning and the message XML on missing `id`
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 return
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
160
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 msg_result_elt = xmlstream.toResponse(msg_elt, "result")
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
162 msg_result_elt.addChild(received_elt_ret)
2129
6a66c8c5a567 core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
163 client.send(msg_result_elt)
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
164
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
165 def onMessageDeliveryReceiptsReceived(self, msg_elt, client):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
166 """This method is called on message delivery receipts **received** (XEP-0184 #7)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
167 @param msg_elt: message element
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
168 @param client: %(doc_client)s"""
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
169 msg_elt.handled = True
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
170 rcv_elt = next(msg_elt.elements(NS_MESSAGE_DELIVERY_RECEIPTS, "received"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 msg_id = rcv_elt["id"]
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
172
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
173 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
174 uid = self._dictRequest[msg_id]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
175 del self._dictRequest[msg_id]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 self.host.bridge.messageState(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 uid, STATUS_MESSAGE_DELIVERY_RECEIVED, client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 _("[XEP-0184] Receive acknowledgment for message id {}".format(msg_id))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 )
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
182 except KeyError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
183 pass
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
184
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
185 def _clearDictRequest(self, msg_id):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
186 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
187 del self._dictRequest[msg_id]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 "[XEP-0184] Delete waiting acknowledgment for message id {}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 msg_id
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 )
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
195 except KeyError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
196 pass
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
197
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
198 def _isActif(self, profile):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
199 return self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
200
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
202 @implementer(iwokkel.IDisco)
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
203 class XEP_0184_handler(XMPPHandler):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
204
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
205 def __init__(self, plugin_parent, profile):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
206 self.plugin_parent = plugin_parent
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
207 self.host = plugin_parent.host
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
208 self.profile = profile
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
209
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
210 def connectionInitialized(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_REQUEST,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 self.plugin_parent.onMessageDeliveryReceiptsRequest,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
214 client=self.parent,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
215 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
217 MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_RECEIVED,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 self.plugin_parent.onMessageDeliveryReceiptsReceived,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
219 client=self.parent,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 )
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
221
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_REQUEST,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 self.plugin_parent.onMessageDeliveryReceiptsRequest,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
225 client=self.parent,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_RECEIVED,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
229 self.plugin_parent.onMessageDeliveryReceiptsReceived,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 client=self.parent,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 )
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
232
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
234 return [disco.DiscoFeature(NS_MESSAGE_DELIVERY_RECEIPTS)]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
235
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
2023
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
237 return []