From d475b0fc89a9940d5454a87bc136d409c11c819f Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 3 Dec 2021 11:20:56 +0300 Subject: [PATCH 1/6] tg_cli: add shortcuts for 'sob online'. --- td/telegram/cli.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 9fdde42df..80a13099b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2211,6 +2211,9 @@ class CliClient final : public Actor { send_request(td_api::make_object(language_code, std::move(str))); } else if (op == "dlp") { send_request(td_api::make_object(args)); + } else if (op == "on" || op == "off") { + send_request(td_api::make_object("online", + td_api::make_object(op == "on"))); } else if (op == "go") { send_request(td_api::make_object(args)); } else if (op == "sob") { From fe4efa3e5b683293ffb812ed9a107aef88539700 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 4 Dec 2021 21:57:44 +0300 Subject: [PATCH 2/6] Allow messageMediaEmpty before authorizartion. --- td/telegram/MessageContent.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 11bd2a8f1..d33cd7224 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4111,7 +4111,8 @@ unique_ptr get_message_content(Td *td, FormattedText message, tl_object_ptr &&media, DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id, int32 *ttl, bool *disable_web_page_preview) { - if (!td->auth_manager_->was_authorized() && !G()->close_flag() && media != nullptr) { + if (!td->auth_manager_->was_authorized() && !G()->close_flag() && media != nullptr && + media->get_id() != telegram_api::messageMediaEmpty::ID) { LOG(ERROR) << "Receive without authorization " << to_string(media); media = nullptr; } From 227fb48fbf9c486b169c7d88c5611d0560890bdc Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 5 Dec 2021 00:12:59 +0300 Subject: [PATCH 3/6] Add MessagesManager::delete_newer_server_messages_at_the_end. --- td/telegram/MessagesManager.cpp | 82 ++++++++++++++++++--------------- td/telegram/MessagesManager.h | 2 + 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index ccf982825..f4e68faa0 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -9035,6 +9035,48 @@ void MessagesManager::on_get_messages(vector message_ids; + find_newer_messages(d->messages.get(), max_message_id, message_ids); + if (message_ids.empty()) { + return false; + } + + bool need_update_dialog_pos = false; + vector deleted_message_ids; + for (auto message_id : message_ids) { + CHECK(message_id > max_message_id); + if (message_id.is_server()) { + auto message = + delete_message(d, message_id, true, &need_update_dialog_pos, "delete_newer_server_messages_at_the_end 1"); + CHECK(message != nullptr); + deleted_message_ids.push_back(message->message_id.get()); + } + } + if (need_update_dialog_pos) { + send_update_chat_last_message(d, "delete_newer_server_messages_at_the_end 2"); + } + + if (!deleted_message_ids.empty()) { + send_update_delete_messages(d->dialog_id, std::move(deleted_message_ids), true, false); + + message_ids.clear(); + find_newer_messages(d->messages.get(), max_message_id, message_ids); + } + + // connect all messages with ID > max_message_id + for (size_t i = 0; i + 1 < message_ids.size(); i++) { + auto m = get_message(d, message_ids[i]); + CHECK(m != nullptr); + if (!m->have_next) { + m->have_next = true; + attach_message_to_next(d, message_ids[i], "delete_newer_server_messages_at_the_end 3"); + } + } + + return !message_ids.empty(); +} + void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_id, MessageId old_last_new_message_id, int32 offset, int32 limit, bool from_the_end, vector> &&messages, Promise &&promise) { @@ -9133,43 +9175,8 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ if (from_the_end) { // delete all server messages with ID > last_received_message_id // there were no new messages received after the getHistory request was sent, so they are already deleted message - vector message_ids; - find_newer_messages(d->messages.get(), last_received_message_id, message_ids); - if (!message_ids.empty()) { - bool need_update_dialog_pos = false; - vector deleted_message_ids; - for (auto message_id : message_ids) { - CHECK(message_id > last_received_message_id); - if (message_id.is_server()) { - auto message = delete_message(d, message_id, true, &need_update_dialog_pos, "on_get_gistory 1"); - CHECK(message != nullptr); - deleted_message_ids.push_back(message->message_id.get()); - } - } - if (need_update_dialog_pos) { - send_update_chat_last_message(d, "on_get_gistory 2"); - } - - if (!deleted_message_ids.empty()) { - send_update_delete_messages(dialog_id, std::move(deleted_message_ids), true, false); - - message_ids.clear(); - find_newer_messages(d->messages.get(), last_received_message_id, message_ids); - } - - // connect all messages with ID > last_received_message_id - for (size_t i = 0; i + 1 < message_ids.size(); i++) { - auto m = get_message(d, message_ids[i]); - CHECK(m != nullptr); - if (!m->have_next) { - m->have_next = true; - attach_message_to_next(d, message_ids[i], "on_get_history 3"); - } - } - - if (!message_ids.empty()) { - have_next = true; - } + if (delete_newer_server_messages_at_the_end(d, last_received_message_id)) { + have_next = true; } } @@ -9327,7 +9334,6 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ << prev_have_full_history << " " << d->debug_last_new_message_id << " " << d->debug_first_database_message_id << " " << d->debug_last_database_message_id << " " << from_message_id << " " << offset << " " << limit << " " << messages.size() << " " << last_received_message_id << " " << d->debug_set_dialog_last_database_message_id; - CHECK(d->last_database_message_id.is_valid()); for (auto &first_message_id : d->first_database_message_id_by_index) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index f70edd7f0..a4fa81223 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2100,6 +2100,8 @@ class MessagesManager final : public Actor { void on_update_dialog_online_member_count_timeout(DialogId dialog_id); + bool delete_newer_server_messages_at_the_end(Dialog *d, MessageId max_message_id); + template vector get_message_history_slice(const T &begin, It it, const T &end, MessageId from_message_id, int32 offset, int32 limit); From a116185e8379c1ac3f5bf5b38576acfbd62b4c27 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 5 Dec 2021 00:22:56 +0300 Subject: [PATCH 4/6] Ensure that all messages after last_added_message_id are connected. --- td/telegram/MessagesManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index f4e68faa0..eddcb4ebd 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -9220,6 +9220,11 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ } } + if (from_the_end && last_added_message_id != last_received_message_id) { + CHECK(last_added_message_id < last_received_message_id); + delete_newer_server_messages_at_the_end(d, last_added_message_id); + } + if (have_full_history) { d->have_full_history = true; on_dialog_updated(dialog_id, "set have_full_history 2"); From 084855c0c346a44f184783d429dee17742491e67 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 5 Dec 2021 01:00:28 +0300 Subject: [PATCH 5/6] tg_cli: increase OP_BLOCK_COUNT. --- td/telegram/cli.cpp | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 80a13099b..1cdd6fa4f 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1636,7 +1636,7 @@ class CliClient final : public Actor { string args; std::tie(op, args) = split(cmd); - const int32 OP_BLOCK_COUNT = 5; + const int32 OP_BLOCK_COUNT = 10; int32 op_not_found_count = 0; if (op == "gas") { @@ -2287,7 +2287,11 @@ class CliClient final : public Actor { send_get_background_url(get_freeform_gradient_background({0xFEDCBA, 0x222222})); send_get_background_url(get_freeform_gradient_background({0xFEDCBA, 0x111111, 0x222222})); send_get_background_url(get_freeform_gradient_background({0xABCDEF, 0xFEDCBA, 0x111111, 0x222222})); - } else if (op == "sbg") { + } else { + op_not_found_count++; + } + + if (op == "sbg") { send_request(td_api::make_object(args)); } else if (op == "sbgd") { send_request(td_api::make_object(nullptr, nullptr, as_bool(args))); @@ -2545,17 +2549,17 @@ class CliClient final : public Actor { send_request(td_api::make_object(args)); } else if (op == "gesu") { send_request(td_api::make_object(args)); - } else { - op_not_found_count++; - } - - if (op == "gsan") { + } else if (op == "gsan") { send_request(td_api::make_object()); } else if (op == "asan") { send_request(td_api::make_object(as_input_file_id(args))); } else if (op == "rsan") { send_request(td_api::make_object(as_input_file_id(args))); - } else if (op == "guf") { + } else { + op_not_found_count++; + } + + if (op == "guf") { send_request(td_api::make_object(as_user_id(args))); } else if (op == "gbg") { send_request(td_api::make_object(as_basic_group_id(args))); @@ -2773,7 +2777,11 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_chat_id(args))); } else if (op == "closeSC" || op == "cancelSC") { send_request(td_api::make_object(as_secret_chat_id(args))); - } else if (op == "cc" || op == "CreateCall") { + } else { + op_not_found_count++; + } + + if (op == "cc" || op == "CreateCall") { send_request(td_api::make_object( as_user_id(args), td_api::make_object(true, true, 65, 65, vector{"2.6", "3.0"}), rand_bool())); @@ -3425,7 +3433,11 @@ class CliClient final : public Actor { get_args(args, chat_id, message_id); send_request(td_api::make_object( as_chat_id(chat_id), as_message_id(message_id), td_api::make_object(""))); - } else if (op == "san") { + } else { + op_not_found_count++; + } + + if (op == "san") { string chat_id; string animation_path; int32 width; @@ -3721,7 +3733,11 @@ class CliClient final : public Actor { send_message(chat_id, td_api::make_object(td_api::make_object( as_location(latitude, longitude, accuracy), title, address, provider, venue_id, venue_type))); - } else if (op == "test") { + } else { + op_not_found_count++; + } + + if (op == "test") { send_request(td_api::make_object()); } else if (op == "alarm") { send_request(td_api::make_object(to_double(args))); @@ -4261,7 +4277,11 @@ class CliClient final : public Actor { bool is_dark; get_args(args, chat_id, is_dark); send_request(td_api::make_object(as_chat_id(chat_id), is_dark)); - } else if (op == "sgs") { + } else { + op_not_found_count++; + } + + if (op == "sgs") { string chat_id; string message_id; string user_id; From 858078d89fcd2ad1d9860547e3f87c49d0f9abe9 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 5 Dec 2021 01:02:22 +0300 Subject: [PATCH 6/6] Fix on_get_history. --- td/telegram/MessagesManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index eddcb4ebd..7f942b5f9 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -9220,7 +9220,7 @@ void MessagesManager::on_get_history(DialogId dialog_id, MessageId from_message_ } } - if (from_the_end && last_added_message_id != last_received_message_id) { + if (from_the_end && last_added_message_id.is_valid() && last_added_message_id != last_received_message_id) { CHECK(last_added_message_id < last_received_message_id); delete_newer_server_messages_at_the_end(d, last_added_message_id); }