UX: Publish changes to TopicView when Topic is updated.

This commit is contained in:
Guo Xiang Tan 2016-04-07 22:29:01 +08:00 committed by Régis Hanol
parent 4e7e4cee7d
commit 6aa447816d
4 changed files with 37 additions and 10 deletions

View file

@ -661,35 +661,41 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
case "revised": case "revised":
case "rebaked": { case "rebaked": {
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh({ id: data.id })); postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh({ id: data.id }));
return; break;
} }
case "deleted": { case "deleted": {
postStream.triggerDeletedPost(data.id, data.post_number).then(() => refresh({ id: data.id })); postStream.triggerDeletedPost(data.id, data.post_number).then(() => refresh({ id: data.id }));
return; break;
} }
case "recovered": { case "recovered": {
postStream.triggerRecoveredPost(data.id, data.post_number).then(() => refresh({ id: data.id })); postStream.triggerRecoveredPost(data.id, data.post_number).then(() => refresh({ id: data.id }));
return; break;
} }
case "created": { case "created": {
postStream.triggerNewPostInStream(data.id).then(() => refresh()); postStream.triggerNewPostInStream(data.id).then(() => refresh());
if (this.get('currentUser.id') !== data.user_id) { if (this.get('currentUser.id') !== data.user_id) {
Discourse.notifyBackgroundCountIncrement(); Discourse.notifyBackgroundCountIncrement();
} }
return; break;
} }
case "move_to_inbox": { case "move_to_inbox": {
topic.set("message_archived",false); topic.set("message_archived",false);
return; break;
} }
case "archived": { case "archived": {
topic.set("message_archived",true); topic.set("message_archived",true);
return; break;
} }
default: { default: {
Em.Logger.warn("unknown topic bus message type", data); Em.Logger.warn("unknown topic bus message type", data);
} }
} }
if (data.reload_topic) {
topic.reload().then(() => {
this.send('postChangedRoute', topic.get('post_number') || 1);
});
}
}); });
}, },

View file

@ -104,7 +104,7 @@ class Post < ActiveRecord::Base
end end
end end
def publish_change_to_clients!(type) def publish_change_to_clients!(type, options = {})
# special failsafe for posts missing topics consistency checks should fix, but message # special failsafe for posts missing topics consistency checks should fix, but message
# is safe to skip # is safe to skip
return unless topic return unless topic
@ -117,7 +117,7 @@ class Post < ActiveRecord::Base
user_id: user_id, user_id: user_id,
last_editor_id: last_editor_id, last_editor_id: last_editor_id,
type: type type: type
} }.merge(options)
if Topic.visible_post_types.include?(post_type) if Topic.visible_post_types.include?(post_type)
MessageBus.publish(channel, msg, group_ids: topic.secure_group_ids) MessageBus.publish(channel, msg, group_ids: topic.secure_group_ids)

View file

@ -433,7 +433,14 @@ class PostRevisor
end end
def publish_changes def publish_changes
@post.publish_change_to_clients!(:revised) options =
if !@topic_changes.diff.empty? && !@topic_changes.errored?
{ reload_topic: true }
else
{}
end
@post.publish_change_to_clients!(:revised, options)
end end
def grant_badge def grant_badge

View file

@ -8,7 +8,6 @@ describe PostRevisor do
let(:post_args) { { user: newuser, topic: topic } } let(:post_args) { { user: newuser, topic: topic } }
context 'TopicChanges' do context 'TopicChanges' do
let(:topic) { Fabricate(:topic) }
let(:tc) { let(:tc) {
topic.reload topic.reload
PostRevisor::TopicChanges.new(topic, topic.user) PostRevisor::TopicChanges.new(topic, topic.user)
@ -348,5 +347,20 @@ describe PostRevisor do
expect(post.raw).to eq(" <-- whitespaces -->") expect(post.raw).to eq(" <-- whitespaces -->")
end end
context "#publish_changes" do
let!(:post) { Fabricate(:post, topic_id: topic.id) }
it "should publish topic changes to clients" do
revisor = described_class.new(topic.ordered_posts.first, topic)
messages = MessageBus.track_publish do
revisor.revise!(newuser, { title: 'this is a test topic' })
end
message = messages.find { |message| message.channel == "/topic/#{topic.id}" }
payload = message.data
expect(payload[:reload_topic]).to eq(true)
end
end
end end
end end