Daniel Brötzmann pushed to branch mainwindow at gajim / gajim


Commits:
54b5dea9 by wurstsalat at 2021-11-28T17:35:49+01:00
Improve unread counter behavior

- - - - -


4 changed files:

- gajim/gtk/chat_list_stack.py
- gajim/gtk/controls/base.py
- gajim/gtk/conversation/jump_to_end_button.py
- gajim/gtk/main.py


Changes:

=====================================
gajim/gtk/chat_list_stack.py
=====================================
@@ -73,7 +73,6 @@ def __init__(self, chat_filter, search_entry):
         self.connect('notify::visible-child-name', self._on_visible_child_name)
         search_entry.connect('search-changed', self._on_search_changed)
         chat_filter.connect('filter-changed', self._on_filter_changed)
-        app.window.connect('notify::is-active', self._on_window_active)
 
         self._add_actions()
         self.show_all()
@@ -92,13 +91,6 @@ def _add_actions(self):
             act.connect('activate', func)
             app.window.add_action(act)
 
-    def _on_window_active(self, window, _param):
-        is_active = window.get_property('is-active')
-        if is_active:
-            chat = self.get_selected_chat()
-            if chat is not None:
-                chat.reset_unread()
-
     def _on_visible_child_name(self, _stack, _param):
         if self._last_visible_child_name == self.get_visible_child_name():
             return


=====================================
gajim/gtk/controls/base.py
=====================================
@@ -182,7 +182,7 @@ def __init__(self, widget_name: str, account: str, jid: 
JID) -> None:
 
         self.xml.conv_view_overlay.add(self._scrolled_view)
 
-        self._jump_to_end_button = JumpToEndButton()
+        self._jump_to_end_button = JumpToEndButton(self.contact)
         self._jump_to_end_button.connect('clicked', self._on_jump_to_end)
         self.xml.conv_view_overlay.add_overlay(self._jump_to_end_button)
 


=====================================
gajim/gtk/conversation/jump_to_end_button.py
=====================================
@@ -25,14 +25,15 @@ class JumpToEndButton(Gtk.Overlay):
             ()),
     }
 
-    def __init__(self):
+    def __init__(self, contact):
         Gtk.Overlay.__init__(self)
-
         self.set_halign(Gtk.Align.END)
         self.set_valign(Gtk.Align.END)
         self.set_margin_end(6)
         self.set_margin_bottom(12)
 
+        self._contact = contact
+
         icon = Gtk.Image.new_from_icon_name(
             'go-bottom-symbolic', Gtk.IconSize.BUTTON)
         icon.set_margin_start(4)
@@ -49,6 +50,11 @@ def __init__(self):
         self._unread_label = Gtk.Label()
         self._unread_label.get_style_context().add_class(
             'unread-counter')
+
+        if contact.is_groupchat and not contact.can_notify():
+            self._unread_label.get_style_context().add_class(
+                'unread-counter-silent')
+
         self._unread_label.set_no_show_all(True)
         self._unread_label.set_halign(Gtk.Align.END)
         self._unread_label.set_valign(Gtk.Align.START)
@@ -62,18 +68,18 @@ def __init__(self):
     def _on_jump_clicked(self, _button):
         self.emit('clicked')
 
-    def toggle(self, visible):
+    def toggle(self, visible: bool) -> None:
         if visible:
             self.show()
         else:
             self.hide()
             self.reset_unread_count()
 
-    def reset_unread_count(self):
+    def reset_unread_count(self) -> None:
         self._count = 0
         self._unread_label.hide()
 
-    def add_unread_count(self):
+    def add_unread_count(self) -> None:
         self._count += 1
         if self._count > 0:
             self._unread_label.set_text(str(self._count))


=====================================
gajim/gtk/main.py
=====================================
@@ -86,6 +86,7 @@ def __init__(self):
         self._ui.account_box.add(self._account_side_bar)
 
         self.connect('motion-notify-event', self._on_window_motion_notify)
+        self.connect('notify::is-active', self._on_window_active)
         self.connect('delete-event', self._on_window_delete)
 
         self._ui.connect_signals(self)
@@ -523,6 +524,18 @@ def mark_as_read(self, account: str, jid: JID,
         chat_list_stack = self._chat_page.get_chat_list_stack()
         chat_list_stack.mark_as_read(account, jid)
 
+    def _on_window_active(self, window, _param):
+        is_active = window.get_property('is-active')
+        if not is_active:
+            return
+
+        control = self.get_active_control()
+        if control is None:
+            return
+
+        if control.get_autoscroll():
+            self.mark_as_read(control.account, control.jid)
+
     @staticmethod
     def contact_info(account, jid):
         client = app.get_client(account)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/54b5dea9bf0da6bc4052215416e77e872b9315cf

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/54b5dea9bf0da6bc4052215416e77e872b9315cf
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to