mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
committed by
GitHub
parent
3d92555f7a
commit
d13716286c
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user