Add td_api::setPinnedForumTopics.

This commit is contained in:
levlam 2022-12-29 23:48:19 +03:00
parent 118c336c01
commit 9fb35e8c95
6 changed files with 80 additions and 0 deletions

View File

@ -6120,6 +6120,9 @@ toggleGeneralForumTopicIsHidden chat_id:int53 is_hidden:Bool = Ok;
//@is_pinned Pass true to pin the topic; pass false to unpin it
toggleForumTopicIsPinned chat_id:int53 message_thread_id:int53 is_pinned:Bool = Ok;
//@description Changes the order of pinned forum topics @chat_id Chat identifier @message_thread_ids The new list of pinned forum topics
setPinnedForumTopics chat_id:int53 message_thread_ids:vector<int53> = Ok;
//@description Deletes all messages in a forum topic; requires can_delete_messages administrator right in the supergroup unless the user is creator of the topic, the topic has no messages from other users and has at most 11 messages
//@chat_id Identifier of the chat
//@message_thread_id Message thread identifier of the forum topic

View File

@ -241,6 +241,47 @@ class UpdatePinnedForumTopicQuery final : public Td::ResultHandler {
}
};
class ReorderPinnedForumTopicsQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
public:
explicit ReorderPinnedForumTopicsQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, const vector<MessageId> &top_thread_message_ids) {
channel_id_ = channel_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
int32 flags = telegram_api::channels_reorderPinnedForumTopics::FORCE_MASK;
send_query(G()->net_query_creator().create(
telegram_api::channels_reorderPinnedForumTopics(flags, true /*ignored*/, std::move(input_channel),
MessageId::get_server_message_ids(top_thread_message_ids)),
{{channel_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_reorderPinnedForumTopics>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for ReorderPinnedForumTopicsQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
if (status.message() == "PINNED_TOPICS_NOT_MODIFIED" && !td_->auth_manager_->is_bot()) {
return promise_.set_value(Unit());
}
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ReorderPinnedForumTopicsQuery");
promise_.set_error(std::move(status));
}
};
class GetForumTopicQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::forumTopic>> promise_;
ChannelId channel_id_;
@ -747,6 +788,21 @@ void ForumTopicManager::toggle_forum_topic_is_pinned(DialogId dialog_id, Message
->send(channel_id, top_thread_message_id, is_pinned);
}
void ForumTopicManager::set_pinned_forum_topics(DialogId dialog_id, vector<MessageId> top_thread_message_ids,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, is_forum(dialog_id));
for (auto top_thread_message_id : top_thread_message_ids) {
TRY_STATUS_PROMISE(promise, can_be_message_thread_id(top_thread_message_id));
}
auto channel_id = dialog_id.get_channel_id();
if (!td_->contacts_manager_->get_channel_permissions(channel_id).can_pin_topics()) {
return promise.set_error(Status::Error(400, "Not enough rights to reorder forum topics"));
}
td_->create_handler<ReorderPinnedForumTopicsQuery>(std::move(promise))->send(channel_id, top_thread_message_ids);
}
void ForumTopicManager::delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, is_forum(dialog_id));

View File

@ -81,6 +81,8 @@ class ForumTopicManager final : public Actor {
void toggle_forum_topic_is_pinned(DialogId dialog_id, MessageId top_thread_message_id, bool is_pinned,
Promise<Unit> &&promise);
void set_pinned_forum_topics(DialogId dialog_id, vector<MessageId> top_thread_message_ids, Promise<Unit> &&promise);
void delete_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise<Unit> &&promise);
void delete_all_dialog_topics(DialogId dialog_id);

View File

@ -5596,6 +5596,13 @@ void Td::on_request(uint64 id, const td_api::toggleForumTopicIsPinned &request)
request.is_pinned_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setPinnedForumTopics &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
forum_topic_manager_->set_pinned_forum_topics(
DialogId(request.chat_id_), MessageId::get_message_ids(request.message_thread_ids_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteForumTopic &request) {
CREATE_OK_REQUEST_PROMISE();
forum_topic_manager_->delete_forum_topic(DialogId(request.chat_id_), MessageId(request.message_thread_id_),

View File

@ -760,6 +760,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::toggleForumTopicIsPinned &request);
void on_request(uint64 id, const td_api::setPinnedForumTopics &request);
void on_request(uint64 id, const td_api::deleteForumTopic &request);
void on_request(uint64 id, td_api::setGameScore &request);

View File

@ -522,6 +522,10 @@ class CliClient final : public Actor {
return as_message_id(str);
}
static vector<int64> as_message_thread_ids(Slice str) {
return as_message_ids(str);
}
td_api::object_ptr<td_api::MessageSender> as_message_sender(Slice sender_id) const {
sender_id = trim(sender_id);
if (sender_id.empty() || sender_id[0] != '-') {
@ -3938,6 +3942,12 @@ class CliClient final : public Actor {
bool is_pinned;
get_args(args, chat_id, message_thread_id, is_pinned);
send_request(td_api::make_object<td_api::toggleForumTopicIsPinned>(chat_id, message_thread_id, is_pinned));
} else if (op == "spft") {
ChatId chat_id;
string message_thread_ids;
get_args(args, chat_id, message_thread_ids);
send_request(
td_api::make_object<td_api::setPinnedForumTopics>(chat_id, as_message_thread_ids(message_thread_ids)));
} else if (op == "dft") {
ChatId chat_id;
MessageThreadId message_thread_id;