Allow to specify emoji for sent stickers.

This commit is contained in:
levlam 2020-12-19 14:31:42 +03:00
parent 905d09d82c
commit bbde4f32c6
9 changed files with 63 additions and 28 deletions

View File

@ -1816,8 +1816,8 @@ inputMessageDocument document:InputFile thumbnail:inputThumbnail disable_content
//@ttl Photo TTL (Time To Live), in seconds (0-60). A non-zero TTL can be specified only in private chats //@ttl Photo TTL (Time To Live), in seconds (0-60). A non-zero TTL can be specified only in private chats
inputMessagePhoto photo:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> width:int32 height:int32 caption:formattedText ttl:int32 = InputMessageContent; inputMessagePhoto photo:InputFile thumbnail:inputThumbnail added_sticker_file_ids:vector<int32> width:int32 height:int32 caption:formattedText ttl:int32 = InputMessageContent;
//@description A sticker message @sticker Sticker to be sent @thumbnail Sticker thumbnail, if available @width Sticker width @height Sticker height //@description A sticker message @sticker Sticker to be sent @thumbnail Sticker thumbnail, if available @width Sticker width @height Sticker height @emoji Emoji used to choose the sticker
inputMessageSticker sticker:InputFile thumbnail:inputThumbnail width:int32 height:int32 = InputMessageContent; inputMessageSticker sticker:InputFile thumbnail:inputThumbnail width:int32 height:int32 emoji:string = InputMessageContent;
//@description A video message @video Video to be sent @thumbnail Video thumbnail, if available @added_sticker_file_ids File identifiers of the stickers added to the video, if applicable //@description A video message @video Video to be sent @thumbnail Video thumbnail, if available @added_sticker_file_ids File identifiers of the stickers added to the video, if applicable
//@duration Duration of the video, in seconds @width Video width @height Video height @supports_streaming True, if the video should be tried to be streamed //@duration Duration of the video, in seconds @width Video width @height Video height @supports_streaming True, if the video should be tried to be streamed

Binary file not shown.

View File

@ -1594,6 +1594,7 @@ static Result<InputMessageContent> create_input_message_content(
unique_ptr<MessageContent> content; unique_ptr<MessageContent> content;
UserId via_bot_user_id; UserId via_bot_user_id;
int32 ttl = 0; int32 ttl = 0;
string emoji;
bool is_bot = td->auth_manager_->is_bot(); bool is_bot = td->auth_manager_->is_bot();
switch (input_message_content->get_id()) { switch (input_message_content->get_id()) {
case td_api::inputMessageText::ID: { case td_api::inputMessageText::ID: {
@ -1709,6 +1710,9 @@ static Result<InputMessageContent> create_input_message_content(
} }
case td_api::inputMessageSticker::ID: { case td_api::inputMessageSticker::ID: {
auto input_sticker = static_cast<td_api::inputMessageSticker *>(input_message_content.get()); auto input_sticker = static_cast<td_api::inputMessageSticker *>(input_message_content.get());
emoji = std::move(input_sticker->emoji_);
td->stickers_manager_->create_sticker(file_id, string(), thumbnail, td->stickers_manager_->create_sticker(file_id, string(), thumbnail,
get_dimensions(input_sticker->width_, input_sticker->height_), nullptr, get_dimensions(input_sticker->width_, input_sticker->height_), nullptr,
false, nullptr); false, nullptr);
@ -1967,7 +1971,8 @@ static Result<InputMessageContent> create_input_message_content(
default: default:
UNREACHABLE(); UNREACHABLE();
} }
return InputMessageContent{std::move(content), disable_web_page_preview, clear_draft, ttl, via_bot_user_id}; return InputMessageContent{std::move(content), disable_web_page_preview, clear_draft, ttl,
via_bot_user_id, std::move(emoji)};
} }
Result<InputMessageContent> get_input_message_content( Result<InputMessageContent> get_input_message_content(
@ -2323,7 +2328,7 @@ static tl_object_ptr<telegram_api::inputMediaInvoice> get_input_media_invoice(co
static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl( static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
const MessageContent *content, Td *td, tl_object_ptr<telegram_api::InputFile> input_file, const MessageContent *content, Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
tl_object_ptr<telegram_api::InputFile> input_thumbnail, int32 ttl) { tl_object_ptr<telegram_api::InputFile> input_thumbnail, int32 ttl, const string &emoji) {
if (!can_have_input_media(td, content)) { if (!can_have_input_media(td, content)) {
return nullptr; return nullptr;
} }
@ -2381,7 +2386,8 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
} }
case MessageContentType::Sticker: { case MessageContentType::Sticker: {
auto m = static_cast<const MessageSticker *>(content); auto m = static_cast<const MessageSticker *>(content);
return td->stickers_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail)); return td->stickers_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail),
emoji);
} }
case MessageContentType::Venue: { case MessageContentType::Venue: {
auto m = static_cast<const MessageVenue *>(content); auto m = static_cast<const MessageVenue *>(content);
@ -2442,7 +2448,8 @@ tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *co
bool force) { bool force) {
bool had_input_file = input_file != nullptr; bool had_input_file = input_file != nullptr;
bool had_input_thumbnail = input_thumbnail != nullptr; bool had_input_thumbnail = input_thumbnail != nullptr;
auto input_media = get_input_media_impl(content, td, std::move(input_file), std::move(input_thumbnail), ttl); auto input_media =
get_input_media_impl(content, td, std::move(input_file), std::move(input_thumbnail), ttl, string());
auto was_uploaded = FileManager::extract_was_uploaded(input_media); auto was_uploaded = FileManager::extract_was_uploaded(input_media);
if (had_input_file) { if (had_input_file) {
if (!was_uploaded) { if (!was_uploaded) {
@ -2471,8 +2478,9 @@ tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *co
return input_media; return input_media;
} }
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td, int32 ttl, bool force) { tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td, int32 ttl,
auto input_media = get_input_media_impl(content, td, nullptr, nullptr, ttl); const string &emoji, bool force) {
auto input_media = get_input_media_impl(content, td, nullptr, nullptr, ttl, emoji);
auto file_reference = FileManager::extract_file_reference(input_media); auto file_reference = FileManager::extract_file_reference(input_media);
if (file_reference == FileReferenceView::invalid_file_reference()) { if (file_reference == FileReferenceView::invalid_file_reference()) {
auto file_id = get_message_content_any_file_id(content); auto file_id = get_message_content_any_file_id(content);

View File

@ -61,14 +61,16 @@ struct InputMessageContent {
bool clear_draft = false; bool clear_draft = false;
int32 ttl = 0; int32 ttl = 0;
UserId via_bot_user_id; UserId via_bot_user_id;
string emoji;
InputMessageContent(unique_ptr<MessageContent> &&content, bool disable_web_page_preview, bool clear_draft, int32 ttl, InputMessageContent(unique_ptr<MessageContent> &&content, bool disable_web_page_preview, bool clear_draft, int32 ttl,
UserId via_bot_user_id) UserId via_bot_user_id, string emoji)
: content(std::move(content)) : content(std::move(content))
, disable_web_page_preview(disable_web_page_preview) , disable_web_page_preview(disable_web_page_preview)
, clear_draft(clear_draft) , clear_draft(clear_draft)
, ttl(ttl) , ttl(ttl)
, via_bot_user_id(via_bot_user_id) { , via_bot_user_id(via_bot_user_id)
, emoji(std::move(emoji)) {
} }
}; };
@ -112,7 +114,8 @@ tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *co
FileId file_id, FileId thumbnail_file_id, int32 ttl, FileId file_id, FileId thumbnail_file_id, int32 ttl,
bool force); bool force);
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td, int32 ttl, bool force); tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td, int32 ttl,
const string &emoji, bool force);
void delete_message_content_thumbnail(MessageContent *content, Td *td); void delete_message_content_thumbnail(MessageContent *content, Td *td);

View File

@ -4568,6 +4568,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
bool has_local_thread_message_ids = !local_thread_message_ids.empty(); bool has_local_thread_message_ids = !local_thread_message_ids.empty();
bool has_linked_top_thread_message_id = linked_top_thread_message_id.is_valid(); bool has_linked_top_thread_message_id = linked_top_thread_message_id.is_valid();
bool has_interaction_info_update_date = interaction_info_update_date != 0; bool has_interaction_info_update_date = interaction_info_update_date != 0;
bool has_send_emoji = !send_emoji.empty();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_channel_post); STORE_FLAG(is_channel_post);
STORE_FLAG(is_outgoing); STORE_FLAG(is_outgoing);
@ -4626,6 +4627,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
STORE_FLAG(has_linked_top_thread_message_id); STORE_FLAG(has_linked_top_thread_message_id);
STORE_FLAG(is_pinned); STORE_FLAG(is_pinned);
STORE_FLAG(has_interaction_info_update_date); STORE_FLAG(has_interaction_info_update_date);
STORE_FLAG(has_send_emoji);
END_STORE_FLAGS(); END_STORE_FLAGS();
} }
@ -4731,6 +4733,9 @@ void MessagesManager::Message::store(StorerT &storer) const {
if (has_interaction_info_update_date) { if (has_interaction_info_update_date) {
store(interaction_info_update_date, storer); store(interaction_info_update_date, storer);
} }
if (has_send_emoji) {
store(send_emoji, storer);
}
store_message_content(content.get(), storer); store_message_content(content.get(), storer);
if (has_reply_markup) { if (has_reply_markup) {
store(reply_markup, storer); store(reply_markup, storer);
@ -4773,6 +4778,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
bool has_local_thread_message_ids = false; bool has_local_thread_message_ids = false;
bool has_linked_top_thread_message_id = false; bool has_linked_top_thread_message_id = false;
bool has_interaction_info_update_date = false; bool has_interaction_info_update_date = false;
bool has_send_emoji = false;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_channel_post); PARSE_FLAG(is_channel_post);
PARSE_FLAG(is_outgoing); PARSE_FLAG(is_outgoing);
@ -4831,6 +4837,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
PARSE_FLAG(has_linked_top_thread_message_id); PARSE_FLAG(has_linked_top_thread_message_id);
PARSE_FLAG(is_pinned); PARSE_FLAG(is_pinned);
PARSE_FLAG(has_interaction_info_update_date); PARSE_FLAG(has_interaction_info_update_date);
PARSE_FLAG(has_send_emoji);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
} }
@ -4942,6 +4949,9 @@ void MessagesManager::Message::parse(ParserT &parser) {
if (has_interaction_info_update_date) { if (has_interaction_info_update_date) {
parse(interaction_info_update_date, parser); parse(interaction_info_update_date, parser);
} }
if (has_send_emoji) {
parse(send_emoji, parser);
}
parse_message_content(content, parser); parse_message_content(content, parser);
if (has_reply_markup) { if (has_reply_markup) {
parse(reply_markup, parser); parse(reply_markup, parser);
@ -22939,6 +22949,7 @@ Result<MessageId> MessagesManager::send_message(DialogId dialog_id, MessageId to
m->ttl = message_content.ttl; m->ttl = message_content.ttl;
m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type()); m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type());
} }
m->send_emoji = std::move(message_content.emoji);
if (message_content.clear_draft) { if (message_content.clear_draft) {
if (top_thread_message_id.is_valid()) { if (top_thread_message_id.is_valid()) {
@ -23001,7 +23012,7 @@ Result<InputMessageContent> MessagesManager::process_input_message_content(
} }
return InputMessageContent(std::move(content), get_message_disable_web_page_preview(copied_message), false, 0, return InputMessageContent(std::move(content), get_message_disable_web_page_preview(copied_message), false, 0,
UserId()); UserId(), copied_message->send_emoji);
} }
TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_)); TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_));
@ -23259,7 +23270,8 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect
on_secret_message_media_uploaded(dialog_id, m, std::move(secret_input_media), file_id, thumbnail_file_id); on_secret_message_media_uploaded(dialog_id, m, std::move(secret_input_media), file_id, thumbnail_file_id);
} }
} else { } else {
auto input_media = get_input_media(content, td_, m->ttl, td_->auth_manager_->is_bot() && bad_parts.empty()); auto input_media =
get_input_media(content, td_, m->ttl, m->send_emoji, td_->auth_manager_->is_bot() && bad_parts.empty());
if (input_media == nullptr) { if (input_media == nullptr) {
if (content_type == MessageContentType::Game || content_type == MessageContentType::Poll) { if (content_type == MessageContentType::Game || content_type == MessageContentType::Poll) {
return; return;
@ -23439,7 +23451,7 @@ void MessagesManager::on_upload_message_media_success(DialogId dialog_id, Messag
update_message_content(dialog_id, m, std::move(content), true, true, true); update_message_content(dialog_id, m, std::move(content), true, true, true);
auto input_media = get_input_media(m->content.get(), td_, m->ttl, true); auto input_media = get_input_media(m->content.get(), td_, m->ttl, m->send_emoji, true);
Status result; Status result;
if (input_media == nullptr) { if (input_media == nullptr) {
result = Status::Error(400, "Failed to upload file"); result = Status::Error(400, "Failed to upload file");
@ -23608,7 +23620,7 @@ void MessagesManager::do_send_message_group(int64 media_album_id) {
} }
const FormattedText *caption = get_message_content_caption(m->content.get()); const FormattedText *caption = get_message_content_caption(m->content.get());
auto input_media = get_input_media(m->content.get(), td_, m->ttl, true); auto input_media = get_input_media(m->content.get(), td_, m->ttl, m->send_emoji, true);
if (input_media == nullptr) { if (input_media == nullptr) {
// TODO return CHECK // TODO return CHECK
auto file_id = get_message_content_any_file_id(m->content.get()); auto file_id = get_message_content_any_file_id(m->content.get());
@ -24819,7 +24831,7 @@ void MessagesManager::edit_inline_message_media(const string &inline_message_id,
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified")); return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
} }
auto input_media = get_input_media(content.content.get(), td_, 0, true); auto input_media = get_input_media(content.content.get(), td_, 0, string(), true);
if (input_media == nullptr) { if (input_media == nullptr) {
return promise.set_error(Status::Error(400, "Invalid message content specified")); return promise.set_error(Status::Error(400, "Invalid message content specified"));
} }
@ -25892,6 +25904,7 @@ Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, v
m->ttl = message->ttl; m->ttl = message->ttl;
m->is_content_secret = message->is_content_secret; m->is_content_secret = message->is_content_secret;
m->media_album_id = new_media_album_ids[message->media_album_id].first; m->media_album_id = new_media_album_ids[message->media_album_id].first;
m->send_emoji = message->send_emoji;
save_send_message_log_event(dialog_id, m); save_send_message_log_event(dialog_id, m);
do_send_message(dialog_id, m); do_send_message(dialog_id, m);
@ -26142,6 +26155,7 @@ Result<MessageId> MessagesManager::add_local_message(
m->ttl = message_content.ttl; m->ttl = message_content.ttl;
} }
m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type()); m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type());
m->send_emoji = std::move(message_content.emoji);
m->have_previous = true; m->have_previous = true;
m->have_next = true; m->have_next = true;

View File

@ -1107,6 +1107,8 @@ class MessagesManager : public Actor {
DialogId real_forward_from_dialog_id; // for resend_message DialogId real_forward_from_dialog_id; // for resend_message
MessageId real_forward_from_message_id; // for resend_message MessageId real_forward_from_message_id; // for resend_message
string send_emoji; // for send_message
NotificationId notification_id; NotificationId notification_id;
NotificationId removed_notification_id; NotificationId removed_notification_id;

View File

@ -2347,14 +2347,18 @@ SecretInputMedia StickersManager::get_secret_input_media(FileId sticker_file_id,
tl_object_ptr<telegram_api::InputMedia> StickersManager::get_input_media( tl_object_ptr<telegram_api::InputMedia> StickersManager::get_input_media(
FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file, FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file,
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const { tl_object_ptr<telegram_api::InputFile> input_thumbnail, const string &emoji) const {
auto file_view = td_->file_manager_->get_file_view(file_id); auto file_view = td_->file_manager_->get_file_view(file_id);
if (file_view.is_encrypted()) { if (file_view.is_encrypted()) {
return nullptr; return nullptr;
} }
if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) { if (file_view.has_remote_location() && !file_view.main_remote_location().is_web() && input_file == nullptr) {
return make_tl_object<telegram_api::inputMediaDocument>(0, file_view.main_remote_location().as_input_document(), 0, int32 flags = 0;
string()); if (!emoji.empty()) {
flags |= telegram_api::inputMediaDocument::QUERY_MASK;
}
return make_tl_object<telegram_api::inputMediaDocument>(flags, file_view.main_remote_location().as_input_document(),
0, emoji);
} }
if (file_view.has_url()) { if (file_view.has_url()) {
return make_tl_object<telegram_api::inputMediaDocumentExternal>(0, file_view.url(), 0); return make_tl_object<telegram_api::inputMediaDocumentExternal>(0, file_view.url(), 0);
@ -4757,7 +4761,7 @@ void StickersManager::create_new_sticker_set(UserId user_id, string &title, stri
void StickersManager::upload_sticker_file(UserId user_id, FileId file_id, Promise<Unit> &&promise) { void StickersManager::upload_sticker_file(UserId user_id, FileId file_id, Promise<Unit> &&promise) {
FileId upload_file_id; FileId upload_file_id;
if (td_->file_manager_->get_file_view(file_id).get_type() == FileType::Sticker) { if (td_->file_manager_->get_file_view(file_id).get_type() == FileType::Sticker) {
CHECK(get_input_media(file_id, nullptr, nullptr) == nullptr); CHECK(get_input_media(file_id, nullptr, nullptr, string()) == nullptr);
upload_file_id = dup_sticker(td_->file_manager_->dup_file_id(file_id), file_id); upload_file_id = dup_sticker(td_->file_manager_->dup_file_id(file_id), file_id);
} else { } else {
CHECK(td_->documents_manager_->get_input_media(file_id, nullptr, nullptr) == nullptr); CHECK(td_->documents_manager_->get_input_media(file_id, nullptr, nullptr) == nullptr);
@ -4818,7 +4822,7 @@ void StickersManager::do_upload_sticker_file(UserId user_id, FileId file_id,
bool is_animated = file_view.get_type() == FileType::Sticker; bool is_animated = file_view.get_type() == FileType::Sticker;
bool had_input_file = input_file != nullptr; bool had_input_file = input_file != nullptr;
auto input_media = is_animated ? get_input_media(file_id, std::move(input_file), nullptr) auto input_media = is_animated ? get_input_media(file_id, std::move(input_file), nullptr, string())
: td_->documents_manager_->get_input_media(file_id, std::move(input_file), nullptr); : td_->documents_manager_->get_input_media(file_id, std::move(input_file), nullptr);
CHECK(input_media != nullptr); CHECK(input_media != nullptr);
if (had_input_file && !FileManager::extract_was_uploaded(input_media)) { if (had_input_file && !FileManager::extract_was_uploaded(input_media)) {

View File

@ -77,7 +77,8 @@ class StickersManager : public Actor {
tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id, tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
tl_object_ptr<telegram_api::InputFile> input_file, tl_object_ptr<telegram_api::InputFile> input_file,
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const; tl_object_ptr<telegram_api::InputFile> input_thumbnail,
const string &emoji) const;
SecretInputMedia get_secret_input_media(FileId sticker_file_id, SecretInputMedia get_secret_input_media(FileId sticker_file_id,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file, tl_object_ptr<telegram_api::InputEncryptedFile> input_file,

View File

@ -3593,8 +3593,8 @@ class CliClient final : public Actor {
string sticker_path; string sticker_path;
std::tie(chat_id, sticker_path) = split(args); std::tie(chat_id, sticker_path) = split(args);
send_message(chat_id, send_message(chat_id, td_api::make_object<td_api::inputMessageSticker>(as_input_file(sticker_path), nullptr, 0, 0,
td_api::make_object<td_api::inputMessageSticker>(as_input_file(sticker_path), nullptr, 0, 0)); string()));
} else if (op == "sstt") { } else if (op == "sstt") {
string chat_id; string chat_id;
string sticker_path; string sticker_path;
@ -3602,14 +3602,17 @@ class CliClient final : public Actor {
std::tie(chat_id, args) = split(args); std::tie(chat_id, args) = split(args);
std::tie(sticker_path, thumbnail_path) = split(args); std::tie(sticker_path, thumbnail_path) = split(args);
send_message(chat_id, td_api::make_object<td_api::inputMessageSticker>(as_input_file(sticker_path), send_message(chat_id, td_api::make_object<td_api::inputMessageSticker>(
as_input_thumbnail(thumbnail_path), 0, 0)); as_input_file(sticker_path), as_input_thumbnail(thumbnail_path), 0, 0, string()));
} else if (op == "ssid") { } else if (op == "ssid") {
string chat_id; string chat_id;
string file_id; string file_id;
std::tie(chat_id, file_id) = split(args); string emoji;
std::tie(chat_id, args) = split(args);
std::tie(file_id, emoji) = split(args);
send_message(chat_id, td_api::make_object<td_api::inputMessageSticker>(as_input_file_id(file_id), nullptr, 0, 0)); send_message(chat_id,
td_api::make_object<td_api::inputMessageSticker>(as_input_file_id(file_id), nullptr, 0, 0, emoji));
} else if (op == "sv" || op == "svttl") { } else if (op == "sv" || op == "svttl") {
string chat_id; string chat_id;
string video_path; string video_path;