Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_chat.py @ 396:ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 09 Feb 2020 23:47:29 +0100 |
parents | c04c3b167cb0 |
children | f7476818f9fb |
comparison
equal
deleted
inserted
replaced
395:c04c3b167cb0 | 396:ae6f7fd1cb0e |
---|---|
619 | 619 |
620 For one2one chat, notification will happen when window has not focus | 620 For one2one chat, notification will happen when window has not focus |
621 or when one2one chat is not visible. A note is also there when widget | 621 or when one2one chat is not visible. A note is also there when widget |
622 is not visible. | 622 is not visible. |
623 For group chat, note will be added on mention, with a desktop notification if | 623 For group chat, note will be added on mention, with a desktop notification if |
624 window has not focus. | 624 window has not focus or is not visible. |
625 """ | 625 """ |
626 visible_clones = [w for w in G.host.getVisibleList(self.__class__) | 626 visible_clones = [w for w in G.host.getVisibleList(self.__class__) |
627 if w.target == self.target] | 627 if w.target == self.target] |
628 if len(visible_clones) > 1 and visible_clones.index(self) > 0: | 628 if len(visible_clones) > 1 and visible_clones.index(self) > 0: |
629 # to avoid multiple notifications in case of multiple cloned widgets | 629 # to avoid multiple notifications in case of multiple cloned widgets |
631 return | 631 return |
632 is_visible = bool(visible_clones) | 632 is_visible = bool(visible_clones) |
633 if self.type == C.CHAT_ONE2ONE: | 633 if self.type == C.CHAT_ONE2ONE: |
634 if (not Window.focus or not is_visible) and not mess_data.history: | 634 if (not Window.focus or not is_visible) and not mess_data.history: |
635 notif_msg = self._get_notif_msg(mess_data) | 635 notif_msg = self._get_notif_msg(mess_data) |
636 G.host.desktop_notif( | 636 G.host.notify( |
637 notif_msg, | 637 type_=C.NOTIFY_MESSAGE, |
638 title=_("private message")) | 638 entity=mess_data.from_jid, |
639 message=notif_msg, | |
640 subject=_("private message"), | |
641 widget=self, | |
642 profile=self.profile | |
643 ) | |
639 if not is_visible: | 644 if not is_visible: |
640 G.host.addNote( | 645 G.host.addNote( |
641 _("private message"), | 646 _("private message"), |
642 notif_msg, | 647 notif_msg, |
643 symbol = "chat", | 648 symbol = "chat", |
645 "action": 'chat', | 650 "action": 'chat', |
646 "target": self.target, | 651 "target": self.target, |
647 "profiles": self.profiles} | 652 "profiles": self.profiles} |
648 ) | 653 ) |
649 else: | 654 else: |
650 if mess_data.mention and not mess_data.history: | 655 if mess_data.mention: |
651 notif_msg = self._get_notif_msg(mess_data) | 656 notif_msg = self._get_notif_msg(mess_data) |
652 G.host.addNote( | 657 G.host.addNote( |
653 _("mention"), | 658 _("mention"), |
654 notif_msg, | 659 notif_msg, |
655 symbol = "chat", | 660 symbol = "chat", |
656 action = { | 661 action = { |
657 "action": 'chat', | 662 "action": 'chat', |
658 "target": self.target, | 663 "target": self.target, |
659 "profiles": self.profiles} | 664 "profiles": self.profiles} |
660 ) | 665 ) |
661 if not Window.focus: | 666 if not is_visible or not Window.focus: |
662 G.host.desktop_notif( | 667 subject=_("mention ({room_jid})").format(room_jid=self.target) |
663 notif_msg, | 668 G.host.notify( |
664 title=_("mention ({room_jid})").format( | 669 type_=C.NOTIFY_MENTION, |
665 room_jid=self.target) | 670 entity=self.target, |
666 ) | 671 message=notif_msg, |
672 subject=subject, | |
673 widget=self, | |
674 profile=self.profile | |
675 ) | |
667 | 676 |
668 # message input | 677 # message input |
669 | 678 |
670 def addNick(self, nick): | 679 def addNick(self, nick): |
671 """Add a nickname to message_input if suitable""" | 680 """Add a nickname to message_input if suitable""" |
787 | 796 |
788 def onVisible(self): | 797 def onVisible(self): |
789 if not self.sync: | 798 if not self.sync: |
790 self.resync() | 799 self.resync() |
791 | 800 |
801 def onSelected(self): | |
802 G.host.clearNotifs(self.target, profile=self.profile) | |
803 | |
792 def onDelete(self, **kwargs): | 804 def onDelete(self, **kwargs): |
793 if kwargs.get('explicit_close', False): | 805 if kwargs.get('explicit_close', False): |
794 wrapper = self.whwrapper | 806 wrapper = self.whwrapper |
795 if wrapper is not None: | 807 if wrapper is not None: |
796 if len(wrapper.carousel.slides) == 1: | 808 if len(wrapper.carousel.slides) == 1: |