js: Clean up user_id type confusion.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-01-16 14:40:20 -05:00 committed by Tim Abbott
parent e6178f2abd
commit 1a07f7b158
8 changed files with 21 additions and 24 deletions

View File

@ -28,8 +28,7 @@ function buddy_list_conf() {
};
conf.get_key_from_li = function (opts) {
const str_user_id = opts.li.expectOne().attr('data-user-id');
return parseInt(str_user_id, 10);
return parseInt(opts.li.expectOne().attr('data-user-id'), 10);
};
conf.get_data_from_keys = function (opts) {

View File

@ -499,8 +499,8 @@ exports.initialize = function () {
$('#user_presences').on('mouseenter', '.user-presence-link, .user_sidebar_entry .user_circle, .user_sidebar_entry .selectable_sidebar_block', function (e) {
e.stopPropagation();
const elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
const user_id = elem.attr('data-user-id');
const title_data = buddy_data.get_title_data(user_id, false);
const user_id_string = elem.attr('data-user-id');
const title_data = buddy_data.get_title_data(user_id_string, false);
do_render_buddy_list_tooltip(elem, title_data);
});

View File

@ -20,17 +20,17 @@ function MessageListView(list, table_name, collapse_messages) {
}
function get_user_id_for_mention_button(elem) {
const user_id = $(elem).attr('data-user-id');
const user_id_string = $(elem).attr('data-user-id');
// Handle legacy markdown that was rendered before we cut
// over to using data-user-id.
const email = $(elem).attr('data-user-email');
if (user_id === "*" || email === "*") {
if (user_id_string === "*" || email === "*") {
return "*";
}
if (user_id) {
return parseInt(user_id, 10);
if (user_id_string) {
return parseInt(user_id_string, 10);
}
if (email) {

View File

@ -245,7 +245,6 @@ exports.get_user_time = function (user_id) {
};
exports.get_user_type = function (user_id) {
user_id = parseInt(user_id, 10);
const user_profile = exports.get_person_from_user_id(user_id);
if (user_profile.is_admin) {

View File

@ -720,19 +720,19 @@ exports.register_click_handlers = function () {
});
$("#main_div").on("click", ".user-mention", function (e) {
const id = $(this).attr('data-user-id');
const id_string = $(this).attr('data-user-id');
// We fallback to email to handle legacy markdown that was rendered
// before we cut over to using data-user-id
const email = $(this).attr('data-user-email');
if (id === '*' || email === '*') {
if (id_string === '*' || email === '*') {
return;
}
const row = $(this).closest(".message_row");
e.stopPropagation();
const message = current_msg_list.get(rows.id(row));
let user;
if (id) {
const user_id = parseInt(id, 10);
if (id_string) {
const user_id = parseInt(id_string, 10);
user = people.get_person_from_user_id(user_id);
} else {
user = people.get_by_email(email);
@ -741,7 +741,7 @@ exports.register_click_handlers = function () {
});
$("#main_div").on("click", ".user-group-mention", function (e) {
const id = $(this).attr('data-user-group-id');
const id = parseInt($(this).attr('data-user-group-id'), 10);
const row = $(this).closest(".message_row");
e.stopPropagation();
const message = current_msg_list.get(rows.id(row));

View File

@ -341,7 +341,7 @@ exports.set_up = function () {
});
$("#active_bots_list").on("click", "button.delete_bot", function (e) {
const bot_id = $(e.currentTarget).attr('data-user-id');
const bot_id = parseInt($(e.currentTarget).attr('data-user-id'), 10);
channel.del({
url: '/json/bots/' + encodeURIComponent(bot_id),
@ -356,7 +356,7 @@ exports.set_up = function () {
});
$("#inactive_bots_list").on("click", "button.reactivate_bot", function (e) {
const user_id = $(e.currentTarget).attr('data-user-id');
const user_id = parseInt($(e.currentTarget).attr('data-user-id'), 10);
channel.post({
url: '/json/users/' + encodeURIComponent(user_id) + "/reactivate",
@ -367,7 +367,7 @@ exports.set_up = function () {
});
$("#active_bots_list").on("click", "button.regenerate_bot_api_key", function (e) {
const bot_id = $(e.currentTarget).attr('data-user-id');
const bot_id = parseInt($(e.currentTarget).attr('data-user-id'), 10);
channel.post({
url: '/json/bots/' + encodeURIComponent(bot_id) + '/api_key/regenerate',
idempotent: true,
@ -387,7 +387,7 @@ exports.set_up = function () {
$("#active_bots_list").on("click", "button.open_edit_bot_form", function (e) {
const li = $(e.currentTarget).closest('li');
const bot_id = li.find('.bot_info').attr('data-user-id').valueOf();
const bot_id = parseInt(li.find('.bot_info').attr('data-user-id'), 10);
const bot = bot_data.get(bot_id);
const users_list = people.get_active_human_persons();
$("#edit_bot").empty();
@ -422,7 +422,7 @@ exports.set_up = function () {
errors.hide();
},
submitHandler: function () {
const bot_id = form.attr('data-user-id');
const bot_id = parseInt(form.attr('data-user-id'), 10);
const type = form.attr('data-type');
const full_name = form.find('.edit_bot_name').val();
@ -485,7 +485,7 @@ exports.set_up = function () {
$("#active_bots_list").on("click", "a.download_bot_zuliprc", function () {
const bot_info = $(this).closest(".bot-information-box").find(".bot_info");
const bot_id = bot_info.attr("data-user-id");
const bot_id = parseInt(bot_info.attr("data-user-id"), 10);
$(this).attr("href", exports.generate_zuliprc_uri(bot_id));
});

View File

@ -371,7 +371,7 @@ exports.on_load_success = function (realm_people_data) {
const button_elem = $(e.target);
const row = button_elem.closest(".user_row");
const bot_id = row.attr("data-user-id");
const bot_id = parseInt(row.attr("data-user-id"), 10);
const url = '/json/bots/' + encodeURIComponent(bot_id);
const opts = {
@ -393,7 +393,7 @@ exports.on_load_success = function (realm_people_data) {
// Go up the tree until we find the user row, then grab the email element
const button_elem = $(e.target);
const row = button_elem.closest(".user_row");
const user_id = row.attr("data-user-id");
const user_id = parseInt(row.attr("data-user-id"), 10);
const url = '/json/users/' + encodeURIComponent(user_id) + "/reactivate";
const data = {};
const status = get_status_field();

View File

@ -288,8 +288,7 @@ exports.show_new_stream_modal = function () {
$('#user-checkboxes label.checkbox').each(function () {
const user_elem = $(this);
const str_user_id = user_elem.attr('data-user-id');
const user_id = parseInt(str_user_id, 10);
const user_id = parseInt(user_elem.attr('data-user-id'), 10);
if (subscriber_ids.has(user_id)) {
user_elem.find('input').prop('checked', checked);