Fir readin histoyr delay.

GitOrigin-RevId: 816dde71f13aefa00750ab9cb4baea455de40c9d
This commit is contained in:
levlam 2020-03-08 02:32:24 +03:00
parent 5ae8f3bc43
commit c04ae16bda

View File

@ -14955,6 +14955,8 @@ DialogId MessagesManager::get_my_dialog_id() const {
}
Status MessagesManager::view_messages(DialogId dialog_id, const vector<MessageId> &message_ids, bool force_read) {
CHECK(!td_->auth_manager_->is_bot());
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
return Status::Error(3, "Chat not found");
@ -15014,18 +15016,28 @@ Status MessagesManager::view_messages(DialogId dialog_id, const vector<MessageId
if (need_read && max_message_id > d->last_read_inbox_message_id) {
MessageId last_read_message_id = max_message_id;
MessageId prev_last_read_inbox_message_id = d->last_read_inbox_message_id;
MessageId read_history_on_server_message_id;
if (dialog_id.get_type() != DialogType::SecretChat) {
if (last_read_message_id.get_prev_server_message_id().get() >
prev_last_read_inbox_message_id.get_prev_server_message_id().get()) {
read_history_on_server(d, last_read_message_id.get_prev_server_message_id());
read_history_on_server_message_id = last_read_message_id.get_prev_server_message_id();
}
} else {
if (last_read_message_id > prev_last_read_inbox_message_id) {
read_history_on_server(d, last_read_message_id);
read_history_on_server_message_id = last_read_message_id;
}
}
// read history on server after sending server request to not repair unread_count early
if (read_history_on_server_message_id.is_valid()) {
// add dummy timeout to not try to repair unread_count in read_history_inbox before server request succeeds
// the timeout will be overwritten in the read_history_on_server call
pending_read_history_timeout_.add_timeout_in(dialog_id.get(), 0);
}
read_history_inbox(d->dialog_id, last_read_message_id, -1, "view_messages");
if (read_history_on_server_message_id.is_valid()) {
// call read_history_on_server after read_history_inbox to not have delay before request if all messages are read
read_history_on_server(d, read_history_on_server_message_id);
}
}
if (need_read && d->is_marked_as_unread) {
set_dialog_is_marked_as_unread(d, false);