Respect global group read position in replies.

This commit is contained in:
John Preston 2020-09-18 14:52:44 +03:00
parent f53f934001
commit ab429212e5
7 changed files with 43 additions and 8 deletions

View File

@ -239,7 +239,7 @@ bool RepliesList::buildFromData(not_null<Viewer*> viewer) {
return viewer->around;
} else if (const auto item = lookupRoot()) {
if (const auto original = item->lookupDiscussionPostOriginal()) {
return original->commentsReadTill();
return original->computeCommentsReadTillFull();
}
}
return viewer->around;

View File

@ -1767,6 +1767,14 @@ MsgId History::loadAroundId() const {
return MsgId(0);
}
MsgId History::inboxReadTillId() const {
return _inboxReadBefore.value_or(1) - 1;
}
MsgId History::outboxReadTillId() const {
return _outboxReadBefore.value_or(1) - 1;
}
HistoryItem *History::lastAvailableMessage() const {
return isEmpty() ? nullptr : blocks.back()->messages.back()->data().get();
}

View File

@ -201,6 +201,8 @@ public:
[[nodiscard]] bool isServerSideUnread(
not_null<const HistoryItem*> item) const;
[[nodiscard]] MsgId loadAroundId() const;
[[nodiscard]] MsgId inboxReadTillId() const;
[[nodiscard]] MsgId outboxReadTillId() const;
[[nodiscard]] bool trackUnreadMessages() const;
[[nodiscard]] int unreadCount() const;

View File

@ -212,6 +212,9 @@ public:
}
virtual void setCommentsPossibleMaxId(MsgId possibleMaxId) {
}
[[nodiscard]] virtual MsgId computeCommentsReadTillFull() const {
return MsgId(0);
}
[[nodiscard]] virtual bool areCommentsUnread() const {
return false;
}

View File

@ -856,10 +856,31 @@ void HistoryMessage::setCommentsPossibleMaxId(MsgId possibleMaxId) {
}
}
MsgId HistoryMessage::computeCommentsReadTillFull() const {
const auto local = commentsReadTill();
const auto views = Get<HistoryMessageViews>();
if (!views || !views->commentsChannelId) {
return local;
}
const auto group = history()->owner().historyLoaded(
peerFromChannel(views->commentsChannelId));
if (!group) {
return local;
}
return std::max(local, group->inboxReadTillId());
}
bool HistoryMessage::areCommentsUnread() const {
if (const auto views = Get<HistoryMessageViews>()) {
return (views->commentsReadTillId > 1)
&& (views->commentsMaxId > views->commentsReadTillId);
if (views->commentsReadTillId < 2
|| views->commentsMaxId <= views->commentsReadTillId) {
return false;
} else if (!views->commentsChannelId) {
return true;
}
const auto group = history()->owner().historyLoaded(
peerFromChannel(views->commentsChannelId));
return !group || (views->commentsMaxId > group->inboxReadTillId());
}
return false;
}

View File

@ -37,7 +37,7 @@ QString GetErrorTextForSending(
bool ignoreSlowmodeCountdown = false);
void FastShareMessage(not_null<HistoryItem*> item);
class HistoryMessage : public HistoryItem {
class HistoryMessage final : public HistoryItem {
public:
HistoryMessage(
not_null<History*> history,
@ -166,6 +166,7 @@ public:
void setCommentsReadTill(MsgId readTillId) override;
void setCommentsMaxId(MsgId maxId) override;
void setCommentsPossibleMaxId(MsgId possibleMaxId) override;
[[nodiscard]] MsgId computeCommentsReadTillFull() const override;
[[nodiscard]] bool areCommentsUnread() const override;
bool updateDependencyItem() override;
[[nodiscard]] MsgId dependencyMsgId() const override {

View File

@ -93,7 +93,7 @@ RepliesMemento::RepliesMemento(
FullMsgId(commentsItem->history()->channelId(), commentId)
});
} else if (const auto original = commentsItem->lookupDiscussionPostOriginal()) {
if (original->commentsReadTill() == MsgId(1)) {
if (original->computeCommentsReadTillFull() == MsgId(1)) {
_list.setAroundPosition(Data::MinMessagePosition);
_list.setScrollTopState(ListMemento::ScrollTopState{
Data::MinMessagePosition
@ -241,7 +241,7 @@ void RepliesWidget::sendReadTillRequest() {
_readRequestId = api->request(MTPmessages_ReadDiscussion(
_commentsRoot->history()->peer->input,
MTP_int(_commentsRoot->id),
MTP_int(_commentsRoot->commentsReadTill())
MTP_int(_commentsRoot->computeCommentsReadTillFull())
)).done([=](const MTPBool &) {
}).send();
}
@ -1519,7 +1519,7 @@ void RepliesWidget::readTill(not_null<HistoryItem*> item) {
if (!_commentsRoot) {
return;
}
const auto was = _commentsRoot->commentsReadTill();
const auto was = _commentsRoot->computeCommentsReadTillFull();
const auto now = item->id;
const auto fast = item->out();
if (was < now) {
@ -1547,7 +1547,7 @@ MessagesBarData RepliesWidget::listMessagesBar(
if (!_commentsRoot || elements.empty()) {
return {};
}
const auto till = _commentsRoot->commentsReadTill();
const auto till = _commentsRoot->computeCommentsReadTillFull();
if (till < 2) {
return {};
}