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

This reverts commit ebb288dc2c.
This commit is contained in:
Bianca Nenciu 2019-12-20 11:56:20 +02:00
parent 7030c93206
commit 9fe11d0fc3
8 changed files with 47 additions and 101 deletions

View File

@ -97,11 +97,16 @@ export default Component.extend({
const composer = this.composer; const composer = this.composer;
if (composer.get("privateMessage")) { if (composer.get("privateMessage")) {
const recipients = composer.targetRecipientsArray; let usernames = composer.get("targetUsernames");
if (usernames) {
usernames = usernames.split(",");
}
if ( if (
recipients.length > 0 && usernames &&
recipients.every(r => r.name === this.currentUser.get("username")) usernames.length === 1 &&
usernames[0] === this.currentUser.get("username")
) { ) {
const message = const message =
this._yourselfConfirm || this._yourselfConfirm ||

View File

@ -25,7 +25,6 @@ import { SAVE_LABELS, SAVE_ICONS } from "discourse/models/composer";
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment"; import ENV from "discourse-common/config/environment";
import EmberObject, { computed } from "@ember/object"; import EmberObject, { computed } from "@ember/object";
import deprecated from "discourse-common/lib/deprecated";
function loadDraft(store, opts) { function loadDraft(store, opts) {
opts = opts || {}; opts = opts || {};
@ -130,7 +129,7 @@ export default Controller.extend({
@discourseComputed( @discourseComputed(
"model.replyingToTopic", "model.replyingToTopic",
"model.creatingPrivateMessage", "model.creatingPrivateMessage",
"model.targetRecipients", "model.targetUsernames",
"model.composeState" "model.composeState"
) )
focusTarget(replyingToTopic, creatingPM, usernames, 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) { showWarning(creatingPrivateMessage, usernames) {
if (!this.get("currentUser.staff")) { if (!this.get("currentUser.staff")) {
return false; return false;
@ -910,24 +909,19 @@ export default Controller.extend({
isWarning: false isWarning: false
}); });
if (!this.model.targetRecipients) { if (opts.usernames && !this.get("model.targetUsernames")) {
if (opts.usernames) { this.set("model.targetUsernames", 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 ( if (
opts.topicTitle && opts.topicTitle &&
opts.topicTitle.length <= this.siteSettings.max_topic_title_length opts.topicTitle.length <= this.siteSettings.max_topic_title_length
) { ) {
this.model.set("title", opts.topicTitle); this.set("model.title", opts.topicTitle);
} }
if (opts.topicCategoryId) { 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) { 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)) (array[index] = tag.substring(0, this.siteSettings.max_tag_length))
); );
this.model.set("tags", tags); this.set("model.tags", tags);
} }
if (opts.topicBody) { if (opts.topicBody) {
this.model.set("reply", opts.topicBody); this.set("model.reply", opts.topicBody);
} }
}, },

View File

@ -39,10 +39,10 @@ export default Mixin.create({
}); });
}, },
openComposerWithMessageParams(recipients, topicTitle, topicBody) { openComposerWithMessageParams(usernames, topicTitle, topicBody) {
this.controllerFor("composer").open({ this.controllerFor("composer").open({
action: Composer.PRIVATE_MESSAGE, action: Composer.PRIVATE_MESSAGE,
recipients, usernames,
topicTitle, topicTitle,
topicBody, topicBody,
archetypeId: "private_message", archetypeId: "private_message",

View File

@ -14,18 +14,13 @@ import {
observes, observes,
on on
} from "discourse-common/utils/decorators"; } from "discourse-common/utils/decorators";
import { import { escapeExpression, tinyAvatar } from "discourse/lib/utilities";
escapeExpression,
tinyAvatar,
emailValid
} from "discourse/lib/utilities";
import { propertyNotEqual } from "discourse/lib/computed"; import { propertyNotEqual } from "discourse/lib/computed";
import { throttle } from "@ember/runloop"; import { throttle } from "@ember/runloop";
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import { set } from "@ember/object"; import { set } from "@ember/object";
import Site from "discourse/models/site"; import Site from "discourse/models/site";
import User from "discourse/models/user"; import User from "discourse/models/user";
import deprecated from "discourse-common/lib/deprecated";
// The actions the composer can take // The actions the composer can take
export const CREATE_TOPIC = "createTopic", export const CREATE_TOPIC = "createTopic",
@ -56,7 +51,7 @@ const CLOSED = "closed",
is_warning: "isWarning", is_warning: "isWarning",
whisper: "whisper", whisper: "whisper",
archetype: "archetypeId", archetype: "archetypeId",
target_recipients: "targetRecipients", target_usernames: "targetUsernames",
typing_duration_msecs: "typingTime", typing_duration_msecs: "typingTime",
composer_open_duration_msecs: "composerTime", composer_open_duration_msecs: "composerTime",
tags: "tags", tags: "tags",
@ -82,9 +77,7 @@ const CLOSED = "closed",
composerTime: "composerTime", composerTime: "composerTime",
typingTime: "typingTime", typingTime: "typingTime",
postId: "post.id", postId: "post.id",
// TODO remove together with 'targetUsername' deprecations usernames: "targetUsernames"
usernames: "targetUsernames",
recipients: "targetRecipients"
}, },
_add_draft_fields = {}, _add_draft_fields = {},
FAST_REPLY_LENGTH_THRESHOLD = 10000; FAST_REPLY_LENGTH_THRESHOLD = 10000;
@ -347,35 +340,11 @@ const Composer = RestModel.extend({
return options; 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( @discourseComputed(
"loading", "loading",
"canEditTitle", "canEditTitle",
"titleLength", "titleLength",
"targetRecipientsArray", "targetUsernames",
"replyLength", "replyLength",
"categoryId", "categoryId",
"missingReplyCharacters", "missingReplyCharacters",
@ -388,7 +357,7 @@ const Composer = RestModel.extend({
loading, loading,
canEditTitle, canEditTitle,
titleLength, titleLength,
targetRecipientsArray, targetUsernames,
replyLength, replyLength,
categoryId, categoryId,
missingReplyCharacters, missingReplyCharacters,
@ -433,7 +402,9 @@ const Composer = RestModel.extend({
if (this.privateMessage) { if (this.privateMessage) {
// need at least one user when sending a PM // need at least one user when sending a PM
return targetRecipientsArray.length === 0; return (
targetUsernames && (targetUsernames.trim() + ",").indexOf(",") === 0
);
} else { } else {
// has a category? (when needed) // has a category? (when needed)
return this.requiredCategoryMissing; return this.requiredCategoryMissing;
@ -696,17 +667,13 @@ const Composer = RestModel.extend({
throw new Error("draft sequence is required"); throw new Error("draft sequence is required");
} }
if (opts.usernames) {
deprecated("`usernames` is deprecated, use `recipients` instead.");
}
this.setProperties({ this.setProperties({
draftKey: opts.draftKey, draftKey: opts.draftKey,
draftSequence: opts.draftSequence, draftSequence: opts.draftSequence,
composeState: opts.composerState || OPEN, composeState: opts.composerState || OPEN,
action: opts.action, action: opts.action,
topic: opts.topic, topic: opts.topic,
targetRecipients: opts.usernames || opts.recipients, targetUsernames: opts.usernames,
composerTotalOpened: opts.composerTime, composerTotalOpened: opts.composerTime,
typingTime: opts.typingTime, typingTime: opts.typingTime,
whisper: opts.whisper, whisper: opts.whisper,

View File

@ -71,20 +71,20 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
}, },
composePrivateMessage(user, post) { composePrivateMessage(user, post) {
const recipients = user ? user.get("username") : ""; const recipient = user ? user.get("username") : "",
const reply = post reply = post
? `${window.location.protocol}//${window.location.host}${post.url}` ? `${window.location.protocol}//${window.location.host}${post.url}`
: null; : null,
const title = post title = post
? I18n.t("composer.reference_topic_title", { ? I18n.t("composer.reference_topic_title", {
title: post.topic.title title: post.topic.title
}) })
: null; : null;
// used only once, one less dependency // used only once, one less dependency
return this.controllerFor("composer").open({ return this.controllerFor("composer").open({
action: Composer.PRIVATE_MESSAGE, action: Composer.PRIVATE_MESSAGE,
recipients, usernames: recipient,
archetypeId: "private_message", archetypeId: "private_message",
draftKey: Composer.NEW_PRIVATE_MESSAGE_KEY, draftKey: Composer.NEW_PRIVATE_MESSAGE_KEY,
reply, reply,
@ -221,8 +221,8 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
); );
}, },
createNewMessageViaParams(recipients, title, body) { createNewMessageViaParams(username, title, body) {
this.openComposerWithMessageParams(recipients, title, body); this.openComposerWithMessageParams(username, title, body);
} }
}, },

View File

@ -53,7 +53,7 @@
{{#if model.creatingPrivateMessage}} {{#if model.creatingPrivateMessage}}
<div class='user-selector'> <div class='user-selector'>
{{composer-user-selector topicId=topicModel.id {{composer-user-selector topicId=topicModel.id
usernames=model.targetRecipients usernames=model.targetUsernames
hasGroups=model.hasTargetGroups hasGroups=model.hasTargetGroups
focusTarget=focusTarget focusTarget=focusTarget
class="users-input"}} class="users-input"}}

View File

@ -675,9 +675,7 @@ class PostsController < ApplicationController
:topic_id, :topic_id,
:archetype, :archetype,
:category, :category,
# TODO remove together with 'targetUsername' deprecations
:target_usernames, :target_usernames,
:target_recipients,
:reply_to_post_number, :reply_to_post_number,
:auto_track, :auto_track,
:typing_duration_msecs, :typing_duration_msecs,
@ -751,19 +749,13 @@ class PostsController < ApplicationController
result[:user_agent] = request.user_agent result[:user_agent] = request.user_agent
result[:referrer] = request.env["HTTP_REFERER"] result[:referrer] = request.env["HTTP_REFERER"]
if recipients = result[:target_usernames] if usernames = result[:target_usernames]
Discourse.deprecate("`target_usernames` is deprecated, use `target_recipients` instead.", output_in_test: true) usernames = usernames.split(",")
else groups = Group.messageable(current_user).where('name in (?)', usernames).pluck('name')
recipients = result[:target_recipients] usernames -= groups
end emails = usernames.select { |user| user.match(/@/) }
usernames -= emails
if recipients result[:target_usernames] = usernames.join(",")
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(",")
result[:target_emails] = emails.join(",") result[:target_emails] = emails.join(",")
result[:target_group_names] = groups.join(",") result[:target_group_names] = groups.join(",")
end end

View File

@ -396,15 +396,3 @@ QUnit.test("allows featured link before choosing a category", assert => {
); );
assert.ok(composer.get("canEditTopicFeaturedLink"), "can paste link"); assert.ok(composer.get("canEditTopicFeaturedLink"), "can paste link");
}); });
QUnit.test("targetRecipientsArray contains types", assert => {
let composer = createComposer({
targetRecipients: "test,codinghorror,staff,foo@bar.com"
});
assert.ok(composer.targetRecipientsArray, [
{ type: "group", name: "test" },
{ type: "user", name: "codinghorror" },
{ type: "group", name: "staff" },
{ type: "email", name: "foo@bar.com" }
]);
});