Support updateTermsOfService in getCurrentState.
GitOrigin-RevId: b12f653432e0ee5b9ed3c7a7e8cb39e6dec7800b
This commit is contained in:
parent
e1812c6531
commit
8e0f49dc62
@ -3169,17 +3169,26 @@ void Td::on_update_status_success(bool is_online) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::updateTermsOfService> Td::get_update_terms_of_service_object() const {
|
||||||
|
auto terms_of_service = pending_terms_of_service_.get_terms_of_service_object();
|
||||||
|
if (terms_of_service == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return td_api::make_object<td_api::updateTermsOfService>(pending_terms_of_service_.get_id().str(),
|
||||||
|
std::move(terms_of_service));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_get_terms_of_service(Result<std::pair<int32, TermsOfService>> result, bool dummy) {
|
void Td::on_get_terms_of_service(Result<std::pair<int32, TermsOfService>> result, bool dummy) {
|
||||||
int32 expires_in = 0;
|
int32 expires_in = 0;
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
expires_in = Random::fast(10, 60);
|
expires_in = Random::fast(10, 60);
|
||||||
} else {
|
} else {
|
||||||
auto terms = std::move(result.ok().second);
|
pending_terms_of_service_ = std::move(result.ok().second);
|
||||||
if (terms.get_id().empty()) {
|
auto update = get_update_terms_of_service_object();
|
||||||
|
if (update == nullptr) {
|
||||||
expires_in = min(max(result.ok().first, G()->unix_time() + 60) - G()->unix_time(), 86400);
|
expires_in = min(max(result.ok().first, G()->unix_time() + 60) - G()->unix_time(), 86400);
|
||||||
} else {
|
} else {
|
||||||
send_update(
|
send_update(std::move(update));
|
||||||
make_tl_object<td_api::updateTermsOfService>(terms.get_id().str(), terms.get_terms_of_service_object()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (expires_in > 0) {
|
if (expires_in > 0) {
|
||||||
@ -3188,6 +3197,10 @@ void Td::on_get_terms_of_service(Result<std::pair<int32, TermsOfService>> result
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Td::schedule_get_terms_of_service(int32 expires_in) {
|
void Td::schedule_get_terms_of_service(int32 expires_in) {
|
||||||
|
if (expires_in == 0) {
|
||||||
|
// drop pending Terms of Service after successful accept
|
||||||
|
pending_terms_of_service_ = TermsOfService();
|
||||||
|
}
|
||||||
if (!close_flag_ && !auth_manager_->is_bot()) {
|
if (!close_flag_ && !auth_manager_->is_bot()) {
|
||||||
alarm_timeout_.set_timeout_in(TERMS_OF_SERVICE_ALARM_ID, expires_in);
|
alarm_timeout_.set_timeout_in(TERMS_OF_SERVICE_ALARM_ID, expires_in);
|
||||||
}
|
}
|
||||||
@ -4605,6 +4618,11 @@ void Td::on_request(uint64 id, const td_api::getCurrentState &request) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto update_terms_of_service = get_update_terms_of_service_object();
|
||||||
|
if (update_terms_of_service != nullptr) {
|
||||||
|
updates.push_back(std::move(update_terms_of_service));
|
||||||
|
}
|
||||||
|
|
||||||
// send response synchronously to prevent "Request aborted" or other changes of the current state
|
// send response synchronously to prevent "Request aborted" or other changes of the current state
|
||||||
send_result(id, td_api::make_object<td_api::updates>(std::move(updates)));
|
send_result(id, td_api::make_object<td_api::updates>(std::move(updates)));
|
||||||
}
|
}
|
||||||
|
@ -255,6 +255,8 @@ class Td final : public NetQueryCallback {
|
|||||||
std::unordered_map<int64, uint64> pending_alarms_;
|
std::unordered_map<int64, uint64> pending_alarms_;
|
||||||
MultiTimeout alarm_timeout_{"AlarmTimeout"};
|
MultiTimeout alarm_timeout_{"AlarmTimeout"};
|
||||||
|
|
||||||
|
TermsOfService pending_terms_of_service_;
|
||||||
|
|
||||||
vector<std::pair<uint64, td_api::object_ptr<td_api::Function>>> pending_preauthentication_requests_;
|
vector<std::pair<uint64, td_api::object_ptr<td_api::Function>>> pending_preauthentication_requests_;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -265,6 +267,8 @@ class Td final : public NetQueryCallback {
|
|||||||
static void on_alarm_timeout_callback(void *td_ptr, int64 alarm_id);
|
static void on_alarm_timeout_callback(void *td_ptr, int64 alarm_id);
|
||||||
void on_alarm_timeout(int64 alarm_id);
|
void on_alarm_timeout(int64 alarm_id);
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::updateTermsOfService> get_update_terms_of_service_object() const;
|
||||||
|
|
||||||
void on_get_terms_of_service(Result<std::pair<int32, TermsOfService>> result, bool dummy);
|
void on_get_terms_of_service(Result<std::pair<int32, TermsOfService>> result, bool dummy);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
Loading…
Reference in New Issue
Block a user