Add ChangeAuthorizationSettingsOnServerLogEvent.
This commit is contained in:
parent
df563e781e
commit
e6fb913798
@ -12,12 +12,16 @@
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/LinkManager.h"
|
||||
#include "td/telegram/logevent/LogEvent.h"
|
||||
#include "td/telegram/logevent/LogEventHelper.h"
|
||||
#include "td/telegram/net/NetQueryCreator.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/TdDb.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/db/binlog/BinlogEvent.h"
|
||||
#include "td/db/binlog/BinlogHelper.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/base64.h"
|
||||
#include "td/utils/buffer.h"
|
||||
@ -822,24 +826,89 @@ void AccountManager::terminate_all_other_sessions(Promise<Unit> &&promise) {
|
||||
td_->create_handler<ResetAuthorizationsQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
class AccountManager::ChangeAuthorizationSettingsOnServerLogEvent {
|
||||
public:
|
||||
int64 hash_;
|
||||
bool set_encrypted_requests_disabled_;
|
||||
bool encrypted_requests_disabled_;
|
||||
bool set_call_requests_disabled_;
|
||||
bool call_requests_disabled_;
|
||||
bool confirm_;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(set_encrypted_requests_disabled_);
|
||||
STORE_FLAG(encrypted_requests_disabled_);
|
||||
STORE_FLAG(set_call_requests_disabled_);
|
||||
STORE_FLAG(call_requests_disabled_);
|
||||
STORE_FLAG(confirm_);
|
||||
END_STORE_FLAGS();
|
||||
td::store(hash_, storer);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser) {
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(set_encrypted_requests_disabled_);
|
||||
PARSE_FLAG(encrypted_requests_disabled_);
|
||||
PARSE_FLAG(set_call_requests_disabled_);
|
||||
PARSE_FLAG(call_requests_disabled_);
|
||||
PARSE_FLAG(confirm_);
|
||||
END_PARSE_FLAGS();
|
||||
td::parse(hash_, parser);
|
||||
}
|
||||
};
|
||||
|
||||
uint64 AccountManager::save_change_authorization_settings_on_server_log_event(
|
||||
int64 hash, bool set_encrypted_requests_disabled, bool encrypted_requests_disabled, bool set_call_requests_disabled,
|
||||
bool call_requests_disabled, bool confirm) {
|
||||
ChangeAuthorizationSettingsOnServerLogEvent log_event{hash,
|
||||
set_encrypted_requests_disabled,
|
||||
encrypted_requests_disabled,
|
||||
set_call_requests_disabled,
|
||||
call_requests_disabled,
|
||||
confirm};
|
||||
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer,
|
||||
get_log_event_storer(log_event));
|
||||
}
|
||||
|
||||
void AccountManager::change_authorization_settings_on_server(int64 hash, bool set_encrypted_requests_disabled,
|
||||
bool encrypted_requests_disabled,
|
||||
bool set_call_requests_disabled,
|
||||
bool call_requests_disabled, bool confirm,
|
||||
uint64 log_event_id, Promise<Unit> &&promise) {
|
||||
if (log_event_id == 0) {
|
||||
log_event_id = save_change_authorization_settings_on_server_log_event(
|
||||
hash, set_encrypted_requests_disabled, encrypted_requests_disabled, set_call_requests_disabled,
|
||||
call_requests_disabled, confirm);
|
||||
}
|
||||
|
||||
auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise));
|
||||
promise = std::move(new_promise); // to prevent self-move
|
||||
|
||||
td_->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(hash, set_encrypted_requests_disabled, encrypted_requests_disabled, set_call_requests_disabled,
|
||||
call_requests_disabled, confirm);
|
||||
}
|
||||
|
||||
void AccountManager::confirm_session(int64 session_id, Promise<Unit> &&promise) {
|
||||
if (!on_confirm_authorization(session_id)) {
|
||||
// the authorization can be from the list of active authorizations, but the update could have been lost
|
||||
// return promise.set_value(Unit());
|
||||
}
|
||||
td_->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(session_id, false, false, false, false, true);
|
||||
change_authorization_settings_on_server(session_id, false, false, false, false, true, 0, std::move(promise));
|
||||
}
|
||||
|
||||
void AccountManager::toggle_session_can_accept_calls(int64 session_id, bool can_accept_calls, Promise<Unit> &&promise) {
|
||||
td_->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(session_id, false, false, true, !can_accept_calls, false);
|
||||
change_authorization_settings_on_server(session_id, false, false, true, !can_accept_calls, false, 0,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void AccountManager::toggle_session_can_accept_secret_chats(int64 session_id, bool can_accept_secret_chats,
|
||||
Promise<Unit> &&promise) {
|
||||
td_->create_handler<ChangeAuthorizationSettingsQuery>(std::move(promise))
|
||||
->send(session_id, true, !can_accept_secret_chats, false, false, false);
|
||||
change_authorization_settings_on_server(session_id, true, !can_accept_secret_chats, false, false, false, 0,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void AccountManager::set_inactive_session_ttl_days(int32 authorization_ttl_days, Promise<Unit> &&promise) {
|
||||
@ -976,6 +1045,28 @@ void AccountManager::send_update_unconfirmed_session() const {
|
||||
send_closure(G()->td(), &Td::send_update, get_update_unconfirmed_session());
|
||||
}
|
||||
|
||||
void AccountManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
||||
if (G()->close_flag()) {
|
||||
return;
|
||||
}
|
||||
for (auto &event : events) {
|
||||
switch (event.type_) {
|
||||
case LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer: {
|
||||
ChangeAuthorizationSettingsOnServerLogEvent log_event;
|
||||
log_event_parse(log_event, event.get_data()).ensure();
|
||||
|
||||
change_authorization_settings_on_server(
|
||||
log_event.hash_, log_event.set_encrypted_requests_disabled_, log_event.encrypted_requests_disabled_,
|
||||
log_event.set_call_requests_disabled_, log_event.call_requests_disabled_, log_event.confirm_, event.id_,
|
||||
Auto());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG(FATAL) << "Unsupported log event type " << event.type_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AccountManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
||||
if (unconfirmed_authorizations_ != nullptr) {
|
||||
updates.push_back(get_update_unconfirmed_session());
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
struct BinlogEvent;
|
||||
|
||||
class Td;
|
||||
|
||||
class AccountManager final : public Actor {
|
||||
@ -68,12 +70,16 @@ class AccountManager final : public Actor {
|
||||
|
||||
bool on_confirm_authorization(int64 hash);
|
||||
|
||||
void on_binlog_events(vector<BinlogEvent> &&events);
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||
|
||||
private:
|
||||
class UnconfirmedAuthorization;
|
||||
class UnconfirmedAuthorizations;
|
||||
|
||||
class ChangeAuthorizationSettingsOnServerLogEvent;
|
||||
|
||||
void start_up() final;
|
||||
|
||||
void timeout_expired() final;
|
||||
@ -92,6 +98,16 @@ class AccountManager final : public Actor {
|
||||
|
||||
void send_update_unconfirmed_session() const;
|
||||
|
||||
uint64 save_change_authorization_settings_on_server_log_event(int64 hash, bool set_encrypted_requests_disabled,
|
||||
bool encrypted_requests_disabled,
|
||||
bool set_call_requests_disabled,
|
||||
bool call_requests_disabled, bool confirm);
|
||||
|
||||
void change_authorization_settings_on_server(int64 hash, bool set_encrypted_requests_disabled,
|
||||
bool encrypted_requests_disabled, bool set_call_requests_disabled,
|
||||
bool call_requests_disabled, bool confirm, uint64 log_event_id,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
Td *td_;
|
||||
ActorShared<> parent_;
|
||||
|
||||
|
@ -3791,6 +3791,8 @@ void Td::init(Parameters parameters, Result<TdDb::OpenedDatabase> r_opened_datab
|
||||
send_closure_later(secret_chats_manager_, &SecretChatsManager::replay_binlog_event, std::move(event));
|
||||
}
|
||||
|
||||
send_closure_later(account_manager_actor_, &AccountManager::on_binlog_events, std::move(events.to_account_manager));
|
||||
|
||||
send_closure_later(poll_manager_actor_, &PollManager::on_binlog_events, std::move(events.to_poll_manager));
|
||||
|
||||
send_closure_later(messages_manager_actor_, &MessagesManager::on_binlog_events,
|
||||
|
@ -144,6 +144,9 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
|
||||
case LogEvent::HandlerType::SaveAppLog:
|
||||
events.save_app_log_events.push_back(event.clone());
|
||||
break;
|
||||
case LogEvent::HandlerType::ChangeAuthorizationSettingsOnServer:
|
||||
events.to_account_manager.push_back(event.clone());
|
||||
break;
|
||||
case LogEvent::HandlerType::BinlogPmcMagic:
|
||||
binlog_pmc.external_init_handle(event);
|
||||
break;
|
||||
|
@ -72,10 +72,11 @@ class TdDb {
|
||||
vector<BinlogEvent> secret_chat_events;
|
||||
vector<BinlogEvent> web_page_events;
|
||||
vector<BinlogEvent> save_app_log_events;
|
||||
vector<BinlogEvent> to_poll_manager;
|
||||
vector<BinlogEvent> to_account_manager;
|
||||
vector<BinlogEvent> to_messages_manager;
|
||||
vector<BinlogEvent> to_notification_manager;
|
||||
vector<BinlogEvent> to_notification_settings_manager;
|
||||
vector<BinlogEvent> to_poll_manager;
|
||||
vector<BinlogEvent> to_story_manager;
|
||||
|
||||
int64 since_last_open = 0;
|
||||
|
@ -112,6 +112,7 @@ class LogEvent {
|
||||
LoadDialogExpiringStories = 0x402,
|
||||
SendStory = 0x403,
|
||||
EditStory = 0x404,
|
||||
ChangeAuthorizationSettingsOnServer = 0x500,
|
||||
ConfigPmcMagic = 0x1f18,
|
||||
BinlogPmcMagic = 0x4327
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user