From d3497cac6889e7fb90e41717f4deda2905e4ecd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Fri, 12 Sep 2025 15:20:18 +0200 Subject: [PATCH] fix: Set unread notification count only if not null in sync Fixes an edge case in the sdk which sets the unread notification count wrongly to 0 on room fake sync. --- lib/src/client.dart | 11 +++++++---- test/room_test.dart | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 8384edfb..22a7b922 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -2979,10 +2979,13 @@ class Client extends MatrixApi { rooms[roomIndex].prev_batch = chatUpdate.timeline?.prevBatch; } rooms[roomIndex].membership = membership; - rooms[roomIndex].notificationCount = - chatUpdate.unreadNotifications?.notificationCount ?? 0; - rooms[roomIndex].highlightCount = - chatUpdate.unreadNotifications?.highlightCount ?? 0; + + if (chatUpdate.unreadNotifications != null) { + rooms[roomIndex].notificationCount = + chatUpdate.unreadNotifications?.notificationCount ?? 0; + rooms[roomIndex].highlightCount = + chatUpdate.unreadNotifications?.highlightCount ?? 0; + } final summary = chatUpdate.summary; if (summary != null) { diff --git a/test/room_test.dart b/test/room_test.dart index 2bf1b684..e6963a4c 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -295,6 +295,8 @@ void main() { ), ); expect(room.hasNewMessages, true); + expect(room.isUnreadOrInvited, true); + room.notificationCount = room.highlightCount = 0; expect(room.isUnreadOrInvited, false); expect(room.lastEvent?.body, 'cd'); await updateLastEvent(