entitiesToApi method

Future<List<Map>> entitiesToApi({
  1. required List oldEntities,
  2. required TelegramClientData telegramClientData,
  3. required bool is_lite,
  4. bool? isUseCache,
  5. Duration? durationCacheExpire,
})

Implementation

Future<List<Map<dynamic, dynamic>>> entitiesToApi({
  required List oldEntities,
  required TelegramClientData telegramClientData,
  required bool is_lite,
  bool? isUseCache,
  Duration? durationCacheExpire,
}) async {
  final List<Map<dynamic, dynamic>> entities_data = [];

  for (var i = 0; i < oldEntities.length; i++) {
    final dataEntities = oldEntities[i];
    try {
      final Map<dynamic, dynamic> jsonEntities = <dynamic, dynamic>{};
      jsonEntities["offset"] = dataEntities["offset"];
      jsonEntities["length"] = dataEntities["length"];
      if (dataEntities["type"]["@type"] != null) {
        final String typeEntities = dataEntities["type"]["@type"]
            .toString()
            .toLowerCase()
            .replaceAll(RegExp("textEntityType", caseSensitive: false), "")
            .replaceAll(RegExp("textUrl", caseSensitive: false), "text_link")
            .replaceAll(
                RegExp("bot_command", caseSensitive: false), "bot_command")
            .replaceAll(
                RegExp("mentionname", caseSensitive: false), "text_mention");
        jsonEntities["type"] = typeEntities;
        if (dataEntities["type"]["url"] != null) {
          jsonEntities["url"] = dataEntities["type"]["url"];
        }
        if (typeEntities == "text_mention" &&
            dataEntities["type"]["user_id"] != null) {
          final int entitiesUserId = dataEntities["type"]["user_id"];
          Map<dynamic, dynamic> fromJson = <dynamic, dynamic>{
            "id": entitiesUserId
          };
          if (is_lite) {
          } else {
            try {
              final Map res = await request(
                parameters: {
                  "@type": "getUser",
                  "user_id": entitiesUserId,
                },
                isUseCache: isUseCache,
                durationCacheExpire: durationCacheExpire,
                is_return_as_api: false,
                telegramClientData: telegramClientData,
              );

              fromJson = res;
            } catch (e) {}
          }
          jsonEntities["user"] = fromJson;
        }
      }
      entities_data.add(jsonEntities);
    } catch (e) {}
  }
  return entities_data;
}