mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: Live update edits
This commit is contained in:
parent
7e88006b20
commit
090f5c99c2
5 changed files with 47 additions and 8 deletions
|
@ -360,8 +360,14 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||
return;
|
||||
}
|
||||
|
||||
var postStream = topicController.get('postStream');
|
||||
if (data.type === "revised"){
|
||||
postStream.triggerChangedPost(data.id, data.updated_at);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the new post into the stream
|
||||
topicController.get('postStream').triggerNewPostInStream(data.id);
|
||||
postStream.triggerNewPostInStream(data.id);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -510,6 +510,21 @@ Discourse.PostStream = Em.Object.extend({
|
|||
}
|
||||
},
|
||||
|
||||
triggerChangedPost: function(postId, updatedAt) {
|
||||
if (!postId) { return; }
|
||||
|
||||
var postIdentityMap = this.get('postIdentityMap'),
|
||||
existing = postIdentityMap.get(postId),
|
||||
postStream = this;
|
||||
|
||||
if (existing && existing.updated_at !== updatedAt) {
|
||||
var url = "/posts/" + postId;
|
||||
Discourse.ajax(url).then(function(p){
|
||||
postStream.storePost(Discourse.Post.create(p));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Returns the "thread" of posts in the history of a post.
|
||||
|
||||
|
|
|
@ -701,6 +701,12 @@ class Topic < ActiveRecord::Base
|
|||
@acting_user = u
|
||||
end
|
||||
|
||||
def secure_group_ids
|
||||
@secure_group_ids ||= if self.category && self.category.read_restricted?
|
||||
self.category.secure_group_ids
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_category_topic_count_by(num)
|
||||
|
|
|
@ -137,12 +137,6 @@ class PostCreator
|
|||
end
|
||||
end
|
||||
|
||||
def secure_group_ids(topic)
|
||||
@secure_group_ids ||= if topic.category && topic.category.read_restricted?
|
||||
topic.category.secure_group_ids
|
||||
end
|
||||
end
|
||||
|
||||
def clear_possible_flags(topic)
|
||||
# at this point we know the topic is a PM and has been replied to ... check if we need to clear any flags
|
||||
#
|
||||
|
@ -255,7 +249,7 @@ class PostCreator
|
|||
user: BasicUserSerializer.new(@post.user).as_json(root: false),
|
||||
post_number: @post.post_number
|
||||
},
|
||||
group_ids: secure_group_ids(@topic)
|
||||
group_ids: @topic.secure_group_ids
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -19,12 +19,30 @@ class PostRevisor
|
|||
update_topic_word_counts
|
||||
@post.advance_draft_sequence
|
||||
PostAlerter.new.after_save_post(@post)
|
||||
publish_revision
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
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 secure_group_ids(topic)
|
||||
@secure_group_ids ||= if topic.category && topic.category.read_restricted?
|
||||
topic.category.secure_group_ids
|
||||
end
|
||||
end
|
||||
|
||||
def should_revise?
|
||||
@post.raw != @new_raw
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue