Commit 341c770b authored by mathieui's avatar mathieui Committed by Link Mauve

invite: remove callback and force impromptu rooms to use mediated

parent 048f3d5f
......@@ -996,7 +996,7 @@ class CommandCore:
name=name, server_address=address, callback=dumb_callback)
@command_args_parser.quoted(2, 1, [None])
def invite(self, args):
async def invite(self, args):
"""/invite <to> <room> [reason]"""
if args is None:
......@@ -1013,8 +1013,9 @@ class CommandCore:
except InvalidJID:
self.core.information('Invalid room JID specified to invite: %s' % args[1], 'Error')
return None
self.core.invite(to.full, room, reason=reason)
self.core.information('Invited %s to %s' % (to.bare, room), 'Info')
result = await self.core.invite(to.full, room, reason=reason)
if result:
self.core.information('Invited %s to %s' % (to.bare, room), 'Info')
@command_args_parser.quoted(1, 0)
def impromptu(self, args: str) -> None:
......
......@@ -885,25 +885,36 @@ class Core:
self.tabs.current_tab.command_say(msg)
return True
def invite(self, jid: JID, room: JID, reason: Optional[str] = None) -> None:
async def invite(self, jid: JID, room: JID, reason: Optional[str] = None, force_mediated: bool = False) -> bool:
"""
Checks if the sender supports XEP-0249, then send an invitation,
or a mediated one if it does not.
TODO: allow passwords
"""
features = set()
def callback(iq):
if not iq:
return
if 'jabber:x:conference' in iq['disco_info'].get_features():
self.xmpp.plugin['xep_0249'].send_invitation(
jid, room, reason=reason)
else: # fallback
self.xmpp.plugin['xep_0045'].invite(
room, jid, reason=reason or '')
self.xmpp.plugin['xep_0030'].get_info(
jid=jid, timeout=5, callback=callback)
# force mediated: act as if the other entity does not
# support direct invites
if not force_mediated:
try:
iq = await self.xmpp.plugin['xep_0030'].get_info(
jid=jid,
timeout=5,
)
features = iq['disco_info'].get_features()
except (IqError, IqTimeout):
pass
supports_direct = 'jabber:x:conference' in features
if supports_direct:
invite = self.xmpp.plugin['xep_0249'].send_invitation
else: # fallback
invite = self.xmpp.plugin['xep_0045'].invite
invite(
jid=jid,
room=room,
reason=reason
)
return True
def _impromptu_room_form(self, room):
fields = [
......@@ -990,7 +1001,7 @@ class Core:
self.information('Room %s created' % room, 'Info')
for jid in jids:
self.invite(jid, room)
await self.invite(jid, room, force_mediated=True)
####################### Tab logic-related things ##############################
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment