Add td_api::getForumTopicLink.

This commit is contained in:
levlam 2022-12-05 13:03:38 +03:00
parent 6e2c2d9e03
commit ec0dd68a57
7 changed files with 53 additions and 5 deletions

View File

@ -3870,7 +3870,7 @@ internalLinkTypeLanguagePack language_pack_id:string = InternalLinkType;
//@description The link is a link to the language settings section of the app
internalLinkTypeLanguageSettings = InternalLinkType;
//@description The link is a link to a Telegram message. Call getMessageLinkInfo with the given URL to process the link @url URL to be passed to getMessageLinkInfo
//@description The link is a link to a Telegram message or a forum topic. Call getMessageLinkInfo with the given URL to process the link @url URL to be passed to getMessageLinkInfo
internalLinkTypeMessage url:string = InternalLinkType;
//@description The link contains a message draft text. A share screen needs to be shown to the user, then the chosen chat must be opened and the text is added to the input field
@ -3939,10 +3939,10 @@ internalLinkTypeVideoChat chat_username:string invite_hash:string is_live_stream
//@description Contains an HTTPS link to a message in a supergroup or channel @link Message link @is_public True, if the link will work for non-members of the chat
messageLink link:string is_public:Bool = MessageLink;
//@description Contains information about a link to a message in a chat
//@description Contains information about a link to a message or a forum topic in a chat
//@is_public True, if the link is a public link for a message in a chat
//@chat_id If found, identifier of the chat to which the message belongs, 0 otherwise
//@message_thread_id If found, identifier of the message thread in which to open the message, or which to open in case of a missing message
//@message_thread_id If found, identifier of the message thread in which to open the message, or which to open if the message is missing
//@message If found, the linked message; may be null
//@media_timestamp Timestamp from which the video/audio/video note/voice note playing must start, in seconds; 0 if not specified. The media can be in the message content or in its web page preview
//@for_album True, if the whole media album to which the message belongs is linked
@ -5343,6 +5343,9 @@ editForumTopic chat_id:int53 message_thread_id:int53 name:string edit_icon_custo
//@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 Returns an HTTPS link to a topic in a forum chat. This is an offline request @chat_id Identifier of the chat @message_thread_id Message thread identifier of the forum topic
getForumTopicLink chat_id:int53 message_thread_id:int53 = HttpUrl;
//@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
//@message_thread_id Message thread identifier of the forum topic

View File

@ -18,6 +18,7 @@
#include "td/telegram/MessagesManager.h"
#include "td/telegram/MessageThreadDb.h"
#include "td/telegram/misc.h"
#include "td/telegram/OptionManager.h"
#include "td/telegram/ServerMessageId.h"
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
@ -387,6 +388,29 @@ void ForumTopicManager::get_forum_topic(DialogId dialog_id, MessageId top_thread
td_->create_handler<GetForumTopicQuery>(std::move(promise))->send(channel_id, top_thread_message_id);
}
void ForumTopicManager::get_forum_topic_link(DialogId dialog_id, MessageId top_thread_message_id,
Promise<string> &&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"));
}
SliceBuilder sb;
sb << td_->option_manager_->get_option_string("t_me_url", "https://t.me/");
auto dialog_username = td_->contacts_manager_->get_channel_first_username(channel_id);
if (!dialog_username.empty()) {
sb << dialog_username;
} else {
sb << "c/" << channel_id.get();
}
sb << '/' << top_thread_message_id.get_server_message_id().get();
promise.set_value(sb.as_cslice().str());
}
void ForumTopicManager::toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id,
bool is_closed, Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, is_forum(dialog_id));

View File

@ -46,6 +46,8 @@ class ForumTopicManager final : public Actor {
void get_forum_topic(DialogId dialog_id, MessageId top_thread_message_id,
Promise<td_api::object_ptr<td_api::forumTopic>> &&promise);
void get_forum_topic_link(DialogId dialog_id, MessageId top_thread_message_id, Promise<string> &&promise);
void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed,
Promise<Unit> &&promise);

View File

@ -5568,6 +5568,19 @@ void Td::on_request(uint64 id, const td_api::getForumTopic &request) {
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getForumTopicLink &request) {
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(td_api::make_object<td_api::httpUrl>(result.move_as_ok()));
}
});
forum_topic_manager_->get_forum_topic_link(DialogId(request.chat_id_), MessageId(request.message_thread_id_),
std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request) {
CREATE_OK_REQUEST_PROMISE();
forum_topic_manager_->toggle_forum_topic_is_closed(DialogId(request.chat_id_), MessageId(request.message_thread_id_),

View File

@ -750,6 +750,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getForumTopic &request);
void on_request(uint64 id, const td_api::getForumTopicLink &request);
void on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request);
void on_request(uint64 id, const td_api::toggleGeneralForumTopicIsHidden &request);

View File

@ -3887,6 +3887,11 @@ class CliClient final : public Actor {
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 == "gftl") {
ChatId chat_id;
MessageThreadId message_thread_id;
get_args(args, chat_id, message_thread_id);
send_request(td_api::make_object<td_api::getForumTopicLink>(chat_id, message_thread_id));
} else if (op == "tftic") {
ChatId chat_id;
MessageThreadId message_thread_id;

View File

@ -95,8 +95,7 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
double now = Clocks::system();
// Keep all immune files
// Remove all files with (atime > now - max_time_from_last_access)
// Remove all suitable files with (atime > now - max_time_from_last_access)
td::remove_if(files, [&](const FullFileInfo &info) {
if (token_) {
return false;