Add td_api::setChatPinnedStories.

This commit is contained in:
levlam 2024-04-25 22:36:19 +03:00
parent 6d57718258
commit 7aca38cab5
7 changed files with 94 additions and 1 deletions

View File

@ -773,7 +773,7 @@ chatPermissions can_send_basic_messages:Bool can_send_audios:Bool can_send_docum
//@can_promote_members True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that were directly or indirectly promoted by them
//@can_manage_video_chats True, if the administrator can manage video chats
//@can_post_stories True, if the administrator can create new chat stories, or edit and delete posted stories; applicable to supergroups and channels only
//@can_edit_stories True, if the administrator can edit stories posted by other users, post stories to the chat page, and access story archive; applicable to supergroups and channels only
//@can_edit_stories True, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access story archive; applicable to supergroups and channels only
//@can_delete_stories True, if the administrator can delete stories posted by other users; applicable to supergroups and channels only
//@is_anonymous True, if the administrator isn't shown in the chat member list and sends messages anonymously; applicable to supergroups only
chatAdministratorRights can_manage_chat:Bool can_change_info:Bool can_post_messages:Bool can_edit_messages:Bool can_delete_messages:Bool can_invite_users:Bool can_restrict_members:Bool can_pin_messages:Bool can_manage_topics:Bool can_promote_members:Bool can_manage_video_chats:Bool can_post_stories:Bool can_edit_stories:Bool can_delete_stories:Bool is_anonymous:Bool = ChatAdministratorRights;
@ -9066,6 +9066,11 @@ getChatPostedToChatPageStories chat_id:int53 from_story_id:int32 limit:int32 = S
//-For optimal performance, the number of returned stories is chosen by TDLib and can be smaller than the specified limit
getChatArchivedStories chat_id:int53 from_story_id:int32 limit:int32 = Stories;
//@description Changes list of pinned stories on a chat page; requires can_edit_stories right in the chat
//@chat_id Identifier of the chat that posted the stories
//@story_ids New list of pinned stories. All stories must be posted to chat page
setChatPinnedStories chat_id:int53 story_ids:vector<int32> = Ok;
//@description Informs TDLib that a story is opened and is being viewed by the user
//@story_sender_chat_id The identifier of the sender of the opened story
//@story_id The identifier of the story

View File

@ -37,6 +37,15 @@ class StoryId {
return input_story_ids;
}
static vector<StoryId> get_story_ids(const vector<int32> &input_story_ids) {
vector<StoryId> story_ids;
story_ids.reserve(input_story_ids.size());
for (auto &input_story_id : input_story_ids) {
story_ids.emplace_back(input_story_id);
}
return story_ids;
}
int32 get() const {
return id;
}

View File

@ -703,6 +703,39 @@ class DeleteStoriesQuery final : public Td::ResultHandler {
}
};
class TogglePinnedStoriesToTopQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
public:
explicit TogglePinnedStoriesToTopQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, vector<StoryId> story_ids) {
dialog_id_ = dialog_id;
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id_, AccessRights::Write);
CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(
telegram_api::stories_togglePinnedToTop(std::move(input_peer), StoryId::get_input_story_ids(story_ids))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stories_togglePinnedToTop>(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 TogglePinnedStoriesToTopQuery: " << ptr;
promise_.set_value(Unit());
}
void on_error(Status status) final {
td_->dialog_manager_->on_get_dialog_error(dialog_id_, status, "GetStoriesViewsQuery");
promise_.set_error(std::move(status));
}
};
class GetStoriesViewsQuery final : public Td::ResultHandler {
vector<StoryId> story_ids_;
DialogId dialog_id_;
@ -2502,6 +2535,28 @@ void StoryManager::on_get_dialog_expiring_stories(DialogId owner_dialog_id,
}
}
void StoryManager::set_pinned_stories(DialogId owner_dialog_id, vector<StoryId> story_ids, Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(owner_dialog_id, false, AccessRights::Write,
"set_pinned_stories"));
if (!can_edit_stories(owner_dialog_id)) {
return promise.set_error(Status::Error(400, "Can't change pinned stories in the chat"));
}
for (const auto &story_id : story_ids) {
StoryFullId story_full_id{owner_dialog_id, story_id};
const Story *story = get_story(story_full_id);
if (story == nullptr) {
return promise.set_error(Status::Error(400, "Story not found"));
}
if (!story->is_pinned_) {
return promise.set_error(Status::Error(400, "The story must be posted to the chat page first"));
}
if (!story_id.is_server()) {
return promise.set_error(Status::Error(400, "Story must be sent first"));
}
}
td_->create_handler<TogglePinnedStoriesToTopQuery>(std::move(promise))->send(owner_dialog_id, std::move(story_ids));
}
void StoryManager::open_story(DialogId owner_dialog_id, StoryId story_id, Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(
promise, td_->dialog_manager_->check_dialog_access(owner_dialog_id, false, AccessRights::Read, "open_story"));

View File

@ -253,6 +253,8 @@ class StoryManager final : public Actor {
void reload_dialog_expiring_stories(DialogId dialog_id);
void set_pinned_stories(DialogId owner_dialog_id, vector<StoryId> story_ids, Promise<Unit> &&promise);
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);

View File

@ -6929,6 +6929,13 @@ void Td::on_request(uint64 id, const td_api::getChatArchivedStories &request) {
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatPinnedStories &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
story_manager_->set_pinned_stories(DialogId(request.chat_id_), StoryId::get_story_ids(request.story_ids_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::openStory &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

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

View File

@ -4604,6 +4604,19 @@ class CliClient final : public Actor {
string limit;
get_args(args, chat_id, from_story_id, limit);
send_request(td_api::make_object<td_api::getChatArchivedStories>(chat_id, from_story_id, as_limit(limit)));
} else if (op == "scps") {
ChatId chat_id;
get_args(args, chat_id, args);
vector<int32> story_ids;
while (true) {
StoryId story_id;
get_args(args, story_id, args);
if (story_id <= 0) {
break;
}
story_ids.push_back(story_id);
}
send_request(td_api::make_object<td_api::setChatPinnedStories>(chat_id, std::move(story_ids)));
} else if (op == "gsnse") {
send_request(td_api::make_object<td_api::getStoryNotificationSettingsExceptions>());
} else if (op == "gcas") {