annotate src/plugins/plugin_xep_0184.py @ 2126:2f264f3df280

core (menus): improvments: - use the new convention for bridge names (getMenus ==> menusGet, etc.) - menu now use canonical path, which is the untranslated path with each element stripped and lowercase, it must be unique by menu type - added menuLaunch method to manually launch a menu like an action, canonical path is used instead of id - added SECURITY_LIMIT_MAX constant
author Goffi <goffi@goffi.org>
date Thu, 26 Jan 2017 20:29:48 +0100
parents ad88808591ef
children 6a66c8c5a567
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 _
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
20 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
21 from twisted.internet import reactor
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
22 from twisted.words.protocols.jabber import xmlstream
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
23 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
24 log = getLogger(__name__)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
25
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
26 from wokkel import disco, iwokkel
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
27 from zope.interface import implements
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
28 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
29 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
30 except ImportError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
31 from wokkel.subprotocols import XMPPHandler
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
32
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 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
35
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
36 MSG = 'message'
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
37
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
38 MSG_CHAT = '/'+MSG+'[@type="chat"]'
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
39 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
40 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
41
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
42 MSG_NORMAL = '/'+MSG+'[@type="normal"]'
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
43 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
44 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
45
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 PARAM_KEY = "Privacy"
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
48 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
49 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
50
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 PLUGIN_INFO = {
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
53 "name": "XEP-0184 Plugin",
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
54 "import_name": "XEP-0184",
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
55 "type": "XEP",
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
56 "protocols": ["XEP-0184"],
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
57 "dependencies": [],
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
58 "main": "XEP_0184",
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
59 "handler": "yes",
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
60 "description": _("""Implementation of Message Delivery Receipts""")
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
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
64 STATUS_MESSAGE_DELIVERY_RECEIVED = "delivered"
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
65 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
66
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 class XEP_0184(object):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
69 """
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
70 Implementation for XEP 0184.
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
71 """
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
72 params = """
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 <individual>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
75 <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
76 <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
77 </category>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
78 </individual>
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
79 </params>
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 'category_name': PARAM_KEY,
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
82 'category_label': _(PARAM_KEY),
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
83 'param_name': PARAM_NAME,
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
84 '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
85 }
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 def __init__(self, host):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
88 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
89 self.host = host
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
90 self._dictRequest = dict()
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
91
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
92 # 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
93 host.memory.updateParams(self.params)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
94
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
95 host.trigger.add("messageSend", self.messageSendTrigger)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
96 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
97
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
98 def getHandler(self, profile):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
99 return XEP_0184_handler(self, profile)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
100
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
101 def messageSendTrigger(self, client, mess_data, pre_xml_treatments, post_xml_treatments):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
102 """Install SendMessage command hook """
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
103 def treatment(mess_data):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
104 message = mess_data['xml']
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
105 message_type = message.getAttribute("type")
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
106
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
107 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
108 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
109 uid = mess_data['uid']
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
110 msg_id = message.getAttribute("id")
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
111 self._dictRequest[msg_id] = uid
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
112 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
113 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
114
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
115 return mess_data
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
116
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
117 post_xml_treatments.addCallback(treatment)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
118 return True
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
119
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
120 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
121 """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
122 @param msg_elt: message element
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
123 @param client: %(doc_client)s"""
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
124
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
125 if self._isActif(client.profile):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
126 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
127 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
128
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
129 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
130 msg_result_elt.addChild(received_elt_ret)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
131 client.xmlstream.send(msg_result_elt)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
132
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
133 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
134 """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
135 @param msg_elt: message element
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
136 @param client: %(doc_client)s"""
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
137 msg_elt.handled = True
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
138 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
139 msg_id = rcv_elt['id']
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
140
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
141 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
142 uid = self._dictRequest[msg_id]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
143 del self._dictRequest[msg_id]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
144 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
145 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
146 except KeyError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
147 pass
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
148
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
149 def _clearDictRequest(self, msg_id):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
150 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
151 del self._dictRequest[msg_id]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
152 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
153 except KeyError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
154 pass
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
155
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
156 def _isActif(self, profile):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
157 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
158
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
159 class XEP_0184_handler(XMPPHandler):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
160 implements(iwokkel.IDisco)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
161
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
162 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
163 self.plugin_parent = plugin_parent
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
164 self.host = plugin_parent.host
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
165 self.profile = profile
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
166
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
167 def connectionInitialized(self):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
168 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
169 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
170
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
171 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
172 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
173
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
174 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
175 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
176
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
177 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
178 return []