FEATURE: allow sending message via a link to multiple users (#15412)

https://meta.discourse.org/t/possible-to-compose-pre-filled-multi-user-private-message-via-url/78020
This commit is contained in:
Arpit Jalan 2021-12-28 06:35:22 +05:30 committed by GitHub
parent c330363e14
commit b75cbec4b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 21 deletions

View File

@ -1,7 +1,6 @@
import DiscourseRoute from "discourse/routes/discourse";
import Group from "discourse/models/group";
import I18n from "I18n";
import User from "discourse/models/user";
import bootbox from "bootbox";
import cookie from "discourse/lib/cookie";
import { next } from "@ember/runloop";
@ -15,24 +14,11 @@ export default DiscourseRoute.extend({
if (this.currentUser) {
this.replaceWith("discovery.latest").then((e) => {
if (params.username) {
// send a message to a user
User.findByUsername(encodeURIComponent(params.username))
.then((user) => {
if (user.can_send_private_message_to_user) {
next(() =>
e.send("createNewMessageViaParams", {
recipients: user.username,
recipients: params.username,
topicTitle: params.title,
topicBody: params.body,
})
);
} else {
bootbox.alert(
I18n.t("composer.cant_send_pm", { username: user.username })
);
}
})
.catch(() => bootbox.alert(I18n.t("generic_error")));
});
} else if (groupName) {
// send a message to a group
Group.messageable(groupName)

View File

@ -22,7 +22,7 @@ acceptance("New Message - Authenticated", function (needs) {
test("accessing new-message route when logged in", async function (assert) {
await visit(
"/new-message?username=charlie&title=message%20title&body=message%20body"
"/new-message?username=charlie,john&title=message%20title&body=message%20body"
);
assert.ok(exists(".composer-fields"), "it opens composer");
@ -40,7 +40,7 @@ acceptance("New Message - Authenticated", function (needs) {
const privateMessageUsers = selectKit("#private-message-users");
assert.strictEqual(
privateMessageUsers.header().value(),
"charlie",
"charlie,john",
"it selects correct username"
);
});