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:
parent
aa5a993935
commit
a4001c1ea0
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"));
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -103,7 +103,8 @@ class PostActionNotifier
|
|||
Notification.types[:edited],
|
||||
post,
|
||||
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
|
||||
|
||||
|
|
|
@ -369,6 +369,7 @@ class PostAlerter
|
|||
original_post_id: original_post.id,
|
||||
original_post_type: original_post.post_type,
|
||||
original_username: original_username,
|
||||
revision_number: opts[:revision_number],
|
||||
display_username: opts[:display_username] || post.user.username)
|
||||
|
||||
if group = opts[:group]
|
||||
|
|
|
@ -37,6 +37,12 @@ describe PostActionNotifier do
|
|||
}.to change(post.user.notifications, :count).by(1)
|
||||
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
|
||||
|
||||
before { SiteSetting.disable_edit_notifications = true }
|
||||
|
|
Loading…
Reference in New Issue