mirror of https://github.com/zulip/zulip.git
compose: Change needs_subscribe_warning to use user_id.
This commit changes the needs_subscribe_warning function to use user_id instead of emails. This change is done because user_ids are immutable and using user_ids is the correct way to uniquely identify a user. We already know that user_ids being passed in this function are active user_ids, since they come from typeaheads. So, we only need to call 'people.get_by_user_id', to get the user object from user_id and do not need to check the active status of user, which was done previously using 'get_active_user_for_email'.
This commit is contained in:
parent
f0a19ed8e6
commit
25aed90da1
|
@ -1065,7 +1065,7 @@ run_test('trigger_submit_compose_form', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('needs_subscribe_warning', () => {
|
run_test('needs_subscribe_warning', () => {
|
||||||
people.get_active_user_for_email = function () {
|
people.get_by_user_id = function () {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1082,17 +1082,15 @@ run_test('needs_subscribe_warning', () => {
|
||||||
stream_data.add_sub(sub);
|
stream_data.add_sub(sub);
|
||||||
assert.equal(compose.needs_subscribe_warning(), false);
|
assert.equal(compose.needs_subscribe_warning(), false);
|
||||||
|
|
||||||
people.get_active_user_for_email = function () {
|
people.get_by_user_id = function () {
|
||||||
return {
|
return {
|
||||||
user_id: 99,
|
|
||||||
is_bot: true,
|
is_bot: true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
assert.equal(compose.needs_subscribe_warning(), false);
|
assert.equal(compose.needs_subscribe_warning(), false);
|
||||||
|
|
||||||
people.get_active_user_for_email = function () {
|
people.get_by_user_id = function () {
|
||||||
return {
|
return {
|
||||||
user_id: 99,
|
|
||||||
is_bot: false,
|
is_bot: false,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1136,9 +1134,9 @@ run_test('warn_if_mentioning_unsubscribed_user', () => {
|
||||||
const checks = [
|
const checks = [
|
||||||
(function () {
|
(function () {
|
||||||
let called;
|
let called;
|
||||||
compose.needs_subscribe_warning = function (email) {
|
compose.needs_subscribe_warning = function (user_id) {
|
||||||
called = true;
|
called = true;
|
||||||
assert.equal(email, 'foo@bar.com');
|
assert.equal(user_id, 34);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
return function () { assert(called); };
|
return function () { assert(called); };
|
||||||
|
|
|
@ -740,7 +740,7 @@ exports.handle_keyup = function (event, textarea) {
|
||||||
rtl.set_rtl_class_for_textarea(textarea);
|
rtl.set_rtl_class_for_textarea(textarea);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.needs_subscribe_warning = function (email) {
|
exports.needs_subscribe_warning = function (user_id) {
|
||||||
// This returns true if all of these conditions are met:
|
// This returns true if all of these conditions are met:
|
||||||
// * the user is valid
|
// * the user is valid
|
||||||
// * the stream in the compose box is valid
|
// * the stream in the compose box is valid
|
||||||
|
@ -755,7 +755,7 @@ exports.needs_subscribe_warning = function (email) {
|
||||||
// We expect the caller to already have verified that we're
|
// We expect the caller to already have verified that we're
|
||||||
// sending to a stream and trying to mention the user.
|
// sending to a stream and trying to mention the user.
|
||||||
|
|
||||||
const user = people.get_active_user_for_email(email);
|
const user = people.get_by_user_id(user_id);
|
||||||
const stream_name = compose_state.stream_name();
|
const stream_name = compose_state.stream_name();
|
||||||
|
|
||||||
if (!stream_name) {
|
if (!stream_name) {
|
||||||
|
@ -774,7 +774,7 @@ exports.needs_subscribe_warning = function (email) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream_data.is_user_subscribed(stream_name, user.user_id)) {
|
if (stream_data.is_user_subscribed(stream_name, user_id)) {
|
||||||
// If our user is already subscribed
|
// If our user is already subscribed
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -905,14 +905,13 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const email = mentioned.email;
|
|
||||||
const user_id = mentioned.user_id;
|
const user_id = mentioned.user_id;
|
||||||
|
|
||||||
if (mentioned.is_broadcast) {
|
if (mentioned.is_broadcast) {
|
||||||
return; // don't check if @all/@everyone/@stream
|
return; // don't check if @all/@everyone/@stream
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exports.needs_subscribe_warning(email)) {
|
if (exports.needs_subscribe_warning(user_id)) {
|
||||||
const error_area = $("#compose_invite_users");
|
const error_area = $("#compose_invite_users");
|
||||||
const existing_invites_area = $('#compose_invite_users .compose_invite_user');
|
const existing_invites_area = $('#compose_invite_users .compose_invite_user');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue