work in progress, live unread / new counters

This commit is contained in:
Sam 2013-05-24 20:58:26 +10:00
parent 52eeecd460
commit 33ff87bf44
6 changed files with 31 additions and 4 deletions

View File

@ -16,7 +16,7 @@ GIT
GIT
remote: https://github.com/SamSaffron/message_bus
revision: 031a107bbe6e468caa67ff540485d70230d1c362
revision: f55b41653d0c149938ebb803a97d946e5ae80439
specs:
message_bus (0.0.2)
eventmachine

View File

@ -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){
}
});

View File

@ -576,6 +576,10 @@ class User < ActiveRecord::Base
end
end
def user_tracking_states
UserTrackingState.report([self.id])
end
protected
def cook

View File

@ -5,9 +5,11 @@
class UserTrackingState
include ActiveModel::SerializerSupport
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|
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)
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
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 categories c ON c.id = topics.id
LEFT JOIN categories c ON c.id = topics.category_id
WHERE u.id IN (:user_ids) AND
topics.archetype <> 'private_message' AND
((#{unread}) OR (#{new})) AND

View File

@ -14,6 +14,8 @@ class CurrentUserSerializer < BasicUserSerializer
:external_links_in_new_tab,
: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
def include_site_flagged_posts_count?

View File

@ -0,0 +1,3 @@
class UserTrackingStateSerializer < ApplicationSerializer
attributes :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name
end