From 9267c162a1f8818cfc12c5f16c6a85b55cfdf70b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 26 Feb 2014 15:37:42 -0500 Subject: [PATCH] FIX: Showing Unread(1) when you weren't tracking the topic. Also includes performance fix when having MANY new or unread topics. --- .../discourse/models/topic_tracking_state.js | 22 ++----------------- app/models/topic_tracking_state.rb | 22 +++++++++++++++---- app/models/topic_user.rb | 14 ++++++------ .../topic_tracking_state_serializer.rb | 2 +- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/discourse/models/topic_tracking_state.js b/app/assets/javascripts/discourse/models/topic_tracking_state.js index d6b45d073ab..5cb6ac2dc69 100644 --- a/app/assets/javascripts/discourse/models/topic_tracking_state.js +++ b/app/assets/javascripts/discourse/models/topic_tracking_state.js @@ -103,26 +103,8 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ } } - if(filter === "new" && !list.more_topics_url){ - // scrub all new rows and reload from list - _.each(this.states, function(state){ - if(state.last_read_post_number === null) { - tracker.removeTopic(state.topic_id); - } - }); - } - - if(filter === "unread" && !list.more_topics_url){ - // scrub all new rows and reload from list - _.each(this.states, function(state){ - if(state.last_read_post_number !== null) { - tracker.removeTopic(state.topic_id); - } - }); - } - _.each(list.topics, function(topic){ - var row = {}; + var row = tracker.states["t" + topic.id] || {}; row.topic_id = topic.id; if(topic.unseen) { @@ -142,7 +124,6 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ } tracker.states["t" + topic.id] = row; - }); this.incrementMessageCount(); @@ -166,6 +147,7 @@ Discourse.TopicTrackingState = Discourse.Model.extend({ return topic.last_read_post_number !== null && topic.last_read_post_number < topic.highest_post_number; }) + .where(function(topic) { return topic.notification_level >= Discourse.Topic.NotificationLevel.TRACKING}) .where(function(topic){ return topic.category_name === category_name || !category_name;}) .value() .length; diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index c8386b802b0..da7de329fb1 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -9,7 +9,13 @@ class TopicTrackingState CHANNEL = "/user-tracking" - attr_accessor :user_id, :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name + attr_accessor :user_id, + :topic_id, + :highest_post_number, + :last_read_post_number, + :created_at, + :category_name, + :notification_level def self.publish_new(topic) @@ -57,7 +63,7 @@ class TopicTrackingState end - def self.publish_read(topic_id, last_read_post_number, user_id) + def self.publish_read(topic_id, last_read_post_number, user_id, notification_level=nil) highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first @@ -67,7 +73,8 @@ class TopicTrackingState payload: { last_read_post_number: last_read_post_number, highest_post_number: highest_post_number, - topic_id: topic_id + topic_id: topic_id, + notification_level: notification_level } } @@ -104,7 +111,13 @@ class TopicTrackingState new = TopicQuery.new_filter(Topic, "xxx").where_values.join(" AND ").gsub!("'xxx'", treat_as_new_topic_clause) sql = <