compose: Change compose_invite_users template to use data-user-id.

This commit changes the compose_invite_users template to use
data-user-id as property intead of data-useremail.

This is changed to maintain consistency with other parts of the
code where user_ids are used for referring to users.

This also helps in removing some of the checks for the case of
undefined emails.
This commit is contained in:
sahil839
2020-06-04 23:11:45 +05:30
committed by Tim Abbott
parent 48ac1082c1
commit 4b67259294
3 changed files with 13 additions and 20 deletions

View File

@@ -1149,7 +1149,7 @@ run_test('warn_if_mentioning_unsubscribed_user', () => {
global.stub_templates(function (template_name, context) { global.stub_templates(function (template_name, context) {
called = true; called = true;
assert.equal(template_name, 'compose_invite_users'); assert.equal(template_name, 'compose_invite_users');
assert.equal(context.email, 'foo@bar.com'); assert.equal(context.user_id, 34);
assert.equal(context.name, 'Foo Barson'); assert.equal(context.name, 'Foo Barson');
return 'fake-compose-invite-user-template'; return 'fake-compose-invite-user-template';
}); });
@@ -1168,6 +1168,7 @@ run_test('warn_if_mentioning_unsubscribed_user', () => {
mentioned = { mentioned = {
email: 'foo@bar.com', email: 'foo@bar.com',
user_id: 34,
full_name: 'Foo Barson', full_name: 'Foo Barson',
}; };
@@ -1181,9 +1182,9 @@ run_test('warn_if_mentioning_unsubscribed_user', () => {
let looked_for_existing; let looked_for_existing;
warning_row.data = function (field) { warning_row.data = function (field) {
assert.equal(field, 'useremail'); assert.equal(field, 'user-id');
looked_for_existing = true; looked_for_existing = true;
return 'foo@bar.com'; return '34';
}; };
const previous_users = $('#compose_invite_users .compose_invite_user'); const previous_users = $('#compose_invite_users .compose_invite_user');
@@ -1281,18 +1282,12 @@ run_test('on_events', () => {
'.compose_invite_user' '.compose_invite_user'
); );
// .data in zjquery is a noop by default, so handler should just return
handler(helper.event);
assert(!invite_user_to_stream_called);
assert(!helper.container_was_removed());
// !sub will result false here and we check the failure code path. // !sub will result false here and we check the failure code path.
blueslip.expect('warn', 'Stream no longer exists: no-stream'); blueslip.expect('warn', 'Stream no longer exists: no-stream');
$('#stream_message_recipient_stream').val('no-stream'); $('#stream_message_recipient_stream').val('no-stream');
helper.container.data = function (field) { helper.container.data = function (field) {
assert.equal(field, 'useremail'); assert.equal(field, 'user-id');
return mentioned.email; return '34';
}; };
$("#compose-textarea").select(noop); $("#compose-textarea").select(noop);
helper.target.prop('disabled', false); helper.target.prop('disabled', false);

View File

@@ -906,6 +906,7 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) {
} }
const email = mentioned.email; const email = mentioned.email;
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
@@ -916,12 +917,12 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) {
const existing_invites_area = $('#compose_invite_users .compose_invite_user'); const existing_invites_area = $('#compose_invite_users .compose_invite_user');
const existing_invites = Array.from($(existing_invites_area), user_row => { const existing_invites = Array.from($(existing_invites_area), user_row => {
return $(user_row).data('useremail'); return parseInt($(user_row).data('user-id'), 10);
}); });
if (!existing_invites.includes(email)) { if (!existing_invites.includes(user_id)) {
const context = { const context = {
email: email, user_id: user_id,
name: mentioned.full_name, name: mentioned.full_name,
can_subscribe_other_users: page_params.can_subscribe_other_users, can_subscribe_other_users: page_params.can_subscribe_other_users,
}; };
@@ -994,11 +995,8 @@ exports.initialize = function () {
const invite_row = $(event.target).parents('.compose_invite_user'); const invite_row = $(event.target).parents('.compose_invite_user');
const email = $(invite_row).data('useremail'); const user_id = parseInt($(invite_row).data('user-id'), 10);
if (email === undefined) {
return;
}
const user_id = people.get_user_id(email);
function success() { function success() {
const all_invites = $("#compose_invite_users"); const all_invites = $("#compose_invite_users");
invite_row.remove(); invite_row.remove();

View File

@@ -1,4 +1,4 @@
<div class="compose_invite_user" data-useremail="{{email}}"> <div class="compose_invite_user" data-user-id="{{user_id}}">
{{#if can_subscribe_other_users}} {{#if can_subscribe_other_users}}
<p>{{#tr this}}<strong>__name__</strong> is not subscribed to this stream. They will not be notified unless you subscribe them.{{/tr}}</p> <p>{{#tr this}}<strong>__name__</strong> is not subscribed to this stream. They will not be notified unless you subscribe them.{{/tr}}</p>
<div class="compose_invite_user_controls"> <div class="compose_invite_user_controls">