getUnreadMessageCountForAllUsers static method
Future<Map<String, int> ?>
getUnreadMessageCountForAllUsers({
- bool? hideMessagesFromBlockedUsers,
- dynamic onSuccess()?,
- dynamic onError(
- CometChatException excep
Gives count of unread messages for every one-on-one and group conversation.
on Success will return 2 keys:
- user - The value for this key holds another map that holds the UIDs of users and their corresponding unread message counts.
- group - The value for this key holds another map that holds the GUIDs of groups and their corresponding unread message counts.
Migration Note: Migrated from platform channels to native Dart implementation. Uses MessageRepository for unread count retrieval. Behavior and signature remain identical for backward compatibility.
Android Reference: CometChat.getUnreadMessageCountForAllUsers(boolean hideMessagesFromBlockedUsers)
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<Map<String, int>?> getUnreadMessageCountForAllUsers(
{bool? hideMessagesFromBlockedUsers,
Function(Map<String, int> message)? onSuccess,
Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart message repository
final count = await sdk.messages.getUnreadMessageCountForAllUsers(
hideMessagesFromBlockedUsers: hideMessagesFromBlockedUsers ?? false,
);
// Call success callback
if (onSuccess != null) onSuccess(count);
return count;
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
return null;
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
return null;
}
}