mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 03:16:15 +08:00
FEATURE: compose a new pre-filled message via URL
This commit is contained in:
parent
8e95c6cf5b
commit
362c515f33
@ -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'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -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'});
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
25
app/assets/javascripts/discourse/routes/new-message.js.es6
Normal file
25
app/assets/javascripts/discourse/routes/new-message.js.es6
Normal 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');
|
||||
}
|
||||
}
|
||||
});
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user