removeReaction static method

Future<BaseMessage?> removeReaction(
  1. int messageId,
  2. String reaction, {
  3. required dynamic onSuccess(
    1. BaseMessage
    )?,
  4. required dynamic onError(
    1. CometChatException excep
    )?,
})

Remove a reaction from a message.

Migration Note: Migrated from platform channels to native Dart. Uses ReactionRepository.removeReaction internally.

Android Reference: CometChat.removeReaction(int messageId, String reaction)

The messageId parameter specifies the ID of the message to remove the reaction from. The reaction parameter specifies the reaction emoji to remove. The onSuccess function is called with the updated BaseMessage when the reaction is removed successfully. The onError function is called with a CometChatException object when there is an error while removing the reaction.

Returns a Future that resolves to the updated BaseMessage or null if there was an error.

Implementation

static Future<BaseMessage?> removeReaction(int messageId, String reaction,
    {required Function(BaseMessage)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    // 1. Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // 2. Call repository (convert int messageId to String)
    final updatedMessage = await sdk.reactions.removeReaction(
      messageId.toString(),
      reaction,
    );

    // 3. Call success callback
    if (onSuccess != null) onSuccess(updatedMessage);
    return updatedMessage;
  } on SdkException catch (sdkEx) {
    // 4. Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    _errorCallbackHandler(cometChatEx, null, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}