Process blocked_my_stories_from flags.

This commit is contained in:
levlam 2023-07-28 16:19:05 +03:00
parent 840f2fd7cf
commit f0e59da1ff
5 changed files with 65 additions and 39 deletions

View File

@ -4738,6 +4738,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const {
STORE_FLAG(has_personal_photo);
STORE_FLAG(has_fallback_photo);
STORE_FLAG(has_pinned_stories);
STORE_FLAG(is_blocked_for_stories);
END_STORE_FLAGS();
if (has_about) {
store(about, storer);
@ -4821,6 +4822,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) {
PARSE_FLAG(has_personal_photo);
PARSE_FLAG(has_fallback_photo);
PARSE_FLAG(has_pinned_stories);
PARSE_FLAG(is_blocked_for_stories);
END_PARSE_FLAGS();
if (has_about) {
parse(about, parser);
@ -12598,7 +12600,8 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
td_->messages_manager_->on_update_dialog_message_ttl(DialogId(user_id), MessageTtl(user->ttl_period_));
td_->messages_manager_->on_update_dialog_is_blocked(DialogId(user_id), user->blocked_);
td_->messages_manager_->on_update_dialog_is_blocked(DialogId(user_id), user->blocked_,
user->blocked_my_stories_from_);
td_->messages_manager_->on_update_dialog_is_translatable(DialogId(user_id), !user->translations_disabled_);
@ -12607,7 +12610,7 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
UserFull *user_full = add_user_full(user_id);
user_full->expires_at = Time::now() + USER_FULL_EXPIRE_TIME;
on_update_user_full_is_blocked(user_full, user_id, user->blocked_);
on_update_user_full_is_blocked(user_full, user_id, user->blocked_, user->blocked_my_stories_from_);
on_update_user_full_common_chat_count(user_full, user_id, user->common_chats_count_);
on_update_user_full_need_phone_number_privacy_exception(user_full, user_id,
user->settings_->need_contacts_exception_);
@ -13155,7 +13158,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
on_update_channel_full_invite_link(channel_full, std::move(channel->exported_invite_));
td_->messages_manager_->on_update_dialog_is_blocked(DialogId(channel_id), channel->blocked_);
td_->messages_manager_->on_update_dialog_is_blocked(DialogId(channel_id), channel->blocked_, false);
td_->messages_manager_->on_update_dialog_last_pinned_message_id(
DialogId(channel_id), MessageId(ServerMessageId(channel->pinned_msg_id_)));
@ -13827,25 +13830,28 @@ 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) {
void ContactsManager::on_update_user_is_blocked(UserId user_id, bool is_blocked, bool is_blocked_for_stories) {
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 || user_full->is_blocked == is_blocked) {
if (user_full == nullptr) {
return;
}
on_update_user_full_is_blocked(user_full, user_id, is_blocked);
on_update_user_full_is_blocked(user_full, user_id, is_blocked, is_blocked_for_stories);
update_user_full(user_full, user_id, "on_update_user_is_blocked");
}
void ContactsManager::on_update_user_full_is_blocked(UserFull *user_full, UserId user_id, bool is_blocked) {
void ContactsManager::on_update_user_full_is_blocked(UserFull *user_full, UserId user_id, bool is_blocked,
bool is_blocked_for_stories) {
CHECK(user_full != nullptr);
if (user_full->is_blocked != is_blocked) {
LOG(INFO) << "Receive update user full is blocked with " << user_id << " and is_blocked = " << is_blocked;
if (user_full->is_blocked != is_blocked || user_full->is_blocked_for_stories != is_blocked_for_stories) {
LOG(INFO) << "Receive update user full is blocked with " << user_id << " and is_blocked = " << is_blocked << '/'
<< is_blocked_for_stories;
user_full->is_blocked = is_blocked;
user_full->is_blocked_for_stories = is_blocked_for_stories;
user_full->is_changed = true;
}
}
@ -14246,7 +14252,8 @@ void ContactsManager::drop_user_full(UserId user_id) {
user_full->photo = Photo();
user_full->personal_photo = Photo();
user_full->fallback_photo = Photo();
user_full->is_blocked = false;
// user_full->is_blocked = false;
// user_full->is_blocked_for_stories = false;
user_full->can_be_called = false;
user_full->supports_video_calls = false;
user_full->has_private_calls = false;

View File

@ -191,7 +191,7 @@ class ContactsManager final : public Actor {
void on_update_user_stories_hidden(UserId user_id, bool stories_hidden);
void on_update_user_online(UserId user_id, tl_object_ptr<telegram_api::UserStatus> &&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_is_blocked(UserId user_id, bool is_blocked, bool is_blocked_for_stories);
void on_update_user_has_pinned_stories(UserId user_id, bool has_pinned_stories);
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);
@ -858,6 +858,7 @@ class ContactsManager final : public Actor {
int32 common_chat_count = 0;
bool is_blocked = false;
bool is_blocked_for_stories = false;
bool can_be_called = false;
bool supports_video_calls = false;
bool has_private_calls = false;
@ -1435,7 +1436,8 @@ class ContactsManager final : public Actor {
void register_user_photo(User *u, UserId user_id, const Photo &photo);
static void on_update_user_full_is_blocked(UserFull *user_full, UserId user_id, bool is_blocked);
static void on_update_user_full_is_blocked(UserFull *user_full, UserId user_id, bool is_blocked,
bool is_blocked_for_stories);
static void on_update_user_full_common_chat_count(UserFull *user_full, UserId user_id, int32 common_chat_count);
static void on_update_user_full_commands(UserFull *user_full, UserId user_id,
vector<tl_object_ptr<telegram_api::botCommand>> &&bot_commands);

View File

@ -1661,7 +1661,7 @@ class ToggleDialogIsBlockedQuery final : public Td::ResultHandler {
LOG(ERROR) << "Receive error for ToggleDialogIsBlockedQuery: " << status;
}
if (!G()->close_flag()) {
td_->messages_manager_->on_update_dialog_is_blocked(dialog_id_, !is_blocked_);
td_->messages_manager_->on_update_dialog_is_blocked(dialog_id_, !is_blocked_, false);
td_->messages_manager_->get_dialog_info_full(dialog_id_, Auto(), "ToggleDialogIsBlockedQuery");
td_->messages_manager_->reget_dialog_action_bar(dialog_id_, "ToggleDialogIsBlockedQuery");
}
@ -5356,6 +5356,8 @@ void MessagesManager::Dialog::store(StorerT &storer) const {
STORE_FLAG(need_repair_unread_mention_count);
STORE_FLAG(is_background_inited);
STORE_FLAG(has_background);
STORE_FLAG(is_blocked_for_stories);
STORE_FLAG(is_is_blocked_for_stories_inited);
END_STORE_FLAGS();
}
@ -5627,11 +5629,15 @@ void MessagesManager::Dialog::parse(ParserT &parser) {
PARSE_FLAG(need_repair_unread_mention_count);
PARSE_FLAG(is_background_inited);
PARSE_FLAG(has_background);
PARSE_FLAG(is_blocked_for_stories);
PARSE_FLAG(is_is_blocked_for_stories_inited);
END_PARSE_FLAGS();
} else {
need_repair_action_bar = false;
is_available_reactions_inited = false;
is_background_inited = false;
is_blocked_for_stories = false;
is_is_blocked_for_stories_inited = false;
}
parse(last_new_message_id, parser);
@ -15772,9 +15778,9 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vector<tl_object_ptr<te
LOG(ERROR) << "Receive " << dialog->ttl_period_ << " as message auto-delete time in " << dialog_id;
dialog->ttl_period_ = 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
if (!d->is_is_blocked_for_stories_inited && !td_->auth_manager_->is_bot()) {
// asynchronously get is_blocked_for_stories from the server
// TODO add is_blocked/is_blocked_for_stories to telegram_api::dialog
reload_dialog_info_full(dialog_id, "on_get_dialogs init is_blocked");
} else if (!d->is_has_bots_inited && !td_->auth_manager_->is_bot()) {
// asynchronously get has_bots from the server
@ -19577,10 +19583,11 @@ Status MessagesManager::toggle_message_sender_is_blocked(const td_api::object_pt
if (is_blocked == d->is_blocked) {
return Status::OK();
}
set_dialog_is_blocked(d, is_blocked);
set_dialog_is_blocked(d, is_blocked, is_blocked ? false : d->is_blocked_for_stories);
} else {
CHECK(dialog_id.get_type() == DialogType::User);
td_->contacts_manager_->on_update_user_is_blocked(dialog_id.get_user_id(), is_blocked);
td_->contacts_manager_->on_update_user_is_blocked(dialog_id.get_user_id(), is_blocked,
is_blocked ? false : d->is_blocked_for_stories);
}
toggle_dialog_is_blocked_on_server(dialog_id, is_blocked, 0);
@ -31719,13 +31726,13 @@ void MessagesManager::set_dialog_is_translatable(Dialog *d, bool is_translatable
}
}
void MessagesManager::on_update_dialog_is_blocked(DialogId dialog_id, bool is_blocked) {
void MessagesManager::on_update_dialog_is_blocked(DialogId dialog_id, bool is_blocked, bool is_blocked_for_stories) {
if (!dialog_id.is_valid()) {
LOG(ERROR) << "Receive pinned message in invalid " << dialog_id;
return;
}
if (dialog_id.get_type() == DialogType::User) {
td_->contacts_manager_->on_update_user_is_blocked(dialog_id.get_user_id(), is_blocked);
td_->contacts_manager_->on_update_user_is_blocked(dialog_id.get_user_id(), is_blocked, is_blocked_for_stories);
}
auto d = get_dialog_force(dialog_id, "on_update_dialog_is_blocked");
@ -31734,33 +31741,36 @@ void MessagesManager::on_update_dialog_is_blocked(DialogId dialog_id, bool is_bl
return;
}
if (d->is_blocked == is_blocked) {
if (!d->is_is_blocked_inited) {
CHECK(is_blocked == false);
if (d->is_blocked == is_blocked && d->is_blocked_for_stories == is_blocked_for_stories) {
if (!d->is_is_blocked_for_stories_inited) {
CHECK(is_blocked_for_stories == false);
d->is_is_blocked_inited = true;
d->is_is_blocked_for_stories_inited = true;
on_dialog_updated(dialog_id, "on_update_dialog_is_blocked");
}
return;
}
set_dialog_is_blocked(d, is_blocked);
set_dialog_is_blocked(d, is_blocked, is_blocked_for_stories);
}
void MessagesManager::set_dialog_is_blocked(Dialog *d, bool is_blocked) {
void MessagesManager::set_dialog_is_blocked(Dialog *d, bool is_blocked, bool is_blocked_for_stories) {
CHECK(d != nullptr);
CHECK(d->is_blocked != is_blocked);
CHECK(d->is_blocked != is_blocked || d->is_blocked_for_stories != is_blocked_for_stories);
d->is_blocked = is_blocked;
d->is_blocked_for_stories = is_blocked_for_stories;
d->is_is_blocked_inited = true;
d->is_is_blocked_for_stories_inited = true;
on_dialog_updated(d->dialog_id, "set_dialog_is_blocked");
LOG(INFO) << "Set " << d->dialog_id << " is_blocked to " << is_blocked;
LOG(INFO) << "Set " << d->dialog_id << " is_blocked to " << is_blocked << '/' << is_blocked_for_stories;
LOG_CHECK(d->is_update_new_chat_sent) << "Wrong " << d->dialog_id << " in set_dialog_is_blocked";
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateChatIsBlocked>(get_chat_id_object(d->dialog_id, "updateChatIsBlocked"),
is_blocked));
if (d->dialog_id.get_type() == DialogType::User) {
td_->contacts_manager_->on_update_user_is_blocked(d->dialog_id.get_user_id(), is_blocked);
td_->contacts_manager_->on_update_user_is_blocked(d->dialog_id.get_user_id(), is_blocked, is_blocked_for_stories);
if (d->know_action_bar) {
if (is_blocked) {
@ -31774,11 +31784,12 @@ void MessagesManager::set_dialog_is_blocked(Dialog *d, bool is_blocked) {
}
td_->contacts_manager_->for_each_secret_chat_with_user(
d->dialog_id.get_user_id(), [this, is_blocked](SecretChatId secret_chat_id) {
d->dialog_id.get_user_id(), [this, is_blocked, is_blocked_for_stories](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);
if (d != nullptr && d->is_update_new_chat_sent &&
(d->is_blocked != is_blocked || d->is_blocked_for_stories != is_blocked_for_stories)) {
set_dialog_is_blocked(d, is_blocked, is_blocked_for_stories);
}
});
}
@ -36504,6 +36515,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&di
break;
case DialogType::Chat:
d->is_is_blocked_inited = true;
d->is_is_blocked_for_stories_inited = true;
d->is_background_inited = true;
break;
case DialogType::Channel: {
@ -36541,6 +36553,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&di
d->is_background_inited = true;
d->is_theme_name_inited = true;
d->is_is_blocked_inited = true;
d->is_is_blocked_for_stories_inited = true;
if (!d->is_folder_id_inited && !td_->auth_manager_->is_bot()) {
do_set_dialog_folder_id(
d, td_->contacts_manager_->get_secret_chat_initial_folder_id(dialog_id.get_secret_chat_id()));
@ -36683,8 +36696,9 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
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), "fix_new_dialog");
if (user_d != nullptr && d->is_blocked != user_d->is_blocked) {
set_dialog_is_blocked(d, user_d->is_blocked);
if (user_d != nullptr &&
(d->is_blocked != user_d->is_blocked || d->is_blocked_for_stories != user_d->is_blocked_for_stories)) {
set_dialog_is_blocked(d, user_d->is_blocked, user_d->is_blocked_for_stories);
}
}
}
@ -36700,9 +36714,9 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
send_get_dialog_query(dialog_id, Auto(), 0, "fix_new_dialog 20");
}
if (being_added_dialog_id_ != dialog_id && !d->is_is_blocked_inited && !td_->auth_manager_->is_bot()) {
// asynchronously get is_blocked from the server
reload_dialog_info_full(dialog_id, "fix_new_dialog init is_blocked");
if (being_added_dialog_id_ != dialog_id && !d->is_is_blocked_for_stories_inited && !td_->auth_manager_->is_bot()) {
// asynchronously get is_blocked_for_stories from the server
reload_dialog_info_full(dialog_id, "fix_new_dialog init is_blocked_for_stories");
} else if (being_added_dialog_id_ != dialog_id && !d->is_has_bots_inited && !td_->auth_manager_->is_bot()) {
// asynchronously get has_bots from the server
reload_dialog_info_full(dialog_id, "fix_new_dialog init has_bots");

View File

@ -301,7 +301,7 @@ class MessagesManager final : public Actor {
void update_is_translatable(bool new_is_premium);
void on_update_dialog_is_blocked(DialogId dialog_id, bool is_blocked);
void on_update_dialog_is_blocked(DialogId dialog_id, bool is_blocked, bool is_blocked_for_stories);
void on_update_dialog_last_pinned_message_id(DialogId dialog_id, MessageId last_pinned_message_id);
@ -1425,6 +1425,8 @@ class MessagesManager final : public Actor {
bool is_marked_as_unread = false;
bool is_blocked = false;
bool is_is_blocked_inited = false;
bool is_blocked_for_stories = false;
bool is_is_blocked_for_stories_inited = false;
bool last_sent_has_scheduled_messages = false;
bool has_scheduled_server_messages = false;
bool has_scheduled_database_messages = false;
@ -2598,7 +2600,7 @@ class MessagesManager final : public Actor {
void set_dialog_is_translatable(Dialog *d, bool is_translatable);
void set_dialog_is_blocked(Dialog *d, bool is_blocked);
void set_dialog_is_blocked(Dialog *d, bool is_blocked, bool is_blocked_for_stories);
void set_dialog_has_bots(Dialog *d, bool has_bots);

View File

@ -3865,7 +3865,8 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateRecentEmojiStat
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePeerBlocked> update, Promise<Unit> &&promise) {
td_->messages_manager_->on_update_dialog_is_blocked(DialogId(update->peer_id_), update->blocked_);
td_->messages_manager_->on_update_dialog_is_blocked(DialogId(update->peer_id_), update->blocked_,
update->blocked_my_stories_from_);
promise.set_value(Unit());
}