diff 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
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.py	Thu Feb 06 21:16:21 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Sun Feb 09 23:47:29 2020 +0100
@@ -621,7 +621,7 @@
         or when one2one chat is not visible. A note is also there when widget
         is not visible.
         For group chat, note will be added on mention, with a desktop notification if
-        window has not focus.
+        window has not focus or is not visible.
         """
         visible_clones = [w for w in G.host.getVisibleList(self.__class__)
                           if w.target == self.target]
@@ -633,9 +633,14 @@
         if self.type == C.CHAT_ONE2ONE:
             if (not Window.focus or not is_visible) and not mess_data.history:
                 notif_msg = self._get_notif_msg(mess_data)
-                G.host.desktop_notif(
-                    notif_msg,
-                    title=_("private message"))
+                G.host.notify(
+                    type_=C.NOTIFY_MESSAGE,
+                    entity=mess_data.from_jid,
+                    message=notif_msg,
+                    subject=_("private message"),
+                    widget=self,
+                    profile=self.profile
+                )
                 if not is_visible:
                     G.host.addNote(
                         _("private message"),
@@ -647,7 +652,7 @@
                             "profiles": self.profiles}
                         )
         else:
-            if mess_data.mention and not mess_data.history:
+            if mess_data.mention:
                 notif_msg = self._get_notif_msg(mess_data)
                 G.host.addNote(
                     _("mention"),
@@ -658,12 +663,16 @@
                         "target": self.target,
                         "profiles": self.profiles}
                     )
-                if not Window.focus:
-                    G.host.desktop_notif(
-                        notif_msg,
-                        title=_("mention ({room_jid})").format(
-                            room_jid=self.target)
-                        )
+                if not is_visible or not Window.focus:
+                    subject=_("mention ({room_jid})").format(room_jid=self.target)
+                    G.host.notify(
+                        type_=C.NOTIFY_MENTION,
+                        entity=self.target,
+                        message=notif_msg,
+                        subject=subject,
+                        widget=self,
+                        profile=self.profile
+                    )
 
     # message input
 
@@ -789,6 +798,9 @@
         if not self.sync:
             self.resync()
 
+    def onSelected(self):
+        G.host.clearNotifs(self.target, profile=self.profile)
+
     def onDelete(self, **kwargs):
         if kwargs.get('explicit_close', False):
             wrapper = self.whwrapper