diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index ee980d5f..9f369a92 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -69,6 +69,35 @@ class SetContactSignUpNotificationQuery : public Td::ResultHandler { } }; +class GetContactSignUpNotificationQuery : public Td::ResultHandler { + Promise promise_; + + public: + explicit GetContactSignUpNotificationQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(create_storer(telegram_api::account_getContactSignUpNotification()))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + td->notification_manager_->on_get_disable_contact_registered_notifications(result_ptr.ok()); + promise_.set_value(Unit()); + } + + void on_error(uint64 id, Status status) override { + if (!G()->close_flag() || 1) { + LOG(ERROR) << "Receive error for get contact sign up notification: " << status; + } + promise_.set_error(std::move(status)); + } +}; + NotificationManager::NotificationManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { flush_pending_notifications_timeout_.set_callback(on_flush_pending_notifications_timeout_callback); flush_pending_notifications_timeout_.set_callback_data(static_cast(this)); @@ -2106,19 +2135,31 @@ void NotificationManager::on_notification_default_delay_changed() { } void NotificationManager::on_disable_contact_registered_notifications_changed() { - auto disable_contact_registered_notifications = - G()->shared_config().get_option_boolean("disable_contact_registered_notifications"); + auto is_disabled = G()->shared_config().get_option_boolean("disable_contact_registered_notifications"); - if (disable_contact_registered_notifications == disable_contact_registered_notifications_) { + if (is_disabled == disable_contact_registered_notifications_) { return; } - disable_contact_registered_notifications_ = disable_contact_registered_notifications; + disable_contact_registered_notifications_ = is_disabled; if (contact_registered_notifications_sync_state_ == SyncState::Completed) { run_contact_registered_notifications_sync(); } } +void NotificationManager::on_get_disable_contact_registered_notifications(bool is_disabled) { + if (disable_contact_registered_notifications_ == is_disabled) { + return; + } + disable_contact_registered_notifications_ = is_disabled; + + if (is_disabled) { + G()->shared_config().set_option_boolean("disable_contact_registered_notifications", is_disabled); + } else { + G()->shared_config().set_option_empty("disable_contact_registered_notifications"); + } +} + void NotificationManager::set_contact_registered_notifications_sync_state(SyncState new_state) { contact_registered_notifications_sync_state_ = new_state; string value; @@ -2161,6 +2202,10 @@ void NotificationManager::on_contact_registered_notifications_sync(bool is_disab } } +void NotificationManager::get_disable_contact_registered_notifications(Promise &&promise) { + td_->create_handler(std::move(promise))->send(); +} + void NotificationManager::process_push_notification(string payload, Promise &&promise) { if (is_disabled()) { promise.set_value(Unit()); diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 188f0750..24a4a54f 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -79,6 +79,8 @@ class NotificationManager : public Actor { void remove_call_notification(DialogId dialog_id, CallId call_id); + void get_disable_contact_registered_notifications(Promise &&promise); + void on_notification_group_count_max_changed(bool send_updates); void on_notification_group_size_max_changed(); @@ -91,6 +93,8 @@ class NotificationManager : public Actor { void on_disable_contact_registered_notifications_changed(); + void on_get_disable_contact_registered_notifications(bool is_disabled); + void process_push_notification(string payload, Promise &&promise); static Result get_push_receiver_id(string push); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7a0ae975..9728da38 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6249,8 +6249,21 @@ void Td::on_request(uint64 id, td_api::getOption &request) { CLEAN_INPUT_STRING(request.name_); tl_object_ptr option_value; + bool is_bot = auth_manager_ != nullptr && auth_manager_->is_authorized() && auth_manager_->is_bot(); switch (request.name_[0]) { // all these options should be added to getCurrentState + case 'd': + if (!is_bot && request.name_ == "disable_contact_registered_notifications") { + auto promise = PromiseCreator::lambda([actor_id = actor_id(this), id](Result &&result) { + // the option is already updated on success, ignore errors + send_closure(actor_id, &Td::send_result, id, + G()->shared_config().get_option_value("disable_contact_registered_notifications")); + }); + send_closure(notification_manager_actor_, &NotificationManager::get_disable_contact_registered_notifications, + std::move(promise)); + return; + } + break; case 'o': if (request.name_ == "online") { option_value = make_tl_object(is_online_);