annotate sat/plugins/plugin_xep_0249.py @ 3728:b15644cae50d

component AP gateway: JID/node ⟺ AP outbox conversion: - convert a combination of JID and optional pubsub node to AP actor handle (see `getJIDAndNode` for details) and vice versa - the gateway now provides a Pubsub service - retrieve pubsub node and convert it to AP collection, AP pagination is converted to RSM - do the opposite: convert AP collection to pubsub and handle RSM request. Due to ActivityStream collection pagination limitations, some RSM request produce inefficient requests, but caching should be used most of the time in the future and avoid the problem. - set specific name to HTTP Server - new `local_only` setting (`True` by default) to indicate if the gateway can request or not XMPP Pubsub nodes from other servers - disco info now specifies important features such as Pubsub RSM, and nodes metadata ticket 363
author Goffi <goffi@goffi.org>
date Tue, 25 Jan 2022 17:54:06 +0100
parents be6d91572633
children 32d714a8ea51
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for managing xep-0249
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3172
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
19
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
20 from sat.core.i18n import _, D_
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 844
diff changeset
21 from sat.core.constants import Const as C
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
22 from sat.core import exceptions
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
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: 968
diff changeset
25 log = getLogger(__name__)
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
26 from sat.tools import xml_tools
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.xish import domish
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
28 from twisted.words.protocols.jabber import jid
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
29
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
30 from zope.interface import implementer
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
31
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
32 from wokkel import disco, iwokkel
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
33
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
34
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
35 try:
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from twisted.words.protocols.xmlstream import XMPPHandler
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 except ImportError:
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from wokkel.subprotocols import XMPPHandler
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
39
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 MESSAGE = "/message"
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
41 NS_X_CONFERENCE = "jabber:x:conference"
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
42 AUTOJOIN_KEY = "Misc"
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
43 AUTOJOIN_NAME = "Auto-join MUC on invitation"
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
44 AUTOJOIN_VALUES = ["ask", "always", "never"]
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
45
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
46 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
47 C.PI_NAME: "XEP 0249 Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
48 C.PI_IMPORT_NAME: "XEP-0249",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
49 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
50 C.PI_PROTOCOLS: ["XEP-0249"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
51 C.PI_DEPENDENCIES: ["XEP-0045"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
52 C.PI_RECOMMENDATIONS: [C.TEXT_CMDS],
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_0249",
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 Direct MUC Invitations"""),
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
56 }
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
57
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
59 class XEP_0249(object):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
60
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
61 params = """
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
62 <params>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
63 <individual>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
64 <category name="%(category_name)s" label="%(category_label)s">
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 916
diff changeset
65 <param name="%(param_name)s" label="%(param_label)s" type="list" security="0">
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
66 %(param_options)s
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
67 </param>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
68 </category>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
69 </individual>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
70 </params>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
71 """ % {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 "category_name": AUTOJOIN_KEY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 "category_label": _("Misc"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 "param_name": AUTOJOIN_NAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 "param_label": _("Auto-join MUC on invitation"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 "param_options": "\n".join(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 '<option value="%s" %s/>'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 % (value, 'selected="true"' if value == AUTOJOIN_VALUES[0] else "")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 for value in AUTOJOIN_VALUES
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 ]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 ),
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
83 }
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
84
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
85 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
86 log.info(_("Plugin XEP_0249 initialization"))
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.host = host
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
88 host.memory.updateParams(self.params)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 "inviteMUC", ".plugin", in_sign="ssa{ss}s", out_sign="", method=self._invite
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 )
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
92 try:
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
93 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
94 except KeyError:
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
95 log.info(_("Text commands not available"))
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
96 host.registerNamespace('x-conference', NS_X_CONFERENCE)
3172
dcebc585c29f core: renamed "MessageReceived" trigger to "messageReceived" for consistency.
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
97 host.trigger.add("messageReceived", self._messageReceivedTrigger)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
98
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
99 def getHandler(self, client):
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
100 return XEP_0249_handler()
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
101
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
102 def _invite(self, guest_jid_s, room_jid_s, options, profile_key):
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
103 """Invite an user to a room
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
104
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
105 @param guest_jid_s: jid of the user to invite
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
106 @param service: jid of the MUC service
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
107 @param roomId: name of the room
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @param profile_key: %(doc_profile_key)s
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
109 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 # TODO: check parameters validity
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
111 client = self.host.getClient(profile_key)
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
112 self.invite(client, jid.JID(guest_jid_s), jid.JID(room_jid_s, options))
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
113
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
114 def invite(self, client, guest, room, options={}):
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
115 """Invite a user to a room
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
116
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
117 @param guest(jid.JID): jid of the user to invite
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
118 @param room(jid.JID): jid of the room where the user is invited
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
119 @param options(dict): attribute with extra info (reason, password) as in #XEP-0249
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
120 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 message = domish.Element((None, "message"))
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
122 message["to"] = guest.full()
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
123 x_elt = message.addElement((NS_X_CONFERENCE, "x"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 x_elt["jid"] = room.userhost()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
125 for key, value in options.items():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 if key not in ("password", "reason", "thread"):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
127 log.warning("Ignoring invalid invite option: {}".format(key))
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
128 continue
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
129 x_elt[key] = value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 #  there is not body in this message, so we can use directly send()
2129
6a66c8c5a567 core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents: 2045
diff changeset
131 client.send(message)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
132
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
133 def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE):
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
134 """Accept the invitation to join a MUC.
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
135
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
136 @param room (jid.JID): JID of the room
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
137 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
138 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
140 _("Invitation accepted for room %(room)s [%(profile)s]")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 % {"room": room_jid.userhost(), "profile": client.profile}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
143 d = self.host.plugins["XEP-0045"].join(client, room_jid, client.jid.user, {})
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
144 return d
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
145
3172
dcebc585c29f core: renamed "MessageReceived" trigger to "messageReceived" for consistency.
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
146 def _messageReceivedTrigger(self, client, message_elt, post_treat):
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
147 """Check if a direct invitation is in the message, and handle it"""
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
148 x_elt = next(message_elt.elements(NS_X_CONFERENCE, 'x'), None)
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
149 if x_elt is None:
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
150 return True
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
151
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
152 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
153 room_jid_s = x_elt["jid"]
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
155 log.warning(_("invalid invitation received: {xml}").format(
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
156 xml=message_elt.toXml()))
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
157 return False
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
158 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
159 _("Invitation received for room %(room)s [%(profile)s]")
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
160 % {"room": room_jid_s, "profile": client.profile}
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
161 )
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
162 from_jid_s = message_elt["from"]
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1002
diff changeset
163 room_jid = jid.JID(room_jid_s)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
164 try:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
165 self.host.plugins["XEP-0045"].checkRoomJoined(client, room_jid)
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
166 except exceptions.NotFound:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
167 pass
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
168 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
170 _("Invitation silently discarded because user is already in the room.")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 )
710
3344f1d8a232 plugin XEP-0249: silently discard MUC invitation if user is already in
souliane <souliane@mailoo.org>
parents: 689
diff changeset
172 return
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
173
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 autojoin = self.host.memory.getParamA(
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
175 AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=client.profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 )
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
177
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
178 if autojoin == "always":
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
179 self._accept(room_jid, client.profile)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
180 elif autojoin == "never":
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 msg = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
182 "An invitation from %(user)s to join the room %(room)s has been "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
183 "declined according to your personal settings."
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 ) % {"user": from_jid_s, "room": room_jid_s}
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
185 title = D_("MUC invitation")
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
186 xml_tools.quickNote(self.host, client, msg, title, C.XMLUI_DATA_LVL_INFO)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
187 else: # leave the default value here
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 confirm_msg = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
189 "You have been invited by %(user)s to join the room %(room)s. "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
190 "Do you accept?"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 ) % {"user": from_jid_s, "room": room_jid_s}
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
192 confirm_title = D_("MUC invitation")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 d = xml_tools.deferConfirm(
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
194 self.host, confirm_msg, confirm_title, profile=client.profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
197 def accept_cb(accepted):
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
198 if accepted:
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
199 self._accept(room_jid, client.profile)
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
200
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
201 d.addCallback(accept_cb)
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
202 return False
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
203
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
204 def cmd_invite(self, client, mess_data):
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
205 """invite someone in the room
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
206
1373
6d0e01809893 plugin text commands: minor docstrings improvments
Goffi <goffi@goffi.org>
parents: 1371
diff changeset
207 @command (group): JID
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
208 - JID: the JID of the person to invite
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
209 """
1384
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1373
diff changeset
210 contact_jid_s = mess_data["unparsed"].strip()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
211 my_host = client.jid.host
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
212 try:
1384
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1373
diff changeset
213 contact_jid = jid.JID(contact_jid_s)
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1373
diff changeset
214 except (RuntimeError, jid.InvalidFormat, AttributeError):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
215 feedback = _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
216 "You must provide a valid JID to invite, like in '/invite "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
217 "contact@{host}'"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 ).format(host=my_host)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
219 self.host.plugins[C.TEXT_CMDS].feedBack(client, feedback, mess_data)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
220 return False
1384
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1373
diff changeset
221 if not contact_jid.user:
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1373
diff changeset
222 contact_jid.user, contact_jid.host = contact_jid.host, my_host
2045
48536a22b599 plugin XEP-0249: some modernisation, don't use anymore deprecated methods, invite bridge method use a single param for room jid
Goffi <goffi@goffi.org>
parents: 1994
diff changeset
223 self.invite(client, contact_jid, mess_data["to"])
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
224 return False
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
225
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
226
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
227 @implementer(iwokkel.IDisco)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
228 class XEP_0249_handler(XMPPHandler):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
229
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
231 return [disco.DiscoFeature(NS_X_CONFERENCE)]
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
232
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
234 return []