From 9ecb61965d9f4837d090ca05c82e23f69caf8901 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 20 Sep 2020 01:54:40 +0300 Subject: [PATCH] Move is_blcoked to Chat. GitOrigin-RevId: 7d1fc672c9487feba0839b7af669323464243ffc --- td/generate/scheme/td_api.tl | 9 ++- td/generate/scheme/td_api.tlo | Bin 181952 -> 182080 bytes td/telegram/ContactsManager.cpp | 66 ++++----------- td/telegram/ContactsManager.h | 7 -- td/telegram/MessagesManager.cpp | 138 +++++++++++++++++++++++--------- td/telegram/MessagesManager.h | 7 +- td/telegram/UpdatesManager.cpp | 6 +- 7 files changed, 131 insertions(+), 102 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index cd5464b59..d0f40c8ea 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -405,7 +405,6 @@ user id:int32 first_name:string last_name:string username:string phone_number:st //@description Contains full information about a user //@photo User profile photo; may be null -//@is_blocked True, if the user is blocked by the current user //@can_be_called True, if the user can be called //@supports_video_calls True, if a video call can be created with the user //@has_private_calls True, if the user can't be called due to their privacy settings @@ -413,7 +412,7 @@ user id:int32 first_name:string last_name:string username:string phone_number:st //@bio A short user bio @share_text For bots, the text that is included with the link when users share the bot //@group_in_common_count Number of group chats where both the other user and the current user are a member; 0 for the current user //@bot_info If the user is a bot, information about the bot; may be null -userFullInfo photo:chatPhoto is_blocked:Bool can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool need_phone_number_privacy_exception:Bool bio:string share_text:string group_in_common_count:int32 bot_info:botInfo = UserFullInfo; +userFullInfo photo:chatPhoto can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool need_phone_number_privacy_exception:Bool bio:string share_text:string group_in_common_count:int32 bot_info:botInfo = UserFullInfo; //@description Represents a list of users @total_count Approximate total count of users found @user_ids A list of user identifiers users total_count:int32 user_ids:vector = Users; @@ -823,6 +822,7 @@ chatPosition list:ChatList order:int64 is_pinned:Bool source:ChatSource = ChatPo //@last_message Last message in the chat; may be null //@positions Positions of the chat in chat lists //@is_marked_as_unread True, if the chat is marked as unread +//@is_blocked True, if the chat is blocked by the current user and private messages from the chat can't be received //@has_scheduled_messages True, if the chat has scheduled messages //@can_be_deleted_only_for_self True, if the chat messages can be deleted only for the current user while other users will continue to see the messages //@can_be_deleted_for_all_users True, if the chat messages can be deleted for all users @@ -838,7 +838,7 @@ chatPosition list:ChatList order:int64 is_pinned:Bool source:ChatSource = ChatPo //@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat //@draft_message A draft of a message in the chat; may be null //@client_data Contains application-specific data associated with the chat. (For example, the chat scroll position or local chat notification settings can be stored here.) Persistent if the message database is used -chat id:int53 type:ChatType title:string photo:chatPhotoInfo permissions:chatPermissions last_message:message positions:vector is_marked_as_unread:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat; +chat id:int53 type:ChatType title:string photo:chatPhotoInfo permissions:chatPermissions last_message:message positions:vector is_marked_as_unread:Bool is_blocked:Bool has_scheduled_messages:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_reported:Bool default_disable_notification:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:chatNotificationSettings action_bar:ChatActionBar pinned_message_id:int53 reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat; //@description Represents a list of chats @total_count Approximate total count of chats found @chat_ids List of chat identifiers chats total_count:int32 chat_ids:vector = Chats; @@ -3144,6 +3144,9 @@ updateChatPosition chat_id:int53 position:chatPosition = Update; //@description A chat was marked as unread or was read @chat_id Chat identifier @is_marked_as_unread New value of is_marked_as_unread updateChatIsMarkedAsUnread chat_id:int53 is_marked_as_unread:Bool = Update; +//@description A chat was blocked or unblocked @chat_id Chat identifier @is_blocked New value of is_blocked +updateChatIsBlocked chat_id:int53 is_blocked:Bool = Update; + //@description A chat's has_scheduled_messages field has changed @chat_id Chat identifier @has_scheduled_messages New value of has_scheduled_messages updateChatHasScheduledMessages chat_id:int53 has_scheduled_messages:Bool = Update; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index daedeb6d8bf6770e5f4a75aadb4db21d6831e5ee..6098f140eb6e3c49a125247792faf9d5f821654d 100644 GIT binary patch delta 2478 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 GIsX8O@PxJi diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5f5c80e13..911bb8f60 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3409,7 +3409,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const { bool has_photo = !photo.is_empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_about); - STORE_FLAG(is_blocked); + STORE_FLAG(false); STORE_FLAG(can_be_called); STORE_FLAG(has_private_calls); STORE_FLAG(can_pin_messages); @@ -3432,9 +3432,10 @@ void ContactsManager::UserFull::parse(ParserT &parser) { using td::parse; bool has_about; bool has_photo; + bool legacy_is_blocked; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_about); - PARSE_FLAG(is_blocked); + PARSE_FLAG(legacy_is_blocked); PARSE_FLAG(can_be_called); PARSE_FLAG(has_private_calls); PARSE_FLAG(can_pin_messages); @@ -3806,7 +3807,6 @@ void ContactsManager::ChannelFull::store(StorerT &storer) const { STORE_FLAG(has_photo); STORE_FLAG(is_can_view_statistics_inited); STORE_FLAG(can_view_statistics); - STORE_FLAG(is_blocked); END_STORE_FLAGS(); if (has_description) { store(description, storer); @@ -3900,7 +3900,6 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) { PARSE_FLAG(has_photo); PARSE_FLAG(is_can_view_statistics_inited); PARSE_FLAG(can_view_statistics); - PARSE_FLAG(is_blocked); END_PARSE_FLAGS(); if (has_description) { parse(description, parser); @@ -4663,13 +4662,13 @@ Status ContactsManager::set_user_is_blocked(UserId user_id, bool is_blocked) { td_->create_handler(std::move(query_promise)) ->send(user_id, std::move(input_user), is_blocked); - on_update_user_is_blocked(user_id, is_blocked); + td_->messages_manager_->on_update_dialog_is_blocked(DialogId(user_id), is_blocked); return Status::OK(); } void ContactsManager::on_set_user_is_blocked_failed(UserId user_id, bool is_blocked, Status error) { LOG(WARNING) << "Receive error for SetUserIsBlockedQuery: " << error; - on_update_user_is_blocked(user_id, !is_blocked); + td_->messages_manager_->on_update_dialog_is_blocked(DialogId(user_id), !is_blocked); reload_user_full(user_id); td_->messages_manager_->reget_dialog_action_bar(DialogId(user_id), "on_set_user_is_blocked_failed"); } @@ -9129,10 +9128,6 @@ void ContactsManager::update_user_full(UserFull *user_full, UserId user_id, bool td_->messages_manager_->drop_common_dialogs_cache(user_id); user_full->is_common_chat_count_changed = false; } - if (user_full->is_is_blocked_changed) { - td_->messages_manager_->on_dialog_user_is_blocked_updated(DialogId(user_id), user_full->is_blocked); - user_full->is_is_blocked_changed = false; - } user_full->need_send_update |= user_full->is_changed; user_full->need_save_to_database |= user_full->is_changed; @@ -9268,6 +9263,10 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u td_->messages_manager_->on_update_dialog_notify_settings(DialogId(user_id), std::move(user_full->notify_settings_), "on_get_user_full"); + { + bool is_blocked = (user_full->flags_ & USER_FULL_FLAG_IS_BLOCKED) != 0; + td_->messages_manager_->on_update_dialog_is_blocked(DialogId(user_id), is_blocked); + } { MessageId pinned_message_id; if ((user_full->flags_ & USER_FULL_FLAG_HAS_PINNED_MESSAGE) != 0) { @@ -9288,7 +9287,6 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u UserFull *user = add_user_full(user_id); user->expires_at = Time::now() + USER_FULL_EXPIRE_TIME; - on_update_user_full_is_blocked(user, user_id, (user_full->flags_ & USER_FULL_FLAG_IS_BLOCKED) != 0); on_update_user_full_common_chat_count(user, user_id, user_full->common_chats_count_); on_update_user_full_need_phone_number_privacy_exception( user, user_id, (user_full->settings_->flags_ & telegram_api::peerSettings::NEED_CONTACTS_EXCEPTION_MASK) != 0); @@ -9605,7 +9603,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c 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; - auto is_blocked = (channel_full->flags_ & CHANNEL_FULL_FLAG_IS_BLOCKED) != 0; StickerSetId sticker_set_id; if (channel_full->stickerset_ != nullptr) { sticker_set_id = @@ -9629,7 +9626,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->sticker_set_id != sticker_set_id || - channel->is_all_history_available != is_all_history_available || channel->is_blocked != is_blocked) { + 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; @@ -9643,7 +9640,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c channel->stats_dc_id = stats_dc_id; channel->is_all_history_available = is_all_history_available; channel->sticker_set_id = sticker_set_id; - channel->is_blocked = is_blocked; channel->is_changed = true; @@ -9674,6 +9670,10 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c on_update_channel_full_invite_link(channel, std::move(channel_full->exported_invite_)); + { + auto is_blocked = (channel_full->flags_ & CHANNEL_FULL_FLAG_IS_BLOCKED) != 0; + td_->messages_manager_->on_update_dialog_is_blocked(DialogId(channel_id), is_blocked); + } { MessageId pinned_message_id; if ((channel_full->flags_ & CHANNEL_FULL_FLAG_HAS_PINNED_MESSAGE) != 0) { @@ -10069,31 +10069,6 @@ void ContactsManager::on_update_user_local_was_online(User *u, UserId user_id, i } } -void ContactsManager::on_update_user_is_blocked(UserId user_id, bool is_blocked) { - LOG(INFO) << "Receive update user is blocked with " << user_id << " and is_blocked = " << is_blocked; - if (!user_id.is_valid()) { - LOG(ERROR) << "Receive invalid " << user_id; - return; - } - - UserFull *user_full = get_user_full_force(user_id); - if (user_full == nullptr) { - td_->messages_manager_->on_dialog_user_is_blocked_updated(DialogId(user_id), is_blocked); - return; - } - on_update_user_full_is_blocked(user_full, user_id, is_blocked); - update_user_full(user_full, user_id); -} - -void ContactsManager::on_update_user_full_is_blocked(UserFull *user_full, UserId user_id, bool is_blocked) { - CHECK(user_full != nullptr); - if (user_full->is_blocked != is_blocked) { - user_full->is_is_blocked_changed = true; - user_full->is_blocked = is_blocked; - user_full->is_changed = true; - } -} - void ContactsManager::on_update_user_common_chat_count(UserId user_id, int32 common_chat_count) { LOG(INFO) << "Receive " << common_chat_count << " common chat count with " << user_id; if (!user_id.is_valid()) { @@ -10369,7 +10344,6 @@ void ContactsManager::drop_user_full(UserId user_id) { user_full->expires_at = 0.0; user_full->photo = Photo(); - user_full->is_blocked = false; user_full->can_be_called = false; user_full->supports_video_calls = false; user_full->has_private_calls = false; @@ -10674,11 +10648,6 @@ bool ContactsManager::is_user_contact(const User *u, UserId user_id) const { return u != nullptr && u->is_contact && user_id != get_my_id(); } -bool ContactsManager::is_user_blocked(UserId user_id) { - const UserFull *user_full = get_user_full_force(user_id); - return user_full != nullptr && user_full->is_blocked; -} - void ContactsManager::on_get_channel_participants_success( ChannelId channel_id, ChannelParticipantsFilter filter, int32 offset, int32 limit, int64 random_id, int32 total_count, vector> &&participants) { @@ -14244,10 +14213,9 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U CHECK(user_full != nullptr); bool is_bot = is_user_bot(user_id); return make_tl_object( - get_chat_photo_object(td_->file_manager_.get(), user_full->photo), user_full->is_blocked, - user_full->can_be_called, user_full->supports_video_calls, user_full->has_private_calls, - user_full->need_phone_number_privacy_exception, is_bot ? string() : user_full->about, - is_bot ? user_full->about : string(), user_full->common_chat_count, + get_chat_photo_object(td_->file_manager_.get(), user_full->photo), user_full->can_be_called, + user_full->supports_video_calls, user_full->has_private_calls, user_full->need_phone_number_privacy_exception, + is_bot ? string() : user_full->about, is_bot ? user_full->about : string(), user_full->common_chat_count, is_bot ? get_bot_info_object(user_id) : nullptr); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 9c5908e0c..43e1b75ea 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -174,7 +174,6 @@ class ContactsManager : public Actor { void on_update_user_photo(UserId user_id, tl_object_ptr &&photo_ptr); void on_update_user_online(UserId user_id, tl_object_ptr &&status); void on_update_user_local_was_online(UserId user_id, int32 local_was_online); - void on_update_user_is_blocked(UserId user_id, bool is_blocked); void on_update_user_common_chat_count(UserId user_id, int32 common_chat_count); void on_update_user_need_phone_number_privacy_exception(UserId user_id, bool need_phone_number_privacy_exception); @@ -426,8 +425,6 @@ class ContactsManager : public Actor { bool is_user_contact(UserId user_id) const; - bool is_user_blocked(UserId user_id); - bool is_user_deleted(UserId user_id) const; bool is_user_bot(UserId user_id) const; @@ -681,14 +678,12 @@ class ContactsManager : public Actor { int32 common_chat_count = 0; - bool is_blocked = false; bool can_be_called = false; bool supports_video_calls = false; bool has_private_calls = false; bool can_pin_messages = false; bool need_phone_number_privacy_exception = false; - bool is_is_blocked_changed = true; bool is_common_chat_count_changed = true; bool is_changed = true; // have new changes that need to be sent to the client and database bool need_send_update = true; // have new changes that need only to be sent to the client @@ -863,7 +858,6 @@ class ContactsManager : public Actor { bool can_view_statistics = false; bool is_can_view_statistics_inited = false; bool is_all_history_available = true; - bool is_blocked = false; bool is_slow_mode_next_send_date_changed = true; bool is_changed = true; // have new changes that need to be sent to the client and database @@ -1158,7 +1152,6 @@ class ContactsManager : public Actor { void register_user_photo(User *u, UserId user_id, const Photo &photo); - void on_update_user_full_is_blocked(UserFull *user_full, UserId user_id, bool is_blocked); void on_update_user_full_common_chat_count(UserFull *user_full, UserId user_id, int32 common_chat_count); void on_update_user_full_need_phone_number_privacy_exception(UserFull *user_full, UserId user_id, bool need_phone_number_privacy_exception); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index ec54a338b..e28cffd13 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -4757,6 +4757,8 @@ void MessagesManager::Dialog::store(StorerT &storer) const { STORE_FLAG(has_distance); STORE_FLAG(hide_distance); STORE_FLAG(has_last_yet_unsent_message); + STORE_FLAG(is_blocked); + STORE_FLAG(is_is_blocked_inited); END_STORE_FLAGS(); } @@ -4923,6 +4925,8 @@ void MessagesManager::Dialog::parse(ParserT &parser) { PARSE_FLAG(has_distance); PARSE_FLAG(hide_distance); PARSE_FLAG(had_last_yet_unsent_message); + PARSE_FLAG(is_blocked); + PARSE_FLAG(is_is_blocked_inited); END_PARSE_FLAGS(); } else { is_folder_id_inited = false; @@ -4937,6 +4941,8 @@ void MessagesManager::Dialog::parse(ParserT &parser) { can_unarchive = false; hide_distance = false; had_last_yet_unsent_message = false; + is_blocked = false; + is_is_blocked_inited = false; } parse(last_new_message_id, parser); @@ -7830,9 +7836,9 @@ void MessagesManager::fix_dialog_action_bar(Dialog *d) { if (dialog_type == DialogType::User) { auto user_id = d->dialog_id.get_user_id(); bool is_me = user_id == td_->contacts_manager_->get_my_id(); - bool is_contact = td_->contacts_manager_->is_user_contact(user_id); - bool is_blocked = td_->contacts_manager_->is_user_blocked(user_id); + bool is_blocked = d->is_blocked; bool is_deleted = td_->contacts_manager_->is_user_deleted(user_id); + bool is_contact = td_->contacts_manager_->is_user_contact(user_id); if (is_me || is_blocked) { d->can_report_spam = false; d->can_unarchive = false; @@ -13413,6 +13419,11 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vectorunread_mentions_count_ = 0; } + if (!d->is_is_blocked_inited && !td_->auth_manager_->is_bot()) { + // asynchronously get is_blocked from the server + // TODO add is_blocked to telegram_api::dialog + get_dialog_info_full(dialog_id, Auto()); + } if (!d->is_pinned_message_id_inited && !td_->auth_manager_->is_bot()) { // asynchronously get dialog pinned message from the server // TODO add pinned_message_id to telegram_api::dialog @@ -18366,8 +18377,8 @@ td_api::object_ptr MessagesManager::get_chat_object(const Dialog * get_chat_photo_info_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)), get_dialog_permissions(d->dialog_id).get_chat_permissions_object(), get_message_object(d->dialog_id, get_message(d, d->last_message_id)), get_chat_positions_object(d), - d->is_marked_as_unread, get_dialog_has_scheduled_messages(d), can_delete_for_self, can_delete_for_all_users, - can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message, + d->is_marked_as_unread, d->is_blocked, get_dialog_has_scheduled_messages(d), can_delete_for_self, + can_delete_for_all_users, can_report_dialog(d->dialog_id), d->notification_settings.silent_send_message, d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(), d->last_read_outbox_message_id.get(), d->unread_mention_count, get_chat_notification_settings_object(&d->notification_settings), get_chat_action_bar_object(d), @@ -27084,6 +27095,71 @@ void MessagesManager::set_dialog_is_marked_as_unread(Dialog *d, bool is_marked_a } } +void MessagesManager::on_update_dialog_is_blocked(DialogId dialog_id, bool is_blocked) { + if (!dialog_id.is_valid()) { + LOG(ERROR) << "Receive pinned message in invalid " << dialog_id; + return; + } + + auto d = get_dialog_force(dialog_id); + if (d == nullptr) { + // nothing to do + return; + } + + if (d->is_blocked == is_blocked) { + if (!d->is_is_blocked_inited) { + CHECK(is_blocked == false); + d->is_is_blocked_inited = true; + on_dialog_updated(dialog_id, "on_update_dialog_is_blocked"); + } + return; + } + + set_dialog_is_blocked(d, is_blocked); +} + +void MessagesManager::set_dialog_is_blocked(Dialog *d, bool is_blocked) { + CHECK(d != nullptr); + CHECK(d->is_blocked != is_blocked); + d->is_blocked = is_blocked; + d->is_is_blocked_inited = true; + on_dialog_updated(d->dialog_id, "set_dialog_is_blocked"); + + LOG(INFO) << "Set " << d->dialog_id << " is_blocked to " << is_blocked; + LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in set_dialog_is_blocked"; + send_closure(G()->td(), &Td::send_update, + make_tl_object(d->dialog_id.get(), is_blocked)); + + if (d->dialog_id.get_type() == DialogType::User) { + if (d->know_action_bar) { + if (is_blocked) { + if (d->can_report_spam || d->can_share_phone_number || d->can_block_user || d->can_add_contact || + d->can_unarchive || d->distance >= 0) { + d->can_report_spam = false; + d->can_share_phone_number = false; + d->can_block_user = false; + d->can_add_contact = false; + d->can_unarchive = false; + d->distance = -1; + send_update_chat_action_bar(d); + } + } else { + repair_dialog_action_bar(d, "on_dialog_user_is_blocked_updated"); + } + } + + td_->contacts_manager_->for_each_secret_chat_with_user( + d->dialog_id.get_user_id(), [this, is_blocked](SecretChatId secret_chat_id) { + DialogId dialog_id(secret_chat_id); + auto d = get_dialog(dialog_id); // must not create the dialog + if (d != nullptr && d->is_update_new_chat_sent && d->is_blocked != is_blocked) { + set_dialog_is_blocked(d, is_blocked); + } + }); + } +} + void MessagesManager::on_update_dialog_pinned_message_id(DialogId dialog_id, MessageId pinned_message_id) { if (!dialog_id.is_valid()) { LOG(ERROR) << "Receive pinned message in invalid " << dialog_id; @@ -27433,29 +27509,6 @@ void MessagesManager::on_dialog_user_is_contact_updated(DialogId dialog_id, bool } } -void MessagesManager::on_dialog_user_is_blocked_updated(DialogId dialog_id, bool is_blocked) { - CHECK(dialog_id.get_type() == DialogType::User); - auto d = get_dialog(dialog_id); // called from update_user_full, must not create the dialog - if (d != nullptr && d->is_update_new_chat_sent) { - if (d->know_action_bar) { - if (is_blocked) { - if (d->can_report_spam || d->can_share_phone_number || d->can_block_user || d->can_add_contact || - d->can_unarchive || d->distance >= 0) { - d->can_report_spam = false; - d->can_share_phone_number = false; - d->can_block_user = false; - d->can_add_contact = false; - d->can_unarchive = false; - d->distance = -1; - send_update_chat_action_bar(d); - } - } else { - repair_dialog_action_bar(d, "on_dialog_user_is_blocked_updated"); - } - } - } -} - void MessagesManager::on_dialog_user_is_deleted_updated(DialogId dialog_id, bool is_deleted) { CHECK(dialog_id.get_type() == DialogType::User); auto d = get_dialog(dialog_id); // called from update_user, must not create the dialog @@ -31389,10 +31442,12 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr &&d, d->is_last_read_inbox_message_id_inited = true; d->is_last_read_outbox_message_id_inited = true; d->is_pinned_message_id_inited = true; + d->is_is_blocked_inited = true; if (!d->is_folder_id_inited && !td_->auth_manager_->is_bot()) { do_set_dialog_folder_id( d.get(), td_->contacts_manager_->get_secret_chat_initial_folder_id(dialog_id.get_secret_chat_id())); } + break; case DialogType::None: default: @@ -31450,12 +31505,28 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab auto dialog_id = d->dialog_id; auto dialog_type = dialog_id.get_type(); + if (!td_->auth_manager_->is_bot() && dialog_type == DialogType::SecretChat) { + auto user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()); + if (user_id.is_valid()) { + force_create_dialog(DialogId(user_id), "add chat with user to load/store action_bar and is_blocked"); + + Dialog *user_d = get_dialog_force(DialogId(user_id)); + if (user_d != nullptr && d->is_blocked != user_d->is_blocked) { + set_dialog_is_blocked(d, user_d->is_blocked); + } + } + } + if (being_added_dialog_id_ != dialog_id && !td_->auth_manager_->is_bot() && !is_dialog_inited(d) && dialog_type != DialogType::SecretChat && have_input_peer(dialog_id, AccessRights::Read)) { // asynchronously get dialog from the server send_get_dialog_query(dialog_id, Auto()); } + if (being_added_dialog_id_ != dialog_id && !d->is_is_blocked_inited && !td_->auth_manager_->is_bot()) { + // asynchronously get is_blocked from the server + get_dialog_info_full(dialog_id, Auto()); + } if (being_added_dialog_id_ != dialog_id && !d->is_pinned_message_id_inited && (dialog_id == get_my_dialog_id() || dialog_type != DialogType::User) && !td_->auth_manager_->is_bot()) { // asynchronously get dialog pinned message from the server @@ -31466,17 +31537,10 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab // asynchronously get dialog folder id from the server get_dialog_info_full(dialog_id, Auto()); } - if (!d->know_action_bar && !td_->auth_manager_->is_bot() && dialog_id != get_my_dialog_id() && - have_input_peer(dialog_id, AccessRights::Read)) { + if (!d->know_action_bar && !td_->auth_manager_->is_bot() && dialog_type != DialogType::SecretChat && + dialog_id != get_my_dialog_id() && have_input_peer(dialog_id, AccessRights::Read)) { // asynchronously get action bar from the server - if (dialog_type == DialogType::SecretChat) { - auto user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id()); - if (user_id.is_valid()) { - force_create_dialog(DialogId(user_id), "add chat with user to load/store action_bar"); - } - } else { - reget_dialog_action_bar(dialog_id, "fix_new_dialog"); - } + reget_dialog_action_bar(dialog_id, "fix_new_dialog"); } if (d->notification_settings.is_synchronized && !d->notification_settings.is_use_default_fixed && diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 73e01ae00..1d0418558 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -312,6 +312,8 @@ class MessagesManager : public Actor { void on_update_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread); + void on_update_dialog_is_blocked(DialogId dialog_id, bool is_blocked); + void on_update_dialog_pinned_message_id(DialogId dialog_id, MessageId pinned_message_id); void on_update_dialog_has_scheduled_server_messages(DialogId dialog_id, bool has_scheduled_server_messages); @@ -751,7 +753,6 @@ class MessagesManager : public Actor { void on_dialog_permissions_updated(DialogId dialog_id); void on_dialog_user_is_contact_updated(DialogId dialog_id, bool is_contact); - void on_dialog_user_is_blocked_updated(DialogId dialog_id, bool is_blocked); void on_dialog_user_is_deleted_updated(DialogId dialog_id, bool is_deleted); void on_dialog_linked_channel_updated(DialogId dialog_id, ChannelId old_linked_channel_id, @@ -1204,6 +1205,8 @@ class MessagesManager : public Actor { bool need_repair_server_unread_count = false; bool need_repair_channel_server_unread_count = false; bool is_marked_as_unread = false; + bool is_blocked = false; + bool is_is_blocked_inited = false; bool last_sent_has_scheduled_messages = false; bool has_scheduled_server_messages = false; bool has_scheduled_database_messages = false; @@ -2229,6 +2232,8 @@ class MessagesManager : public Actor { void set_dialog_is_marked_as_unread(Dialog *d, bool is_marked_as_unread); + void set_dialog_is_blocked(Dialog *d, bool is_blocked); + void set_dialog_pinned_message_id(Dialog *d, MessageId pinned_message_id); void repair_dialog_scheduled_messages(Dialog *d); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 92593ba4d..a89c39a34 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1971,11 +1971,7 @@ void UpdatesManager::on_update(tl_object_ptr upda } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { - DialogId dialog_id(update->peer_id_); - if (dialog_id.get_type() != DialogType::User) { - return; - } - td_->contacts_manager_->on_update_user_is_blocked(dialog_id.get_user_id(), update->blocked_); + td_->messages_manager_->on_update_dialog_is_blocked(DialogId(update->peer_id_), update->blocked_); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) {