Ensure /bookmark{,_local} and /join use the proper tab object

Now that _add_bookmark is async.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-02-25 19:05:54 +01:00
parent a1af1355a9
commit 06dbefebb7
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -446,13 +446,18 @@ class CommandCore:
""" """
/bookmark_local [room][/nick] [password] /bookmark_local [room][/nick] [password]
""" """
if not args and not isinstance(self.core.tabs.current_tab, tab = self.core.tabs.current_tab
tabs.MucTab): if not args and not isinstance(tab, tabs.MucTab):
return return
room, nick = self._parse_join_jid(args[0] if args else '') room, nick = self._parse_join_jid(args[0] if args else '')
password = args[1] if len(args) > 1 else None password = args[1] if len(args) > 1 else None
if not room:
room = tab.jid.bare
if password is None and tab.password is not None:
password = tab.password
asyncio.create_task( asyncio.create_task(
self._add_bookmark( self._add_bookmark(
room=room, room=room,
@ -468,8 +473,8 @@ class CommandCore:
""" """
/bookmark [room][/nick] [autojoin] [password] /bookmark [room][/nick] [autojoin] [password]
""" """
if not args and not isinstance(self.core.tabs.current_tab, tab = self.core.tabs.current_tab
tabs.MucTab): if not args and not isinstance(tab, tabs.MucTab):
return return
room, nick = self._parse_join_jid(args[0] if args else '') room, nick = self._parse_join_jid(args[0] if args else '')
password = args[2] if len(args) > 2 else None password = args[2] if len(args) > 2 else None
@ -478,13 +483,18 @@ class CommandCore:
autojoin = (method == 'local' or autojoin = (method == 'local' or
(len(args) > 1 and args[1].lower() == 'true')) (len(args) > 1 and args[1].lower() == 'true'))
if not room:
room = tab.jid.bare
if password is None and tab.password is not None:
password = tab.password
asyncio.create_task( asyncio.create_task(
self._add_bookmark(room, nick, autojoin, password, method) self._add_bookmark(room, nick, autojoin, password, method)
) )
async def _add_bookmark( async def _add_bookmark(
self, self,
room: Optional[str], room: str,
nick: Optional[str], nick: Optional[str],
autojoin: bool, autojoin: bool,
password: str, password: str,
@ -503,16 +513,8 @@ class CommandCore:
method: 'local' or 'remote'. method: 'local' or 'remote'.
''' '''
# No room Jid was specified. A nick may have been specified. Set the
# room Jid to be bookmarked to the current tab bare jid. if room == '*':
if not room:
tab = self.core.tabs.current_tab
if not isinstance(tab, tabs.MucTab):
return
room = tab.jid.bare
if password is None and tab.password is not None:
password = tab.password
elif room == '*':
return await self._add_wildcard_bookmarks(method) return await self._add_wildcard_bookmarks(method)
# Once we found which room to bookmark, find corresponding tab if it # Once we found which room to bookmark, find corresponding tab if it