Support recommended sponsored messages.

This commit is contained in:
levlam 2022-05-07 12:12:16 +03:00
parent 412404a721
commit 0da61037d3
2 changed files with 10 additions and 6 deletions

View File

@ -889,11 +889,12 @@ messageCalendar total_count:int32 days:vector<messageCalendarDay> = MessageCalen
//@description Describes a sponsored message //@description Describes a sponsored message
//@message_id Message identifier; unique for the chat to which the sponsored message belongs among both ordinary and sponsored messages //@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 is recommended
//@sponsor_chat_id Sponsor chat identifier; 0 if the sponsor chat is accessible through an invite link //@sponsor_chat_id Sponsor chat identifier; 0 if the sponsor chat is accessible through an invite link
//@sponsor_chat_info Information about the sponsor chat; may be null unless sponsor_chat_id == 0 //@sponsor_chat_info Information about the sponsor chat; may be null unless sponsor_chat_id == 0
//@link An internal link to be opened when the sponsored message is clicked; may be null if the sponsor chat needs to be opened instead //@link An internal link to be opened when the sponsored message is clicked; may be null if the sponsor chat needs to be opened instead
//@content Content of the message. Currently, can be only of the type messageText //@content Content of the message. Currently, can be only of the type messageText
sponsoredMessage message_id:int53 sponsor_chat_id:int53 sponsor_chat_info:chatInviteLinkInfo link:InternalLinkType content:MessageContent = SponsoredMessage; sponsoredMessage message_id:int53 is_recommended:Bool sponsor_chat_id:int53 sponsor_chat_info:chatInviteLinkInfo link:InternalLinkType content:MessageContent = SponsoredMessage;
//@description Describes a file added to file download list //@description Describes a file added to file download list

View File

@ -90,6 +90,7 @@ class ViewSponsoredMessageQuery final : public Td::ResultHandler {
struct SponsoredMessageManager::SponsoredMessage { struct SponsoredMessageManager::SponsoredMessage {
int64 local_id = 0; int64 local_id = 0;
bool is_recommended = false;
DialogId sponsor_dialog_id; DialogId sponsor_dialog_id;
ServerMessageId server_message_id; ServerMessageId server_message_id;
string start_param; string start_param;
@ -97,9 +98,10 @@ struct SponsoredMessageManager::SponsoredMessage {
unique_ptr<MessageContent> content; unique_ptr<MessageContent> content;
SponsoredMessage() = default; SponsoredMessage() = default;
SponsoredMessage(int64 local_id, DialogId sponsor_dialog_id, ServerMessageId server_message_id, string start_param, SponsoredMessage(int64 local_id, bool is_recommended, DialogId sponsor_dialog_id, ServerMessageId server_message_id,
string invite_hash, unique_ptr<MessageContent> content) string start_param, string invite_hash, unique_ptr<MessageContent> content)
: local_id(local_id) : local_id(local_id)
, is_recommended(is_recommended)
, sponsor_dialog_id(sponsor_dialog_id) , sponsor_dialog_id(sponsor_dialog_id)
, server_message_id(server_message_id) , server_message_id(server_message_id)
, start_param(std::move(start_param)) , start_param(std::move(start_param))
@ -187,8 +189,9 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
break; break;
} }
return td_api::make_object<td_api::sponsoredMessage>( return td_api::make_object<td_api::sponsoredMessage>(
sponsored_message.local_id, sponsored_message.sponsor_dialog_id.get(), std::move(chat_invite_link_info), sponsored_message.local_id, sponsored_message.is_recommended, sponsored_message.sponsor_dialog_id.get(),
std::move(link), get_message_content_object(sponsored_message.content.get(), td_, dialog_id, 0, false, true, -1)); std::move(chat_invite_link_info), std::move(link),
get_message_content_object(sponsored_message.content.get(), td_, dialog_id, 0, false, true, -1));
} }
td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponsored_message_object( td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponsored_message_object(
@ -312,7 +315,7 @@ void SponsoredMessageManager::on_get_dialog_sponsored_messages(
CHECK(!current_sponsored_message_id_.is_scheduled()); CHECK(!current_sponsored_message_id_.is_scheduled());
CHECK(messages->message_random_ids.count(local_id) == 0); CHECK(messages->message_random_ids.count(local_id) == 0);
messages->message_random_ids[local_id] = sponsored_message->random_id_.as_slice().str(); messages->message_random_ids[local_id] = sponsored_message->random_id_.as_slice().str();
messages->messages.emplace_back(local_id, sponsor_dialog_id, server_message_id, messages->messages.emplace_back(local_id, sponsored_message->recommended_, sponsor_dialog_id, server_message_id,
std::move(sponsored_message->start_param_), std::move(invite_hash), std::move(sponsored_message->start_param_), std::move(invite_hash),
std::move(content)); std::move(content));
} }