comparison libervia/backend/plugins/plugin_xep_0249.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents a7d4007a8fa5
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
29 from libervia.backend.core.i18n import D_, _ 29 from libervia.backend.core.i18n import D_, _
30 from libervia.backend.core.log import getLogger 30 from libervia.backend.core.log import getLogger
31 from libervia.backend.tools import xml_tools 31 from libervia.backend.tools import xml_tools
32 32
33 log = getLogger(__name__) 33 log = getLogger(__name__)
34
35 34
36 35
37 try: 36 try:
38 from twisted.words.protocols.xmlstream import XMPPHandler 37 from twisted.words.protocols.xmlstream import XMPPHandler
39 except ImportError: 38 except ImportError:
93 ) 92 )
94 try: 93 try:
95 self.host.plugins[C.TEXT_CMDS].register_text_commands(self) 94 self.host.plugins[C.TEXT_CMDS].register_text_commands(self)
96 except KeyError: 95 except KeyError:
97 log.info(_("Text commands not available")) 96 log.info(_("Text commands not available"))
98 host.register_namespace('x-conference', NS_X_CONFERENCE) 97 host.register_namespace("x-conference", NS_X_CONFERENCE)
99 host.trigger.add("message_received", self._message_received_trigger) 98 host.trigger.add("message_received", self._message_received_trigger)
100 99
101 def get_handler(self, client): 100 def get_handler(self, client):
102 return XEP_0249_handler() 101 return XEP_0249_handler()
103 102
118 client: SatXMPPEntity, 117 client: SatXMPPEntity,
119 guest: jid.JID, 118 guest: jid.JID,
120 room: jid.JID, 119 room: jid.JID,
121 # the dict is only used internally, so we can safely use a default dict instead of 120 # the dict is only used internally, so we can safely use a default dict instead of
122 # None here. 121 # None here.
123 **options 122 **options,
124 ) -> None: 123 ) -> None:
125 """Invite a user to a room 124 """Invite a user to a room
126 125
127 @param guest: jid of the user to invite 126 @param guest: jid of the user to invite
128 @param room: jid of the room where the user is invited 127 @param room: jid of the room where the user is invited
154 ) 153 )
155 return d 154 return d
156 155
157 def _message_received_trigger(self, client, message_elt, post_treat): 156 def _message_received_trigger(self, client, message_elt, post_treat):
158 """Check if a direct invitation is in the message, and handle it""" 157 """Check if a direct invitation is in the message, and handle it"""
159 x_elt = next(message_elt.elements(NS_X_CONFERENCE, 'x'), None) 158 x_elt = next(message_elt.elements(NS_X_CONFERENCE, "x"), None)
160 if x_elt is None: 159 if x_elt is None:
161 return True 160 return True
162 161
163 try: 162 try:
164 room_jid_s = x_elt["jid"] 163 room_jid_s = x_elt["jid"]
165 except KeyError: 164 except KeyError:
166 log.warning(_("invalid invitation received: {xml}").format( 165 log.warning(
167 xml=message_elt.toXml())) 166 _("invalid invitation received: {xml}").format(xml=message_elt.toXml())
167 )
168 return False 168 return False
169 log.info( 169 log.info(
170 _("Invitation received for room %(room)s [%(profile)s]") 170 _("Invitation received for room %(room)s [%(profile)s]")
171 % {"room": room_jid_s, "profile": client.profile} 171 % {"room": room_jid_s, "profile": client.profile}
172 ) 172 )
198 else: # leave the default value here 198 else: # leave the default value here
199 action_extra = { 199 action_extra = {
200 "type": C.META_TYPE_CONFIRM, 200 "type": C.META_TYPE_CONFIRM,
201 "subtype": C.META_TYPE_MUC_INVIRATION, 201 "subtype": C.META_TYPE_MUC_INVIRATION,
202 "from_jid": from_jid_s, 202 "from_jid": from_jid_s,
203 "room_jid": room_jid_s 203 "room_jid": room_jid_s,
204 } 204 }
205 confirm_msg = D_( 205 confirm_msg = D_(
206 "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. "
207 "Do you accept?" 207 "Do you accept?"
208 ) % {"user": from_jid_s, "room": room_jid_s} 208 ) % {"user": from_jid_s, "room": room_jid_s}
209 confirm_title = D_("MUC invitation") 209 confirm_title = D_("MUC invitation")
210 d = xml_tools.defer_confirm( 210 d = xml_tools.defer_confirm(
211 self.host, confirm_msg, confirm_title, profile=client.profile, 211 self.host,
212 action_extra=action_extra 212 confirm_msg,
213 confirm_title,
214 profile=client.profile,
215 action_extra=action_extra,
213 ) 216 )
214 217
215 def accept_cb(accepted): 218 def accept_cb(accepted):
216 if accepted: 219 if accepted:
217 self._accept(room_jid, client.profile) 220 self._accept(room_jid, client.profile)