From 0dda4a53f30760e5a6c8c23047ce2f13f406fb8d Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 24 Apr 2024 17:33:06 +0300 Subject: [PATCH] Add td_api::updateReactionNotificationSettings. --- td/generate/scheme/td_api.tl | 3 ++ td/telegram/NotificationSettingsManager.cpp | 60 +++++++++++++++++++++ td/telegram/NotificationSettingsManager.h | 10 ++++ td/telegram/UpdatesManager.cpp | 1 + 4 files changed, 74 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5e79a5168..0c5932880 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6979,6 +6979,9 @@ updateForumTopicInfo chat_id:int53 info:forumTopicInfo = Update; //@description Notification settings for some type of chats were updated @scope Types of chats for which notification settings were updated @notification_settings The new notification settings updateScopeNotificationSettings scope:NotificationSettingsScope notification_settings:scopeNotificationSettings = Update; +//@description Notification settings for reactions were updated @notification_settings The new notification settings +updateReactionNotificationSettings notification_settings:reactionNotificationSettings = Update; + //@description A notification was changed @notification_group_id Unique notification group identifier @notification Changed notification updateNotification notification_group_id:int32 notification:notification = Update; diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index 0c0e1fb88..1d9da30b9 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -375,6 +375,34 @@ class GetScopeNotifySettingsQuery final : public Td::ResultHandler { } }; +class GetReactionsNotifySettingsQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit GetReactionsNotifySettingsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::account_getReactionsNotifySettings())); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + td_->notification_settings_manager_->on_update_reaction_notification_settings( + ReactionNotificationSettings(std::move(ptr))); + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class UpdateDialogNotifySettingsQuery final : public Td::ResultHandler { Promise promise_; DialogId dialog_id_; @@ -717,6 +745,12 @@ NotificationSettingsManager::get_update_scope_notification_settings_object(Notif get_notification_settings_scope_object(scope), get_scope_notification_settings_object(notification_settings)); } +td_api::object_ptr +NotificationSettingsManager::get_update_reaction_notification_settings_object() const { + return td_api::make_object( + reaction_notification_settings_.get_reaction_notification_settings_object()); +} + void NotificationSettingsManager::on_scope_unmute(NotificationSettingsScope scope) { if (td_->auth_manager_->is_bot()) { // just in case @@ -826,6 +860,30 @@ bool NotificationSettingsManager::update_scope_notification_settings(Notificatio return need_update_server; } +void NotificationSettingsManager::send_get_reaction_notification_settings_query(Promise &&promise) { + if (td_->auth_manager_->is_bot()) { + LOG(ERROR) << "Can't get reaction notification settings"; + return promise.set_error(Status::Error(500, "Wrong getReactionNotificationSettings query")); + } + + td_->create_handler(std::move(promise))->send(); +} + +void NotificationSettingsManager::on_update_reaction_notification_settings( + ReactionNotificationSettings reaction_notification_settings) { + CHECK(!td_->auth_manager_->is_bot()); + if (reaction_notification_settings == reaction_notification_settings_) { + return; + } + + VLOG(notifications) << "Update reaction notification settings from " << reaction_notification_settings_ << " to " + << reaction_notification_settings; + + reaction_notification_settings_ = std::move(reaction_notification_settings); + + send_closure(G()->td(), &Td::send_update, get_update_reaction_notification_settings_object()); +} + void NotificationSettingsManager::schedule_scope_unmute(NotificationSettingsScope scope, int32 mute_until, int32 unix_time) { if (mute_until >= unix_time && mute_until < unix_time + 366 * 86400) { @@ -1566,6 +1624,8 @@ void NotificationSettingsManager::get_current_state(vector &&peer_notify_settings); + void on_update_reaction_notification_settings(ReactionNotificationSettings reaction_notification_settings); + void add_saved_ringtone(td_api::object_ptr &&input_file, Promise> &&promise); @@ -92,6 +95,8 @@ class NotificationSettingsManager final : public Actor { Promise &&promise); void send_get_scope_notification_settings_query(NotificationSettingsScope scope, Promise &&promise); + void send_get_reaction_notification_settings_query(Promise &&promise); + void on_get_dialog_notification_settings_query_finished(DialogId dialog_id, MessageId top_thread_message_id, Status &&status); @@ -172,6 +177,9 @@ class NotificationSettingsManager final : public Actor { td_api::object_ptr get_update_scope_notification_settings_object( NotificationSettingsScope scope) const; + td_api::object_ptr get_update_reaction_notification_settings_object() + const; + td_api::object_ptr get_update_saved_notification_sounds_object() const; void on_scope_unmute(NotificationSettingsScope scope); @@ -203,6 +211,8 @@ class NotificationSettingsManager final : public Actor { ScopeNotificationSettings chats_notification_settings_; ScopeNotificationSettings channels_notification_settings_; + ReactionNotificationSettings reaction_notification_settings_; + MultiTimeout scope_unmute_timeout_{"ScopeUnmuteTimeout"}; int64 saved_ringtone_hash_ = 0; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 306edc1da..bc3428c29 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -2252,6 +2252,7 @@ void UpdatesManager::try_reload_data() { get_default_emoji_statuses(td_, Auto()); get_default_channel_emoji_statuses(td_, Auto()); td_->notification_settings_manager_->reload_saved_ringtones(Auto()); + td_->notification_settings_manager_->send_get_reaction_notification_settings_query(Auto()); td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Private, Auto()); td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Group,