From f82e83067e6a61815a60ea8c56f944aa49d79e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 1 Apr 2020 00:51:21 +0200 Subject: [PATCH 1/5] reorder: Add TODO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/reorder.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/reorder.py b/plugins/reorder.py index 8d9516f8..ca3bda08 100644 --- a/plugins/reorder.py +++ b/plugins/reorder.py @@ -177,6 +177,8 @@ class Plugin(BasePlugin): if tab: new_tabs.append(tab) + # TODO: Ensure we don't break poezio and call this with whatever + # tablist we have. The roster tab at least needs to be in there. self.core.tabs.replace_tabs(new_tabs) self.core.refresh_window() From 00b91fe46218be23e040813aacbc73987b9015a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 1 Apr 2020 01:16:11 +0200 Subject: [PATCH 2/5] reorder: Ensure valid JID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/reorder.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/reorder.py b/plugins/reorder.py index ca3bda08..eebc810a 100644 --- a/plugins/reorder.py +++ b/plugins/reorder.py @@ -59,6 +59,8 @@ And finally, the ``[tab name]`` must be: - For a type ``static``, the full JID of the contact """ +from slixmpp import InvalidJID, JID + from poezio import tabs from poezio.decorators import command_args_parser from poezio.plugin import BasePlugin @@ -162,13 +164,18 @@ class Plugin(BasePlugin): new_tabs += [ tabs.GapTab(self.core) for i in range(pos - last - 1) ] - cls, name = tabs_spec[pos] - tab = self.core.tabs.by_name_and_class(name, cls=cls) + cls, jid = tabs_spec[pos] + try: + jid = JID(jid) + except InvalidJID: + self.api.information('Reorder: Invalid JID \'%s\'.' % jid, 'Warning') + continue + tab = self.core.tabs.by_name_and_class(str(jid), cls=cls) if tab and tab in old_tabs: new_tabs.append(tab) old_tabs.remove(tab) else: - self.api.information('Tab %s not found' % name, 'Warning') + self.api.information('Tab %s not found' % jid, 'Warning') if create_gaps: new_tabs.append(tabs.GapTab(self.core)) last = pos From 7d6b301087dcdc95fb177ea62eb9866ba354ccf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 1 Apr 2020 01:17:01 +0200 Subject: [PATCH 3/5] reorder: Create ConversationTabs when they don't exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/reorder.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/reorder.py b/plugins/reorder.py index eebc810a..2708d395 100644 --- a/plugins/reorder.py +++ b/plugins/reorder.py @@ -175,9 +175,15 @@ class Plugin(BasePlugin): new_tabs.append(tab) old_tabs.remove(tab) else: - self.api.information('Tab %s not found' % jid, 'Warning') - if create_gaps: - new_tabs.append(tabs.GapTab(self.core)) + self.api.information('Tab %s not found. Creating it' % jid, 'Warning') + # TODO: Add support for MucTab. Requires nickname. + if cls in (tabs.DynamicConversationTab, tabs.StaticConversationTab): + try: + new_tab = cls(self.core, jid) + new_tabs.append(new_tab) + except: + self.api.information('Failed to create tab \'%s\'.' % jid, 'Error') + continue last = pos for tab in old_tabs: From 496752d0db3d54dac7c15220042c9631d587e226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 1 Apr 2020 01:26:08 +0200 Subject: [PATCH 4/5] reorder: create GapTab if configured, when creating ConversationTab fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/reorder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/reorder.py b/plugins/reorder.py index 2708d395..e61a9925 100644 --- a/plugins/reorder.py +++ b/plugins/reorder.py @@ -183,7 +183,8 @@ class Plugin(BasePlugin): new_tabs.append(new_tab) except: self.api.information('Failed to create tab \'%s\'.' % jid, 'Error') - continue + if create_gaps: + new_tabs.append(tabs.GapTab(self.core)) last = pos for tab in old_tabs: From da695768b099d91e24c678d7abc70560ff75444a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 1 Apr 2020 01:33:09 +0200 Subject: [PATCH 5/5] reorder: group exception handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/reorder.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/plugins/reorder.py b/plugins/reorder.py index e61a9925..7be0b350 100644 --- a/plugins/reorder.py +++ b/plugins/reorder.py @@ -167,25 +167,22 @@ class Plugin(BasePlugin): cls, jid = tabs_spec[pos] try: jid = JID(jid) - except InvalidJID: - self.api.information('Reorder: Invalid JID \'%s\'.' % jid, 'Warning') - continue - tab = self.core.tabs.by_name_and_class(str(jid), cls=cls) - if tab and tab in old_tabs: - new_tabs.append(tab) - old_tabs.remove(tab) - else: - self.api.information('Tab %s not found. Creating it' % jid, 'Warning') - # TODO: Add support for MucTab. Requires nickname. - if cls in (tabs.DynamicConversationTab, tabs.StaticConversationTab): - try: + tab = self.core.tabs.by_name_and_class(str(jid), cls=cls) + if tab and tab in old_tabs: + new_tabs.append(tab) + old_tabs.remove(tab) + else: + self.api.information('Tab %s not found. Creating it' % jid, 'Warning') + # TODO: Add support for MucTab. Requires nickname. + if cls in (tabs.DynamicConversationTab, tabs.StaticConversationTab): new_tab = cls(self.core, jid) new_tabs.append(new_tab) - except: - self.api.information('Failed to create tab \'%s\'.' % jid, 'Error') - if create_gaps: - new_tabs.append(tabs.GapTab(self.core)) - last = pos + except: + self.api.information('Failed to create tab \'%s\'.' % jid, 'Error') + if create_gaps: + new_tabs.append(tabs.GapTab(self.core)) + finally: + last = pos for tab in old_tabs: if tab: