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");
    if(errorCallback != null) { errorCallback(e.getCode(), e.getMessage()); }
  } catch(e){
    Logger.log("$e");
    if(errorCallback != null) { errorCallback(-1, e.toString()); }
  }
  return 0;
}