FEATURE: update likes and flags live.

This commit is contained in:
Sam 2014-03-24 13:22:03 +11:00
parent 090f5c99c2
commit 1cd32ced33
3 changed files with 21 additions and 1 deletions

View File

@ -361,7 +361,9 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
}
var postStream = topicController.get('postStream');
if (data.type === "revised"){
if (data.type === "revised" || data.type === "acted"){
// TODO we could update less data for "acted"
// (only post actions)
postStream.triggerChangedPost(data.id, data.updated_at);
return;
}

View File

@ -212,6 +212,10 @@ class PostsController < ApplicationController
def render_post_json(post)
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
post_serializer.add_raw = true
counts = PostAction.counts_for([post], current_user)
if counts && counts = counts[post.id]
post_serializer.post_actions = counts
end
render_json_dump(post_serializer)
end

View File

@ -20,6 +20,7 @@ class PostAction < ActiveRecord::Base
after_save :update_counters
after_save :enforce_rules
after_save :notify_subscribers
def self.update_flagged_posts_count
posts_flagged_count = PostAction.joins(post: :topic)
@ -136,6 +137,7 @@ class PostAction < ActiveRecord::Base
staff_took_action: opts[:take_action] || false,
related_post_id: related_post_id,
targets_topic: !!targets_topic )
rescue ActiveRecord::RecordNotUnique
# can happen despite being .create
# since already bookmarked
@ -259,6 +261,18 @@ class PostAction < ActiveRecord::Base
SpamRulesEnforcer.enforce!(post.user) if post_action_type_key == :spam
end
def notify_subscribers
if (is_like? || is_flag?) && post
MessageBus.publish("/topic/#{post.topic_id}",{
id: post.id,
post_number: post.post_number,
type: "acted"
},
group_ids: post.topic.secure_group_ids
)
end
end
def self.auto_hide_if_needed(post, post_action_type)
return if post.hidden