Add td_api::setStoryPrivacyRules.

This commit is contained in:
levlam 2023-05-25 18:18:28 +03:00
parent 173ba06d62
commit eb1581a233
6 changed files with 65 additions and 0 deletions

View File

@ -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

View File

@ -128,6 +128,36 @@ class GetUserStoriesQuery final : public Td::ResultHandler {
}
};
class EditStoryPrivacyQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit EditStoryPrivacyQuery(Promise<Unit> &&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<telegram_api::object_ptr<telegram_api::MessageEntity>>(),
privacy_rules.get_input_privacy_rules(td_))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stories_editStory>(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<StoryManager::PendingStory> pending_story_;
@ -633,4 +663,17 @@ void StoryManager::on_send_story_file_part_missing(unique_ptr<PendingStory> &&pe
{bad_part});
}
void StoryManager::set_story_privacy_rules(StoryId story_id,
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules,
Promise<Unit> &&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<EditStoryPrivacyQuery>(std::move(promise))->send(story_id, std::move(privacy_rules));
}
} // namespace td

View File

@ -70,6 +70,9 @@ class StoryManager final : public Actor {
void on_send_story_file_part_missing(unique_ptr<PendingStory> &&pending_story, int bad_part);
void set_story_privacy_rules(StoryId story_id, td_api::object_ptr<td_api::userPrivacySettingRules> &&rules,
Promise<Unit> &&promise);
void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit,
Promise<td_api::object_ptr<td_api::stories>> &&promise);

View File

@ -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));

View File

@ -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);

View File

@ -3934,6 +3934,13 @@ class CliClient final : public Actor {
td_api::make_object<td_api::inputStoryContentVideo>(as_input_file(video),
to_integers<int32>(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<td_api::setStoryPrivacyRules>(story_id, as_user_privacy_setting_rules(allow, ids)));
} else if (op == "gups") {
UserId user_id;
StoryId from_story_id;