reconcileUnreads method

  1. @override
Future<ChatResult<void>> reconcileUnreads(
  1. List<UnreadRoom> unreads
)
override

Replaces the cached unread set with exactly unreads, removing any previously cached room absent from the new list. Use this for an authoritative type='all' room listing so rooms deleted or left on the server stop reappearing from cache (plain saveUnreads merges and never evicts). The default implementation diffs against getUnreads and deleteUnread; datasources with a native "replace box" primitive should override it for atomicity.

Kicked rooms are preserved: the backend stops listing a room the moment the user leaves or is removed, but its unread snapshot is the last-message preview the read-only chat renders, so evicting it would blank the row and risk the room vanishing on cold start.

Implementation

@override
Future<ChatResult<void>> reconcileUnreads(List<UnreadRoom> unreads) async {
  final serverIds = unreads.map((u) => u.roomId).toSet();
  _unreads.removeWhere(
    (id, _) => !serverIds.contains(id) && !_kickedRoomIds.contains(id),
  );
  _unreads.addEntries(unreads.map((u) => MapEntry(u.roomId, u)));
  return const ChatSuccess(null);
}