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() {
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({
selectedPostIds: [],
quoteState: new QuoteState()

View File

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

View File

@@ -711,6 +711,16 @@ export default RestModel.extend({
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.
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();
},
showHistory(model) {
showHistory(model, revision) {
showModal("history", { model });
const historyController = this.controllerFor("history");
historyController.refresh(model.get("id"), "latest");
historyController.refresh(model.get("id"), revision || "latest");
historyController.set("post", model);
historyController.set("topicController", this.controllerFor("topic"));

View File

@@ -52,6 +52,7 @@ createWidget("notification-item", {
}
const topicId = attrs.topic_id;
if (topicId) {
return postUrl(attrs.slug, topicId, attrs.post_number);
}
@@ -152,6 +153,18 @@ createWidget("notification-item", {
e.preventDefault();
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
);
}
});
}
});