diff --git a/Gemfile.lock b/Gemfile.lock index 7b7a673096b..03e64adeb19 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,7 +16,7 @@ GIT GIT remote: https://github.com/SamSaffron/message_bus - revision: 031a107bbe6e468caa67ff540485d70230d1c362 + revision: f55b41653d0c149938ebb803a97d946e5ae80439 specs: message_bus (0.0.2) eventmachine diff --git a/app/assets/javascripts/discourse/models/user_tracking_state.js b/app/assets/javascripts/discourse/models/user_tracking_state.js new file mode 100644 index 00000000000..5843d12503d --- /dev/null +++ b/app/assets/javascripts/discourse/models/user_tracking_state.js @@ -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){ + + } +}); diff --git a/app/models/user.rb b/app/models/user.rb index 28467c99427..02f84a31ef3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -576,6 +576,10 @@ class User < ActiveRecord::Base end end + def user_tracking_states + UserTrackingState.report([self.id]) + end + protected def cook diff --git a/app/models/user_tracking_state.rb b/app/models/user_tracking_state.rb index f25f68b8793..50c8f8fce56 100644 --- a/app/models/user_tracking_state.rb +++ b/app/models/user_tracking_state.rb @@ -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 = < 'private_message' AND ((#{unread}) OR (#{new})) AND diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index e19d6bc77bd..dd4747116f9 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -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? diff --git a/app/serializers/user_tracking_state_serializer.rb b/app/serializers/user_tracking_state_serializer.rb new file mode 100644 index 00000000000..1abd7c08b8e --- /dev/null +++ b/app/serializers/user_tracking_state_serializer.rb @@ -0,0 +1,3 @@ +class UserTrackingStateSerializer < ApplicationSerializer + attributes :topic_id, :highest_post_number, :last_read_post_number, :created_at, :category_name +end