Support telegram_api::updateMessageExtendedMedia.

This commit is contained in:
levlam 2022-09-23 12:07:07 +03:00
parent 7a50d0764e
commit 7f353cd064
10 changed files with 81 additions and 7 deletions

View File

@ -394,6 +394,12 @@ FileId get_input_invoice_thumbnail_file_id(const Td *td, const InputInvoice &inp
return input_invoice.extended_media.get_thumbnail_file_id(td);
}
bool update_input_invoice_extended_media(InputInvoice &input_invoice,
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
DialogId owner_dialog_id, Td *td) {
return input_invoice.extended_media.update_to(td, std::move(extended_media), owner_dialog_id);
}
tl_object_ptr<td_api::formattedText> get_product_description_object(const string &description) {
FormattedText result;
result.text = description;

View File

@ -99,6 +99,10 @@ FileId get_input_invoice_any_file_id(const InputInvoice &input_invoice);
FileId get_input_invoice_thumbnail_file_id(const Td *td, const InputInvoice &input_invoice);
bool update_input_invoice_extended_media(InputInvoice &input_invoice,
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
DialogId owner_dialog_id, Td *td);
tl_object_ptr<td_api::formattedText> get_product_description_object(const string &description);
} // namespace td

View File

@ -5690,6 +5690,15 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte
}
}
bool update_message_content_extended_media(MessageContent *content,
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
DialogId owner_dialog_id, Td *td) {
CHECK(content != nullptr);
CHECK(content->get_type() == MessageContentType::Invoice);
return update_input_invoice_extended_media(static_cast<MessageInvoice *>(content)->input_invoice,
std::move(extended_media), owner_dialog_id, td);
}
void get_message_content_animated_emoji_click_sticker(const MessageContent *content, FullMessageId full_message_id,
Td *td, Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
if (content->get_type() != MessageContentType::Text) {

View File

@ -228,6 +228,10 @@ vector<FileId> get_message_content_file_ids(const MessageContent *content, const
string get_message_content_search_text(const Td *td, const MessageContent *content);
bool update_message_content_extended_media(MessageContent *content,
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
DialogId owner_dialog_id, Td *td);
void get_message_content_animated_emoji_click_sticker(const MessageContent *content, FullMessageId full_message_id,
Td *td, Promise<td_api::object_ptr<td_api::sticker>> &&promise);

View File

@ -98,6 +98,20 @@ void MessageExtendedMedia::update_from(const MessageExtendedMedia &old_extended_
}
}
bool MessageExtendedMedia::update_to(Td *td,
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media_ptr,
DialogId owner_dialog_id) {
MessageExtendedMedia new_extended_media(td, std::move(extended_media_ptr), FormattedText(caption_), owner_dialog_id);
if (!new_extended_media.is_media() && is_media()) {
return false;
}
if (*this != new_extended_media || get_unsupported_version() != new_extended_media.get_unsupported_version()) {
*this = std::move(new_extended_media);
return true;
}
return false;
}
td_api::object_ptr<td_api::MessageExtendedMedia> MessageExtendedMedia::get_message_extended_media_object(
Td *td, bool skip_bot_commands, int32 max_media_timestamp) const {
if (type_ == Type::Empty) {

View File

@ -56,6 +56,9 @@ class MessageExtendedMedia {
void update_from(const MessageExtendedMedia &old_extended_media);
bool update_to(Td *td, telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media_ptr,
DialogId owner_dialog_id);
td_api::object_ptr<td_api::MessageExtendedMedia> get_message_extended_media_object(Td *td, bool skip_bot_commands,
int32 max_media_timestamp) const;

View File

@ -7133,6 +7133,36 @@ void MessagesManager::on_update_some_live_location_viewed(Promise<Unit> &&promis
promise.set_value(Unit());
}
void MessagesManager::on_update_message_extended_media(
FullMessageId full_message_id, telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media) {
auto dialog_id = full_message_id.get_dialog_id();
Dialog *d = get_dialog_force(dialog_id, "on_update_message_extended_media");
if (d == nullptr) {
LOG(INFO) << "Ignore update of message extended media in unknown " << dialog_id;
return;
}
auto m = get_message_force(d, full_message_id.get_message_id(), "on_update_message_extended_media");
if (m == nullptr) {
LOG(INFO) << "Ignore update of message extended media in unknown " << full_message_id;
return;
}
auto content = m->content.get();
auto content_type = content->get_type();
if (content_type != MessageContentType::Invoice) {
if (content_type != MessageContentType::Unsupported) {
LOG(ERROR) << "Receive updateMessageExtendedMedia for " << full_message_id << " of type " << content_type;
}
return;
}
if (update_message_content_extended_media(content, std::move(extended_media), dialog_id, td_)) {
send_update_message_content(d, m, true, "on_update_message_extended_media");
on_message_changed(d, m, true, "on_update_message_extended_media");
on_message_notification_changed(d, m, "on_update_message_extended_media"); // usually a no-op
}
}
bool MessagesManager::need_skip_bot_commands(DialogId dialog_id, const Message *m) const {
if (td_->auth_manager_->is_bot()) {
return false;

View File

@ -364,6 +364,9 @@ class MessagesManager final : public Actor {
void on_update_some_live_location_viewed(Promise<Unit> &&promise);
void on_update_message_extended_media(FullMessageId full_message_id,
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media);
void on_external_update_message_content(FullMessageId full_message_id);
void on_update_message_content(FullMessageId full_message_id);

View File

@ -3521,6 +3521,13 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateGeoLiveViewed>
promise.set_value(Unit());
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageExtendedMedia> update,
Promise<Unit> &&promise) {
td_->messages_manager_->on_update_message_extended_media(
{DialogId(update->peer_), MessageId(ServerMessageId(update->msg_id_))}, std::move(update->extended_media_));
promise.set_value(Unit());
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessagePoll> update, Promise<Unit> &&promise) {
td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_),
"updateMessagePoll");
@ -3596,9 +3603,4 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateTranscribedAudi
// unsupported updates
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessageExtendedMedia> update,
Promise<Unit> &&promise) {
promise.set_value(Unit());
}
} // namespace td

View File

@ -517,6 +517,7 @@ class UpdatesManager final : public Actor {
void on_update(tl_object_ptr<telegram_api::updateLangPack> update, Promise<Unit> &&promise);
void on_update(tl_object_ptr<telegram_api::updateGeoLiveViewed> update, Promise<Unit> &&promise);
void on_update(tl_object_ptr<telegram_api::updateMessageExtendedMedia> update, Promise<Unit> &&promise);
void on_update(tl_object_ptr<telegram_api::updateMessagePoll> update, Promise<Unit> &&promise);
void on_update(tl_object_ptr<telegram_api::updateMessagePollVote> update, Promise<Unit> &&promise);
@ -540,8 +541,6 @@ class UpdatesManager final : public Actor {
void on_update(tl_object_ptr<telegram_api::updateTranscribedAudio> update, Promise<Unit> &&promise);
// unsupported updates
void on_update(tl_object_ptr<telegram_api::updateMessageExtendedMedia> update, Promise<Unit> &&promise);
};
} // namespace td