Add max_message_id and max_read_message_id to MessageReplyInfo.

GitOrigin-RevId: f58dafcd0abd825019010b88f3e9d2835ad69311
This commit is contained in:
levlam 2020-09-15 19:45:45 +03:00
parent cd6cfc52ac
commit b5fc3012b3
5 changed files with 124 additions and 28 deletions

View File

@ -643,8 +643,8 @@ messageForwardInfo origin:MessageForwardOrigin date:int32 public_service_announc
//@description Contains information about interactions with a message
//@view_count Number of times the message was viewed
//@forward_count Number of times the message was forwarded
//@reply_count Number of times the message was directly or indirectly replied; supergroups and linked channels only
//@recent_replier_user_ids User identifiers of the recent repliers to the message
//@reply_count Number of times the message was directly or indirectly replied; discussion supergroups and discussed channels only
//@recent_replier_user_ids User identifiers of the recent repliers to the channel post
messageInteractionInfo view_count:int32 forward_count:int32 reply_count:int32 recent_replier_user_ids:vector<int32> = MessageInteractionInfo;

View File

@ -21,16 +21,8 @@ MessageReplyInfo::MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &
reply_count = reply_info->replies_;
pts = reply_info->replies_pts_;
for (auto &peer : reply_info->recent_repliers_) {
DialogId dialog_id(peer);
if (dialog_id.is_valid()) {
recent_replier_dialog_ids.push_back(dialog_id);
} else {
LOG(ERROR) << "Receive " << dialog_id << " as a recent replier";
}
}
is_comment = reply_info->comments_;
if (is_comment) {
channel_id = ChannelId(reply_info->channel_id_);
if (!channel_id.is_valid()) {
@ -39,6 +31,23 @@ MessageReplyInfo::MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &
is_comment = false;
}
}
if (is_comment) {
for (auto &peer : reply_info->recent_repliers_) {
DialogId dialog_id(peer);
if (dialog_id.is_valid()) {
recent_replier_dialog_ids.push_back(dialog_id);
} else {
LOG(ERROR) << "Receive " << dialog_id << " as a recent replier";
}
}
if ((reply_info->flags_ & telegram_api::messageReplies::MAX_ID_MASK) != 0 && reply_info->max_id_ > 0) {
max_message_id = MessageId(ServerMessageId(reply_info->max_id_));
}
if ((reply_info->flags_ & telegram_api::messageReplies::READ_MAX_ID_MASK) != 0 && reply_info->read_max_id_ > 0) {
max_read_message_id = MessageId(ServerMessageId(reply_info->read_max_id_));
}
}
}
bool MessageReplyInfo::need_update_to(const MessageReplyInfo &other) const {
@ -48,11 +57,28 @@ bool MessageReplyInfo::need_update_to(const MessageReplyInfo &other) const {
return reply_count != other.reply_count || recent_replier_dialog_ids != other.recent_replier_dialog_ids;
}
void MessageReplyInfo::add_reply(DialogId replier_dialog_id) {
bool MessageReplyInfo::update_max_message_ids(const MessageReplyInfo &other) {
if (!is_comment || !other.is_comment) {
return false;
}
bool result = false;
if (other.max_message_id > max_message_id) {
max_message_id = other.max_message_id;
result = true;
}
if (other.max_read_message_id > max_read_message_id) {
max_read_message_id = other.max_read_message_id;
result = true;
}
return result;
}
void MessageReplyInfo::add_reply(DialogId replier_dialog_id, MessageId reply_message_id) {
CHECK(!is_empty());
reply_count++;
if (replier_dialog_id.is_valid() &&
if (is_comment && replier_dialog_id.is_valid() &&
(recent_replier_dialog_ids.empty() || recent_replier_dialog_ids[0] != replier_dialog_id)) {
td::remove(recent_replier_dialog_ids, replier_dialog_id);
recent_replier_dialog_ids.insert(recent_replier_dialog_ids.begin(), replier_dialog_id);
@ -60,10 +86,19 @@ void MessageReplyInfo::add_reply(DialogId replier_dialog_id) {
recent_replier_dialog_ids.pop_back();
}
}
if (is_comment && reply_message_id > max_message_id) {
max_message_id = reply_message_id;
}
}
StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info) {
return string_builder << reply_info.reply_count << " replies by " << reply_info.recent_replier_dialog_ids;
if (reply_info.is_comment) {
return string_builder << reply_info.reply_count << " comments in " << reply_info.channel_id << " by "
<< reply_info.recent_replier_dialog_ids << " read up to " << reply_info.max_read_message_id;
} else {
return string_builder << reply_info.reply_count << " replies";
}
}
} // namespace td

View File

@ -8,6 +8,7 @@
#include "td/telegram/ChannelId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
@ -19,8 +20,10 @@ namespace td {
struct MessageReplyInfo {
int32 reply_count = -1;
int32 pts = -1;
vector<DialogId> recent_replier_dialog_ids;
ChannelId channel_id;
vector<DialogId> recent_replier_dialog_ids; // comments only
ChannelId channel_id; // comments only
MessageId max_message_id; // comments only
MessageId max_read_message_id; // comments only
bool is_comment = false;
MessageReplyInfo() = default;
@ -33,17 +36,23 @@ struct MessageReplyInfo {
bool need_update_to(const MessageReplyInfo &other) const;
void add_reply(DialogId replier_dialog_id);
bool update_max_message_ids(const MessageReplyInfo &other);
void add_reply(DialogId replier_dialog_id, MessageId reply_message_id);
template <class StorerT>
void store(StorerT &storer) const {
CHECK(!is_empty());
bool has_recent_replier_dialog_ids = !recent_replier_dialog_ids.empty();
bool has_channel_id = channel_id.is_valid();
bool has_max_message_id = max_message_id.is_valid();
bool has_max_read_message_id = max_read_message_id.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(is_comment);
STORE_FLAG(has_recent_replier_dialog_ids);
STORE_FLAG(has_channel_id);
STORE_FLAG(has_max_message_id);
STORE_FLAG(has_max_read_message_id);
END_STORE_FLAGS();
td::store(reply_count, storer);
td::store(pts, storer);
@ -53,16 +62,26 @@ struct MessageReplyInfo {
if (has_channel_id) {
td::store(channel_id, storer);
}
if (has_max_message_id) {
td::store(max_message_id, storer);
}
if (has_max_read_message_id) {
td::store(max_read_message_id, storer);
}
}
template <class ParserT>
void parse(ParserT &parser) {
bool has_recent_replier_dialog_ids = !recent_replier_dialog_ids.empty();
bool has_channel_id = channel_id.is_valid();
bool has_recent_replier_dialog_ids;
bool has_channel_id;
bool has_max_message_id;
bool has_max_read_message_id;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_comment);
PARSE_FLAG(has_recent_replier_dialog_ids);
PARSE_FLAG(has_channel_id);
PARSE_FLAG(has_max_message_id);
PARSE_FLAG(has_max_read_message_id);
END_PARSE_FLAGS();
td::parse(reply_count, parser);
td::parse(pts, parser);
@ -72,6 +91,12 @@ struct MessageReplyInfo {
if (has_channel_id) {
td::parse(channel_id, parser);
}
if (has_max_message_id) {
td::parse(max_message_id, parser);
}
if (has_max_read_message_id) {
td::parse(max_read_message_id, parser);
}
}
};

View File

@ -6258,6 +6258,16 @@ bool MessagesManager::update_message_interaction_info(DialogId dialog_id, Messag
MessageReplyInfo &&reply_info) {
CHECK(m != nullptr);
bool need_update_reply_info = has_reply_info && m->reply_info.need_update_to(reply_info);
if (has_reply_info && m->reply_info.channel_id == reply_info.channel_id) {
if (need_update_reply_info) {
reply_info.update_max_message_ids(m->reply_info);
} else {
if (m->reply_info.update_max_message_ids(reply_info) && view_count <= m->view_count &&
forward_count <= m->forward_count) {
on_message_changed(get_dialog(dialog_id), m, false, "update_message_interaction_info");
}
}
}
if (view_count > m->view_count || forward_count > m->forward_count || need_update_reply_info) {
LOG(DEBUG) << "Update interaction info of " << FullMessageId{dialog_id, m->message_id} << " from " << m->view_count
<< '/' << m->forward_count << "/" << m->reply_info << " to " << view_count << '/' << forward_count << "/"
@ -21249,7 +21259,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, Dialo
add_dialog_and_dependencies(dependencies, m->forward_info->from_dialog_id);
}
for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) {
if (dialog_id.get_type() == DialogType::User) {
if (recent_replier_dialog_id.get_type() == DialogType::User) {
dependencies.user_ids.insert(recent_replier_dialog_id.get_user_id());
}
}
@ -29541,8 +29551,21 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
}
if (from_update && message->top_reply_message_id.is_valid() && message->top_reply_message_id != message_id &&
message_id.is_server() &&
have_message_force({dialog_id, message->top_reply_message_id}, "preload top reply message")) {
LOG(INFO) << "Preloaded top reply message pinned " << message->top_reply_message_id << " from database";
LOG(INFO) << "Preloaded top reply " << message->top_reply_message_id << " from database";
Message *top_m = get_message(d, message->top_reply_message_id);
CHECK(top_m != nullptr);
if (is_active_message_reply_info(dialog_id, top_m->reply_info) && !top_m->sender_user_id.is_valid() &&
top_m->forward_info != nullptr && top_m->forward_info->sender_dialog_id.is_valid() &&
top_m->forward_info->message_id.is_valid() &&
have_message_force({top_m->forward_info->sender_dialog_id, top_m->forward_info->message_id},
"preload discussed message")) {
LOG(INFO) << "Preloaded discussed "
<< FullMessageId{top_m->forward_info->sender_dialog_id, top_m->forward_info->message_id}
<< " from database";
}
}
// there must be no two recursive calls to add_message_to_dialog
@ -29891,13 +29914,26 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
}
if (!td_->auth_manager_->is_bot() && m->top_reply_message_id.is_valid() && m->top_reply_message_id != message_id) {
if (!td_->auth_manager_->is_bot() && m->top_reply_message_id.is_valid() && m->top_reply_message_id != message_id &&
message_id.is_server()) {
Message *top_m = get_message(d, m->top_reply_message_id);
if (top_m != nullptr && is_active_message_reply_info(dialog_id, top_m->reply_info)) {
top_m->reply_info.add_reply(has_message_sender_user_id(dialog_id, m) ? DialogId(m->sender_user_id)
: m->sender_dialog_id);
auto replier_dialog_id =
has_message_sender_user_id(dialog_id, m) ? DialogId(m->sender_user_id) : m->sender_dialog_id;
top_m->reply_info.add_reply(replier_dialog_id, message_id);
send_update_message_interaction_info(dialog_id, top_m);
on_message_changed(d, top_m, true, "update_message_reply_count");
on_message_changed(d, top_m, true, "update_message_reply_count 1");
if (!top_m->sender_user_id.is_valid() && top_m->forward_info != nullptr &&
top_m->forward_info->sender_dialog_id.is_valid() && top_m->forward_info->message_id.is_valid()) {
auto channel_dialog_id = top_m->forward_info->sender_dialog_id;
Message *channel_m = get_message({channel_dialog_id, top_m->forward_info->message_id});
if (channel_m != nullptr && is_active_message_reply_info(channel_dialog_id, channel_m->reply_info)) {
channel_m->reply_info.add_reply(replier_dialog_id, message_id);
send_update_message_interaction_info(channel_dialog_id, channel_m);
on_message_changed(get_dialog(channel_dialog_id), channel_m, true, "update_message_reply_count 2");
}
}
}
}
}
@ -29955,7 +29991,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
}
}
if (!td_->auth_manager_->is_bot() && from_update && m->forward_info != nullptr && m->sender_user_id.is_valid() &&
if (!td_->auth_manager_->is_bot() && from_update && m->sender_user_id.is_valid() && m->forward_info != nullptr &&
m->forward_info->sender_dialog_id.is_valid() && m->forward_info->message_id.is_valid()) {
update_forward_count(m->forward_info->sender_dialog_id, m->forward_info->message_id);
}

View File

@ -66,8 +66,8 @@ void store(const ReplyMarkup &reply_markup, StorerT &storer) {
template <class ParserT>
void parse(ReplyMarkup &reply_markup, ParserT &parser) {
bool has_keyboard = !reply_markup.keyboard.empty();
bool has_inline_keyboard = !reply_markup.inline_keyboard.empty();
bool has_keyboard;
bool has_inline_keyboard;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(reply_markup.is_personal);
PARSE_FLAG(reply_markup.need_resize_keyboard);