annotate sat/plugins/plugin_xep_0280.py @ 2686:ce1e15d59496

quick frontend (contact list): use property to retrieve "whoami" in ProfileContactList: this avoid a crash introduced by early creation of contact list during profile plugging, and avoid desynchronisation risk.
author Goffi <goffi@goffi.org>
date Fri, 09 Nov 2018 16:17:45 +0100
parents 56f94936df1e
children 5060cbeec01e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for managing xep-0280
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _, D_
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
22
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 log = getLogger(__name__)
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core import exceptions
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.constants import Const as C
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.xmpp import SatMessageProtocol
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber.error import StanzaError
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.internet import defer
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from wokkel import disco, iwokkel
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from zope.interface import implements
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
31
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 try:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from twisted.words.protocols.xmlstream import XMPPHandler
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 except ImportError:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from wokkel.subprotocols import XMPPHandler
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 PARAM_CATEGORY = "Misc"
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 PARAM_NAME = "carbon"
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 PARAM_LABEL = D_(u"Message carbons")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 NS_CARBONS = "urn:xmpp:carbons:2"
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_NAME: u"XEP-0280 Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
45 C.PI_IMPORT_NAME: u"XEP-0280",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
46 C.PI_TYPE: u"XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
47 C.PI_PROTOCOLS: [u"XEP-0280"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
48 C.PI_DEPENDENCIES: [],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
49 C.PI_MAIN: u"XEP_0280",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
50 C.PI_HANDLER: u"yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 C.PI_DESCRIPTION: D_(u"""Implementation of Message Carbons"""),
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 }
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 class XEP_0280(object):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 #  TODO: param is only checked at profile connection
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 # activate carbons on param change even after profile connection
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 # TODO: chat state notifications are not handled yet (and potentially other XEPs?)
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 params = """
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 <params>
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 <individual>
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 <category name="{category_name}" label="{category_label}">
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 <param name="{param_name}" label="{param_label}" value="true" type="bool" security="0" />
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 </category>
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 </individual>
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 </params>
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 """.format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 category_name=PARAM_CATEGORY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 category_label=D_(PARAM_CATEGORY),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 param_name=PARAM_NAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 param_label=PARAM_LABEL,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 )
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def __init__(self, host):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 log.info(_("Plugin XEP_0280 initialization"))
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.host = host
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 host.memory.updateParams(self.params)
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=1000)
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2133
diff changeset
81 def getHandler(self, client):
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 return XEP_0280_handler()
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83
2133
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
84 def setPrivate(self, message_elt):
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
85 """Add a <private/> element to a message
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
86
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
87 this method is intented to be called on final domish.Element by other plugins
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
88 (in particular end 2 end encryption plugins)
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
89 @param message_elt(domish.Element): <message> stanza
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
90 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 if message_elt.name != u"message":
2133
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
92 log.error(u"addPrivateElt must be used with <message> stanzas")
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
93 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 message_elt.addElement((NS_CARBONS, u"private"))
2133
7de291c3cd0c plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents: 2099
diff changeset
95
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 @defer.inlineCallbacks
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2133
diff changeset
97 def profileConnected(self, client):
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 """activate message carbons on connection if possible and activated in config"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 activate = self.host.memory.getParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 PARAM_NAME, PARAM_CATEGORY, profile_key=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 )
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 if not activate:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 log.info(_(u"Not activating message carbons as requested in params"))
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 return
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 try:
2148
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
106 yield self.host.checkFeatures(client, (NS_CARBONS,))
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 except exceptions.FeatureNotFound:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 log.warning(_(u"server doesn't handle message carbons"))
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 else:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 log.info(_(u"message carbons available, enabling it"))
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 iq_elt = client.IQ()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 iq_elt.addElement((NS_CARBONS, "enable"))
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 try:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 yield iq_elt.send()
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 except StanzaError as e:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 log.warning(u"Can't activate message carbons: {}".format(e))
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 else:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 log.info(_(u"message carbons activated"))
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 def messageReceivedTrigger(self, client, message_elt, post_treat):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 """get message and handle it if carbons namespace is present"""
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 carbons_elt = None
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 for e in message_elt.elements():
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 if e.uri == NS_CARBONS:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 carbons_elt = e
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 break
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 if carbons_elt is None:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 # this is not a message carbons,
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 # we continue normal behaviour
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 return True
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 if message_elt["from"] != client.jid.userhost():
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 u"The message carbon received is not from our server, hack attempt?\n{xml}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 xml=message_elt.toXml()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 )
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 forwarded_elt = next(carbons_elt.elements(C.NS_FORWARD, "forwarded"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 cc_message_elt = next(forwarded_elt.elements(C.NS_CLIENT, "message"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 if carbons_elt.name == "received":
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 # on receive we replace the wrapping message with the CCed one
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 # and continue the normal behaviour
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 message_elt["from"] = cc_message_elt["from"]
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 del message_elt.children[:]
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 for c in cc_message_elt.children:
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 message_elt.addChild(c)
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 return True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 elif carbons_elt.name == "sent":
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 # on send we parse the message and just add it to history
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 # and send it to frontends (without normal sending treatments)
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 mess_data = SatMessageProtocol.parseMessage(cc_message_elt, client)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 if not mess_data["message"] and not mess_data["subject"]:
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155 return False
2152
6a004a22dd9e plugins XEP-0033, XEP-0280, text commands: fixed method renaming after client refactoring
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
156 client.messageAddToHistory(mess_data)
6a004a22dd9e plugins XEP-0033, XEP-0280, text commands: fixed method renaming after client refactoring
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
157 client.messageSendToBridge(mess_data)
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 u"invalid message carbons received:\n{xml}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 xml=message_elt.toXml()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 )
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 return False
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 class XEP_0280_handler(XMPPHandler):
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 implements(iwokkel.IDisco)
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 return [disco.DiscoFeature(NS_CARBONS)]
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
2099
ad88808591ef plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 return []