Add class td_api::messageSponsor.

This commit is contained in:
levlam 2023-06-02 14:42:28 +03:00
parent 6e011cb212
commit 2969f570b8
4 changed files with 60 additions and 17 deletions

View File

@ -1223,17 +1223,31 @@ messageSourceScreenshot = MessageSource;
messageSourceOther = MessageSource;
//@class MessageSponsorType @description Describes type of a message sponsor
//@description The sponsor is a bot @bot_user_id User identifier of the bot @link An internal link to be opened when the sponsored message is clicked
messageSponsorTypeBot bot_user_id:int53 link:InternalLinkType = MessageSponsorType;
//@description The sponsor is a public channel chat @chat_id Sponsor chat identifier @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
messageSponsorTypePublicChannel chat_id:int53 link:InternalLinkType = MessageSponsorType;
//@description The sponsor is a private channel chat @title Title of the chat @invite_link Invite link for the channel
messageSponsorTypePrivateChannel title:string invite_link:string = MessageSponsorType;
//@description Information about the sponsor of a message
//@type Type of the sponsor
//@photo Photo of the sponsor; may be null if must not be shown
//@info Additional optional information about the sponsor to be shown along with the message
messageSponsor type:MessageSponsorType photo:chatPhotoInfo info:string = MessageSponsor;
//@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
//@is_recommended True, if the message needs to be labeled as "recommended" instead of "sponsored"
//@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
//@show_chat_photo True, if the sponsor's chat photo must be shown
//@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
//@sponsor_info If non-empty, information about the sponsor to be shown along with the message
//@sponsor Information about the sponsor of the message
//@additional_info If non-empty, additional information about the sponsored message to be shown along with the message
sponsoredMessage message_id:int53 is_recommended:Bool sponsor_chat_id:int53 sponsor_chat_info:chatInviteLinkInfo show_chat_photo:Bool link:InternalLinkType content:MessageContent sponsor_info:string additional_info:string = SponsoredMessage;
sponsoredMessage message_id:int53 is_recommended:Bool content:MessageContent sponsor:messageSponsor additional_info:string = SponsoredMessage;
//@description Contains a list of sponsored messages @messages List of sponsored messages @messages_between The minimum number of messages between shown sponsored messages, or 0 if only one sponsored message must be shown after all ordinary messages
sponsoredMessages messages:vector<sponsoredMessage> messages_between:int32 = SponsoredMessages;

View File

@ -84,6 +84,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const ProfilePhoto &pro
DialogPhoto get_dialog_photo(FileManager *file_manager, DialogId dialog_id, int64 dialog_access_hash,
tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr);
tl_object_ptr<td_api::chatPhotoInfo> get_chat_photo_info_object(FileManager *file_manager,
const DialogPhoto *dialog_photo);

View File

@ -15,6 +15,7 @@
#include "td/telegram/MessagesManager.h"
#include "td/telegram/net/NetQueryCreator.h"
#include "td/telegram/OptionManager.h"
#include "td/telegram/Photo.h"
#include "td/telegram/ServerMessageId.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
@ -195,10 +196,10 @@ 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::chatInviteLinkInfo> chat_invite_link_info;
td_api::object_ptr<td_api::InternalLinkType> link;
td_api::object_ptr<td_api::messageSponsor> SponsoredMessageManager::get_message_sponsor_object(
const SponsoredMessage &sponsored_message) const {
td_api::object_ptr<td_api::MessageSponsorType> type;
td_api::object_ptr<td_api::chatPhotoInfo> photo;
switch (sponsored_message.sponsor_dialog_id.get_type()) {
case DialogType::User: {
auto user_id = sponsored_message.sponsor_dialog_id.get_user_id();
@ -211,7 +212,13 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
LOG(ERROR) << "Sponsor " << user_id << " has no username";
return nullptr;
}
link = td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username, sponsored_message.start_param, false);
type = td_api::make_object<td_api::messageSponsorTypeBot>(
td_->contacts_manager_->get_user_id_object(user_id, "messageSponsorTypeBot"),
td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username, sponsored_message.start_param, false));
if (sponsored_message.show_dialog_photo) {
photo = get_chat_photo_info_object(td_->file_manager_.get(),
td_->contacts_manager_->get_user_dialog_photo(user_id));
}
break;
}
case DialogType::Channel: {
@ -220,17 +227,25 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
LOG(ERROR) << "Sponsor " << channel_id << " is not a channel";
return nullptr;
}
td_api::object_ptr<td_api::InternalLinkType> link;
if (sponsored_message.server_message_id.is_valid()) {
link = td_api::make_object<td_api::internalLinkTypeMessage>(
PSTRING() << LinkManager::get_t_me_url() << "c/" << channel_id.get() << '/'
<< sponsored_message.server_message_id.get());
}
type = td_api::make_object<td_api::messageSponsorTypePublicChannel>(
td_->messages_manager_->get_chat_id_object(sponsored_message.sponsor_dialog_id, "sponsoredMessage"),
std::move(link));
if (sponsored_message.show_dialog_photo) {
photo = get_chat_photo_info_object(td_->file_manager_.get(),
td_->contacts_manager_->get_channel_dialog_photo(channel_id));
}
break;
}
case DialogType::None: {
CHECK(!sponsored_message.invite_hash.empty());
auto invite_link = LinkManager::get_dialog_invite_link(sponsored_message.invite_hash, false);
chat_invite_link_info = td_->contacts_manager_->get_chat_invite_link_info_object(invite_link);
auto chat_invite_link_info = td_->contacts_manager_->get_chat_invite_link_info_object(invite_link);
if (chat_invite_link_info == nullptr) {
LOG(ERROR) << "Failed to get invite link info for " << invite_link;
return nullptr;
@ -240,18 +255,28 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
LOG(ERROR) << "Receive sponsor chat of a wrong type " << to_string(chat_invite_link_info->type_);
return nullptr;
}
link = td_api::make_object<td_api::internalLinkTypeChatInvite>(
LinkManager::get_dialog_invite_link(sponsored_message.invite_hash, true));
type = td_api::make_object<td_api::messageSponsorTypePrivateChannel>(chat_invite_link_info->title_, invite_link);
if (sponsored_message.show_dialog_photo) {
photo = std::move(chat_invite_link_info->photo_);
}
break;
}
default:
break;
}
return td_api::make_object<td_api::messageSponsor>(std::move(type), std::move(photo), sponsored_message.sponsor_info);
}
td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponsored_message_object(
DialogId dialog_id, const SponsoredMessage &sponsored_message) const {
auto sponsor = get_message_sponsor_object(sponsored_message);
if (sponsor == nullptr) {
return nullptr;
}
return td_api::make_object<td_api::sponsoredMessage>(
sponsored_message.local_id, sponsored_message.is_recommended,
td_->messages_manager_->get_chat_id_object(sponsored_message.sponsor_dialog_id, "sponsoredMessage"),
std::move(chat_invite_link_info), sponsored_message.show_dialog_photo, std::move(link),
get_message_content_object(sponsored_message.content.get(), td_, dialog_id, 0, false, true, -1),
sponsored_message.sponsor_info, sponsored_message.additional_info);
std::move(sponsor), sponsored_message.additional_info);
}
td_api::object_ptr<td_api::sponsoredMessages> SponsoredMessageManager::get_sponsored_messages_object(

View File

@ -51,6 +51,9 @@ class SponsoredMessageManager final : public Actor {
void delete_cached_sponsored_messages(DialogId dialog_id);
td_api::object_ptr<td_api::messageSponsor> get_message_sponsor_object(
const SponsoredMessage &sponsored_message) const;
td_api::object_ptr<td_api::sponsoredMessage> get_sponsored_message_object(
DialogId dialog_id, const SponsoredMessage &sponsored_message) const;