Improve updating of reply info.

This commit is contained in:
levlam 2022-11-19 11:21:41 +03:00
parent fe7ea9bac9
commit 2d2446ae77
3 changed files with 32 additions and 21 deletions

View File

@ -118,10 +118,6 @@ bool MessageReplyInfo::update_max_message_ids(MessageId other_max_message_id,
MessageId other_last_read_inbox_message_id,
MessageId other_last_read_outbox_message_id) {
bool result = false;
if (other_max_message_id > max_message_id) {
max_message_id = other_max_message_id;
result = true;
}
if (other_last_read_inbox_message_id > last_read_inbox_message_id) {
last_read_inbox_message_id = other_last_read_inbox_message_id;
result = true;
@ -130,13 +126,18 @@ bool MessageReplyInfo::update_max_message_ids(MessageId other_max_message_id,
last_read_outbox_message_id = other_last_read_outbox_message_id;
result = true;
}
if (last_read_inbox_message_id > max_message_id) {
max_message_id = last_read_inbox_message_id;
result = true;
}
if (last_read_outbox_message_id > max_message_id) {
max_message_id = last_read_outbox_message_id;
result = true;
if (other_max_message_id.is_valid() ||
(!other_last_read_inbox_message_id.is_valid() && !other_last_read_outbox_message_id.is_valid())) {
if (other_max_message_id < last_read_inbox_message_id) {
other_max_message_id = last_read_inbox_message_id;
}
if (other_max_message_id < last_read_outbox_message_id) {
other_max_message_id = last_read_outbox_message_id;
}
if (other_max_message_id != max_message_id) {
max_message_id = other_max_message_id;
result = true;
}
}
return result;
}

View File

@ -21428,7 +21428,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, MessageId top_thread_m
return Status::OK();
}
if (top_thread_message_id.is_valid()) {
if (top_thread_message_id.is_valid() && max_message_id.is_valid()) {
MessageId prev_last_read_inbox_message_id;
MessageId max_thread_message_id;
Message *top_m = get_message_force(d, top_thread_message_id, "view_messages 2");

View File

@ -2939,22 +2939,32 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateChannelAvailabl
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionInbox> update,
Promise<Unit> &&promise) {
td_->messages_manager_->on_update_read_message_comments(
DialogId(ChannelId(update->channel_id_)), MessageId(ServerMessageId(update->top_msg_id_)), MessageId(),
MessageId(ServerMessageId(update->read_max_id_)), MessageId());
auto last_read_inbox_message_id = MessageId(ServerMessageId(update->read_max_id_));
if (!last_read_inbox_message_id.is_valid()) {
LOG(ERROR) << "Receive " << to_string(update);
return;
}
td_->messages_manager_->on_update_read_message_comments(DialogId(ChannelId(update->channel_id_)),
MessageId(ServerMessageId(update->top_msg_id_)), MessageId(),
last_read_inbox_message_id, MessageId());
if ((update->flags_ & telegram_api::updateReadChannelDiscussionInbox::BROADCAST_ID_MASK) != 0) {
td_->messages_manager_->on_update_read_message_comments(
DialogId(ChannelId(update->broadcast_id_)), MessageId(ServerMessageId(update->broadcast_post_)), MessageId(),
MessageId(ServerMessageId(update->read_max_id_)), MessageId());
td_->messages_manager_->on_update_read_message_comments(DialogId(ChannelId(update->broadcast_id_)),
MessageId(ServerMessageId(update->broadcast_post_)),
MessageId(), last_read_inbox_message_id, MessageId());
}
promise.set_value(Unit());
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadChannelDiscussionOutbox> update,
Promise<Unit> &&promise) {
td_->messages_manager_->on_update_read_message_comments(
DialogId(ChannelId(update->channel_id_)), MessageId(ServerMessageId(update->top_msg_id_)), MessageId(),
MessageId(), MessageId(ServerMessageId(update->read_max_id_)));
auto last_read_outbox_message_id = MessageId(ServerMessageId(update->read_max_id_));
if (!last_read_outbox_message_id.is_valid()) {
LOG(ERROR) << "Receive " << to_string(update);
return;
}
td_->messages_manager_->on_update_read_message_comments(DialogId(ChannelId(update->channel_id_)),
MessageId(ServerMessageId(update->top_msg_id_)), MessageId(),
MessageId(), last_read_outbox_message_id);
promise.set_value(Unit());
}