From d5b4c57993af179aa9cdb98a5ae44d5eefb84e1b Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 22 Jun 2020 02:02:21 +0300 Subject: [PATCH] Add inputMessageDocument.force_file. GitOrigin-RevId: 7f2780ba7f333e5f8df9c28bab429b8b12eaf26c --- td/generate/scheme/td_api.tl | 4 +-- td/generate/scheme/td_api.tlo | Bin 174580 -> 174616 bytes td/generate/scheme/telegram_api.tl | 2 +- td/generate/scheme/telegram_api.tlo | Bin 206580 -> 206624 bytes td/telegram/AnimationsManager.cpp | 4 +-- td/telegram/AudiosManager.cpp | 4 +-- td/telegram/DocumentsManager.cpp | 7 ++++-- td/telegram/MessageContent.cpp | 5 ++-- td/telegram/MessagesManager.cpp | 1 + td/telegram/StickersManager.cpp | 4 +-- td/telegram/VideoNotesManager.cpp | 4 +-- td/telegram/VideosManager.cpp | 4 +-- td/telegram/VoiceNotesManager.cpp | 2 +- td/telegram/cli.cpp | 35 +++++++++++++------------- td/telegram/files/FileDownloader.cpp | 9 ++++--- td/telegram/files/FileGcWorker.cpp | 2 ++ td/telegram/files/FileLocation.h | 1 + td/telegram/files/FileLocation.hpp | 1 + td/telegram/files/FileManager.cpp | 6 +++-- td/telegram/files/FileStats.cpp | 12 +++++++++ td/telegram/files/FileStatsWorker.cpp | 2 +- td/telegram/files/FileType.h | 5 ++++ td/telegram/net/NetStatsManager.cpp | 14 ++++++++--- test/tdclient.cpp | 4 +-- 24 files changed, 84 insertions(+), 48 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7af77bff0..7fba3f002 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1644,8 +1644,8 @@ inputMessageAnimation animation:InputFile thumbnail:inputThumbnail added_sticker //@performer Performer of the audio; 0-64 characters, may be replaced by the server @caption Audio caption; 0-GetOption("message_caption_length_max") characters inputMessageAudio audio:InputFile album_cover_thumbnail:inputThumbnail duration:int32 title:string performer:string caption:formattedText = InputMessageContent; -//@description A document message (general file) @document Document to be sent @thumbnail Document thumbnail, if available @caption Document caption; 0-GetOption("message_caption_length_max") characters -inputMessageDocument document:InputFile thumbnail:inputThumbnail caption:formattedText = InputMessageContent; +//@description A document message (general file) @document Document to be sent @thumbnail Document thumbnail, if available @force_file If true, automatic file type detection will be disabled and the document will be always sent as file. Always true for files sent to secret chats @caption Document caption; 0-GetOption("message_caption_length_max") characters +inputMessageDocument document:InputFile thumbnail:inputThumbnail force_file:Bool caption:formattedText = InputMessageContent; //@description A photo message @photo Photo to send @thumbnail Photo thumbnail to be sent, this is sent to the other party in secret chats only @added_sticker_file_ids File identifiers of the stickers added to the photo, if applicable @width Photo width @height Photo height @caption Photo caption; 0-GetOption("message_caption_length_max") characters //@ttl Photo TTL (Time To Live), in seconds (0-60). A non-zero TTL can be specified only in private chats diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 36d67a4a1da940cf84056c3a2c4fa06517965d11..199519af4415a753fda7a4a5c1016fda62f70ad6 100644 GIT binary patch delta 711 zcmexznQO)st_=l3EU!2gypp{-ObC5P_7@<@MI40c+dSb=0FpS%kv&MfCr5b@yvZWRC7{L~?|?A&9M|9k zIs4`@As_bX8^1HEPu_4&W3t2971ITb7zHM8I3)s6$a7K!u8?i=LL>3X0VmIhfV46| z!Bsh~nCo&^OC}qfl7K5^nH+e^pOY&szbH91J}q;4;x|U=$uWObAcmee1z~Lda7qN~ zOpY^9IfFA(po*X(n?IaMfhvkPhj2B^^odD8GdWI}OrCI3W%8M+Q2i?BH6Z!}&d-4` zKEOm|E<`{?DlR}3FSuX;5xD{r`2!O%xCm7faWMpgypp{-ObC5P_7@<@MI40c+dSb=0FpS%kv&MfCr5b@yvZWRC7{L~?|?A&9M|9k zIs4`@As_b18&^qB|L~oWXYz+FER!A1o|*jSyb44e&q)=yI=0CRjl?GhoIE1}(#Ze? zSLL{3)_A`#pKNdnV#)M|LPmwjIj2kzro1_YFok`3U?-C@#HQ0PAhzh7LCCXAPJE<3 zx#3I(MCuKa6z62d|Kghs&U!$-R&!1RqG-jrIS_`&d4#uEraLAxN>AoEAu##RIhE-b zUNfp7TqJS8_{#W2nH3!L(>H!#l;3V4$z;QbEHFcg$p?~drUMl#Z0C?=5 stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; +inputMediaUploadedDocument#5b38c6c1 flags:# nosound_video:flags.3?true force_file:flags.4?true file:InputFile thumb:flags.2?InputFile mime_type:string attributes:Vector stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; inputMediaDocument#23ab23d2 flags:# id:InputDocument ttl_seconds:flags.0?int = InputMedia; inputMediaVenue#c13d1c11 geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string = InputMedia; inputMediaPhotoExternal#e5bbfe1a flags:# url:string ttl_seconds:flags.0?int = InputMedia; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index a15fad90f0809124f20cd879c5e469858f9fb9ef..460aca001c1d7cbf4912f6b696925a6e360be050 100644 GIT binary patch delta 58 zcmV-A0LB0G%?zN<46yjillagqlO)VA3kqg$a${v*W@&6?ldn@ElU<I{*Lx delta 30 ocmV+(0O9|j&J6U;46yjiljNo>lO)VAgMiG3fXo56fXo7*S`3*GSpWb4 diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index dd029c82d..0d3263906 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -381,8 +381,8 @@ tl_object_ptr AnimationsManager::get_input_media( flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK; } return make_tl_object( - flags, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, std::move(attributes), - vector>(), 0); + flags, false /*ignored*/, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, + std::move(attributes), vector>(), 0); } else { CHECK(!file_view.has_remote_location()); } diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index c7a64031a..dd0bc539f 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -253,8 +253,8 @@ tl_object_ptr AudiosManager::get_input_media( flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK; } return make_tl_object( - flags, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, std::move(attributes), - vector>(), 0); + flags, false /*ignored*/, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, + std::move(attributes), vector>(), 0); } else { CHECK(!file_view.has_remote_location()); } diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 0c632cfcd..3e52e2d8b 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -599,9 +599,12 @@ tl_object_ptr DocumentsManager::get_input_media( if (input_thumbnail != nullptr) { flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK; } + if (file_view.get_type() == FileType::DocumentAsFile) { + flags |= telegram_api::inputMediaUploadedDocument::FORCE_FILE_MASK; + } return make_tl_object( - flags, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), document->mime_type, - std::move(attributes), vector>(), 0); + flags, false /*ignored*/, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), + document->mime_type, std::move(attributes), vector>(), 0); } else { CHECK(!file_view.has_remote_location()); } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 262c7f44f..e7f4a2dda 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -1855,8 +1855,9 @@ Result get_input_message_content( } case td_api::inputMessageDocument::ID: { auto input_message = static_cast(input_message_content.get()); - r_file_id = td->file_manager_->get_input_file_id(FileType::Document, input_message->document_, dialog_id, false, - is_secret, true); + auto file_type = input_message->force_file_ ? FileType::DocumentAsFile : FileType::Document; + r_file_id = + td->file_manager_->get_input_file_id(file_type, input_message->document_, dialog_id, false, is_secret, true); input_thumbnail = std::move(input_message->thumbnail_); break; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a0621d141..e77030f54 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -29774,6 +29774,7 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me case FileType::Animation: case FileType::Audio: case FileType::Document: + case FileType::DocumentAsFile: case FileType::Sticker: case FileType::Video: case FileType::VideoNote: diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 5a1384efd..c5247bb80 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -2103,8 +2103,8 @@ tl_object_ptr StickersManager::get_input_media( } } return make_tl_object( - flags, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, std::move(attributes), - vector>(), 0); + flags, false /*ignored*/, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, + std::move(attributes), vector>(), 0); } else { CHECK(!file_view.has_remote_location()); } diff --git a/td/telegram/VideoNotesManager.cpp b/td/telegram/VideoNotesManager.cpp index a7a80748b..1e525b067 100644 --- a/td/telegram/VideoNotesManager.cpp +++ b/td/telegram/VideoNotesManager.cpp @@ -223,8 +223,8 @@ tl_object_ptr VideoNotesManager::get_input_media( flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK; } return make_tl_object( - flags, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), "video/mp4", std::move(attributes), - vector>(), 0); + flags, false /*ignored*/, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), "video/mp4", + std::move(attributes), vector>(), 0); } else { CHECK(!file_view.has_remote_location()); } diff --git a/td/telegram/VideosManager.cpp b/td/telegram/VideosManager.cpp index 01e623faf..0d1eb65ce 100644 --- a/td/telegram/VideosManager.cpp +++ b/td/telegram/VideosManager.cpp @@ -299,8 +299,8 @@ tl_object_ptr VideosManager::get_input_media( flags |= telegram_api::inputMediaUploadedDocument::THUMB_MASK; } return make_tl_object( - flags, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, std::move(attributes), - std::move(added_stickers), ttl); + flags, false /*ignored*/, false /*ignored*/, std::move(input_file), std::move(input_thumbnail), mime_type, + std::move(attributes), std::move(added_stickers), ttl); } else { CHECK(!file_view.has_remote_location()); } diff --git a/td/telegram/VoiceNotesManager.cpp b/td/telegram/VoiceNotesManager.cpp index 7ba0f8d7b..59711ce43 100644 --- a/td/telegram/VoiceNotesManager.cpp +++ b/td/telegram/VoiceNotesManager.cpp @@ -192,7 +192,7 @@ tl_object_ptr VoiceNotesManager::get_input_media( mime_type = "audio/ogg"; } return make_tl_object( - 0, false /*ignored*/, std::move(input_file), nullptr, mime_type, std::move(attributes), + 0, false /*ignored*/, false /*ignored*/, std::move(input_file), nullptr, mime_type, std::move(attributes), vector>(), 0); } else { CHECK(!file_view.has_remote_location()); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index dbe998dce..a5d98a94f 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2991,7 +2991,7 @@ class CliClient final : public Actor { std::tie(message_id, document) = split(args); send_request(td_api::make_object( as_chat_id(chat_id), as_message_id(message_id), nullptr, - td_api::make_object(as_input_file(document), nullptr, as_caption("")))); + td_api::make_object(as_input_file(document), nullptr, false, as_caption("")))); } else if (op == "emp") { string chat_id; string message_id; @@ -3188,22 +3188,22 @@ class CliClient final : public Actor { std::tie(chat_id, emoji) = split(args); send_message(chat_id, td_api::make_object(emoji, op == "sdicecd")); - } else if (op == "sd") { + } else if (op == "sd" || op == "sdf") { string chat_id; string document_path; std::tie(chat_id, document_path) = split(args); send_message(chat_id, td_api::make_object( - as_input_file(document_path), nullptr, + as_input_file(document_path), nullptr, op == "sdf", as_caption(u8"\u1680\u180Etest \u180E\n\u180E\n\u180E\n cap\ttion\u180E\u180E"))); - } else if (op == "sdt") { + } else if (op == "sdt" || op == "sdtf") { string chat_id; string document_path; string thumbnail_path; std::tie(chat_id, args) = split(args); std::tie(document_path, thumbnail_path) = split(args); - send_message(chat_id, - td_api::make_object( - as_input_file(document_path), as_input_thumbnail(thumbnail_path), as_caption("test caption"))); + send_message(chat_id, td_api::make_object( + as_input_file(document_path), as_input_thumbnail(thumbnail_path), op == "sdtf", + as_caption("test caption"))); } else if (op == "sdg" || op == "sdgu") { string chat_id; string document_path; @@ -3214,9 +3214,9 @@ class CliClient final : public Actor { send_request( td_api::make_object(as_generated_file(document_path, document_conversion), nullptr, 1)); } - send_message(chat_id, - td_api::make_object( - as_generated_file(document_path, document_conversion), nullptr, as_caption("test caption"))); + send_message(chat_id, td_api::make_object( + as_generated_file(document_path, document_conversion), nullptr, false, + as_caption("test caption"))); } else if (op == "sdtg") { string chat_id; string document_path; @@ -3227,7 +3227,7 @@ class CliClient final : public Actor { std::tie(thumbnail_path, thumbnail_conversion) = split(args); send_message(chat_id, td_api::make_object( as_input_file(document_path), as_input_thumbnail(thumbnail_path, thumbnail_conversion), - as_caption("test caption"))); + false, as_caption("test caption"))); } else if (op == "sdgtg") { string chat_id; string document_path; @@ -3238,22 +3238,23 @@ class CliClient final : public Actor { std::tie(document_path, args) = split(args); std::tie(document_conversion, args) = split(args); std::tie(thumbnail_path, thumbnail_conversion) = split(args); - send_message(chat_id, td_api::make_object( - as_generated_file(document_path, document_conversion), - as_input_thumbnail(thumbnail_path, thumbnail_conversion), as_caption("test caption"))); + send_message(chat_id, + td_api::make_object( + as_generated_file(document_path, document_conversion), + as_input_thumbnail(thumbnail_path, thumbnail_conversion), false, as_caption("test caption"))); } else if (op == "sdid") { string chat_id; string file_id; std::tie(chat_id, file_id) = split(args); - send_message(chat_id, td_api::make_object(as_input_file_id(file_id), nullptr, + send_message(chat_id, td_api::make_object(as_input_file_id(file_id), nullptr, false, as_caption(""))); } else if (op == "sdurl") { string chat_id; string url; std::tie(chat_id, url) = split(args); - send_message(chat_id, - td_api::make_object(as_remote_file(url), nullptr, as_caption(""))); + send_message(chat_id, td_api::make_object(as_remote_file(url), nullptr, false, + as_caption(""))); } else if (op == "sg") { string chat_id; string bot_user_id; diff --git a/td/telegram/files/FileDownloader.cpp b/td/telegram/files/FileDownloader.cpp index 854253f53..24a0c83f2 100644 --- a/td/telegram/files/FileDownloader.cpp +++ b/td/telegram/files/FileDownloader.cpp @@ -108,11 +108,12 @@ Result FileDownloader::init() { res.ready_parts = bitmask.as_vector(); res.use_part_count_limit = false; res.only_check = only_check_; + auto file_type = remote_.file_type_; res.need_delay = - !is_small_ && (remote_.file_type_ == FileType::VideoNote || remote_.file_type_ == FileType::Document || - remote_.file_type_ == FileType::VoiceNote || remote_.file_type_ == FileType::Audio || - remote_.file_type_ == FileType::Video || remote_.file_type_ == FileType::Animation || - (remote_.file_type_ == FileType::Encrypted && size_ > (1 << 20))); + !is_small_ && + (file_type == FileType::VideoNote || file_type == FileType::Document || file_type == FileType::DocumentAsFile || + file_type == FileType::VoiceNote || file_type == FileType::Audio || file_type == FileType::Video || + file_type == FileType::Animation || (file_type == FileType::Encrypted && size_ > (1 << 20))); res.offset = offset_; res.limit = limit_; return res; diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index 3efe65678..bf8f16b06 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -53,6 +53,8 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector(FileType::SecureRaw)] = false; } else if (file_type == FileType::Background) { immune_types[narrow_cast(FileType::Wallpaper)] = false; + } else if (file_type == FileType::Document) { + immune_types[narrow_cast(FileType::DocumentAsFile)] = false; } immune_types[narrow_cast(file_type)] = false; } diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index c0d3355cd..d6fd26283 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -210,6 +210,7 @@ class FullRemoteFileLocation { case FileType::SecureRaw: case FileType::Secure: case FileType::Background: + case FileType::DocumentAsFile: return LocationType::Common; case FileType::None: case FileType::Size: diff --git a/td/telegram/files/FileLocation.hpp b/td/telegram/files/FileLocation.hpp index 502c4a01c..6aa4d0dac 100644 --- a/td/telegram/files/FileLocation.hpp +++ b/td/telegram/files/FileLocation.hpp @@ -238,6 +238,7 @@ void FullRemoteFileLocation::AsUnique::store(StorerT &storer) const { case FileType::Animation: case FileType::VideoNote: case FileType::Background: + case FileType::DocumentAsFile: return 2; case FileType::SecureRaw: case FileType::Secure: diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 74d9d5e25..fb7097c1e 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -766,7 +766,8 @@ FileManager::FileManager(unique_ptr context) : context_(std::move(conte }; for (int32 i = 0; i < file_type_size; i++) { FileType file_type = static_cast(i); - if (file_type == FileType::SecureRaw || file_type == FileType::Background) { + if (file_type == FileType::SecureRaw || file_type == FileType::Background || + file_type == FileType::DocumentAsFile) { continue; } auto path = get_files_dir(file_type); @@ -847,6 +848,7 @@ string FileManager::get_file_name(FileType file_type, Slice path) { case FileType::EncryptedThumbnail: case FileType::Secure: case FileType::SecureRaw: + case FileType::DocumentAsFile: break; default: UNREACHABLE(); @@ -2726,7 +2728,7 @@ void FileManager::cancel_upload(FileId file_id) { static bool is_document_type(FileType type) { return type == FileType::Document || type == FileType::Sticker || type == FileType::Audio || - type == FileType::Animation || type == FileType::Background; + type == FileType::Animation || type == FileType::Background || type == FileType::DocumentAsFile; } static bool is_background_type(FileType type) { diff --git a/td/telegram/files/FileStats.cpp b/td/telegram/files/FileStats.cpp index e919363dd..0a3bd35d8 100644 --- a/td/telegram/files/FileStats.cpp +++ b/td/telegram/files/FileStats.cpp @@ -138,6 +138,8 @@ tl_object_ptr as_td_api(DialogId dialog_id, int32 secure_raw_cnt = 0; int64 wallpaper_raw_size = 0; int32 wallpaper_raw_cnt = 0; + int64 document_raw_size = 0; + int32 document_raw_cnt = 0; for (int32 i = 0; i < file_type_size; i++) { FileType file_type = static_cast(i); auto size = stat_by_type[i].size; @@ -153,6 +155,11 @@ tl_object_ptr as_td_api(DialogId dialog_id, wallpaper_raw_cnt = cnt; continue; } + if (file_type == FileType::Document) { + document_raw_size = size; + document_raw_cnt = cnt; + continue; + } if (file_type == FileType::Secure) { size += secure_raw_size; cnt += secure_raw_cnt; @@ -161,6 +168,11 @@ tl_object_ptr as_td_api(DialogId dialog_id, size += wallpaper_raw_size; cnt += wallpaper_raw_cnt; } + if (file_type == FileType::DocumentAsFile) { + size += document_raw_size; + cnt += document_raw_cnt; + continue; + } if (size == 0) { continue; } diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index 34d9edb88..92e595692 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -102,7 +102,7 @@ template void scan_fs(CancellationToken &token, CallbackT &&callback) { for (int32 i = 0; i < file_type_size; i++) { auto file_type = static_cast(i); - if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { + if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper || file_type == FileType::DocumentAsFile) { continue; } auto files_dir = get_files_dir(file_type); diff --git a/td/telegram/files/FileType.h b/td/telegram/files/FileType.h index 31c0427aa..1698457e8 100644 --- a/td/telegram/files/FileType.h +++ b/td/telegram/files/FileType.h @@ -32,6 +32,7 @@ enum class FileType : int32 { SecureRaw, Secure, Background, + DocumentAsFile, Size, None }; @@ -113,6 +114,8 @@ inline tl_object_ptr as_td_api(FileType file_type) { return make_tl_object(); case FileType::Background: return make_tl_object(); + case FileType::DocumentAsFile: + return make_tl_object(); case FileType::None: return make_tl_object(); default: @@ -159,6 +162,8 @@ inline CSlice get_file_type_name(FileType file_type) { return CSlice("passport"); case FileType::Background: return CSlice("wallpapers"); + case FileType::DocumentAsFile: + return CSlice("documents"); case FileType::Size: case FileType::None: default: diff --git a/td/telegram/net/NetStatsManager.cpp b/td/telegram/net/NetStatsManager.cpp index 0475947c9..259c98a01 100644 --- a/td/telegram/net/NetStatsManager.cpp +++ b/td/telegram/net/NetStatsManager.cpp @@ -60,8 +60,12 @@ void NetStatsManager::init() { }; for_each_stat([&](NetStatsInfo &stat, size_t id, CSlice name, FileType file_type) { - if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { - id++; + if (file_type == FileType::SecureRaw) { + id += static_cast(FileType::SecureRaw) - static_cast(FileType::Secure); + } else if (file_type == FileType::Wallpaper) { + id += static_cast(FileType::Background) - static_cast(FileType::Wallpaper); + } else if (file_type == FileType::DocumentAsFile) { + id += static_cast(FileType::Document) - static_cast(FileType::DocumentAsFile); } stat.key = "net_stats_" + name.str(); stat.stats.set_callback(make_unique(actor_id(this), id)); @@ -113,7 +117,8 @@ void NetStatsManager::get_network_stats(bool current, Promise prom entry.is_call = true; result.entries.push_back(std::move(entry)); } else if (file_type != FileType::None) { - if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { + if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper || + file_type == FileType::DocumentAsFile) { return; } @@ -193,7 +198,7 @@ void NetStatsManager::add_network_stats_impl(NetStatsInfo &info, const NetworkSt void NetStatsManager::start_up() { for_each_stat([&](NetStatsInfo &info, size_t id, CSlice name, FileType file_type) { - if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper) { + if (file_type == FileType::SecureRaw || file_type == FileType::Wallpaper || file_type == FileType::DocumentAsFile) { return; } @@ -258,6 +263,7 @@ std::vector> NetStatsManager::get_file_stats_c auto result = transform(files_stats_, [](auto &stat) { return stat.stats.get_callback(); }); result[static_cast(FileType::SecureRaw)] = result[static_cast(FileType::Secure)]; result[static_cast(FileType::Wallpaper)] = result[static_cast(FileType::Background)]; + result[static_cast(FileType::DocumentAsFile)] = result[static_cast(FileType::Document)]; return result; } diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 6f80f2859..ed9e64823 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -490,14 +490,14 @@ class TestFileGenerated : public Task { make_tl_object(file_path, "square", 0), make_tl_object( make_tl_object(file_path, "thumbnail", 0), 0, 0), - make_tl_object(tag_, Auto()))), + true, make_tl_object(tag_, Auto()))), [](auto res) { check_td_error(res); }); this->send_query( make_tl_object(chat_id_, 0, nullptr, nullptr, make_tl_object( make_tl_object(file_path, "square", 0), - nullptr, make_tl_object(tag_, Auto()))), + nullptr, true, make_tl_object(tag_, Auto()))), [](auto res) { check_td_error(res); }); }