From 101694ddbcbb061128b74ed29483a2031623029f Mon Sep 17 00:00:00 2001 From: James Magahern Date: Mon, 28 Apr 2025 18:40:16 -0700 Subject: [PATCH] Some fixups for the badge --- src/conversation-row.vala | 19 +++++++++++-------- src/conversation.vala | 8 ++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/conversation-row.vala b/src/conversation-row.vala index 260e9ad..c94e080 100644 --- a/src/conversation-row.vala +++ b/src/conversation-row.vala @@ -2,7 +2,7 @@ using Adw; using Gtk; public class ConversationRow : Adw.ActionRow { - private Label? unread_badge; + private Label unread_badge; public ConversationRow(Conversation conversation) { Object(); @@ -10,13 +10,16 @@ public class ConversationRow : Adw.ActionRow { title = conversation.display_name; subtitle = conversation.last_message_preview; subtitle_lines = 1; - - // Add unread badge if needed - if (conversation.is_unread && conversation.unread_count > 0) { - unread_badge = new Label(conversation.unread_count.to_string()); - unread_badge.add_css_class("badge"); - unread_badge.add_css_class("accent"); - add_suffix(unread_badge); + + unread_badge = new Label(conversation.unread_count.to_string()); + unread_badge.add_css_class("badge"); + unread_badge.add_css_class("accent"); + add_prefix(unread_badge); + + if (conversation.is_unread) { + unread_badge.opacity = 1.0; + } else { + unread_badge.opacity = 0.0; } // Add timestamp if available diff --git a/src/conversation.vala b/src/conversation.vala index b58f038..a88ddbd 100644 --- a/src/conversation.vala +++ b/src/conversation.vala @@ -3,11 +3,12 @@ using GLib; public class Conversation : Object { public string id { get; set; default = ""; } public string last_message_preview { get; set; default = ""; } - public bool is_unread { get; set; default = false; } public int64 date { get; set; default = 0; } public string[] participants { get; set; default = new string[0]; } public int unread_count { get; set; default = 0; } + public bool is_unread { get { return unread_count > 0; } } + public string display_name { owned get { if (_display_name != null && _display_name.length > 0) { @@ -54,11 +55,6 @@ public class Conversation : Object { last_message_preview = last_message_variant.get_string(); } - Variant? is_unread_variant = dict.lookup_value("is_unread", VariantType.BOOLEAN); - if (is_unread_variant != null) { - is_unread = is_unread_variant.get_boolean(); - } - Variant? date_variant = dict.lookup_value("date", VariantType.INT64); if (date_variant != null) { date = date_variant.get_int64();