read state is now published
This commit is contained in:
parent
8874c9ea75
commit
6ad86aa305
|
@ -17,7 +17,7 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
|
||||||
tracker.removeTopic(data.topic_id);
|
tracker.removeTopic(data.topic_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.message_type === "new_topic" || data.message_type === "unread") {
|
if (data.message_type === "new_topic" || data.message_type === "unread" || data.message_type == "read") {
|
||||||
tracker.states["t" + data.topic_id] = data.payload;
|
tracker.states["t" + data.topic_id] = data.payload;
|
||||||
tracker.notify(data);
|
tracker.notify(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,21 @@ class TopicTrackingState
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.publish_read(topic_id, highest_post_number, user_id)
|
def self.publish_read(topic_id, last_read_post_number, user_id)
|
||||||
|
|
||||||
|
highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first
|
||||||
|
|
||||||
|
message = {
|
||||||
|
topic_id: topic_id,
|
||||||
|
message_type: "read",
|
||||||
|
payload: {
|
||||||
|
last_read_post_number: last_read_post_number,
|
||||||
|
highest_post_number: highest_post_number,
|
||||||
|
topic_id: topic_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBus.publish("/unread/#{user_id}", message.as_json, user_ids: [user_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.treat_as_new_topic_clause
|
def self.treat_as_new_topic_clause
|
||||||
|
|
|
@ -156,7 +156,7 @@ class TopicUser < ActiveRecord::Base
|
||||||
tu.topic_id = :topic_id AND
|
tu.topic_id = :topic_id AND
|
||||||
tu.user_id = :user_id
|
tu.user_id = :user_id
|
||||||
RETURNING
|
RETURNING
|
||||||
topic_users.notification_level, tu.notification_level old_level
|
topic_users.notification_level, tu.notification_level old_level, tu.last_read_post_number
|
||||||
",
|
",
|
||||||
args).values
|
args).values
|
||||||
|
|
||||||
|
@ -164,12 +164,20 @@ class TopicUser < ActiveRecord::Base
|
||||||
before = rows[0][1].to_i
|
before = rows[0][1].to_i
|
||||||
after = rows[0][0].to_i
|
after = rows[0][0].to_i
|
||||||
|
|
||||||
|
before_last_read = rows[0][2].to_i
|
||||||
|
|
||||||
|
if before_last_read < post_number
|
||||||
|
TopicTrackingState.publish_read(topic_id, post_number, user.id)
|
||||||
|
end
|
||||||
|
|
||||||
if before != after
|
if before != after
|
||||||
MessageBus.publish("/topic/#{topic_id}", {notification_level_change: after}, user_ids: [user.id])
|
MessageBus.publish("/topic/#{topic_id}", {notification_level_change: after}, user_ids: [user.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if rows.length == 0
|
if rows.length == 0
|
||||||
|
TopicTrackingState.publish_read(topic_id, post_number, user.id)
|
||||||
|
|
||||||
args[:tracking] = notification_levels[:tracking]
|
args[:tracking] = notification_levels[:tracking]
|
||||||
args[:regular] = notification_levels[:regular]
|
args[:regular] = notification_levels[:regular]
|
||||||
args[:site_setting] = SiteSetting.auto_track_topics_after
|
args[:site_setting] = SiteSetting.auto_track_topics_after
|
||||||
|
|
Loading…
Reference in New Issue