FIX: PM automatic groups via URL

This commit is contained in:
Régis Hanol 2016-07-27 19:16:31 +02:00
parent 11172b7c2d
commit ea59283c1e

View file

@ -1,43 +1,41 @@
import User from 'discourse/models/user';
import Group from 'discourse/models/group'; import Group from 'discourse/models/group';
export default Discourse.Route.extend({ export default Discourse.Route.extend({
beforeModel: function(transition) {
const self = this; beforeModel(transition) {
if (Discourse.User.current()) { const params = transition.queryParams;
// User is logged in
self.replaceWith('discovery.latest').then(function(e) { if (this.currentUser) {
if (transition.queryParams.username) { this.replaceWith("discovery.latest").then(e => {
// send a message to user if (params.username) {
Discourse.User.findByUsername(transition.queryParams.username).then((user) => { // send a message to a user
User.findByUsername(params.username).then(user => {
if (user.can_send_private_message_to_user) { if (user.can_send_private_message_to_user) {
Ember.run.next(function() { Ember.run.next(() => e.send("createNewMessageViaParams", user.username, params.title, params.body));
e.send('createNewMessageViaParams', user.username, transition.queryParams.title, transition.queryParams.body);
});
} else { } else {
bootbox.alert(I18n.t("composer.cant_send_pm", {username: user.username})); bootbox.alert(I18n.t("composer.cant_send_pm", { username: user.username }));
} }
}).catch(() => { }).catch(function() {
bootbox.alert(I18n.t("generic_error")); bootbox.alert(I18n.t("generic_error"));
}); });
} else if (params.groupname) {
// send a message to a group
Group.find(params.groupname).then(group => {
if (group.mentionable) {
Ember.run.next(() => e.send("createNewMessageViaParams", group.name, params.title, params.body));
} else { } else {
// send a message to group bootbox.alert(I18n.t("composer.cant_send_pm", { username: group.name }));
Group.find(transition.queryParams.groupname).then((group) => {
if (!group.automatic && group.mentionable) {
Ember.run.next(function() {
e.send('createNewMessageViaParams', group.name, transition.queryParams.title, transition.queryParams.body);
});
} else {
bootbox.alert(I18n.t("composer.cant_send_pm", {username: group.name}));
} }
}).catch(() => { }).catch(function() {
bootbox.alert(I18n.t("generic_error")); bootbox.alert(I18n.t("generic_error"));
}); });
} }
}); });
} else { } else {
// User is not logged in this.session.set("shouldRedirectToUrl", window.location.href);
self.session.set("shouldRedirectToUrl", window.location.href); this.replaceWith('login');
self.replaceWith('login');
} }
} }
}); });