Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0249.py @ 4322:00837fa13e5a default tip @
tools (common/template), cli (call/gui): use font-awesome instead of fontello:
following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 22:42:17 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 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 | 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 |
4245
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
28 from libervia.backend.core.core_types import SatXMPPEntity |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
29 from libervia.backend.core.i18n import D_, _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
30 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
31 from libervia.backend.tools import xml_tools |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
33 log = getLogger(__name__) |
317
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 |
4245
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
60 class XEP_0249: |
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")) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
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 |
4245
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
115 def invite( |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
116 self, |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
117 client: SatXMPPEntity, |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
118 guest: jid.JID, |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
119 room: jid.JID, |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
120 # the dict is only used internally, so we can safely use a default dict instead of |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
121 # None here. |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
122 **options, |
4245
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
123 ) -> None: |
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
|
124 """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
|
125 |
4245
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
126 @param guest: jid of the user to invite |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
127 @param room: jid of the room where the user is invited |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
128 @param options: attribute with extra info (reason, password) as in #XEP-0249 |
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 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 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
|
131 message["to"] = guest.full() |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
132 x_elt = message.addElement((NS_X_CONFERENCE, "x")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 x_elt["jid"] = room.userhost() |
3028 | 134 for key, value in options.items(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 if key not in ("password", "reason", "thread"): |
3028 | 136 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
|
137 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
|
138 x_elt[key] = value |
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
|
139 client.send(message) |
317
f1f7c94278f2
added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
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
|
141 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
|
142 """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
|
143 |
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
|
144 @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
|
145 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4001
diff
changeset
|
146 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 log.info( |
3028 | 148 _("Invitation accepted for room %(room)s [%(profile)s]") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 % {"room": room_jid.userhost(), "profile": client.profile} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 ) |
4001
32d714a8ea51
plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
151 d = defer.ensureDeferred( |
32d714a8ea51
plugin XEP-0045: dot not wait for MAM retrieval to be completed:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
152 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
|
153 ) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
968
diff
changeset
|
154 return d |
689
78bf4ed37574
plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
155 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4001
diff
changeset
|
156 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
|
157 """Check if a direct invitation is in the message, and handle it""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
158 x_elt = next(message_elt.elements(NS_X_CONFERENCE, "x"), None) |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
159 if x_elt is None: |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
160 return True |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
161 |
317
f1f7c94278f2
added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 try: |
3028 | 163 room_jid_s = x_elt["jid"] |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
164 except KeyError: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
165 log.warning( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
166 _("invalid invitation received: {xml}").format(xml=message_elt.toXml()) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
167 ) |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
168 return False |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
169 log.info( |
3028 | 170 _("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
|
171 % {"room": room_jid_s, "profile": client.profile} |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
172 ) |
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
173 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
|
174 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
|
175 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4001
diff
changeset
|
176 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
|
177 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
|
178 pass |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
179 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 log.info( |
3028 | 181 _("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
|
182 ) |
710
3344f1d8a232
plugin XEP-0249: silently discard MUC invitation if user is already in
souliane <souliane@mailoo.org>
parents:
689
diff
changeset
|
183 return |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
184 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4001
diff
changeset
|
185 autojoin = self.host.memory.param_get_a( |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
186 AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=client.profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 ) |
689
78bf4ed37574
plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
188 |
78bf4ed37574
plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
189 if autojoin == "always": |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
190 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
|
191 elif autojoin == "never": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
192 msg = D_( |
3028 | 193 "An invitation from %(user)s to join the room %(room)s has been " |
194 "declined according to your personal settings." | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 ) % {"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
|
196 title = D_("MUC invitation") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4001
diff
changeset
|
197 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
|
198 else: # leave the default value here |
4245
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
199 action_extra = { |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
200 "type": C.META_TYPE_CONFIRM, |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
201 "subtype": C.META_TYPE_MUC_INVIRATION, |
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
202 "from_jid": from_jid_s, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
203 "room_jid": room_jid_s, |
4245
a7d4007a8fa5
plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji)
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
204 } |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
205 confirm_msg = D_( |
3028 | 206 "You have been invited by %(user)s to join the room %(room)s. " |
207 "Do you accept?" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 ) % {"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
|
209 confirm_title = D_("MUC invitation") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4001
diff
changeset
|
210 d = xml_tools.defer_confirm( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
211 self.host, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
212 confirm_msg, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
213 confirm_title, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
214 profile=client.profile, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4245
diff
changeset
|
215 action_extra=action_extra, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
217 |
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
|
218 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
|
219 if accepted: |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
220 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
|
221 |
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
|
222 d.addCallback(accept_cb) |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
223 return False |
1002
291eb8216f6e
plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
224 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
225 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
|
226 """invite someone in the room |
291eb8216f6e
plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
227 |
1373
6d0e01809893
plugin text commands: minor docstrings improvments
Goffi <goffi@goffi.org>
parents:
1371
diff
changeset
|
228 @command (group): JID |
1002
291eb8216f6e
plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
229 - 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
|
230 """ |
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
|
231 contact_jid_s = mess_data["unparsed"].strip() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
232 my_host = client.jid.host |
1002
291eb8216f6e
plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
233 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
|
234 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
|
235 except (RuntimeError, jid.InvalidFormat, AttributeError): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 feedback = _( |
3028 | 237 "You must provide a valid JID to invite, like in '/invite " |
238 "contact@{host}'" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 ).format(host=my_host) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4001
diff
changeset
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 return False |
317
f1f7c94278f2
added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 |
f1f7c94278f2
added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 |
3028 | 248 @implementer(iwokkel.IDisco) |
317
f1f7c94278f2
added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 class XEP_0249_handler(XMPPHandler): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
250 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
3002
6acaa8244220
plugin 0249: fixed invitation handling + some improvments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
252 return [disco.DiscoFeature(NS_X_CONFERENCE)] |
317
f1f7c94278f2
added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
254 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
317
f1f7c94278f2
added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 return [] |