diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ad8064aa7..437a49f07 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -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 diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index d7d155638..1919b068d 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -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(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 &&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 &&promise) { TRY_STATUS_PROMISE(promise, is_forum(dialog_id)); diff --git a/td/telegram/ForumTopicManager.h b/td/telegram/ForumTopicManager.h index 3a6e526f1..dd28bb595 100644 --- a/td/telegram/ForumTopicManager.h +++ b/td/telegram/ForumTopicManager.h @@ -46,6 +46,8 @@ class ForumTopicManager final : public Actor { void get_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, Promise> &&promise); + void get_forum_topic_link(DialogId dialog_id, MessageId top_thread_message_id, Promise &&promise); + void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 25cc75866..48363c9ff 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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 result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(td_api::make_object(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_), diff --git a/td/telegram/Td.h b/td/telegram/Td.h index b5122a29d..f8990aac8 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -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); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 461878061..d9e1f6982 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -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(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(chat_id, message_thread_id)); } else if (op == "tftic") { ChatId chat_id; MessageThreadId message_thread_id; diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index cefdeba4b..1dfa51c32 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -95,8 +95,7 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector 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;