mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 03:35:43 +08:00
work in progress, live unread / new counters
This commit is contained in:
parent
52eeecd460
commit
33ff87bf44
@ -16,7 +16,7 @@ GIT
|
|||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/SamSaffron/message_bus
|
remote: https://github.com/SamSaffron/message_bus
|
||||||
revision: 031a107bbe6e468caa67ff540485d70230d1c362
|
revision: f55b41653d0c149938ebb803a97d946e5ae80439
|
||||||
specs:
|
specs:
|
||||||
message_bus (0.0.2)
|
message_bus (0.0.2)
|
||||||
eventmachine
|
eventmachine
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
Discourse.UserTrackingState = Discourse.Model.extend({
|
||||||
|
unreadPosts: function(){
|
||||||
|
return 10;
|
||||||
|
}.property(),
|
||||||
|
|
||||||
|
newPosts: function() {
|
||||||
|
return 10;
|
||||||
|
}.property()
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Discourse.UserTrackingState.reopenClass({
|
||||||
|
init: function(data){
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
@ -576,6 +576,10 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_tracking_states
|
||||||
|
UserTrackingState.report([self.id])
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def cook
|
def cook
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
class UserTrackingState
|
class UserTrackingState
|
||||||
|
|
||||||
|
include ActiveModel::SerializerSupport
|
||||||
|
|
||||||
CHANNEL = "/user-tracking"
|
CHANNEL = "/user-tracking"
|
||||||
|
|
||||||
attr_accessor :user_id, :topic_id, :highest_post_number, :last_read_post_number, :created_at
|
attr_accessor :user_id, :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name
|
||||||
|
|
||||||
MessageBus.client_filter(CHANNEL) do |user_id, message|
|
MessageBus.client_filter(CHANNEL) do |user_id, message|
|
||||||
if user_id
|
if user_id
|
||||||
@ -50,11 +52,11 @@ class UserTrackingState
|
|||||||
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
|
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
|
||||||
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
|
||||||
LEFT JOIN categories c ON c.id = topics.id
|
LEFT JOIN categories c ON c.id = topics.category_id
|
||||||
WHERE u.id IN (:user_ids) AND
|
WHERE u.id IN (:user_ids) AND
|
||||||
topics.archetype <> 'private_message' AND
|
topics.archetype <> 'private_message' AND
|
||||||
((#{unread}) OR (#{new})) AND
|
((#{unread}) OR (#{new})) AND
|
||||||
|
@ -14,6 +14,8 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
:external_links_in_new_tab,
|
:external_links_in_new_tab,
|
||||||
:trust_level
|
:trust_level
|
||||||
|
|
||||||
|
has_many :user_tracking_states, serializer: UserTrackingStateSerializer, embed: :objects
|
||||||
|
|
||||||
# we probably want to move this into site, but that json is cached so hanging it off current user seems okish
|
# we probably want to move this into site, but that json is cached so hanging it off current user seems okish
|
||||||
|
|
||||||
def include_site_flagged_posts_count?
|
def include_site_flagged_posts_count?
|
||||||
|
3
app/serializers/user_tracking_state_serializer.rb
Normal file
3
app/serializers/user_tracking_state_serializer.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class UserTrackingStateSerializer < ApplicationSerializer
|
||||||
|
attributes :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user