# HG changeset patch # User Goffi # Date 1581020181 -3600 # Node ID e2f806779b53938be3df9d493d77f6a7fce95666 # Parent d7948d2c1cc6de577e298180ec280f2b8d48fa3f chat: added a "close" item in menu, to leave MUC/close current chat widget. diff -r d7948d2c1cc6 -r e2f806779b53 cagou/plugins/plugin_wid_chat.kv --- 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 @@ : auto_width: False MenuButton: - text: _("Bookmarks") + text: _("bookmarks") on_release: root.select("bookmark") + MenuButton: + text: _("close") + on_release: root.select("close") : size_hint: None, 1 diff -r d7948d2c1cc6 -r e2f806779b53 cagou/plugins/plugin_wid_chat.py --- 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))