Add messageReplyToMessage.content.

This commit is contained in:
levlam 2023-10-26 22:53:25 +03:00
parent e113fb47f1
commit e50a3ce18c
7 changed files with 113 additions and 17 deletions

View File

@ -1233,7 +1233,10 @@ messageSendingStateFailed error:error can_retry:Bool need_another_sender:Bool re
//@is_quote_manual True, if the quote was manually chosen by the message sender
//@origin Information about origin of the message if the message was replied from another chat; may be null for messages from the same chat
//@origin_send_date Point in time (Unix timestamp) when the message was sent if the message was replied from another chat; 0 for messages from the same chat
messageReplyToMessage chat_id:int53 message_id:int53 quote:formattedText is_quote_manual:Bool origin:MessageOrigin origin_send_date:int32 = MessageReplyTo;
//@content Media content of the message if the message was replied from another chat; may be null for messages from the same chat and non-media messages.
//-Can be only one of the following types: messageAnimation, messageAudio, messageContact, messageDice, messageDocument, messageGame, messageGiveaway, messageInvoice,
//-messageLocation, messagePhoto, messagePoll, messageSticker, messageStory, messageVenue, messageVideo, messageVideoNote, or messageVoiceNote
messageReplyToMessage chat_id:int53 message_id:int53 quote:formattedText is_quote_manual:Bool origin:MessageOrigin origin_send_date:int32 content:MessageContent = MessageReplyTo;
//@description Describes a story replied by a given message @story_sender_chat_id The identifier of the sender of the story @story_id The identifier of the story
messageReplyToStory story_sender_chat_id:int53 story_id:int32 = MessageReplyTo;

View File

@ -66,6 +66,7 @@
#include "td/telegram/PollId.h"
#include "td/telegram/PollId.hpp"
#include "td/telegram/PollManager.h"
#include "td/telegram/RepliedMessageInfo.h"
#include "td/telegram/secret_api.hpp"
#include "td/telegram/SecureValue.h"
#include "td/telegram/SecureValue.hpp"
@ -4256,8 +4257,14 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
void compare_message_contents(Td *td, const MessageContent *old_content, const MessageContent *new_content,
bool &is_content_changed, bool &need_update) {
if (old_content == nullptr) {
if (new_content != nullptr) {
need_update = true;
}
return;
}
MessageContentType content_type = old_content->get_type();
if (new_content->get_type() != content_type) {
if (new_content == nullptr || new_content->get_type() != content_type) {
need_update = true;
return;
}
@ -4273,8 +4280,10 @@ void compare_message_contents(Td *td, const MessageContent *old_content, const M
lhs->force_large_media != rhs->force_large_media ||
lhs->skip_web_page_confirmation != rhs->skip_web_page_confirmation) {
is_content_changed = true;
need_update |= td->web_pages_manager_->have_web_page(lhs->web_page_id) ||
td->web_pages_manager_->have_web_page(rhs->web_page_id);
if (td == nullptr || td->web_pages_manager_->have_web_page(lhs->web_page_id) ||
td->web_pages_manager_->have_web_page(rhs->web_page_id)) {
need_update = true;
}
}
break;
}
@ -7116,6 +7125,7 @@ void update_failed_to_send_message_content(Td *td, unique_ptr<MessageContent> &c
}
void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content, bool is_bot) {
CHECK(message_content != nullptr);
switch (message_content->get_type()) {
case MessageContentType::Text: {
const auto *content = static_cast<const MessageText *>(message_content);

View File

@ -18,7 +18,6 @@
#include "td/telegram/MessageFullId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/Photo.h"
#include "td/telegram/RepliedMessageInfo.h"
#include "td/telegram/ReplyMarkup.h"
#include "td/telegram/secret_api.h"
#include "td/telegram/SecretInputMedia.h"
@ -44,6 +43,7 @@ class DialogAction;
class Game;
class MultiPromiseActor;
struct Photo;
class RepliedMessageInfo;
class Td;
class Venue;

View File

@ -24690,9 +24690,10 @@ bool MessagesManager::is_message_auto_read(DialogId dialog_id, bool is_outgoing)
}
void MessagesManager::add_message_dependencies(Dependencies &dependencies, const Message *m) {
auto is_bot = td_->auth_manager_->is_bot();
dependencies.add(m->sender_user_id);
dependencies.add_dialog_and_dependencies(m->sender_dialog_id);
m->replied_message_info.add_dependencies(dependencies);
m->replied_message_info.add_dependencies(dependencies, is_bot);
dependencies.add_dialog_and_dependencies(m->reply_to_story_full_id.get_dialog_id());
dependencies.add_dialog_and_dependencies(m->real_forward_from_dialog_id);
dependencies.add(m->via_bot_user_id);
@ -24711,7 +24712,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, const
m->reactions->add_min_channels(td_);
m->reactions->add_dependencies(dependencies);
}
add_message_content_dependencies(dependencies, m->content.get(), td_->auth_manager_->is_bot());
add_message_content_dependencies(dependencies, m->content.get(), is_bot);
add_reply_markup_dependencies(dependencies, m->reply_markup.get());
add_draft_message_dependencies(dependencies, m->thread_draft_message);
}

View File

@ -8,6 +8,7 @@
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageFullId.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/misc.h"
@ -37,6 +38,8 @@ static bool has_qts_messages(const Td *td, DialogId dialog_id) {
}
}
RepliedMessageInfo::~RepliedMessageInfo() = default;
RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messageReplyHeader> &&reply_header,
DialogId dialog_id, MessageId message_id, int32 date) {
CHECK(reply_header != nullptr);
@ -101,6 +104,40 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messa
}
}
}
if (reply_header->reply_media_ != nullptr &&
reply_header->reply_media_->get_id() != telegram_api::messageMediaEmpty::ID) {
content_ = get_message_content(td, FormattedText(), std::move(reply_header->reply_media_), dialog_id, true,
UserId(), nullptr, nullptr, "messageReplyHeader");
CHECK(content_ != nullptr);
switch (content_->get_type()) {
case MessageContentType::Animation:
case MessageContentType::Audio:
case MessageContentType::Contact:
case MessageContentType::Dice:
case MessageContentType::Document:
// case MessageContentType::ExpiredPhoto:
// case MessageContentType::ExpiredVideo:
case MessageContentType::Game:
case MessageContentType::Giveaway:
case MessageContentType::Invoice:
// case MessageContentType::LiveLocation:
case MessageContentType::Location:
case MessageContentType::Photo:
case MessageContentType::Poll:
case MessageContentType::Sticker:
case MessageContentType::Story:
// case MessageContentType::Text:
case MessageContentType::Unsupported:
case MessageContentType::Venue:
case MessageContentType::Video:
case MessageContentType::VideoNote:
case MessageContentType::VoiceNote:
break;
default:
LOG(ERROR) << "Receive reply with media of the type " << content_->get_type();
content_ = nullptr;
}
}
}
if (!reply_header->quote_text_.empty()) {
is_quote_manual_ = reply_header->quote_;
@ -177,10 +214,13 @@ bool RepliedMessageInfo::need_reply_changed_warning(
return true;
}
void RepliedMessageInfo::add_dependencies(Dependencies &dependencies) const {
void RepliedMessageInfo::add_dependencies(Dependencies &dependencies, bool is_bot) const {
dependencies.add_dialog_and_dependencies(dialog_id_);
origin_.add_dependencies(dependencies);
add_formatted_text_dependencies(dependencies, &quote_);
if (content_ != nullptr) {
add_message_content_dependencies(dependencies, content_.get(), is_bot);
}
}
td_api::object_ptr<td_api::messageReplyToMessage> RepliedMessageInfo::get_message_reply_to_message_object(
@ -204,8 +244,17 @@ td_api::object_ptr<td_api::messageReplyToMessage> RepliedMessageInfo::get_messag
CHECK(origin->get_id() != td_api::messageOriginChannel::ID);
}
td_api::object_ptr<td_api::MessageContent> content;
if (content_ != nullptr) {
content = get_message_content_object(content_.get(), td, dialog_id, 0, false, true, -1, false);
if (content->get_id() == td_api::messageUnsupported::ID) {
content = nullptr;
}
}
return td_api::make_object<td_api::messageReplyToMessage>(chat_id, message_id_.get(), std::move(quote),
is_quote_manual_, std::move(origin), origin_date_);
is_quote_manual_, std::move(origin), origin_date_,
std::move(content));
}
MessageId RepliedMessageInfo::get_same_chat_reply_to_message_id() const {
@ -220,9 +269,18 @@ MessageFullId RepliedMessageInfo::get_reply_message_full_id(DialogId owner_dialo
}
bool operator==(const RepliedMessageInfo &lhs, const RepliedMessageInfo &rhs) {
return lhs.message_id_ == rhs.message_id_ && lhs.dialog_id_ == rhs.dialog_id_ &&
lhs.origin_date_ == rhs.origin_date_ && lhs.origin_ == rhs.origin_ && lhs.quote_ == rhs.quote_ &&
lhs.is_quote_manual_ == rhs.is_quote_manual_;
if (!(lhs.message_id_ == rhs.message_id_ && lhs.dialog_id_ == rhs.dialog_id_ &&
lhs.origin_date_ == rhs.origin_date_ && lhs.origin_ == rhs.origin_ && lhs.quote_ == rhs.quote_ &&
lhs.is_quote_manual_ == rhs.is_quote_manual_)) {
return false;
}
bool need_update = false;
bool is_content_changed = false;
compare_message_contents(nullptr, lhs.content_.get(), rhs.content_.get(), is_content_changed, need_update);
if (need_update || is_content_changed) {
return false;
}
return true;
}
bool operator!=(const RepliedMessageInfo &lhs, const RepliedMessageInfo &rhs) {
@ -241,6 +299,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const RepliedMessageInf
string_builder << " with " << info.quote_.text.size() << (info.is_quote_manual_ ? " manually" : "")
<< " quoted bytes";
}
if (info.content_ != nullptr) {
string_builder << " and content of the type " << info.content_->get_type();
}
return string_builder;
}

View File

@ -7,6 +7,7 @@
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageInputReplyTo.h"
@ -26,9 +27,10 @@ class Td;
class RepliedMessageInfo {
MessageId message_id_;
DialogId dialog_id_; // DialogId() if reply is to a message in the same chat
int32 origin_date_ = 0; // for replies in other chats
MessageOrigin origin_; // for replies in other chats
DialogId dialog_id_; // DialogId() if reply is to a message in the same chat
int32 origin_date_ = 0; // for replies in other chats
MessageOrigin origin_; // for replies in other chats
unique_ptr<MessageContent> content_; // for replies in other chats
FormattedText quote_;
bool is_quote_manual_ = false;
@ -38,6 +40,11 @@ class RepliedMessageInfo {
public:
RepliedMessageInfo() = default;
RepliedMessageInfo(const RepliedMessageInfo &) = delete;
RepliedMessageInfo &operator=(const RepliedMessageInfo &) = delete;
RepliedMessageInfo(RepliedMessageInfo &&) = default;
RepliedMessageInfo &operator=(RepliedMessageInfo &&) = default;
~RepliedMessageInfo();
explicit RepliedMessageInfo(MessageId reply_to_message_id) : message_id_(reply_to_message_id) {
}
@ -57,14 +64,14 @@ class RepliedMessageInfo {
bool is_empty() const {
return message_id_ == MessageId() && dialog_id_ == DialogId() && origin_date_ == 0 && origin_.is_empty() &&
quote_.text.empty();
quote_.text.empty() && content_ == nullptr;
}
static bool need_reply_changed_warning(
const RepliedMessageInfo &old_info, const RepliedMessageInfo &new_info, MessageId old_top_thread_message_id,
bool is_yet_unsent, std::function<bool(const RepliedMessageInfo &info)> is_reply_to_deleted_message);
void add_dependencies(Dependencies &dependencies) const;
void add_dependencies(Dependencies &dependencies, bool is_bot) const;
td_api::object_ptr<td_api::messageReplyToMessage> get_message_reply_to_message_object(Td *td,
DialogId dialog_id) const;

View File

@ -8,6 +8,7 @@
#include "td/telegram/RepliedMessageInfo.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageEntity.hpp"
#include "td/telegram/MessageOrigin.hpp"
@ -22,6 +23,7 @@ void RepliedMessageInfo::store(StorerT &storer) const {
bool has_origin_date = origin_date_ != 0;
bool has_origin = !origin_.is_empty();
bool has_quote = !quote_.text.empty();
bool has_content = content_ != nullptr;
BEGIN_STORE_FLAGS();
STORE_FLAG(has_message_id);
STORE_FLAG(has_dialog_id);
@ -29,6 +31,7 @@ void RepliedMessageInfo::store(StorerT &storer) const {
STORE_FLAG(has_origin);
STORE_FLAG(has_quote);
STORE_FLAG(is_quote_manual_);
STORE_FLAG(has_content);
END_STORE_FLAGS();
if (has_message_id) {
td::store(message_id_, storer);
@ -42,6 +45,12 @@ void RepliedMessageInfo::store(StorerT &storer) const {
if (has_origin) {
td::store(origin_, storer);
}
if (has_quote) {
td::store(quote_, storer);
}
if (has_content) {
store_message_content(content_.get(), storer);
}
}
template <class ParserT>
@ -51,6 +60,7 @@ void RepliedMessageInfo::parse(ParserT &parser) {
bool has_origin_date;
bool has_origin;
bool has_quote;
bool has_content;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_message_id);
PARSE_FLAG(has_dialog_id);
@ -58,6 +68,7 @@ void RepliedMessageInfo::parse(ParserT &parser) {
PARSE_FLAG(has_origin);
PARSE_FLAG(has_quote);
PARSE_FLAG(is_quote_manual_);
PARSE_FLAG(has_content);
END_PARSE_FLAGS();
if (has_message_id) {
td::parse(message_id_, parser);
@ -74,6 +85,9 @@ void RepliedMessageInfo::parse(ParserT &parser) {
if (has_quote) {
td::parse(quote_, parser);
}
if (has_content) {
parse_message_content(content_, parser);
}
}
} // namespace td