onMessageReactionDidChange method

  1. @override
void onMessageReactionDidChange(
  1. List<MessageReactionEvent> events
)
override

Implementation

@override
void onMessageReactionDidChange(List<MessageReactionEvent> events) async {
  bool needUpdate = false;
  for (var reactionEvent in events) {
    if (reactionEvent.conversationId == thread?.threadId) {
      final index = msgModelList.indexWhere(
          (element) => element.message.msgId == reactionEvent.messageId);
      if (index != -1) {
        Message? msg = await ChatUIKit.instance
            .loadMessage(messageId: msgModelList[index].message.msgId);
        if (msg != null) {
          needUpdate = true;
          List<MessageReaction>? reactions = await msg.reactionList();
          msgModelList[index] = msgModelList[index].copyWith(
            message: msg,
            reactions: reactions,
          );
        }
      }
    }
  }
  if (needUpdate) {
    refresh();
  }
}