diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a98193069..1726c85d3 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7169,6 +7169,9 @@ readChatList chat_list:ChatList = Ok; //@is_pinned Pass true to keep the story accessible after 24 hours sendStory content:InputStoryContent caption:formattedText privacy_rules:userPrivacySettingRules is_pinned:Bool = Story; +//@description Changes privacy rules of a previously sent story @story_id Identifier of the story @privacy_rules The new privacy rules for the story +setStoryPrivacyRules story_id:int32 privacy_rules:userPrivacySettingRules = Ok; + //@description Returns the list of pinned stories of a given user. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id). //-For optimal performance, the number of returned stories is chosen by TDLib //@user_id User identifier diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 37d3e464c..08abd7138 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -128,6 +128,36 @@ class GetUserStoriesQuery final : public Td::ResultHandler { } }; +class EditStoryPrivacyQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit EditStoryPrivacyQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(StoryId story_id, UserPrivacySettingRules &&privacy_rules) { + int32 flags = telegram_api::stories_editStory::PRIVACY_RULES_MASK; + send_query(G()->net_query_creator().create(telegram_api::stories_editStory( + flags, story_id.get(), nullptr, string(), vector>(), + privacy_rules.get_input_privacy_rules(td_)))); + } + + 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(); + LOG(DEBUG) << "Receive result for EditStoryPrivacyQuery: " << to_string(ptr); + td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class StoryManager::SendStoryQuery final : public Td::ResultHandler { FileId file_id_; unique_ptr pending_story_; @@ -633,4 +663,17 @@ void StoryManager::on_send_story_file_part_missing(unique_ptr &&pe {bad_part}); } +void StoryManager::set_story_privacy_rules(StoryId story_id, + td_api::object_ptr &&rules, + Promise &&promise) { + DialogId dialog_id(td_->contacts_manager_->get_my_id()); + const Story *story = get_story({dialog_id, story_id}); + if (story == nullptr) { + return promise.set_error(Status::Error(400, "Story not found")); + } + TRY_RESULT_PROMISE(promise, privacy_rules, + UserPrivacySettingRules::get_user_privacy_setting_rules(td_, std::move(rules))); + td_->create_handler(std::move(promise))->send(story_id, std::move(privacy_rules)); +} + } // namespace td diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 8f1dfd880..77af4c850 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -70,6 +70,9 @@ class StoryManager final : public Actor { void on_send_story_file_part_missing(unique_ptr &&pending_story, int bad_part); + void set_story_privacy_rules(StoryId story_id, td_api::object_ptr &&rules, + Promise &&promise); + void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 75654b136..67722dc86 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5624,6 +5624,13 @@ void Td::on_request(uint64 id, td_api::sendStory &request) { std::move(request.privacy_rules_), request.is_pinned_, std::move(promise)); } +void Td::on_request(uint64 id, td_api::setStoryPrivacyRules &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + story_manager_->set_story_privacy_rules(StoryId(request.story_id_), std::move(request.privacy_rules_), + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request) { CREATE_REQUEST_PROMISE(); stickers_manager_->get_default_topic_icons(false, std::move(promise)); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 6ad771bdf..3deb70b96 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -788,6 +788,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::sendStory &request); + void on_request(uint64 id, td_api::setStoryPrivacyRules &request); + void on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request); void on_request(uint64 id, td_api::createForumTopic &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f3eac3b78..5cdb337e5 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3934,6 +3934,13 @@ class CliClient final : public Actor { td_api::make_object(as_input_file(video), to_integers(sticker_file_ids), duration), as_caption(caption), as_user_privacy_setting_rules(allow, ids), false)); + } else if (op == "sspr") { + StoryId story_id; + string allow; + string ids; + get_args(args, story_id, allow, ids); + send_request( + td_api::make_object(story_id, as_user_privacy_setting_rules(allow, ids))); } else if (op == "gups") { UserId user_id; StoryId from_story_id;