markAsRead static method

Future<void> markAsRead(
  1. BaseMessage baseMessage, {
  2. required dynamic onSuccess(
    1. String
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    )?,
})

Messages for both user and group conversations can be marked as read using this method.

Ideally, you should mark all the messages as read for any conversation when the user opens the chat window.

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

receiverId In case of one to one conversation message's sender UID will be the receipt's receiver Id.In case of group conversation message's receiver Id will be the receipt's receiver Id

senderId The UID of the sender of the message

method could throw PlatformException with error codes specifying the cause

Implementation

static Future<void> markAsRead(BaseMessage baseMessage,
    {required Function(String)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    Map<String, dynamic> map = baseMessage.toJson();
    final result =
        await channel.invokeMethod('markAsRead', {'baseMessage': map});
    if (onSuccess != null) onSuccess(result);
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
}