From 71690cacc1cf82173f04fec192a9e6796dd36eff Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 21 Jan 2020 14:31:26 -0600 Subject: [PATCH] forum: fix topics being incorrectly marked as unread. This happened when the user marked all topics as read and so didn't have any forum topic visits. The OR clause wasn't handled correctly for this case. --- app/models/forum_topic.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index b34f28c2e..57916e0a4 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -59,7 +59,11 @@ class ForumTopic < ApplicationRecord def read_by_user(user) return none if user.last_forum_read_at.nil? || user.last_forum_read_at < '2000-01-01' - merge(user.visited_forum_topics.where("forum_topic_visits.last_read_at >= forum_topics.updated_at OR ? >= forum_topics.updated_at", user.last_forum_read_at)) + + read_topics = user.visited_forum_topics.where("forum_topic_visits.last_read_at >= forum_topics.updated_at") + old_topics = where("? >= forum_topics.updated_at", user.last_forum_read_at) + + where(id: read_topics).or(where(id: old_topics)) end def sticky_first