From 06dbefebb763c86bee3e242e290370df6f7d50f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 25 Feb 2022 19:05:54 +0100 Subject: [PATCH] Ensure /bookmark{,_local} and /join use the proper tab object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that _add_bookmark is async. Signed-off-by: Maxime “pep” Buquet --- poezio/core/commands.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/poezio/core/commands.py b/poezio/core/commands.py index bc594494..4c7b3e4f 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -446,13 +446,18 @@ class CommandCore: """ /bookmark_local [room][/nick] [password] """ - if not args and not isinstance(self.core.tabs.current_tab, - tabs.MucTab): + tab = self.core.tabs.current_tab + if not args and not isinstance(tab, tabs.MucTab): return room, nick = self._parse_join_jid(args[0] if args else '') 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( self._add_bookmark( room=room, @@ -468,8 +473,8 @@ class CommandCore: """ /bookmark [room][/nick] [autojoin] [password] """ - if not args and not isinstance(self.core.tabs.current_tab, - tabs.MucTab): + tab = self.core.tabs.current_tab + if not args and not isinstance(tab, tabs.MucTab): return room, nick = self._parse_join_jid(args[0] if args else '') password = args[2] if len(args) > 2 else None @@ -478,13 +483,18 @@ class CommandCore: autojoin = (method == 'local' or (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( self._add_bookmark(room, nick, autojoin, password, method) ) async def _add_bookmark( self, - room: Optional[str], + room: str, nick: Optional[str], autojoin: bool, password: str, @@ -503,16 +513,8 @@ class CommandCore: 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 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 == '*': + + if room == '*': return await self._add_wildcard_bookmarks(method) # Once we found which room to bookmark, find corresponding tab if it