From 4ed0b15a41f4920b6027f3b9befcff2310dd566b Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 28 Jul 2021 06:15:57 +0300 Subject: [PATCH 1/3] Add suggested_video_note_* options. --- td/generate/scheme/td_api.tl | 2 +- td/telegram/ConfigManager.cpp | 32 ++++++++++++++++++++++++++++++++ td/telegram/Td.cpp | 9 +++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 4cf6df194..aacaa1919 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3235,7 +3235,7 @@ networkStatistics since_date:int32 entries:vector = Netw //@max_photo_file_size The maximum size of a photo file to be auto-downloaded //@max_video_file_size The maximum size of a video file to be auto-downloaded //@max_other_file_size The maximum size of other file types to be auto-downloaded -//@video_upload_bitrate The maximum suggested bitrate for uploaded videos +//@video_upload_bitrate The maximum suggested bitrate for uploaded videos, in kbit/s //@preload_large_videos True, if the beginning of video files needs to be preloaded for instant playback //@preload_next_audio True, if the next audio track needs to be preloaded while the user is listening to an audio file //@use_less_data_for_calls True, if "use less data for calls" option needs to be enabled diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 4cfadc2d7..f7d9912a2 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -1678,6 +1678,38 @@ void ConfigManager::process_app_config(tl_object_ptr &c } continue; } + if (key == "round_video_encoding") { + if (value->get_id() == telegram_api::jsonObject::ID) { + auto video_note_settings = std::move(static_cast(value)->value_); + for (auto &video_note_setting : video_note_settings) { + CHECK(video_note_setting != nullptr); + if (video_note_setting->key_ != "diameter" && video_note_setting->key_ != "video_bitrate" && + video_note_setting->key_ != "audio_bitrate") { + continue; + } + if (video_note_setting->value_->get_id() == telegram_api::jsonNumber::ID) { + auto setting_value = static_cast( + static_cast(video_note_setting->value_.get())->value_); + if (value > 0) { + if (video_note_setting->key_ == "diameter") { + G()->shared_config().set_option_integer("suggested_video_note_length", setting_value); + } + if (video_note_setting->key_ == "video_bitrate") { + G()->shared_config().set_option_integer("suggested_video_note_video_bitrate", setting_value); + } + if (video_note_setting->key_ == "audio_bitrate") { + G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", setting_value); + } + } + } else { + LOG(ERROR) << "Receive unexpected video note setting " << to_string(video_note_setting); + } + } + } else { + LOG(ERROR) << "Receive unexpected round_video_encoding " << to_string(*value); + } + continue; + } new_values.push_back(std::move(key_value)); } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 15e35236c..b02ecebf4 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4255,6 +4255,15 @@ void Td::init_options_and_network() { if (!G()->shared_config().have_option("message_caption_length_max")) { G()->shared_config().set_option_integer("message_caption_length_max", 1024); } + if (!G()->shared_config().have_option("suggested_video_note_length")) { + G()->shared_config().set_option_integer("suggested_video_note_length", 384); + } + if (!G()->shared_config().have_option("suggested_video_note_video_bitrate")) { + G()->shared_config().set_option_integer("suggested_video_note_video_bitrate", 1000); + } + if (!G()->shared_config().have_option("suggested_video_note_audio_bitrate")) { + G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", 64); + } init_connection_creator(); From a6151aff7b050443e7487f5fd2e600f5d5f7b57b Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 28 Jul 2021 21:39:17 +0300 Subject: [PATCH 2/3] Don't delete old document after sticker upload. --- td/telegram/StickersManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index b8a47477d..f59627821 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -5029,9 +5029,10 @@ void StickersManager::on_uploaded_sticker_file(FileId file_id, tl_object_ptrdocuments_manager_->merge_documents(parsed_document.file_id, file_id, true); + // must not delete the old document, because the file_id could be used for simultaneous URL uploads + td_->documents_manager_->merge_documents(parsed_document.file_id, file_id, false); } promise.set_value(Unit()); } From 645973c0a35bb6d53f902883439f8596ec29bc57 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 29 Jul 2021 02:04:28 +0300 Subject: [PATCH 3/3] Avoid channel dialog creation by new updates, which can't be applied anyway. --- td/telegram/MessagesManager.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index b87c373a4..d0a7306a8 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -7276,7 +7276,7 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p auto channel_id = dialog_id.get_channel_id(); if (!td_->contacts_manager_->have_channel(channel_id) && td_->contacts_manager_->have_min_channel(channel_id)) { - td_->updates_manager_->schedule_get_difference("on_update_new_channel_message"); + td_->updates_manager_->schedule_get_difference("add_pending_channel_update 1"); promise.set_value(Unit()); return; } @@ -7284,7 +7284,7 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p // TODO need to save all updates that can change result of running queries not associated with pts (for example // getHistory) and apply them to result of these queries - Dialog *d = get_dialog_force(dialog_id, "add_pending_channel_update"); + Dialog *d = get_dialog_force(dialog_id, "add_pending_channel_update 2"); if (d == nullptr) { auto pts = load_channel_pts(dialog_id); if (pts > 0) { @@ -7295,10 +7295,25 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p return; } - d = add_dialog(dialog_id, "add_pending_channel_update"); + if (new_pts <= pts && new_pts >= pts - 19999) { + LOG(INFO) << "There is no need to process an update with pts " << new_pts << " in " << dialog_id << " with pts " + << pts; + promise.set_value(Unit()); + return; + } + + if (new_pts > pts && pts != new_pts - pts_count) { + LOG(INFO) << "Found a gap in the " << dialog_id << " with pts = " << pts << ". new_pts = " << new_pts + << ", pts_count = " << pts_count << " in update from " << source; + get_channel_difference(dialog_id, pts, true, "add_pending_channel_update 3"); + promise.set_value(Unit()); + return; + } + + d = add_dialog(dialog_id, "add_pending_channel_update 4"); CHECK(d != nullptr); CHECK(d->pts == pts); - update_dialog_pos(d, "add_pending_channel_update"); + update_dialog_pos(d, "add_pending_channel_update 5"); } } if (d == nullptr) { @@ -35615,6 +35630,7 @@ void MessagesManager::on_get_channel_difference( LOG(INFO) << "Receive result of getChannelDifference for " << dialog_id << " with pts = " << request_pts << " and limit = " << request_limit << ": " << to_string(difference_ptr); + bool have_new_messages = false; switch (difference_ptr->get_id()) { case telegram_api::updates_channelDifferenceEmpty::ID: if (d == nullptr) { @@ -35625,12 +35641,14 @@ void MessagesManager::on_get_channel_difference( break; case telegram_api::updates_channelDifference::ID: { auto difference = static_cast(difference_ptr.get()); + have_new_messages = !difference->new_messages_.empty(); td_->contacts_manager_->on_get_users(std::move(difference->users_), "updates.channelDifference"); td_->contacts_manager_->on_get_chats(std::move(difference->chats_), "updates.channelDifference"); break; } case telegram_api::updates_channelDifferenceTooLong::ID: { auto difference = static_cast(difference_ptr.get()); + have_new_messages = difference->dialog_->get_id() == telegram_api::dialog::ID && !difference->messages_.empty(); td_->contacts_manager_->on_get_users(std::move(difference->users_), "updates.channelDifferenceTooLong"); td_->contacts_manager_->on_get_chats(std::move(difference->chats_), "updates.channelDifferenceTooLong"); break; @@ -35641,7 +35659,12 @@ void MessagesManager::on_get_channel_difference( bool need_update_dialog_pos = false; if (d == nullptr) { + if (have_new_messages) { + CHECK(!being_added_by_new_message_dialog_id_.is_valid()); + being_added_by_new_message_dialog_id_ = dialog_id; + } d = add_dialog(dialog_id, "on_get_channel_difference"); + being_added_by_new_message_dialog_id_ = DialogId(); need_update_dialog_pos = true; }