Add td_api::editForumTopic.

This commit is contained in:
levlam 2022-10-27 16:53:23 +03:00
parent 3b58079799
commit be81c6d2b9
6 changed files with 98 additions and 1 deletions

View File

@ -5294,10 +5294,19 @@ editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:Messa
//@description Returns list of custom emojis, which can be used as forum topic icon by all users
getForumTopicDefaultIcons = Stickers;
//@description Creates a topic in a forum supergroup chat; requires can_manage_topics rights in the supergroup @chat_id Identifier of the chat @title Title of the topic
//@description Creates a topic in a forum supergroup chat; requires can_manage_topics rights in the supergroup
//@chat_id Identifier of the chat
//@title Title of the topic
//@icon Icon of the topic. Icon color must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F. Telegram Premium users can use any custom emoji as topic icon, other users can use only a custom emoji returned by getForumTopicDefaultIcons
createForumTopic chat_id:int53 title:string icon:forumTopicIcon = ForumTopicInfo;
//@description Edits title and icon of a topic in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup
//@chat_id Identifier of the chat
//@message_thread_id Message thread identifier of the forum topic
//@title New title of the topic
//@icon_custom_emoji_id Identifier of the new custom emoji for topic icon. Telegram Premium users can use any custom emoji, other users can use only a custom emoji returned by getForumTopicDefaultIcons
editForumTopic chat_id:int53 message_thread_id:int53 title:string icon_custom_emoji_id:int64 = Ok;
//@description Returns information about a emoji reaction. Returns a 404 error if the reaction is not found @emoji Text representation of the reaction
getEmojiReaction emoji:string = EmojiReaction;

View File

@ -104,6 +104,49 @@ class CreateForumTopicQuery final : public Td::ResultHandler {
}
};
class EditForumTopicQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
MessageId top_thread_message_id_;
public:
explicit EditForumTopicQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, MessageId top_thread_message_id, const string &title,
CustomEmojiId icon_custom_emoji_id) {
channel_id_ = channel_id;
top_thread_message_id_ = top_thread_message_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
int32 flags =
telegram_api::channels_editForumTopic::TITLE_MASK | telegram_api::channels_editForumTopic::ICON_EMOJI_ID_MASK;
send_query(G()->net_query_creator().create(
telegram_api::channels_editForumTopic(flags, std::move(input_channel),
top_thread_message_id.get_server_message_id().get(), title,
icon_custom_emoji_id.get(), false),
{{channel_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_editForumTopic>(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 EditForumTopicQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "EditForumTopicQuery");
promise_.set_error(std::move(status));
}
};
ForumTopicManager::ForumTopicManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}
@ -164,6 +207,28 @@ void ForumTopicManager::on_forum_topic_created(DialogId dialog_id, unique_ptr<Fo
promise.set_value(topic_info->get_forum_topic_info_object(td_));
}
void ForumTopicManager::edit_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, string &&title,
CustomEmojiId icon_custom_emoji_id, Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, is_forum(dialog_id));
auto channel_id = dialog_id.get_channel_id();
if (!top_thread_message_id.is_valid() || !top_thread_message_id.is_server()) {
return promise.set_error(Status::Error(400, "Invalid message thread identifier specified"));
}
if (!td_->contacts_manager_->get_channel_permissions(channel_id).can_edit_topics()) {
return promise.set_error(Status::Error(400, "Not enough rights to edit a topic"));
}
auto new_title = clean_name(std::move(title), MAX_FORUM_TOPIC_TITLE_LENGTH);
if (new_title.empty()) {
return promise.set_error(Status::Error(400, "Title must be non-empty"));
}
td_->create_handler<EditForumTopicQuery>(std::move(promise))
->send(channel_id, top_thread_message_id, new_title, icon_custom_emoji_id);
}
Status ForumTopicManager::is_forum(DialogId dialog_id) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "ForumTopicManager::is_forum")) {
return Status::Error(400, "Chat not found");

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/CustomEmojiId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/ForumTopicInfo.h"
#include "td/telegram/td_api.h"
@ -35,6 +36,9 @@ class ForumTopicManager final : public Actor {
void on_forum_topic_created(DialogId dialog_id, unique_ptr<ForumTopicInfo> &&forum_topic_info,
Promise<td_api::object_ptr<td_api::forumTopicInfo>> &&promise);
void edit_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, string &&title,
CustomEmojiId icon_custom_emoji_id, Promise<Unit> &&promise);
private:
static constexpr size_t MAX_FORUM_TOPIC_TITLE_LENGTH = 128; // server side limit for forum topic title

View File

@ -5523,6 +5523,15 @@ void Td::on_request(uint64 id, td_api::createForumTopic &request) {
std::move(request.icon_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::editForumTopic &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.title_);
CREATE_OK_REQUEST_PROMISE();
forum_topic_manager_->edit_forum_topic(DialogId(request.chat_id_), MessageId(request.message_thread_id_),
std::move(request.title_), CustomEmojiId(request.icon_custom_emoji_id_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::setGameScore &request) {
CHECK_IS_BOT();
CREATE_REQUEST_PROMISE();

View File

@ -734,6 +734,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::createForumTopic &request);
void on_request(uint64 id, td_api::editForumTopic &request);
void on_request(uint64 id, td_api::setGameScore &request);
void on_request(uint64 id, td_api::setInlineGameScore &request);

View File

@ -3863,6 +3863,14 @@ class CliClient final : public Actor {
get_args(args, chat_id, title, icon_color);
send_request(td_api::make_object<td_api::createForumTopic>(
chat_id, title, td_api::make_object<td_api::forumTopicIcon>(icon_color, 0)));
} else if (op == "eft") {
ChatId chat_id;
MessageThreadId message_thread_id;
string title;
int64 icon_custom_emoji_id;
get_args(args, chat_id, message_thread_id, title, icon_custom_emoji_id);
send_request(
td_api::make_object<td_api::editForumTopic>(chat_id, message_thread_id, title, icon_custom_emoji_id));
} else if (op == "gallm") {
send_request(td_api::make_object<td_api::getActiveLiveLocationMessages>());
} else if (op == "sbsm") {