markMessageAsUnread static method
Future<Conversation?>
markMessageAsUnread(
- BaseMessage baseMessage, {
- required dynamic onSuccess()?,
- required dynamic onError(
- CometChatException excep
Marks a BaseMessage as unread.
The markMessageAsUnread function takes in a BaseMessage object, which represents the message you want to mark as unread.
Returns a Conversation object on success. Marks a message as unread and returns the updated conversation.
Migration Note: Migrated from platform channels to native Dart implementation. Uses MessageRepository for marking messages as unread.
Android Reference: CometChat.markMessageAsUnread()
Implementation
static Future<Conversation?> markMessageAsUnread(BaseMessage baseMessage,
{required Function(Conversation)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart message repository
await sdk.messages.markAsUnread(
baseMessage.id,
baseMessage.receiverUid,
baseMessage.receiverType,
);
// Get updated conversation
final conversation = baseMessage.receiverType == 'user'
? await sdk.conversations.getUserConversation(baseMessage.receiverUid)
: await sdk.conversations
.getGroupConversation(baseMessage.receiverUid);
// Call success callback
if (onSuccess != null) onSuccess(conversation);
return conversation;
} 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;
}