compose_state: Rename compost_state.recipient to be about PMs only.

The compose_state.recipient field was only actually the recipient for
the message if it was a private_message_recipient (in the sense of
other code); we store the stream in compose_state.stream instead.

As a result, the name was quite confusing, resulting in the
possibility of problematic correctness bugs where code assumes this
field has a valid value for stream messages.  Fix this by changing it
to compose_state.private_message_recipient for clarity.
This commit is contained in:
Tim Abbott
2019-12-02 08:53:55 -08:00
parent 65270419b9
commit ea7c6d395f
13 changed files with 34 additions and 33 deletions

View File

@@ -176,7 +176,7 @@ function create_message_object() {
if (message.type === "private") {
// TODO: this should be collapsed with the code in composebox_typeahead.js
const recipient = compose_state.recipient();
const recipient = compose_state.private_message_recipient();
const emails = util.extract_pm_recipients(recipient);
message.to = emails;
message.reply_to = recipient;
@@ -372,7 +372,7 @@ exports.do_post_send_tasks = function () {
};
exports.update_email = function (user_id, new_email) {
let reply_to = compose_state.recipient();
let reply_to = compose_state.private_message_recipient();
if (!reply_to) {
return;
@@ -380,11 +380,12 @@ exports.update_email = function (user_id, new_email) {
reply_to = people.update_email_in_reply_to(reply_to, user_id, new_email);
compose_state.recipient(reply_to);
compose_state.private_message_recipient(reply_to);
};
exports.get_invalid_recipient_emails = function () {
const private_recipients = util.extract_pm_recipients(compose_state.recipient());
const private_recipients = util.extract_pm_recipients(
compose_state.private_message_recipient());
const invalid_recipients = _.reject(private_recipients, people.is_valid_email_for_compose);
return invalid_recipients;
@@ -561,7 +562,7 @@ function validate_stream_message() {
// The function checks whether the recipients are users of the realm or cross realm users (bots
// for now)
function validate_private_message() {
if (compose_state.recipient().length === 0) {
if (compose_state.private_message_recipient().length === 0) {
compose_error(i18n.t("Please specify at least one valid recipient"), $("#private_message_recipient"));
return false;
} else if (page_params.realm_is_zephyr_mirror_realm) {