From f1486c772857138529dcfd2e2d0d9ad54209be47 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 18 Aug 2014 16:15:26 -0400 Subject: [PATCH] FIX: Inconsistency between unread counter and unread filter --- .../discourse/models/topic_tracking_state.js | 2 ++ app/serializers/listable_topic_serializer.rb | 10 +++++++++- lib/topic_query.rb | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/models/topic_tracking_state.js b/app/assets/javascripts/discourse/models/topic_tracking_state.js index d47a06115..b98901afe 100644 --- a/app/assets/javascripts/discourse/models/topic_tracking_state.js +++ b/app/assets/javascripts/discourse/models/topic_tracking_state.js @@ -157,6 +157,8 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ list.topics.forEach(function(topic){ var row = tracker.states["t" + topic.id] || {}; row.topic_id = topic.id; + row.notification_level = topic.notification_level; + if (topic.unseen) { row.last_read_post_number = null; diff --git a/app/serializers/listable_topic_serializer.rb b/app/serializers/listable_topic_serializer.rb index 713ca6327..b89c05aea 100644 --- a/app/serializers/listable_topic_serializer.rb +++ b/app/serializers/listable_topic_serializer.rb @@ -18,7 +18,8 @@ class ListableTopicSerializer < BasicTopicSerializer :excerpt, :visible, :closed, - :archived + :archived, + :notification_level has_one :last_poster, serializer: BasicUserSerializer, embed: :objects def include_last_poster? @@ -40,6 +41,13 @@ class ListableTopicSerializer < BasicTopicSerializer !seen end + def notification_level + object.user_data.notification_level + end + def include_notification_level? + object.user_data.present? + end + def last_read_post_number return nil unless object.user_data object.user_data.last_read_post_number diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 02160c3b0..29e550701 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -147,7 +147,7 @@ class TopicQuery end def self.unread_filter(list) - list.where("tu.last_read_post_number < topics.highest_post_number") + list.where("tu.seen_post_count < topics.highest_post_number") .where("COALESCE(tu.notification_level, :regular) >= :tracking", regular: TopicUser.notification_levels[:regular], tracking: TopicUser.notification_levels[:tracking]) end