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(