Ignore errors when processing telegram_api::PrivacyRule.
This commit is contained in:
parent
95f2961c9b
commit
65e01ad063
|
@ -69,35 +69,29 @@ void PrivacyManager::set_privacy(tl_object_ptr<td_api::UserPrivacySetting> key,
|
|||
privacy_rules.get_input_privacy_rules(G()->td().get_actor_unsafe())));
|
||||
|
||||
info.has_set_query = true;
|
||||
send_with_promise(std::move(net_query),
|
||||
PromiseCreator::lambda([this, user_privacy_setting,
|
||||
promise = std::move(promise)](Result<NetQueryPtr> x_net_query) mutable {
|
||||
send_with_promise(
|
||||
std::move(net_query), PromiseCreator::lambda([this, user_privacy_setting, promise = std::move(promise)](
|
||||
Result<NetQueryPtr> x_net_query) mutable {
|
||||
promise.set_result([&]() -> Result<Unit> {
|
||||
get_info(user_privacy_setting).has_set_query = false;
|
||||
TRY_RESULT(net_query, std::move(x_net_query));
|
||||
TRY_RESULT(rules, fetch_result<telegram_api::account_setPrivacy>(std::move(net_query)));
|
||||
LOG(INFO) << "Receive " << to_string(rules);
|
||||
TRY_RESULT(privacy_rules, UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
G()->td().get_actor_unsafe(), std::move(rules)));
|
||||
auto privacy_rules =
|
||||
UserPrivacySettingRules::get_user_privacy_setting_rules(G()->td().get_actor_unsafe(), std::move(rules));
|
||||
do_update_privacy(user_privacy_setting, std::move(privacy_rules), true);
|
||||
return Unit();
|
||||
}());
|
||||
}));
|
||||
}
|
||||
|
||||
void PrivacyManager::update_privacy(tl_object_ptr<telegram_api::updatePrivacy> update) {
|
||||
void PrivacyManager::on_update_privacy(tl_object_ptr<telegram_api::updatePrivacy> update) {
|
||||
CHECK(update != nullptr);
|
||||
CHECK(update->key_ != nullptr);
|
||||
UserPrivacySetting user_privacy_setting(*update->key_);
|
||||
auto r_privacy_rules =
|
||||
auto privacy_rules =
|
||||
UserPrivacySettingRules::get_user_privacy_setting_rules(G()->td().get_actor_unsafe(), std::move(update->rules_));
|
||||
if (r_privacy_rules.is_error()) {
|
||||
LOG(INFO) << "Skip updatePrivacy: " << r_privacy_rules.error().message();
|
||||
auto &info = get_info(user_privacy_setting);
|
||||
info.is_synchronized = false;
|
||||
} else {
|
||||
do_update_privacy(user_privacy_setting, r_privacy_rules.move_as_ok(), true);
|
||||
}
|
||||
do_update_privacy(user_privacy_setting, std::move(privacy_rules), true);
|
||||
}
|
||||
|
||||
void PrivacyManager::on_get_result(UserPrivacySetting user_privacy_setting,
|
||||
|
|
|
@ -34,7 +34,7 @@ class PrivacyManager final : public NetQueryCallback {
|
|||
void set_privacy(tl_object_ptr<td_api::UserPrivacySetting> key, tl_object_ptr<td_api::userPrivacySettingRules> rules,
|
||||
Promise<Unit> promise);
|
||||
|
||||
void update_privacy(tl_object_ptr<telegram_api::updatePrivacy> update);
|
||||
void on_update_privacy(tl_object_ptr<telegram_api::updatePrivacy> update);
|
||||
|
||||
private:
|
||||
ActorShared<> parent_;
|
||||
|
|
|
@ -3932,7 +3932,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateEncryptedMessag
|
|||
}
|
||||
|
||||
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updatePrivacy> update, Promise<Unit> &&promise) {
|
||||
send_closure(td_->privacy_manager_, &PrivacyManager::update_privacy, std::move(update));
|
||||
send_closure(td_->privacy_manager_, &PrivacyManager::on_update_privacy, std::move(update));
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
|
|
|
@ -179,27 +179,31 @@ telegram_api::object_ptr<telegram_api::InputPrivacyRule> UserPrivacySettingRule:
|
|||
}
|
||||
}
|
||||
|
||||
Result<UserPrivacySettingRule> UserPrivacySettingRule::get_user_privacy_setting_rule(
|
||||
UserPrivacySettingRule UserPrivacySettingRule::get_user_privacy_setting_rule(
|
||||
Td *td, telegram_api::object_ptr<telegram_api::PrivacyRule> rule) {
|
||||
CHECK(rule != nullptr);
|
||||
UserPrivacySettingRule result(*rule);
|
||||
for (auto user_id : result.user_ids_) {
|
||||
td::remove_if(result.user_ids_, [td](UserId user_id) {
|
||||
if (!td->contacts_manager_->have_user(user_id)) {
|
||||
return Status::Error(500, "Receive inaccessible user from the server");
|
||||
LOG(ERROR) << "Receive unknown " << user_id << " from the server";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (auto chat_id_int : result.chat_ids_) {
|
||||
return false;
|
||||
});
|
||||
td::remove_if(result.chat_ids_, [td](int64 chat_id_int) {
|
||||
ChatId chat_id(chat_id_int);
|
||||
DialogId dialog_id(chat_id);
|
||||
if (!td->contacts_manager_->have_chat(chat_id)) {
|
||||
ChannelId channel_id(chat_id_int);
|
||||
dialog_id = DialogId(channel_id);
|
||||
if (!td->contacts_manager_->have_channel(channel_id)) {
|
||||
return Status::Error(500, "Receive inaccessible chat from the server");
|
||||
LOG(ERROR) << "Receive unknown group " << channel_id << " from the server";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
td->messages_manager_->force_create_dialog(dialog_id, "UserPrivacySettingRule");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -239,19 +243,18 @@ vector<UserId> UserPrivacySettingRule::get_restricted_user_ids() const {
|
|||
return {};
|
||||
}
|
||||
|
||||
Result<UserPrivacySettingRules> UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
UserPrivacySettingRules UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
Td *td, telegram_api::object_ptr<telegram_api::account_privacyRules> rules) {
|
||||
td->contacts_manager_->on_get_users(std::move(rules->users_), "on get privacy rules");
|
||||
td->contacts_manager_->on_get_chats(std::move(rules->chats_), "on get privacy rules");
|
||||
return get_user_privacy_setting_rules(td, std::move(rules->rules_));
|
||||
}
|
||||
|
||||
Result<UserPrivacySettingRules> UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
UserPrivacySettingRules UserPrivacySettingRules::get_user_privacy_setting_rules(
|
||||
Td *td, vector<telegram_api::object_ptr<telegram_api::PrivacyRule>> rules) {
|
||||
UserPrivacySettingRules result;
|
||||
for (auto &rule : rules) {
|
||||
TRY_RESULT(new_rule, UserPrivacySettingRule::get_user_privacy_setting_rule(td, std::move(rule)));
|
||||
result.rules_.push_back(new_rule);
|
||||
result.rules_.push_back(UserPrivacySettingRule::get_user_privacy_setting_rule(td, std::move(rule)));
|
||||
}
|
||||
if (!result.rules_.empty() && result.rules_.back().get_user_privacy_setting_rule_object(td)->get_id() ==
|
||||
td_api::userPrivacySettingRuleRestrictAll::ID) {
|
||||
|
|
|
@ -23,8 +23,8 @@ class UserPrivacySettingRule {
|
|||
|
||||
UserPrivacySettingRule(Td *td, const td_api::UserPrivacySettingRule &rule);
|
||||
|
||||
static Result<UserPrivacySettingRule> get_user_privacy_setting_rule(
|
||||
Td *td, telegram_api::object_ptr<telegram_api::PrivacyRule> rule);
|
||||
static UserPrivacySettingRule get_user_privacy_setting_rule(Td *td,
|
||||
telegram_api::object_ptr<telegram_api::PrivacyRule> rule);
|
||||
|
||||
td_api::object_ptr<td_api::UserPrivacySettingRule> get_user_privacy_setting_rule_object(Td *td) const;
|
||||
|
||||
|
@ -65,10 +65,10 @@ class UserPrivacySettingRules {
|
|||
public:
|
||||
UserPrivacySettingRules() = default;
|
||||
|
||||
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
||||
static UserPrivacySettingRules get_user_privacy_setting_rules(
|
||||
Td *td, telegram_api::object_ptr<telegram_api::account_privacyRules> rules);
|
||||
|
||||
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
||||
static UserPrivacySettingRules get_user_privacy_setting_rules(
|
||||
Td *td, vector<telegram_api::object_ptr<telegram_api::PrivacyRule>> rules);
|
||||
|
||||
static Result<UserPrivacySettingRules> get_user_privacy_setting_rules(
|
||||
|
|
Loading…
Reference in New Issue
Block a user