From 05a3fdd4fd904791d5384c6419c0d330c67d89b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BF=B4=EF=BF=B4?= <￴￴> Date: Tue, 15 Oct 2024 17:07:36 +0700 Subject: [PATCH] up --- package/telegram_client/.gitignore | 10 +- .../telegram_client/lib/tdlib/tdlib_core.dart | 755 +++++------------- .../lib/tdlib/tdlib_library/base.dart | 65 +- .../lib/tdlib/tdlib_library/io.dart | 5 + .../lib/tdlib/tdlib_library/none.dart | 6 +- .../lib/tdlib/tdlib_library/tdlib.dart | 2 +- .../lib/tdlib/tdlib_library/web.dart | 42 +- .../function/send_message_raw.dart | 328 +++----- .../lib/telegram_client/update/message.dart | 131 +-- package/telegram_client/pubspec.yaml | 5 +- 10 files changed, 411 insertions(+), 938 deletions(-) diff --git a/package/telegram_client/.gitignore b/package/telegram_client/.gitignore index 97ba29a3..8880c643 100644 --- a/package/telegram_client/.gitignore +++ b/package/telegram_client/.gitignore @@ -37,4 +37,12 @@ linux/flutter/ephemeral macos/Flutter/ephemeral windows/ephemeral tmp/ -temp/ \ No newline at end of file +temp/ + +wasm/ + + +dev/ + +tg_db/ +tg_file/ \ No newline at end of file diff --git a/package/telegram_client/lib/tdlib/tdlib_core.dart b/package/telegram_client/lib/tdlib/tdlib_core.dart index 260c529f..ca798f3b 100644 --- a/package/telegram_client/lib/tdlib/tdlib_core.dart +++ b/package/telegram_client/lib/tdlib/tdlib_core.dart @@ -163,6 +163,21 @@ class Tdlib extends TdlibNative { super.on_generate_extra_invoke, super.isInvokeThrowOnError, }); + FutureOr closeClients() async { + final int client_id_first = () { + if (first_client_id < 1) { + return td_create_client_id(); + } + return first_client_id; + }(); + if (client_id_first >= 1) { + for (int i = 1; i <= client_id_first; i++) { + try { + await invoke("close", clientId: i, isInvokeThrowOnError: false, isVoid: true); + } catch (e) {} + } + } + } /// set up authorizationStateWaitTdlibParameters new client without more code Future initClient( @@ -202,8 +217,7 @@ class Tdlib extends TdlibNative { return await invoke( "checkDatabaseEncryptionKey", parameters: { - "encryption_key": - TgUtils.stringToBase64(value: client_option["database_key"]), + "encryption_key": TgUtils.stringToBase64(value: client_option["database_key"]), }, isUseCache: false, durationCacheExpire: null, @@ -216,8 +230,7 @@ class Tdlib extends TdlibNative { return await invoke( "setDatabaseEncryptionKey", parameters: { - "new_encryption_key": - TgUtils.stringToBase64(value: client_option["database_key"]), + "new_encryption_key": TgUtils.stringToBase64(value: client_option["database_key"]), }, clientId: clientId, isVoid: isVoid, @@ -230,8 +243,7 @@ class Tdlib extends TdlibNative { } if (authStateType == "authorizationStateClosed") { - await exitClientById(update.client_id, - isInvokeThrowOnError: isInvokeThrowOnError); + await exitClientById(update.client_id, isInvokeThrowOnError: isInvokeThrowOnError); return {"@type": "ok"}; } @@ -408,10 +420,8 @@ class Tdlib extends TdlibNative { Map makeParametersApi(Map parameters) { Map jsonResult = {"@type": ""}; try { - String regexMethodSend = - r"^(sendMessage|sendPhoto|sendVideo|sendAudio|sendVoice|sendDocument|sendSticker|sendAnimation|editMessage(Text))$"; - if (RegExp(regexMethodSend, caseSensitive: false) - .hashData(parameters["@type"])) { + String regexMethodSend = r"^(sendMessage|sendPhoto|sendVideo|sendAudio|sendVoice|sendDocument|sendSticker|sendAnimation|editMessage(Text))$"; + if (RegExp(regexMethodSend, caseSensitive: false).hashData(parameters["@type"])) { jsonResult["@type"] = "sendMessage"; jsonResult["options"] = { "@type": "messageSendOptions", @@ -423,8 +433,7 @@ class Tdlib extends TdlibNative { } catch (e) {} } }); - if (RegExp("editMessage(Text)", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp("editMessage(Text)", caseSensitive: false).hashData(parameters["@type"])) { jsonResult["@type"] = parameters["@type"]; } @@ -442,8 +451,7 @@ class Tdlib extends TdlibNative { }; jsonResult["chat_id"] = parameters["chat_id"]; if (parameters["disable_notification"] is bool) { - jsonResult["disable_notification"] = - parameters["reply_to_message_id"]; + jsonResult["disable_notification"] = parameters["reply_to_message_id"]; } if (parameters["reply_to_message_id"] is int) { jsonResult["reply_to_message_id"] = parameters["reply_to_message_id"]; @@ -469,8 +477,7 @@ class Tdlib extends TdlibNative { if (parameters.containsKey("reply_markup")) { jsonResult["reply_markup"] = replyMarkup(parameters["reply_markup"]); } - if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false).hashData(parameters["@type"])) { var text = parseMode( parameters["text"].toString(), parameters["parse_mode"], @@ -479,58 +486,45 @@ class Tdlib extends TdlibNative { jsonResult["input_message_content"]["@type"] = "inputMessageText"; jsonResult["input_message_content"]["text"] = text; } - if (RegExp(r"^(sendPhoto)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendPhoto)$", caseSensitive: false).hashData(parameters["@type"])) { var getDetailFile = typeFile(parameters["photo"]); jsonResult["input_message_content"]["@type"] = "inputMessagePhoto"; jsonResult["input_message_content"]["photo"] = getDetailFile; } - if (RegExp(r"^(sendVoice)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendVoice)$", caseSensitive: false).hashData(parameters["@type"])) { var getDetailFile = typeFile(parameters["voice"]); - jsonResult["input_message_content"]["@type"] = - "inputMessageVoiceNote"; + jsonResult["input_message_content"]["@type"] = "inputMessageVoiceNote"; jsonResult["input_message_content"]["voice_note"] = getDetailFile; } - if (RegExp(r"^(sendSticker)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendSticker)$", caseSensitive: false).hashData(parameters["@type"])) { var getDetailFile = typeFile(parameters["sticker"]); jsonResult["input_message_content"]["@type"] = "inputMessageSticker"; jsonResult["input_message_content"]["sticker"] = getDetailFile; } - if (RegExp(r"^(sendAnimation)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendAnimation)$", caseSensitive: false).hashData(parameters["@type"])) { var getDetailFile = typeFile(parameters["animation"]); - jsonResult["input_message_content"]["@type"] = - "inputMessageAnimation"; + jsonResult["input_message_content"]["@type"] = "inputMessageAnimation"; jsonResult["input_message_content"]["animation"] = getDetailFile; } - if (RegExp(r"^(sendDocument)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendDocument)$", caseSensitive: false).hashData(parameters["@type"])) { var getDetailFile = typeFile(parameters["document"]); jsonResult["input_message_content"]["@type"] = "inputMessageDocument"; jsonResult["input_message_content"]["document"] = getDetailFile; } - if (RegExp(r"^(sendAudio)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendAudio)$", caseSensitive: false).hashData(parameters["@type"])) { var getDetailFile = typeFile(parameters["audio"]); jsonResult["input_message_content"]["@type"] = "inputMessageAudio"; jsonResult["input_message_content"]["audio"] = getDetailFile; } - if (RegExp(r"^(sendVideo)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendVideo)$", caseSensitive: false).hashData(parameters["@type"])) { var getDetailFile = typeFile(parameters["video"]); jsonResult["input_message_content"]["@type"] = "inputMessageVideo"; jsonResult["input_message_content"]["video"] = getDetailFile; } - if (!RegExp(r"^(sendMessage|sendLocation|sendSticker)$", - caseSensitive: false) - .hashData(parameters["@type"])) { + if (!RegExp(r"^(sendMessage|sendLocation|sendSticker)$", caseSensitive: false).hashData(parameters["@type"])) { if (parameters["caption"] != null) { var caption = parseMode( - (parameters["caption"] != null) - ? parameters["caption"].toString() - : "", + (parameters["caption"] != null) ? parameters["caption"].toString() : "", parameters["parse_mode"], parameters["entities"], ); @@ -540,8 +534,7 @@ class Tdlib extends TdlibNative { return jsonResult; } - if (RegExp(r"^answerInlineQuery$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^answerInlineQuery$", caseSensitive: false).hashData(parameters["@type"])) { parameters["@type"] = "answerInlineQuery"; if (parameters["results"] is List) { @@ -550,8 +543,7 @@ class Tdlib extends TdlibNative { Map loop_data = parameters["results"][i]; if (loop_data["type"] is String) { - loop_data["@type"] = - "inputInlineQueryResult${loop_data["type"].toString().replaceAll(RegExp(r"inputInlineQueryResult", caseSensitive: false), "")}"; + loop_data["@type"] = "inputInlineQueryResult${loop_data["type"].toString().replaceAll(RegExp(r"inputInlineQueryResult", caseSensitive: false), "")}"; loop_data.remove("type"); } if (loop_data["id"] is String == false) { @@ -560,8 +552,7 @@ class Tdlib extends TdlibNative { } if (loop_data["reply_markup"] is Map) { - loop_data["reply_markup"] = - (replyMarkup(loop_data["reply_markup"])); + loop_data["reply_markup"] = (replyMarkup(loop_data["reply_markup"])); } array_results.add(loop_data); } @@ -584,8 +575,7 @@ class Tdlib extends TdlibNative { "@type": 'inputFileRemote', "id": content, }; - } else if (RegExp(r"^(\/|\.\.?\/|~\/)", caseSensitive: false) - .hashData(content)) { + } else if (RegExp(r"^(\/|\.\.?\/|~\/)", caseSensitive: false).hashData(content)) { data = { "@type": 'inputFileLocal', "path": content, @@ -686,8 +676,7 @@ class Tdlib extends TdlibNative { result["usernames"] = get_me["usernames"]; if (get_user_usernames["active_usernames"] is List) { if ((get_user_usernames["active_usernames"] as List).isNotEmpty) { - result["username"] = - (get_user_usernames["active_usernames"] as List).first; + result["username"] = (get_user_usernames["active_usernames"] as List).first; } } } @@ -695,14 +684,8 @@ class Tdlib extends TdlibNative { if (get_me["phone_number"].toString().isNotEmpty) { result["phone_number"] = get_me["phone_number"]; } - result["status"] = get_me["status"]["@type"] - .toString() - .toLowerCase() - .replaceAll(RegExp("userStatus", caseSensitive: false), ""); - result["type_account"] = get_me["type"]["@type"] - .toString() - .toLowerCase() - .replaceAll(RegExp("userType", caseSensitive: false), ""); + result["status"] = get_me["status"]["@type"].toString().toLowerCase().replaceAll(RegExp("userStatus", caseSensitive: false), ""); + result["type_account"] = get_me["type"]["@type"].toString().toLowerCase().replaceAll(RegExp("userType", caseSensitive: false), ""); result["type"] = "private"; if (result["type_account"] == "bot") { result["is_bot"] = true; @@ -731,15 +714,13 @@ class Tdlib extends TdlibNative { "file_id": "", }; if (get_me["profile_photo"]["big"] is Map) { - (get_me["profile_photo"]["big"]["local"] as Map) - .forEach((key, value) { + (get_me["profile_photo"]["big"]["local"] as Map).forEach((key, value) { if (key != "@type") { result["profile_photo"][key.toString()] = value; } }); if (get_me["profile_photo"]["big"]["remote"] is Map) { - result["profile_photo"]["file_id"] = - get_me["profile_photo"]["big"]["remote"]["id"]; + result["profile_photo"]["file_id"] = get_me["profile_photo"]["big"]["remote"]["id"]; } } } @@ -758,12 +739,10 @@ class Tdlib extends TdlibNative { Map json = { "@type": "replyMarkupRemoveKeyboard", }; - json["is_personal"] = - (keyboard["is_personal"] is bool) ? keyboard["is_personal"] : true; + json["is_personal"] = (keyboard["is_personal"] is bool) ? keyboard["is_personal"] : true; return json; } - if (keyboard["keyboard"] is List && - (keyboard["keyboard"] as List).isNotEmpty) { + if (keyboard["keyboard"] is List && (keyboard["keyboard"] as List).isNotEmpty) { Map json = { "@type": "replyMarkupShowKeyboard", }; @@ -784,12 +763,10 @@ class Tdlib extends TdlibNative { in_json_keyboard["text"] = in_loop_array_keyboard["text"]; } if (in_loop_array_keyboard["request_contact"] == true) { - in_json_keyboard["type"]["@type"] = - "keyboardButtonTypeRequestPhoneNumber"; + in_json_keyboard["type"]["@type"] = "keyboardButtonTypeRequestPhoneNumber"; } if (in_loop_array_keyboard["request_location"] == true) { - in_json_keyboard["type"]["@type"] = - "keyboardButtonTypeRequestLocation"; + in_json_keyboard["type"]["@type"] = "keyboardButtonTypeRequestLocation"; } array_loop.add(in_json_keyboard); } @@ -797,18 +774,13 @@ class Tdlib extends TdlibNative { array_rows.add(array_loop); } json["rows"] = array_rows; - json["resize_keyboard"] = (keyboard["resize_keyboard"] is bool) - ? keyboard["resize_keyboard"] - : true; - json["one_time"] = - (keyboard["one_time"] is bool) ? keyboard["one_time"] : true; - json["is_personal"] = - (keyboard["is_personal"] is bool) ? keyboard["is_personal"] : true; + json["resize_keyboard"] = (keyboard["resize_keyboard"] is bool) ? keyboard["resize_keyboard"] : true; + json["one_time"] = (keyboard["one_time"] is bool) ? keyboard["one_time"] : true; + json["is_personal"] = (keyboard["is_personal"] is bool) ? keyboard["is_personal"] : true; return json; } - if (keyboard["inline_keyboard"] is List && - keyboard["inline_keyboard"].length > 0) { + if (keyboard["inline_keyboard"] is List && keyboard["inline_keyboard"].length > 0) { Map json = { "@type": "replyMarkupInlineKeyboard", }; @@ -824,10 +796,7 @@ class Tdlib extends TdlibNative { } if (TgUtils.getBoolean(in_loop_array_keyboard["url"])) { - in_json_keyboard["type"] = { - "@type": "inlineKeyboardButtonTypeUrl", - "url": in_loop_array_keyboard["url"] - }; + in_json_keyboard["type"] = {"@type": "inlineKeyboardButtonTypeUrl", "url": in_loop_array_keyboard["url"]}; } if (TgUtils.getBoolean(in_loop_array_keyboard["login_url"])) { @@ -837,45 +806,21 @@ class Tdlib extends TdlibNative { }; } if (TgUtils.getBoolean(in_loop_array_keyboard["callback_data"])) { - in_json_keyboard["type"] = { - "@type": "inlineKeyboardButtonTypeCallback", - "data": convert.base64.encode(convert.utf8 - .encode(in_loop_array_keyboard["callback_data"])) - }; + in_json_keyboard["type"] = {"@type": "inlineKeyboardButtonTypeCallback", "data": convert.base64.encode(convert.utf8.encode(in_loop_array_keyboard["callback_data"]))}; } - if (TgUtils.getBoolean( - in_loop_array_keyboard["callback_data_password"])) { - in_json_keyboard["type"] = { - "@type": "inlineKeyboardButtonTypeCallbackWithPassword", - "data": convert.base64.encode(convert.utf8 - .encode(in_loop_array_keyboard["callback_data_password"])) - }; + if (TgUtils.getBoolean(in_loop_array_keyboard["callback_data_password"])) { + in_json_keyboard["type"] = {"@type": "inlineKeyboardButtonTypeCallbackWithPassword", "data": convert.base64.encode(convert.utf8.encode(in_loop_array_keyboard["callback_data_password"]))}; } - if (TgUtils.getBoolean( - in_loop_array_keyboard["switch_inline_query"])) { - in_json_keyboard["type"] = { - "@type": "inlineKeyboardButtonTypeSwitchInline", - "query": in_loop_array_keyboard["switch_inline_query"], - "in_current_chat": false - }; + if (TgUtils.getBoolean(in_loop_array_keyboard["switch_inline_query"])) { + in_json_keyboard["type"] = {"@type": "inlineKeyboardButtonTypeSwitchInline", "query": in_loop_array_keyboard["switch_inline_query"], "in_current_chat": false}; } - if (TgUtils.getBoolean( - in_loop_array_keyboard["switch_inline_query_current_chat"])) { - in_json_keyboard["type"] = { - "@type": "inlineKeyboardButtonTypeSwitchInline", - "query": - in_loop_array_keyboard["switch_inline_query_current_chat"], - "in_current_chat": true - }; + if (TgUtils.getBoolean(in_loop_array_keyboard["switch_inline_query_current_chat"])) { + in_json_keyboard["type"] = {"@type": "inlineKeyboardButtonTypeSwitchInline", "query": in_loop_array_keyboard["switch_inline_query_current_chat"], "in_current_chat": true}; } if (TgUtils.getBoolean(in_loop_array_keyboard["callback_game"])) { - in_json_keyboard["type"] = { - "@type": "inlineKeyboardButtonTypeSwitchInline", - "query": in_loop_array_keyboard["callback_game"], - "in_current_chat": false - }; + in_json_keyboard["type"] = {"@type": "inlineKeyboardButtonTypeSwitchInline", "query": in_loop_array_keyboard["callback_game"], "in_current_chat": false}; } if (TgUtils.getBoolean(in_loop_array_keyboard["user_id"])) { in_json_keyboard["type"] = { @@ -884,9 +829,7 @@ class Tdlib extends TdlibNative { }; } if (TgUtils.getBoolean(in_loop_array_keyboard["pay"])) { - in_json_keyboard["type"] = { - "@type": "inlineKeyboardButtonTypeBuy" - }; + in_json_keyboard["type"] = {"@type": "inlineKeyboardButtonTypeBuy"}; } array_loop.add(in_json_keyboard); } @@ -910,10 +853,8 @@ class Tdlib extends TdlibNative { Duration? invokeTimeOut, String? extra, bool? isAutoGetChat, - FutureOr Function(int client_id, TdlibBase libTdJson)? - onGenerateExtraInvoke, - FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? - onGetInvokeData, + FutureOr Function(int client_id, TdlibBase libTdJson)? onGenerateExtraInvoke, + FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? onGetInvokeData, bool? isInvokeThrowOnError, bool isAutoExtendMessage = false, bool? isUseCache, @@ -923,9 +864,7 @@ class Tdlib extends TdlibNative { parameters ??= {}; isAutoGetChat ??= false; - if (parameters["chat_id"] is String && - RegExp(r"^(@)?[a-z0-9_]+", caseSensitive: false) - .hashData(parameters["chat_id"])) { + if (parameters["chat_id"] is String && RegExp(r"^(@)?[a-z0-9_]+", caseSensitive: false).hashData(parameters["chat_id"])) { isAutoGetChat = false; var search_public_chat = await invoke( "searchPublicChat", @@ -946,9 +885,7 @@ class Tdlib extends TdlibNative { parameters["chat_id"] = search_public_chat["id"]; } } - if (parameters["user_id"] is String && - RegExp(r"^(@)?[a-z0-9_]+", caseSensitive: false) - .hashData(parameters["user_id"])) { + if (parameters["user_id"] is String && RegExp(r"^(@)?[a-z0-9_]+", caseSensitive: false).hashData(parameters["user_id"])) { isAutoGetChat = false; var search_public_chat = await invoke( "searchPublicChat", @@ -969,16 +906,13 @@ class Tdlib extends TdlibNative { parameters["user_id"] = search_public_chat["id"]; } } - String regexMethodSend = - r"^(sendMessage|sendPhoto|sendVideo|sendAudio|sendVoice|sendDocument|sendSticker|sendAnimation)$"; + String regexMethodSend = r"^(sendMessage|sendPhoto|sendVideo|sendAudio|sendVoice|sendDocument|sendSticker|sendAnimation)$"; if (RegExp(regexMethodSend, caseSensitive: false).hashData(method)) { Map result_request = { "ok": false, }; result_request = await invoke( - (RegExp("editMessageText", caseSensitive: false).hashData(method)) - ? method - : "sendMessage", + (RegExp("editMessageText", caseSensitive: false).hashData(method)) ? method : "sendMessage", parameters: makeParametersApi( { "@type": method, @@ -1017,14 +951,11 @@ class Tdlib extends TdlibNative { return; } Map updateOrigin = update.raw; - if (!["updateMessageSendSucceeded", "updateMessageSendFailed"] - .contains(updateOrigin["@type"])) { + if (!["updateMessageSendSucceeded", "updateMessageSendFailed"].contains(updateOrigin["@type"])) { return; } - if (updateOrigin["message"] is Map && - updateOrigin["message"]["chat_id"] == result_request["chat_id"] && - updateOrigin["old_message_id"] == result_request["id"]) { + if (updateOrigin["message"] is Map && updateOrigin["message"]["chat_id"] == result_request["chat_id"] && updateOrigin["old_message_id"] == result_request["id"]) { // updateOrigin.printPretty(2); // completer.complete(updateOrigin); @@ -1122,37 +1053,24 @@ class Tdlib extends TdlibNative { message_id: parameters["message_id"], text: parameters["text"], inline_message_id: parameters["inline_message_id"], - parse_mode: (parameters["parse_mode"] is String) - ? parameters["parse_mode"] - : "html", - entities: - (parameters["entities"] is List) ? parameters["entities"] : [], - disable_web_page_preview: - (parameters["disable_web_page_preview"] is bool) - ? parameters["disable_web_page_preview"] - : false, + parse_mode: (parameters["parse_mode"] is String) ? parameters["parse_mode"] : "html", + entities: (parameters["entities"] is List) ? parameters["entities"] : [], + disable_web_page_preview: (parameters["disable_web_page_preview"] is bool) ? parameters["disable_web_page_preview"] : false, reply_markup: parameters["reply_markup"], clientId: clientId, isUseCache: isUseCache, durationCacheExpire: durationCacheExpire, ); } - if (RegExp(r"^editMessageCaption$", caseSensitive: false) - .hashData(method)) { + if (RegExp(r"^editMessageCaption$", caseSensitive: false).hashData(method)) { return await editMessageCaption( chat_id: parameters["chat_id"], message_id: parameters["message_id"], caption: parameters["caption"], inline_message_id: parameters["inline_message_id"], - parse_mode: (parameters["parse_mode"] is String) - ? parameters["parse_mode"] - : "html", - entities: - (parameters["entities"] is List) ? parameters["entities"] : [], - disable_web_page_preview: - (parameters["disable_web_page_preview"] is bool) - ? parameters["disable_web_page_preview"] - : false, + parse_mode: (parameters["parse_mode"] is String) ? parameters["parse_mode"] : "html", + entities: (parameters["entities"] is List) ? parameters["entities"] : [], + disable_web_page_preview: (parameters["disable_web_page_preview"] is bool) ? parameters["disable_web_page_preview"] : false, reply_markup: parameters["reply_markup"], clientId: clientId, isUseCache: isUseCache, @@ -1178,8 +1096,7 @@ class Tdlib extends TdlibNative { onGetInvokeData: onGetInvokeData, ); } - if (RegExp(r"^joinChatByInviteLink$", caseSensitive: false) - .hashData(method)) { + if (RegExp(r"^joinChatByInviteLink$", caseSensitive: false).hashData(method)) { return await invoke( "joinChatByInviteLink", parameters: { @@ -1274,8 +1191,7 @@ class Tdlib extends TdlibNative { durationCacheExpire: durationCacheExpire, ); } - if (RegExp(r"^answerCallbackQuery$", caseSensitive: false) - .hashData(method)) { + if (RegExp(r"^answerCallbackQuery$", caseSensitive: false).hashData(method)) { return await answerCallbackQuery( parameters["callback_query_id"], text: parameters["text"], @@ -1340,10 +1256,8 @@ class Tdlib extends TdlibNative { Duration? invokeTimeOut, String? extra, bool? isAutoGetChat, - FutureOr Function(int client_id, TdlibBase libTdJson)? - onGenerateExtraInvoke, - FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? - onGetInvokeData, + FutureOr Function(int client_id, TdlibBase libTdJson)? onGenerateExtraInvoke, + FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? onGetInvokeData, bool? isInvokeThrowOnError, bool isAutoExtendMessage = false, bool? isUseCache, @@ -1363,8 +1277,7 @@ class Tdlib extends TdlibNative { try { await Future.delayed(Duration(milliseconds: 500)); parameters["text"] = loopData; - if (RegExp("(editMessageText)", caseSensitive: false) - .hasMatch(method)) { + if (RegExp("(editMessageText)", caseSensitive: false).hasMatch(method)) { if (i != 0) { method = "sendMessage"; } @@ -1403,8 +1316,7 @@ class Tdlib extends TdlibNative { try { await Future.delayed(Duration(milliseconds: 500)); parameters["caption"] = loopData; - if (RegExp("(editMessageCaption)", caseSensitive: false) - .hasMatch(method)) { + if (RegExp("(editMessageCaption)", caseSensitive: false).hasMatch(method)) { if (i != 0) { parameters["text"] = loopData; method = "sendMessage"; @@ -1675,8 +1587,7 @@ class Tdlib extends TdlibNative { extra: extra, ); - if (RegExp("^chatMember\$", caseSensitive: false) - .hashData(get_chat_member["@type"])) { + if (RegExp("^chatMember\$", caseSensitive: false).hashData(get_chat_member["@type"])) { var json = {}; var get_user = await getUser( @@ -1688,10 +1599,7 @@ class Tdlib extends TdlibNative { 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["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"]; @@ -1726,14 +1634,11 @@ class Tdlib extends TdlibNative { String? extra, }) async { try { - if (chat_id is String && - RegExp(r"^((@)?[a-z0-9_]+)$", caseSensitive: false) - .hashData(chat_id)) { + if (chat_id is String && RegExp(r"^((@)?[a-z0-9_]+)$", caseSensitive: false).hashData(chat_id)) { var search_public_chat = await invoke( "searchPublicChat", parameters: { - "username": - chat_id.replaceAll(RegExp(r"@", caseSensitive: false), ""), + "username": chat_id.replaceAll(RegExp(r"@", caseSensitive: false), ""), }, isUseCache: isUseCache, durationCacheExpire: durationCacheExpire, @@ -1755,20 +1660,14 @@ class Tdlib extends TdlibNative { extra: extra, ); Map json = {}; - if (RegExp(r"^(chat)$", caseSensitive: false) - .hashData(getchat["@type"])) { - var type_chat = getchat["type"]["@type"] - .toString() - .toLowerCase() - .replaceAll(RegExp("chattype", caseSensitive: false), ""); + if (RegExp(r"^(chat)$", caseSensitive: false).hashData(getchat["@type"])) { + var type_chat = getchat["type"]["@type"].toString().toLowerCase().replaceAll(RegExp("chattype", caseSensitive: false), ""); if (type_chat == "supergroup") { var getSupergroup = await invoke( "getSupergroup", parameters: { "supergroup_id": int.parse( - chat_id - .toString() - .replaceAll(RegExp("^-100", caseSensitive: false), ""), + chat_id.toString().replaceAll(RegExp("^-100", caseSensitive: false), ""), ), }, isUseCache: isUseCache, @@ -1787,52 +1686,15 @@ class Tdlib extends TdlibNative { json["usernames"] = getSupergroup["usernames"]; if (get_user_usernames["active_usernames"] is List) { if ((get_user_usernames["active_usernames"] as List).isNotEmpty) { - json["username"] = - (get_user_usernames["active_usernames"] as List).first; + json["username"] = (get_user_usernames["active_usernames"] as List).first; } } } if (getSupergroup["status"] is Map) { - json["status"] = getSupergroup["status"]["@type"] - .toString() - .toLowerCase() - .replaceAll( - RegExp("chatMemberStatus", caseSensitive: false), ""); + json["status"] = getSupergroup["status"]["@type"].toString().toLowerCase().replaceAll(RegExp("chatMemberStatus", caseSensitive: false), ""); } - json["type"] = - getchat["type"]["is_channel"] ? "channel" : "supergroup"; - json["detail"] = { - "member_count": getSupergroup["member_count"], - "administrator_count": 0, - "restricted_count": 0, - "banned_count": 0, - "has_protected_content": getchat["has_protected_content"] ?? false, - "is_marked_as_unread": getchat["is_marked_as_unread"] ?? false, - "is_blocked": getchat["is_blocked"] ?? false, - "has_scheduled_messages": - getchat["has_scheduled_messages"] ?? false, - "can_be_deleted_only_for_self": - getchat["can_be_deleted_only_for_self"] ?? false, - "can_be_deleted_for_all_users": - getchat["can_be_deleted_for_all_users"] ?? false, - "can_be_reported": getchat["can_be_reported"] ?? false, - "default_disable_notification": - getchat["default_disable_notification"] ?? false, - "unread_count": getchat["unread_count"] ?? 0, - "last_read_inbox_message_id": - getchat["last_read_inbox_message_id"] ?? 0, - "last_read_outbox_message_id": - getchat["last_read_outbox_message_id"] ?? 0, - "unread_mention_count": getchat["unread_mention_count"] ?? 0, - "has_linked_chat": getSupergroup["has_linked_chat"], - "has_location": getSupergroup["has_location"], - "sign_messages": getSupergroup["sign_messages"], - "is_slow_mode_enabled": getSupergroup["is_slow_mode_enabled"], - "is_broadcast_group": getSupergroup["is_broadcast_group"], - "is_verified": getSupergroup["is_verified"], - "is_scam": getSupergroup["is_scam"], - "is_fake": getSupergroup["is_fake"] - }; + json["type"] = getchat["type"]["is_channel"] ? "channel" : "supergroup"; + json["detail"] = {"member_count": getSupergroup["member_count"], "administrator_count": 0, "restricted_count": 0, "banned_count": 0, "has_protected_content": getchat["has_protected_content"] ?? false, "is_marked_as_unread": getchat["is_marked_as_unread"] ?? false, "is_blocked": getchat["is_blocked"] ?? false, "has_scheduled_messages": getchat["has_scheduled_messages"] ?? false, "can_be_deleted_only_for_self": getchat["can_be_deleted_only_for_self"] ?? false, "can_be_deleted_for_all_users": getchat["can_be_deleted_for_all_users"] ?? false, "can_be_reported": getchat["can_be_reported"] ?? false, "default_disable_notification": getchat["default_disable_notification"] ?? false, "unread_count": getchat["unread_count"] ?? 0, "last_read_inbox_message_id": getchat["last_read_inbox_message_id"] ?? 0, "last_read_outbox_message_id": getchat["last_read_outbox_message_id"] ?? 0, "unread_mention_count": getchat["unread_mention_count"] ?? 0, "has_linked_chat": getSupergroup["has_linked_chat"], "has_location": getSupergroup["has_location"], "sign_messages": getSupergroup["sign_messages"], "is_slow_mode_enabled": getSupergroup["is_slow_mode_enabled"], "is_broadcast_group": getSupergroup["is_broadcast_group"], "is_verified": getSupergroup["is_verified"], "is_scam": getSupergroup["is_scam"], "is_fake": getSupergroup["is_fake"]}; if (getSupergroup["username"].toString().isEmpty) { json.remove("username"); json["type"] = getchat["type"]["is_channel"] ? "channel" : "group"; @@ -1859,9 +1721,7 @@ class Tdlib extends TdlibNative { getSuperGroupFullInfo = await invoke( "getSupergroupFullInfo", parameters: { - "supergroup_id": int.parse(chat_id - .toString() - .replaceAll(RegExp("^-100", caseSensitive: false), "")), + "supergroup_id": int.parse(chat_id.toString().replaceAll(RegExp("^-100", caseSensitive: false), "")), }, isUseCache: isUseCache, durationCacheExpire: durationCacheExpire, @@ -1870,25 +1730,16 @@ class Tdlib extends TdlibNative { ); } catch (e) {} if (getSuperGroupFullInfo["photo"] is Map) { - json["profile_photo"] = { - "id": getSuperGroupFullInfo["photo"]["id"], - "path": "", - "file_id": "" - }; + json["profile_photo"] = {"id": getSuperGroupFullInfo["photo"]["id"], "path": "", "file_id": ""}; if (getSuperGroupFullInfo["photo"]["@type"] == "chatPhoto") { if (getSuperGroupFullInfo["photo"]["sizes"] is List) { try { - var getPhoto = getSuperGroupFullInfo["photo"]["sizes"] - [getSuperGroupFullInfo["photo"]["sizes"].length - 1]; - var getPathPhoto = - getPhoto["photo"]["local"]["path"] as String; + var getPhoto = getSuperGroupFullInfo["photo"]["sizes"][getSuperGroupFullInfo["photo"]["sizes"].length - 1]; + var getPathPhoto = getPhoto["photo"]["local"]["path"] as String; json["profile_photo"]["path"] = getPathPhoto; - (json["profile_photo"] as Map) - .addAll(getPhoto["photo"]["local"]); - json["profile_photo"]["file_id"] = - getPhoto["photo"]["remote"]["id"]; - json["profile_photo"]["file_unique_id"] = - getPhoto["photo"]["remote"]["unique_id"]; + (json["profile_photo"] as Map).addAll(getPhoto["photo"]["local"]); + json["profile_photo"]["file_id"] = getPhoto["photo"]["remote"]["id"]; + json["profile_photo"]["file_unique_id"] = getPhoto["photo"]["remote"]["unique_id"]; } catch (e) {} } } @@ -1914,12 +1765,9 @@ class Tdlib extends TdlibNative { }); } catch (e) {} - if (json["profile_photo"] is Map && - RegExp(r"^([0-9]+)$", caseSensitive: false) - .hashData(json["profile_photo"]["id"])) { + if (json["profile_photo"] is Map && RegExp(r"^([0-9]+)$", caseSensitive: false).hashData(json["profile_photo"]["id"])) { try { - json["profile_photo"]["id"] = - (int.parse(json["profile_photo"]["id"])); + json["profile_photo"]["id"] = (int.parse(json["profile_photo"]["id"])); } catch (e) {} } } @@ -1929,9 +1777,7 @@ class Tdlib extends TdlibNative { var getBasicGroup = await invoke( "getBasicGroup", parameters: { - "basic_group_id": int.parse(chat_id - .toString() - .replaceAll(RegExp("^-", caseSensitive: false), "")), + "basic_group_id": int.parse(chat_id.toString().replaceAll(RegExp("^-", caseSensitive: false), "")), }, isUseCache: isUseCache, durationCacheExpire: durationCacheExpire, @@ -1941,11 +1787,7 @@ class Tdlib extends TdlibNative { json["id"] = chat_id; json["title"] = getchat["title"]; if (getBasicGroup["status"] is Map) { - json["status"] = getBasicGroup["status"]["@type"] - .toString() - .toLowerCase() - .replaceAll( - RegExp("chatMemberStatus", caseSensitive: false), ""); + json["status"] = getBasicGroup["status"]["@type"].toString().toLowerCase().replaceAll(RegExp("chatMemberStatus", caseSensitive: false), ""); } json["type"] = "group"; json["detail"] = { @@ -1953,20 +1795,14 @@ class Tdlib extends TdlibNative { "has_protected_content": getchat["has_protected_content"] ?? false, "is_marked_as_unread": getchat["is_marked_as_unread"] ?? false, "is_blocked": getchat["is_blocked"] ?? false, - "has_scheduled_messages": - getchat["has_scheduled_messages"] ?? false, - "can_be_deleted_only_for_self": - getchat["can_be_deleted_only_for_self"] ?? false, - "can_be_deleted_for_all_users": - getchat["can_be_deleted_for_all_users"] ?? false, + "has_scheduled_messages": getchat["has_scheduled_messages"] ?? false, + "can_be_deleted_only_for_self": getchat["can_be_deleted_only_for_self"] ?? false, + "can_be_deleted_for_all_users": getchat["can_be_deleted_for_all_users"] ?? false, "can_be_reported": getchat["can_be_reported"] ?? false, - "default_disable_notification": - getchat["default_disable_notification"] ?? false, + "default_disable_notification": getchat["default_disable_notification"] ?? false, "unread_count": getchat["unread_count"] ?? 0, - "last_read_inbox_message_id": - getchat["last_read_inbox_message_id"] ?? 0, - "last_read_outbox_message_id": - getchat["last_read_outbox_message_id"] ?? 0, + "last_read_inbox_message_id": getchat["last_read_inbox_message_id"] ?? 0, + "last_read_outbox_message_id": getchat["last_read_outbox_message_id"] ?? 0, "unread_mention_count": getchat["unread_mention_count"] ?? 0, }; if (is_detail) { @@ -1997,13 +1833,11 @@ class Tdlib extends TdlibNative { clientId: clientId, extra: extra, ); - if (RegExp("^user\$", caseSensitive: false) - .hashData(get_user["@type"])) { + if (RegExp("^user\$", caseSensitive: false).hashData(get_user["@type"])) { var json = {}; json["id"] = get_user["id"]; try { - if (RegExp("^userTypeBot\$", caseSensitive: false) - .hashData(get_user["type"]["@type"])) { + if (RegExp("^userTypeBot\$", caseSensitive: false).hashData(get_user["type"]["@type"])) { json["is_bot"] = true; } else { json["is_bot"] = false; @@ -2023,10 +1857,8 @@ class Tdlib extends TdlibNative { Map get_user_usernames = (get_user["usernames"] as Map); json["usernames"] = get_user["usernames"]; if (get_user_usernames["active_usernames"] is List) { - if ((get_user_usernames["active_usernames"] as List) - .isNotEmpty) { - json["username"] = - (get_user_usernames["active_usernames"] as List).first; + if ((get_user_usernames["active_usernames"] as List).isNotEmpty) { + json["username"] = (get_user_usernames["active_usernames"] as List).first; } } } @@ -2038,34 +1870,7 @@ class Tdlib extends TdlibNative { json["language_code"] = get_user["language_code"]; } json["type"] = 'private'; - json["detail"] = { - "has_protected_content": - getchat["has_protected_content"] ?? false, - "is_marked_as_unread": getchat["is_marked_as_unread"] ?? false, - "is_blocked": getchat["is_blocked"] ?? false, - "has_scheduled_messages": - getchat["has_scheduled_messages"] ?? false, - "can_be_deleted_only_for_self": - getchat["can_be_deleted_only_for_self"] ?? false, - "can_be_deleted_for_all_users": - getchat["can_be_deleted_for_all_users"] ?? false, - "can_be_reported": getchat["can_be_reported"] ?? false, - "default_disable_notification": - getchat["default_disable_notification"] ?? false, - "unread_count": getchat["unread_count"] ?? 0, - "last_read_inbox_message_id": - getchat["last_read_inbox_message_id"] ?? 0, - "last_read_outbox_message_id": - getchat["last_read_outbox_message_id"] ?? 0, - "unread_mention_count": getchat["unread_mention_count"] ?? 0, - "is_contact": get_user["is_contact"], - "is_mutual_contact": get_user["is_mutual_contact"], - "is_verified": get_user["is_verified"], - "is_support": get_user["is_support"], - "is_scam": get_user["is_scam"], - "is_fake": get_user["is_fake"], - "have_acces": get_user["have_access"] - }; + json["detail"] = {"has_protected_content": getchat["has_protected_content"] ?? false, "is_marked_as_unread": getchat["is_marked_as_unread"] ?? false, "is_blocked": getchat["is_blocked"] ?? false, "has_scheduled_messages": getchat["has_scheduled_messages"] ?? false, "can_be_deleted_only_for_self": getchat["can_be_deleted_only_for_self"] ?? false, "can_be_deleted_for_all_users": getchat["can_be_deleted_for_all_users"] ?? false, "can_be_reported": getchat["can_be_reported"] ?? false, "default_disable_notification": getchat["default_disable_notification"] ?? false, "unread_count": getchat["unread_count"] ?? 0, "last_read_inbox_message_id": getchat["last_read_inbox_message_id"] ?? 0, "last_read_outbox_message_id": getchat["last_read_outbox_message_id"] ?? 0, "unread_mention_count": getchat["unread_mention_count"] ?? 0, "is_contact": get_user["is_contact"], "is_mutual_contact": get_user["is_mutual_contact"], "is_verified": get_user["is_verified"], "is_support": get_user["is_support"], "is_scam": get_user["is_scam"], "is_fake": get_user["is_fake"], "have_acces": get_user["have_access"]}; if (is_detail) { if (getchat["last_message"] is Map) { try { @@ -2100,27 +1905,17 @@ class Tdlib extends TdlibNative { ); } catch (e) {} if (getUserFullInfo["photo"] is Map) { - json["profile_photo"] = { - "id": getUserFullInfo["photo"]["id"], - "path": "", - "file_id": "" - }; + json["profile_photo"] = {"id": getUserFullInfo["photo"]["id"], "path": "", "file_id": ""}; if (getUserFullInfo["photo"]["@type"] == "chatPhoto") { if (getUserFullInfo["photo"]["sizes"] is List) { try { - var getPhoto = getUserFullInfo["photo"]["sizes"] - [getUserFullInfo["photo"]["sizes"].length - 1]; - var getPathPhoto = - getPhoto["photo"]["local"]["path"] as String; + var getPhoto = getUserFullInfo["photo"]["sizes"][getUserFullInfo["photo"]["sizes"].length - 1]; + var getPathPhoto = getPhoto["photo"]["local"]["path"] as String; json["profile_photo"]["path"] = getPathPhoto; - (json["profile_photo"] as Map) - .addAll(getPhoto["photo"]["local"]); - json["profile_photo"]["id"] = - getPhoto["photo"]["local"]["id"]; - json["profile_photo"]["file_id"] = - getPhoto["photo"]["remote"]["id"]; - json["profile_photo"]["file_unique_id"] = - getPhoto["photo"]["remote"]["unique_id"]; + (json["profile_photo"] as Map).addAll(getPhoto["photo"]["local"]); + json["profile_photo"]["id"] = getPhoto["photo"]["local"]["id"]; + json["profile_photo"]["file_id"] = getPhoto["photo"]["remote"]["id"]; + json["profile_photo"]["file_unique_id"] = getPhoto["photo"]["remote"]["unique_id"]; } catch (e) {} } } @@ -2146,12 +1941,9 @@ class Tdlib extends TdlibNative { }); } catch (e) {} - if (json["profile_photo"] is Map && - RegExp(r"^([0-9]+)$", caseSensitive: false) - .hashData(json["profile_photo"]["id"])) { + if (json["profile_photo"] is Map && RegExp(r"^([0-9]+)$", caseSensitive: false).hashData(json["profile_photo"]["id"])) { try { - json["profile_photo"]["id"] = - (int.parse(json["profile_photo"]["id"])); + json["profile_photo"]["id"] = (int.parse(json["profile_photo"]["id"])); } catch (e) {} } } catch (e) { @@ -2163,8 +1955,7 @@ class Tdlib extends TdlibNative { } } } catch (e) { - if (RegExp("^[0-9]+\$", caseSensitive: false) - .hashData(chat_id.toString())) { + if (RegExp("^[0-9]+\$", caseSensitive: false).hashData(chat_id.toString())) { try { return await getUser( chat_id, @@ -2256,12 +2047,10 @@ class Tdlib extends TdlibNative { chat_json["type"] = "channel"; chat_json["title"] = ""; } else { - if (RegExp("^-100", caseSensitive: false) - .hashData(update["chat_id"])) { + if (RegExp("^-100", caseSensitive: false).hashData(update["chat_id"])) { chat_json["type"] = "supergroup"; chat_json["title"] = ""; - } else if (RegExp("^-", caseSensitive: false) - .hashData(update["chat_id"])) { + } else if (RegExp("^-", caseSensitive: false).hashData(update["chat_id"])) { chat_json["type"] = "group"; chat_json["title"] = ""; } else { @@ -2309,20 +2098,12 @@ class Tdlib extends TdlibNative { json["is_outgoing"] = update["is_outgoing"] ?? false; json["is_pinned"] = update["is_pinned"] ?? false; if (update["sender_id"] is Map) { - Map from_json = { - "id": 0, - "first_name": "", - "title": "", - "type": "", - "detail": {}, - "last_message": {} - }; + Map from_json = {"id": 0, "first_name": "", "title": "", "type": "", "detail": {}, "last_message": {}}; if (update["sender_id"]["user_id"] != null) { from_json["id"] = update["sender_id"]["user_id"]; if (update["chat_id"] == from_json["id"]) { from_json["type"] = chat_json["type"]; - } else if (RegExp("^-", caseSensitive: false) - .hashData(from_json["chat_id"])) { + } else if (RegExp("^-", caseSensitive: false).hashData(from_json["chat_id"])) { from_json["type"] = "group"; } else { from_json["type"] = "private"; @@ -2360,8 +2141,7 @@ class Tdlib extends TdlibNative { from_json["id"] = update["sender_id"]["chat_id"]; if (update["chat_id"] == from_json["id"]) { from_json["type"] = chat_json["type"]; - } else if (RegExp("^-", caseSensitive: false) - .hashData(from_json["chat_id"])) { + } else if (RegExp("^-", caseSensitive: false).hashData(from_json["chat_id"])) { from_json["type"] = "group"; } else { from_json["type"] = "private"; @@ -2427,16 +2207,8 @@ class Tdlib extends TdlibNative { if (update["forward_info"] is Map) { var forward_info = update["forward_info"]; if (forward_info["origin"] is Map) { - if (forward_info["origin"]["@type"] == - "messageForwardOriginChannel") { - Map forward_json = { - "id": forward_info["origin"]["chat_id"], - "first_name": "", - "title": "", - "type": "", - "detail": {}, - "last_message": {} - }; + if (forward_info["origin"]["@type"] == "messageForwardOriginChannel") { + Map forward_json = {"id": forward_info["origin"]["chat_id"], "first_name": "", "title": "", "type": "", "detail": {}, "last_message": {}}; try { var getchat_forward = await getChat( forward_json["id"], @@ -2450,22 +2222,12 @@ class Tdlib extends TdlibNative { } } catch (e) {} json["forward_from_chat"] = forward_json; - json["forward_from_message_id"] = - forward_info["origin"]["message_id"] ?? 0; - json["api_forward_from_message_id"] = - TgUtils.messageTdlibToApi(json["forward_from_message_id"]); - json["forward_from_author_signature"] = - forward_info["origin"]["author_signature"] ?? ""; + json["forward_from_message_id"] = forward_info["origin"]["message_id"] ?? 0; + json["api_forward_from_message_id"] = TgUtils.messageTdlibToApi(json["forward_from_message_id"]); + json["forward_from_author_signature"] = forward_info["origin"]["author_signature"] ?? ""; } if (forward_info["origin"]["@type"] == "messageForwardOriginUser") { - Map forward_json = { - "id": forward_info["origin"]["sender_user_id"], - "first_name": "", - "title": "", - "type": "", - "detail": {}, - "last_message": {} - }; + Map forward_json = {"id": forward_info["origin"]["sender_user_id"], "first_name": "", "title": "", "type": "", "detail": {}, "last_message": {}}; try { var getuser_forward = await getUser( forward_json["id"], @@ -2501,9 +2263,7 @@ class Tdlib extends TdlibNative { } } } - if (update["reply_to_message_id"] != 0 && - update["reply_in_chat_id"] != 0 && - !is_skip_reply_message) { + if (update["reply_to_message_id"] != 0 && update["reply_in_chat_id"] != 0 && !is_skip_reply_message) { try { var get_message = await getMessage( update["reply_in_chat_id"], @@ -2518,11 +2278,8 @@ class Tdlib extends TdlibNative { ); if (get_message["ok"] == true) { json["reply_to_message"] = get_message["result"]; - json["reply_to_message"]["message_id"] = - json["reply_to_message"]["message_id"]; - json["reply_to_message"]["api_message_id"] = - TgUtils.messageTdlibToApi( - json["reply_to_message"]["message_id"]); + json["reply_to_message"]["message_id"] = json["reply_to_message"]["message_id"]; + json["reply_to_message"]["api_message_id"] = TgUtils.messageTdlibToApi(json["reply_to_message"]["message_id"]); } } catch (e) {} } @@ -2557,8 +2314,7 @@ class Tdlib extends TdlibNative { json_photo["file_id"] = photo_json["photo"]["remote"]["id"]; } if (photo_json["photo"]["remote"]["unique_id"] != null) { - json_photo["file_unique_id"] = - photo_json["photo"]["remote"]["unique_id"]; + json_photo["file_unique_id"] = photo_json["photo"]["remote"]["unique_id"]; } json_photo["file_size"] = photo_json["photo"]["size"]; json_photo["width"] = photo_json["width"]; @@ -2581,18 +2337,12 @@ class Tdlib extends TdlibNative { json_video["file_name"] = content_video["file_name"]; json_video["mime_type"] = content_video["mime_type"]; try { - if (update["content"]["video"]["thumbnail"] != null && - update["content"]["video"]["thumbnail"]["@type"] - .toString() - .toLowerCase() == - "thumbnail") { + if (update["content"]["video"]["thumbnail"] != null && update["content"]["video"]["thumbnail"]["@type"].toString().toLowerCase() == "thumbnail") { var content_thumb = content_video["thumbnail"]; var json_thumb = {}; json_video["thumb"] = json_thumb; - json_thumb["file_id"] = - content_thumb["file"]["remote"]["id"]; - json_thumb["file_unique_id"] = - content_thumb["file"]["remote"]["unique_id"]; + json_thumb["file_id"] = content_thumb["file"]["remote"]["id"]; + json_thumb["file_unique_id"] = content_thumb["file"]["remote"]["unique_id"]; json_thumb["file_size"] = content_thumb["file"]["size"]; json_thumb["width"] = content_thumb["width"]; json_thumb["height"] = content_thumb["height"]; @@ -2617,12 +2367,9 @@ class Tdlib extends TdlibNative { json_content["performer"] = content_update["performer"]; json_content["file_name"] = content_update["file_name"]; json_content["mime_type"] = content_update["mime_type"]; - json_content["file_id"] = - content_update[type_content]["remote"]["id"]; - json_content["unique_id"] = - content_update[type_content]["remote"]["unique_id"]; - json_content["file_size"] = - content_update[type_content]["size"]; + json_content["file_id"] = content_update[type_content]["remote"]["id"]; + json_content["unique_id"] = content_update[type_content]["remote"]["unique_id"]; + json_content["file_size"] = content_update[type_content]["size"]; json[type_content] = json_content; } } @@ -2644,29 +2391,20 @@ class Tdlib extends TdlibNative { json_content["has_stickers"] = content_update["has_stickers"]; try { - if (update["content"][type_content]["thumbnail"] != null && - update["content"][type_content]["thumbnail"]["@type"] - .toString() - .toLowerCase() == - "thumbnail") { + if (update["content"][type_content]["thumbnail"] != null && update["content"][type_content]["thumbnail"]["@type"].toString().toLowerCase() == "thumbnail") { var content_thumb = content_update["thumbnail"]; var json_thumb = {}; - json_thumb["file_id"] = - content_thumb["file"]["remote"]["id"]; - json_thumb["file_unique_id"] = - content_thumb["file"]["remote"]["unique_id"]; + json_thumb["file_id"] = content_thumb["file"]["remote"]["id"]; + json_thumb["file_unique_id"] = content_thumb["file"]["remote"]["unique_id"]; json_thumb["file_size"] = content_thumb["file"]["size"]; json_thumb["width"] = content_thumb["width"]; json_thumb["height"] = content_thumb["height"]; json_content["thumb"] = json_thumb; } } catch (e) {} - json_content["file_id"] = - content_update[type_content]["remote"]["id"]; - json_content["unique_id"] = - content_update[type_content]["remote"]["unique_id"]; - json_content["file_size"] = - content_update[type_content]["size"]; + json_content["file_id"] = content_update[type_content]["remote"]["id"]; + json_content["unique_id"] = content_update[type_content]["remote"]["unique_id"]; + json_content["file_size"] = content_update[type_content]["size"]; json[type_content] = json_content; } } @@ -2699,10 +2437,8 @@ class Tdlib extends TdlibNative { json_content["id"] = content_update["id"]; json_content["question"] = content_update["question"]; json_content["options"] = content_update["options"]; - json_content["total_voter_count"] = - content_update["total_voter_count"]; - json_content["recent_voter_user_ids"] = - content_update["recent_voter_user_ids"]; + json_content["total_voter_count"] = content_update["total_voter_count"]; + json_content["recent_voter_user_ids"] = content_update["recent_voter_user_ids"]; json_content["is_anonymous"] = content_update["is_anonymous"]; json_content["type"] = content_update["type"]; json_content["open_period"] = content_update["open_period"]; @@ -2723,12 +2459,9 @@ class Tdlib extends TdlibNative { json_content["file_name"] = content_update["file_name"]; json_content["mime_type"] = content_update["mime_type"]; - json_content["file_id"] = - content_update[type_content]["remote"]["id"]; - json_content["unique_id"] = - content_update[type_content]["remote"]["unique_id"]; - json_content["file_size"] = - content_update[type_content]["size"]; + json_content["file_id"] = content_update[type_content]["remote"]["id"]; + json_content["unique_id"] = content_update[type_content]["remote"]["unique_id"]; + json_content["file_size"] = content_update[type_content]["size"]; json[type_content] = json_content; } } @@ -2749,17 +2482,11 @@ class Tdlib extends TdlibNative { json_content["is_mask"] = content_update["is_mask"]; try { - if (update["content"][type_content]["thumbnail"] != null && - update["content"][type_content]["thumbnail"]["@type"] - .toString() - .toLowerCase() == - "thumbnail") { + if (update["content"][type_content]["thumbnail"] != null && update["content"][type_content]["thumbnail"]["@type"].toString().toLowerCase() == "thumbnail") { var content_thumb = content_update["thumbnail"]; var json_thumb = {}; - json_thumb["file_id"] = - content_thumb["file"]["remote"]["id"]; - json_thumb["file_unique_id"] = - content_thumb["file"]["remote"]["unique_id"]; + json_thumb["file_id"] = content_thumb["file"]["remote"]["id"]; + json_thumb["file_unique_id"] = content_thumb["file"]["remote"]["unique_id"]; json_thumb["file_size"] = content_thumb["file"]["size"]; json_thumb["width"] = content_thumb["width"]; json_thumb["height"] = content_thumb["height"]; @@ -2767,12 +2494,9 @@ class Tdlib extends TdlibNative { } } catch (e) {} - json_content["file_id"] = - content_update[type_content]["remote"]["id"]; - json_content["unique_id"] = - content_update[type_content]["remote"]["unique_id"]; - json_content["file_size"] = - content_update[type_content]["size"]; + json_content["file_id"] = content_update[type_content]["remote"]["id"]; + json_content["unique_id"] = content_update[type_content]["remote"]["unique_id"]; + json_content["file_size"] = content_update[type_content]["size"]; json[type_content] = json_content; } } @@ -2790,10 +2514,8 @@ class Tdlib extends TdlibNative { json_content["waveform"] = content_update["waveform"]; json_content["mime_type"] = content_update["mime_type"]; - json_content["file_id"] = - content_update["voice"]["remote"]["id"]; - json_content["unique_id"] = - content_update["voice"]["remote"]["unique_id"]; + json_content["file_id"] = content_update["voice"]["remote"]["id"]; + json_content["unique_id"] = content_update["voice"]["remote"]["unique_id"]; json_content["file_size"] = content_update["voice"]["size"]; json["voice"] = json_content; } @@ -2811,9 +2533,7 @@ class Tdlib extends TdlibNative { json["type_content"] = "new_member"; List new_members = []; if (is_super_detail) { - for (var i = 0; - i < update["content"]["member_user_ids"].length; - i++) { + for (var i = 0; i < update["content"]["member_user_ids"].length; i++) { var loop_data = update["content"]["member_user_ids"][i]; try { Map result_user = await getUser( @@ -2827,13 +2547,7 @@ class Tdlib extends TdlibNative { } catch (e) {} new_members.add(result_user["result"]); } catch (e) { - new_members.add({ - "id": loop_data, - "is_bot": false, - "first_name": "", - "last_name": "", - "type": "private" - }); + new_members.add({"id": loop_data, "is_bot": false, "first_name": "", "last_name": "", "type": "private"}); } } } else { @@ -2858,22 +2572,10 @@ class Tdlib extends TdlibNative { } catch (e) {} left_member.add(result_user["result"]); } catch (e) { - left_member.add({ - "id": update["content"]["user_id"], - "is_bot": false, - "first_name": "", - "last_name": "", - "type": "private" - }); + left_member.add({"id": update["content"]["user_id"], "is_bot": false, "first_name": "", "last_name": "", "type": "private"}); } } else { - left_member.add({ - "id": update["content"]["user_id"], - "is_bot": false, - "first_name": "", - "last_name": "", - "type": "private" - }); + left_member.add({"id": update["content"]["user_id"], "is_bot": false, "first_name": "", "last_name": "", "type": "private"}); } json["left_member"] = left_member; } @@ -2896,23 +2598,12 @@ class Tdlib extends TdlibNative { json_entities["offset"] = data_entities["offset"]; json_entities["length"] = data_entities["length"]; if (data_entities["type"]["@type"] != null) { - var type_entities = data_entities["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"); + var type_entities = data_entities["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"); json_entities["type"] = type_entities; if (data_entities["type"]["url"] != null) { json_entities["url"] = data_entities["type"]["url"]; } - if (type_entities == "text_mention" && - data_entities["type"]["user_id"] != null) { + if (type_entities == "text_mention" && data_entities["type"]["user_id"] != null) { var entitiesUserId = data_entities["type"]["user_id"]; var fromJson = {"id": entitiesUserId}; try { @@ -2940,23 +2631,17 @@ class Tdlib extends TdlibNative { Map update_reply_markup = update["reply_markup"]; json["reply_markup"] = {}; if (update_reply_markup["resize_keyboard"] is bool) { - json["reply_markup"]["resize_keyboard"] = - (update_reply_markup["resize_keyboard"] == true); + json["reply_markup"]["resize_keyboard"] = (update_reply_markup["resize_keyboard"] == true); } if (update_reply_markup["one_time"] is bool) { - json["reply_markup"]["one_time"] = - (update_reply_markup["one_time"] == true); + json["reply_markup"]["one_time"] = (update_reply_markup["one_time"] == true); } if (update_reply_markup["is_personal"] is bool) { - json["reply_markup"]["is_personal"] = - (update_reply_markup["is_personal"] == true); + json["reply_markup"]["is_personal"] = (update_reply_markup["is_personal"] == true); } if (update_reply_markup["input_field_placeholder"] is String) { - json["reply_markup"]["input_field_placeholder"] = - (update_reply_markup["input_field_placeholder"] is String) - ? (update_reply_markup["input_field_placeholder"] as String) - : ""; + json["reply_markup"]["input_field_placeholder"] = (update_reply_markup["input_field_placeholder"] is String) ? (update_reply_markup["input_field_placeholder"] as String) : ""; } try { if (update_reply_markup["@type"] == "replyMarkupShowKeyboard") { @@ -2976,17 +2661,14 @@ class Tdlib extends TdlibNative { }; if (raw_keyboard_data["type"] is Map) { // https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_inline_keyboard_button_type.html - if (raw_keyboard_data["@type"] == - "keyboardButtonTypeRequestPoll") { + if (raw_keyboard_data["@type"] == "keyboardButtonTypeRequestPoll") { jsonDataKeyboard["is_request_poll"] = true; } - if (raw_keyboard_data["@type"] == - "keyboardButtonTypeRequestLocation") { + if (raw_keyboard_data["@type"] == "keyboardButtonTypeRequestLocation") { jsonDataKeyboard["is_request_location"] = true; } // - if (raw_keyboard_data["@type"] == - "keyboardButtonTypeRequestPhoneNumber") { + if (raw_keyboard_data["@type"] == "keyboardButtonTypeRequestPhoneNumber") { jsonDataKeyboard["is_request_phone_number"] = true; } } @@ -3015,20 +2697,15 @@ class Tdlib extends TdlibNative { }; if (raw_keyboard_data["type"] is Map) { // https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_inline_keyboard_button_type.html - if (raw_keyboard_data["@type"] == - "inlineKeyboardButtonTypeCallback") { + if (raw_keyboard_data["@type"] == "inlineKeyboardButtonTypeCallback") { if (raw_keyboard_data["type"]["data"] is String) { - jsonDataKeyboard["callback_data"] = convert.utf8 - .decode(convert.base64 - .decode(raw_keyboard_data["type"]["data"])); + jsonDataKeyboard["callback_data"] = convert.utf8.decode(convert.base64.decode(raw_keyboard_data["type"]["data"])); } } // - if (raw_keyboard_data["@type"] == - "inlineKeyboardButtonTypeUrl") { + if (raw_keyboard_data["@type"] == "inlineKeyboardButtonTypeUrl") { if (raw_keyboard_data["type"]["url"] is String) { - jsonDataKeyboard["url"] = - raw_keyboard_data["type"]["url"]; + jsonDataKeyboard["url"] = raw_keyboard_data["type"]["url"]; } } } @@ -3129,14 +2806,12 @@ class Tdlib extends TdlibNative { } } } catch (e) {} - json["api_message_id"] = - TgUtils.messageTdlibToApi(update["message_id"]); + json["api_message_id"] = TgUtils.messageTdlibToApi(update["message_id"]); json["message_id"] = update["message_id"]; json["from"] = from; json["chat"] = chat; json["chat_instance"] = update["chat_instance"]; - json["data"] = convert.utf8 - .decode(convert.base64.decode(update["payload"]["data"])); + json["data"] = convert.utf8.decode(convert.base64.decode(update["payload"]["data"])); // json["data"] = Buffer.from(update["payload"]["data"], 'base64').toStringEncode('utf8'); return { "ok": true, @@ -3178,11 +2853,8 @@ class Tdlib extends TdlibNative { json["date"] = update["date"]; if (update["old_chat_member"]["@type"] == "chatMember") { Map json_new_member = {}; - if (update["old_chat_member"]["member_id"]["@type"] == - "messageSenderUser") { - Map json_data_user = { - "id": update["old_chat_member"]["member_id"]["user_id"] - }; + if (update["old_chat_member"]["member_id"]["@type"] == "messageSenderUser") { + Map json_data_user = {"id": update["old_chat_member"]["member_id"]["user_id"]}; if (is_super_detail) { try { var fromResult = await getUser( @@ -3199,21 +2871,14 @@ class Tdlib extends TdlibNative { json_new_member["user"] = json_data_user; } - json_new_member["status"] = update["old_chat_member"]["status"] - ["@type"] - .toString() - .replaceAll(RegExp(r"chatMemberStatus", caseSensitive: false), "") - .toLowerCase(); + json_new_member["status"] = update["old_chat_member"]["status"]["@type"].toString().replaceAll(RegExp(r"chatMemberStatus", caseSensitive: false), "").toLowerCase(); json["old_member"] = json_new_member; } if (update["new_chat_member"]["@type"] == "chatMember") { Map json_new_member = {}; - if (update["new_chat_member"]["member_id"]["@type"] == - "messageSenderUser") { - Map json_data_user = { - "id": update["new_chat_member"]["member_id"]["user_id"] - }; + if (update["new_chat_member"]["member_id"]["@type"] == "messageSenderUser") { + Map json_data_user = {"id": update["new_chat_member"]["member_id"]["user_id"]}; if (is_super_detail) { try { var fromResult = await getUser( @@ -3230,11 +2895,7 @@ class Tdlib extends TdlibNative { json_new_member["user"] = json_data_user; } - json_new_member["status"] = update["new_chat_member"]["status"] - ["@type"] - .toString() - .replaceAll(RegExp(r"chatMemberStatus", caseSensitive: false), "") - .toLowerCase(); + json_new_member["status"] = update["new_chat_member"]["status"]["@type"].toString().replaceAll(RegExp(r"chatMemberStatus", caseSensitive: false), "").toLowerCase(); json["new_member"] = json_new_member; } @@ -3260,13 +2921,9 @@ class Tdlib extends TdlibNative { } } catch (e) {} json["from"] = from; - json["chat_type"] = update["chat_type"]["@type"] - .toString() - .replaceAll(RegExp("chatType", caseSensitive: false), "") - .toLowerCase(); + json["chat_type"] = update["chat_type"]["@type"].toString().replaceAll(RegExp("chatType", caseSensitive: false), "").toLowerCase(); try { - if (json["chat_type"] == "supergroup" && - update["chat_type"]["is_channel"]) { + if (json["chat_type"] == "supergroup" && update["chat_type"]["is_channel"]) { json["chat_type"] = "channel"; } } catch (e) {} @@ -3315,8 +2972,7 @@ class Tdlib extends TdlibNative { var json = {}; json["id"] = get_user["id"]; try { - if (RegExp(r"^userTypeBot$", caseSensitive: false) - .hashData(get_user["type"]["@type"])) { + if (RegExp(r"^userTypeBot$", caseSensitive: false).hashData(get_user["type"]["@type"])) { json["is_bot"] = true; } else { json["is_bot"] = false; @@ -3337,8 +2993,7 @@ class Tdlib extends TdlibNative { json["usernames"] = get_user["usernames"]; if (get_user_usernames["active_usernames"] is List) { if ((get_user_usernames["active_usernames"] as List).isNotEmpty) { - json["username"] = - (get_user_usernames["active_usernames"] as List).first; + json["username"] = (get_user_usernames["active_usernames"] as List).first; } } } @@ -3349,27 +3004,7 @@ class Tdlib extends TdlibNative { json["language_code"] = get_user["language_code"]; } json["type"] = "private"; - json["detail"] = { - "has_protected_content": false, - "is_marked_as_unread": false, - "is_blocked": false, - "has_scheduled_messages": false, - "can_be_deleted_only_for_self": false, - "can_be_deleted_for_all_users": false, - "can_be_reported": false, - "default_disable_notification": false, - "unread_count": 0, - "last_read_inbox_message_id": 0, - "last_read_outbox_message_id": 0, - "unread_mention_count": 0, - "is_contact": get_user["is_contact"], - "is_mutual_contact": get_user["is_mutual_contact"], - "is_verified": get_user["is_verified"], - "is_support": get_user["is_support"], - "is_scam": get_user["is_scam"], - "is_fake": get_user["is_fake"], - "have_acces": get_user["have_access"] - }; + json["detail"] = {"has_protected_content": false, "is_marked_as_unread": false, "is_blocked": false, "has_scheduled_messages": false, "can_be_deleted_only_for_self": false, "can_be_deleted_for_all_users": false, "can_be_reported": false, "default_disable_notification": false, "unread_count": 0, "last_read_inbox_message_id": 0, "last_read_outbox_message_id": 0, "unread_mention_count": 0, "is_contact": get_user["is_contact"], "is_mutual_contact": get_user["is_mutual_contact"], "is_verified": get_user["is_verified"], "is_support": get_user["is_support"], "is_scam": get_user["is_scam"], "is_fake": get_user["is_fake"], "have_acces": get_user["have_access"]}; return {"ok": true, "result": json}; } get_user["ok"] = false; diff --git a/package/telegram_client/lib/tdlib/tdlib_library/base.dart b/package/telegram_client/lib/tdlib/tdlib_library/base.dart index 52004241..30b6d685 100644 --- a/package/telegram_client/lib/tdlib/tdlib_library/base.dart +++ b/package/telegram_client/lib/tdlib/tdlib_library/base.dart @@ -49,6 +49,10 @@ import 'package:telegram_client/tdlib/update_td.dart'; import 'package:universal_io/io.dart'; abstract class TdlibBaseCore { + Future is_td_initialized() async{ + return false; + } + /// create client id for multi client String platformType() { return "unknown"; @@ -114,11 +118,9 @@ abstract class TdlibBaseCore { /// abstract class TdlibBase implements TdlibBaseCore { final ReceivePort receivePort = ReceivePort(); - final TelegramClientLibraryTdlibOptionParameter client_option = - TelegramClientLibraryTdlibOptionParameter.create( + final TelegramClientLibraryTdlibOptionParameter client_option = TelegramClientLibraryTdlibOptionParameter.create( api_id: num.tryParse("OTQ1NzU=".general_lib_utils_decryptFromBase64()), - api_hash: 'YTM0MDZkZThkMTcxYmI0MjJiYjZkZGYzYmJkODAwZTI=' - .general_lib_utils_decryptFromBase64(), + api_hash: 'YTM0MDZkZThkMTcxYmI0MjJiYjZkZGYzYmJkODAwZTI='.general_lib_utils_decryptFromBase64(), database_directory: "tg_db", files_directory: "tg_file", use_file_database: true, @@ -129,8 +131,7 @@ abstract class TdlibBase implements TdlibBaseCore { system_language_code: 'en', new_verbosity_level: 0, application_version: 'v1', - device_model: 'VGVsZWdyYW0gQ2xpZW50IEFaS0FERVYgR0xPQkFMIENPUlBPUkFUSU9O' - .general_lib_utils_decryptFromBase64(), + device_model: 'VGVsZWdyYW0gQ2xpZW50IEFaS0FERVYgR0xPQkFMIENPUlBPUkFUSU9O'.general_lib_utils_decryptFromBase64(), system_version: Platform.operatingSystemVersion, database_key: "", start: true, @@ -157,12 +158,9 @@ abstract class TdlibBase implements TdlibBaseCore { Duration invoke_time_out = Duration(minutes: 10); double timeOutUpdate; bool is_invoke_throw_on_error = false; - FutureOr Function(dynamic update, TdlibBase libTdJson)? - on_receive_update; - FutureOr Function(int client_id, TdlibBase libTdJson)? - on_generate_extra_invoke; - FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? - on_get_invoke_data; + FutureOr Function(dynamic update, TdlibBase libTdJson)? on_receive_update; + FutureOr Function(int client_id, TdlibBase libTdJson)? on_generate_extra_invoke; + FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? on_get_invoke_data; int task_max_count; int task_min_cooldown; TdlibBase({ @@ -216,15 +214,12 @@ abstract class TdlibBase implements TdlibBaseCore { TdlibIsolateReceiveData tdlibIsolateReceiveData = update; try { if (tdlibIsolateReceiveData.updateData["@extra"] is String) { - event_emitter.emit( - eventName: event_invoke, value: tdlibIsolateReceiveData); + event_emitter.emit(eventName: event_invoke, value: tdlibIsolateReceiveData); } else { - event_emitter.emit( - eventName: event_update, value: tdlibIsolateReceiveData); + event_emitter.emit(eventName: event_update, value: tdlibIsolateReceiveData); } } catch (e) { - event_emitter.emit( - eventName: event_update, value: tdlibIsolateReceiveData); + event_emitter.emit(eventName: event_update, value: tdlibIsolateReceiveData); } } else if (update is TdlibIsolateReceiveDataError) { is_init_isolate = false; @@ -343,9 +338,7 @@ abstract class TdlibBase implements TdlibBaseCore { client_new_option[key] = value; } }); - final Map tdlib_option_should_not_empty_num = { - "api_id": client_option.api_id ?? 0 - }; + final Map tdlib_option_should_not_empty_num = {"api_id": client_option.api_id ?? 0}; tdlib_option_should_not_empty_num.forEach((key, value) { try { if (client_new_option[key] is num == false) { @@ -518,11 +511,8 @@ abstract class TdlibBase implements TdlibBaseCore { required String extra, required bool isAutoGetChat, required bool isInvokeThrowOnError, - required FutureOr Function(int client_id, TdlibBase libTdJson)? - onGenerateExtraInvoke, - required FutureOr Function( - String extra, int client_id, TdlibBase libTdJson)? - onGetInvokeData, + required FutureOr Function(int client_id, TdlibBase libTdJson)? onGenerateExtraInvoke, + required FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? onGetInvokeData, }) async { final Completer completer = Completer(); late final EventEmitterListener listener; @@ -544,8 +534,7 @@ abstract class TdlibBase implements TdlibBaseCore { if (extra.isEmpty) { parameters["@extra"] = extra; } else if (onGenerateExtraInvoke != null) { - parameters["@extra"] = - await onGenerateExtraInvoke(clientId, this); + parameters["@extra"] = await onGenerateExtraInvoke(clientId, this); } else { parameters["@extra"] = generateUuid(15); } @@ -558,9 +547,7 @@ abstract class TdlibBase implements TdlibBaseCore { return extra_procces; }(); - if (isAutoGetChat && - RegExp(r"^(sendMessage|getChatMember)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (isAutoGetChat && RegExp(r"^(sendMessage|getChatMember)$", caseSensitive: false).hashData(parameters["@type"])) { if (parameters["chat_id"] is int) { td_send(clientId, { "@type": "getChat", @@ -644,9 +631,7 @@ abstract class TdlibBase implements TdlibBaseCore { event_emitter.off(listener: listener); } catch (e) {} - if (result.isEmpty || - result["@type"] is String == false || - result["@type"] == "error") { + if (result.isEmpty || result["@type"] is String == false || result["@type"] == "error") { if (isInvokeThrowOnError) { result["@type"] = "error"; throw result; @@ -679,10 +664,8 @@ abstract class TdlibBase implements TdlibBaseCore { String? extra, bool? isAutoGetChat, bool? isInvokeThrowOnError, - FutureOr Function(int client_id, TdlibBase libTdJson)? - onGenerateExtraInvoke, - FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? - onGetInvokeData, + FutureOr Function(int client_id, TdlibBase libTdJson)? onGenerateExtraInvoke, + FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? onGetInvokeData, }) async { isUseCache ??= false; durationCacheExpire ??= Duration( @@ -724,10 +707,8 @@ abstract class TdlibBase implements TdlibBaseCore { bool? isUseCache, Duration? durationCacheExpire, bool? isAutoGetChat, - FutureOr Function(int client_id, TdlibBase libTdJson)? - onGenerateExtraInvoke, - FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? - onGetInvokeData, + FutureOr Function(int client_id, TdlibBase libTdJson)? onGenerateExtraInvoke, + FutureOr Function(String extra, int client_id, TdlibBase libTdJson)? onGetInvokeData, bool? isInvokeThrowOnError, }) async { return await invoke( diff --git a/package/telegram_client/lib/tdlib/tdlib_library/io.dart b/package/telegram_client/lib/tdlib/tdlib_library/io.dart index 71687ee0..e9ae4fc5 100644 --- a/package/telegram_client/lib/tdlib/tdlib_library/io.dart +++ b/package/telegram_client/lib/tdlib/tdlib_library/io.dart @@ -187,4 +187,9 @@ class TdlibNative extends TdlibBase { String platformType() { return "io"; } + + @override + Future is_td_initialized() async{ + return true; + } } diff --git a/package/telegram_client/lib/tdlib/tdlib_library/none.dart b/package/telegram_client/lib/tdlib/tdlib_library/none.dart index eccb6d8d..5a5f2dbf 100644 --- a/package/telegram_client/lib/tdlib/tdlib_library/none.dart +++ b/package/telegram_client/lib/tdlib/tdlib_library/none.dart @@ -74,7 +74,6 @@ class TdlibNative extends TdlibBase { super.task_min_cooldown, super.timeOutUpdate, }); - @override int td_create_client_id() { // TODO: implement td_create_client_id @@ -95,4 +94,9 @@ class TdlibNative extends TdlibBase { String platformType() { return "none"; } + + @override + Future is_td_initialized() async{ + return true; + } } diff --git a/package/telegram_client/lib/tdlib/tdlib_library/tdlib.dart b/package/telegram_client/lib/tdlib/tdlib_library/tdlib.dart index 30731346..09b5693d 100644 --- a/package/telegram_client/lib/tdlib/tdlib_library/tdlib.dart +++ b/package/telegram_client/lib/tdlib/tdlib_library/tdlib.dart @@ -34,7 +34,7 @@ Bukan maksud kami menipu itu karena harga yang sudah di kalkulasi + bantuan tiba export "base.dart"; export "none.dart" if (dart.library.io) 'io.dart' - if (dart.library.html) 'web.dart'; + if (dart.library.js_interop) 'web.dart'; // export 'tdlib_io.dart'; // // // export "tdlib_none.dart"; diff --git a/package/telegram_client/lib/tdlib/tdlib_library/web.dart b/package/telegram_client/lib/tdlib/tdlib_library/web.dart index 22f00489..435b7ee8 100644 --- a/package/telegram_client/lib/tdlib/tdlib_library/web.dart +++ b/package/telegram_client/lib/tdlib/tdlib_library/web.dart @@ -37,9 +37,10 @@ Bukan maksud kami menipu itu karena harga yang sudah di kalkulasi + bantuan tiba // import 'dart:ffi'; +import 'dart:async'; + import 'package:telegram_client/tdlib/tdlib_library/base.dart'; -import 'package:universal_io/io.dart'; -import 'package:wasm_ffi/ffi.dart'; +import 'package:wasm_ffi/ffi.dart'; typedef TdCharNative = Pointer; typedef TdReceiveNative = TdCharNative Function(Double timout); @@ -68,6 +69,7 @@ typedef TdExecuteNative = TdCharNative Function(TdCharNative parameters); /// ```` /// class TdlibNative extends TdlibBase { + static final Completer _td_completer = Completer(); TdlibNative({ super.clientOption, super.delayInvoke, @@ -86,20 +88,17 @@ class TdlibNative extends TdlibBase { super.task_min_cooldown, super.timeOutUpdate, }) { - opentdLib(pathTdlib: path_tdlib).then((a){ - - - if (client_option["start"] == true) { - invokeSync( - parameters: { - "@type": "setLogVerbosityLevel", - "new_verbosity_level": client_option['new_verbosity_level'], - }, - ); - ensureInitialized(); - } + opentdLib(pathTdlib: path_tdlib).then((a) { + if (client_option["start"] == true) { + invokeSync( + parameters: { + "@type": "setLogVerbosityLevel", + "new_verbosity_level": client_option['new_verbosity_level'], + }, + ); + ensureInitialized(); + } }); - } static late DynamicLibrary tdLib; static bool is_open_tdlib = false; @@ -129,6 +128,11 @@ class TdlibNative extends TdlibBase { String platformType() { return "web"; } + + @override + Future is_td_initialized() { + return _td_completer.future; + } } Future opentdLib({ @@ -138,14 +142,12 @@ Future opentdLib({ if (TdlibNative.is_open_tdlib) { return; } - if (Platform.isIOS || Platform.isMacOS) { - TdlibNative.tdLib = await DynamicLibrary.open(pathTdlib); - } else { - TdlibNative.tdLib = await DynamicLibrary.open(pathTdlib); - } + + TdlibNative.tdLib = await DynamicLibrary.open(pathTdlib); TdlibNative.is_open_tdlib = true; TdlibNative.td_execute_native_function = TdlibNative.tdLib.lookupFunction('td_execute'); TdlibNative.td_send_function = TdlibNative.tdLib.lookupFunction('td_send'); TdlibNative.td_pointer_native_function = TdlibNative.tdLib.lookupFunction('td_create_client_id'); TdlibNative.td_receive_function = TdlibNative.tdLib.lookupFunction('td_receive'); + TdlibNative._td_completer.complete(true); } diff --git a/package/telegram_client/lib/telegram_client/function/send_message_raw.dart b/package/telegram_client/lib/telegram_client/function/send_message_raw.dart index a59037da..7dc39ec8 100644 --- a/package/telegram_client/lib/telegram_client/function/send_message_raw.dart +++ b/package/telegram_client/lib/telegram_client/function/send_message_raw.dart @@ -49,16 +49,12 @@ extension SendMessageRawDataOn on TelegramClient { required TelegramClientCallApiInvoke callApiInvoke, required TelegramClientData telegramClientData, }) async { - final dynamic target_chat_id = - TgUtils.parse_all_chat_id(parameters: parameters); - if (target_chat_id is String && - RegExp(r"^((@)[a-z0-9_]+)$", caseSensitive: false) - .hashData(target_chat_id)) { + final dynamic target_chat_id = TgUtils.parse_all_chat_id(parameters: parameters); + if (target_chat_id is String && RegExp(r"^((@)[a-z0-9_]+)$", caseSensitive: false).hashData(target_chat_id)) { final Map search_public_chat = await callApiInvoke( parameters: { "@type": "searchPublicChat", - "username": (target_chat_id) - .replaceAll(RegExp(r"@", caseSensitive: false), ""), + "username": (target_chat_id).replaceAll(RegExp(r"@", caseSensitive: false), ""), }, is_invoke_no_relevance: true, ); @@ -85,8 +81,7 @@ extension SendMessageRawDataOn on TelegramClient { ]; for (var option_parameter in options_parameters) { if (parameters[option_parameter] is bool) { - request_parameters["options"][option_parameter] = - parameters[option_parameter]; + request_parameters["options"][option_parameter] = parameters[option_parameter]; } } final List input_message_content_parameters = [ @@ -95,19 +90,19 @@ extension SendMessageRawDataOn on TelegramClient { ]; for (var option_parameter in input_message_content_parameters) { if (parameters[option_parameter] is bool) { - request_parameters["input_message_content"][option_parameter] = - parameters[option_parameter]; + request_parameters["input_message_content"][option_parameter] = parameters[option_parameter]; } } if (parameters.containsKey("message_thread_id")) { - request_parameters["message_thread_id"] = - (parameters["message_thread_id"]); + request_parameters["message_thread_id"] = TgUtils.messageApiToTdlib(parameters["message_thread_id"]); + } + if (parameters.containsKey("message_tdlib_thread_id")) { + request_parameters["message_thread_id"] = parameters["message_tdlib_thread_id"]; } if (parameters.containsKey("message_id")) { - request_parameters["message_id"] = - TgUtils.messageApiToTdlib(parameters["message_id"]); + request_parameters["message_id"] = TgUtils.messageApiToTdlib(parameters["message_id"]); } if (parameters.containsKey("inline_message_id")) { request_parameters["inline_message_id"] = parameters["inline_message_id"]; @@ -116,8 +111,7 @@ extension SendMessageRawDataOn on TelegramClient { request_parameters["reply_to"] = { "@type": "inputMessageReplyToMessage", "chat_id": request_parameters["chat_id"], - "message_id": - TgUtils.messageApiToTdlib(parameters["reply_to_message_id"]), + "message_id": TgUtils.messageApiToTdlib(parameters["reply_to_message_id"]), }; } else if (parameters["reply_to_story_id"] is int) { request_parameters["reply_to"] = { @@ -130,8 +124,7 @@ extension SendMessageRawDataOn on TelegramClient { "@type": "formattedText", }; - if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false).hashData(parameters["@type"])) { formatted_text["text"] = parameters["text"]; } else { if (parameters["caption"] is String) { @@ -192,122 +185,91 @@ extension SendMessageRawDataOn on TelegramClient { // editMessageSchedulingState // editMessageText final String add_inline = () { - if (parameters["inline_message_id"] is String && - (parameters["inline_message_id"] as String).isNotEmpty) { + if (parameters["inline_message_id"] is String && (parameters["inline_message_id"] as String).isNotEmpty) { return "Inline"; } return ""; }(); - if (RegExp(r"^(editMessageCaption)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(editMessageCaption)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["@type"] = "edit${add_inline}MessageCaption"; } - if (RegExp(r"^(editMessageMedia)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(editMessageMedia)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["@type"] = "edit${add_inline}MessageMedia"; } - if (RegExp(r"^(editMessageReplyMarkup)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(editMessageReplyMarkup)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["@type"] = "edit${add_inline}MessageReplyMarkup"; } - if (RegExp(r"^(editMessageText)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(editMessageText)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["@type"] = "edit${add_inline}MessageText"; } - if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["input_message_content"]["@type"] = "inputMessageText"; if (parameters["clear_draft"] is bool) { - request_parameters["input_message_content"]["clear_draft"] = - parameters["clear_draft"]; + request_parameters["input_message_content"]["clear_draft"] = parameters["clear_draft"]; } if (formatted_text != null) { request_parameters["input_message_content"]["text"] = formatted_text; } } else { - if (RegExp(r"^(forwardMessage|copyMessage)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageForwarded"; - request_parameters["input_message_content"]["from_chat_id"] = - parameters["from_chat_id"]; - request_parameters["input_message_content"]["message_id"] = - TgUtils.messageApiToTdlib(parameters["message_id"]); + if (RegExp(r"^(forwardMessage|copyMessage)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageForwarded"; + request_parameters["input_message_content"]["from_chat_id"] = parameters["from_chat_id"]; + request_parameters["input_message_content"]["message_id"] = TgUtils.messageApiToTdlib(parameters["message_id"]); if (parameters["in_game_share"] is bool) { - request_parameters["input_message_content"]["in_game_share"] = - parameters["in_game_share"]; + request_parameters["input_message_content"]["in_game_share"] = parameters["in_game_share"]; } - if (RegExp(r"^(copyMessage)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(copyMessage)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["input_message_content"]["copy_options"] = { "@type": "messageCopyOptions", "send_copy": true, }; if (formatted_text != null) { - request_parameters["input_message_content"]["copy_options"] - ["replace_caption"] = true; - request_parameters["input_message_content"]["copy_options"] - ["new_caption"] = formatted_text; + request_parameters["input_message_content"]["copy_options"]["replace_caption"] = true; + request_parameters["input_message_content"]["copy_options"]["new_caption"] = formatted_text; } } } else { if (formatted_text != null) { - if (RegExp(r"^(editMessageCaption)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(editMessageCaption)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["caption"] = formatted_text; } else { - request_parameters["input_message_content"]["caption"] = - formatted_text; + request_parameters["input_message_content"]["caption"] = formatted_text; } } } - if (RegExp(r"^(sendAudio)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageAudio"; - request_parameters["input_message_content"]["audio"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendAudio)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageAudio"; + request_parameters["input_message_content"]["audio"] = (await TgUtils.typeFile( content: parameters["audio"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendPhoto)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessagePhoto"; - request_parameters["input_message_content"]["photo"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendPhoto)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessagePhoto"; + request_parameters["input_message_content"]["photo"] = (await TgUtils.typeFile( content: parameters["photo"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendAnimation)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageAnimation"; - request_parameters["input_message_content"]["animation"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendAnimation)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageAnimation"; + request_parameters["input_message_content"]["animation"] = (await TgUtils.typeFile( content: parameters["animation"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendDocument)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageDocument"; - request_parameters["input_message_content"]["document"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendDocument)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageDocument"; + request_parameters["input_message_content"]["document"] = (await TgUtils.typeFile( content: parameters["document"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendContact)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageContact"; + if (RegExp(r"^(sendContact)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageContact"; request_parameters["input_message_content"]["contact"] = { "@type": "contact", "latitude": parameters["latitude"], @@ -322,110 +284,83 @@ extension SendMessageRawDataOn on TelegramClient { ]; for (var contact_parameter in contact_parameters) { if (parameters.containsKey(contact_parameter)) { - request_parameters["input_message_content"]["contact"] - [contact_parameter] = parameters[contact_parameter]; + request_parameters["input_message_content"]["contact"][contact_parameter] = parameters[contact_parameter]; } } } - if (RegExp(r"^(sendVenue)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageVenue"; + if (RegExp(r"^(sendVenue)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageVenue"; request_parameters["input_message_content"]["venue"] = { "@type": "location", "latitude": parameters["latitude"], "longitude": parameters["longitude"], }; if (parameters.containsKey("horizontal_accuracy")) { - request_parameters["input_message_content"]["location"] - ["horizontal_accuracy"] = parameters["horizontal_accuracy"]; + request_parameters["input_message_content"]["location"]["horizontal_accuracy"] = parameters["horizontal_accuracy"]; } if (parameters.containsKey("live_period")) { - request_parameters["input_message_content"]["live_period"] = - parameters["live_period"]; + request_parameters["input_message_content"]["live_period"] = parameters["live_period"]; } if (parameters.containsKey("heading")) { - request_parameters["input_message_content"]["heading"] = - parameters["heading"]; + request_parameters["input_message_content"]["heading"] = parameters["heading"]; } if (parameters.containsKey("proximity_alert_radius")) { - request_parameters["input_message_content"] - ["proximity_alert_radius"] = parameters["proximity_alert_radius"]; + request_parameters["input_message_content"]["proximity_alert_radius"] = parameters["proximity_alert_radius"]; } } - if (RegExp(r"^(sendLocation)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageLocation"; + if (RegExp(r"^(sendLocation)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageLocation"; request_parameters["input_message_content"]["location"] = { "@type": "location", "latitude": parameters["latitude"], "longitude": parameters["longitude"], }; if (parameters.containsKey("horizontal_accuracy")) { - request_parameters["input_message_content"]["location"] - ["horizontal_accuracy"] = parameters["horizontal_accuracy"]; + request_parameters["input_message_content"]["location"]["horizontal_accuracy"] = parameters["horizontal_accuracy"]; } if (parameters.containsKey("live_period")) { - request_parameters["input_message_content"]["live_period"] = - parameters["live_period"]; + request_parameters["input_message_content"]["live_period"] = parameters["live_period"]; } if (parameters.containsKey("heading")) { - request_parameters["input_message_content"]["heading"] = - parameters["heading"]; + request_parameters["input_message_content"]["heading"] = parameters["heading"]; } if (parameters.containsKey("proximity_alert_radius")) { - request_parameters["input_message_content"] - ["proximity_alert_radius"] = parameters["proximity_alert_radius"]; + request_parameters["input_message_content"]["proximity_alert_radius"] = parameters["proximity_alert_radius"]; } } - if (RegExp(r"^(sendDice)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageDice"; - request_parameters["input_message_content"]["emoji"] = - parameters["emoji"]; + if (RegExp(r"^(sendDice)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageDice"; + request_parameters["input_message_content"]["emoji"] = parameters["emoji"]; if (parameters["clear_draft"] is bool) { - request_parameters["input_message_content"]["clear_draft"] = - parameters["clear_draft"]; + request_parameters["input_message_content"]["clear_draft"] = parameters["clear_draft"]; } } - if (RegExp(r"^(sendSticker)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageSticker"; - request_parameters["input_message_content"]["sticker"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendSticker)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageSticker"; + request_parameters["input_message_content"]["sticker"] = (await TgUtils.typeFile( content: parameters["sticker"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendVideo)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageVideo"; - request_parameters["input_message_content"]["video"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendVideo)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageVideo"; + request_parameters["input_message_content"]["video"] = (await TgUtils.typeFile( content: parameters["video"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendVoice)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageVoiceNote"; - request_parameters["input_message_content"]["voice_note"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendVoice)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageVoiceNote"; + request_parameters["input_message_content"]["voice_note"] = (await TgUtils.typeFile( content: parameters["voice"], directory_temp: directory_temp, )); } } if (parameters["reply_markup"] is Map) { - final Map? reply_markup = TgUtils.replyMarkupTgApiToTdlib( - replyMarkup: parameters["reply_markup"]); + final Map? reply_markup = TgUtils.replyMarkupTgApiToTdlib(replyMarkup: parameters["reply_markup"]); if (reply_markup != null) { request_parameters["reply_markup"] = reply_markup; } @@ -471,21 +406,16 @@ extension SendMessageRawDataOn on TelegramClient { final EventEmitterListener listen = on( event_name: event_update, onUpdate: (UpdateTelegramClient updateTelegramClient) async { - if (updateTelegramClient.telegramClientData.telegramClientType == - TelegramClientType.tdlib) { - if (updateTelegramClient.telegramClientData.tdlib_client_id != - telegramClientData.tdlib_client_id) { + if (updateTelegramClient.telegramClientData.telegramClientType == TelegramClientType.tdlib) { + if (updateTelegramClient.telegramClientData.tdlib_client_id != telegramClientData.tdlib_client_id) { return; } Map updateOrigin = updateTelegramClient.rawData; - if (!["updateMessageSendSucceeded", "updateMessageSendFailed"] - .contains(updateOrigin["@type"])) { + if (!["updateMessageSendSucceeded", "updateMessageSendFailed"].contains(updateOrigin["@type"])) { return; } - if (updateOrigin["message"] is Map && - updateOrigin["message"]["chat_id"] == message_send["chat_id"] && - updateOrigin["old_message_id"] == message_send["id"]) { + if (updateOrigin["message"] is Map && updateOrigin["message"]["chat_id"] == message_send["chat_id"] && updateOrigin["old_message_id"] == message_send["id"]) { if (updateOrigin["error"] is Map) { completer.complete(updateOrigin["error"]); // result = updateOrigin["error"]; @@ -537,16 +467,12 @@ extension SendMessageRawDataOn on TelegramClient { required TelegramClientCallApiInvoke callApiInvoke, required TelegramClientData telegramClientData, }) async { - final dynamic target_chat_id = - TgUtils.parse_all_chat_id(parameters: parameters); - if (target_chat_id is String && - RegExp(r"^((@)[a-z0-9_]+)$", caseSensitive: false) - .hashData(target_chat_id)) { + final dynamic target_chat_id = TgUtils.parse_all_chat_id(parameters: parameters); + if (target_chat_id is String && RegExp(r"^((@)[a-z0-9_]+)$", caseSensitive: false).hashData(target_chat_id)) { final Map search_public_chat = await callApiInvoke( parameters: { "@type": "searchPublicChat", - "username": (target_chat_id) - .replaceAll(RegExp(r"@", caseSensitive: false), ""), + "username": (target_chat_id).replaceAll(RegExp(r"@", caseSensitive: false), ""), }, is_invoke_no_relevance: true, ); @@ -571,8 +497,7 @@ extension SendMessageRawDataOn on TelegramClient { ]; for (var option_parameter in options_parameters) { if (parameters[option_parameter] is bool) { - request_parameters["options"][option_parameter] = - parameters[option_parameter]; + request_parameters["options"][option_parameter] = parameters[option_parameter]; } } @@ -585,19 +510,16 @@ extension SendMessageRawDataOn on TelegramClient { ]; for (var option_parameter in input_message_content_parameters) { if (parameters[option_parameter] is bool) { - request_parameters["input_message_content"][option_parameter] = - parameters[option_parameter]; + request_parameters["input_message_content"][option_parameter] = parameters[option_parameter]; } } if (parameters.containsKey("message_thread_id")) { - request_parameters["message_thread_id"] = - (parameters["message_thread_id"]); + request_parameters["message_thread_id"] = (parameters["message_thread_id"]); } if (parameters.containsKey("message_id")) { - request_parameters["message_id"] = - TgUtils.messageApiToTdlib(parameters["message_id"]); + request_parameters["message_id"] = TgUtils.messageApiToTdlib(parameters["message_id"]); } if (parameters.containsKey("inline_message_id")) { request_parameters["inline_message_id"] = parameters["inline_message_id"]; @@ -606,16 +528,14 @@ extension SendMessageRawDataOn on TelegramClient { request_parameters["reply_to"] = { "@type": "inputMessageReplyToMessage", "chat_id": request_parameters["chat_id"], - "message_id": - TgUtils.messageApiToTdlib(request_parameters["message_id"]), + "message_id": TgUtils.messageApiToTdlib(request_parameters["message_id"]), }; } else if (parameters["reply_to_story_id"] is int) {} Map? formatted_text = { "@type": "formattedText", }; - if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false).hashData(parameters["@type"])) { formatted_text["text"] = parameters["text"]; } else { if (parameters["caption"] is String) { @@ -658,8 +578,7 @@ extension SendMessageRawDataOn on TelegramClient { } } - if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false) - .hashData(parameters["@type"])) { + if (RegExp(r"^(sendMessage|editMessageText)$", caseSensitive: false).hashData(parameters["@type"])) { request_parameters["input_message_content"]["@type"] = "inputMessageText"; if (formatted_text != null) { @@ -669,81 +588,59 @@ extension SendMessageRawDataOn on TelegramClient { if (formatted_text != null) { request_parameters["input_message_content"]["caption"] = formatted_text; } - if (RegExp(r"^(sendAudio)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageAudio"; - request_parameters["input_message_content"]["audio"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendAudio)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageAudio"; + request_parameters["input_message_content"]["audio"] = (await TgUtils.typeFile( content: parameters["audio"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendPhoto)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessagePhoto"; - request_parameters["input_message_content"]["photo"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendPhoto)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessagePhoto"; + request_parameters["input_message_content"]["photo"] = (await TgUtils.typeFile( content: parameters["photo"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendAnimation)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageAnimation"; - request_parameters["input_message_content"]["animation"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendAnimation)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageAnimation"; + request_parameters["input_message_content"]["animation"] = (await TgUtils.typeFile( content: parameters["animation"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendDocument)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageDocument"; - request_parameters["input_message_content"]["document"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendDocument)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageDocument"; + request_parameters["input_message_content"]["document"] = (await TgUtils.typeFile( content: parameters["document"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendSticker)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageSticker"; - request_parameters["input_message_content"]["sticker"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendSticker)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageSticker"; + request_parameters["input_message_content"]["sticker"] = (await TgUtils.typeFile( content: parameters["sticker"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendVideo)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageVideo"; - request_parameters["input_message_content"]["video"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendVideo)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageVideo"; + request_parameters["input_message_content"]["video"] = (await TgUtils.typeFile( content: parameters["video"], directory_temp: directory_temp, )); } - if (RegExp(r"^(sendVoice)$", caseSensitive: false) - .hashData(parameters["@type"])) { - request_parameters["input_message_content"]["@type"] = - "inputMessageVoiceNote"; - request_parameters["input_message_content"]["voice_note"] = - (await TgUtils.typeFile( + if (RegExp(r"^(sendVoice)$", caseSensitive: false).hashData(parameters["@type"])) { + request_parameters["input_message_content"]["@type"] = "inputMessageVoiceNote"; + request_parameters["input_message_content"]["voice_note"] = (await TgUtils.typeFile( content: parameters["voice"], directory_temp: directory_temp, )); } } if (parameters["reply_markup"] is Map) { - final Map? reply_markup = TgUtils.replyMarkupTgApiToTdlib( - replyMarkup: parameters["reply_markup"]); + final Map? reply_markup = TgUtils.replyMarkupTgApiToTdlib(replyMarkup: parameters["reply_markup"]); if (reply_markup != null) { request_parameters["reply_markup"] = reply_markup; } @@ -773,21 +670,16 @@ extension SendMessageRawDataOn on TelegramClient { final EventEmitterListener listen = on( event_name: event_update, onUpdate: (UpdateTelegramClient updateTelegramClient) async { - if (updateTelegramClient.telegramClientData.telegramClientType == - TelegramClientType.tdlib) { - if (updateTelegramClient.telegramClientData.tdlib_client_id != - telegramClientData.tdlib_client_id) { + if (updateTelegramClient.telegramClientData.telegramClientType == TelegramClientType.tdlib) { + if (updateTelegramClient.telegramClientData.tdlib_client_id != telegramClientData.tdlib_client_id) { return; } Map updateOrigin = updateTelegramClient.rawData; - if (!["updateMessageSendSucceeded", "updateMessageSendFailed"] - .contains(updateOrigin["@type"])) { + if (!["updateMessageSendSucceeded", "updateMessageSendFailed"].contains(updateOrigin["@type"])) { return; } - if (updateOrigin["message"] is Map && - updateOrigin["message"]["chat_id"] == message_send["chat_id"] && - updateOrigin["old_message_id"] == message_send["id"]) { + if (updateOrigin["message"] is Map && updateOrigin["message"]["chat_id"] == message_send["chat_id"] && updateOrigin["old_message_id"] == message_send["id"]) { // result = updateOrigin; completer.complete(updateOrigin); } diff --git a/package/telegram_client/lib/telegram_client/update/message.dart b/package/telegram_client/lib/telegram_client/update/message.dart index 609782d3..d16603c0 100644 --- a/package/telegram_client/lib/telegram_client/update/message.dart +++ b/package/telegram_client/lib/telegram_client/update/message.dart @@ -51,10 +51,10 @@ extension MessageDataDataOn on TelegramClient { // message.printPretty(2); final Map message_thread_json = {}; // message.printPretty(2); - if (message["message_thread_id"] is int && - message["message_thread_id"] > 0) { + if (message["message_thread_id"] is num && message["message_thread_id"] > 0) { if (message["is_topic_message"] == true) { - message_thread_json["message_thread_id"] = message["message_thread_id"]; + message_thread_json["message_tdlib_thread_id"] = message["message_thread_id"]; + message_thread_json["message_thread_id"] = TgUtils.messageTdlibToApi(message["message_thread_id"]); } } final Map message_from_json = {}; @@ -90,8 +90,7 @@ extension MessageDataDataOn on TelegramClient { if (message["sender_id"]["@type"] == "messageSenderChat") { message_sender_chat_json["sender_chat"] = {}; if (message["sender_id"]["chat_id"] is int) { - message_sender_chat_json["sender_chat"]["id"] = - message["sender_id"]["chat_id"]; + message_sender_chat_json["sender_chat"]["id"] = message["sender_id"]["chat_id"]; if (is_lite) { } else { final Map res = await request( @@ -133,8 +132,7 @@ extension MessageDataDataOn on TelegramClient { } if (message["is_channel_post"] != true) { if (message_sender_chat_json["sender_chat"] is Map) { - if (message["chat_id"] == - message_sender_chat_json["sender_chat"]["id"]) { + if (message["chat_id"] == message_sender_chat_json["sender_chat"]["id"]) { message_from_json["from"] = { "id": 1087968824, "is_bot": true, @@ -156,16 +154,14 @@ extension MessageDataDataOn on TelegramClient { } catch (e) {} } } else { - message_from_json["from"] = - message_sender_chat_json["sender_chat"] as Map; + message_from_json["from"] = message_sender_chat_json["sender_chat"] as Map; } } } if (telegramClientData.is_bot == false) { if ((message_from_json["from"] is Map)) { - (message_from_json["from"] as Map) - .removeWhere((key, value) => key == "phone_number"); + (message_from_json["from"] as Map).removeWhere((key, value) => key == "phone_number"); } message_chat_json.removeWhere((key, value) => key == "phone_number"); } @@ -192,8 +188,7 @@ extension MessageDataDataOn on TelegramClient { if (is_skip_reply_message == false) { if (message["reply_to"]["@type"] == "messageReplyToMessage") { final int message_reply_to_chat_id = message["reply_to"]["chat_id"]; - final int message_reply_to_message_id = - message["reply_to"]["message_id"]; + final int message_reply_to_message_id = message["reply_to"]["message_id"]; if (message_reply_to_message_id > 0) { try { final Map message_reply_to = await invoke( @@ -238,8 +233,7 @@ extension MessageDataDataOn on TelegramClient { }); } - if (message["author_signature"] is String && - (message["author_signature"] as String).isNotEmpty) { + if (message["author_signature"] is String && (message["author_signature"] as String).isNotEmpty) { msg["author_signature"] = message["author_signature"]; } @@ -301,8 +295,7 @@ extension MessageDataDataOn on TelegramClient { } if (message_content["caption"] is Map) { - if (message_content["caption"]["text"] is String && - (message_content["caption"]["text"] as String).isNotEmpty) { + if (message_content["caption"]["text"] is String && (message_content["caption"]["text"] as String).isNotEmpty) { msg["caption"] = message_content["caption"]["text"]; } if (message["content"]["caption"]["entities"] is List) { @@ -331,15 +324,12 @@ extension MessageDataDataOn on TelegramClient { animation["id"] = message_animation["id"]; if (message_animation["local"] is Map) { animation["file_path"] = message_animation["local"]["path"]; - animation["is_downloading_active"] = - message_animation["local"]["is_downloading_active"]; - animation["is_downloading_completed"] = - message_animation["local"]["is_downloading_completed"]; + animation["is_downloading_active"] = message_animation["local"]["is_downloading_active"]; + animation["is_downloading_completed"] = message_animation["local"]["is_downloading_completed"]; } if (message_animation["remote"] is Map) { animation["file_id"] = message_animation["remote"]["id"]; - animation["file_unique_id"] = - message_animation["remote"]["unique_id"]; + animation["file_unique_id"] = message_animation["remote"]["unique_id"]; animation["file_size"] = message_animation["remote"]["size"]; } } @@ -369,15 +359,12 @@ extension MessageDataDataOn on TelegramClient { jsonDataPhoto["id"] = message_photo["id"]; if (message_photo["local"] is Map) { jsonDataPhoto["file_path"] = message_photo["local"]["path"]; - jsonDataPhoto["is_downloading_active"] = - message_photo["local"]["is_downloading_active"]; - jsonDataPhoto["is_downloading_completed"] = - message_photo["local"]["is_downloading_completed"]; + jsonDataPhoto["is_downloading_active"] = message_photo["local"]["is_downloading_active"]; + jsonDataPhoto["is_downloading_completed"] = message_photo["local"]["is_downloading_completed"]; } if (message_photo["remote"] is Map) { jsonDataPhoto["file_id"] = message_photo["remote"]["id"]; - jsonDataPhoto["file_unique_id"] = - message_photo["remote"]["unique_id"]; + jsonDataPhoto["file_unique_id"] = message_photo["remote"]["unique_id"]; jsonDataPhoto["file_size"] = message_photo["remote"]["size"]; } photos.add(jsonDataPhoto); @@ -399,17 +386,12 @@ extension MessageDataDataOn on TelegramClient { jsonVideo["file_name"] = contentVideo["file_name"]; jsonVideo["mime_type"] = contentVideo["mime_type"]; try { - if (message["content"]["video"]["thumbnail"] is Map && - message["content"]["video"]["thumbnail"]["@type"] - .toString() - .toLowerCase() == - "thumbnail") { + if (message["content"]["video"]["thumbnail"] is Map && message["content"]["video"]["thumbnail"]["@type"].toString().toLowerCase() == "thumbnail") { final Map contentThumb = contentVideo["thumbnail"]; final Map jsonThumb = {}; jsonVideo["thumb"] = jsonThumb; jsonThumb["file_id"] = contentThumb["file"]["remote"]["id"]; - jsonThumb["file_unique_id"] = - contentThumb["file"]["remote"]["unique_id"]; + jsonThumb["file_unique_id"] = contentThumb["file"]["remote"]["unique_id"]; jsonThumb["file_size"] = contentThumb["file"]["size"]; jsonThumb["width"] = contentThumb["width"]; jsonThumb["height"] = contentThumb["height"]; @@ -432,16 +414,12 @@ extension MessageDataDataOn on TelegramClient { final Map contentUpdate = message["content"][contentType]; jsonContent["id"] = contentUpdate[contentType]["id"]; - jsonContent["file_path"] = - contentUpdate[contentType]["local"]["path"]; - jsonContent["is_downloading_active"] = - contentUpdate[contentType]["local"]["is_downloading_active"]; - jsonContent["is_downloading_completed"] = - contentUpdate[contentType]["local"]["is_downloading_completed"]; + jsonContent["file_path"] = contentUpdate[contentType]["local"]["path"]; + jsonContent["is_downloading_active"] = contentUpdate[contentType]["local"]["is_downloading_active"]; + jsonContent["is_downloading_completed"] = contentUpdate[contentType]["local"]["is_downloading_completed"]; jsonContent["file_id"] = contentUpdate[contentType]["remote"]["id"]; - jsonContent["file_unique_id"] = - contentUpdate[contentType]["remote"]["unique_id"]; + jsonContent["file_unique_id"] = contentUpdate[contentType]["remote"]["unique_id"]; jsonContent["duration"] = contentUpdate["duration"]; jsonContent["performer"] = contentUpdate["performer"]; jsonContent["file_name"] = contentUpdate["file_name"]; @@ -481,10 +459,8 @@ extension MessageDataDataOn on TelegramClient { jsonContent["id"] = contentUpdate["id"]; jsonContent["question"] = contentUpdate["question"]; jsonContent["options"] = contentUpdate["options"]; - jsonContent["total_voter_count"] = - contentUpdate["total_voter_count"]; - jsonContent["recent_voter_user_ids"] = - contentUpdate["recent_voter_user_ids"]; + jsonContent["total_voter_count"] = contentUpdate["total_voter_count"]; + jsonContent["recent_voter_user_ids"] = contentUpdate["recent_voter_user_ids"]; jsonContent["is_anonymous"] = contentUpdate["is_anonymous"]; jsonContent["type"] = contentUpdate["type"]; jsonContent["open_period"] = contentUpdate["open_period"]; @@ -506,8 +482,7 @@ extension MessageDataDataOn on TelegramClient { jsonContent["mime_type"] = contentUpdate["mime_type"]; jsonContent["file_id"] = contentUpdate[contentType]["remote"]["id"]; - jsonContent["unique_id"] = - contentUpdate[contentType]["remote"]["unique_id"]; + jsonContent["unique_id"] = contentUpdate[contentType]["remote"]["unique_id"]; jsonContent["file_size"] = contentUpdate[contentType]["size"]; msg[contentType] = jsonContent; } @@ -527,8 +502,7 @@ extension MessageDataDataOn on TelegramClient { final Map res = await invoke( parameters: { "@type": "getStickerSet", - "set_id": int.tryParse(contentUpdate["set_id"]) ?? - contentUpdate["set_id"], + "set_id": int.tryParse(contentUpdate["set_id"]) ?? contentUpdate["set_id"], }, isUseCache: isUseCache, durationCacheExpire: durationCacheExpire, @@ -546,16 +520,11 @@ extension MessageDataDataOn on TelegramClient { jsonContent["is_mask"] = contentUpdate["is_mask"]; try { - if (message["content"][contentType]["thumbnail"] is Map && - message["content"][contentType]["thumbnail"]["@type"] - .toString() - .toLowerCase() == - "thumbnail") { + if (message["content"][contentType]["thumbnail"] is Map && message["content"][contentType]["thumbnail"]["@type"].toString().toLowerCase() == "thumbnail") { final Map contentThumb = contentUpdate["thumbnail"]; final Map jsonThumb = {}; jsonThumb["file_id"] = contentThumb["file"]["remote"]["id"]; - jsonThumb["file_unique_id"] = - contentThumb["file"]["remote"]["unique_id"]; + jsonThumb["file_unique_id"] = contentThumb["file"]["remote"]["unique_id"]; jsonThumb["file_size"] = contentThumb["file"]["size"]; jsonThumb["width"] = contentThumb["width"]; jsonThumb["height"] = contentThumb["height"]; @@ -564,8 +533,7 @@ extension MessageDataDataOn on TelegramClient { } catch (e) {} jsonContent["file_id"] = contentUpdate[contentType]["remote"]["id"]; - jsonContent["file_unique_id"] = - contentUpdate[contentType]["remote"]["unique_id"]; + jsonContent["file_unique_id"] = contentUpdate[contentType]["remote"]["unique_id"]; jsonContent["file_size"] = contentUpdate[contentType]["size"]; msg[contentType] = jsonContent; } @@ -585,8 +553,7 @@ extension MessageDataDataOn on TelegramClient { jsonContent["mime_type"] = contentUpdate["mime_type"]; jsonContent["file_id"] = contentUpdate["voice"]["remote"]["id"]; - jsonContent["unique_id"] = - contentUpdate["voice"]["remote"]["unique_id"]; + jsonContent["unique_id"] = contentUpdate["voice"]["remote"]["unique_id"]; jsonContent["file_size"] = contentUpdate["voice"]["size"]; msg["voice"] = jsonContent; } @@ -651,25 +618,14 @@ extension MessageDataDataOn on TelegramClient { 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"); + 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) { + if (typeEntities == "text_mention" && dataEntities["type"]["user_id"] != null) { final int entitiesUserId = dataEntities["type"]["user_id"]; - Map fromJson = { - "id": entitiesUserId - }; + Map fromJson = {"id": entitiesUserId}; if (is_lite) { } else { try { @@ -728,19 +684,12 @@ extension MessageDataDataOn on TelegramClient { if (message["is_channel_post"] == true) { chat_type = "channel"; } - if (chat_type.isNotEmpty && - updataOptionTelegramClient - .updataMessageTelegramClient.skip_old_chat_types - .contains(chat_type)) { - final DateTime dateTime = - DateTime.now().copyWith(microsecond: 0, millisecond: 0); - final DateTime dateTimeMessage = - DateTime.fromMillisecondsSinceEpoch((message["date"] * 1000)); + if (chat_type.isNotEmpty && updataOptionTelegramClient.updataMessageTelegramClient.skip_old_chat_types.contains(chat_type)) { + final DateTime dateTime = DateTime.now().copyWith(microsecond: 0, millisecond: 0); + final DateTime dateTimeMessage = DateTime.fromMillisecondsSinceEpoch((message["date"] * 1000)); final Duration duration = dateTime.difference(dateTimeMessage); - if (duration > - updataOptionTelegramClient - .updataMessageTelegramClient.duration_old_message_skip) { + if (duration > updataOptionTelegramClient.updataMessageTelegramClient.duration_old_message_skip) { return true; } } @@ -749,16 +698,14 @@ extension MessageDataDataOn on TelegramClient { // check user if (telegramClientData.is_bot == false) { - if (updataOptionTelegramClient - .updataMessageTelegramClient.user_is_skip_old_message) { + if (updataOptionTelegramClient.updataMessageTelegramClient.user_is_skip_old_message) { final bool is_skip_update = isSkipUpdate(); if (is_skip_update) { return null; } } } else { - if (updataOptionTelegramClient - .updataMessageTelegramClient.bot_is_skip_old_message) { + if (updataOptionTelegramClient.updataMessageTelegramClient.bot_is_skip_old_message) { final bool is_skip_update = isSkipUpdate(); if (is_skip_update) { return null; diff --git a/package/telegram_client/pubspec.yaml b/package/telegram_client/pubspec.yaml index 4173d9bd..13502013 100644 --- a/package/telegram_client/pubspec.yaml +++ b/package/telegram_client/pubspec.yaml @@ -32,7 +32,6 @@ dependencies: http: '>=1.1.2 <=2.1.2' path: '^1.9.0' universal_io: '^2.2.2' - # web_ffi: '^0.7.2' mason_logger: '^0.3.1' mime: '^1.0.5' general_lib: '^0.0.46' @@ -40,8 +39,8 @@ dependencies: server_universe: '^0.0.22' yaml: '^3.1.2' yaml_writer: '^2.0.0' - js: "^0.6.7" - wasm_ffi: ^1.0.2 + js: '^0.6.7' + wasm_ffi: '^1.0.2' screenshots: - description: 'Telegram Logo' path: 'assets/telegram.png'