updateRoomData function

Map<String, MRoom>? updateRoomData({
  1. required Map<String, MRoom>? fromServer,
  2. required Map<String, MRoom>? fromState,
  3. required bool invite,
})

Loops through the new events from Matrix and runs updates on the old events

Used for subsequent room updates after the initial sync

Implementation

Map<String, MRoom>? updateRoomData({
  // From server
  required Map<String, MRoom>? fromServer,

  // From state
  required Map<String, MRoom>? fromState,

  // Whether the room is an invite or not
  required bool invite,
}) {
  if (fromServer != null) {
    /// Loop through all rooms from the server
    final Map<String, MRoom> updatedRooms = <String, MRoom>{};

    fromServer.forEach((String rID, MRoom r) {
      if (fromState?.containsKey(rID) ?? false) {
        updatedRooms[rID] = processRoomUpdates(
          serverRoom: r,
          stateRoom: fromState![rID]!,
          invite: invite,
        );
      } else {
        updatedRooms[rID] = enrichRoom(room: r, roomID: rID, invite: invite);
      }
    });

    // Update state with new/updated rooms from server
    final Map<String, MRoom>? rewRooms = fromState?..addAll(updatedRooms);

    return (rewRooms?.isNotEmpty ?? false) ? rewRooms : Map<String, MRoom>();
  }

  return fromState;
}