FEATURE: update likes and flags live.
This commit is contained in:
parent
090f5c99c2
commit
1cd32ced33
|
@ -361,7 +361,9 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
||||||
}
|
}
|
||||||
|
|
||||||
var postStream = topicController.get('postStream');
|
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);
|
postStream.triggerChangedPost(data.id, data.updated_at);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,6 +212,10 @@ class PostsController < ApplicationController
|
||||||
def render_post_json(post)
|
def render_post_json(post)
|
||||||
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
||||||
post_serializer.add_raw = true
|
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)
|
render_json_dump(post_serializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ class PostAction < ActiveRecord::Base
|
||||||
|
|
||||||
after_save :update_counters
|
after_save :update_counters
|
||||||
after_save :enforce_rules
|
after_save :enforce_rules
|
||||||
|
after_save :notify_subscribers
|
||||||
|
|
||||||
def self.update_flagged_posts_count
|
def self.update_flagged_posts_count
|
||||||
posts_flagged_count = PostAction.joins(post: :topic)
|
posts_flagged_count = PostAction.joins(post: :topic)
|
||||||
|
@ -136,6 +137,7 @@ class PostAction < ActiveRecord::Base
|
||||||
staff_took_action: opts[:take_action] || false,
|
staff_took_action: opts[:take_action] || false,
|
||||||
related_post_id: related_post_id,
|
related_post_id: related_post_id,
|
||||||
targets_topic: !!targets_topic )
|
targets_topic: !!targets_topic )
|
||||||
|
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique
|
||||||
# can happen despite being .create
|
# can happen despite being .create
|
||||||
# since already bookmarked
|
# since already bookmarked
|
||||||
|
@ -259,6 +261,18 @@ class PostAction < ActiveRecord::Base
|
||||||
SpamRulesEnforcer.enforce!(post.user) if post_action_type_key == :spam
|
SpamRulesEnforcer.enforce!(post.user) if post_action_type_key == :spam
|
||||||
end
|
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)
|
def self.auto_hide_if_needed(post, post_action_type)
|
||||||
return if post.hidden
|
return if post.hidden
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue