getChatMember method

Future<Map> getChatMember(
  1. dynamic chat_id,
  2. dynamic user_id, {
  3. required int clientId,
  4. String? extra,
  5. bool? isUseCache,
  6. Duration? durationCacheExpire,
})

getChatMember return result

{
  "ok":true,
  "result": {
  }
}

Implementation

Future<Map> getChatMember(
  dynamic chat_id,
  dynamic user_id, {
  required int clientId,
  String? extra,
  bool? isUseCache,
  Duration? durationCacheExpire,
}) async {
  chat_id ??= 0;
  user_id ??= 0;
  if (RegExp("^@.*", caseSensitive: false).hashData(chat_id)) {
    var search_public_chat = await invoke(
      "searchPublicChat",
      parameters: {
        "username": chat_id,
      },
      isUseCache: isUseCache,
      durationCacheExpire: durationCacheExpire,
      clientId: clientId,
      extra: extra,
    );
    if (search_public_chat["@type"] == "chat") {
      chat_id = search_public_chat["id"];
    }
  }
  if (RegExp("^@.*", caseSensitive: false).hashData(user_id)) {
    var search_public_chat = await invoke(
      "searchPublicChat",
      parameters: {
        "username": user_id,
      },
      isUseCache: isUseCache,
      durationCacheExpire: durationCacheExpire,
      clientId: clientId,
      extra: extra,
    );
    if (search_public_chat["@type"] == "chat") {
      user_id = search_public_chat["id"];
    }
  }
  var get_chat_member = await invoke(
    "getChatMember",
    parameters: {
      "chat_id": chat_id,
      "member_id": {
        "@type": "messageSenderUser",
        "user_id": user_id,
      }
    },
    isUseCache: isUseCache,
    durationCacheExpire: durationCacheExpire,
    clientId: clientId,
    extra: extra,
  );

  if (RegExp("^chatMember\$", caseSensitive: false)
      .hashData(get_chat_member["@type"])) {
    var json = {};

    var get_user = await getUser(
      get_chat_member["member_id"]["user_id"],
      clientId: clientId,
      isUseCache: isUseCache,
      durationCacheExpire: durationCacheExpire,
    );
    json["user"] = get_user["result"];
    json["join_date"] = get_chat_member["joined_chat_date"];
    var status = get_chat_member["status"];
    json["status"] = status["@type"]
        .toString()
        .toLowerCase()
        .replaceAll(RegExp("chatmemberstatus", caseSensitive: false), "");
    json["custom_title"] = status["custom_title"];
    json["can_be_edited"] = status["can_be_edited"];
    json["can_manage_chat"] = status["can_manage_chat"];
    json["can_change_info"] = status["can_change_info"];
    json["can_post_messages"] = status["can_post_messages"];
    json["can_edit_messages"] = status["can_edit_messages"];
    json["can_delete_messages"] = status["can_delete_messages"];
    json["can_invite_users"] = status["can_invite_users"];
    json["can_restrict_members"] = status["can_restrict_members"];
    json["can_pin_messages"] = status["can_pin_messages"];
    json["can_promote_members"] = status["can_promote_members"];
    json["can_manage_voice_chats"] = status["can_manage_voice_chats"];
    json["is_anonymous"] = status["is_anonymous"];
    return {"ok": true, "result": json};
  } else {
    return {"ok": false, "result": {}};
  }
}