Improve MessageForwardInfo field names.
This commit is contained in:
parent
d59abc099d
commit
5ccb67f28e
@ -52,42 +52,42 @@ unique_ptr<MessageForwardInfo> MessageForwardInfo::get_message_forward_info(
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::messageForwardInfo> MessageForwardInfo::get_message_forward_info_object(Td *td) const {
|
||||
if (is_imported) {
|
||||
if (is_imported_) {
|
||||
return nullptr;
|
||||
}
|
||||
return td_api::make_object<td_api::messageForwardInfo>(
|
||||
origin.get_message_origin_object(td), date, psa_type,
|
||||
td->messages_manager_->get_chat_id_object(from_dialog_id, "messageForwardInfo"), from_message_id.get());
|
||||
origin_.get_message_origin_object(td), date_, psa_type_,
|
||||
td->messages_manager_->get_chat_id_object(from_dialog_id_, "messageForwardInfo"), from_message_id_.get());
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::messageImportInfo> MessageForwardInfo::get_message_import_info_object() const {
|
||||
if (!is_imported) {
|
||||
if (!is_imported_) {
|
||||
return nullptr;
|
||||
}
|
||||
return td_api::make_object<td_api::messageImportInfo>(origin.get_sender_name(), date);
|
||||
return td_api::make_object<td_api::messageImportInfo>(origin_.get_sender_name(), date_);
|
||||
}
|
||||
|
||||
void MessageForwardInfo::add_dependencies(Dependencies &dependencies) const {
|
||||
origin.add_dependencies(dependencies);
|
||||
dependencies.add_dialog_and_dependencies(from_dialog_id);
|
||||
origin_.add_dependencies(dependencies);
|
||||
dependencies.add_dialog_and_dependencies(from_dialog_id_);
|
||||
}
|
||||
|
||||
void MessageForwardInfo::add_min_user_ids(vector<UserId> &user_ids) const {
|
||||
origin.add_user_ids(user_ids);
|
||||
// from_dialog_id can be a user only in Saved Messages
|
||||
origin_.add_user_ids(user_ids);
|
||||
// from_dialog_id_ can be a user only in Saved Messages
|
||||
}
|
||||
|
||||
void MessageForwardInfo::add_min_channel_ids(vector<ChannelId> &channel_ids) const {
|
||||
origin.add_channel_ids(channel_ids);
|
||||
if (from_dialog_id.get_type() == DialogType::Channel) {
|
||||
channel_ids.push_back(from_dialog_id.get_channel_id());
|
||||
origin_.add_channel_ids(channel_ids);
|
||||
if (from_dialog_id_.get_type() == DialogType::Channel) {
|
||||
channel_ids.push_back(from_dialog_id_.get_channel_id());
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs) {
|
||||
return lhs.origin == rhs.origin && lhs.date == rhs.date && lhs.from_dialog_id == rhs.from_dialog_id &&
|
||||
lhs.from_message_id == rhs.from_message_id && lhs.psa_type == rhs.psa_type &&
|
||||
lhs.is_imported == rhs.is_imported;
|
||||
return lhs.origin_ == rhs.origin_ && lhs.date_ == rhs.date_ && lhs.from_dialog_id_ == rhs.from_dialog_id_ &&
|
||||
lhs.from_message_id_ == rhs.from_message_id_ && lhs.psa_type_ == rhs.psa_type_ &&
|
||||
lhs.is_imported_ == rhs.is_imported_;
|
||||
}
|
||||
|
||||
bool operator!=(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs) {
|
||||
@ -95,14 +95,14 @@ bool operator!=(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs) {
|
||||
}
|
||||
|
||||
StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info) {
|
||||
string_builder << "MessageForwardInfo[" << (forward_info.is_imported ? "imported " : "") << forward_info.origin;
|
||||
if (!forward_info.psa_type.empty()) {
|
||||
string_builder << ", psa_type " << forward_info.psa_type;
|
||||
string_builder << "MessageForwardInfo[" << (forward_info.is_imported_ ? "imported " : "") << forward_info.origin_;
|
||||
if (!forward_info.psa_type_.empty()) {
|
||||
string_builder << ", psa_type_ " << forward_info.psa_type_;
|
||||
}
|
||||
if (forward_info.from_dialog_id.is_valid() || forward_info.from_message_id.is_valid()) {
|
||||
string_builder << ", from " << MessageFullId(forward_info.from_dialog_id, forward_info.from_message_id);
|
||||
if (forward_info.from_dialog_id_.is_valid() || forward_info.from_message_id_.is_valid()) {
|
||||
string_builder << ", from " << MessageFullId(forward_info.from_dialog_id_, forward_info.from_message_id_);
|
||||
}
|
||||
return string_builder << " at " << forward_info.date << ']';
|
||||
return string_builder << " at " << forward_info.date_ << ']';
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -24,23 +24,27 @@ class Dependencies;
|
||||
class Td;
|
||||
|
||||
struct MessageForwardInfo {
|
||||
MessageOrigin origin;
|
||||
int32 date = 0;
|
||||
DialogId from_dialog_id;
|
||||
MessageId from_message_id;
|
||||
string psa_type;
|
||||
bool is_imported = false;
|
||||
MessageOrigin origin_;
|
||||
int32 date_ = 0;
|
||||
DialogId from_dialog_id_;
|
||||
MessageId from_message_id_;
|
||||
string psa_type_;
|
||||
bool is_imported_ = false;
|
||||
|
||||
MessageForwardInfo() = default;
|
||||
|
||||
MessageForwardInfo(MessageOrigin &&origin, int32 date, DialogId from_dialog_id, MessageId from_message_id,
|
||||
string &&psa_type, bool is_imported)
|
||||
: origin(std::move(origin))
|
||||
, date(date)
|
||||
, from_dialog_id(from_dialog_id)
|
||||
, from_message_id(from_message_id)
|
||||
, psa_type(std::move(psa_type))
|
||||
, is_imported(is_imported) {
|
||||
: origin_(std::move(origin))
|
||||
, date_(date)
|
||||
, from_dialog_id_(from_dialog_id)
|
||||
, from_message_id_(from_message_id)
|
||||
, psa_type_(std::move(psa_type))
|
||||
, is_imported_(is_imported) {
|
||||
if (from_dialog_id_.is_valid() != from_message_id_.is_valid()) {
|
||||
from_dialog_id_ = DialogId();
|
||||
from_message_id_ = MessageId();
|
||||
}
|
||||
}
|
||||
|
||||
static unique_ptr<MessageForwardInfo> get_message_forward_info(
|
||||
@ -57,15 +61,15 @@ struct MessageForwardInfo {
|
||||
void add_min_channel_ids(vector<ChannelId> &channel_ids) const;
|
||||
|
||||
MessageFullId get_origin_message_full_id() const {
|
||||
return origin.get_message_full_id();
|
||||
return origin_.get_message_full_id();
|
||||
}
|
||||
|
||||
DialogId get_last_dialog_id() const {
|
||||
return from_dialog_id;
|
||||
return from_dialog_id_;
|
||||
}
|
||||
|
||||
MessageFullId get_last_message_full_id() const {
|
||||
return {from_dialog_id, from_message_id};
|
||||
return {from_dialog_id_, from_message_id_};
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
|
@ -18,21 +18,21 @@ namespace td {
|
||||
|
||||
template <class StorerT>
|
||||
void MessageForwardInfo::store(StorerT &storer) const {
|
||||
bool has_from = from_dialog_id.is_valid() && from_message_id.is_valid();
|
||||
bool has_psa_type = !psa_type.empty();
|
||||
bool has_from = from_dialog_id_.is_valid() && from_message_id_.is_valid();
|
||||
bool has_psa_type = !psa_type_.empty();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(is_imported);
|
||||
STORE_FLAG(is_imported_);
|
||||
STORE_FLAG(has_from);
|
||||
STORE_FLAG(has_psa_type);
|
||||
END_STORE_FLAGS();
|
||||
td::store(origin, storer);
|
||||
td::store(date, storer);
|
||||
td::store(origin_, storer);
|
||||
td::store(date_, storer);
|
||||
if (has_from) {
|
||||
td::store(from_dialog_id, storer);
|
||||
td::store(from_message_id, storer);
|
||||
td::store(from_dialog_id_, storer);
|
||||
td::store(from_message_id_, storer);
|
||||
}
|
||||
if (has_psa_type) {
|
||||
td::store(psa_type, storer);
|
||||
td::store(psa_type_, storer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,22 +41,22 @@ void MessageForwardInfo::parse(ParserT &parser) {
|
||||
bool has_from;
|
||||
bool has_psa_type;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(is_imported);
|
||||
PARSE_FLAG(is_imported_);
|
||||
PARSE_FLAG(has_from);
|
||||
PARSE_FLAG(has_psa_type);
|
||||
END_PARSE_FLAGS();
|
||||
td::parse(origin, parser);
|
||||
td::parse(date, parser);
|
||||
td::parse(origin_, parser);
|
||||
td::parse(date_, parser);
|
||||
if (has_from) {
|
||||
td::parse(from_dialog_id, parser);
|
||||
td::parse(from_message_id, parser);
|
||||
if (!from_dialog_id.is_valid() || !from_message_id.is_valid()) {
|
||||
from_dialog_id = DialogId();
|
||||
from_message_id = MessageId();
|
||||
td::parse(from_dialog_id_, parser);
|
||||
td::parse(from_message_id_, parser);
|
||||
if (!from_dialog_id_.is_valid() || !from_message_id_.is_valid()) {
|
||||
from_dialog_id_ = DialogId();
|
||||
from_message_id_ = MessageId();
|
||||
}
|
||||
}
|
||||
if (has_psa_type) {
|
||||
td::parse(psa_type, parser);
|
||||
td::parse(psa_type_, parser);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4262,8 +4262,8 @@ void MessagesManager::Message::parse(ParserT &parser) {
|
||||
} else if (legacy_is_forwarded) {
|
||||
forward_info = make_unique<MessageForwardInfo>();
|
||||
if (legacy_has_forward_origin) {
|
||||
parse(forward_info->origin, parser);
|
||||
parse(forward_info->date, parser);
|
||||
parse(forward_info->origin_, parser);
|
||||
parse(forward_info->date_, parser);
|
||||
} else {
|
||||
UserId forward_sender_user_id;
|
||||
DialogId forward_sender_dialog_id;
|
||||
@ -4271,7 +4271,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
|
||||
string forward_author_signature;
|
||||
string forward_sender_name;
|
||||
parse(forward_sender_user_id, parser);
|
||||
parse(forward_info->date, parser);
|
||||
parse(forward_info->date_, parser);
|
||||
parse(forward_sender_dialog_id, parser);
|
||||
parse(forward_message_id, parser);
|
||||
if (legacy_has_forward_author_signature) {
|
||||
@ -4280,17 +4280,17 @@ void MessagesManager::Message::parse(ParserT &parser) {
|
||||
if (legacy_has_forward_sender_name) {
|
||||
parse(forward_sender_name, parser);
|
||||
}
|
||||
forward_info->origin = MessageOrigin(forward_sender_user_id, forward_sender_dialog_id, forward_message_id,
|
||||
std::move(forward_author_signature), std::move(forward_sender_name));
|
||||
forward_info->origin_ = MessageOrigin(forward_sender_user_id, forward_sender_dialog_id, forward_message_id,
|
||||
std::move(forward_author_signature), std::move(forward_sender_name));
|
||||
}
|
||||
if (legacy_has_forward_from) {
|
||||
parse(forward_info->from_dialog_id, parser);
|
||||
parse(forward_info->from_message_id, parser);
|
||||
parse(forward_info->from_dialog_id_, parser);
|
||||
parse(forward_info->from_message_id_, parser);
|
||||
}
|
||||
if (legacy_has_forward_psa_type) {
|
||||
parse(forward_info->psa_type, parser);
|
||||
parse(forward_info->psa_type_, parser);
|
||||
}
|
||||
forward_info->is_imported = legacy_is_imported;
|
||||
forward_info->is_imported_ = legacy_is_imported;
|
||||
}
|
||||
if (has_real_forward_from) {
|
||||
parse(real_forward_from_dialog_id, parser);
|
||||
@ -9319,7 +9319,7 @@ bool MessagesManager::can_get_message_statistics(DialogId dialog_id, const Messa
|
||||
return false;
|
||||
}
|
||||
if (m == nullptr || m->message_id.is_scheduled() || !m->message_id.is_server() || m->view_count == 0 ||
|
||||
m->had_forward_info || (m->forward_info != nullptr && m->forward_info->origin.is_channel_post())) {
|
||||
m->had_forward_info || (m->forward_info != nullptr && m->forward_info->origin_.is_channel_post())) {
|
||||
return false;
|
||||
}
|
||||
return td_->contacts_manager_->can_get_channel_message_statistics(dialog_id);
|
||||
@ -13905,7 +13905,7 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
|
||||
CHECK(old_message_text != nullptr);
|
||||
FormattedText new_message_text = get_message_text(
|
||||
td_->contacts_manager_.get(), old_message_text->text, std::move(entities), true, td_->auth_manager_->is_bot(),
|
||||
m->forward_info ? m->forward_info->date : m->date, m->media_album_id != 0, "on_update_sent_text_message");
|
||||
m->forward_info ? m->forward_info->date_ : m->date, m->media_album_id != 0, "on_update_sent_text_message");
|
||||
auto new_content = get_message_content(td_, std::move(new_message_text), std::move(message_media), dialog_id, m->date,
|
||||
true /*likely ignored*/, UserId() /*likely ignored*/, nullptr /*ignored*/,
|
||||
nullptr, "on_update_sent_text_message");
|
||||
@ -15897,12 +15897,12 @@ void MessagesManager::block_message_sender_from_replies(MessageId message_id, bo
|
||||
|
||||
DialogId sender_dialog_id;
|
||||
if (m->forward_info != nullptr) {
|
||||
sender_dialog_id = m->forward_info->origin.get_sender();
|
||||
sender_dialog_id = m->forward_info->origin_.get_sender();
|
||||
}
|
||||
vector<MessageId> message_ids;
|
||||
if (need_delete_all_messages && sender_dialog_id.is_valid()) {
|
||||
message_ids = find_dialog_messages(d, [sender_dialog_id](const Message *m) {
|
||||
return !m->is_outgoing && m->forward_info != nullptr && m->forward_info->origin.get_sender() == sender_dialog_id;
|
||||
return !m->is_outgoing && m->forward_info != nullptr && m->forward_info->origin_.get_sender() == sender_dialog_id;
|
||||
});
|
||||
CHECK(td::contains(message_ids, message_id));
|
||||
} else if (need_delete_message) {
|
||||
@ -16804,12 +16804,11 @@ Status MessagesManager::can_get_media_timestamp_link(DialogId dialog_id, const M
|
||||
}
|
||||
|
||||
if (dialog_id.get_type() != DialogType::Channel) {
|
||||
auto forward_info = m->forward_info.get();
|
||||
if (!can_message_content_have_media_timestamp(m->content.get()) || forward_info == nullptr ||
|
||||
forward_info->is_imported) {
|
||||
if (!can_message_content_have_media_timestamp(m->content.get()) || m->forward_info == nullptr ||
|
||||
m->forward_info->is_imported_) {
|
||||
return Status::Error(400, "Message links are available only for messages in supergroups and channel chats");
|
||||
}
|
||||
auto origin_message_full_id = forward_info->get_origin_message_full_id();
|
||||
auto origin_message_full_id = m->forward_info->get_origin_message_full_id();
|
||||
auto origin_message_id = origin_message_full_id.get_message_id();
|
||||
if (!origin_message_id.is_valid() || !origin_message_id.is_server()) {
|
||||
return Status::Error(400, "Message links are available only for messages in supergroups and channel chats");
|
||||
@ -22250,9 +22249,8 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
|
||||
// in Saved Messages all non-forwarded messages must be outgoing
|
||||
// a forwarded message is outgoing, only if it doesn't have from_dialog_id and its sender isn't hidden
|
||||
// i.e. a message is incoming only if it's a forwarded message with known from_dialog_id or with a hidden sender
|
||||
auto forward_info = m->forward_info.get();
|
||||
is_outgoing = is_scheduled || forward_info == nullptr ||
|
||||
(!forward_info->get_last_dialog_id().is_valid() && !forward_info->origin.is_sender_hidden());
|
||||
is_outgoing = is_scheduled || m->forward_info == nullptr ||
|
||||
(!m->forward_info->get_last_dialog_id().is_valid() && !m->forward_info->origin_.is_sender_hidden());
|
||||
}
|
||||
|
||||
double ttl_expires_in = m->ttl_expires_at != 0 ? clamp(m->ttl_expires_at - Time::now(), 1e-3, m->ttl - 1e-3) : 0.0;
|
||||
@ -22722,7 +22720,7 @@ MessagesManager::ForwardedMessageInfo MessagesManager::get_forwarded_message_inf
|
||||
return result;
|
||||
}
|
||||
auto dialog_id = message_full_id.get_dialog_id();
|
||||
result.origin_date_ = m->forward_info != nullptr ? m->forward_info->date : m->date;
|
||||
result.origin_date_ = m->forward_info != nullptr ? m->forward_info->date_ : m->date;
|
||||
result.origin_ = get_forwarded_message_origin(dialog_id, m);
|
||||
result.content_ = dup_message_content(td_, td_->dialog_manager_->get_my_dialog_id(), m->content.get(),
|
||||
MessageContentDupType::Forward, MessageCopyOptions());
|
||||
@ -24612,11 +24610,10 @@ int32 MessagesManager::get_message_schedule_date(const Message *m) {
|
||||
DialogId MessagesManager::get_message_original_sender(const Message *m) {
|
||||
CHECK(m != nullptr);
|
||||
if (m->forward_info != nullptr) {
|
||||
auto forward_info = m->forward_info.get();
|
||||
if (forward_info->is_imported) {
|
||||
if (m->forward_info->is_imported_) {
|
||||
return DialogId();
|
||||
}
|
||||
return forward_info->origin.get_sender();
|
||||
return m->forward_info->origin_.get_sender();
|
||||
}
|
||||
return get_message_sender(m);
|
||||
}
|
||||
@ -25804,7 +25801,7 @@ MessageOrigin MessagesManager::get_forwarded_message_origin(DialogId dialog_id,
|
||||
CHECK(m != nullptr);
|
||||
MessageOrigin origin;
|
||||
if (m->forward_info != nullptr) {
|
||||
origin = m->forward_info->origin;
|
||||
origin = m->forward_info->origin_;
|
||||
} else if (m->is_channel_post) {
|
||||
if (td_->dialog_manager_->is_broadcast_channel(dialog_id)) {
|
||||
auto author_signature = m->sender_user_id.is_valid() ? td_->contacts_manager_->get_user_title(m->sender_user_id)
|
||||
@ -25844,10 +25841,10 @@ unique_ptr<MessageForwardInfo> MessagesManager::create_message_forward_info(Dial
|
||||
|
||||
if (m->forward_info != nullptr) {
|
||||
auto forward_info = make_unique<MessageForwardInfo>(*m->forward_info);
|
||||
forward_info->from_dialog_id = saved_from_dialog_id;
|
||||
forward_info->from_message_id = saved_from_message_id;
|
||||
if (!forward_info->is_imported) {
|
||||
forward_info->origin.hide_sender_if_needed(td_);
|
||||
forward_info->from_dialog_id_ = saved_from_dialog_id;
|
||||
forward_info->from_message_id_ = saved_from_message_id;
|
||||
if (!forward_info->is_imported_) {
|
||||
forward_info->origin_.hide_sender_if_needed(td_);
|
||||
}
|
||||
return forward_info;
|
||||
}
|
||||
@ -27641,7 +27638,7 @@ bool MessagesManager::is_message_notification_disabled(const Dialog *d, const Me
|
||||
td_->option_manager_->get_option_boolean("disable_sent_scheduled_message_notifications")) {
|
||||
return true;
|
||||
}
|
||||
if (m->forward_info != nullptr && m->forward_info->is_imported) {
|
||||
if (m->forward_info != nullptr && m->forward_info->is_imported_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -33096,15 +33093,15 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
|
||||
if (replace_legacy) {
|
||||
return false;
|
||||
}
|
||||
if (old_message->forward_info->is_imported || new_message->forward_info->is_imported) {
|
||||
if (old_message->forward_info->is_imported_ || new_message->forward_info->is_imported_) {
|
||||
return true;
|
||||
}
|
||||
if (!is_scheduled && !message_id.is_yet_unsent()) {
|
||||
return true;
|
||||
}
|
||||
// yet unsent or scheduled messages can change sender name or author signature when being sent
|
||||
return !old_message->forward_info->origin.has_sender_signature() &&
|
||||
!new_message->forward_info->origin.has_sender_signature();
|
||||
return !old_message->forward_info->origin_.has_sender_signature() &&
|
||||
!new_message->forward_info->origin_.has_sender_signature();
|
||||
}();
|
||||
if (need_warning) {
|
||||
LOG(ERROR) << message_id << " in " << dialog_id << " has changed forward info from "
|
||||
|
Loading…
Reference in New Issue
Block a user