Parse new MessageReplyHeader.
This commit is contained in:
parent
4027e73309
commit
abca2962f2
@ -16,7 +16,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
MessageReplyHeader::MessageReplyHeader(tl_object_ptr<telegram_api::MessageReplyHeader> &&reply_header_ptr,
|
||||
MessageReplyHeader::MessageReplyHeader(Td *td, tl_object_ptr<telegram_api::MessageReplyHeader> &&reply_header_ptr,
|
||||
DialogId dialog_id, MessageId message_id, int32 date, bool can_have_thread) {
|
||||
if (reply_header_ptr == nullptr) {
|
||||
return;
|
||||
@ -49,30 +49,54 @@ MessageReplyHeader::MessageReplyHeader(tl_object_ptr<telegram_api::MessageReplyH
|
||||
LOG(ERROR) << "Receive reply to " << reply_to_message_id_ << " in " << MessageFullId{dialog_id, message_id};
|
||||
reply_to_message_id_ = MessageId();
|
||||
}
|
||||
} else if (reply_header->reply_to_msg_id_ > 0 && reply_header->reply_from_ == nullptr) {
|
||||
reply_to_message_id_ = MessageId(ServerMessageId(reply_header->reply_to_msg_id_));
|
||||
auto reply_to_peer_id = std::move(reply_header->reply_to_peer_id_);
|
||||
if (reply_to_peer_id != nullptr) {
|
||||
reply_in_dialog_id_ = DialogId(reply_to_peer_id);
|
||||
if (!reply_in_dialog_id_.is_valid()) {
|
||||
LOG(ERROR) << "Receive reply in invalid " << to_string(reply_to_peer_id);
|
||||
if (reply_header->reply_from_ != nullptr || reply_header->reply_media_ != nullptr ||
|
||||
!reply_header->quote_text_.empty() || !reply_header->quote_entities_.empty()) {
|
||||
LOG(ERROR) << "Receive reply from other chat " << to_string(reply_header) << " in "
|
||||
<< MessageFullId{dialog_id, message_id};
|
||||
}
|
||||
} else {
|
||||
if (reply_header->reply_to_msg_id_ != 0) {
|
||||
reply_to_message_id_ = MessageId(ServerMessageId(reply_header->reply_to_msg_id_));
|
||||
auto reply_to_peer_id = std::move(reply_header->reply_to_peer_id_);
|
||||
if (reply_to_peer_id != nullptr) {
|
||||
reply_in_dialog_id_ = DialogId(reply_to_peer_id);
|
||||
if (!reply_in_dialog_id_.is_valid()) {
|
||||
LOG(ERROR) << "Receive reply in invalid " << to_string(reply_to_peer_id);
|
||||
reply_to_message_id_ = MessageId();
|
||||
reply_in_dialog_id_ = DialogId();
|
||||
}
|
||||
if (reply_in_dialog_id_ == dialog_id) {
|
||||
reply_in_dialog_id_ = DialogId(); // just in case
|
||||
}
|
||||
}
|
||||
if (!reply_to_message_id_.is_valid()) {
|
||||
LOG(ERROR) << "Receive " << to_string(reply_header) << " in " << MessageFullId{dialog_id, message_id};
|
||||
reply_to_message_id_ = MessageId();
|
||||
reply_in_dialog_id_ = DialogId();
|
||||
}
|
||||
if (reply_in_dialog_id_ == dialog_id) {
|
||||
reply_in_dialog_id_ = DialogId(); // just in case
|
||||
}
|
||||
} else if (reply_header->reply_to_peer_id_ != nullptr) {
|
||||
LOG(ERROR) << "Receive " << to_string(reply_header) << " in " << MessageFullId{dialog_id, message_id};
|
||||
}
|
||||
if (reply_to_message_id_.is_valid() && !message_id.is_scheduled() && !reply_in_dialog_id_.is_valid() &&
|
||||
can_have_thread) {
|
||||
if ((reply_header->flags_ & telegram_api::messageReplyHeader::REPLY_TO_TOP_ID_MASK) != 0) {
|
||||
top_thread_message_id_ = MessageId(ServerMessageId(reply_header->reply_to_top_id_));
|
||||
if (reply_header->reply_from_ != nullptr) {
|
||||
reply_date_ = reply_header->reply_from_->date_;
|
||||
if (reply_header->reply_from_->channel_post_ != 0) {
|
||||
LOG(ERROR) << "Receive " << to_string(reply_header) << " in " << MessageFullId{dialog_id, message_id};
|
||||
} else {
|
||||
top_thread_message_id_ = reply_to_message_id_;
|
||||
auto r_reply_origin = MessageOrigin::get_message_origin(td, std::move(reply_header->reply_from_));
|
||||
if (r_reply_origin.is_error()) {
|
||||
reply_date_ = 0;
|
||||
}
|
||||
}
|
||||
is_topic_message_ = reply_header->forum_topic_;
|
||||
}
|
||||
}
|
||||
if (!message_id.is_scheduled() && can_have_thread) {
|
||||
if ((reply_header->flags_ & telegram_api::messageReplyHeader::REPLY_TO_TOP_ID_MASK) != 0) {
|
||||
top_thread_message_id_ = MessageId(ServerMessageId(reply_header->reply_to_top_id_));
|
||||
} else if (reply_to_message_id_.is_valid() && !reply_in_dialog_id_.is_valid() && reply_date_ == 0) {
|
||||
top_thread_message_id_ = reply_to_message_id_;
|
||||
}
|
||||
is_topic_message_ = top_thread_message_id_.is_valid() && reply_header->forum_topic_;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/MessageId.h"
|
||||
#include "td/telegram/MessageOrigin.h"
|
||||
#include "td/telegram/StoryFullId.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
@ -15,9 +16,13 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
class Td;
|
||||
|
||||
struct MessageReplyHeader {
|
||||
MessageId reply_to_message_id_;
|
||||
DialogId reply_in_dialog_id_;
|
||||
int32 reply_date_ = 0; // for replies in other chats
|
||||
MessageOrigin reply_origin_; // for replies in other chats
|
||||
MessageId top_thread_message_id_;
|
||||
bool is_topic_message_ = false;
|
||||
|
||||
@ -27,7 +32,7 @@ struct MessageReplyHeader {
|
||||
|
||||
MessageReplyHeader() = default;
|
||||
|
||||
MessageReplyHeader(tl_object_ptr<telegram_api::MessageReplyHeader> &&reply_header_ptr, DialogId dialog_id,
|
||||
MessageReplyHeader(Td *td, tl_object_ptr<telegram_api::MessageReplyHeader> &&reply_header_ptr, DialogId dialog_id,
|
||||
MessageId message_id, int32 date, bool can_have_thread);
|
||||
};
|
||||
|
||||
|
@ -14246,7 +14246,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
|
||||
message_info.forward_header = std::move(message->fwd_from_);
|
||||
bool can_have_thread =
|
||||
message_info.dialog_id.get_type() == DialogType::Channel && !is_broadcast_channel(message_info.dialog_id);
|
||||
message_info.reply_header = MessageReplyHeader(std::move(message->reply_to_), message_info.dialog_id,
|
||||
message_info.reply_header = MessageReplyHeader(td_, std::move(message->reply_to_), message_info.dialog_id,
|
||||
message_info.message_id, message_info.date, can_have_thread);
|
||||
if (message->flags_ & telegram_api::message::VIA_BOT_ID_MASK) {
|
||||
message_info.via_bot_user_id = UserId(message->via_bot_id_);
|
||||
@ -14315,7 +14315,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
|
||||
message_info.has_unread_content = message->media_unread_;
|
||||
bool can_have_thread =
|
||||
message_info.dialog_id.get_type() == DialogType::Channel && !is_broadcast_channel(message_info.dialog_id);
|
||||
message_info.reply_header = MessageReplyHeader(std::move(message->reply_to_), message_info.dialog_id,
|
||||
message_info.reply_header = MessageReplyHeader(td_, std::move(message->reply_to_), message_info.dialog_id,
|
||||
message_info.message_id, message_info.date, can_have_thread);
|
||||
message_info.content = get_action_message_content(td_, std::move(message->action_), message_info.dialog_id,
|
||||
message_info.reply_header.reply_in_dialog_id_,
|
||||
|
Loading…
x
Reference in New Issue
Block a user