Add td_api::deleteStory.

This commit is contained in:
levlam 2023-06-01 17:28:49 +03:00
parent eec9826dec
commit d929790bad
6 changed files with 77 additions and 3 deletions

View File

@ -7184,6 +7184,9 @@ setStoryPrivacyRules story_id:int32 privacy_rules:userPrivacySettingRules = Ok;
//@description Toggles whether a story is accessible after expiration @story_id Identifier of the story @is_pinned Pass true to make the story accessible after expiration; pass false to make it private //@description Toggles whether a story is accessible after expiration @story_id Identifier of the story @is_pinned Pass true to make the story accessible after expiration; pass false to make it private
toggleStoryIsPinned story_id:int32 is_pinned:Bool = Ok; toggleStoryIsPinned story_id:int32 is_pinned:Bool = Ok;
//@description Deletes a previously sent story @story_id Identifier of the story to delete
deleteStory story_id:int32 = 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). //@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 //-For optimal performance, the number of returned stories is chosen by TDLib
//@user_id User identifier //@user_id User identifier

View File

@ -185,6 +185,33 @@ class ToggleStoryPinnedQuery final : public Td::ResultHandler {
} }
}; };
class DeleteStoriesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit DeleteStoriesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(vector<int32> story_ids) {
send_query(G()->net_query_creator().create(telegram_api::stories_deleteStories(std::move(story_ids))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stories_deleteStories>(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 DeleteStoriesQuery: " << ptr;
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class StoryManager::SendStoryQuery final : public Td::ResultHandler { class StoryManager::SendStoryQuery final : public Td::ResultHandler {
FileId file_id_; FileId file_id_;
unique_ptr<PendingStory> pending_story_; unique_ptr<PendingStory> pending_story_;
@ -634,6 +661,11 @@ void StoryManager::on_delete_story(DialogId owner_dialog_id, StoryId story_id) {
} }
StoryFullId story_full_id{owner_dialog_id, story_id}; StoryFullId story_full_id{owner_dialog_id, story_id};
const Story *story = get_story(story_full_id);
if (story == nullptr) {
return;
}
delete_story_files(story);
stories_.erase(story_full_id); stories_.erase(story_full_id);
} }
@ -984,9 +1016,32 @@ void StoryManager::on_toggle_story_is_pinned(StoryId story_id, bool is_pinned, P
TRY_STATUS_PROMISE(promise, G()->close_status()); TRY_STATUS_PROMISE(promise, G()->close_status());
DialogId dialog_id(td_->contacts_manager_->get_my_id()); DialogId dialog_id(td_->contacts_manager_->get_my_id());
Story *story = get_story_editable({dialog_id, story_id}); Story *story = get_story_editable({dialog_id, story_id});
CHECK(story != nullptr); if (story != nullptr) {
story->is_pinned_ = is_pinned; story->is_pinned_ = is_pinned;
on_story_changed({dialog_id, story_id}, story, true, true); on_story_changed({dialog_id, story_id}, story, true, true);
}
promise.set_value(Unit());
}
void StoryManager::delete_story(StoryId story_id, 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"));
}
if (!story_id.is_server()) {
return promise.set_error(Status::Error(400, "Invalid story identifier"));
}
delete_story_on_server(dialog_id, story_id, 0, std::move(promise));
on_delete_story(dialog_id, story_id);
}
void StoryManager::delete_story_on_server(DialogId dialog_id, StoryId story_id, uint64 log_event_id,
Promise<Unit> &&promise) {
LOG(INFO) << "Delete " << story_id << " in " << dialog_id << " from server";
td_->create_handler<DeleteStoriesQuery>(std::move(promise))->send({story_id.get()});
} }
} // namespace td } // namespace td

View File

@ -88,6 +88,8 @@ class StoryManager final : public Actor {
void toggle_story_is_pinned(StoryId story_id, bool is_pinned, Promise<Unit> &&promise); void toggle_story_is_pinned(StoryId story_id, bool is_pinned, Promise<Unit> &&promise);
void delete_story(StoryId story_id, Promise<Unit> &&promise);
void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit, void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit,
Promise<td_api::object_ptr<td_api::stories>> &&promise); Promise<td_api::object_ptr<td_api::stories>> &&promise);
@ -142,6 +144,8 @@ class StoryManager final : public Actor {
vector<FileId> get_story_file_ids(const Story *story) const; vector<FileId> get_story_file_ids(const Story *story) const;
void delete_story_on_server(DialogId dialog_id, StoryId story_id, uint64 log_event_id, Promise<Unit> &&promise);
void delete_story_files(const Story *story) const; void delete_story_files(const Story *story) const;
void change_story_files(StoryFullId story_full_id, const Story *story, const vector<FileId> &old_file_ids); void change_story_files(StoryFullId story_full_id, const Story *story, const vector<FileId> &old_file_ids);

View File

@ -5644,6 +5644,12 @@ void Td::on_request(uint64 id, const td_api::toggleStoryIsPinned &request) {
story_manager_->toggle_story_is_pinned(StoryId(request.story_id_), request.is_pinned_, std::move(promise)); story_manager_->toggle_story_is_pinned(StoryId(request.story_id_), request.is_pinned_, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::deleteStory &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
story_manager_->delete_story(StoryId(request.story_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request) { void Td::on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request) {
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();
stickers_manager_->get_default_topic_icons(false, std::move(promise)); stickers_manager_->get_default_topic_icons(false, std::move(promise));

View File

@ -794,6 +794,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::toggleStoryIsPinned &request); void on_request(uint64 id, const td_api::toggleStoryIsPinned &request);
void on_request(uint64 id, const td_api::deleteStory &request);
void on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request); void on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request);
void on_request(uint64 id, td_api::createForumTopic &request); void on_request(uint64 id, td_api::createForumTopic &request);

View File

@ -3990,6 +3990,10 @@ class CliClient final : public Actor {
bool is_pinned; bool is_pinned;
get_args(args, story_id, is_pinned); get_args(args, story_id, is_pinned);
send_request(td_api::make_object<td_api::toggleStoryIsPinned>(story_id, is_pinned)); send_request(td_api::make_object<td_api::toggleStoryIsPinned>(story_id, is_pinned));
} else if (op == "ds") {
StoryId story_id;
get_args(args, story_id);
send_request(td_api::make_object<td_api::deleteStory>(story_id));
} else if (op == "gups") { } else if (op == "gups") {
UserId user_id; UserId user_id;
StoryId from_story_id; StoryId from_story_id;