Add starTransactionPartnerChannel.media.
This commit is contained in:
parent
0115a73d6e
commit
9cb1df3586
@ -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;
|
||||
|
@ -46,50 +46,7 @@ MessageExtendedMedia::MessageExtendedMedia(
|
||||
}
|
||||
case telegram_api::messageExtendedMedia::ID: {
|
||||
auto media = move_tl_object_as<telegram_api::messageExtendedMedia>(extended_media);
|
||||
type_ = Type::Unsupported;
|
||||
switch (media->media_->get_id()) {
|
||||
case telegram_api::messageMediaPhoto::ID: {
|
||||
auto photo = move_tl_object_as<telegram_api::messageMediaPhoto>(media->media_);
|
||||
if (photo->photo_ == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
photo_ = get_photo(td, std::move(photo->photo_), owner_dialog_id);
|
||||
if (photo_.is_empty()) {
|
||||
break;
|
||||
}
|
||||
type_ = Type::Photo;
|
||||
break;
|
||||
}
|
||||
case telegram_api::messageMediaDocument::ID: {
|
||||
auto document = move_tl_object_as<telegram_api::messageMediaDocument>(media->media_);
|
||||
if (document->document_ == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto document_ptr = std::move(document->document_);
|
||||
int32 document_id = document_ptr->get_id();
|
||||
if (document_id == telegram_api::documentEmpty::ID) {
|
||||
break;
|
||||
}
|
||||
CHECK(document_id == telegram_api::document::ID);
|
||||
|
||||
auto parsed_document = td->documents_manager_->on_get_document(
|
||||
move_tl_object_as<telegram_api::document>(document_ptr), owner_dialog_id);
|
||||
if (parsed_document.empty() || parsed_document.type != Document::Type::Video) {
|
||||
break;
|
||||
}
|
||||
CHECK(parsed_document.file_id.is_valid());
|
||||
video_file_id_ = parsed_document.file_id;
|
||||
type_ = Type::Video;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (type_ == Type::Unsupported) {
|
||||
unsupported_version_ = CURRENT_VERSION;
|
||||
}
|
||||
init_from_media(td, std::move(media->media_), owner_dialog_id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -97,6 +54,59 @@ MessageExtendedMedia::MessageExtendedMedia(
|
||||
}
|
||||
}
|
||||
|
||||
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->get_id()) {
|
||||
case telegram_api::messageMediaPhoto::ID: {
|
||||
auto photo = move_tl_object_as<telegram_api::messageMediaPhoto>(media);
|
||||
if (photo->photo_ == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
photo_ = get_photo(td, std::move(photo->photo_), owner_dialog_id);
|
||||
if (photo_.is_empty()) {
|
||||
break;
|
||||
}
|
||||
type_ = Type::Photo;
|
||||
break;
|
||||
}
|
||||
case telegram_api::messageMediaDocument::ID: {
|
||||
auto document = move_tl_object_as<telegram_api::messageMediaDocument>(media);
|
||||
if (document->document_ == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto document_ptr = std::move(document->document_);
|
||||
int32 document_id = document_ptr->get_id();
|
||||
if (document_id == telegram_api::documentEmpty::ID) {
|
||||
break;
|
||||
}
|
||||
CHECK(document_id == telegram_api::document::ID);
|
||||
|
||||
auto parsed_document = td->documents_manager_->on_get_document(
|
||||
move_tl_object_as<telegram_api::document>(document_ptr), owner_dialog_id);
|
||||
if (parsed_document.empty() || parsed_document.type != Document::Type::Video) {
|
||||
break;
|
||||
}
|
||||
CHECK(parsed_document.file_id.is_valid());
|
||||
video_file_id_ = parsed_document.file_id;
|
||||
type_ = Type::Video;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (type_ == Type::Unsupported) {
|
||||
unsupported_version_ = CURRENT_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
Result<MessageExtendedMedia> MessageExtendedMedia::get_message_extended_media(
|
||||
Td *td, td_api::object_ptr<td_api::InputMessageContent> &&extended_media_content, DialogId owner_dialog_id,
|
||||
bool is_premium) {
|
||||
|
@ -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);
|
||||
|
@ -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>();
|
||||
|
Loading…
Reference in New Issue
Block a user