Support setting "is_location_visible" option before authorization.

This commit is contained in:
levlam 2022-08-19 14:16:53 +03:00
parent f99327ca50
commit 73f945bd8b
4 changed files with 25 additions and 23 deletions

View File

@ -3373,7 +3373,6 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent
G()->td_db()->get_binlog_pmc()->get("pending_location_visibility_expire_date");
if (!pending_location_visibility_expire_date_string.empty()) {
pending_location_visibility_expire_date_ = to_integer<int32>(pending_location_visibility_expire_date_string);
try_send_set_location_visibility_query();
}
update_is_location_visible();
LOG(INFO) << "Loaded location_visibility_expire_date = " << location_visibility_expire_date_
@ -3411,6 +3410,12 @@ ContactsManager::~ContactsManager() {
linked_channel_ids_, restricted_user_ids_, restricted_channel_ids_);
}
void ContactsManager::start_up() {
if (!pending_location_visibility_expire_date_) {
try_send_set_location_visibility_query();
}
}
void ContactsManager::tear_down() {
parent_.reset();
@ -6036,20 +6041,24 @@ void ContactsManager::set_location(const Location &location, Promise<Unit> &&pro
td_->create_handler<SearchDialogsNearbyQuery>(std::move(query_promise))->send(location, true, -1);
}
void ContactsManager::set_location_visibility() {
bool is_location_visible = td_->option_manager_->get_option_boolean("is_location_visible");
void ContactsManager::set_location_visibility(Td *td) {
bool is_location_visible = td->option_manager_->get_option_boolean("is_location_visible");
auto pending_location_visibility_expire_date = is_location_visible ? std::numeric_limits<int32>::max() : 0;
if (pending_location_visibility_expire_date_ == -1 &&
pending_location_visibility_expire_date == location_visibility_expire_date_) {
return;
}
if (pending_location_visibility_expire_date_ != pending_location_visibility_expire_date) {
pending_location_visibility_expire_date_ = pending_location_visibility_expire_date;
if (td->contacts_manager_ == nullptr) {
G()->td_db()->get_binlog_pmc()->set("pending_location_visibility_expire_date",
to_string(pending_location_visibility_expire_date));
update_is_location_visible();
return;
}
try_send_set_location_visibility_query();
if (td->contacts_manager_->pending_location_visibility_expire_date_ == -1 &&
pending_location_visibility_expire_date == td->contacts_manager_->location_visibility_expire_date_) {
return;
}
if (td->contacts_manager_->pending_location_visibility_expire_date_ != pending_location_visibility_expire_date) {
td->contacts_manager_->pending_location_visibility_expire_date_ = pending_location_visibility_expire_date;
G()->td_db()->get_binlog_pmc()->set("pending_location_visibility_expire_date",
to_string(pending_location_visibility_expire_date));
}
td->contacts_manager_->try_send_set_location_visibility_query();
}
void ContactsManager::try_send_set_location_visibility_query() {
@ -6060,6 +6069,7 @@ void ContactsManager::try_send_set_location_visibility_query() {
return;
}
LOG(INFO) << "Trying to send set location visibility query";
if (is_set_location_visibility_request_sent_) {
return;
}

View File

@ -324,7 +324,7 @@ class ContactsManager final : public Actor {
void set_location(const Location &location, Promise<Unit> &&promise);
void set_location_visibility();
static void set_location_visibility(Td *td);
void get_is_location_visible(Promise<Unit> &&promise);
@ -1687,6 +1687,8 @@ class ContactsManager final : public Actor {
void on_channel_participant_cache_timeout(ChannelId channel_id);
void start_up() final;
void tear_down() final;
Td *td_;

View File

@ -108,11 +108,6 @@ OptionManager::~OptionManager() = default;
void OptionManager::on_td_inited() {
is_td_inited_ = true;
if (have_pending_is_location_visible_) {
have_pending_is_location_visible_ = false;
td_->contacts_manager_->set_location_visibility();
}
for (auto &request : pending_get_options_) {
get_option(request.first, std::move(request.second));
}
@ -693,11 +688,7 @@ void OptionManager::set_option(const string &name, td_api::object_ptr<td_api::Op
return;
}
if (!is_bot && set_boolean_option("is_location_visible")) {
if (is_td_inited_) {
td_->contacts_manager_->set_location_visibility();
} else {
have_pending_is_location_visible_ = true;
}
ContactsManager::set_location_visibility(td_);
return;
}
break;

View File

@ -84,7 +84,6 @@ class OptionManager {
Td *td_;
bool is_td_inited_ = false;
bool have_pending_is_location_visible_ = false;
vector<std::pair<string, Promise<td_api::object_ptr<td_api::OptionValue>>>> pending_get_options_;
unique_ptr<TsSeqKeyValue> options_;