getUnreadMessageCountForGroup static method

Future<Map<String, int>?> getUnreadMessageCountForGroup({
  1. required String guid,
  2. bool? hideMessagesFromBlockedUsers,
  3. dynamic onSuccess(
    1. Map<String, int> message
    )?,
  4. 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>?> getUnreadMessageCountForGroup({required String guid, bool? hideMessagesFromBlockedUsers, Function(Map<String, int> message)? onSuccess, Function(CometChatException excep)? onError}) async {
  try {
    final count = await channel.invokeMethod(
        'getUnreadMessageCountForGroup', {
      'guid': guid,
      '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;
  }
}