From 40e925d3f96e6250a8db2db93d5436e28945ec8a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 15 Sep 2020 14:47:26 +0300 Subject: [PATCH] Remove redundant read comments thread requests. --- .../history/view/history_view_replies_section.cpp | 10 ++++++++-- .../history/view/history_view_replies_section.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index f6b7bd864..5c900e8d1 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -218,11 +218,13 @@ RepliesWidget::~RepliesWidget() { void RepliesWidget::sendReadTillRequest() { if (!_commentsRoot) { + _readRequestPending = true; return; } if (_readRequestTimer.isActive()) { _readRequestTimer.cancel(); } + _readRequestPending = false; const auto api = &_history->session().api(); api->request(base::take(_readRequestId)).cancel(); _readRequestId = api->request(MTPmessages_ReadDiscussion( @@ -258,14 +260,18 @@ void RepliesWidget::setupCommentsRoot() { if (!postChannel) { return; } else if (_commentsRoot) { - sendReadTillRequest(); + if (_readRequestTimer.isActive() || _readRequestPending) { + sendReadTillRequest(); + } } else { const auto forwarded = _root->Get(); const auto messageId = forwarded->savedFromMsgId; const auto done = crl::guard(this, [=](ChannelData*, MsgId) { _commentsRoot = lookupCommentsRoot(); if (_commentsRoot) { - sendReadTillRequest(); + if (_readRequestTimer.isActive() || _readRequestPending) { + sendReadTillRequest(); + } } }); _history->session().api().requestMessageData( diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index 82459de55..c073509b3 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -257,6 +257,7 @@ private: bool _choosingAttach = false; base::Timer _readRequestTimer; + bool _readRequestPending = false; mtpRequestId _readRequestId = 0; };