annotate src/plugins/plugin_xep_0184.py @ 2090:52bd463e6fe7

core(stdui/profile manager): fixed authentication cancellation
author Goffi <goffi@goffi.org>
date Sun, 04 Dec 2016 21:35:23 +0100
parents 224c8b0886bc
children 522c4c8903f9
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">
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
76 <param name="%(param_name)s" label="%(param_label)s" value="false" type="bool" security="0"/>
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
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"""
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
125
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
126 if self._isActif(client.profile):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
127 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
128 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
129
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
130 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
131 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
132 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
133
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
134 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
135 """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
136 @param msg_elt: message element
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
137 @param client: %(doc_client)s"""
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
138 msg_elt.handled = True
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
139 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
140 msg_id = rcv_elt['id']
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 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
143 uid = self._dictRequest[msg_id]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
144 del self._dictRequest[msg_id]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
145 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
146 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
147 except KeyError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
148 pass
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
149
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
150 def _clearDictRequest(self, msg_id):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
151 try:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
152 del self._dictRequest[msg_id]
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
153 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
154 except KeyError:
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
155 pass
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
156
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
157 def _isActif(self, profile):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
158 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
159
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
160 class XEP_0184_handler(XMPPHandler):
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
161 implements(iwokkel.IDisco)
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
162
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
163 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
164 self.plugin_parent = plugin_parent
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
165 self.host = plugin_parent.host
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
166 self.profile = profile
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
167
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
168 def connectionInitialized(self):
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_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
170 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
171
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_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
173 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
174
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
175 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
176 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
177
224c8b0886bc plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff changeset
178 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
179 return []