getUnreadMessageCountForAllUsers static method

Future<Map<String, int>?> getUnreadMessageCountForAllUsers({
  1. bool? hideMessagesFromBlockedUsers,
  2. dynamic onSuccess(
    1. Map<String, int> message
    )?,
  3. dynamic onError(
    1. CometChatException excep
    )?,
})

Gives count of unread messages for every one-on-one and group conversation.

on Success will return 2 keys:

  1. user - The value for this key holds another map that holds the UIDs of users and their corresponding unread message counts.
  2. group - The value for this key holds another map that holds the GUIDs of groups and their corresponding unread message counts.

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 {
    final count = await channel.invokeMethod('getUnreadMessageCountForAllUsers', {'hideMessagesFromBlockedUsers': hideMessagesFromBlockedUsers});
    final res = Map<String, int>.from(count);
    if(onSuccess != null) onSuccess(res);
    return res;
  } on PlatformException catch (platformException) {
    if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
    return null;
  } catch (e) {
    debugPrint("Error: $e");
    if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
    return null;
  }
}