annotate libervia/backend/plugins/plugin_xep_0249.py @ 4197:9cda0347e0ac

plugin XEP-0359: if no origin ID is found, use <message> ID instead: This way, we always have the right ID to check for non groupchat message in `History.origin_id`.
author Goffi <goffi@goffi.org>
date Wed, 13 Dec 2023 22:00:25 +0100
parents 4b842c1fb686
children a7d4007a8fa5
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
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
20 from twisted.internet import defer
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
21 from twisted.words.protocols.jabber import jid
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
22 from twisted.words.xish import domish
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
23 from wokkel import disco, iwokkel
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
24 from zope.interface import implementer
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
25
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
26 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
27 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
28 from libervia.backend.core.i18n import D_, _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
29 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4051
diff changeset
30 from libervia.backend.tools import xml_tools
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
31
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
32 log = getLogger(__name__)
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
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
36 try:
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from twisted.words.protocols.xmlstream import XMPPHandler
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
38 except ImportError:
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
39 from wokkel.subprotocols import XMPPHandler
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
40
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 MESSAGE = "/message"
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
42 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
43 AUTOJOIN_KEY = "Misc"
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
44 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
45 AUTOJOIN_VALUES = ["ask", "always", "never"]
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
46
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.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: "XEP 0249 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-0249",
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-0249"],
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: ["XEP-0045"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
53 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
54 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
55 C.PI_HANDLER: "yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 C.PI_DESCRIPTION: _("""Implementation of Direct MUC Invitations"""),
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
57 }
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
58
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
59
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
60 class XEP_0249(object):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
61
689
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 <params>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
64 <individual>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
65 <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
66 <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
67 %(param_options)s
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
68 </param>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
69 </category>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
70 </individual>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
71 </params>
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
72 """ % {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 "category_name": AUTOJOIN_KEY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 "category_label": _("Misc"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 "param_name": AUTOJOIN_NAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 "param_label": _("Auto-join MUC on invitation"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 "param_options": "\n".join(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 '<option value="%s" %s/>'
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 % (value, 'selected="true"' if value == AUTOJOIN_VALUES[0] else "")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 for value in AUTOJOIN_VALUES
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 ]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 ),
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
84 }
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
85
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
87 log.info(_("Plugin XEP_0249 initialization"))
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.host = host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
89 host.memory.update_params(self.params)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
90 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
91 "muc_invite", ".plugin", in_sign="ssa{ss}s", out_sign="", method=self._invite
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 )
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
93 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
94 self.host.plugins[C.TEXT_CMDS].register_text_commands(self)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
95 except KeyError:
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
96 log.info(_("Text commands not available"))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
97 host.register_namespace('x-conference', NS_X_CONFERENCE)
4051
c23cad65ae99 core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
98 host.trigger.add("message_received", self._message_received_trigger)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
99
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
100 def get_handler(self, client):
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
101 return XEP_0249_handler()
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
102
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
103 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
104 """Invite an user to a room
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
105
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
106 @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
107 @param service: jid of the MUC service
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @param roomId: name of the room
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
109 @param profile_key: %(doc_profile_key)s
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
110 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 # TODO: check parameters validity
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
112 client = self.host.get_client(profile_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
113 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
114
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 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
116 """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
117
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 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
119 @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
120 @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
121 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 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
123 message["to"] = guest.full()
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
124 x_elt = message.addElement((NS_X_CONFERENCE, "x"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 x_elt["jid"] = room.userhost()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
126 for key, value in options.items():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 if key not in ("password", "reason", "thread"):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
128 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
129 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
130 x_elt[key] = value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 #  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
132 client.send(message)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
133
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
134 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
135 """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
136
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
137 @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
138 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
139 client = self.host.get_client(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
141 _("Invitation accepted for room %(room)s [%(profile)s]")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 % {"room": room_jid.userhost(), "profile": client.profile}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 )
4001
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
144 d = defer.ensureDeferred(
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
145 self.host.plugins["XEP-0045"].join(client, room_jid, client.jid.user, {})
32d714a8ea51 plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
146 )
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 968
diff changeset
147 return d
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
148
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
149 def _message_received_trigger(self, client, message_elt, post_treat):
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
150 """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
151 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
152 if x_elt is None:
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
153 return True
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
155 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
156 room_jid_s = x_elt["jid"]
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
157 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
158 log.warning(_("invalid invitation received: {xml}").format(
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
159 xml=message_elt.toXml()))
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
160 return False
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
161 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
162 _("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
163 % {"room": room_jid_s, "profile": client.profile}
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
164 )
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
165 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
166 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
167 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
168 self.host.plugins["XEP-0045"].check_room_joined(client, room_jid)
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
169 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
170 pass
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
171 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
173 _("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
174 )
710
3344f1d8a232 plugin XEP-0249: silently discard MUC invitation if user is already in
souliane <souliane@mailoo.org>
parents: 689
diff changeset
175 return
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
176
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
177 autojoin = self.host.memory.param_get_a(
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
178 AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=client.profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 )
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
180
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
181 if autojoin == "always":
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
182 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
183 elif autojoin == "never":
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 msg = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
185 "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
186 "declined according to your personal settings."
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 ) % {"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
188 title = D_("MUC invitation")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
189 xml_tools.quick_note(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
190 else: # leave the default value here
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 confirm_msg = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
192 "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
193 "Do you accept?"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 ) % {"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
195 confirm_title = D_("MUC invitation")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
196 d = xml_tools.defer_confirm(
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
197 self.host, confirm_msg, confirm_title, profile=client.profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199
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 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
201 if accepted:
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
202 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
203
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
204 d.addCallback(accept_cb)
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
205 return False
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
206
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
207 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
208 """invite someone in the room
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
209
1373
6d0e01809893 plugin text commands: minor docstrings improvments
Goffi <goffi@goffi.org>
parents: 1371
diff changeset
210 @command (group): JID
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
211 - 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
212 """
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_s = mess_data["unparsed"].strip()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
214 my_host = client.jid.host
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
215 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
216 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
217 except (RuntimeError, jid.InvalidFormat, AttributeError):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 feedback = _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
219 "You must provide a valid JID to invite, like in '/invite "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
220 "contact@{host}'"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 ).format(host=my_host)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4001
diff changeset
222 self.host.plugins[C.TEXT_CMDS].feed_back(client, feedback, mess_data)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
223 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
224 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
225 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
226 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
227 return False
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
228
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
229
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3002
diff changeset
230 @implementer(iwokkel.IDisco)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
231 class XEP_0249_handler(XMPPHandler):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
232
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
3002
6acaa8244220 plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
234 return [disco.DiscoFeature(NS_X_CONFERENCE)]
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
235
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
237 return []