FIX: Unread group PMs should use GroupUser#first_unread_pm_at. (#14075)

This bug was causing unread PMs for groups to appear inaccurate.
This commit is contained in:
Alan Guo Xiang Tan
2021-08-18 11:23:28 +08:00
committed by GitHub
parent 3d92555f7a
commit d13716286c
2 changed files with 36 additions and 8 deletions

View File

@@ -182,9 +182,23 @@ class TopicQuery
staff: user.staff?
)
first_unread_pm_at = UserStat
.where(user_id: user.id)
.pluck_first(:first_unread_pm_at)
first_unread_pm_at =
case type
when :user
user_first_unread_pm_at(user)
when :group
GroupUser
.where(user: user, group: group)
.pluck_first(:first_unread_pm_at)
else
user_first_unread_pm_at = user_first_unread_pm_at(user)
group_first_unread_pm_at = GroupUser
.where(user: user)
.minimum(:first_unread_pm_at)
[user_first_unread_pm_at, group_first_unread_pm_at].compact.min
end
if first_unread_pm_at
list = list.where("topics.updated_at >= ?", first_unread_pm_at)
@@ -246,5 +260,9 @@ class TopicQuery
.first
end
end
def user_first_unread_pm_at(user)
UserStat.where(user: user).pluck_first(:first_unread_pm_at)
end
end
end