comparison libervia/backend/plugins/plugin_xep_0249.py @ 4245:a7d4007a8fa5

plugin XEP-0272: implement XEP-0272: Multiparty Jingle (Muji) rel 429
author Goffi <goffi@goffi.org>
date Wed, 15 May 2024 17:34:46 +0200
parents 4b842c1fb686
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4244:05f01ac1d5b2 4245:a7d4007a8fa5
23 from wokkel import disco, iwokkel 23 from wokkel import disco, iwokkel
24 from zope.interface import implementer 24 from zope.interface import implementer
25 25
26 from libervia.backend.core import exceptions 26 from libervia.backend.core import exceptions
27 from libervia.backend.core.constants import Const as C 27 from libervia.backend.core.constants import Const as C
28 from libervia.backend.core.core_types import SatXMPPEntity
28 from libervia.backend.core.i18n import D_, _ 29 from libervia.backend.core.i18n import D_, _
29 from libervia.backend.core.log import getLogger 30 from libervia.backend.core.log import getLogger
30 from libervia.backend.tools import xml_tools 31 from libervia.backend.tools import xml_tools
31 32
32 log = getLogger(__name__) 33 log = getLogger(__name__)
55 C.PI_HANDLER: "yes", 56 C.PI_HANDLER: "yes",
56 C.PI_DESCRIPTION: _("""Implementation of Direct MUC Invitations"""), 57 C.PI_DESCRIPTION: _("""Implementation of Direct MUC Invitations"""),
57 } 58 }
58 59
59 60
60 class XEP_0249(object): 61 class XEP_0249:
61 62
62 params = """ 63 params = """
63 <params> 64 <params>
64 <individual> 65 <individual>
65 <category name="%(category_name)s" label="%(category_label)s"> 66 <category name="%(category_name)s" label="%(category_label)s">
110 """ 111 """
111 # TODO: check parameters validity 112 # TODO: check parameters validity
112 client = self.host.get_client(profile_key) 113 client = self.host.get_client(profile_key)
113 self.invite(client, jid.JID(guest_jid_s), jid.JID(room_jid_s, options)) 114 self.invite(client, jid.JID(guest_jid_s), jid.JID(room_jid_s, options))
114 115
115 def invite(self, client, guest, room, options={}): 116 def invite(
117 self,
118 client: SatXMPPEntity,
119 guest: jid.JID,
120 room: jid.JID,
121 # the dict is only used internally, so we can safely use a default dict instead of
122 # None here.
123 **options
124 ) -> None:
116 """Invite a user to a room 125 """Invite a user to a room
117 126
118 @param guest(jid.JID): jid of the user to invite 127 @param guest: jid of the user to invite
119 @param room(jid.JID): jid of the room where the user is invited 128 @param room: jid of the room where the user is invited
120 @param options(dict): attribute with extra info (reason, password) as in #XEP-0249 129 @param options: attribute with extra info (reason, password) as in #XEP-0249
121 """ 130 """
122 message = domish.Element((None, "message")) 131 message = domish.Element((None, "message"))
123 message["to"] = guest.full() 132 message["to"] = guest.full()
124 x_elt = message.addElement((NS_X_CONFERENCE, "x")) 133 x_elt = message.addElement((NS_X_CONFERENCE, "x"))
125 x_elt["jid"] = room.userhost() 134 x_elt["jid"] = room.userhost()
126 for key, value in options.items(): 135 for key, value in options.items():
127 if key not in ("password", "reason", "thread"): 136 if key not in ("password", "reason", "thread"):
128 log.warning("Ignoring invalid invite option: {}".format(key)) 137 log.warning("Ignoring invalid invite option: {}".format(key))
129 continue 138 continue
130 x_elt[key] = value 139 x_elt[key] = value
131 #  there is not body in this message, so we can use directly send()
132 client.send(message) 140 client.send(message)
133 141
134 def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE): 142 def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE):
135 """Accept the invitation to join a MUC. 143 """Accept the invitation to join a MUC.
136 144
186 "declined according to your personal settings." 194 "declined according to your personal settings."
187 ) % {"user": from_jid_s, "room": room_jid_s} 195 ) % {"user": from_jid_s, "room": room_jid_s}
188 title = D_("MUC invitation") 196 title = D_("MUC invitation")
189 xml_tools.quick_note(self.host, client, msg, title, C.XMLUI_DATA_LVL_INFO) 197 xml_tools.quick_note(self.host, client, msg, title, C.XMLUI_DATA_LVL_INFO)
190 else: # leave the default value here 198 else: # leave the default value here
199 action_extra = {
200 "type": C.META_TYPE_CONFIRM,
201 "subtype": C.META_TYPE_MUC_INVIRATION,
202 "from_jid": from_jid_s,
203 "room_jid": room_jid_s
204 }
191 confirm_msg = D_( 205 confirm_msg = D_(
192 "You have been invited by %(user)s to join the room %(room)s. " 206 "You have been invited by %(user)s to join the room %(room)s. "
193 "Do you accept?" 207 "Do you accept?"
194 ) % {"user": from_jid_s, "room": room_jid_s} 208 ) % {"user": from_jid_s, "room": room_jid_s}
195 confirm_title = D_("MUC invitation") 209 confirm_title = D_("MUC invitation")
196 d = xml_tools.defer_confirm( 210 d = xml_tools.defer_confirm(
197 self.host, confirm_msg, confirm_title, profile=client.profile 211 self.host, confirm_msg, confirm_title, profile=client.profile,
212 action_extra=action_extra
198 ) 213 )
199 214
200 def accept_cb(accepted): 215 def accept_cb(accepted):
201 if accepted: 216 if accepted:
202 self._accept(room_jid, client.profile) 217 self._accept(room_jid, client.profile)