Add td_api::getStory.

This commit is contained in:
levlam 2023-06-05 16:55:06 +03:00
parent 11c353dc7f
commit 2fcdb02c39
6 changed files with 60 additions and 0 deletions

View File

@ -7180,6 +7180,9 @@ setPinnedChats chat_list:ChatList chat_ids:vector<int53> = Ok;
readChatList chat_list:ChatList = Ok; readChatList chat_list:ChatList = Ok;
//@description Returns a story @user_id Identifier of the user, which sent the story @story_id Story identifier
getStory user_id:int53 story_id:int32 = Story;
//@description Sends a new story. Returns a temporary story with identifier 0 //@description Sends a new story. Returns a temporary story with identifier 0
//@content Content of the story //@content Content of the story
//@caption Story caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters //@caption Story caption; pass null to use an empty caption; 0-getOption("message_caption_length_max") characters

View File

@ -829,6 +829,44 @@ void StoryManager::reload_story(StoryFullId story_full_id, Promise<Unit> &&promi
td_->create_handler<GetStoriesByIDQuery>(std::move(promise))->send(user_id, {story_full_id.get_story_id().get()}); td_->create_handler<GetStoriesByIDQuery>(std::move(promise))->send(user_id, {story_full_id.get_story_id().get()});
} }
void StoryManager::get_story(DialogId owner_dialog_id, StoryId story_id,
Promise<td_api::object_ptr<td_api::story>> &&promise) {
if (!td_->messages_manager_->have_dialog_info_force(owner_dialog_id)) {
return promise.set_error(Status::Error(400, "Story sender not found"));
}
if (!td_->messages_manager_->have_input_peer(owner_dialog_id, AccessRights::Read)) {
return promise.set_error(Status::Error(400, "Can't access the story sender"));
}
if (!story_id.is_server()) {
return promise.set_error(Status::Error(400, "Invalid story identifier specified"));
}
if (owner_dialog_id.get_type() != DialogType::User) {
return promise.set_value(nullptr);
}
StoryFullId story_full_id{owner_dialog_id, story_id};
const Story *story = get_story(story_full_id);
if (story != nullptr) {
return promise.set_value(get_story_object(story_full_id, story));
}
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), story_full_id, promise = std::move(promise)](Result<Unit> &&result) mutable {
send_closure(actor_id, &StoryManager::do_get_story, story_full_id, std::move(result), std::move(promise));
});
td_->create_handler<GetStoriesByIDQuery>(std::move(query_promise))
->send(owner_dialog_id.get_user_id(), {story_id.get()});
}
void StoryManager::do_get_story(StoryFullId story_full_id, Result<Unit> &&result,
Promise<td_api::object_ptr<td_api::story>> &&promise) {
G()->ignore_result_if_closing(result);
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
promise.set_value(get_story_object(story_full_id));
}
void StoryManager::send_story(td_api::object_ptr<td_api::InputStoryContent> &&input_story_content, void StoryManager::send_story(td_api::object_ptr<td_api::InputStoryContent> &&input_story_content,
td_api::object_ptr<td_api::formattedText> &&input_caption, td_api::object_ptr<td_api::formattedText> &&input_caption,
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, bool is_pinned, td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, bool is_pinned,

View File

@ -75,6 +75,8 @@ class StoryManager final : public Actor {
StoryManager &operator=(StoryManager &&) = delete; StoryManager &operator=(StoryManager &&) = delete;
~StoryManager() final; ~StoryManager() final;
void get_story(DialogId owner_dialog_id, StoryId story_id, Promise<td_api::object_ptr<td_api::story>> &&promise);
void send_story(td_api::object_ptr<td_api::InputStoryContent> &&input_story_content, void send_story(td_api::object_ptr<td_api::InputStoryContent> &&input_story_content,
td_api::object_ptr<td_api::formattedText> &&input_caption, td_api::object_ptr<td_api::formattedText> &&input_caption,
td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, bool is_pinned, td_api::object_ptr<td_api::userPrivacySettingRules> &&rules, bool is_pinned,
@ -160,6 +162,9 @@ class StoryManager final : public Actor {
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);
void do_get_story(StoryFullId story_full_id, Result<Unit> &&result,
Promise<td_api::object_ptr<td_api::story>> &&promise);
void do_send_story(unique_ptr<PendingStory> &&pending_story, vector<int> bad_parts); void do_send_story(unique_ptr<PendingStory> &&pending_story, vector<int> bad_parts);
void on_upload_story(FileId file_id, telegram_api::object_ptr<telegram_api::InputFile> input_file); void on_upload_story(FileId file_id, telegram_api::object_ptr<telegram_api::InputFile> input_file);

View File

@ -121,6 +121,7 @@
#include "td/telegram/StickersManager.h" #include "td/telegram/StickersManager.h"
#include "td/telegram/StickerType.h" #include "td/telegram/StickerType.h"
#include "td/telegram/StorageManager.h" #include "td/telegram/StorageManager.h"
#include "td/telegram/StoryId.h"
#include "td/telegram/StoryManager.h" #include "td/telegram/StoryManager.h"
#include "td/telegram/SuggestedAction.h" #include "td/telegram/SuggestedAction.h"
#include "td/telegram/Support.h" #include "td/telegram/Support.h"
@ -5619,6 +5620,12 @@ void Td::on_request(uint64 id, td_api::editMessageSchedulingState &request) {
std::move(request.scheduling_state_), std::move(promise)); std::move(request.scheduling_state_), std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getStory &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
story_manager_->get_story(DialogId(UserId(request.user_id_)), StoryId(request.story_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::sendStory &request) { void Td::on_request(uint64 id, td_api::sendStory &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();

View File

@ -786,6 +786,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::editMessageSchedulingState &request); void on_request(uint64 id, td_api::editMessageSchedulingState &request);
void on_request(uint64 id, const td_api::getStory &request);
void on_request(uint64 id, td_api::sendStory &request); void on_request(uint64 id, td_api::sendStory &request);
void on_request(uint64 id, td_api::editStory &request); void on_request(uint64 id, td_api::editStory &request);

View File

@ -3935,6 +3935,11 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setPinnedChats>(as_chat_list(op), as_chat_ids(args))); send_request(td_api::make_object<td_api::setPinnedChats>(as_chat_list(op), as_chat_ids(args)));
} else if (op == "rcl" || op == "rcla" || begins_with(op, "rcl-")) { } else if (op == "rcl" || op == "rcla" || begins_with(op, "rcl-")) {
send_request(td_api::make_object<td_api::readChatList>(as_chat_list(op))); send_request(td_api::make_object<td_api::readChatList>(as_chat_list(op)));
} else if (op == "gst") {
UserId user_id;
StoryId story_id;
get_args(args, user_id, story_id);
send_request(td_api::make_object<td_api::getStory>(user_id, story_id));
} else if (op == "ssp" || op == "sspp") { } else if (op == "ssp" || op == "sspp") {
string photo; string photo;
string caption; string caption;