Skip to content
Snippets Groups Projects
Commit 283ff921 authored by Nico's avatar Nico
Browse files

Show unread messages counter in contact list

Fixes #29
parent d9767386
No related branches found
No related tags found
No related merge requests found
Pipeline #5051 passed
......@@ -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)
......
......@@ -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"
......
......@@ -91,3 +91,13 @@ row .timestamp {
border: none;
}
.notify-badge {
background-color: #555;
color: white;
font-weight: bold;
font-size: 0.7em;
border-radius: 8px;
min-width: 0.7em;
padding: 2px 5px;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment