diff --git a/briar-gtk/briar_gtk/containers/private_chat.py b/briar-gtk/briar_gtk/containers/private_chat.py index dc5109f2dd731aeaec9879c86ddce0eb14679811..0600ca09fef883a6148709d796f6712817553479 100644 --- a/briar-gtk/briar_gtk/containers/private_chat.py +++ b/briar-gtk/briar_gtk/containers/private_chat.py @@ -99,6 +99,8 @@ class PrivateChatContainer(Container): # Abusing idle_add function here because otherwise the message box # is too small and scrolling cuts out messages GLib.idle_add(self._add_message, message) + if message.get("read", True) is False: + GLib.idle_add(private_chat.mark_read, message["id"]) socket_listener = APP().api.socket_listener signal_id = socket_listener.connect("ConversationMessageReceivedEvent", self._add_message_async) @@ -120,8 +122,12 @@ class PrivateChatContainer(Container): return "text" not in message def _add_message_async(self, message): - if message["data"]["contactId"] == self._contact_id: - GLib.idle_add(self._add_message_and_scroll, message["data"]) + if message["data"]["contactId"] != self._contact_id: + return + GLib.idle_add(self._add_message_and_scroll, message["data"]) + if message["data"].get("read", True) is False: + private_chat = PrivateChat(APP().api, self._contact_id) + GLib.idle_add(private_chat.mark_read, message["data"]["id"]) def _add_message_and_scroll(self, message): self._add_message(message) diff --git a/briar-gtk/briar_gtk/widgets/contact_row.py b/briar-gtk/briar_gtk/widgets/contact_row.py index 41b4784ae5382571bf8b8c1b9bd3db9bf46adba8..bd0d7fe6189a88dde2c37cd8b3375562da334e7f 100644 --- a/briar-gtk/briar_gtk/widgets/contact_row.py +++ b/briar-gtk/briar_gtk/widgets/contact_row.py @@ -17,6 +17,10 @@ class ContactRowWidget(Gtk.ListBoxRow): def _setup_view(self, contact): name = ContactRowWidget._get_contact_name(contact) contact_label = ContactRowWidget._create_contact_label(name) + unread_count = str(contact['unreadCount']) + contact_unread_count = ContactRowWidget._create_unread_count( + unread_count + ) connected = contact["connected"] contact_state = ContactRowWidget._create_contact_state(connected) contact_box = ContactRowWidget._create_contact_box() @@ -24,6 +28,7 @@ class ContactRowWidget(Gtk.ListBoxRow): contact_box.pack_start(contact_label, True, True, 0) contact_box.pack_end(contact_state, False, False, 0) + contact_box.pack_end(contact_unread_count, False, False, 0) contact_event_box.add(contact_box) self.add(contact_event_box) @@ -45,6 +50,17 @@ class ContactRowWidget(Gtk.ListBoxRow): contact_label.set_ellipsize(Pango.EllipsizeMode.END) return contact_label + @staticmethod + def _create_unread_count(unread_count): + if unread_count == "0": + return Gtk.EventBox() + unread_count_label = Gtk.Label.new(unread_count) + unread_count_label.set_valign(Gtk.Align.CENTER) + unread_count_label.set_halign(Gtk.Align.START) + style = unread_count_label.get_style_context() + style.add_class("notify-badge") + return unread_count_label + @staticmethod def _create_contact_state(connected): file_name = "contact_disconnected" diff --git a/briar-gtk/data/ui/application.css b/briar-gtk/data/ui/application.css index fc3c7b361ad6da4f386d918286d0fd09a34eece7..15fe11572de4d70467dcf58609c74bd36e907ec8 100644 --- a/briar-gtk/data/ui/application.css +++ b/briar-gtk/data/ui/application.css @@ -91,3 +91,17 @@ row .timestamp { border: none; } +/** + From GNOME Fractal + https://gitlab.gnome.org/GNOME/fractal/-/blob/4.4.0/fractal-gtk/res/app.css#L5 +**/ +.notify-badge { + background-color: #555; + color: white; + font-weight: bold; + font-size: 0.7em; + border-radius: 8px; + min-width: 0.7em; + padding: 2px 5px; +} +