Add starTransactionPartnerChannel.media.

This commit is contained in:
levlam 2024-06-21 15:47:12 +03:00
parent 0115a73d6e
commit 9cb1df3586
4 changed files with 68 additions and 46 deletions

View File

@ -873,7 +873,8 @@ starTransactionPartnerBot bot_user_id:int53 product_info:productInfo invoice_pay
//@description The transaction is a transaction with a channel chat
//@chat_id Identifier of the chat
//@paid_media_message_id Identifier of the corresponding message with paid media; can be an identifier of a deleted message
starTransactionPartnerChannel chat_id:int53 paid_media_message_id:int53 = StarTransactionPartner;
//@media Information about the bought media
starTransactionPartnerChannel chat_id:int53 paid_media_message_id:int53 media:vector<MessageExtendedMedia> = StarTransactionPartner;
//@description The transaction is a transaction with unknown partner
starTransactionPartnerUnsupported = StarTransactionPartner;

View File

@ -46,10 +46,25 @@ MessageExtendedMedia::MessageExtendedMedia(
}
case telegram_api::messageExtendedMedia::ID: {
auto media = move_tl_object_as<telegram_api::messageExtendedMedia>(extended_media);
init_from_media(td, std::move(media->media_), owner_dialog_id);
break;
}
default:
UNREACHABLE();
}
}
MessageExtendedMedia::MessageExtendedMedia(Td *td, telegram_api::object_ptr<telegram_api::MessageMedia> &&media,
DialogId owner_dialog_id) {
init_from_media(td, std::move(media), owner_dialog_id);
}
void MessageExtendedMedia::init_from_media(Td *td, telegram_api::object_ptr<telegram_api::MessageMedia> &&media,
DialogId owner_dialog_id) {
type_ = Type::Unsupported;
switch (media->media_->get_id()) {
switch (media->get_id()) {
case telegram_api::messageMediaPhoto::ID: {
auto photo = move_tl_object_as<telegram_api::messageMediaPhoto>(media->media_);
auto photo = move_tl_object_as<telegram_api::messageMediaPhoto>(media);
if (photo->photo_ == nullptr) {
break;
}
@ -62,7 +77,7 @@ MessageExtendedMedia::MessageExtendedMedia(
break;
}
case telegram_api::messageMediaDocument::ID: {
auto document = move_tl_object_as<telegram_api::messageMediaDocument>(media->media_);
auto document = move_tl_object_as<telegram_api::messageMediaDocument>(media);
if (document->document_ == nullptr) {
break;
}
@ -90,11 +105,6 @@ MessageExtendedMedia::MessageExtendedMedia(
if (type_ == Type::Unsupported) {
unsupported_version_ = CURRENT_VERSION;
}
break;
}
default:
UNREACHABLE();
}
}
Result<MessageExtendedMedia> MessageExtendedMedia::get_message_extended_media(

View File

@ -44,6 +44,8 @@ class MessageExtendedMedia {
friend bool operator==(const MessageExtendedMedia &lhs, const MessageExtendedMedia &rhs);
void init_from_media(Td *td, telegram_api::object_ptr<telegram_api::MessageMedia> &&media, DialogId owner_dialog_id);
bool is_media() const {
return type_ != Type::Empty && type_ != Type::Preview;
}
@ -54,6 +56,8 @@ class MessageExtendedMedia {
MessageExtendedMedia(Td *td, telegram_api::object_ptr<telegram_api::MessageExtendedMedia> &&extended_media,
FormattedText &&caption, DialogId owner_dialog_id);
MessageExtendedMedia(Td *td, telegram_api::object_ptr<telegram_api::MessageMedia> &&media, DialogId owner_dialog_id);
static Result<MessageExtendedMedia> get_message_extended_media(
Td *td, td_api::object_ptr<td_api::InputMessageContent> &&extended_media_content, DialogId owner_dialog_id,
bool is_premium);

View File

@ -13,6 +13,7 @@
#include "td/telegram/DialogManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/InputInvoice.h"
#include "td/telegram/MessageExtendedMedia.h"
#include "td/telegram/MessageSender.h"
#include "td/telegram/PasswordManager.h"
#include "td/telegram/Photo.h"
@ -22,6 +23,7 @@
#include "td/telegram/UpdatesManager.h"
#include "td/telegram/UserManager.h"
#include "td/utils/algorithm.h"
#include "td/utils/buffer.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
@ -183,15 +185,20 @@ class GetStarsTransactionsQuery final : public Td::ResultHandler {
if (td_->dialog_manager_->is_broadcast_channel(dialog_id)) {
SCOPE_EXIT {
transaction->msg_id_ = 0;
transaction->extended_media_.clear();
};
auto message_id = MessageId(ServerMessageId(transaction->msg_id_));
if (message_id != MessageId() && !message_id.is_valid()) {
LOG(ERROR) << "Receive " << message_id << " in " << to_string(transaction);
message_id = MessageId();
}
auto extended_media =
transform(std::move(transaction->extended_media_), [td = td_, dialog_id](auto &&media) {
return MessageExtendedMedia(td, std::move(media), dialog_id).get_message_extended_media_object(td);
});
return td_api::make_object<td_api::starTransactionPartnerChannel>(
td_->dialog_manager_->get_chat_id_object(dialog_id, "starTransactionPartnerChannel"),
message_id.get());
message_id.get(), std::move(extended_media));
}
LOG(ERROR) << "Receive star transaction with " << dialog_id;
return td_api::make_object<td_api::starTransactionPartnerUnsupported>();