getTotalUnreadCount static method

Future<int> getTotalUnreadCount({
  1. dynamic errorCallback(
    1. int? errorCode,
    2. String? errorMessage
    )?,
})

Implementation

static Future<int> getTotalUnreadCount(
    {
      Function(int? errorCode, String? errorMessage)? errorCallback
    }) async
{
  if (!_isInitialized(errorCallback: errorCallback)) { return 0; }
  if (!_checkAuthInfo(errorCallback: errorCallback)) { return 0; }

  try {
    String url = "/channels/unread/count";
    Map<String, dynamic> response = await HttpUtil.get(url);
    int totalUnreadCount = response["count"];
    return totalUnreadCount;
  } on TPException catch(e) {
    Logger.log("${e.getCode()}, ${e.getMessage()}");
    errorCallback?.call(e.getCode(), e.getMessage());
  } catch(e){
    Logger.log("$e");
    errorCallback?.call(-1, e.toString());
  }
  return 0;
}