1
0
mirror of https://github.com/flarum/core.git synced 2025-07-17 06:41:21 +02:00

Fix discussion unreadCount could be higher than commentCount (#2195)

* Fix discussion unreadCount being higher than commentCount if posts have been deleted
This commit is contained in:
w-4
2020-06-20 21:18:26 +07:00
committed by GitHub
parent f14da4b159
commit 395ee845ae

View File

@@ -68,7 +68,10 @@ Object.assign(Discussion.prototype, {
const user = app.session.user;
if (user && user.markedAllAsReadAt() < this.lastPostedAt()) {
return Math.max(0, this.lastPostNumber() - (this.lastReadPostNumber() || 0));
const unreadCount = Math.max(0, this.lastPostNumber() - (this.lastReadPostNumber() || 0));
// If posts have been deleted, it's possible that the unread count could exceed the
// actual post count. As such, we take the min of the two to ensure this isn't an issue.
return Math.min(unreadCount, this.commentCount());
}
return 0;