Improve sponsoredMessage.

This commit is contained in:
levlam 2021-10-08 15:00:13 +03:00
parent d0ac845c72
commit 564521453f
2 changed files with 20 additions and 3 deletions

View File

@ -789,8 +789,8 @@ foundMessages total_count:int32 messages:vector<message> next_offset:string = Fo
//@description Describes a sponsored message @id Unique sponsored message identifier @sponsor_chat_id Chat identifier
//@start_parameter Parameter for the bot start message if the sponsored chat is a chat with a bot @content Content of the message
sponsoredMessage id:int32 sponsor_chat_id:int53 start_parameter:string content:MessageContent = SponsoredMessage;
//@link An internal link to be opened when the sponsored message is clicked; may be null. If null, the sponsor chat needs to be opened instead @content Content of the message
sponsoredMessage id:int32 sponsor_chat_id:int53 link:InternalLinkType content:MessageContent = SponsoredMessage;
//@description Contains a list of sponsored messages @messages List of sponsored messages
sponsoredMessages messages:vector<sponsoredMessage> = SponsoredMessages;

View File

@ -148,8 +148,25 @@ void SponsoredMessageManager::delete_cached_sponsored_messages(DialogId dialog_i
td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponsored_message_object(
DialogId dialog_id, const SponsoredMessage &sponsored_message) const {
td_api::object_ptr<td_api::InternalLinkType> link;
switch (sponsored_message.sponsor_dialog_id.get_type()) {
case DialogType::User: {
auto user_id = sponsored_message.sponsor_dialog_id.get_user_id();
if (!td_->contacts_manager_->is_user_bot(user_id)) {
break;
}
auto bot_username = td_->contacts_manager_->get_user_username(user_id);
if (bot_username.empty()) {
break;
}
link = td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username, sponsored_message.start_param);
break;
}
default:
break;
}
return td_api::make_object<td_api::sponsoredMessage>(
sponsored_message.local_id, sponsored_message.sponsor_dialog_id.get(), sponsored_message.start_param,
sponsored_message.local_id, sponsored_message.sponsor_dialog_id.get(), std::move(link),
get_message_content_object(sponsored_message.content.get(), td_, dialog_id, 0, false, true, -1));
}