From 00ff276a1fd710fe2b1be3c227cac5ab3967f1c8 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 4 Oct 2020 01:30:59 +0300 Subject: [PATCH 1/4] tg_cli: keep client settings after reset. GitOrigin-RevId: c3bd45d9369250f9eb867e9500d6854d0dda19a9 --- td/telegram/cli.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index dfd970179..4b829fcc0 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -854,6 +854,13 @@ class CliClient final : public Actor { options.net_query_stats = net_query_stats_; td_client_ = create_actor(name, make_unique(this, ++generation_), std::move(options)); + + if (get_chat_list_) { + send_request(td_api::make_object(nullptr, std::numeric_limits::max(), 0, 100)); + } + if (disable_network_) { + send_request(td_api::make_object(td_api::make_object())); + } } void init_td() { @@ -923,13 +930,6 @@ class CliClient final : public Actor { reactivate_readline(); #endif Scheduler::subscribe(stdin_.get_poll_info().extract_pollable_fd(this), PollFlags::Read()); - - if (get_chat_list_) { - send_request(td_api::make_object(nullptr, std::numeric_limits::max(), 0, 100)); - } - if (disable_network_) { - send_request(td_api::make_object(td_api::make_object())); - } } #ifndef USE_READLINE size_t buffer_pos_ = 0; From f50e017c1f8348ebdb356772f6b09901ff172e4e Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 4 Oct 2020 13:01:53 +0300 Subject: [PATCH 2/4] Add seq overflow handling. GitOrigin-RevId: 082d5989e061b8408f88dd92a3bf1665d3db6d79 --- td/telegram/UpdatesManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 3d291d4c2..57fb0ae7f 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1357,6 +1357,9 @@ void UpdatesManager::on_pending_updates(vector= 1000000000 && seq_begin < seq_ - 1000000000) { + set_seq_gap_timeout(0.001); + } if (seq_end > seq_) { LOG(ERROR) << "Strange updates from " << source << " coming with seq_begin = " << seq_begin << ", seq_end = " << seq_end << ", but seq = " << seq_; From c36741034ccc6650a847e94cbb38bb5412980f52 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 4 Oct 2020 13:04:15 +0300 Subject: [PATCH 3/4] Improve chatMemberStatus.is_anonymous documentation. GitOrigin-RevId: 7d158b884e18dac088a8ed31e4c8b137430b229e --- td/generate/scheme/td_api.tl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 214c01ab9..cd63d52f5 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -441,7 +441,7 @@ chatPermissions can_send_messages:Bool can_send_media_messages:Bool can_send_pol //@description The user is the owner of a chat and has all the administrator privileges //@custom_title A custom title of the owner; 0-16 characters without emojis; applicable to supergroups only -//@is_anonymous True, if the creator isn't shown in the chat member list and sends messages anonymously +//@is_anonymous True, if the creator isn't shown in the chat member list and sends messages anonymously; applicable to supergroups only //@is_member True, if the user is a member of the chat chatMemberStatusCreator custom_title:string is_anonymous:Bool is_member:Bool = ChatMemberStatus; @@ -456,7 +456,7 @@ chatMemberStatusCreator custom_title:string is_anonymous:Bool is_member:Bool = C //@can_restrict_members True, if the administrator can restrict, ban, or unban chat members //@can_pin_messages True, if the administrator can pin messages; applicable to groups only //@can_promote_members True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that were directly or indirectly promoted by them -//@is_anonymous True, if the administrator isn't shown in the chat member list and sends messages anonymously +//@is_anonymous True, if the administrator isn't shown in the chat member list and sends messages anonymously; applicable to supergroups only chatMemberStatusAdministrator custom_title:string can_be_edited:Bool can_change_info:Bool can_post_messages:Bool can_edit_messages:Bool can_delete_messages:Bool can_invite_users:Bool can_restrict_members:Bool can_pin_messages:Bool can_promote_members:Bool is_anonymous:Bool = ChatMemberStatus; //@description The user is a member of a chat, without any additional privileges or restrictions From 6d9953aea5e431cc80162f11127a7198453639e9 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 4 Oct 2020 23:33:21 +0300 Subject: [PATCH 4/4] Add add_anonymous_bot_user. GitOrigin-RevId: 9eadd5f3621f7c5a2dc065d51d105c07ffc25616 --- td/telegram/ContactsManager.cpp | 86 +++++++++++++++++++++++---------- td/telegram/ContactsManager.h | 4 ++ 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index f89fee27f..04449d3fd 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4418,6 +4418,18 @@ UserId ContactsManager::get_replies_bot_user_id() { return UserId(G()->is_test_dc() ? 708513 : 1271266957); } +UserId ContactsManager::get_anonymous_bot_user_id() { + return UserId(G()->is_test_dc() ? 552888 : 1087968824); +} + +UserId ContactsManager::add_anonymous_bot_user() { + auto user_id = get_anonymous_bot_user_id(); + if (!have_user_force(user_id)) { + LOG(FATAL) << "Failed to load anonymous bot user"; + } + return user_id; +} + void ContactsManager::check_dialog_username(DialogId dialog_id, const string &username, Promise &&promise) { if (dialog_id != DialogId() && !dialog_id.is_valid()) { @@ -7530,38 +7542,60 @@ bool ContactsManager::have_user_force(UserId user_id) { ContactsManager::User *ContactsManager::get_user_force(UserId user_id) { auto u = get_user_force_impl(user_id); - if (user_id == get_service_notifications_user_id() && (u == nullptr || !u->is_received)) { + if ((u == nullptr || !u->is_received) && + (user_id == get_service_notifications_user_id() || user_id == get_replies_bot_user_id() || + user_id == get_anonymous_bot_user_id())) { int32 flags = telegram_api::user::ACCESS_HASH_MASK | telegram_api::user::FIRST_NAME_MASK | - telegram_api::user::PHONE_MASK | telegram_api::user::PHOTO_MASK | telegram_api::user::VERIFIED_MASK | - telegram_api::user::SUPPORT_MASK | telegram_api::user::APPLY_MIN_PHOTO_MASK; - auto profile_photo = telegram_api::make_object( - 0, false /*ignored*/, 3337190045231023, - telegram_api::make_object(107738948, 13226), - telegram_api::make_object(107738948, 13228), 1); - if (G()->is_test_dc()) { - profile_photo = nullptr; - flags -= telegram_api::user::PHOTO_MASK; + telegram_api::user::APPLY_MIN_PHOTO_MASK; + int64 profile_photo_id = 0; + int64 profile_photo_volume_id = 0; + int32 profile_photo_local_id = 0; + int32 profile_photo_dc_id = 1; + string first_name; + string username; + string phone_number; + int32 bot_info_version = 0; + + if (user_id == get_service_notifications_user_id()) { + flags |= telegram_api::user::PHONE_MASK | telegram_api::user::VERIFIED_MASK | telegram_api::user::SUPPORT_MASK; + first_name = "Telegram"; + phone_number = "42777"; + profile_photo_id = 3337190045231023; + profile_photo_volume_id = 107738948; + profile_photo_local_id = 13226; + } else if (user_id == get_replies_bot_user_id()) { + flags |= telegram_api::user::USERNAME_MASK | telegram_api::user::BOT_MASK; + first_name = "Replies"; + username = "replies"; + bot_info_version = G()->is_test_dc() ? 1 : 3; + } else if (user_id == get_anonymous_bot_user_id()) { + flags |= telegram_api::user::USERNAME_MASK | telegram_api::user::BOT_MASK; + first_name = "Group"; + username = G()->is_test_dc() ? "izgroupbot" : "GroupAnonymousBot"; + bot_info_version = G()->is_test_dc() ? 1 : 3; + profile_photo_id = 5159307831025969322; + profile_photo_volume_id = 806529792; + profile_photo_local_id = 188482; + } + + telegram_api::object_ptr profile_photo; + if (!G()->is_test_dc() && profile_photo_id != 0) { + flags |= telegram_api::user::PHOTO_MASK; + profile_photo = telegram_api::make_object( + 0, false /*ignored*/, profile_photo_id, + telegram_api::make_object(profile_photo_volume_id, + profile_photo_local_id), + telegram_api::make_object(profile_photo_volume_id, + profile_photo_local_id + 2), + profile_photo_dc_id); } auto user = telegram_api::make_object( flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, user_id.get(), 1, "Telegram", - string(), string(), "42777", std::move(profile_photo), nullptr, 0, Auto(), string(), string()); - on_get_user(std::move(user), "get_user_force"); - u = get_user(user_id); - CHECK(u != nullptr && u->is_received); - } - if (user_id == get_replies_bot_user_id() && (u == nullptr || !u->is_received)) { - int32 flags = telegram_api::user::ACCESS_HASH_MASK | telegram_api::user::FIRST_NAME_MASK | - telegram_api::user::USERNAME_MASK | - /*telegram_api::user::PHOTO_MASK | telegram_api::user::VERIFIED_MASK |*/ - telegram_api::user::BOT_MASK | telegram_api::user::APPLY_MIN_PHOTO_MASK; - auto user = telegram_api::make_object( - flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, user_id.get(), 1, "Replies", - string(), "replies", "", nullptr, nullptr, 1, Auto(), string(), string()); + false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, user_id.get(), 1, first_name, + string(), username, phone_number, std::move(profile_photo), nullptr, bot_info_version, Auto(), string(), + string()); on_get_user(std::move(user), "get_user_force"); u = get_user(user_id); CHECK(u != nullptr && u->is_received); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 3507c18c8..6b6a31216 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -265,6 +265,10 @@ class ContactsManager : public Actor { static UserId get_replies_bot_user_id(); + static UserId get_anonymous_bot_user_id(); + + UserId add_anonymous_bot_user(); + void on_update_online_status_privacy(); void on_update_phone_number_privacy();