markAsRead static method
Future<void>
markAsRead(
- BaseMessage baseMessage, {
- required dynamic onSuccess()?,
- required dynamic onError(
- 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 (platformException) {
if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
} catch (e) {
debugPrint("Error: $e");
if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
}
}