Add td_api::getForumTopic.
This commit is contained in:
parent
c29a48c9ac
commit
cdaddd75b2
@ -1327,7 +1327,7 @@ forumTopicInfo message_thread_id:int53 name:string icon:forumTopicIcon creation_
|
|||||||
|
|
||||||
//@description Describes a forum topic
|
//@description Describes a forum topic
|
||||||
//@info Basic information about the topic
|
//@info Basic information about the topic
|
||||||
//@last_message Last message in the topic; may be null
|
//@last_message Last message in the topic; may be null if unknown
|
||||||
//@is_pinned True, if the topic is pinned in the topic list
|
//@is_pinned True, if the topic is pinned in the topic list
|
||||||
//@unread_count Number of unread messages in the topic
|
//@unread_count Number of unread messages in the topic
|
||||||
//@last_read_inbox_message_id Identifier of the last read incoming message
|
//@last_read_inbox_message_id Identifier of the last read incoming message
|
||||||
@ -5337,6 +5337,9 @@ createForumTopic chat_id:int53 name:string icon:forumTopicIcon = ForumTopicInfo;
|
|||||||
//@icon_custom_emoji_id Identifier of the new custom emoji for topic icon; pass 0 to remove the custom emoji. Ignored if edit_icon_custom_emoji is false. Telegram Premium users can use any custom emoji, other users can use only a custom emoji returned by getForumTopicDefaultIcons
|
//@icon_custom_emoji_id Identifier of the new custom emoji for topic icon; pass 0 to remove the custom emoji. Ignored if edit_icon_custom_emoji is false. 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 name:string edit_icon_custom_emoji:Bool icon_custom_emoji_id:int64 = Ok;
|
editForumTopic chat_id:int53 message_thread_id:int53 name:string edit_icon_custom_emoji:Bool icon_custom_emoji_id:int64 = Ok;
|
||||||
|
|
||||||
|
//@description Returns information about a forum topic @chat_id Identifier of the chat @message_thread_id Message thread identifier of the forum topic
|
||||||
|
getForumTopic chat_id:int53 message_thread_id:int53 = ForumTopic;
|
||||||
|
|
||||||
//@description Toggles whether a topic is closed in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup unless the user is creator of the topic
|
//@description Toggles whether a topic is closed in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup unless the user is creator of the topic
|
||||||
//@chat_id Identifier of the chat
|
//@chat_id Identifier of the chat
|
||||||
//@message_thread_id Message thread identifier of the forum topic
|
//@message_thread_id Message thread identifier of the forum topic
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/telegram/DialogNotificationSettings.h"
|
#include "td/telegram/DialogNotificationSettings.h"
|
||||||
|
#include "td/telegram/DraftMessage.h"
|
||||||
#include "td/telegram/MessageId.h"
|
#include "td/telegram/MessageId.h"
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
@ -15,7 +16,6 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class DraftMessage;
|
|
||||||
class ForumTopicInfo;
|
class ForumTopicInfo;
|
||||||
class Td;
|
class Td;
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "td/telegram/ChannelId.h"
|
#include "td/telegram/ChannelId.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
#include "td/telegram/CustomEmojiId.h"
|
#include "td/telegram/CustomEmojiId.h"
|
||||||
|
#include "td/telegram/ForumTopic.h"
|
||||||
#include "td/telegram/ForumTopicIcon.h"
|
#include "td/telegram/ForumTopicIcon.h"
|
||||||
#include "td/telegram/ForumTopicInfo.hpp"
|
#include "td/telegram/ForumTopicInfo.hpp"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
@ -193,6 +194,72 @@ class EditForumTopicQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GetForumTopicQuery final : public Td::ResultHandler {
|
||||||
|
Promise<td_api::object_ptr<td_api::forumTopic>> promise_;
|
||||||
|
ChannelId channel_id_;
|
||||||
|
MessageId top_thread_message_id_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetForumTopicQuery(Promise<td_api::object_ptr<td_api::forumTopic>> &&promise)
|
||||||
|
: promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(ChannelId channel_id, MessageId top_thread_message_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);
|
||||||
|
|
||||||
|
send_query(G()->net_query_creator().create(
|
||||||
|
telegram_api::channels_getForumTopicsByID(std::move(input_channel),
|
||||||
|
{top_thread_message_id_.get_server_message_id().get()}),
|
||||||
|
{{channel_id}}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::channels_getForumTopicsByID>(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 GetForumTopicQuery: " << to_string(ptr);
|
||||||
|
|
||||||
|
td_->contacts_manager_->on_get_users(std::move(ptr->users_), "GetForumTopicQuery");
|
||||||
|
td_->contacts_manager_->on_get_chats(std::move(ptr->chats_), "GetForumTopicQuery");
|
||||||
|
td_->messages_manager_->on_get_messages(std::move(ptr->messages_), true, false, Promise<Unit>(),
|
||||||
|
"GetForumTopicQuery");
|
||||||
|
if (ptr->topics_.size() != 1u) {
|
||||||
|
return promise_.set_value(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto topic = std::move(ptr->topics_[0]);
|
||||||
|
switch (topic->get_id()) {
|
||||||
|
case telegram_api::forumTopicDeleted::ID:
|
||||||
|
return promise_.set_value(nullptr);
|
||||||
|
case telegram_api::forumTopic::ID: {
|
||||||
|
ForumTopicInfo forum_topic_info(topic);
|
||||||
|
ForumTopic forum_topic(td_, std::move(topic));
|
||||||
|
if (forum_topic.is_short()) {
|
||||||
|
return promise_.set_error(Status::Error(500, "Receive short forum topic"));
|
||||||
|
}
|
||||||
|
if (forum_topic_info.get_top_thread_message_id() != top_thread_message_id_) {
|
||||||
|
return promise_.set_error(Status::Error(500, "Wrong forum topic received"));
|
||||||
|
}
|
||||||
|
return promise_.set_value(forum_topic.get_forum_topic_object(td_, forum_topic_info));
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "GetForumTopicQuery");
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
void ForumTopicManager::Topic::store(StorerT &storer) const {
|
void ForumTopicManager::Topic::store(StorerT &storer) const {
|
||||||
CHECK(info_ != nullptr);
|
CHECK(info_ != nullptr);
|
||||||
@ -306,6 +373,18 @@ void ForumTopicManager::edit_forum_topic(DialogId dialog_id, MessageId top_threa
|
|||||||
->send(channel_id, top_thread_message_id, edit_title, new_title, edit_icon_custom_emoji, icon_custom_emoji_id);
|
->send(channel_id, top_thread_message_id, edit_title, new_title, edit_icon_custom_emoji, icon_custom_emoji_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ForumTopicManager::get_forum_topic(DialogId dialog_id, MessageId top_thread_message_id,
|
||||||
|
Promise<td_api::object_ptr<td_api::forumTopic>> &&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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
td_->create_handler<GetForumTopicQuery>(std::move(promise))->send(channel_id, top_thread_message_id);
|
||||||
|
}
|
||||||
|
|
||||||
void ForumTopicManager::toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id,
|
void ForumTopicManager::toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id,
|
||||||
bool is_closed, Promise<Unit> &&promise) {
|
bool is_closed, Promise<Unit> &&promise) {
|
||||||
TRY_STATUS_PROMISE(promise, is_forum(dialog_id));
|
TRY_STATUS_PROMISE(promise, is_forum(dialog_id));
|
||||||
|
@ -43,6 +43,9 @@ class ForumTopicManager final : public Actor {
|
|||||||
void edit_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, string &&title,
|
void edit_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, string &&title,
|
||||||
bool edit_icon_custom_emoji, CustomEmojiId icon_custom_emoji_id, Promise<Unit> &&promise);
|
bool edit_icon_custom_emoji, CustomEmojiId icon_custom_emoji_id, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void get_forum_topic(DialogId dialog_id, MessageId top_thread_message_id,
|
||||||
|
Promise<td_api::object_ptr<td_api::forumTopic>> &&promise);
|
||||||
|
|
||||||
void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed,
|
void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
@ -5562,6 +5562,12 @@ void Td::on_request(uint64 id, td_api::editForumTopic &request) {
|
|||||||
CustomEmojiId(request.icon_custom_emoji_id_), std::move(promise));
|
CustomEmojiId(request.icon_custom_emoji_id_), std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::getForumTopic &request) {
|
||||||
|
CREATE_REQUEST_PROMISE();
|
||||||
|
forum_topic_manager_->get_forum_topic(DialogId(request.chat_id_), MessageId(request.message_thread_id_),
|
||||||
|
std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request) {
|
void Td::on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request) {
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
forum_topic_manager_->toggle_forum_topic_is_closed(DialogId(request.chat_id_), MessageId(request.message_thread_id_),
|
forum_topic_manager_->toggle_forum_topic_is_closed(DialogId(request.chat_id_), MessageId(request.message_thread_id_),
|
||||||
|
@ -748,6 +748,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, td_api::editForumTopic &request);
|
void on_request(uint64 id, td_api::editForumTopic &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::getForumTopic &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request);
|
void on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::toggleGeneralForumTopicIsHidden &request);
|
void on_request(uint64 id, const td_api::toggleGeneralForumTopicIsHidden &request);
|
||||||
|
@ -3882,6 +3882,11 @@ class CliClient final : public Actor {
|
|||||||
get_args(args, chat_id, message_thread_id, name, edit_icon_custom_emoji, icon_custom_emoji_id);
|
get_args(args, chat_id, message_thread_id, name, edit_icon_custom_emoji, icon_custom_emoji_id);
|
||||||
send_request(td_api::make_object<td_api::editForumTopic>(chat_id, message_thread_id, name, edit_icon_custom_emoji,
|
send_request(td_api::make_object<td_api::editForumTopic>(chat_id, message_thread_id, name, edit_icon_custom_emoji,
|
||||||
icon_custom_emoji_id));
|
icon_custom_emoji_id));
|
||||||
|
} else if (op == "gft") {
|
||||||
|
ChatId chat_id;
|
||||||
|
MessageThreadId message_thread_id;
|
||||||
|
get_args(args, chat_id, message_thread_id);
|
||||||
|
send_request(td_api::make_object<td_api::getForumTopic>(chat_id, message_thread_id));
|
||||||
} else if (op == "tftic") {
|
} else if (op == "tftic") {
|
||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
MessageThreadId message_thread_id;
|
MessageThreadId message_thread_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user