getUnreadMessageCount static method

Future<Map<String, Map<String, int>>?> getUnreadMessageCount({
  1. bool? hideMessagesFromBlockedUsers,
  2. dynamic onSuccess(
    1. Map<String, 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, Map<String, int>>?> getUnreadMessageCount(
    {bool? hideMessagesFromBlockedUsers,
    Function(Map<String, Map<String, int>> message)? onSuccess,
    Function(CometChatException excep)? onError}) async {
  try {
    final count = await channel.invokeMethod('getUnreadMessageCount');
    final countMap = Map<String, dynamic>.from(count);
    final res = countMap.map((k, v) => MapEntry(k, Map<String, int>.from(v)));
    if (!res.containsKey('group')) res['group'] = {};
    if (!res.containsKey('user')) res['user'] = {};
    if (onSuccess != null) onSuccess(res);
    return res;
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
    return null;
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
    return null;
  }
}