loadData method

Future<void> loadData()

Loads the Room, RoomUsers and Message as well, this needs to be called at the start of the chat to load the initial data

Implementation

Future<void> loadData() async {
  startLoading();
  final room = (await _chatApi.chatRoomsRetrieve(id: roomId.toString())).data;
  final result =
      (await _chatApi.chatRoomsMembersRetrieve(id: roomId.toString()))
          .data
          ?.members;
  final roomUsers = Map<int, User>.fromEntries(
    (result ?? []).map(
      (e) => MapEntry(e.id ?? 0, e),
    ),
  );

  emit(
    state.copyWith(
      loading: true,
      roomUsers: roomUsers,
      me: _getMe(roomUsers),
      room: room,
    ),
  );

  loadMoreMessages(roomId: roomId, reload: true);
}