From 0e5886bedf208cbf874cac889a77ea9e724857ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 27 Mar 2022 18:47:24 +0200 Subject: [PATCH] sidebar: Always show the total number of notifications --- src/session/room/mod.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs index 3bd95d9a..abfd29a0 100644 --- a/src/session/room/mod.rs +++ b/src/session/room/mod.rs @@ -245,8 +245,6 @@ mod imp { } fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { - let matrix_room = self.matrix_room.borrow(); - let matrix_room = matrix_room.as_ref().unwrap(); match pspec.name() { "room-id" => obj.room_id().as_str().to_value(), "session" => obj.session().to_value(), @@ -258,17 +256,7 @@ mod imp { "highlight" => obj.highlight().to_value(), "topic" => obj.topic().to_value(), "members" => obj.members().to_value(), - "notification-count" => { - let highlight = matrix_room.unread_notification_counts().highlight_count; - let notification = matrix_room.unread_notification_counts().notification_count; - - if highlight > 0 { - highlight - } else { - notification - } - .to_value() - } + "notification-count" => obj.notification_count().to_value(), "latest-change" => obj.latest_change().to_value(), "predecessor" => obj.predecessor().map_or_else( || { @@ -675,6 +663,16 @@ impl Room { ); } + /// The number of unread notifications of this room. + pub fn notification_count(&self) -> u64 { + let matrix_room = self.imp().matrix_room.borrow(); + matrix_room + .as_ref() + .unwrap() + .unread_notification_counts() + .notification_count + } + /// Updates the Matrix room with the given name. pub fn store_room_name(&self, room_name: String) { if self.display_name() == room_name {