Improve MessateReplyHeader processing.

This commit is contained in:
levlam 2022-11-02 14:04:43 +03:00
parent 481387b12d
commit 4cc5ed345d
3 changed files with 10 additions and 9 deletions

View File

@ -15,7 +15,7 @@
namespace td {
MessageReplyHeader::MessageReplyHeader(tl_object_ptr<telegram_api::messageReplyHeader> &&reply_header,
DialogId dialog_id, MessageId message_id, int32 date) {
DialogId dialog_id, MessageId message_id, int32 date, bool can_have_thread) {
if (reply_header == nullptr) {
return;
}
@ -51,6 +51,8 @@ MessageReplyHeader::MessageReplyHeader(tl_object_ptr<telegram_api::messageReplyH
if (reply_to_message_id.is_valid() && !message_id.is_scheduled() && !reply_in_dialog_id.is_valid()) {
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 (can_have_thread) {
top_thread_message_id = reply_to_message_id;
}
is_topic_message = reply_header->forum_topic_;
}

View File

@ -23,7 +23,7 @@ struct MessageReplyHeader {
MessageReplyHeader() = default;
MessageReplyHeader(tl_object_ptr<telegram_api::messageReplyHeader> &&reply_header, DialogId dialog_id,
MessageId message_id, int32 date);
MessageId message_id, int32 date, bool can_have_thread);
};
} // namespace td

View File

@ -14628,8 +14628,10 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
}
message_info.date = message->date_;
message_info.forward_header = std::move(message->fwd_from_);
bool can_have_thread = !is_scheduled && 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.message_id, message_info.date);
message_info.message_id, message_info.date, can_have_thread);
if (message->flags_ & MESSAGE_FLAG_IS_SENT_VIA_BOT) {
message_info.via_bot_user_id = UserId(message->via_bot_id_);
if (!message_info.via_bot_user_id.is_valid()) {
@ -14694,8 +14696,10 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.ttl_period = message->ttl_period_;
}
message_info.flags = message->flags_;
bool can_have_thread = !is_scheduled && 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.message_id, message_info.date);
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,
message_info.reply_header.reply_to_message_id);
@ -14882,11 +14886,6 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
forward_count = 0;
}
MessageReplyInfo reply_info(td_, std::move(message_info.reply_info), td_->auth_manager_->is_bot());
if (reply_to_message_id.is_valid() && !reply_in_dialog_id.is_valid() && message_id.is_valid() &&
message_id.is_server() && !top_thread_message_id.is_valid() && dialog_type == DialogType::Channel &&
!is_broadcast_channel(dialog_id)) {
top_thread_message_id = reply_to_message_id;
}
if (!top_thread_message_id.is_valid() && is_thread_message(dialog_id, message_id, reply_info, content_type)) {
top_thread_message_id = message_id;
is_topic_message = (content_type == MessageContentType::TopicCreate);