From 5c3bbc7bb9d1ac9e1a2cee8b0cd0352f8da96936 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 6 Jul 2023 19:15:00 +0300 Subject: [PATCH] Add getStoryNotificationSettingsExceptions. --- td/generate/scheme/td_api.tl | 5 +- td/telegram/NotificationSettingsManager.cpp | 63 +++++++++++++++++++++ td/telegram/NotificationSettingsManager.h | 2 + td/telegram/Td.cpp | 6 ++ td/telegram/Td.h | 2 + td/telegram/cli.cpp | 2 + 6 files changed, 79 insertions(+), 1 deletion(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 32958257a..d5bb9caa4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7226,7 +7226,7 @@ addSavedNotificationSound sound:InputFile = NotificationSound; removeSavedNotificationSound notification_sound_id:int64 = Ok; -//@description Returns list of chats with non-default notification settings +//@description Returns list of chats with non-default notification settings for new messages //@scope If specified, only chats from the scope will be returned; pass null to return chats from all scopes //@compare_sound Pass true to include in the response chats with only non-default sound getChatNotificationSettingsExceptions scope:NotificationSettingsScope compare_sound:Bool = Chats; @@ -7289,6 +7289,9 @@ loadActiveStories story_list:StoryList = Ok; //@description Toggles whether stories posted by the chat are available above chat lists @chat_id Identifier of the chat that posted stories @are_hidden Pass true to make the stories unavailable above the chat lists; pass false to make them available toggleChatStoriesAreHidden chat_id:int53 are_hidden:Bool = Ok; +//@description Returns list of chats with non-default notification settings for stories +getStoryNotificationSettingsExceptions = Chats; + //@description Returns the list of active stories posted by the given chat @chat_id Chat identifier getChatActiveStories chat_id:int53 = ActiveStories; diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index 24cb54dbf..8416d1003 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -283,6 +283,64 @@ class GetNotifySettingsExceptionsQuery final : public Td::ResultHandler { } }; +class GetStoryNotifySettingsExceptionsQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetStoryNotifySettingsExceptionsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send() { + int32 flags = telegram_api::account_getNotifyExceptions::COMPARE_STORIES_MASK; + send_query(G()->net_query_creator().create( + telegram_api::account_getNotifyExceptions(flags, false /*ignored*/, false /*ignored*/, nullptr))); + } + + 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 updates_ptr = result_ptr.move_as_ok(); + auto dialog_ids = UpdatesManager::get_update_notify_settings_dialog_ids(updates_ptr.get()); + vector> users; + vector> chats; + switch (updates_ptr->get_id()) { + case telegram_api::updatesCombined::ID: { + auto updates = static_cast(updates_ptr.get()); + users = std::move(updates->users_); + chats = std::move(updates->chats_); + reset_to_empty(updates->users_); + reset_to_empty(updates->chats_); + break; + } + case telegram_api::updates::ID: { + auto updates = static_cast(updates_ptr.get()); + users = std::move(updates->users_); + chats = std::move(updates->chats_); + reset_to_empty(updates->users_); + reset_to_empty(updates->chats_); + break; + } + } + td_->contacts_manager_->on_get_users(std::move(users), "GetStoryNotifySettingsExceptionsQuery"); + td_->contacts_manager_->on_get_chats(std::move(chats), "GetStoryNotifySettingsExceptionsQuery"); + for (auto &dialog_id : dialog_ids) { + td_->messages_manager_->force_create_dialog(dialog_id, "GetStoryNotifySettingsExceptionsQuery"); + } + auto chat_ids = td_->messages_manager_->get_chats_object(-1, dialog_ids, "GetStoryNotifySettingsExceptionsQuery"); + auto promise = PromiseCreator::lambda([promise = std::move(promise_), chat_ids = std::move(chat_ids)]( + Result) mutable { promise.set_value(std::move(chat_ids)); }); + td_->updates_manager_->on_get_updates(std::move(updates_ptr), std::move(promise)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class GetScopeNotifySettingsQuery final : public Td::ResultHandler { Promise promise_; NotificationSettingsScope scope_; @@ -1455,6 +1513,11 @@ void NotificationSettingsManager::get_notify_settings_exceptions(NotificationSet td_->create_handler(std::move(promise))->send(scope, filter_scope, compare_sound); } +void NotificationSettingsManager::get_story_notification_settings_exceptions( + Promise> &&promise) { + td_->create_handler(std::move(promise))->send(); +} + void NotificationSettingsManager::on_binlog_events(vector &&events) { if (G()->close_flag()) { return; diff --git a/td/telegram/NotificationSettingsManager.h b/td/telegram/NotificationSettingsManager.h index 95d2c7728..0cfeaa6c7 100644 --- a/td/telegram/NotificationSettingsManager.h +++ b/td/telegram/NotificationSettingsManager.h @@ -102,6 +102,8 @@ class NotificationSettingsManager final : public Actor { void get_notify_settings_exceptions(NotificationSettingsScope scope, bool filter_scope, bool compare_sound, Promise &&promise); + void get_story_notification_settings_exceptions(Promise> &&promise); + void init(); void on_binlog_events(vector &&events); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d0e2e1c3a..8d829483b 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6429,6 +6429,12 @@ void Td::on_request(uint64 id, const td_api::readChatList &request) { messages_manager_->read_all_dialogs_from_list(DialogListId(request.chat_list_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getStoryNotificationSettingsExceptions &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + notification_settings_manager_->get_story_notification_settings_exceptions(std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getChatActiveStories &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index d3dc98691..bc53776ac 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1002,6 +1002,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::readChatList &request); + void on_request(uint64 id, const td_api::getStoryNotificationSettingsExceptions &request); + void on_request(uint64 id, const td_api::getChatActiveStories &request); void on_request(uint64 id, const td_api::getChatPinnedStories &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index df672c300..8f5384903 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4064,6 +4064,8 @@ class CliClient final : public Actor { string limit; get_args(args, from_story_id, limit); send_request(td_api::make_object(from_story_id, as_limit(limit))); + } else if (op == "gsnse") { + send_request(td_api::make_object()); } else if (op == "gcas") { ChatId chat_id; get_args(args, chat_id);