Remove redundant read comments thread requests.

This commit is contained in:
John Preston 2020-09-15 14:47:26 +03:00
parent 808e8dcf4f
commit 40e925d3f9
2 changed files with 9 additions and 2 deletions

View File

@ -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<HistoryMessageForwarded>();
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(

View File

@ -257,6 +257,7 @@ private:
bool _choosingAttach = false;
base::Timer _readRequestTimer;
bool _readRequestPending = false;
mtpRequestId _readRequestId = 0;
};