summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/core/commands.py7
-rw-r--r--poezio/core/core.py39
2 files changed, 29 insertions, 17 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index 5dbf5b8b..b68a922e 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -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:
diff --git a/poezio/core/core.py b/poezio/core/core.py
index ee1a111b..703319c5 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -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 ##############################