FEATURE: compose a new pre-filled message via URL

This commit is contained in:
Arpit Jalan 2015-11-24 18:16:42 +05:30
parent 8e95c6cf5b
commit 362c515f33
7 changed files with 47 additions and 3 deletions

View File

@ -12,7 +12,7 @@ export default Ember.Mixin.create({
});
},
openComposerWithParams(controller, topicTitle, topicBody, topicCategoryId, topicCategory) {
openComposerWithTopicParams(controller, topicTitle, topicBody, topicCategoryId, topicCategory) {
const Composer = require('discourse/models/composer').default;
this.controllerFor('composer').open({
action: Composer.CREATE_TOPIC,
@ -23,6 +23,18 @@ export default Ember.Mixin.create({
draftKey: controller.get('model.draft_key'),
draftSequence: controller.get('model.draft_sequence')
});
},
openComposerWithMessageParams(usernames, topicTitle, topicBody) {
const Composer = require('discourse/models/composer').default;
this.controllerFor('composer').open({
action: Composer.PRIVATE_MESSAGE,
usernames,
topicTitle,
topicBody,
archetypeId: 'private_message',
draftKey: 'new_private_message'
});
}
});

View File

@ -93,6 +93,7 @@ export default function() {
this.route('guidelines', {path: '/guidelines'});
this.route('new-topic', {path: '/new-topic'});
this.route('new-message', {path: '/new-message'});
this.resource('badges', function() {
this.route('show', {path: '/:id/:slug'});

View File

@ -145,7 +145,11 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
},
createNewTopicViaParams(title, body, category_id, category) {
this.openComposerWithParams(this.controllerFor('discovery/topics'), title, body, category_id, category);
this.openComposerWithTopicParams(this.controllerFor('discovery/topics'), title, body, category_id, category);
},
createNewMessageViaParams(username, title, body) {
this.openComposerWithMessageParams(username, title, body);
}
},

View File

@ -0,0 +1,25 @@
export default Discourse.Route.extend({
beforeModel: function(transition) {
const self = this;
if (Discourse.User.current()) {
// User is logged in
self.replaceWith('discovery.latest').then(function(e) {
Discourse.User.findByUsername(transition.queryParams.username).then((user) => {
if (user.can_send_private_message_to_user) {
Ember.run.next(function() {
e.send('createNewMessageViaParams', user.username, transition.queryParams.title, transition.queryParams.body);
});
} else {
bootbox.alert(I18n.t("composer.cant_send_pm", {username: user.username}));
}
}).catch((error) => {
bootbox.alert(I18n.t("generic_error"));
});
});
} else {
// User is not logged in
self.session.set("shouldRedirectToUrl", window.location.href);
self.replaceWith('login');
}
}
});

View File

@ -75,7 +75,7 @@ class StaticController < ApplicationController
uri.path !~ /\./
destination = uri.path
destination = "#{uri.path}?#{uri.query}" if uri.path =~ /new-topic/
destination = "#{uri.path}?#{uri.query}" if uri.path =~ /new-topic/ || uri.path =~ /new-message/
end
rescue URI::InvalidURIError
# Do nothing if the URI is invalid

View File

@ -907,6 +907,7 @@ en:
toggler: "hide or show the composer panel"
modal_ok: "OK"
modal_cancel: "Cancel"
cant_send_pm: "Sorry, you can't send a message to %{username}."
admin_options_title: "Optional staff settings for this topic"
auto_close:

View File

@ -463,6 +463,7 @@ Discourse::Application.routes.draw do
get 'embed/info' => 'embed#info'
get "new-topic" => "list#latest"
get "new-message" => "list#latest"
# Topic routes
get "t/id_for/:slug" => "topics#id_for_slug"