Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0184.py @ 2411:f9167c053475
jp (ad-hoc/run): node is now a positional argument
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 31 Oct 2017 23:30:18 +0100 |
parents | 33c8c4973743 |
children |
rev | line source |
---|---|
2023
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
1 #!/usr/bin/python |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
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 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
25 log = getLogger(__name__) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
26 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
27 from wokkel import disco, iwokkel |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
28 from zope.interface import implements |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
29 try: |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
30 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
|
31 except ImportError: |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
32 from wokkel.subprotocols import XMPPHandler |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
33 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
34 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
35 NS_MESSAGE_DELIVERY_RECEIPTS = 'urn:xmpp:receipts' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
36 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
37 MSG = 'message' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
38 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
39 MSG_CHAT = '/'+MSG+'[@type="chat"]' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
40 MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_REQUEST = MSG_CHAT+'/request[@xmlns="'+NS_MESSAGE_DELIVERY_RECEIPTS+'"]' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
41 MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_RECEIVED = MSG_CHAT+'/received[@xmlns="'+NS_MESSAGE_DELIVERY_RECEIPTS+'"]' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
42 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
43 MSG_NORMAL = '/'+MSG+'[@type="normal"]' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
44 MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_REQUEST = MSG_NORMAL+'/request[@xmlns="'+NS_MESSAGE_DELIVERY_RECEIPTS+'"]' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
45 MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_RECEIVED = MSG_NORMAL+'/received[@xmlns="'+NS_MESSAGE_DELIVERY_RECEIPTS+'"]' |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
46 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
47 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
48 PARAM_KEY = "Privacy" |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
49 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
|
50 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
|
51 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
52 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
53 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
54 C.PI_NAME: "XEP-0184 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
55 C.PI_IMPORT_NAME: "XEP-0184", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
56 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
57 C.PI_PROTOCOLS: ["XEP-0184"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
58 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
59 C.PI_MAIN: "XEP_0184", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
60 C.PI_HANDLER: "yes", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
61 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
|
62 } |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
63 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
64 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
65 STATUS_MESSAGE_DELIVERY_RECEIVED = "delivered" |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
66 TEMPO_DELETE_WAITING_ACK_S = 300 # 5 min |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
67 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
68 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
69 class XEP_0184(object): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
70 """ |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
71 Implementation for XEP 0184. |
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 params = """ |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
74 <params> |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
75 <individual> |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
76 <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
|
77 <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
|
78 </category> |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
79 </individual> |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
80 </params> |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
81 """ % { |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
82 'category_name': PARAM_KEY, |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
83 'category_label': _(PARAM_KEY), |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
84 'param_name': PARAM_NAME, |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
85 'param_label': _('Enable message delivery receipts') |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
86 } |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
87 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
88 def __init__(self, host): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
89 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
|
90 self.host = host |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
91 self._dictRequest = dict() |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
92 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
93 # 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
|
94 host.memory.updateParams(self.params) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
95 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2140
diff
changeset
|
96 host.trigger.add("sendMessage", self.sendMessageTrigger) |
2023
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
97 host.bridge.addSignal("messageState", ".plugin", signature='sss') # message_uid, status, profile |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
98 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2140
diff
changeset
|
99 def getHandler(self, client): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2140
diff
changeset
|
100 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
|
101 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2140
diff
changeset
|
102 def sendMessageTrigger(self, client, mess_data, pre_xml_treatments, post_xml_treatments): |
2023
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
103 """Install SendMessage command hook """ |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
104 def treatment(mess_data): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
105 message = mess_data['xml'] |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
106 message_type = message.getAttribute("type") |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
107 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
108 if self._isActif(client.profile) and (message_type == "chat" or message_type == "normal"): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
109 message.addElement('request', NS_MESSAGE_DELIVERY_RECEIPTS) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
110 uid = mess_data['uid'] |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
111 msg_id = message.getAttribute("id") |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
112 self._dictRequest[msg_id] = uid |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
113 reactor.callLater(TEMPO_DELETE_WAITING_ACK_S, self._clearDictRequest, msg_id) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
114 log.debug(_("[XEP-0184] Request acknowledgment for message id {}".format(msg_id))) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
115 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
116 return mess_data |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
117 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
118 post_xml_treatments.addCallback(treatment) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
119 return True |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
120 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
121 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
|
122 """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
|
123 @param msg_elt: message element |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
124 @param client: %(doc_client)s""" |
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
|
125 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
|
126 |
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
|
127 if self._isActif(client.profile) and client.roster.isPresenceAuthorised(from_jid): |
2023
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
128 received_elt_ret = domish.Element((NS_MESSAGE_DELIVERY_RECEIPTS, 'received')) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
129 received_elt_ret["id"] = msg_elt["id"] |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
130 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
131 msg_result_elt = xmlstream.toResponse(msg_elt, 'result') |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
132 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
|
133 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
|
134 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
135 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
|
136 """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
|
137 @param msg_elt: message element |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
138 @param client: %(doc_client)s""" |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
139 msg_elt.handled = True |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
140 rcv_elt = msg_elt.elements(NS_MESSAGE_DELIVERY_RECEIPTS, 'received').next() |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
141 msg_id = rcv_elt['id'] |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
142 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
143 try: |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
144 uid = self._dictRequest[msg_id] |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
145 del self._dictRequest[msg_id] |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
146 self.host.bridge.messageState(uid, STATUS_MESSAGE_DELIVERY_RECEIVED, client.profile) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
147 log.debug(_("[XEP-0184] Receive acknowledgment for message id {}".format(msg_id))) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
148 except KeyError: |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
149 pass |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
150 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
151 def _clearDictRequest(self, msg_id): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
152 try: |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
153 del self._dictRequest[msg_id] |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
154 log.debug(_("[XEP-0184] Delete waiting acknowledgment for message id {}".format(msg_id))) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
155 except KeyError: |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
156 pass |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
157 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
158 def _isActif(self, profile): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
159 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
|
160 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
161 class XEP_0184_handler(XMPPHandler): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
162 implements(iwokkel.IDisco) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
163 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
164 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
|
165 self.plugin_parent = plugin_parent |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
166 self.host = plugin_parent.host |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
167 self.profile = profile |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
168 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
169 def connectionInitialized(self): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
170 self.xmlstream.addObserver(MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_REQUEST, self.plugin_parent.onMessageDeliveryReceiptsRequest, client=self.parent) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
171 self.xmlstream.addObserver(MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_RECEIVED, self.plugin_parent.onMessageDeliveryReceiptsReceived, client=self.parent) |
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 self.xmlstream.addObserver(MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_REQUEST, self.plugin_parent.onMessageDeliveryReceiptsRequest, client=self.parent) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
174 self.xmlstream.addObserver(MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_RECEIVED, self.plugin_parent.onMessageDeliveryReceiptsReceived, client=self.parent) |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
175 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
176 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
177 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
|
178 |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
179 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
180 return [] |