A platform for community discussion. Free, open, simple.
FIX: When creating new message via URL do not redirect (#27153)
Arpit Jalan9db83c37e42e
diff --git a/app/assets/javascripts/discourse/app/routes/new-message.js b/app/assets/javascripts/discourse/app/routes/new-message.jsindex 85ead554967..1def6a37e4f 100644--- a/app/assets/javascripts/discourse/app/routes/new-message.js+++ b/app/assets/javascripts/discourse/app/routes/new-message.js@@ -12,49 +12,78 @@ export default DiscourseRoute.extend({beforeModel(transition) {const params = transition.to.queryParams;-+ const userName = params.username;const groupName = params.groupname || params.group_name;- if (this.currentUser) {+ if (!this.currentUser) {+ cookie("destination_url", window.location.href);+ this.router.replaceWith("login");+ return;+ }++ if (transition.from) {+ transition.abort();++ if (userName) {+ return this.openComposer(transition, userName);+ }++ if (groupName) {+ // send a message to a group+ return Group.messageable(groupName)+ .then((result) => {+ if (result.messageable) {+ this.openComposer(transition, groupName);+ } else {+ this.dialog.alert(+ I18n.t("composer.cant_send_pm", { username: groupName })+ );+ }+ })+ .catch(() =>+ this.dialog.alert(I18n.t("composer.create_message_error"))+ );+ }++ return this.openComposer(transition);+ } else {this.router.replaceWith("discovery.latest").followRedirects().then(() => {- if (params.username) {- this.composer.openNewMessage({- recipients: params.username,- title: params.title,- body: params.body,- });- } else if (groupName) {+ if (userName) {+ return this.openComposer(transition, userName);+ }++ if (groupName) {// send a message to a group- Group.messageable(groupName)+ return Group.messageable(groupName).then((result) => {if (result.messageable) {- next(() =>- this.composer.openNewMessage({- recipients: groupName,- title: params.title,- body: params.body,- })- );+ this.openComposer(transition, groupName);} else {this.dialog.alert(I18n.t("composer.cant_send_pm", { username: groupName }));}})- .catch(() => this.dialog.alert(I18n.t("generic_error")));- } else {- this.composer.openNewMessage({- title: params.title,- body: params.body,- });+ .catch(() =>+ this.dialog.alert(I18n.t("composer.create_message_error"))+ );}++ return this.openComposer(transition);});- } else {- cookie("destination_url", window.location.href);- this.router.replaceWith("login");}},++ openComposer(transition, recipients) {+ next(() => {+ this.composer.openNewMessage({+ recipients,+ title: transition.to.queryParams.title,+ body: transition.to.queryParams.body,+ });+ });+ },});diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 19528a08eca..1e84567389d 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -2596,6 +2596,7 @@ en:modal_ok: "OK"modal_cancel: "Cancel"cant_send_pm: "Sorry, you can't send a message to %{username}."+ create_message_error: "Sorry, there was an error creating that message. Please try again."yourself_confirm:title: "Did you forget to add recipients?"body: "Right now this message is only being sent to yourself!"