From a3f19c073bf642e9ce1449056d5dbba9767c8428 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Feb 2020 13:37:00 +0400 Subject: [PATCH] Fix 'reading' of an empty history. --- Telegram/SourceFiles/data/data_histories.cpp | 6 +++++- Telegram/SourceFiles/history/history.cpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/data/data_histories.cpp b/Telegram/SourceFiles/data/data_histories.cpp index c3e945da5..f3516d2ca 100644 --- a/Telegram/SourceFiles/data/data_histories.cpp +++ b/Telegram/SourceFiles/data/data_histories.cpp @@ -131,6 +131,8 @@ void Histories::readInboxTill( not_null history, MsgId tillId, bool force) { + Expects(IsServerMsgId(tillId) || (!tillId && !force)); + if (!history->readInboxTillNeedsRequest(tillId) && !force) { return; } else if (!force) { @@ -202,7 +204,9 @@ void Histories::sendReadRequests() { const auto now = crl::now(); auto next = std::optional(); for (auto &[history, state] : _states) { - if (state.readTill && state.readWhen <= now) { + if (!state.readTill) { + continue; + } else if (state.readWhen <= now) { sendReadRequest(history, state); } else if (!next || *next > state.readWhen) { next = state.readWhen; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index c225d8cb8..d0c953fe3 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1615,13 +1615,13 @@ void History::calculateFirstUnreadMessage() { } bool History::readInboxTillNeedsRequest(MsgId tillId) { - Expects(IsServerMsgId(tillId)); + Expects(!tillId || IsServerMsgId(tillId)); readClientSideMessages(); if (unreadMark()) { session().api().changeDialogUnreadMark(this, false); } - return (_inboxReadBefore.value_or(1) <= tillId); + return IsServerMsgId(tillId) && (_inboxReadBefore.value_or(1) <= tillId); } void History::readClientSideMessages() {