changeset 393:e2f806779b53

chat: added a "close" item in menu, to leave MUC/close current chat widget.
author Goffi <goffi@goffi.org>
date Thu, 06 Feb 2020 21:16:21 +0100
parents d7948d2c1cc6
children d15828ca9d86
files cagou/plugins/plugin_wid_chat.kv cagou/plugins/plugin_wid_chat.py
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.kv	Thu Feb 06 21:16:21 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.kv	Thu Feb 06 21:16:21 2020 +0100
@@ -165,8 +165,11 @@
 <ExtraMenu>:
     auto_width: False
     MenuButton:
-        text: _("Bookmarks")
+        text: _("bookmarks")
         on_release: root.select("bookmark")
+    MenuButton:
+        text: _("close")
+        on_release: root.select("close")
 
 <ExtraButton>:
     size_hint: None, 1
--- a/cagou/plugins/plugin_wid_chat.py	Thu Feb 06 21:16:21 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Thu Feb 06 21:16:21 2020 +0100
@@ -198,6 +198,15 @@
                                      callback=partial(
                                         G.host.actionManager, profile=self.chat.profile),
                                      errback=G.host.errback)
+        elif menu == 'close':
+            if self.chat.type == C.CHAT_GROUP:
+                # for MUC, we have to indicate the backend that we've left
+                G.host.bridge.mucLeave(self.chat.target, self.chat.profile)
+            else:
+                # for one2one, backend doesn't keep any state, so we just delete the
+                # widget here in the frontend
+                G.host.widgets.deleteWidget(
+                    self.chat, all_instances=True, explicit_close=True)
         else:
             raise exceptions.InternalError("Unknown menu: {}".format(menu))
 
@@ -778,6 +787,16 @@
             self.resync()
 
     def onDelete(self, **kwargs):
+        if kwargs.get('explicit_close', False):
+            wrapper = self.whwrapper
+            if wrapper is not None:
+                if len(wrapper.carousel.slides) == 1:
+                    # if we delete the last opened chat, we need to show the selector
+                    screen_manager = self.screen_manager
+                    screen_manager.transition.direction = 'down'
+                    screen_manager.current = 'chat_selector'
+                wrapper.carousel.remove_widget(self)
+            return True
         # 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))