markConversationAsRead static method
Future<String?>
markConversationAsRead(
- String conversationWithId,
- String conversationType, {
- required dynamic onSuccess(
- String message
- 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: ConversationsRequest.markAsRead()
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();
// Note: We need the last message ID to mark as read
// For now, we'll use a placeholder approach - this should be enhanced
// to fetch the last message ID from the conversation
await sdk.conversations.markAsRead(
conversationType,
conversationWithId,
'0', // Placeholder - should be last message ID
);
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;
}