Skip to content

A platform for community discussion. Free, open, simple.

Revert "Rename 'target usernames' with 'target recipients' in Composer (#8468)"

Bianca Nenciu9fe11d0fc338
diff --git a/app/assets/javascripts/discourse/components/composer-messages.js.es6 b/app/assets/javascripts/discourse/components/composer-messages.js.es6
index cafae730587..e9860973a2a 100644
--- a/app/assets/javascripts/discourse/components/composer-messages.js.es6
+++ b/app/assets/javascripts/discourse/components/composer-messages.js.es6
@@ -97,11 +97,16 @@ export default Component.extend({
const composer = this.composer;
if (composer.get("privateMessage")) {
- const recipients = composer.targetRecipientsArray;
+ let usernames = composer.get("targetUsernames");
+
+ if (usernames) {
+ usernames = usernames.split(",");
+ }
if (
- recipients.length > 0 &&
- recipients.every(r => r.name === this.currentUser.get("username"))
+ usernames &&
+ usernames.length === 1 &&
+ usernames[0] === this.currentUser.get("username")
) {
const message =
this._yourselfConfirm ||
diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index 1e2414894ae..a379d8f7e11 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -25,7 +25,6 @@ import { SAVE_LABELS, SAVE_ICONS } from "discourse/models/composer";
import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment";
import EmberObject, { computed } from "@ember/object";
-import deprecated from "discourse-common/lib/deprecated";
function loadDraft(store, opts) {
opts = opts || {};
@@ -130,7 +129,7 @@ export default Controller.extend({
@discourseComputed(
"model.replyingToTopic",
"model.creatingPrivateMessage",
- "model.targetRecipients",
+ "model.targetUsernames",
"model.composeState"
)
focusTarget(replyingToTopic, creatingPM, usernames, composeState) {
@@ -295,7 +294,7 @@ export default Controller.extend({
}
},
- @discourseComputed("model.creatingPrivateMessage", "model.targetRecipients")
+ @discourseComputed("model.creatingPrivateMessage", "model.targetUsernames")
showWarning(creatingPrivateMessage, usernames) {
if (!this.get("currentUser.staff")) {
return false;
@@ -910,24 +909,19 @@ export default Controller.extend({
isWarning: false
});
- if (!this.model.targetRecipients) {
- if (opts.usernames) {
- deprecated("`usernames` is deprecated, use `recipients` instead.");
- this.model.set("targetRecipients", opts.usernames);
- } else if (opts.recipients) {
- this.model.set("targetRecipients", opts.recipients);
- }
+ if (opts.usernames && !this.get("model.targetUsernames")) {
+ this.set("model.targetUsernames", opts.usernames);
}
if (
opts.topicTitle &&
opts.topicTitle.length <= this.siteSettings.max_topic_title_length
) {
- this.model.set("title", opts.topicTitle);
+ this.set("model.title", opts.topicTitle);
}
if (opts.topicCategoryId) {
- this.model.set("categoryId", opts.topicCategoryId);
+ this.set("model.categoryId", opts.topicCategoryId);
}
if (opts.topicTags && !this.site.mobileView && this.site.can_tag_topics) {
@@ -940,11 +934,11 @@ export default Controller.extend({
(array[index] = tag.substring(0, this.siteSettings.max_tag_length))
);
- this.model.set("tags", tags);
+ this.set("model.tags", tags);
}
if (opts.topicBody) {
- this.model.set("reply", opts.topicBody);
+ this.set("model.reply", opts.topicBody);
}
},
diff --git a/app/assets/javascripts/discourse/mixins/open-composer.js.es6 b/app/assets/javascripts/discourse/mixins/open-composer.js.es6
index 480eae57835..136cca6d50a 100644
--- a/app/assets/javascripts/discourse/mixins/open-composer.js.es6
+++ b/app/assets/javascripts/discourse/mixins/open-composer.js.es6
@@ -39,10 +39,10 @@ export default Mixin.create({
});
},
- openComposerWithMessageParams(recipients, topicTitle, topicBody) {
+ openComposerWithMessageParams(usernames, topicTitle, topicBody) {
this.controllerFor("composer").open({
action: Composer.PRIVATE_MESSAGE,
- recipients,
+ usernames,
topicTitle,
topicBody,
archetypeId: "private_message",
diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6
index 48a3cfe09ba..a630f521c41 100644
--- a/app/assets/javascripts/discourse/models/composer.js.es6
+++ b/app/assets/javascripts/discourse/models/composer.js.es6
@@ -14,18 +14,13 @@ import {
observes,
on
} from "discourse-common/utils/decorators";
-import {
- escapeExpression,
- tinyAvatar,
- emailValid
-} from "discourse/lib/utilities";
+import { escapeExpression, tinyAvatar } from "discourse/lib/utilities";
import { propertyNotEqual } from "discourse/lib/computed";
import { throttle } from "@ember/runloop";
import { Promise } from "rsvp";
import { set } from "@ember/object";
import Site from "discourse/models/site";
import User from "discourse/models/user";
-import deprecated from "discourse-common/lib/deprecated";
// The actions the composer can take
export const CREATE_TOPIC = "createTopic",
@@ -56,7 +51,7 @@ const CLOSED = "closed",
is_warning: "isWarning",
whisper: "whisper",
archetype: "archetypeId",
- target_recipients: "targetRecipients",
+ target_usernames: "targetUsernames",
typing_duration_msecs: "typingTime",
composer_open_duration_msecs: "composerTime",
tags: "tags",
@@ -82,9 +77,7 @@ const CLOSED = "closed",
composerTime: "composerTime",
typingTime: "typingTime",
postId: "post.id",
- // TODO remove together with 'targetUsername' deprecations
- usernames: "targetUsernames",
- recipients: "targetRecipients"
+ usernames: "targetUsernames"
},
_add_draft_fields = {},
FAST_REPLY_LENGTH_THRESHOLD = 10000;
@@ -347,35 +340,11 @@ const Composer = RestModel.extend({
return options;
},
- @discourseComputed("targetRecipients")
- targetUsernames(targetRecipients) {
- deprecated(
- "`targetUsernames` is deprecated, use `targetRecipients` instead."
- );
- return targetRecipients;
- },
-
- @discourseComputed("targetRecipients")
- targetRecipientsArray(targetRecipients) {
- const recipients = targetRecipients ? targetRecipients.split(",") : [];
- const groups = new Set(this.site.groups.map(g => g.name));
-
- return recipients.map(item => {
- if (groups.has(item)) {
- return { type: "group", name: item };
- } else if (emailValid(item)) {
- return { type: "email", name: item };
- } else {
- return { type: "user", name: item };
- }
- });
- },
-
@discourseComputed(
"loading",
"canEditTitle",
"titleLength",
- "targetRecipientsArray",
+ "targetUsernames",
"replyLength",
"categoryId",
"missingReplyCharacters",
@@ -388,7 +357,7 @@ const Composer = RestModel.extend({
loading,
canEditTitle,
titleLength,
- targetRecipientsArray,
+ targetUsernames,
replyLength,
categoryId,
missingReplyCharacters,
@@ -433,7 +402,9 @@ const Composer = RestModel.extend({
if (this.privateMessage) {
// need at least one user when sending a PM
- return targetRecipientsArray.length === 0;
+ return (
+ targetUsernames && (targetUsernames.trim() + ",").indexOf(",") === 0
+ );
} else {
// has a category? (when needed)
return this.requiredCategoryMissing;
@@ -696,17 +667,13 @@ const Composer = RestModel.extend({
throw new Error("draft sequence is required");
}
- if (opts.usernames) {
- deprecated("`usernames` is deprecated, use `recipients` instead.");
- }
-
this.setProperties({
draftKey: opts.draftKey,
draftSequence: opts.draftSequence,
composeState: opts.composerState || OPEN,
action: opts.action,
topic: opts.topic,
- targetRecipients: opts.usernames || opts.recipients,
+ targetUsernames: opts.usernames,
composerTotalOpened: opts.composerTime,
typingTime: opts.typingTime,
whisper: opts.whisper,
diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6
index e877d8ceff2..793c8a64923 100644
--- a/app/assets/javascripts/discourse/routes/application.js.es6
+++ b/app/assets/javascripts/discourse/routes/application.js.es6
@@ -71,20 +71,20 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
},
composePrivateMessage(user, post) {
- const recipients = user ? user.get("username") : "";
- const reply = post
- ? `${window.location.protocol}//${window.location.host}${post.url}`
- : null;
- const title = post
- ? I18n.t("composer.reference_topic_title", {
- title: post.topic.title
- })
- : null;
+ const recipient = user ? user.get("username") : "",
+ reply = post
+ ? `${window.location.protocol}//${window.location.host}${post.url}`
+ : null,
+ title = post
+ ? I18n.t("composer.reference_topic_title", {
+ title: post.topic.title
+ })
+ : null;
// used only once, one less dependency
return this.controllerFor("composer").open({
action: Composer.PRIVATE_MESSAGE,
- recipients,
+ usernames: recipient,
archetypeId: "private_message",
draftKey: Composer.NEW_PRIVATE_MESSAGE_KEY,
reply,
@@ -221,8 +221,8 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
);
},
- createNewMessageViaParams(recipients, title, body) {
- this.openComposerWithMessageParams(recipients, title, body);
+ createNewMessageViaParams(username, title, body) {
+ this.openComposerWithMessageParams(username, title, body);
}
},
diff --git a/app/assets/javascripts/discourse/templates/composer.hbs b/app/assets/javascripts/discourse/templates/composer.hbs
index 4a5a1789462..f738efc3625 100644
--- a/app/assets/javascripts/discourse/templates/composer.hbs
+++ b/app/assets/javascripts/discourse/templates/composer.hbs
@@ -53,7 +53,7 @@
{{#if model.creatingPrivateMessage}}
<div class='user-selector'>
{{composer-user-selector topicId=topicModel.id
- usernames=model.targetRecipients
+ usernames=model.targetUsernames
hasGroups=model.hasTargetGroups
focusTarget=focusTarget
class="users-input"}}
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 789dfaf74f1..44dd116c19f 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -675,9 +675,7 @@ class PostsController < ApplicationController
:topic_id,
:archetype,
:category,
- # TODO remove together with 'targetUsername' deprecations
:target_usernames,
- :target_recipients,
:reply_to_post_number,
:auto_track,
:typing_duration_msecs,
@@ -751,19 +749,13 @@ class PostsController < ApplicationController
result[:user_agent] = request.user_agent
result[:referrer] = request.env["HTTP_REFERER"]
- if recipients = result[:target_usernames]
- Discourse.deprecate("`target_usernames` is deprecated, use `target_recipients` instead.", output_in_test: true)
- else
- recipients = result[:target_recipients]
- end
-
- if recipients
- recipients = recipients.split(",")
- groups = Group.messageable(current_user).where('name in (?)', recipients).pluck('name')
- recipients -= groups
- emails = recipients.select { |user| user.match(/@/) }
- recipients -= emails
- result[:target_usernames] = recipients.join(",")
+ if usernames = result[:target_usernames]
+ usernames = usernames.split(",")
+ groups = Group.messageable(current_user).where('name in (?)', usernames).pluck('name')
+ usernames -= groups
+ emails = usernames.select { |user| user.match(/@/) }
+ usernames -= emails
+ result[:target_usernames] = usernames.join(",")
result[:target_emails] = emails.join(",")
result[:target_group_names] = groups.join(",")
end
diff --git a/test/javascripts/models/composer-test.js.es6 b/test/javascripts/models/composer-test.js.es6
index e2e35fa3463..cd3135b74f6 100644
--- a/test/javascripts/models/composer-test.js.es6
+++ b/test/javascripts/models/composer-test.js.es6
@@ -396,15 +396,3 @@ QUnit.test("allows featured link before choosing a category", assert => {
);
assert.ok(composer.get("canEditTopicFeaturedLink"), "can paste link");
});
-
-QUnit.test("targetRecipientsArray contains types", assert => {
- let composer = createComposer({
- targetRecipients: "test,codinghorror,staff,[email protected]"
- });
- assert.ok(composer.targetRecipientsArray, [
- { type: "group", name: "test" },
- { type: "user", name: "codinghorror" },
- { type: "group", name: "staff" },
- { type: "email", name: "[email protected]" }
- ]);
-});