Add td_api::getMessageEmbeddingCode.
GitOrigin-RevId: cd26212418c3de5fc5046da456fad84f0f633d0d
This commit is contained in:
parent
ecc97d06b9
commit
8f4e9b2ed4
@ -661,7 +661,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
|
||||
|
||||
|
||||
//@description Describes a message
|
||||
//@id Message identifier, unique for the chat to which the message belongs
|
||||
//@id Message identifier; unique for the chat to which the message belongs
|
||||
//@sender_user_id Identifier of the user who sent the message; 0 if unknown. Currently, it is unknown for channel posts, for channel posts automatically forwarded to discussion group and for anonimously sent supergroup messages
|
||||
//@sender_chat_id Identifier of the chat on behalf of which the message was sent; 0 if none
|
||||
//@chat_id Chat identifier
|
||||
@ -682,7 +682,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
|
||||
//@interaction_info Information about interactions with the message; may be null
|
||||
//@reply_in_chat_id If non-zero, the identifier of the chat to which the replied message belongs; Currently, only messages in the Replies chat can have different reply_in_chat_id and chat_id
|
||||
//@reply_to_message_id If non-zero, the identifier of the message this message is replying to; can be the identifier of a deleted message
|
||||
//@message_thread_id If non-zero, the identifier of the message thread the message belongs to
|
||||
//@message_thread_id If non-zero, the identifier of the message thread the message belongs to; unique within the chat to which the message belongs
|
||||
//@ttl For self-destructing messages, the message's TTL (Time To Live), in seconds; 0 if none. TDLib will send updateDeleteMessages or updateMessageContent once the TTL expires
|
||||
//@ttl_expires_in Time left before the message expires, in seconds
|
||||
//@via_bot_user_id If non-zero, the user identifier of the bot through which this message was sent
|
||||
@ -3702,6 +3702,12 @@ getPublicMessageLink chat_id:int53 message_id:int53 for_album:Bool for_comment:B
|
||||
//@for_comment Pass true to create a link to the message as a channel post comment, or from a message thread
|
||||
getMessageLink chat_id:int53 message_id:int53 for_album:Bool for_comment:Bool = HttpUrl;
|
||||
|
||||
//@description Returns an HTML code for embedding the message. Available only for messages in supergroups and channels with a username
|
||||
//@chat_id Identifier of the chat to which the message belongs
|
||||
//@message_id Identifier of the message
|
||||
//@for_album Pass true to return an HTML code for embedding of the whole media album
|
||||
getMessageEmbeddingCode chat_id:int53 message_id:int53 for_album:Bool = Text;
|
||||
|
||||
//@description Returns information about a public or private message link @url The message link in the format "https://t.me/c/...", or "tg://privatepost?...", or "https://t.me/username/...", or "tg://resolve?..."
|
||||
getMessageLinkInfo url:string = MessageLinkInfo;
|
||||
|
||||
|
Binary file not shown.
@ -16212,6 +16212,59 @@ string MessagesManager::get_message_link(FullMessageId full_message_id, bool for
|
||||
<< dialog_id.get_channel_id().get() << "/" << m->message_id.get_server_message_id().get() << args;
|
||||
}
|
||||
|
||||
string MessagesManager::get_message_embedding_code(FullMessageId full_message_id, bool for_group,
|
||||
Promise<Unit> &&promise) {
|
||||
auto dialog_id = full_message_id.get_dialog_id();
|
||||
auto d = get_dialog_force(dialog_id);
|
||||
if (d == nullptr) {
|
||||
promise.set_error(Status::Error(400, "Chat not found"));
|
||||
return {};
|
||||
}
|
||||
if (!have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
promise.set_error(Status::Error(400, "Can't access the chat"));
|
||||
return {};
|
||||
}
|
||||
if (dialog_id.get_type() != DialogType::Channel ||
|
||||
td_->contacts_manager_->get_channel_username(dialog_id.get_channel_id()).empty()) {
|
||||
promise.set_error(Status::Error(
|
||||
400, "Message embedding code is available only for messages in public supergroups and channel chats"));
|
||||
return {};
|
||||
}
|
||||
|
||||
auto *m = get_message_force(d, full_message_id.get_message_id(), "get_message_embedding_code");
|
||||
if (m == nullptr) {
|
||||
promise.set_error(Status::Error(400, "Message not found"));
|
||||
return {};
|
||||
}
|
||||
if (m->message_id.is_yet_unsent()) {
|
||||
promise.set_error(Status::Error(400, "Message is yet unsent"));
|
||||
return {};
|
||||
}
|
||||
if (m->message_id.is_scheduled()) {
|
||||
promise.set_error(Status::Error(400, "Message is scheduled"));
|
||||
return {};
|
||||
}
|
||||
if (!m->message_id.is_server()) {
|
||||
promise.set_error(Status::Error(400, "Message is local"));
|
||||
return {};
|
||||
}
|
||||
|
||||
if (m->media_album_id == 0) {
|
||||
for_group = true; // default is true
|
||||
}
|
||||
|
||||
auto &links = public_message_links_[for_group][dialog_id].links_;
|
||||
auto it = links.find(m->message_id);
|
||||
if (it == links.end()) {
|
||||
td_->create_handler<ExportChannelMessageLinkQuery>(std::move(promise))
|
||||
->send(dialog_id.get_channel_id(), m->message_id, for_group, false);
|
||||
return {};
|
||||
}
|
||||
|
||||
promise.set_value(Unit());
|
||||
return it->second.second;
|
||||
}
|
||||
|
||||
Result<MessagesManager::MessageLinkInfo> MessagesManager::get_message_link_info(Slice url) {
|
||||
if (url.empty()) {
|
||||
return Status::Error("URL must be non-empty");
|
||||
|
@ -589,6 +589,8 @@ class MessagesManager : public Actor {
|
||||
std::pair<string, string> get_public_message_link(FullMessageId full_message_id, bool for_group, bool for_comment,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
string get_message_embedding_code(FullMessageId full_message_id, bool for_group, Promise<Unit> &&promise);
|
||||
|
||||
void on_get_public_message_link(FullMessageId full_message_id, bool for_group, string url, string html);
|
||||
|
||||
string get_message_link(FullMessageId full_message_id, bool for_group, bool for_comment, Promise<Unit> &&promise);
|
||||
|
@ -1165,6 +1165,29 @@ class GetMessageLinkRequest : public RequestActor<> {
|
||||
}
|
||||
};
|
||||
|
||||
class GetMessageEmbeddingCodeRequest : public RequestActor<> {
|
||||
FullMessageId full_message_id_;
|
||||
bool for_group_;
|
||||
|
||||
string html_;
|
||||
|
||||
void do_run(Promise<Unit> &&promise) override {
|
||||
html_ = td->messages_manager_->get_message_embedding_code(full_message_id_, for_group_, std::move(promise));
|
||||
}
|
||||
|
||||
void do_send_result() override {
|
||||
send_result(make_tl_object<td_api::text>(html_));
|
||||
}
|
||||
|
||||
public:
|
||||
GetMessageEmbeddingCodeRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id, int64 message_id,
|
||||
bool for_group)
|
||||
: RequestActor(std::move(td), request_id)
|
||||
, full_message_id_(DialogId(dialog_id), MessageId(message_id))
|
||||
, for_group_(for_group) {
|
||||
}
|
||||
};
|
||||
|
||||
class GetMessageLinkInfoRequest : public RequestActor<MessagesManager::MessageLinkInfo> {
|
||||
string url_;
|
||||
|
||||
@ -5148,6 +5171,11 @@ void Td::on_request(uint64 id, const td_api::getMessageLink &request) {
|
||||
request.for_comment_);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getMessageEmbeddingCode &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST(GetMessageEmbeddingCodeRequest, request.chat_id_, request.message_id_, request.for_album_);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getMessageLinkInfo &request) {
|
||||
CLEAN_INPUT_STRING(request.url_);
|
||||
CREATE_REQUEST(GetMessageLinkInfoRequest, std::move(request.url_));
|
||||
|
@ -500,6 +500,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, const td_api::getMessageLink &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getMessageEmbeddingCode &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getMessageLinkInfo &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getFile &request);
|
||||
|
@ -2633,6 +2633,14 @@ class CliClient final : public Actor {
|
||||
std::tie(for_album, for_comment) = split(args);
|
||||
send_request(td_api::make_object<td_api::getMessageLink>(as_chat_id(chat_id), as_message_id(message_id),
|
||||
as_bool(for_album), as_bool(for_comment)));
|
||||
} else if (op == "gmec") {
|
||||
string chat_id;
|
||||
string message_id;
|
||||
string for_album;
|
||||
std::tie(chat_id, args) = split(args);
|
||||
std::tie(message_id, for_album) = split(args);
|
||||
send_request(td_api::make_object<td_api::getMessageEmbeddingCode>(as_chat_id(chat_id), as_message_id(message_id),
|
||||
as_bool(for_album)));
|
||||
} else if (op == "gmli") {
|
||||
send_request(td_api::make_object<td_api::getMessageLinkInfo>(args));
|
||||
} else if (op == "gcmbd") {
|
||||
|
Loading…
Reference in New Issue
Block a user