mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
UX: Publish changes to TopicView when Topic is updated.
This commit is contained in:
parent
4e7e4cee7d
commit
6aa447816d
4 changed files with 37 additions and 10 deletions
|
@ -661,35 +661,41 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
|||
case "revised":
|
||||
case "rebaked": {
|
||||
postStream.triggerChangedPost(data.id, data.updated_at).then(() => refresh({ id: data.id }));
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case "deleted": {
|
||||
postStream.triggerDeletedPost(data.id, data.post_number).then(() => refresh({ id: data.id }));
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case "recovered": {
|
||||
postStream.triggerRecoveredPost(data.id, data.post_number).then(() => refresh({ id: data.id }));
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case "created": {
|
||||
postStream.triggerNewPostInStream(data.id).then(() => refresh());
|
||||
if (this.get('currentUser.id') !== data.user_id) {
|
||||
Discourse.notifyBackgroundCountIncrement();
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case "move_to_inbox": {
|
||||
topic.set("message_archived",false);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
case "archived": {
|
||||
topic.set("message_archived",true);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Em.Logger.warn("unknown topic bus message type", data);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.reload_topic) {
|
||||
topic.reload().then(() => {
|
||||
this.send('postChangedRoute', topic.get('post_number') || 1);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ class Post < ActiveRecord::Base
|
|||
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
|
||||
# is safe to skip
|
||||
return unless topic
|
||||
|
@ -117,7 +117,7 @@ class Post < ActiveRecord::Base
|
|||
user_id: user_id,
|
||||
last_editor_id: last_editor_id,
|
||||
type: type
|
||||
}
|
||||
}.merge(options)
|
||||
|
||||
if Topic.visible_post_types.include?(post_type)
|
||||
MessageBus.publish(channel, msg, group_ids: topic.secure_group_ids)
|
||||
|
|
|
@ -433,7 +433,14 @@ class PostRevisor
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def grant_badge
|
||||
|
|
|
@ -8,7 +8,6 @@ describe PostRevisor do
|
|||
let(:post_args) { { user: newuser, topic: topic } }
|
||||
|
||||
context 'TopicChanges' do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:tc) {
|
||||
topic.reload
|
||||
PostRevisor::TopicChanges.new(topic, topic.user)
|
||||
|
@ -348,5 +347,20 @@ describe PostRevisor do
|
|||
expect(post.raw).to eq(" <-- whitespaces -->")
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue