onMessagesReceived method

  1. @override
void onMessagesReceived(
  1. List<Message> messages
)
override

Implementation

@override
void onMessagesReceived(List<Message> messages) {
  List<MessageModel> list = [];
  for (var element in messages) {
    if (element.conversationId == profile.id) {
      list.add(
        MessageModel(message: element),
      );
      ChatUIKitProfile? profile =
          ChatUIKitProvider.instance.getProfileById(element.from!);
      profile ??= element.fromProfile;
      userMap[element.from!] = profile;
    }
  }
  if (list.isNotEmpty) {
    _clearMention(list);
    if (onBottom) {
      msgModelList.insertAll(0, list.reversed);
      lastActionType = MessageLastActionType.bottomPosition;
    } else {
      cacheMessages.addAll(list.reversed);
      lastActionType = MessageLastActionType.originalPosition;
    }

    refresh();
  }
}