diff --git a/td/generate/scheme/telegram_api.tl b/td/generate/scheme/telegram_api.tl index 0bd9e6749..139f6cdb0 100644 --- a/td/generate/scheme/telegram_api.tl +++ b/td/generate/scheme/telegram_api.tl @@ -96,7 +96,7 @@ storage.fileMp4#b3cea0e4 = storage.FileType; storage.fileWebp#1081464c = storage.FileType; userEmpty#200250ba id:int = User; -user#938458c1 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User; +user#938458c1 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User; userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto; userProfilePhoto#69d3ab26 flags:# has_video:flags.0?true photo_id:long photo_small:FileLocation photo_big:FileLocation dc_id:int = UserProfilePhoto; @@ -115,7 +115,7 @@ channel#d31a961e flags:# creator:flags.0?true left:flags.2?true broadcast:flags. channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat; chatFull#1b7c9db3 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int folder_id:flags.11?int = ChatFull; -channelFull#f0e6672a flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_view_stats:flags.12?true can_set_location:flags.16?true has_scheduled:flags.19?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int = ChatFull; +channelFull#f0e6672a flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int = ChatFull; chatParticipant#c8d7493e user_id:int inviter_id:int date:int = ChatParticipant; chatParticipantCreator#da13538a user_id:int = ChatParticipant; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index 20968326a..bd63deac4 100644 Binary files a/td/generate/scheme/telegram_api.tlo and b/td/generate/scheme/telegram_api.tlo differ diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 7ff1a3981..89bbefb98 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3220,6 +3220,7 @@ void ContactsManager::User::store(StorerT &storer) const { STORE_FLAG(is_contact); STORE_FLAG(is_mutual_contact); STORE_FLAG(has_restriction_reasons); + STORE_FLAG(need_apply_min_photo); END_STORE_FLAGS(); store(first_name, storer); if (has_last_name) { @@ -3288,6 +3289,7 @@ void ContactsManager::User::parse(ParserT &parser) { PARSE_FLAG(is_contact); PARSE_FLAG(is_mutual_contact); PARSE_FLAG(has_restriction_reasons); + PARSE_FLAG(need_apply_min_photo); END_PARSE_FLAGS(); parse(first_name, parser); if (has_last_name) { @@ -3750,6 +3752,8 @@ void ContactsManager::ChannelFull::store(StorerT &storer) const { STORE_FLAG(is_slow_mode_delay_active); STORE_FLAG(has_stats_dc_id); STORE_FLAG(has_photo); + STORE_FLAG(is_can_view_statistics_inited); + STORE_FLAG(can_view_statistics); END_STORE_FLAGS(); if (has_description) { store(description, storer); @@ -3841,6 +3845,8 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) { PARSE_FLAG(is_slow_mode_delay_active); PARSE_FLAG(has_stats_dc_id); PARSE_FLAG(has_photo); + PARSE_FLAG(is_can_view_statistics_inited); + PARSE_FLAG(can_view_statistics); END_PARSE_FLAGS(); if (has_description) { parse(description, parser); @@ -3893,6 +3899,9 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) { if (legacy_can_view_statistics) { LOG(DEBUG) << "Ignore legacy can view statistics flag"; } + if (!is_can_view_statistics_inited) { + can_view_statistics = stats_dc_id.is_exact(); + } } template @@ -5972,7 +5981,8 @@ void ContactsManager::set_channel_slow_mode_delay(DialogId dialog_id, int32 slow td_->create_handler(std::move(promise))->send(channel_id, slow_mode_delay); } -void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, Promise &&promise) { +void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics, + Promise &&promise) { if (!dialog_id.is_valid()) { return promise.set_error(Status::Error(400, "Invalid chat identifier specified")); } @@ -5991,11 +6001,13 @@ void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, Promisestats_dc_id.is_exact()) { - auto query_promise = PromiseCreator::lambda( - [actor_id = actor_id(this), channel_id, promise = std::move(promise)](Result result) mutable { - send_closure(actor_id, &ContactsManager::get_channel_statistics_dc_id_impl, channel_id, std::move(promise)); - }); + if (channel_full == nullptr || !channel_full->stats_dc_id.is_exact() || + (for_full_statistics && !channel_full->can_view_statistics)) { + auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), channel_id, for_full_statistics, + promise = std::move(promise)](Result result) mutable { + send_closure(actor_id, &ContactsManager::get_channel_statistics_dc_id_impl, channel_id, for_full_statistics, + std::move(promise)); + }); send_get_channel_full_query(channel_full, channel_id, std::move(query_promise), "get_channel_statistics_dc_id"); return; } @@ -6003,7 +6015,8 @@ void ContactsManager::get_channel_statistics_dc_id(DialogId dialog_id, Promisestats_dc_id)); } -void ContactsManager::get_channel_statistics_dc_id_impl(ChannelId channel_id, Promise &&promise) { +void ContactsManager::get_channel_statistics_dc_id_impl(ChannelId channel_id, bool for_full_statistics, + Promise &&promise) { if (G()->close_flag()) { return promise.set_error(Status::Error(500, "Request aborted")); } @@ -6013,7 +6026,7 @@ void ContactsManager::get_channel_statistics_dc_id_impl(ChannelId channel_id, Pr return promise.set_error(Status::Error(400, "Chat full info not found")); } - if (!channel_full->stats_dc_id.is_exact()) { + if (!channel_full->stats_dc_id.is_exact() || (for_full_statistics && !channel_full->can_view_statistics)) { return promise.set_error(Status::Error(400, "Chat statistics is not available")); } @@ -6030,7 +6043,7 @@ void ContactsManager::get_channel_statistics(DialogId dialog_id, bool is_dark, send_closure(actor_id, &ContactsManager::send_get_channel_stats_query, r_dc_id.move_as_ok(), dialog_id.get_channel_id(), is_dark, std::move(promise)); }); - get_channel_statistics_dc_id(dialog_id, std::move(dc_id_promise)); + get_channel_statistics_dc_id(dialog_id, true, std::move(dc_id_promise)); } void ContactsManager::send_get_channel_stats_query(DcId dc_id, ChannelId channel_id, bool is_dark, @@ -6057,7 +6070,7 @@ void ContactsManager::load_statistics_graph(DialogId dialog_id, const string &to send_closure(actor_id, &ContactsManager::send_load_async_graph_query, r_dc_id.move_as_ok(), std::move(token), x, std::move(promise)); }); - get_channel_statistics_dc_id(dialog_id, std::move(dc_id_promise)); + get_channel_statistics_dc_id(dialog_id, false, std::move(dc_id_promise)); } void ContactsManager::send_load_async_graph_query(DcId dc_id, string token, int64 x, @@ -7209,7 +7222,9 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, if (is_received || !user->phone_.empty()) { on_update_user_phone_number(u, user_id, std::move(user->phone_)); } - on_update_user_photo(u, user_id, std::move(user->photo_), source); + if (is_received || u->need_apply_min_photo) { + on_update_user_photo(u, user_id, std::move(user->photo_), source); + } if (is_received) { on_update_user_online(u, user_id, std::move(user->status_)); @@ -7234,6 +7249,7 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, string inline_query_placeholder = user->bot_inline_placeholder_; bool need_location_bot = (flags & USER_FLAG_NEED_LOCATION_BOT) != 0; bool has_bot_info_version = (flags & USER_FLAG_HAS_BOT_INFO_VERSION) != 0; + bool need_apply_min_photo = (flags & USER_FLAG_NEED_APPLY_MIN_PHOTO) != 0; LOG_IF(ERROR, !is_support && expect_support) << "Receive non-support " << user_id << ", but expected a support user"; LOG_IF(ERROR, !can_join_groups && !is_bot) @@ -7255,6 +7271,7 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, inline_query_placeholder = string(); need_location_bot = false; has_bot_info_version = false; + need_apply_min_photo = false; } LOG_IF(ERROR, has_bot_info_version && !is_bot) @@ -7288,6 +7305,10 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, LOG(DEBUG) << "Bot info version has changed for " << user_id; u->need_save_to_database = true; } + if (u->need_apply_min_photo != need_apply_min_photo) { + u->need_apply_min_photo = need_apply_min_photo; + u->need_save_to_database = true; + } if (is_received && !u->is_received) { u->is_received = true; @@ -7555,7 +7576,7 @@ ContactsManager::User *ContactsManager::get_user_force(UserId user_id) { if (user_id == UserId(777000) && (u == nullptr || !u->is_received)) { 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::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), @@ -7568,8 +7589,8 @@ ContactsManager::User *ContactsManager::get_user_force(UserId user_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*/, 777000, 1, "Telegram", string(), string(), "42777", - std::move(profile_photo), nullptr, 0, Auto(), string(), string()); + false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, 777000, 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); @@ -9465,15 +9486,20 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c auto can_set_sticker_set = (channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_SET_STICKER_SET) != 0; auto can_set_location = (channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_SET_LOCATION) != 0; auto is_all_history_available = (channel_full->flags_ & CHANNEL_FULL_FLAG_IS_ALL_HISTORY_HIDDEN) == 0; + auto can_view_statistics = (channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS) != 0; StickerSetId sticker_set_id; if (channel_full->stickerset_ != nullptr) { sticker_set_id = td_->stickers_manager_->on_get_sticker_set(std::move(channel_full->stickerset_), true, "on_get_channel_full"); } DcId stats_dc_id; - if ((channel_full->flags_ & CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS) != 0) { + if ((channel_full->flags_ & CHANNEL_FULL_FLAG_HAS_STATISTICS_DC_ID) != 0) { stats_dc_id = DcId::create(channel_full->stats_dc_); } + if (!stats_dc_id.is_exact() && can_view_statistics) { + LOG(ERROR) << "Receive can_view_statistics == true, but invalid statistics DC ID in " << channel_id; + can_view_statistics = false; + } ChannelFull *channel = add_channel_full(channel_id); channel->repair_request_version = 0; @@ -9482,8 +9508,9 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c channel->administrator_count != administrator_count || channel->restricted_count != restricted_count || channel->banned_count != banned_count || channel->can_get_participants != can_get_participants || channel->can_set_username != can_set_username || channel->can_set_sticker_set != can_set_sticker_set || - channel->can_set_location != can_set_location || channel->stats_dc_id != stats_dc_id || - channel->sticker_set_id != sticker_set_id || channel->is_all_history_available != is_all_history_available) { + channel->can_set_location != can_set_location || channel->can_view_statistics != can_view_statistics || + channel->stats_dc_id != stats_dc_id || channel->sticker_set_id != sticker_set_id || + channel->is_all_history_available != is_all_history_available) { channel->description = std::move(channel_full->about_); channel->participant_count = participant_count; channel->administrator_count = administrator_count; @@ -9493,6 +9520,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c channel->can_set_username = can_set_username; channel->can_set_sticker_set = can_set_sticker_set; channel->can_set_location = can_set_location; + channel->can_view_statistics = can_view_statistics; channel->stats_dc_id = stats_dc_id; channel->is_all_history_available = is_all_history_available; channel->sticker_set_id = sticker_set_id; @@ -9505,6 +9533,10 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c update_channel(c, channel_id); } } + if (!channel->is_can_view_statistics_inited) { + channel->is_can_view_statistics_inited = true; + channel->need_save_to_database = true; + } on_update_channel_full_photo( channel, channel_id, @@ -14102,7 +14134,7 @@ tl_object_ptr ContactsManager::get_supergroup_full_i channel_full->participant_count, channel_full->administrator_count, channel_full->restricted_count, channel_full->banned_count, DialogId(channel_full->linked_channel_id).get(), channel_full->slow_mode_delay, slow_mode_delay_expires_in, channel_full->can_get_participants, channel_full->can_set_username, - channel_full->can_set_sticker_set, channel_full->can_set_location, channel_full->stats_dc_id.is_exact(), + channel_full->can_set_sticker_set, channel_full->can_set_location, channel_full->can_view_statistics, channel_full->is_all_history_available, channel_full->sticker_set_id.get(), channel_full->location.get_chat_location_object(), channel_full->invite_link, get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"), diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 71c079785..b38352623 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -589,7 +589,7 @@ class ContactsManager : public Actor { std::unordered_map online_member_dialogs; // id -> time - static constexpr uint32 CACHE_VERSION = 2; + static constexpr uint32 CACHE_VERSION = 3; uint32 cache_version = 0; bool is_min_access_hash = true; @@ -605,6 +605,7 @@ class ContactsManager : public Actor { bool is_scam = false; bool is_contact = false; bool is_mutual_contact = false; + bool need_apply_min_photo = false; bool is_photo_inited = false; @@ -843,6 +844,8 @@ class ContactsManager : public Actor { bool can_set_username = false; bool can_set_sticker_set = false; bool can_set_location = false; + bool can_view_statistics = false; + bool is_can_view_statistics_inited = false; bool is_all_history_available = true; bool is_slow_mode_next_send_date_changed = true; @@ -957,6 +960,7 @@ class ContactsManager : public Actor { static constexpr int32 USER_FLAG_HAS_LANGUAGE_CODE = 1 << 22; static constexpr int32 USER_FLAG_IS_SUPPORT = 1 << 23; static constexpr int32 USER_FLAG_IS_SCAM = 1 << 24; + static constexpr int32 USER_FLAG_NEED_APPLY_MIN_PHOTO = 1 << 25; static constexpr int32 USER_FULL_FLAG_IS_BLOCKED = 1 << 0; static constexpr int32 USER_FULL_FLAG_HAS_ABOUT = 1 << 1; @@ -1011,7 +1015,7 @@ class ContactsManager : public Actor { static constexpr int32 CHANNEL_FULL_FLAG_HAS_AVAILABLE_MIN_MESSAGE_ID = 1 << 9; static constexpr int32 CHANNEL_FULL_FLAG_IS_ALL_HISTORY_HIDDEN = 1 << 10; static constexpr int32 CHANNEL_FULL_FLAG_HAS_FOLDER_ID = 1 << 11; - static constexpr int32 CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS = 1 << 12; + static constexpr int32 CHANNEL_FULL_FLAG_HAS_STATISTICS_DC_ID = 1 << 12; static constexpr int32 CHANNEL_FULL_FLAG_HAS_ONLINE_MEMBER_COUNT = 1 << 13; static constexpr int32 CHANNEL_FULL_FLAG_HAS_LINKED_CHANNEL_ID = 1 << 14; static constexpr int32 CHANNEL_FULL_FLAG_HAS_LOCATION = 1 << 15; @@ -1019,6 +1023,7 @@ class ContactsManager : public Actor { static constexpr int32 CHANNEL_FULL_FLAG_HAS_SLOW_MODE_DELAY = 1 << 17; static constexpr int32 CHANNEL_FULL_FLAG_HAS_SLOW_MODE_NEXT_SEND_DATE = 1 << 18; static constexpr int32 CHANNEL_FULL_FLAG_HAS_SCHEDULED_MESSAGES = 1 << 19; + static constexpr int32 CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS = 1 << 20; static constexpr int32 CHAT_INVITE_FLAG_IS_CHANNEL = 1 << 0; static constexpr int32 CHAT_INVITE_FLAG_IS_BROADCAST = 1 << 1; @@ -1409,9 +1414,9 @@ class ContactsManager : public Actor { tl_object_ptr input_check_password, Promise &&promise); - void get_channel_statistics_dc_id(DialogId dialog_id, Promise &&promise); + void get_channel_statistics_dc_id(DialogId dialog_id, bool for_full_statistics, Promise &&promise); - void get_channel_statistics_dc_id_impl(ChannelId channel_id, Promise &&promise); + void get_channel_statistics_dc_id_impl(ChannelId channel_id, bool for_full_statistics, Promise &&promise); void send_get_channel_stats_query(DcId dc_id, ChannelId channel_id, bool is_dark, Promise> &&promise); diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 0edb4559e..6d3396b7c 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -3252,8 +3252,9 @@ Status NotificationManager::process_push_notification_payload(string payload, bo 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*/, sender_user_id.get(), sender_access_hash, user_name, - string(), string(), string(), std::move(sender_photo), nullptr, 0, Auto(), string(), string()); + false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, sender_user_id.get(), + sender_access_hash, user_name, string(), string(), string(), std::move(sender_photo), nullptr, 0, Auto(), + string(), string()); td_->contacts_manager_->on_get_user(std::move(user), "process_push_notification_payload"); } @@ -3573,8 +3574,8 @@ void NotificationManager::add_message_push_notification( 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*/, sender_user_id.get(), 0, user_name, string(), string(), - string(), nullptr, nullptr, 0, Auto(), string(), string()); + false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/, sender_user_id.get(), 0, user_name, + string(), string(), string(), nullptr, nullptr, 0, Auto(), string(), string()); td_->contacts_manager_->on_get_user(std::move(user), "add_message_push_notification"); }