Merge pull request #2705 from riking/live-lightbox
Publish lightboxing on the message bus
This commit is contained in:
commit
4a3f24ea24
|
@ -496,25 +496,30 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, {
|
||||||
}
|
}
|
||||||
|
|
||||||
var postStream = topicController.get('postStream');
|
var postStream = topicController.get('postStream');
|
||||||
if (data.type === "revised" || data.type === "acted"){
|
if (data.type === "revised" || data.type === "acted") {
|
||||||
// TODO we could update less data for "acted"
|
// TODO we could update less data for "acted"
|
||||||
// (only post actions)
|
// (only post actions)
|
||||||
postStream.triggerChangedPost(data.id, data.updated_at);
|
postStream.triggerChangedPost(data.id, data.updated_at);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.type === "deleted"){
|
if (data.type === "deleted") {
|
||||||
postStream.triggerDeletedPost(data.id, data.post_number);
|
postStream.triggerDeletedPost(data.id, data.post_number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.type === "recovered"){
|
if (data.type === "recovered") {
|
||||||
postStream.triggerRecoveredPost(data.id, data.post_number);
|
postStream.triggerRecoveredPost(data.id, data.post_number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new post into the stream
|
if (data.type === "created") {
|
||||||
postStream.triggerNewPostInStream(data.id);
|
postStream.triggerNewPostInStream(data.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// log a warning
|
||||||
|
Em.Logger.warn("unknown topic bus message type", data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,10 @@ module Jobs
|
||||||
cp.post_process(args[:bypass_bump])
|
cp.post_process(args[:bypass_bump])
|
||||||
|
|
||||||
# If we changed the document, save it
|
# If we changed the document, save it
|
||||||
post.update_column(:cooked, cp.html) if cp.dirty?
|
if cp.dirty?
|
||||||
|
post.update_column(:cooked, cp.html)
|
||||||
|
post.publish_change_to_clients! :revised
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -87,6 +87,15 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publish_change_to_clients!(type)
|
||||||
|
MessageBus.publish("/topic/#{topic_id}", {
|
||||||
|
id: id,
|
||||||
|
post_number: post_number,
|
||||||
|
updated_at: Time.now,
|
||||||
|
type: type
|
||||||
|
}, group_ids: topic.secure_group_ids)
|
||||||
|
end
|
||||||
|
|
||||||
def trash!(trashed_by=nil)
|
def trash!(trashed_by=nil)
|
||||||
self.topic_links.each(&:destroy)
|
self.topic_links.each(&:destroy)
|
||||||
super(trashed_by)
|
super(trashed_by)
|
||||||
|
|
|
@ -375,13 +375,7 @@ class PostAction < ActiveRecord::Base
|
||||||
|
|
||||||
def notify_subscribers
|
def notify_subscribers
|
||||||
if (is_like? || is_flag?) && post
|
if (is_like? || is_flag?) && post
|
||||||
MessageBus.publish("/topic/#{post.topic_id}",{
|
post.publish_change_to_clients! :acted
|
||||||
id: post.id,
|
|
||||||
post_number: post.post_number,
|
|
||||||
type: "acted"
|
|
||||||
},
|
|
||||||
group_ids: post.topic.secure_group_ids
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -270,14 +270,7 @@ class PostCreator
|
||||||
return if @opts[:import_mode]
|
return if @opts[:import_mode]
|
||||||
return unless @post.post_number > 1
|
return unless @post.post_number > 1
|
||||||
|
|
||||||
MessageBus.publish("/topic/#{@post.topic_id}",{
|
@post.publish_change_to_clients! :created
|
||||||
id: @post.id,
|
|
||||||
created_at: @post.created_at,
|
|
||||||
user: BasicUserSerializer.new(@post.user).as_json(root: false),
|
|
||||||
post_number: @post.post_number
|
|
||||||
},
|
|
||||||
group_ids: @topic.secure_group_ids
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_links
|
def extract_links
|
||||||
|
@ -288,8 +281,8 @@ class PostCreator
|
||||||
def track_topic
|
def track_topic
|
||||||
return if @opts[:auto_track] == false
|
return if @opts[:auto_track] == false
|
||||||
|
|
||||||
TopicUser.change(@post.user.id,
|
TopicUser.change(@post.user_id,
|
||||||
@post.topic.id,
|
@topic.id,
|
||||||
posted: true,
|
posted: true,
|
||||||
last_read_post_number: @post.post_number,
|
last_read_post_number: @post.post_number,
|
||||||
seen_post_count: @post.post_number)
|
seen_post_count: @post.post_number)
|
||||||
|
|
|
@ -51,7 +51,7 @@ class PostDestroyer
|
||||||
|
|
||||||
def staff_recovered
|
def staff_recovered
|
||||||
@post.recover!
|
@post.recover!
|
||||||
publish("recovered")
|
@post.publish_change_to_clients! :recovered
|
||||||
end
|
end
|
||||||
|
|
||||||
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
||||||
|
@ -75,21 +75,8 @@ class PostDestroyer
|
||||||
update_associated_category_latest_topic
|
update_associated_category_latest_topic
|
||||||
update_user_counts
|
update_user_counts
|
||||||
end
|
end
|
||||||
publish("deleted")
|
|
||||||
end
|
|
||||||
|
|
||||||
def publish(message)
|
@post.publish_change_to_clients! :deleted if @post.topic
|
||||||
# edge case, topic is already destroyed
|
|
||||||
return unless @post.topic
|
|
||||||
|
|
||||||
MessageBus.publish("/topic/#{@post.topic_id}",{
|
|
||||||
id: @post.id,
|
|
||||||
post_number: @post.post_number,
|
|
||||||
updated_at: @post.updated_at,
|
|
||||||
type: message
|
|
||||||
},
|
|
||||||
group_ids: @post.topic.secure_group_ids
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# When a user 'deletes' their own post. We just change the text.
|
# When a user 'deletes' their own post. We just change the text.
|
||||||
|
@ -100,6 +87,9 @@ class PostDestroyer
|
||||||
@post.update_flagged_posts_count
|
@post.update_flagged_posts_count
|
||||||
@post.topic_links.each(&:destroy)
|
@post.topic_links.each(&:destroy)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# covered by PostRevisor
|
||||||
|
# @post.publish_change_to_clients! :revised
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_recovered
|
def user_recovered
|
||||||
|
@ -109,6 +99,9 @@ class PostDestroyer
|
||||||
@post.revise(@user, @post.revisions.last.modifications["raw"][0], force_new_version: true)
|
@post.revise(@user, @post.revisions.last.modifications["raw"][0], force_new_version: true)
|
||||||
@post.update_flagged_posts_count
|
@post.update_flagged_posts_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# covered by PostRevisor
|
||||||
|
# @post.publish_change_to_clients! :revised
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ class PostRevisor
|
||||||
@opts = opts
|
@opts = opts
|
||||||
@new_raw = TextCleaner.normalize_whitespaces(new_raw).strip
|
@new_raw = TextCleaner.normalize_whitespaces(new_raw).strip
|
||||||
|
|
||||||
|
# TODO this is not in a transaction - dangerous!
|
||||||
return false unless should_revise?
|
return false unless should_revise?
|
||||||
@post.acting_user = @editor
|
@post.acting_user = @editor
|
||||||
revise_post
|
revise_post
|
||||||
|
@ -30,7 +31,7 @@ class PostRevisor
|
||||||
update_topic_word_counts
|
update_topic_word_counts
|
||||||
@post.advance_draft_sequence
|
@post.advance_draft_sequence
|
||||||
PostAlerter.new.after_save_post(@post)
|
PostAlerter.new.after_save_post(@post)
|
||||||
publish_revision
|
@post.publish_change_to_clients! :revised
|
||||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
|
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
|
||||||
|
|
||||||
true
|
true
|
||||||
|
@ -38,17 +39,6 @@ class PostRevisor
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def publish_revision
|
|
||||||
MessageBus.publish("/topic/#{@post.topic_id}",{
|
|
||||||
id: @post.id,
|
|
||||||
post_number: @post.post_number,
|
|
||||||
updated_at: @post.updated_at,
|
|
||||||
type: "revised"
|
|
||||||
},
|
|
||||||
group_ids: @post.topic.secure_group_ids
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def should_revise?
|
def should_revise?
|
||||||
@post.raw != @new_raw || @opts[:changed_owner]
|
@post.raw != @new_raw || @opts[:changed_owner]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue