Simplify RepliedMessageInfo field names.
This commit is contained in:
parent
82b9f21cec
commit
2d7b2b4545
@ -20,19 +20,19 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messa
|
||||
DialogId dialog_id, MessageId message_id, int32 date) {
|
||||
CHECK(reply_header != nullptr);
|
||||
if (reply_header->reply_to_scheduled_) {
|
||||
reply_to_message_id_ = MessageId(ScheduledServerMessageId(reply_header->reply_to_msg_id_), date);
|
||||
message_id_ = MessageId(ScheduledServerMessageId(reply_header->reply_to_msg_id_), date);
|
||||
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);
|
||||
LOG(ERROR) << "Receive reply to " << MessageFullId{reply_in_dialog_id_, reply_to_message_id_} << " in "
|
||||
dialog_id_ = DialogId(reply_to_peer_id);
|
||||
LOG(ERROR) << "Receive reply to " << MessageFullId{dialog_id_, message_id_} << " in "
|
||||
<< MessageFullId{dialog_id, message_id};
|
||||
reply_to_message_id_ = MessageId();
|
||||
reply_in_dialog_id_ = DialogId();
|
||||
message_id_ = MessageId();
|
||||
dialog_id_ = DialogId();
|
||||
}
|
||||
} else {
|
||||
LOG(ERROR) << "Receive reply to " << reply_to_message_id_ << " in " << MessageFullId{dialog_id, message_id};
|
||||
reply_to_message_id_ = MessageId();
|
||||
LOG(ERROR) << "Receive reply to " << message_id_ << " in " << MessageFullId{dialog_id, message_id};
|
||||
message_id_ = MessageId();
|
||||
}
|
||||
if (reply_header->reply_from_ != nullptr || reply_header->reply_media_ != nullptr ||
|
||||
!reply_header->quote_text_.empty() || !reply_header->quote_entities_.empty()) {
|
||||
@ -41,35 +41,35 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messa
|
||||
}
|
||||
} else {
|
||||
if (reply_header->reply_to_msg_id_ != 0) {
|
||||
reply_to_message_id_ = MessageId(ServerMessageId(reply_header->reply_to_msg_id_));
|
||||
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()) {
|
||||
dialog_id_ = DialogId(reply_to_peer_id);
|
||||
if (!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();
|
||||
message_id_ = MessageId();
|
||||
dialog_id_ = DialogId();
|
||||
}
|
||||
if (reply_in_dialog_id_ == dialog_id) {
|
||||
reply_in_dialog_id_ = DialogId(); // just in case
|
||||
if (dialog_id_ == dialog_id) {
|
||||
dialog_id_ = DialogId(); // just in case
|
||||
}
|
||||
}
|
||||
if (!reply_to_message_id_.is_valid()) {
|
||||
if (!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();
|
||||
message_id_ = MessageId();
|
||||
dialog_id_ = DialogId();
|
||||
}
|
||||
} else if (reply_header->reply_to_peer_id_ != nullptr) {
|
||||
LOG(ERROR) << "Receive " << to_string(reply_header) << " in " << MessageFullId{dialog_id, message_id};
|
||||
}
|
||||
if (reply_header->reply_from_ != nullptr) {
|
||||
reply_date_ = reply_header->reply_from_->date_;
|
||||
origin_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 {
|
||||
auto r_reply_origin = MessageOrigin::get_message_origin(td, std::move(reply_header->reply_from_));
|
||||
if (r_reply_origin.is_error()) {
|
||||
reply_date_ = 0;
|
||||
origin_date_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,16 +77,16 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messa
|
||||
}
|
||||
|
||||
MessageId RepliedMessageInfo::get_same_chat_reply_to_message_id() const {
|
||||
return is_same_chat_reply() ? reply_to_message_id_ : MessageId();
|
||||
return is_same_chat_reply() ? message_id_ : MessageId();
|
||||
}
|
||||
|
||||
MessageFullId RepliedMessageInfo::get_reply_message_full_id() const {
|
||||
return {reply_in_dialog_id_, reply_to_message_id_};
|
||||
return {dialog_id_, message_id_};
|
||||
}
|
||||
|
||||
bool operator==(const RepliedMessageInfo &lhs, const RepliedMessageInfo &rhs) {
|
||||
return lhs.reply_to_message_id_ == rhs.reply_to_message_id_ && lhs.reply_in_dialog_id_ == rhs.reply_in_dialog_id_ &&
|
||||
lhs.reply_date_ == rhs.reply_date_ && lhs.reply_origin_ == rhs.reply_origin_;
|
||||
return lhs.message_id_ == rhs.message_id_ && lhs.dialog_id_ == rhs.dialog_id_ &&
|
||||
lhs.origin_date_ == rhs.origin_date_ && lhs.origin_ == rhs.origin_;
|
||||
}
|
||||
|
||||
bool operator!=(const RepliedMessageInfo &lhs, const RepliedMessageInfo &rhs) {
|
||||
|
@ -18,29 +18,28 @@ namespace td {
|
||||
class Td;
|
||||
|
||||
class RepliedMessageInfo {
|
||||
MessageId reply_to_message_id_;
|
||||
DialogId reply_in_dialog_id_; // DialogId() if reply is to a message in the same chat
|
||||
int32 reply_date_ = 0; // for replies in other chats
|
||||
MessageOrigin reply_origin_; // for replies in other chats
|
||||
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
|
||||
|
||||
friend bool operator==(const RepliedMessageInfo &lhs, const RepliedMessageInfo &rhs);
|
||||
|
||||
public:
|
||||
RepliedMessageInfo() = default;
|
||||
|
||||
explicit RepliedMessageInfo(MessageId reply_to_message_id) : reply_to_message_id_(reply_to_message_id) {
|
||||
explicit RepliedMessageInfo(MessageId reply_to_message_id) : message_id_(reply_to_message_id) {
|
||||
}
|
||||
|
||||
RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messageReplyHeader> &&reply_header, DialogId dialog_id,
|
||||
MessageId message_id, int32 date);
|
||||
|
||||
bool is_same_chat_reply() const {
|
||||
return reply_in_dialog_id_ == DialogId() && reply_date_ == 0;
|
||||
return dialog_id_ == DialogId() && origin_date_ == 0;
|
||||
}
|
||||
|
||||
bool is_empty() const {
|
||||
return reply_to_message_id_ == MessageId() && reply_in_dialog_id_ == DialogId() && reply_date_ == 0 &&
|
||||
reply_origin_.is_empty();
|
||||
return message_id_ == MessageId() && dialog_id_ == DialogId() && origin_date_ == 0 && origin_.is_empty();
|
||||
}
|
||||
|
||||
MessageId get_same_chat_reply_to_message_id() const;
|
||||
|
@ -16,53 +16,53 @@ namespace td {
|
||||
|
||||
template <class StorerT>
|
||||
void RepliedMessageInfo::store(StorerT &storer) const {
|
||||
bool has_reply_to_message_id = reply_to_message_id_.is_valid() || reply_to_message_id_.is_valid_scheduled();
|
||||
bool has_reply_in_dialog_id = reply_in_dialog_id_.is_valid();
|
||||
bool has_reply_date = reply_date_ != 0;
|
||||
bool has_reply_origin = !reply_origin_.is_empty();
|
||||
bool has_message_id = message_id_.is_valid() || message_id_.is_valid_scheduled();
|
||||
bool has_dialog_id = dialog_id_.is_valid();
|
||||
bool has_origin_date = origin_date_ != 0;
|
||||
bool has_origin = !origin_.is_empty();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(has_reply_to_message_id);
|
||||
STORE_FLAG(has_reply_in_dialog_id);
|
||||
STORE_FLAG(has_reply_date);
|
||||
STORE_FLAG(has_reply_origin);
|
||||
STORE_FLAG(has_message_id);
|
||||
STORE_FLAG(has_dialog_id);
|
||||
STORE_FLAG(has_origin_date);
|
||||
STORE_FLAG(has_origin);
|
||||
END_STORE_FLAGS();
|
||||
if (has_reply_to_message_id) {
|
||||
td::store(reply_to_message_id_, storer);
|
||||
if (has_message_id) {
|
||||
td::store(message_id_, storer);
|
||||
}
|
||||
if (has_reply_in_dialog_id) {
|
||||
td::store(reply_in_dialog_id_, storer);
|
||||
if (has_dialog_id) {
|
||||
td::store(dialog_id_, storer);
|
||||
}
|
||||
if (has_reply_date) {
|
||||
td::store(reply_date_, storer);
|
||||
if (has_origin_date) {
|
||||
td::store(origin_date_, storer);
|
||||
}
|
||||
if (has_reply_origin) {
|
||||
td::store(reply_origin_, storer);
|
||||
if (has_origin) {
|
||||
td::store(origin_, storer);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void RepliedMessageInfo::parse(ParserT &parser) {
|
||||
bool has_reply_to_message_id;
|
||||
bool has_reply_in_dialog_id;
|
||||
bool has_reply_date;
|
||||
bool has_reply_origin;
|
||||
bool has_message_id;
|
||||
bool has_dialog_id;
|
||||
bool has_origin_date;
|
||||
bool has_origin;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(has_reply_to_message_id);
|
||||
PARSE_FLAG(has_reply_in_dialog_id);
|
||||
PARSE_FLAG(has_reply_date);
|
||||
PARSE_FLAG(has_reply_origin);
|
||||
PARSE_FLAG(has_message_id);
|
||||
PARSE_FLAG(has_dialog_id);
|
||||
PARSE_FLAG(has_origin_date);
|
||||
PARSE_FLAG(has_origin);
|
||||
END_PARSE_FLAGS();
|
||||
if (has_reply_to_message_id) {
|
||||
td::parse(reply_to_message_id_, parser);
|
||||
if (has_message_id) {
|
||||
td::parse(message_id_, parser);
|
||||
}
|
||||
if (has_reply_in_dialog_id) {
|
||||
td::parse(reply_in_dialog_id_, parser);
|
||||
if (has_dialog_id) {
|
||||
td::parse(dialog_id_, parser);
|
||||
}
|
||||
if (has_reply_date) {
|
||||
td::parse(reply_date_, parser);
|
||||
if (has_origin_date) {
|
||||
td::parse(origin_date_, parser);
|
||||
}
|
||||
if (has_reply_origin) {
|
||||
td::parse(reply_origin_, parser);
|
||||
if (has_origin) {
|
||||
td::parse(origin_, parser);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user