Support getOption for "disable_contact_registered_notifications".
GitOrigin-RevId: 5bcfaab65cc7a25fcb8c99ceb8e6fe9c01b714e1
This commit is contained in:
parent
ec692e98e4
commit
fa89033923
@ -69,6 +69,35 @@ class SetContactSignUpNotificationQuery : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class GetContactSignUpNotificationQuery : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit GetContactSignUpNotificationQuery(Promise<Unit> &&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<telegram_api::account_getContactSignUpNotification>(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<void *>(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<Unit> &&promise) {
|
||||
td_->create_handler<GetContactSignUpNotificationQuery>(std::move(promise))->send();
|
||||
}
|
||||
|
||||
void NotificationManager::process_push_notification(string payload, Promise<Unit> &&promise) {
|
||||
if (is_disabled()) {
|
||||
promise.set_value(Unit());
|
||||
|
@ -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<Unit> &&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<Unit> &&promise);
|
||||
|
||||
static Result<int64> get_push_receiver_id(string push);
|
||||
|
@ -6249,8 +6249,21 @@ void Td::on_request(uint64 id, td_api::getOption &request) {
|
||||
CLEAN_INPUT_STRING(request.name_);
|
||||
|
||||
tl_object_ptr<td_api::OptionValue> 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<Unit> &&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<td_api::optionValueBoolean>(is_online_);
|
||||
|
Reference in New Issue
Block a user