changeset 261:a579eda31f4f

chat: don't use "force" argument anymore
author Goffi <goffi@goffi.org>
date Mon, 11 Mar 2019 08:39:43 +0100
parents 145c29b5f2b5
children 825e8c91b703
files cagou/plugins/plugin_wid_chat.py
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.py	Mon Mar 11 08:39:43 2019 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Mon Mar 11 08:39:43 2019 +0100
@@ -678,14 +678,16 @@
         self.encryption_btn.symbol = self.encryption_btn.getSymbol()
         self.encryption_btn.color = self.encryption_btn.getColor()
 
-    def onDelete(self, force=False):
-        if force==True:
-            return self._onDelete()
-        if len(list(G.host.widgets.getWidgets(
-            self.__class__, self.target, profiles=self.profiles))) > 1:
-            # we don't keep duplicate widgets
-            return self._onDelete()
-        return False
+    def onDelete(self):
+        # we always keep one widget, so it's available when swiping
+        # TODO: delete all widgets when chat is closed
+        nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self))
+        if nb_instances > 1:
+            self.host.removeListener('progressFinished', self.onProgressFinished)
+            self.host.removeListener('progressError', self.onProgressError)
+            return super(Chat, self).onDelete()
+        else:
+            return False
 
 
 PLUGIN_INFO["factory"] = Chat.factory