markAsInteracted static method

Future<void> markAsInteracted(
  1. int messageId,
  2. String interactedElementId, {
  3. required dynamic onSuccess(
    1. String
    )?,
  4. required dynamic onError(
    1. CometChatException excep
    )?,
})

Messages elements can be marked as interacted.

messageId The ID of the message above which all messages for a particular conversation are to be marked as read.

Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.

Android Reference: CometChat.markAsInteracted(long messageId, String interactedElementId, CallbackListener)

Note: Android SDK sends interactedElementIds as a JSON array in the request body. This method wraps the single element ID in a list for API parity.

method could throw PlatformException with error codes specifying the cause

Implementation

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

    // Call native Dart message repository (convert int to String)
    // Android SDK wraps single element ID in a list: Arrays.asList(interactedElementId)
    // Reference: CometChat.markAsInteracted(long messageId, String interactedElementId, CallbackListener)
    await sdk.messages
        .markAsInteracted(messageId.toString(), [interactedElementId]);

    // Call success callback
    if (onSuccess != null) onSuccess('Message marked as interacted');
  } on SdkException catch (sdkEx) {
    // 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);
  }
}