annotate sat/plugins/plugin_xep_0249.py @ 2746:1e2f0856c845

memory (sqlite): retry _runInteraction in the same way as for _runQuery, this improve reliability
author Goffi <goffi@goffi.org>
date Fri, 04 Jan 2019 09:21:16 +0100
parents 56f94936df1e
children 003b8b4b56a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
5 # Copyright (C) 2009-2018 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
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from zope.interface import implements
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"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 NS_DIRECT_MUC_INVITATION = "jabber:x:conference"
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
42 DIRECT_MUC_INVITATION_REQUEST = MESSAGE + '/x[@xmlns="' + NS_DIRECT_MUC_INVITATION + '"]'
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
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
89 host.memory.updateParams(self.params)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 "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
92 )
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
93 try:
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
94 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
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"))
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
97
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2138
diff changeset
98 def getHandler(self, client):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
99 return XEP_0249_handler(self)
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
100
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
101 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
102 """Invite an user to a room
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
103
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
104 @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
105 @param service: jid of the MUC service
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
106 @param roomId: name of the room
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
107 @param profile_key: %(doc_profile_key)s
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
108 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 # 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
110 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
111 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
112
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 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
114 """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
115
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 @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
117 @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
118 @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
119 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 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
121 message["to"] = guest.full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 x_elt = message.addElement((NS_DIRECT_MUC_INVITATION, "x"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 x_elt["jid"] = room.userhost()
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 for key, value in options.iteritems():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 if key not in ("password", "reason", "thread"):
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
126 log.warning(u"Ignoring invalid invite option: {}".format(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
127 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
128 x_elt[key] = value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 #  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
130 client.send(message)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
131
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
132 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
133 """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
134
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 @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
136 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
137 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 _(u"Invitation accepted for room %(room)s [%(profile)s]")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 % {"room": room_jid.userhost(), "profile": client.profile}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
142 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
143 return d
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
144
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
145 def onInvitation(self, message, profile):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
146 """
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
147 called when an invitation is received
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
148 @param message: message element
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
149 @profile: %(doc_profile)s
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
150 """
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
151 client = self.host.getClient(profile)
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
152 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
153 room_jid_s = message.firstChildElement()["jid"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155 _(u"Invitation received for room %(room)s [%(profile)s]")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 % {"room": room_jid_s, "profile": profile}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 )
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
158 except:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 log.error(_("Error while parsing invitation"))
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
160 return
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
161 from_jid_s = message["from"]
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
162 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
163 try:
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
164 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
165 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
166 pass
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
167 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 _(u"Invitation silently discarded because user is already in the room.")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 )
710
3344f1d8a232 plugin XEP-0249: silently discard MUC invitation if user is already in
souliane <souliane@mailoo.org>
parents: 689
diff changeset
171 return
1970
200cd707a46d plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
172
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 autojoin = self.host.memory.getParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 )
689
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
176
78bf4ed37574 plugin XEP-249: added parameter Misc / Auto-join MUC on invitation
souliane <souliane@mailoo.org>
parents: 609
diff changeset
177 if autojoin == "always":
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
178 self._accept(room_jid, profile)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
179 elif autojoin == "never":
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 msg = D_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 "An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings."
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 ) % {"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
183 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
184 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
185 else: # leave the default value here
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 confirm_msg = D_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 "You have been invited by %(user)s to join the room %(room)s. Do you accept?"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 ) % {"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
189 confirm_title = D_("MUC invitation")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 d = xml_tools.deferConfirm(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 self.host, confirm_msg, confirm_title, profile=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193
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
194 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
195 if 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
196 self._accept(room_jid, profile)
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
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 d.addCallback(accept_cb)
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
199
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
200 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
201 """invite someone in the room
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
202
1373
6d0e01809893 plugin text commands: minor docstrings improvments
Goffi <goffi@goffi.org>
parents: 1371
diff changeset
203 @command (group): JID
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
204 - 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
205 """
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
206 contact_jid_s = mess_data["unparsed"].strip()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
207 my_host = client.jid.host
1002
291eb8216f6e plugins TEXT-COMMANDS, XEP-0045, XEP-0048, XEP-0249:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
208 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
209 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
210 except (RuntimeError, jid.InvalidFormat, AttributeError):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 feedback = _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 u"You must provide a valid JID to invite, like in '/invite contact@{host}'"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 ).format(host=my_host)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
214 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
215 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
216 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
217 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
218 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
219 return False
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
220
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
221
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
222 class XEP_0249_handler(XMPPHandler):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
223 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
224
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
225 def __init__(self, plugin_parent):
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
226 self.plugin_parent = plugin_parent
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
227 self.host = plugin_parent.host
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 def connectionInitialized(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 DIRECT_MUC_INVITATION_REQUEST,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 self.plugin_parent.onInvitation,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 profile=self.parent.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 )
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 getDiscoInfo(self, requestor, target, nodeIdentifier=""):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
237 return [disco.DiscoFeature(NS_DIRECT_MUC_INVITATION)]
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
238
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
239 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
317
f1f7c94278f2 added plugin XEP-0249: direct MUC invitation
Goffi <goffi@goffi.org>
parents:
diff changeset
240 return []