mirror of
https://github.com/discourse/discourse.git
synced 2025-04-24 06:04:27 +08:00
FIX: Showing Unread(1) when you weren't tracking the topic. Also
includes performance fix when having MANY new or unread topics.
This commit is contained in:
parent
1c51a613b2
commit
9267c162a1
app
assets/javascripts/discourse/models
models
serializers
@ -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){
|
_.each(list.topics, function(topic){
|
||||||
var row = {};
|
var row = tracker.states["t" + topic.id] || {};
|
||||||
|
|
||||||
row.topic_id = topic.id;
|
row.topic_id = topic.id;
|
||||||
if(topic.unseen) {
|
if(topic.unseen) {
|
||||||
@ -142,7 +124,6 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
tracker.states["t" + topic.id] = row;
|
tracker.states["t" + topic.id] = row;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.incrementMessageCount();
|
this.incrementMessageCount();
|
||||||
@ -166,6 +147,7 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
|
|||||||
return topic.last_read_post_number !== null &&
|
return topic.last_read_post_number !== null &&
|
||||||
topic.last_read_post_number < topic.highest_post_number;
|
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;})
|
.where(function(topic){ return topic.category_name === category_name || !category_name;})
|
||||||
.value()
|
.value()
|
||||||
.length;
|
.length;
|
||||||
|
@ -9,7 +9,13 @@ class TopicTrackingState
|
|||||||
|
|
||||||
CHANNEL = "/user-tracking"
|
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)
|
def self.publish_new(topic)
|
||||||
|
|
||||||
@ -57,7 +63,7 @@ class TopicTrackingState
|
|||||||
|
|
||||||
end
|
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
|
highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first
|
||||||
|
|
||||||
@ -67,7 +73,8 @@ class TopicTrackingState
|
|||||||
payload: {
|
payload: {
|
||||||
last_read_post_number: last_read_post_number,
|
last_read_post_number: last_read_post_number,
|
||||||
highest_post_number: highest_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)
|
new = TopicQuery.new_filter(Topic, "xxx").where_values.join(" AND ").gsub!("'xxx'", treat_as_new_topic_clause)
|
||||||
|
|
||||||
sql = <<SQL
|
sql = <<SQL
|
||||||
SELECT u.id AS user_id, topics.id AS topic_id, topics.created_at, highest_post_number, last_read_post_number, c.name AS category_name
|
SELECT u.id AS user_id,
|
||||||
|
topics.id AS topic_id,
|
||||||
|
topics.created_at,
|
||||||
|
highest_post_number,
|
||||||
|
last_read_post_number,
|
||||||
|
c.name AS category_name,
|
||||||
|
tu.notification_level
|
||||||
FROM users u
|
FROM users u
|
||||||
FULL OUTER JOIN topics ON 1=1
|
FULL OUTER JOIN topics ON 1=1
|
||||||
LEFT JOIN topic_users tu ON tu.topic_id = topics.id AND tu.user_id = u.id
|
LEFT JOIN topic_users tu ON tu.topic_id = topics.id AND tu.user_id = u.id
|
||||||
@ -126,6 +139,7 @@ SQL
|
|||||||
if topic_id
|
if topic_id
|
||||||
sql << " AND topics.id = :topic_id"
|
sql << " AND topics.id = :topic_id"
|
||||||
end
|
end
|
||||||
|
sql << " ORDER BY topics.bumped_at DESC LIMIT 500"
|
||||||
|
|
||||||
SqlBuilder.new(sql)
|
SqlBuilder.new(sql)
|
||||||
.map_exec(TopicTrackingState, user_ids: user_ids, topic_id: topic_id)
|
.map_exec(TopicTrackingState, user_ids: user_ids, topic_id: topic_id)
|
||||||
|
@ -183,7 +183,7 @@ class TopicUser < ActiveRecord::Base
|
|||||||
|
|
||||||
if before_last_read < post_number
|
if before_last_read < post_number
|
||||||
# The user read at least one new post
|
# The user read at least one new post
|
||||||
TopicTrackingState.publish_read(topic_id, post_number, user.id)
|
TopicTrackingState.publish_read(topic_id, post_number, user.id, after)
|
||||||
user.update_posts_read!(post_number - before_last_read)
|
user.update_posts_read!(post_number - before_last_read)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -194,15 +194,15 @@ class TopicUser < ActiveRecord::Base
|
|||||||
|
|
||||||
if rows.length == 0
|
if rows.length == 0
|
||||||
# The user read at least one post in a topic that they haven't viewed before.
|
# The user read at least one post in a topic that they haven't viewed before.
|
||||||
TopicTrackingState.publish_read(topic_id, post_number, user.id)
|
args[:new_status] = notification_levels[:regular]
|
||||||
|
if (user.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after) == 0
|
||||||
|
args[:new_status] = notification_levels[:tracking]
|
||||||
|
end
|
||||||
|
TopicTrackingState.publish_read(topic_id, post_number, user.id, args[:new_status])
|
||||||
user.update_posts_read!(post_number)
|
user.update_posts_read!(post_number)
|
||||||
|
|
||||||
args[:tracking] = notification_levels[:tracking]
|
|
||||||
args[:regular] = notification_levels[:regular]
|
|
||||||
args[:site_setting] = SiteSetting.auto_track_topics_after
|
|
||||||
exec_sql("INSERT INTO topic_users (user_id, topic_id, last_read_post_number, seen_post_count, last_visited_at, first_visited_at, notification_level)
|
exec_sql("INSERT INTO topic_users (user_id, topic_id, last_read_post_number, seen_post_count, last_visited_at, first_visited_at, notification_level)
|
||||||
SELECT :user_id, :topic_id, :post_number, ft.highest_post_number, :now, :now,
|
SELECT :user_id, :topic_id, :post_number, ft.highest_post_number, :now, :now, :new_status
|
||||||
case when coalesce(u.auto_track_topics_after_msecs, :site_setting) = 0 then :tracking else :regular end
|
|
||||||
FROM topics AS ft
|
FROM topics AS ft
|
||||||
JOIN users u on u.id = :user_id
|
JOIN users u on u.id = :user_id
|
||||||
WHERE ft.id = :topic_id
|
WHERE ft.id = :topic_id
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
class TopicTrackingStateSerializer < ApplicationSerializer
|
class TopicTrackingStateSerializer < ApplicationSerializer
|
||||||
attributes :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name
|
attributes :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name, :notification_level
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user