Support animation, photo and video in sponsored messages.

This commit is contained in:
levlam 2024-08-09 13:45:08 +03:00
parent 2aa1da2ee6
commit f6c181bea8
2 changed files with 20 additions and 4 deletions

View File

@ -1754,7 +1754,7 @@ messageSponsor url:string photo:photo info:string = MessageSponsor;
//@message_id Message identifier; unique for the chat to which the sponsored message belongs among both ordinary and sponsored messages
//@is_recommended True, if the message needs to be labeled as "recommended" instead of "sponsored"
//@can_be_reported True, if the message can be reported to Telegram moderators through reportChatSponsoredMessage
//@content Content of the message. Currently, can be only of the type messageText
//@content Content of the message. Currently, can be only of the types messageText, messageAnimation, messagePhoto, or messageVideo
//@sponsor Information about the sponsor of the message
//@title Title of the sponsored message
//@button_text Text for the message action button

View File

@ -281,7 +281,7 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
return td_api::make_object<td_api::sponsoredMessage>(
sponsored_message.local_id, sponsored_message.is_recommended, sponsored_message.can_be_reported,
get_message_content_object(sponsored_message.content.get(), td_, dialog_id, false, 0, false, true, -1, false,
false),
true),
std::move(sponsor), sponsored_message.title, sponsored_message.button_text,
td_->theme_manager_->get_accent_color_id_object(sponsored_message.peer_color.accent_color_id_, AccentColorId()),
sponsored_message.peer_color.background_custom_emoji_id_.get(), sponsored_message.additional_info);
@ -364,12 +364,28 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
std::move(sponsored_message->entities_), true, true, 0, false,
"on_get_dialog_sponsored_messages");
MessageSelfDestructType ttl;
auto content = get_message_content(td_, std::move(message_text), nullptr, DialogId(), G()->unix_time(), true,
UserId(), &ttl, nullptr, "on_get_dialog_sponsored_messages");
auto content =
get_message_content(td_, std::move(message_text), std::move(sponsored_message->media_), DialogId(),
G()->unix_time(), true, UserId(), &ttl, nullptr, "on_get_dialog_sponsored_messages");
if (!ttl.is_empty()) {
LOG(ERROR) << "Receive sponsored message with " << ttl;
continue;
}
bool is_allowed_content_type = [&] {
switch (content->get_type()) {
case MessageContentType::Animation:
case MessageContentType::Photo:
case MessageContentType::Text:
case MessageContentType::Video:
return true;
default:
return false;
}
}();
if (!is_allowed_content_type) {
LOG(ERROR) << "Receive sponsored message with " << content->get_type();
continue;
}
current_sponsored_message_id_ = current_sponsored_message_id_.get_next_message_id(MessageType::Local);
if (!current_sponsored_message_id_.is_valid_sponsored()) {