Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0085.py @ 3231:e756e0eb1be4
core (memory/encryption): automatic start encryption if peer send encrypted message:
If peer sends encrypted message and we have no encryption activated, we automatically
start encryption to avoid sending plain text message when answering.
markAsEncrypted now needs the encryption algorithm namespace as mandatory argument.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 23 Mar 2020 17:52:18 +0100 |
parents | dcebc585c29f |
children | 6cf4bd6972c2 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 # SAT plugin for Chat State Notifications Protocol (xep-0085) |
1766 | 5 # Copyright (C) 2009-2016 Adrien Cossa (souliane@mailoo.org) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
908
diff
changeset
|
21 from sat.core.constants import Const as C |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 from sat.core import exceptions |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
922
diff
changeset
|
23 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
24 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
922
diff
changeset
|
25 log = getLogger(__name__) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 from wokkel import disco, iwokkel |
3028 | 27 from zope.interface import implementer |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from twisted.words.protocols.jabber.jid import JID |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
29 |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 try: |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 from twisted.words.protocols.xmlstream import XMPPHandler |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 except ImportError: |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 from wokkel.subprotocols import XMPPHandler |
660
69a8bfd266a5
core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
Goffi <goffi@goffi.org>
parents:
659
diff
changeset
|
34 from twisted.words.xish import domish |
1547
0632d96f08ad
plugin XEP-0085: fixed bad use of threads resulting in delay and crash when stopping the backend.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
35 from twisted.internet import reactor |
1563
075a63180eab
plugin XEP-0085: fixed chatstate blinking following 0632d96f08ad change
Goffi <goffi@goffi.org>
parents:
1547
diff
changeset
|
36 from twisted.internet import error as internet_error |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 NS_XMPP_CLIENT = "jabber:client" |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 NS_CHAT_STATES = "http://jabber.org/protocol/chatstates" |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 CHAT_STATES = ["active", "inactive", "gone", "composing", "paused"] |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 MESSAGE_TYPES = ["chat", "groupchat"] |
643
262d9d9ad27a
plugin XEP-0085: renamed category and parameter
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
42 PARAM_KEY = "Notifications" |
262d9d9ad27a
plugin XEP-0085: renamed category and parameter
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
43 PARAM_NAME = "Enable chat state notifications" |
262d9d9ad27a
plugin XEP-0085: renamed category and parameter
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
44 ENTITY_KEY = PARAM_KEY + "_" + PARAM_NAME |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
45 DELETE_VALUE = "DELETE" |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
48 C.PI_NAME: "Chat State Notifications Protocol Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
49 C.PI_IMPORT_NAME: "XEP-0085", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
50 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
|
51 C.PI_PROTOCOLS: ["XEP-0085"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
52 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
53 C.PI_MAIN: "XEP_0085", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
54 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 C.PI_DESCRIPTION: _("""Implementation of Chat State Notifications Protocol"""), |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 } |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 # Describe the internal transitions that are triggered |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 # by a timer. Beside that, external transitions can be |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 # runned to target the states "active" or "composing". |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 # Delay is specified here in seconds. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 TRANSITIONS = { |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 "active": {"next_state": "inactive", "delay": 120}, |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 "inactive": {"next_state": "gone", "delay": 480}, |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 "gone": {"next_state": "", "delay": 0}, |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 "composing": {"next_state": "paused", "delay": 30}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 "paused": {"next_state": "inactive", "delay": 450}, |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 } |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 class UnknownChatStateException(Exception): |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 This error is raised when an unknown chat state is used. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 pass |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 class XEP_0085(object): |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 Implementation for XEP 0085 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 params = """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 <params> |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 <individual> |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 <category name="%(category_name)s" label="%(category_label)s"> |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" security="0"/> |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 </category> |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 </individual> |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 </params> |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 """ % { |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 "category_name": PARAM_KEY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 "category_label": _(PARAM_KEY), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 "param_name": PARAM_NAME, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 "param_label": _("Enable chat state notifications"), |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 } |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
922
diff
changeset
|
101 log.info(_("Chat State Notifications plugin initialization")) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 self.host = host |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
103 self.map = {} # FIXME: would be better to use client instead of mapping profile to data |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 # parameter value is retrieved before each use |
662
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
660
diff
changeset
|
106 host.memory.updateParams(self.params) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 # triggers from core |
3172
dcebc585c29f
core: renamed "MessageReceived" trigger to "messageReceived" for consistency.
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
109 host.trigger.add("messageReceived", self.messageReceivedTrigger) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
110 host.trigger.add("sendMessage", self.sendMessageTrigger) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 host.trigger.add("paramUpdateTrigger", self.paramUpdateTrigger) |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
113 # args: to_s (jid as string), profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 "chatStateComposing", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 method=self.chatStateComposing, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 ) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 # args: from (jid as string), state in CHAT_STATES, profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 host.bridge.addSignal("chatStateReceived", ".plugin", signature="sss") |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
125 def getHandler(self, client): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
126 return XEP_0085_handler(self, client.profile) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
128 def profileDisconnected(self, client): |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
129 """Eventually send a 'gone' state to all one2one contacts.""" |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
130 profile = client.profile |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
131 if profile not in self.map: |
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
132 return |
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
133 for to_jid in self.map[profile]: |
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
134 # FIXME: the "unavailable" presence stanza is received by to_jid |
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
135 # before the chat state, so it will be ignored... find a way to |
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
136 # actually defer the disconnection |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 self.map[profile][to_jid]._onEvent("gone") |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
138 del self.map[profile] |
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
139 |
1330
22fce2e51c70
plugin XEP-0085: fixes the calls to memory.deleteEntityDatum and self.updateCache (was self.updateEntityData, has been renamed to avoid confusion with the memory method)
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
140 def updateCache(self, entity_jid, value, profile): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
141 """Update the entity data of the given profile for one or all contacts. |
1330
22fce2e51c70
plugin XEP-0085: fixes the calls to memory.deleteEntityDatum and self.updateCache (was self.updateEntityData, has been renamed to avoid confusion with the memory method)
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
142 Reset the chat state(s) display if the notification has been disabled. |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
143 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
144 @param entity_jid: contact's JID, or C.ENTITY_ALL to update all contacts. |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
145 @param value: True, False or DELETE_VALUE to delete the entity data |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
146 @param profile: current profile |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
148 if value == DELETE_VALUE: |
1330
22fce2e51c70
plugin XEP-0085: fixes the calls to memory.deleteEntityDatum and self.updateCache (was self.updateEntityData, has been renamed to avoid confusion with the memory method)
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
149 self.host.memory.delEntityDatum(entity_jid, ENTITY_KEY, profile) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
150 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 self.host.memory.updateEntityData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 entity_jid, ENTITY_KEY, value, profile_key=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 ) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
154 if not value or value == DELETE_VALUE: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
155 # reinit chat state UI for this or these contact(s) |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
156 self.host.bridge.chatStateReceived(entity_jid.full(), "", profile) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
158 def paramUpdateTrigger(self, name, value, category, type_, profile): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
159 """Reset all the existing chat state entity data associated with this profile after a parameter modification. |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
160 |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
161 @param name: parameter name |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
162 @param value: "true" to activate the notifications, or any other value to delete it |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
163 @param category: parameter category |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
164 @param type_: parameter type |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 if (category, name) == (PARAM_KEY, PARAM_NAME): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 self.updateCache( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 C.ENTITY_ALL, True if C.bool(value) else DELETE_VALUE, profile=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 ) |
868
967b94ef821e
plugin XEP-0085: fixed bad trigger return value
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
170 return False |
967b94ef821e
plugin XEP-0085: fixed bad trigger return value
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
171 return True |
967b94ef821e
plugin XEP-0085: fixed bad trigger return value
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
172 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
173 def messageReceivedTrigger(self, client, message, post_treat): |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 Update the entity cache when we receive a message with body. |
908
2ef523f0b5c3
plugin XEP-0085: bug fixes, especially for groupchat messages
souliane <souliane@mailoo.org>
parents:
868
diff
changeset
|
176 Check for a chat state in the message and signal frontends. |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 """ |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
178 profile = client.profile |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile): |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 return True |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 |
908
2ef523f0b5c3
plugin XEP-0085: bug fixes, especially for groupchat messages
souliane <souliane@mailoo.org>
parents:
868
diff
changeset
|
182 from_jid = JID(message.getAttribute("from")) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
183 if self._isMUC(from_jid, profile): |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
184 from_jid = from_jid.userhostJID() |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
185 else: # update entity data for one2one chat |
1264
60dfa2f5d61f
plugin XEP-0085: disabled a problematic assert (see FIXME)
Goffi <goffi@goffi.org>
parents:
1253
diff
changeset
|
186 # assert from_jid.resource # FIXME: assert doesn't work on normal message from server (e.g. server announce), because there is no resource |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 try: |
3028 | 188 next(domish.generateElementsNamed(message.elements(), name="body")) |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
189 try: |
3028 | 190 next(domish.generateElementsNamed(message.elements(), name="active")) |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
191 # contact enabled Chat State Notifications |
1330
22fce2e51c70
plugin XEP-0085: fixes the calls to memory.deleteEntityDatum and self.updateCache (was self.updateEntityData, has been renamed to avoid confusion with the memory method)
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
192 self.updateCache(from_jid, True, profile=profile) |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
193 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
194 if message.getAttribute("type") == "chat": |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
195 # contact didn't enable Chat State Notifications |
1330
22fce2e51c70
plugin XEP-0085: fixes the calls to memory.deleteEntityDatum and self.updateCache (was self.updateEntityData, has been renamed to avoid confusion with the memory method)
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
196 self.updateCache(from_jid, False, profile=profile) |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
197 return True |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 except StopIteration: |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
199 pass |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 |
908
2ef523f0b5c3
plugin XEP-0085: bug fixes, especially for groupchat messages
souliane <souliane@mailoo.org>
parents:
868
diff
changeset
|
201 # send our next "composing" states to any MUC and to the contacts who enabled the feature |
1565
d86685c0c019
plugin XEP-0085: renamed "__xxx" methods to "_xxx"
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
202 self._chatStateInit(from_jid, message.getAttribute("type"), profile) |
908
2ef523f0b5c3
plugin XEP-0085: bug fixes, especially for groupchat messages
souliane <souliane@mailoo.org>
parents:
868
diff
changeset
|
203 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
204 state_list = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
205 child.name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
206 for child in message.elements() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 if message.getAttribute("type") in MESSAGE_TYPES |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 and child.name in CHAT_STATES |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
209 and child.defaultUri == NS_CHAT_STATES |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
210 ] |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 for state in state_list: |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
212 # there must be only one state according to the XEP |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
213 if state != "gone" or message.getAttribute("type") != "groupchat": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
214 self.host.bridge.chatStateReceived( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
215 message.getAttribute("from"), state, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 ) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 break |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 return True |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
220 def sendMessageTrigger( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 self, client, mess_data, pre_xml_treatments, post_xml_treatments |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 ): |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 Eventually add the chat state to the message and initiate |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 the state machine when sending an "active" state. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 """ |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
227 profile = client.profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
229 def treatment(mess_data): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
230 message = mess_data["xml"] |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
231 to_jid = JID(message.getAttribute("to")) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
232 if not self._checkActivation(to_jid, forceEntityData=True, profile=profile): |
724
6edd9bda4e3f
plugin XEP-0085: fixed bad return value for sendMessage trigger's post treatment
Goffi <goffi@goffi.org>
parents:
698
diff
changeset
|
233 return mess_data |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
234 try: |
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
235 # message with a body always mean active state |
3028 | 236 next(domish.generateElementsNamed(message.elements(), name="body")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 message.addElement("active", NS_CHAT_STATES) |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
238 # launch the chat state machine (init the timer) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
239 if self._isMUC(to_jid, profile): |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
240 to_jid = to_jid.userhostJID() |
1565
d86685c0c019
plugin XEP-0085: renamed "__xxx" methods to "_xxx"
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
241 self._chatStateActive(to_jid, mess_data["type"], profile) |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
242 except StopIteration: |
698
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
243 if "chat_state" in mess_data["extra"]: |
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
244 state = mess_data["extra"].pop("chat_state") |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
245 assert state in CHAT_STATES |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
246 message.addElement(state, NS_CHAT_STATES) |
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
247 return mess_data |
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
663
diff
changeset
|
248 |
922
c897c8d321b3
core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
249 post_xml_treatments.addCallback(treatment) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 return True |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
252 def _isMUC(self, to_jid, profile): |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
253 """Tell if that JID is a MUC or not |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
254 |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
255 @param to_jid (JID): full or bare JID to check |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
256 @param profile (str): %(doc_profile)s |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
257 @return: bool |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
258 """ |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
259 try: |
2994
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
260 type_ = self.host.memory.getEntityDatum( |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
261 to_jid.userhostJID(), C.ENTITY_TYPE, profile) |
94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
262 if type_ == C.ENTITY_TYPE_MUC: |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
263 return True |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
264 except (exceptions.UnknownEntityError, KeyError): |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
265 pass |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
266 return False |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
267 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
268 def _checkActivation(self, to_jid, forceEntityData, profile): |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
269 """ |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
270 @param to_jid: the contact's full JID (or bare if you know it's a MUC) |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
271 @param forceEntityData: if set to True, a non-existing |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
272 entity data will be considered to be True (and initialized) |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
273 @param: current profile |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
274 @return: True if the notifications should be sent to this JID. |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
275 """ |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
276 # check if the parameter is active |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
277 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile): |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
278 return False |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
279 # check if notifications should be sent to this contact |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
280 if self._isMUC(to_jid, profile): |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
281 return True |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
282 # FIXME: this assertion crash when we want to send a message to an online bare jid |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
283 # assert to_jid.resource or not self.host.memory.isEntityAvailable(to_jid, profile) # must either have a resource, or talk to an offline contact |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
284 try: |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
285 return self.host.memory.getEntityDatum(to_jid, ENTITY_KEY, profile) |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
286 except (exceptions.UnknownEntityError, KeyError): |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
287 if forceEntityData: |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
288 # enable it for the first time |
1330
22fce2e51c70
plugin XEP-0085: fixes the calls to memory.deleteEntityDatum and self.updateCache (was self.updateEntityData, has been renamed to avoid confusion with the memory method)
souliane <souliane@mailoo.org>
parents:
1315
diff
changeset
|
289 self.updateCache(to_jid, True, profile=profile) |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
290 return True |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
291 # wait for the first message before sending states |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
292 return False |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
293 |
1565
d86685c0c019
plugin XEP-0085: renamed "__xxx" methods to "_xxx"
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
294 def _chatStateInit(self, to_jid, mess_type, profile): |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 Data initialization for the chat state machine. |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
297 |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
298 @param to_jid (JID): full JID for one2one, bare JID for MUC |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
299 @param mess_type (str): "one2one" or "groupchat" |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
300 @param profile (str): %(doc_profile)s |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 if mess_type is None: |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 return |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 profile_map = self.map.setdefault(profile, {}) |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
305 if to_jid not in profile_map: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
306 machine = ChatStateMachine(self.host, to_jid, mess_type, profile) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 self.map[profile][to_jid] = machine |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 |
1565
d86685c0c019
plugin XEP-0085: renamed "__xxx" methods to "_xxx"
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
309 def _chatStateActive(self, to_jid, mess_type, profile_key): |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 Launch the chat state machine on "active" state. |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
312 |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
313 @param to_jid (JID): full JID for one2one, bare JID for MUC |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
314 @param mess_type (str): "one2one" or "groupchat" |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
315 @param profile (str): %(doc_profile)s |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 profile = self.host.memory.getProfileName(profile_key) |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
318 if profile is None: |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 raise exceptions.ProfileUnknownError |
1565
d86685c0c019
plugin XEP-0085: renamed "__xxx" methods to "_xxx"
Goffi <goffi@goffi.org>
parents:
1563
diff
changeset
|
320 self._chatStateInit(to_jid, mess_type, profile) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 self.map[profile][to_jid]._onEvent("active") |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
322 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
323 def chatStateComposing(self, to_jid_s, profile_key): |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
324 """Move to the "composing" state when required. |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
325 |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
326 Since this method is called from the front-end, it needs to check the |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
327 values of the parameter "Send chat state notifications" and the entity |
654
5c5cf5bca240
plugin XEP-0085: improvement for sending "composing" state
souliane <souliane@mailoo.org>
parents:
643
diff
changeset
|
328 data associated to the target JID. |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
329 |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
330 @param to_jid_s (str): contact full JID as a string |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
331 @param profile_key (str): %(doc_profile_key)s |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 """ |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
333 # TODO: try to optimize this method which is called often |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
334 client = self.host.getClient(profile_key) |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
335 to_jid = JID(to_jid_s) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
336 if self._isMUC(to_jid, client.profile): |
1252
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
337 to_jid = to_jid.userhostJID() |
5ff9f9af9d1f
plugin XEP-0085: use the full JID + fixes bad entity data "type" value
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
338 elif not to_jid.resource: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
339 to_jid.resource = self.host.memory.getMainResource(client, to_jid) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 if not self._checkActivation( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
341 to_jid, forceEntityData=False, profile=client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
342 ): |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
343 return |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 try: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
345 self.map[client.profile][to_jid]._onEvent("composing") |
908
2ef523f0b5c3
plugin XEP-0085: bug fixes, especially for groupchat messages
souliane <souliane@mailoo.org>
parents:
868
diff
changeset
|
346 except (KeyError, AttributeError): |
659
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
347 # no message has been sent/received since the notifications |
b6c22d9f593a
plugin xep-0085: bug fix + improvement
souliane <souliane@mailoo.org>
parents:
654
diff
changeset
|
348 # have been enabled, it's better to wait for a first one |
654
5c5cf5bca240
plugin XEP-0085: improvement for sending "composing" state
souliane <souliane@mailoo.org>
parents:
643
diff
changeset
|
349 pass |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
351 |
1547
0632d96f08ad
plugin XEP-0085: fixed bad use of threads resulting in delay and crash when stopping the backend.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
352 class ChatStateMachine(object): |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 This class represents a chat state, between one profile and |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 one target contact. A timer is used to move from one state |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 to the other. The initialization is done through the "active" |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 state which is internally set when a message is sent. The state |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 "composing" can be set externally (through the bridge by a |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 frontend). Other states are automatically set with the timer. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
360 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 def __init__(self, host, to_jid, mess_type, profile): |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
364 Initialization need to store the target, message type |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 and a profile for sending later messages. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 self.host = host |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
368 self.to_jid = to_jid |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 self.mess_type = mess_type |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
370 self.profile = profile |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 self.state = None |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
372 self.timer = None |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
374 def _onEvent(self, state): |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 """ |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 Move to the specified state, eventually send the |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
377 notification to the contact (the "active" state is |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
378 automatically sent with each message) and set the timer. |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
380 assert state in TRANSITIONS |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
381 transition = TRANSITIONS[state] |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1264
diff
changeset
|
382 assert "next_state" in transition and "delay" in transition |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
383 |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 if state != self.state and state != "active": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
385 if state != "gone" or self.mess_type != "groupchat": |
908
2ef523f0b5c3
plugin XEP-0085: bug fixes, especially for groupchat messages
souliane <souliane@mailoo.org>
parents:
868
diff
changeset
|
386 # send a new message without body |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
387 log.debug( |
3028 | 388 "sending state '{state}' to {jid}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
389 state=state, jid=self.to_jid.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
390 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
391 ) |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
392 client = self.host.getClient(self.profile) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
393 mess_data = { |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
394 "from": client.jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
395 "to": self.to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
396 "uid": "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
397 "message": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
398 "type": self.mess_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
399 "subject": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
400 "extra": {}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
401 } |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
402 client.generateMessageXML(mess_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
403 mess_data["xml"].addElement(state, NS_CHAT_STATES) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
404 client.send(mess_data["xml"]) |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
405 |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
406 self.state = state |
1563
075a63180eab
plugin XEP-0085: fixed chatstate blinking following 0632d96f08ad change
Goffi <goffi@goffi.org>
parents:
1547
diff
changeset
|
407 try: |
075a63180eab
plugin XEP-0085: fixed chatstate blinking following 0632d96f08ad change
Goffi <goffi@goffi.org>
parents:
1547
diff
changeset
|
408 self.timer.cancel() |
075a63180eab
plugin XEP-0085: fixed chatstate blinking following 0632d96f08ad change
Goffi <goffi@goffi.org>
parents:
1547
diff
changeset
|
409 except (internet_error.AlreadyCalled, AttributeError): |
075a63180eab
plugin XEP-0085: fixed chatstate blinking following 0632d96f08ad change
Goffi <goffi@goffi.org>
parents:
1547
diff
changeset
|
410 pass |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
411 |
1253
c13a46207410
plugin XEP-0085: send 'gone' state before disconnection
souliane <souliane@mailoo.org>
parents:
1252
diff
changeset
|
412 if transition["next_state"] and transition["delay"] > 0: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 self.timer = reactor.callLater( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
414 transition["delay"], self._onEvent, transition["next_state"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 ) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
416 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 |
3028 | 418 @implementer(iwokkel.IDisco) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
419 class XEP_0085_handler(XMPPHandler): |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
420 |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
421 def __init__(self, plugin_parent, profile): |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
422 self.plugin_parent = plugin_parent |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
423 self.host = plugin_parent.host |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
424 self.profile = profile |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
427 return [disco.DiscoFeature(NS_CHAT_STATES)] |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
430 return [] |