loadMoreMessages method

Future<void> loadMoreMessages({
  1. required int roomId,
  2. bool reload = false,
})

Load messages, automatically load more messages for pagination

Implementation

Future<void> loadMoreMessages({
  required int roomId,
  bool reload = false,
}) async {
  final messages = ((await _chatApi.chatRoomsMessagesList(
        roomId: roomId,
        limit: defaultChatPageSize,
        offset: reload ? 0 : state.messages.length,
      ))
          .data
          ?.results ??
      []);
  final chatMessages = messages;

  emit(
    state.copyWith(
      loading: false,
      messages: reload ? chatMessages : [...state.messages, ...chatMessages],
    ),
  );

  // final seenIds = messages.unseenMessageIds;

  // final reactionIds = <String>[];
  // for (final reactionMessage in messages) {
  //   if (reactionMessage.reactions != null &&
  //       reactionMessage.reactions!.isNotEmpty) {
  //     reactionIds.addAll(
  //       reactionMessage.reactions!.unseenMessageIds,
  //     );
  //   }
  // }

  // if (seenIds.isNotEmpty || reactionIds.isNotEmpty) {
  //   markMessagesAsSeen(
  //     roomId: roomId,
  //     messageIds: [...seenIds, ...reactionIds],
  //   );
  // }
}