markConversationAsRead static method
Future<String?>
markConversationAsRead(
- String conversationWithId,
- String conversationType, {
- required dynamic onSuccess(
- String result
- required dynamic onError(
- CometChatException excep
Marks all messages in a conversation as read.
conversationWithId The UID of the user or GUID of the group whose conversation messages are to be marked as read.
conversationType The type of conversation - 'user' or 'group'.
Migration Note: Migrated from platform channels to native Dart implementation. Uses ConversationRepository for marking messages as read. Behavior and signature remain identical for backward compatibility.
Android Reference: ApiConnection.markConversationAsRead()
Returns a success message on success.
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<String?> markConversationAsRead(
String conversationWithId,
String conversationType, {
required Function(String message)? onSuccess,
required Function(CometChatException excep)? onError,
}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Offline (Task 4 / BEH-CONV-04): clear the whole conversation's cached
// unread badge locally, resolving the canonical key from the bare peer id +
// type. Fires independent of the network call below (works offline).
OfflineRuntime.instance.onConversationReadByPeer(
conversationWithId,
conversationType,
);
// No message ID: the endpoint marks the whole conversation read when the
// body is omitted, which is what this API promises the caller.
await sdk.conversations.markConversationAsRead(
conversationWithId,
conversationType,
);
final result = 'Conversation marked as read';
if (onSuccess != null) onSuccess(result);
return result;
} 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);
}
return null;
}