Add messageSticker.is_premium.

This commit is contained in:
levlam 2022-06-03 16:33:49 +03:00
parent 1e417ea212
commit 8b9bed6a0b
5 changed files with 49 additions and 25 deletions

View File

@ -1845,8 +1845,8 @@ messagePhoto photo:photo caption:formattedText is_secret:Bool = MessageContent;
//@description An expired photo message (self-destructed after TTL has elapsed)
messageExpiredPhoto = MessageContent;
//@description A sticker message @sticker The sticker description
messageSticker sticker:sticker = MessageContent;
//@description A sticker message @sticker The sticker description @is_premium True, if premium animation of the sticker must be played
messageSticker sticker:sticker is_premium:Bool = MessageContent;
//@description A video message @video The video description @caption Video caption @is_secret True, if the video thumbnail must be blurred and the video must be shown only while tapped
messageVideo video:video caption:formattedText is_secret:Bool = MessageContent;

View File

@ -14,6 +14,7 @@
#include "td/telegram/CallDiscardReason.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Contact.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
@ -172,9 +173,10 @@ class MessagePhoto final : public MessageContent {
class MessageSticker final : public MessageContent {
public:
FileId file_id;
bool is_premium = false;
MessageSticker() = default;
explicit MessageSticker(FileId file_id) : file_id(file_id) {
MessageSticker(FileId file_id, bool is_premium) : file_id(file_id), is_premium(is_premium) {
}
MessageContentType get_type() const final {
@ -848,6 +850,9 @@ static void store(const MessageContent *content, StorerT &storer) {
case MessageContentType::Sticker: {
const auto *m = static_cast<const MessageSticker *>(content);
td->stickers_manager_->store_sticker(m->file_id, false, storer, "MessageSticker");
BEGIN_STORE_FLAGS();
STORE_FLAG(m->is_premium);
END_STORE_FLAGS();
break;
}
case MessageContentType::Text: {
@ -1210,6 +1215,11 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
case MessageContentType::Sticker: {
auto m = make_unique<MessageSticker>();
m->file_id = td->stickers_manager_->parse_sticker(false, parser);
if (parser.version() >= static_cast<int32>(Version::AddMessageStickerFlags)) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(m->is_premium);
END_PARSE_FLAGS();
}
is_bad = !m->file_id.is_valid();
content = std::move(m);
break;
@ -1654,7 +1664,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
} else if (allowed_media_content_id == td_api::inputMessagePhoto::ID) {
result.message_content = make_unique<MessagePhoto>(std::move(*photo), std::move(caption));
} else if (allowed_media_content_id == td_api::inputMessageSticker::ID) {
result.message_content = make_unique<MessageSticker>(file_id);
result.message_content = make_unique<MessageSticker>(file_id, false);
} else if (allowed_media_content_id == td_api::inputMessageVideo::ID) {
result.message_content = make_unique<MessageVideo>(file_id, std::move(caption));
} else if (allowed_media_content_id == td_api::inputMessageVoiceNote::ID) {
@ -1692,7 +1702,7 @@ unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl) {
static Result<InputMessageContent> create_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td,
FormattedText caption, FileId file_id, PhotoSize thumbnail, vector<FileId> sticker_file_ids) {
FormattedText caption, FileId file_id, PhotoSize thumbnail, vector<FileId> sticker_file_ids, bool is_premium) {
CHECK(input_message_content != nullptr);
LOG(INFO) << "Create InputMessageContent with file " << file_id << " and thumbnail " << thumbnail.file_id;
@ -1840,7 +1850,7 @@ static Result<InputMessageContent> create_input_message_content(
get_dimensions(input_sticker->width_, input_sticker->height_, nullptr),
nullptr, StickerFormat::Unknown, nullptr);
content = make_unique<MessageSticker>(file_id);
content = make_unique<MessageSticker>(file_id, is_premium);
break;
}
case td_api::inputMessageVideo::ID: {
@ -2003,7 +2013,7 @@ static Result<InputMessageContent> create_input_message_content(
}
Result<InputMessageContent> get_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td) {
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td, bool is_premium) {
bool is_secret = dialog_id.get_type() == DialogType::SecretChat;
LOG(INFO) << "Get input message content from " << to_string(input_message_content);
@ -2116,7 +2126,7 @@ Result<InputMessageContent> get_input_message_content(
TRY_RESULT(caption, process_input_caption(td->contacts_manager_.get(), dialog_id,
extract_input_caption(input_message_content), td->auth_manager_->is_bot()));
return create_input_message_content(dialog_id, std::move(input_message_content), td, std::move(caption), file_id,
std::move(thumbnail), std::move(sticker_file_ids));
std::move(thumbnail), std::move(sticker_file_ids), is_premium);
}
bool can_have_input_media(const Td *td, const MessageContent *content, bool is_server) {
@ -3094,7 +3104,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Animation: {
const auto *old_ = static_cast<const MessageAnimation *>(old_content);
const auto *new_ = static_cast<const MessageAnimation *>(new_content);
if (new_->file_id != old_->file_id) {
if (old_->file_id != new_->file_id) {
if (need_merge_files) {
td->animations_manager_->merge_animations(new_->file_id, old_->file_id, false);
}
@ -3108,7 +3118,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Audio: {
const auto *old_ = static_cast<const MessageAudio *>(old_content);
const auto *new_ = static_cast<const MessageAudio *>(new_content);
if (new_->file_id != old_->file_id) {
if (old_->file_id != new_->file_id) {
if (need_merge_files) {
td->audios_manager_->merge_audios(new_->file_id, old_->file_id, false);
}
@ -3130,7 +3140,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Document: {
const auto *old_ = static_cast<const MessageDocument *>(old_content);
const auto *new_ = static_cast<const MessageDocument *>(new_content);
if (new_->file_id != old_->file_id) {
if (old_->file_id != new_->file_id) {
if (need_merge_files) {
td->documents_manager_->merge_documents(new_->file_id, old_->file_id, false);
}
@ -3266,12 +3276,15 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Sticker: {
const auto *old_ = static_cast<const MessageSticker *>(old_content);
const auto *new_ = static_cast<const MessageSticker *>(new_content);
if (new_->file_id != old_->file_id) {
if (old_->file_id != new_->file_id) {
if (need_merge_files) {
td->stickers_manager_->merge_stickers(new_->file_id, old_->file_id, false);
}
need_update = true;
}
if (old_->is_premium != new_->is_premium) {
need_update = true;
}
break;
}
case MessageContentType::Venue: {
@ -3289,7 +3302,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Video: {
const auto *old_ = static_cast<const MessageVideo *>(old_content);
const auto *new_ = static_cast<const MessageVideo *>(new_content);
if (new_->file_id != old_->file_id) {
if (old_->file_id != new_->file_id) {
if (need_merge_files) {
td->videos_manager_->merge_videos(new_->file_id, old_->file_id, false);
}
@ -3303,7 +3316,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::VideoNote: {
const auto *old_ = static_cast<const MessageVideoNote *>(old_content);
const auto *new_ = static_cast<const MessageVideoNote *>(new_content);
if (new_->file_id != old_->file_id) {
if (old_->file_id != new_->file_id) {
if (need_merge_files) {
td->video_notes_manager_->merge_video_notes(new_->file_id, old_->file_id, false);
}
@ -3317,7 +3330,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::VoiceNote: {
const auto *old_ = static_cast<const MessageVoiceNote *>(old_content);
const auto *new_ = static_cast<const MessageVoiceNote *>(new_content);
if (new_->file_id != old_->file_id) {
if (old_->file_id != new_->file_id) {
if (need_merge_files) {
td->voice_notes_manager_->merge_voice_notes(new_->file_id, old_->file_id, false);
}
@ -3979,7 +3992,7 @@ static tl_object_ptr<ToT> secret_to_telegram(FromT &from) {
}
static unique_ptr<MessageContent> get_document_message_content(Document &&parsed_document, FormattedText &&caption,
bool is_opened) {
bool is_opened, bool is_premium) {
auto file_id = parsed_document.file_id;
if (!parsed_document.empty()) {
CHECK(file_id.is_valid());
@ -3992,7 +4005,7 @@ static unique_ptr<MessageContent> get_document_message_content(Document &&parsed
case Document::Type::General:
return make_unique<MessageDocument>(file_id, std::move(caption));
case Document::Type::Sticker:
return make_unique<MessageSticker>(file_id);
return make_unique<MessageSticker>(file_id, is_premium);
case Document::Type::Unknown:
return make_unique<MessageUnsupported>();
case Document::Type::Video:
@ -4009,11 +4022,11 @@ static unique_ptr<MessageContent> get_document_message_content(Document &&parsed
static unique_ptr<MessageContent> get_document_message_content(Td *td, tl_object_ptr<telegram_api::document> &&document,
DialogId owner_dialog_id, FormattedText &&caption,
bool is_opened,
bool is_opened, bool is_premium,
MultiPromiseActor *load_data_multipromise_ptr) {
return get_document_message_content(
td->documents_manager_->on_get_document(std::move(document), owner_dialog_id, load_data_multipromise_ptr),
std::move(caption), is_opened);
std::move(caption), is_opened, is_premium);
}
unique_ptr<MessageContent> get_secret_message_content(
@ -4181,7 +4194,7 @@ unique_ptr<MessageContent> get_secret_message_content(
auto external_document = move_tl_object_as<secret_api::decryptedMessageMediaExternalDocument>(media);
auto document = secret_to_telegram_document(*external_document);
return get_document_message_content(td, std::move(document), owner_dialog_id,
FormattedText{std::move(message_text), std::move(entities)}, false,
FormattedText{std::move(message_text), std::move(entities)}, false, false,
&load_data_multipromise);
}
default:
@ -4221,7 +4234,8 @@ unique_ptr<MessageContent> get_secret_message_content(
message_document->attributes_.clear();
auto document = td->documents_manager_->on_get_document(
{std::move(file), std::move(message_document), std::move(attributes)}, owner_dialog_id);
return get_document_message_content(std::move(document), {std::move(message_text), std::move(entities)}, false);
return get_document_message_content(std::move(document), {std::move(message_text), std::move(entities)}, false,
false);
}
default:
LOG(ERROR) << "Unsupported: " << to_string(media);
@ -4355,7 +4369,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
*ttl = message_document->ttl_seconds_;
}
return get_document_message_content(td, move_tl_object_as<telegram_api::document>(document_ptr), owner_dialog_id,
std::move(message), is_content_read, nullptr);
std::move(message), is_content_read, !message_document->nopremium_, nullptr);
}
case telegram_api::messageMediaGame::ID: {
auto message_game = move_tl_object_as<telegram_api::messageMediaGame>(media);
@ -4572,6 +4586,11 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
}
result->file_id = td->stickers_manager_->dup_sticker(fix_file_id(result->file_id), result->file_id);
CHECK(result->file_id.is_valid());
if (type == MessageContentDupType::SendViaBot || type == MessageContentDupType::Forward) {
result->is_premium = false;
} else {
result->is_premium = G()->shared_config().get_option_boolean("is_premium");
}
return std::move(result);
}
case MessageContentType::Text:
@ -4995,7 +5014,10 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::Sticker: {
const auto *m = static_cast<const MessageSticker *>(content);
return make_tl_object<td_api::messageSticker>(td->stickers_manager_->get_sticker_object(m->file_id));
auto sticker = td->stickers_manager_->get_sticker_object(m->file_id);
CHECK(sticker != nullptr);
auto is_premium = m->is_premium && sticker->premium_animation_ != nullptr;
return make_tl_object<td_api::messageSticker>(std::move(sticker), is_premium);
}
case MessageContentType::Text: {
const auto *m = static_cast<const MessageText *>(content);

View File

@ -102,7 +102,7 @@ unique_ptr<MessageContent> create_screenshot_taken_message_content();
unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl);
Result<InputMessageContent> get_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td);
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td, bool is_premium);
bool can_have_input_media(const Td *td, const MessageContent *content, bool is_server);

View File

@ -25405,7 +25405,8 @@ Result<InputMessageContent> MessagesManager::process_input_message_content(
UserId(), copied_message->send_emoji);
}
TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_));
bool is_premium = G()->shared_config().get_option_boolean("is_premium");
TRY_RESULT(content, get_input_message_content(dialog_id, std::move(input_message_content), td_, is_premium));
if (content.ttl < 0 || content.ttl > MAX_PRIVATE_MESSAGE_TTL) {
return Status::Error(400, "Invalid message content TTL specified");

View File

@ -53,6 +53,7 @@ enum class Version : int32 {
UseServerForwardAsCopy,
AddMainDialogListPosition,
AddVoiceNoteFlags,
AddMessageStickerFlags, // 40
Next
};