FEATURE: Pop revise modal on post edited notification (#6287)

* Add revision number to notification url

* Pop modal on route change

* Add semicolon

* Ensure modal pops even when navigating within a topic

* Ensure modal pops when visiting from other page

* Fix eslint errors

* Fix prettier errors

* Add callback for notification item click

* Remove stray revisionUrl function

* Rename to afterRouteComplete
This commit is contained in:
James Kiesel 2018-08-24 08:13:07 -05:00 committed by Robin Ward
parent aa5a993935
commit a4001c1ea0
8 changed files with 49 additions and 4 deletions

View File

@ -98,6 +98,16 @@ export default Ember.Controller.extend(BufferedContent, {
init() { init() {
this._super(); this._super();
this.appEvents.on("post:show-revision", (postNumber, revision) => {
const post = this.model.get("postStream").postForPostNumber(postNumber);
if (!post) {
return;
}
Ember.run.scheduleOnce("afterRender", () => {
this.send("showHistory", post, revision);
});
});
this.setProperties({ this.setProperties({
selectedPostIds: [], selectedPostIds: [],
quoteState: new QuoteState() quoteState: new QuoteState()

View File

@ -242,6 +242,10 @@ const DiscourseURL = Ember.Object.extend({
path = rewritePath(path); path = rewritePath(path);
if (typeof opts.afterRouteComplete === "function") {
Ember.run.schedule("afterRender", opts.afterRouteComplete);
}
if (this.navigatedToPost(oldPath, path, opts)) { if (this.navigatedToPost(oldPath, path, opts)) {
return; return;
} }

View File

@ -711,6 +711,16 @@ export default RestModel.extend({
return resolved; return resolved;
}, },
postForPostNumber(postNumber) {
if (!this.get("hasPosts")) {
return;
}
return this.get("posts").find(p => {
return p.get("post_number") === postNumber;
});
},
/** /**
Returns the closest post given a postNumber that may not exist in the stream. Returns the closest post given a postNumber that may not exist in the stream.
For example, if the user asks for a post that's deleted or otherwise outside the range. For example, if the user asks for a post that's deleted or otherwise outside the range.

View File

@ -91,11 +91,11 @@ const TopicRoute = Discourse.Route.extend({
this.controllerFor("invite").reset(); this.controllerFor("invite").reset();
}, },
showHistory(model) { showHistory(model, revision) {
showModal("history", { model }); showModal("history", { model });
const historyController = this.controllerFor("history"); const historyController = this.controllerFor("history");
historyController.refresh(model.get("id"), "latest"); historyController.refresh(model.get("id"), revision || "latest");
historyController.set("post", model); historyController.set("post", model);
historyController.set("topicController", this.controllerFor("topic")); historyController.set("topicController", this.controllerFor("topic"));

View File

@ -52,6 +52,7 @@ createWidget("notification-item", {
} }
const topicId = attrs.topic_id; const topicId = attrs.topic_id;
if (topicId) { if (topicId) {
return postUrl(attrs.slug, topicId, attrs.post_number); return postUrl(attrs.slug, topicId, attrs.post_number);
} }
@ -152,6 +153,18 @@ createWidget("notification-item", {
e.preventDefault(); e.preventDefault();
this.sendWidgetEvent("linkClicked"); this.sendWidgetEvent("linkClicked");
DiscourseURL.routeTo(this.url()); DiscourseURL.routeTo(this.url(), {
afterRouteComplete: () => {
if (!this.attrs.data.revision_number) {
return;
}
this.appEvents.trigger(
"post:show-revision",
this.attrs.post_number,
this.attrs.data.revision_number
);
}
});
} }
}); });

View File

@ -103,7 +103,8 @@ class PostActionNotifier
Notification.types[:edited], Notification.types[:edited],
post, post,
display_username: post_revision.user.username, display_username: post_revision.user.username,
acting_user_id: post_revision.try(:user_id) acting_user_id: post_revision.try(:user_id),
revision_number: post_revision.number
) )
end end

View File

@ -369,6 +369,7 @@ class PostAlerter
original_post_id: original_post.id, original_post_id: original_post.id,
original_post_type: original_post.post_type, original_post_type: original_post.post_type,
original_username: original_username, original_username: original_username,
revision_number: opts[:revision_number],
display_username: opts[:display_username] || post.user.username) display_username: opts[:display_username] || post.user.username)
if group = opts[:group] if group = opts[:group]

View File

@ -37,6 +37,12 @@ describe PostActionNotifier do
}.to change(post.user.notifications, :count).by(1) }.to change(post.user.notifications, :count).by(1)
end end
it 'stores the revision number with the notification' do
post.revise(evil_trout, raw: "world is the new body of the message")
notification_data = JSON.parse post.user.notifications.last.data
expect(notification_data['revision_number']).to eq post.post_revisions.last.number
end
context "edit notifications are disabled" do context "edit notifications are disabled" do
before { SiteSetting.disable_edit_notifications = true } before { SiteSetting.disable_edit_notifications = true }