tdlight/td/telegram/MessageReplyHeader.cpp

103 lines
4.6 KiB
C++
Raw Normal View History

2022-11-02 04:28:35 +01:00
//
2022-12-31 22:28:08 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
2022-11-02 04:28:35 +01:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/MessageReplyHeader.h"
2023-09-21 18:11:17 +02:00
#include "td/telegram/MessageFullId.h"
2022-11-02 04:28:35 +01:00
#include "td/telegram/ScheduledServerMessageId.h"
#include "td/telegram/ServerMessageId.h"
2023-07-01 15:22:01 +02:00
#include "td/telegram/StoryId.h"
#include "td/telegram/UserId.h"
2022-11-02 04:28:35 +01:00
#include "td/utils/logging.h"
namespace td {
2023-10-23 19:54:47 +02:00
MessageReplyHeader::MessageReplyHeader(Td *td, tl_object_ptr<telegram_api::MessageReplyHeader> &&reply_header_ptr,
2022-11-02 12:04:43 +01:00
DialogId dialog_id, MessageId message_id, int32 date, bool can_have_thread) {
if (reply_header_ptr == nullptr) {
2022-11-02 04:28:35 +01:00
return;
}
if (reply_header_ptr->get_id() == telegram_api::messageReplyStoryHeader::ID) {
auto reply_header = telegram_api::move_object_as<telegram_api::messageReplyStoryHeader>(reply_header_ptr);
UserId user_id(reply_header->user_id_);
StoryId story_id(reply_header->story_id_);
if (!user_id.is_valid() || !story_id.is_server()) {
LOG(ERROR) << "Receive " << to_string(reply_header);
} else {
2023-06-07 14:10:46 +02:00
story_full_id_ = {DialogId(user_id), story_id};
}
return;
}
CHECK(reply_header_ptr->get_id() == telegram_api::messageReplyHeader::ID);
2023-05-01 20:07:01 +02:00
auto reply_header = telegram_api::move_object_as<telegram_api::messageReplyHeader>(reply_header_ptr);
2022-11-02 04:28:35 +01:00
if (reply_header->reply_to_scheduled_) {
reply_to_message_id_ = MessageId(ScheduledServerMessageId(reply_header->reply_to_msg_id_), date);
2022-11-02 04:28:35 +01:00
if (message_id.is_scheduled()) {
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);
2023-09-21 18:11:17 +02:00
LOG(ERROR) << "Receive reply to " << MessageFullId{reply_in_dialog_id_, reply_to_message_id_} << " in "
<< MessageFullId{dialog_id, message_id};
reply_to_message_id_ = MessageId();
reply_in_dialog_id_ = DialogId();
2022-11-02 04:28:35 +01:00
}
} else {
2023-09-21 18:11:17 +02:00
LOG(ERROR) << "Receive reply to " << reply_to_message_id_ << " in " << MessageFullId{dialog_id, message_id};
reply_to_message_id_ = MessageId();
2022-11-02 04:28:35 +01:00
}
2023-10-23 19:54:47 +02:00
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();
2022-11-02 04:28:35 +01:00
}
2023-10-23 19:54:47 +02:00
} else if (reply_header->reply_to_peer_id_ != nullptr) {
LOG(ERROR) << "Receive " << to_string(reply_header) << " in " << MessageFullId{dialog_id, message_id};
2022-11-02 04:28:35 +01:00
}
2023-10-23 19:54:47 +02:00
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 {
2023-10-23 19:54:47 +02:00
auto r_reply_origin = MessageOrigin::get_message_origin(td, std::move(reply_header->reply_from_));
if (r_reply_origin.is_error()) {
reply_date_ = 0;
}
2022-11-02 04:28:35 +01:00
}
}
}
2023-10-23 19:54:47 +02:00
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_;
}
2022-11-02 04:28:35 +01:00
}
} // namespace td