comparison cagou/plugins/plugin_wid_chat.py @ 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 d61bbbac4160
children d15828ca9d86
comparison
equal deleted inserted replaced
392:d7948d2c1cc6 393:e2f806779b53
196 G.host.bridge.menuLaunch(C.MENU_GLOBAL, ("groups", "bookmarks"), 196 G.host.bridge.menuLaunch(C.MENU_GLOBAL, ("groups", "bookmarks"),
197 {}, C.NO_SECURITY_LIMIT, self.chat.profile, 197 {}, C.NO_SECURITY_LIMIT, self.chat.profile,
198 callback=partial( 198 callback=partial(
199 G.host.actionManager, profile=self.chat.profile), 199 G.host.actionManager, profile=self.chat.profile),
200 errback=G.host.errback) 200 errback=G.host.errback)
201 elif menu == 'close':
202 if self.chat.type == C.CHAT_GROUP:
203 # for MUC, we have to indicate the backend that we've left
204 G.host.bridge.mucLeave(self.chat.target, self.chat.profile)
205 else:
206 # for one2one, backend doesn't keep any state, so we just delete the
207 # widget here in the frontend
208 G.host.widgets.deleteWidget(
209 self.chat, all_instances=True, explicit_close=True)
201 else: 210 else:
202 raise exceptions.InternalError("Unknown menu: {}".format(menu)) 211 raise exceptions.InternalError("Unknown menu: {}".format(menu))
203 212
204 213
205 class ExtraButton(SymbolButton): 214 class ExtraButton(SymbolButton):
776 def onVisible(self): 785 def onVisible(self):
777 if not self.sync: 786 if not self.sync:
778 self.resync() 787 self.resync()
779 788
780 def onDelete(self, **kwargs): 789 def onDelete(self, **kwargs):
790 if kwargs.get('explicit_close', False):
791 wrapper = self.whwrapper
792 if wrapper is not None:
793 if len(wrapper.carousel.slides) == 1:
794 # if we delete the last opened chat, we need to show the selector
795 screen_manager = self.screen_manager
796 screen_manager.transition.direction = 'down'
797 screen_manager.current = 'chat_selector'
798 wrapper.carousel.remove_widget(self)
799 return True
781 # we always keep one widget, so it's available when swiping 800 # we always keep one widget, so it's available when swiping
782 # TODO: delete all widgets when chat is closed 801 # TODO: delete all widgets when chat is closed
783 nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self)) 802 nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self))
784 # we want to keep at least one instance of Chat by WHWrapper 803 # we want to keep at least one instance of Chat by WHWrapper
785 nb_to_keep = len(G.host.widgets_handler.children) 804 nb_to_keep = len(G.host.widgets_handler.children)