Add td_api::closeStory and register opened owned stories.

This commit is contained in:
levlam 2023-06-15 18:34:05 +03:00
parent 541165e21f
commit 37e5847cc3
6 changed files with 66 additions and 1 deletions

View File

@ -7274,6 +7274,11 @@ getArchivedStories from_story_id:int32 limit:int32 = Stories;
//@story_id The identifier of the story
openStory story_sender_user_id:int53 story_id:int32 = Ok;
//@description Informs TDLib that a story is closed by the user
//@story_sender_user_id The identifier of the sender of the closed story
//@story_id The identifier of the story
closeStory story_sender_user_id:int53 story_id:int32 = Ok;
//@description Returns information about a bot that can be added to attachment menu @bot_user_id Bot's user identifier
getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot;

View File

@ -694,7 +694,18 @@ void StoryManager::open_story(DialogId owner_dialog_id, StoryId story_id, Promis
StoryFullId story_full_id{owner_dialog_id, story_id};
const Story *story = get_story(story_full_id);
if (story == nullptr || story->content_ == nullptr) {
if (story == nullptr) {
return promise.set_value(Unit());
}
if (is_story_owned(owner_dialog_id)) {
auto &open_count = opened_owned_stories_[story_full_id];
if (++open_count == 1) {
on_owned_story_opened(story_full_id);
}
}
if (story->content_ == nullptr) {
return promise.set_value(Unit());
}
@ -721,6 +732,35 @@ void StoryManager::open_story(DialogId owner_dialog_id, StoryId story_id, Promis
promise.set_value(Unit());
}
void StoryManager::close_story(DialogId owner_dialog_id, StoryId story_id, Promise<Unit> &&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_valid()) {
return promise.set_error(Status::Error(400, "Invalid story identifier specified"));
}
StoryFullId story_full_id{owner_dialog_id, story_id};
if (is_story_owned(owner_dialog_id)) {
auto &open_count = opened_owned_stories_[story_full_id];
if (open_count == 0) {
return promise.set_error(Status::Error(400, "The story wasn't opened"));
}
if (--open_count == 0) {
opened_owned_stories_.erase(story_full_id);
}
}
promise.set_value(Unit());
}
void StoryManager::on_owned_story_opened(StoryFullId story_full_id) {
// TODO reget story view counter
}
void StoryManager::increment_story_views(DialogId owner_dialog_id, PendingStoryViews &story_views) {
CHECK(!story_views.has_query_);
vector<int32> viewed_story_ids;

View File

@ -117,6 +117,8 @@ class StoryManager final : public Actor {
void open_story(DialogId owner_dialog_id, StoryId story_id, Promise<Unit> &&promise);
void close_story(DialogId owner_dialog_id, StoryId story_id, Promise<Unit> &&promise);
StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr);
std::pair<int32, vector<StoryId>> on_get_stories(DialogId owner_dialog_id, vector<int32> &&expected_story_ids,
@ -236,6 +238,8 @@ class StoryManager final : public Actor {
void send_update_active_stories(DialogId owner_dialog_id);
void on_owned_story_opened(StoryFullId story_full_id);
void increment_story_views(DialogId owner_dialog_id, PendingStoryViews &story_views);
void on_increment_story_views(DialogId owner_dialog_id);
@ -264,6 +268,8 @@ class StoryManager final : public Actor {
FlatHashMap<DialogId, PendingStoryViews, DialogIdHash> pending_story_views_;
FlatHashMap<StoryFullId, uint32, StoryFullIdHash> opened_owned_stories_;
uint32 send_story_count_ = 0;
FlatHashMap<FileId, unique_ptr<PendingStory>, FileIdHash> being_uploaded_files_;

View File

@ -6450,6 +6450,13 @@ void Td::on_request(uint64 id, const td_api::openStory &request) {
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::closeStory &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
story_manager_->close_story(DialogId(UserId(request.story_sender_user_id_)), StoryId(request.story_id_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -1008,6 +1008,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::openStory &request);
void on_request(uint64 id, const td_api::closeStory &request);
void on_request(uint64 id, const td_api::getAttachmentMenuBot &request);
void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request);

View File

@ -4063,6 +4063,11 @@ class CliClient final : public Actor {
StoryId story_id;
get_args(args, story_sender_user_id, story_id);
send_request(td_api::make_object<td_api::openStory>(story_sender_user_id, story_id));
} else if (op == "cs") {
UserId story_sender_user_id;
StoryId story_id;
get_args(args, story_sender_user_id, story_id);
send_request(td_api::make_object<td_api::closeStory>(story_sender_user_id, story_id));
} else if (op == "gamb") {
UserId user_id;
get_args(args, user_id);