mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Respect global group read position in replies.
This commit is contained in:
parent
f53f934001
commit
ab429212e5
7 changed files with 43 additions and 8 deletions
|
@ -239,7 +239,7 @@ bool RepliesList::buildFromData(not_null<Viewer*> viewer) {
|
||||||
return viewer->around;
|
return viewer->around;
|
||||||
} else if (const auto item = lookupRoot()) {
|
} else if (const auto item = lookupRoot()) {
|
||||||
if (const auto original = item->lookupDiscussionPostOriginal()) {
|
if (const auto original = item->lookupDiscussionPostOriginal()) {
|
||||||
return original->commentsReadTill();
|
return original->computeCommentsReadTillFull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return viewer->around;
|
return viewer->around;
|
||||||
|
|
|
@ -1767,6 +1767,14 @@ MsgId History::loadAroundId() const {
|
||||||
return MsgId(0);
|
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 {
|
HistoryItem *History::lastAvailableMessage() const {
|
||||||
return isEmpty() ? nullptr : blocks.back()->messages.back()->data().get();
|
return isEmpty() ? nullptr : blocks.back()->messages.back()->data().get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,6 +201,8 @@ public:
|
||||||
[[nodiscard]] bool isServerSideUnread(
|
[[nodiscard]] bool isServerSideUnread(
|
||||||
not_null<const HistoryItem*> item) const;
|
not_null<const HistoryItem*> item) const;
|
||||||
[[nodiscard]] MsgId loadAroundId() const;
|
[[nodiscard]] MsgId loadAroundId() const;
|
||||||
|
[[nodiscard]] MsgId inboxReadTillId() const;
|
||||||
|
[[nodiscard]] MsgId outboxReadTillId() const;
|
||||||
|
|
||||||
[[nodiscard]] bool trackUnreadMessages() const;
|
[[nodiscard]] bool trackUnreadMessages() const;
|
||||||
[[nodiscard]] int unreadCount() const;
|
[[nodiscard]] int unreadCount() const;
|
||||||
|
|
|
@ -212,6 +212,9 @@ public:
|
||||||
}
|
}
|
||||||
virtual void setCommentsPossibleMaxId(MsgId possibleMaxId) {
|
virtual void setCommentsPossibleMaxId(MsgId possibleMaxId) {
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] virtual MsgId computeCommentsReadTillFull() const {
|
||||||
|
return MsgId(0);
|
||||||
|
}
|
||||||
[[nodiscard]] virtual bool areCommentsUnread() const {
|
[[nodiscard]] virtual bool areCommentsUnread() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
bool HistoryMessage::areCommentsUnread() const {
|
||||||
if (const auto views = Get<HistoryMessageViews>()) {
|
if (const auto views = Get<HistoryMessageViews>()) {
|
||||||
return (views->commentsReadTillId > 1)
|
if (views->commentsReadTillId < 2
|
||||||
&& (views->commentsMaxId > views->commentsReadTillId);
|
|| 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ QString GetErrorTextForSending(
|
||||||
bool ignoreSlowmodeCountdown = false);
|
bool ignoreSlowmodeCountdown = false);
|
||||||
void FastShareMessage(not_null<HistoryItem*> item);
|
void FastShareMessage(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
class HistoryMessage : public HistoryItem {
|
class HistoryMessage final : public HistoryItem {
|
||||||
public:
|
public:
|
||||||
HistoryMessage(
|
HistoryMessage(
|
||||||
not_null<History*> history,
|
not_null<History*> history,
|
||||||
|
@ -166,6 +166,7 @@ public:
|
||||||
void setCommentsReadTill(MsgId readTillId) override;
|
void setCommentsReadTill(MsgId readTillId) override;
|
||||||
void setCommentsMaxId(MsgId maxId) override;
|
void setCommentsMaxId(MsgId maxId) override;
|
||||||
void setCommentsPossibleMaxId(MsgId possibleMaxId) override;
|
void setCommentsPossibleMaxId(MsgId possibleMaxId) override;
|
||||||
|
[[nodiscard]] MsgId computeCommentsReadTillFull() const override;
|
||||||
[[nodiscard]] bool areCommentsUnread() const override;
|
[[nodiscard]] bool areCommentsUnread() const override;
|
||||||
bool updateDependencyItem() override;
|
bool updateDependencyItem() override;
|
||||||
[[nodiscard]] MsgId dependencyMsgId() const override {
|
[[nodiscard]] MsgId dependencyMsgId() const override {
|
||||||
|
|
|
@ -93,7 +93,7 @@ RepliesMemento::RepliesMemento(
|
||||||
FullMsgId(commentsItem->history()->channelId(), commentId)
|
FullMsgId(commentsItem->history()->channelId(), commentId)
|
||||||
});
|
});
|
||||||
} else if (const auto original = commentsItem->lookupDiscussionPostOriginal()) {
|
} else if (const auto original = commentsItem->lookupDiscussionPostOriginal()) {
|
||||||
if (original->commentsReadTill() == MsgId(1)) {
|
if (original->computeCommentsReadTillFull() == MsgId(1)) {
|
||||||
_list.setAroundPosition(Data::MinMessagePosition);
|
_list.setAroundPosition(Data::MinMessagePosition);
|
||||||
_list.setScrollTopState(ListMemento::ScrollTopState{
|
_list.setScrollTopState(ListMemento::ScrollTopState{
|
||||||
Data::MinMessagePosition
|
Data::MinMessagePosition
|
||||||
|
@ -241,7 +241,7 @@ void RepliesWidget::sendReadTillRequest() {
|
||||||
_readRequestId = api->request(MTPmessages_ReadDiscussion(
|
_readRequestId = api->request(MTPmessages_ReadDiscussion(
|
||||||
_commentsRoot->history()->peer->input,
|
_commentsRoot->history()->peer->input,
|
||||||
MTP_int(_commentsRoot->id),
|
MTP_int(_commentsRoot->id),
|
||||||
MTP_int(_commentsRoot->commentsReadTill())
|
MTP_int(_commentsRoot->computeCommentsReadTillFull())
|
||||||
)).done([=](const MTPBool &) {
|
)).done([=](const MTPBool &) {
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
@ -1519,7 +1519,7 @@ void RepliesWidget::readTill(not_null<HistoryItem*> item) {
|
||||||
if (!_commentsRoot) {
|
if (!_commentsRoot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto was = _commentsRoot->commentsReadTill();
|
const auto was = _commentsRoot->computeCommentsReadTillFull();
|
||||||
const auto now = item->id;
|
const auto now = item->id;
|
||||||
const auto fast = item->out();
|
const auto fast = item->out();
|
||||||
if (was < now) {
|
if (was < now) {
|
||||||
|
@ -1547,7 +1547,7 @@ MessagesBarData RepliesWidget::listMessagesBar(
|
||||||
if (!_commentsRoot || elements.empty()) {
|
if (!_commentsRoot || elements.empty()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const auto till = _commentsRoot->commentsReadTill();
|
const auto till = _commentsRoot->computeCommentsReadTillFull();
|
||||||
if (till < 2) {
|
if (till < 2) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue