diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index c269067a6f..f0ea9863a4 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -35,7 +35,7 @@ people.add(steve); people.initialize_current_user(me.user_id); function assert_same_operators(result, terms) { - terms = _.map(terms, function (term) { + terms = terms.map(term => { // If negated flag is undefined, we explicitly // set it to false. let negated = term.negated; @@ -508,9 +508,10 @@ run_test('canonicalizations', () => { }); function get_predicate(operators) { - operators = _.map(operators, function (op) { - return {operator: op[0], operand: op[1]}; - }); + operators = operators.map(op => ({ + operator: op[0], + operand: op[1], + })); return new Filter(operators).predicate(); } diff --git a/frontend_tests/node_tests/list_render.js b/frontend_tests/node_tests/list_render.js index f50de7f430..836db6b52f 100644 --- a/frontend_tests/node_tests/list_render.js +++ b/frontend_tests/node_tests/list_render.js @@ -268,7 +268,7 @@ run_test('sorting', () => { }; function html_for(people) { - return _.map(people, opts.modifier).join(''); + return people.map(opts.modifier).join(''); } list_render.create(container, list, opts); diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index ba4b98d086..553d50dff4 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -132,9 +132,9 @@ function config_process_results(messages) { } function message_range(start, end) { - return _.map(_.range(start, end), function (idx) { - return { id: idx }; - }); + return _.range(start, end).map(idx => ({ + id: idx, + })); } const initialize_data = { diff --git a/frontend_tests/node_tests/message_list_data.js b/frontend_tests/node_tests/message_list_data.js index 5c8663c0a8..039db9a878 100644 --- a/frontend_tests/node_tests/message_list_data.js +++ b/frontend_tests/node_tests/message_list_data.js @@ -22,7 +22,7 @@ function make_msg(msg_id) { } function make_msgs(msg_ids) { - return _.map(msg_ids, make_msg); + return msg_ids.map(make_msg); } function assert_contents(mld, msg_ids) { diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js index 77c2ea44c0..3dd6eeb0c5 100644 --- a/frontend_tests/node_tests/message_list_view.js +++ b/frontend_tests/node_tests/message_list_view.js @@ -167,9 +167,7 @@ run_test('merge_message_groups', () => { } function extract_message_ids(lst) { - return _.map(lst, (item) => { - return item.msg.id; - }); + return lst.map(item => item.msg.id); } function assert_message_list_equal(list1, list2) { @@ -184,8 +182,8 @@ run_test('merge_message_groups', () => { } function assert_message_groups_list_equal(list1, list2) { - const ids1 = _.map(list1, extract_group); - const ids2 = _.map(list2, extract_group); + const ids1 = list1.map(extract_group); + const ids2 = list2.map(extract_group); assert(ids1.length); assert.deepEqual(ids1, ids2); } @@ -547,11 +545,9 @@ run_test('render_windows', () => { let messages; function reset_list(opts) { - messages = _.map(_.range(opts.count), function (i) { - return { - id: i, - }; - }); + messages = _.range(opts.count).map(i => ({ + id: i, + })); list.selected_idx = function () { return 0; }; list.clear(); diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 9bc06c0a7b..1c7bc697d0 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -68,13 +68,11 @@ global.people.initialize_current_user(me.user_id); function convert_recipients(people) { // Display_recipient uses `id` for user_ids. - return _.map(people, (p) => { - return { - email: p.email, - id: p.user_id, - full_name: p.full_name, - }; - }); + return people.map(p => ({ + email: p.email, + id: p.user_id, + full_name: p.full_name, + })); } run_test('add_message_metadata', () => { diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.js index ea0c7fe7c2..219143ab8b 100644 --- a/frontend_tests/node_tests/narrow.js +++ b/frontend_tests/node_tests/narrow.js @@ -15,9 +15,10 @@ set_global('page_params', { zrequire('narrow'); function set_filter(operators) { - operators = _.map(operators, function (op) { - return {operator: op[0], operand: op[1]}; - }); + operators = operators.map(op => ({ + operator: op[0], + operand: op[1], + })); narrow_state.set_current_filter(new Filter(operators)); } diff --git a/frontend_tests/node_tests/narrow_state.js b/frontend_tests/node_tests/narrow_state.js index d1aa913730..74f2d41186 100644 --- a/frontend_tests/node_tests/narrow_state.js +++ b/frontend_tests/node_tests/narrow_state.js @@ -10,9 +10,10 @@ set_global('blueslip', global.make_zblueslip()); set_global('page_params', {}); function set_filter(operators) { - operators = _.map(operators, function (op) { - return {operator: op[0], operand: op[1]}; - }); + operators = operators.map(op => ({ + operator: op[0], + operand: op[1], + })); narrow_state.set_current_filter(new Filter(operators)); } diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.js index eecdb49dbe..66f81bd5f0 100644 --- a/frontend_tests/node_tests/topic_list_data.js +++ b/frontend_tests/node_tests/topic_list_data.js @@ -82,9 +82,7 @@ run_test('get_list_info unreads', () => { // Going forward, we just stub get_recent_names // for simpler test setup. topic_data.get_recent_names = () => { - return _.map(_.range(15), (i) => { - return 'topic ' + i; - }); + return _.range(15).map(i => 'topic ' + i); }; const unread_cnt = {}; @@ -111,7 +109,7 @@ run_test('get_list_info unreads', () => { assert.equal(list_info.num_possible_topics, 15); assert.deepEqual( - _.map(list_info.items, (li) => li.topic_name), + list_info.items.map(li => li.topic_name), [ 'topic 0', 'topic 1', @@ -131,7 +129,7 @@ run_test('get_list_info unreads', () => { assert.equal(list_info.num_possible_topics, 15); assert.deepEqual( - _.map(list_info.items, (li) => li.topic_name), + list_info.items.map(li => li.topic_name), [ 'topic 0', 'topic 1', @@ -158,7 +156,7 @@ run_test('get_list_info unreads', () => { assert.equal(list_info.num_possible_topics, 15); assert.deepEqual( - _.map(list_info.items, (li) => li.topic_name), + list_info.items.map(li => li.topic_name), [ 'topic 0', 'topic 1', diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js index c4b8a7f593..2f225db2d9 100644 --- a/frontend_tests/node_tests/typeahead_helper.js +++ b/frontend_tests/node_tests/typeahead_helper.js @@ -24,8 +24,8 @@ let next_id = 0; function assertSameEmails(lst1, lst2) { assert.deepEqual( - _.map(lst1, (r) => r.email), - _.map(lst2, (r) => r.email) + lst1.map(r => r.email), + lst2.map(r => r.email) ); } @@ -209,9 +209,7 @@ function get_typeahead_result(query, current_stream, current_topic) { current_stream, current_topic ); - return _.map(result, function (person) { - return person.email; - }); + return result.map(person => person.email); } run_test('sort_recipients', () => { @@ -363,9 +361,7 @@ run_test('sort_recipients dup bots', () => { const dup_objects = matches.concat([a_bot]); const recipients = th.sort_recipients(dup_objects, "b", "", ""); - const recipients_email = _.map(recipients, function (person) { - return person.email; - }); + const recipients_email = recipients.map(person => person.email); const expected = [ 'b_bot@example.com', 'b_user_3@zulip.net', @@ -402,9 +398,7 @@ run_test('sort_recipients subscribers', () => { // b_user_2 is a subscriber and b_user_1 is not. const small_matches = [b_user_2, b_user_1]; const recipients = th.sort_recipients(small_matches, "b", "Dev", "Dev Topic"); - const recipients_email = _.map(recipients, function (person) { - return person.email; - }); + const recipients_email = recipients.map(person => person.email); const expected = [ 'b_user_2@zulip.net', 'b_user_1@zulip.net', @@ -417,9 +411,7 @@ run_test('sort_recipients pm partners', () => { // both are not subscribered to the stream Linux. const small_matches = [b_user_3, b_user_2]; const recipients = th.sort_recipients(small_matches, "b", "Linux", "Linux Topic"); - const recipients_email = _.map(recipients, function (person) { - return person.email; - }); + const recipients_email = recipients.map(person => person.email); const expected = [ 'b_user_3@zulip.net', 'b_user_2@zulip.net', @@ -438,7 +430,7 @@ run_test('sort broadcast mentions', () => { ''); assert.deepEqual( - _.map(results, (r) => r.email), + results.map(r => r.email), ['all', 'everyone', 'stream'] ); @@ -455,7 +447,7 @@ run_test('sort broadcast mentions', () => { ''); assert.deepEqual( - _.map(results2, (r) => r.email), + results2.map(r => r.email), ['all', 'everyone', 'stream', @@ -715,9 +707,7 @@ run_test('sort_slash_commands', () => { run_test('sort_recipientbox_typeahead', () => { let recipients = th.sort_recipientbox_typeahead("b, a", matches, ""); // search "a" - let recipients_email = _.map(recipients, function (person) { - return person.email; - }); + let recipients_email = recipients.map(person => person.email); assert.deepEqual(recipients_email, [ 'a_user@zulip.org', // matches "a" 'a_bot@zulip.com', // matches "a" @@ -729,9 +719,7 @@ run_test('sort_recipientbox_typeahead', () => { ]); recipients = th.sort_recipientbox_typeahead("b, a, b", matches, ""); // search "b" - recipients_email = _.map(recipients, function (person) { - return person.email; - }); + recipients_email = recipients.map(person => person.email); assert.deepEqual(recipients_email, [ 'b_bot@example.com', 'b_user_3@zulip.net', diff --git a/frontend_tests/node_tests/vdom.js b/frontend_tests/node_tests/vdom.js index 4725e42353..b5b081c275 100644 --- a/frontend_tests/node_tests/vdom.js +++ b/frontend_tests/node_tests/vdom.js @@ -97,9 +97,7 @@ function make_child(i, name) { } function make_children(lst) { - return _.map(lst, (i) => { - return make_child(i, 'foo' + i); - }); + return lst.map(i => make_child(i, 'foo' + i)); } run_test('children', () => { diff --git a/frontend_tests/zjsunit/i18n.js b/frontend_tests/zjsunit/i18n.js index eee0468746..ba3d7f3bed 100644 --- a/frontend_tests/zjsunit/i18n.js +++ b/frontend_tests/zjsunit/i18n.js @@ -17,7 +17,7 @@ exports.t = function (str, context) { */ const keyword_regex = /__(- )?(\w)+__/g; const keys_in_str = str.match(keyword_regex) || []; - const substitutions = _.map(keys_in_str, function (key) { + const substitutions = keys_in_str.map(key => { let prefix_length; if (key.startsWith("__- ")) { prefix_length = 4; diff --git a/frontend_tests/zjsunit/mdiff.js b/frontend_tests/zjsunit/mdiff.js index 60f9b63094..a8b585913f 100644 --- a/frontend_tests/zjsunit/mdiff.js +++ b/frontend_tests/zjsunit/mdiff.js @@ -118,7 +118,7 @@ function diff_strings(string_0, string_1) { const emphasize_codes = (string) => { return "\u001b[34m" + string.slice(0, 1) + "\u001b[0m" + string.slice(1); }; - output_lines = _.map(output_lines, emphasize_codes); + output_lines = output_lines.map(emphasize_codes); return output_lines.join("\n"); } diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 0095ee83f4..c357bd0ada 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -524,13 +524,9 @@ exports.make_zjquery = function (opts) { zjquery.state = function () { // useful for debugging - let res = _.map(elems, function (v) { - return v.debug(); - }); + let res = elems.map(v => v.debug()); - res = _.map(res, function (v) { - return [v.selector, v.value, v.shown]; - }); + res = res.map(v => [v.selector, v.value, v.shown]); res.sort(); diff --git a/static/js/activity.js b/static/js/activity.js index ffb93ecc88..0aa8275c1a 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -128,15 +128,13 @@ exports.get_huddles = function () { }; function huddle_split(huddle) { - return _.map(huddle.split(','), function (s) { - return parseInt(s, 10); - }); + return huddle.split(',').map(s => parseInt(s, 10)); } exports.full_huddle_name = function (huddle) { const user_ids = huddle_split(huddle); - const names = _.map(user_ids, function (user_id) { + const names = user_ids.map(user_id => { const person = people.get_by_user_id(user_id); return person.full_name; }); @@ -148,7 +146,7 @@ exports.short_huddle_name = function (huddle) { const user_ids = huddle_split(huddle); const num_to_show = 3; - let names = _.map(user_ids, function (user_id) { + let names = user_ids.map(user_id => { const person = people.get_by_user_id(user_id); return person.full_name; }); @@ -246,15 +244,13 @@ exports.update_huddles = function () { return; } - const group_pms = _.map(huddles, function (huddle) { - return { - user_ids_string: huddle, - name: exports.full_huddle_name(huddle), - href: hash_util.huddle_with_uri(huddle), - fraction_present: buddy_data.huddle_fraction_present(huddle), - short_name: exports.short_huddle_name(huddle), - }; - }); + const group_pms = huddles.map(huddle => ({ + user_ids_string: huddle, + name: exports.full_huddle_name(huddle), + href: hash_util.huddle_with_uri(huddle), + fraction_present: buddy_data.huddle_fraction_present(huddle), + short_name: exports.short_huddle_name(huddle), + })); const html = render_group_pms({group_pms: group_pms}); ui.get_content_element($('#group-pms')).html(html); diff --git a/static/js/bot_data.js b/static/js/bot_data.js index 71f6a84cb9..9a4a915cd7 100644 --- a/static/js/bot_data.js +++ b/static/js/bot_data.js @@ -26,9 +26,7 @@ exports.add = function bot_data__add(bot) { const clean_bot = _.pick(bot, bot_fields); bots.set(bot.user_id, clean_bot); set_can_admin(clean_bot); - const clean_services = _.map(bot.services, function (service) { - return _.pick(service, services_fields); - }); + const clean_services = bot.services.map(service => _.pick(service, services_fields)); services.set(bot.user_id, clean_services); send_change_event(); diff --git a/static/js/buddy_data.js b/static/js/buddy_data.js index 5daf225ca0..c1e4f6d15e 100644 --- a/static/js/buddy_data.js +++ b/static/js/buddy_data.js @@ -118,13 +118,9 @@ function filter_user_ids(filter_text, user_ids) { user_ids = _.reject(user_ids, people.is_my_user_id); let search_terms = filter_text.toLowerCase().split(/[|,]+/); - search_terms = _.map(search_terms, function (s) { - return s.trim(); - }); + search_terms = search_terms.map(s => s.trim()); - const persons = _.map(user_ids, function (user_id) { - return people.get_by_user_id(user_id); - }); + const persons = user_ids.map(user_id => people.get_by_user_id(user_id)); const user_id_dict = people.filter_people_by_search_terms(persons, search_terms); return Array.from(user_id_dict.keys()); @@ -330,7 +326,7 @@ exports.get_filtered_and_sorted_user_ids = function (filter_text) { }; exports.get_items_for_users = function (user_ids) { - const user_info = _.map(user_ids, exports.info_for); + const user_info = user_ids.map(exports.info_for); compose_fade.update_user_info(user_info, fade_config); return user_info; }; diff --git a/static/js/compose_ui.js b/static/js/compose_ui.js index 1246bc0067..7b3d20531c 100644 --- a/static/js/compose_ui.js +++ b/static/js/compose_ui.js @@ -92,7 +92,7 @@ exports.compute_placeholder_text = function (opts) { // For Private Messages if (opts.private_message_recipient) { const recipient_list = opts.private_message_recipient.split(","); - const recipient_names = _.map(recipient_list, (recipient) => { + const recipient_names = recipient_list.map(recipient => { const user = people.get_by_email(recipient); return user.full_name; }).join(", "); diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index 17997885e9..1f85c91561 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -325,19 +325,22 @@ exports.tokenize_compose_str = function (s) { }; exports.broadcast_mentions = function () { - return _.map(['all', 'everyone', 'stream'], function (mention, idx) { - return { - special_item_text: i18n.t("__wildcard_mention_token__ (Notify stream)", - {wildcard_mention_token: mention}), - email: mention, - // Always sort above, under the assumption that names will - // be longer and only contain "all" as a substring. - pm_recipient_count: Infinity, - full_name: mention, - is_broadcast: true, - idx: idx, // used for sorting - }; - }); + return ['all', 'everyone', 'stream'].map((mention, idx) => ({ + special_item_text: i18n.t("__wildcard_mention_token__ (Notify stream)", + {wildcard_mention_token: mention}), + + email: mention, + + // Always sort above, under the assumption that names will + // be longer and only contain "all" as a substring. + pm_recipient_count: Infinity, + + full_name: mention, + is_broadcast: true, + + // used for sorting + idx: idx, + })); }; function filter_mention_name(current_token) { diff --git a/static/js/drafts.js b/static/js/drafts.js index 90c612be5b..509918fdbb 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -228,7 +228,7 @@ exports.format_draft = function (draft) { }; } else { const emails = util.extract_pm_recipients(draft.private_message_recipient); - const recipients = _.map(emails, function (email) { + const recipients = emails.map(email => { email = email.trim(); const person = people.get_by_email(email); if (person !== undefined) { @@ -305,7 +305,7 @@ exports.launch = function () { return draft_b.updatedAt - draft_a.updatedAt; }); - const sorted_formatted_drafts = _.filter(_.map(sorted_raw_drafts, exports.format_draft)); + const sorted_formatted_drafts = _.filter(sorted_raw_drafts.map(exports.format_draft)); return sorted_formatted_drafts; } diff --git a/static/js/echo.js b/static/js/echo.js index f73645091f..d1229825dd 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -51,7 +51,7 @@ exports.build_display_recipient = function (message) { const emails = util.extract_pm_recipients(message.private_message_recipient); let sender_in_display_recipients = false; - const display_recipient = _.map(emails, function (email) { + const display_recipient = emails.map(email => { email = email.trim(); const person = people.get_by_email(email); if (person === undefined) { diff --git a/static/js/fenced_code.js b/static/js/fenced_code.js index 959cb07205..e809b2ee54 100644 --- a/static/js/fenced_code.js +++ b/static/js/fenced_code.js @@ -42,9 +42,7 @@ function wrap_quote(text) { // beginning of each line for (const paragraph of paragraphs) { const lines = paragraph.split('\n'); - quoted_paragraphs.push(_.map( - _.reject(lines, function (line) { return line === ''; }), - function (line) { return '> ' + line; }).join('\n')); + quoted_paragraphs.push(_.reject(lines, function (line) { return line === ''; }).map(line => '> ' + line).join('\n')); } return quoted_paragraphs.join('\n\n'); diff --git a/static/js/filter.js b/static/js/filter.js index fdd1a876fa..9ed0035cb4 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -310,7 +310,7 @@ Filter.parse = function (str) { might need to support multiple operators of the same type. */ Filter.unparse = function (operators) { - const parts = _.map(operators, function (elem) { + const parts = operators.map(elem => { if (elem.operator === 'search') { // Search terms are the catch-all case. @@ -481,13 +481,11 @@ Filter.prototype = { }, _canonicalize_operators: function (operators_mixed_case) { - return _.map(operators_mixed_case, function (tuple) { - return Filter.canonicalize_term(tuple); - }); + return operators_mixed_case.map(tuple => Filter.canonicalize_term(tuple)); }, filter_with_new_topic: function (new_topic) { - const terms = _.map(this._operators, function (term) { + const terms = this._operators.map(term => { const new_term = _.clone(term); if (new_term.operator === 'topic' && !new_term.negated) { new_term.operand = new_topic; @@ -503,7 +501,7 @@ Filter.prototype = { sorted_term_types: function () { const terms = this._operators; - const term_types = _.map(terms, Filter.term_type); + const term_types = terms.map(Filter.term_type); const sorted_terms = Filter.sorted_term_types(term_types); return sorted_terms; }, @@ -712,7 +710,7 @@ function describe_unescaped(operators) { } } - const more_parts = _.map(operators, function (elem) { + const more_parts = operators.map(elem => { const operand = elem.operand; const canonicalized_operator = Filter.canonicalize_operator(elem.operator); if (canonicalized_operator === 'is') { diff --git a/static/js/floating_recipient_bar.js b/static/js/floating_recipient_bar.js index 593b5fb139..e5af1f9022 100644 --- a/static/js/floating_recipient_bar.js +++ b/static/js/floating_recipient_bar.js @@ -175,7 +175,7 @@ exports.relevant_recipient_bars = function () { return []; } - const items = _.map(elems, function (elem, i) { + const items = elems.map((elem, i) => { let date_html; let need_frb; diff --git a/static/js/info_overlay.js b/static/js/info_overlay.js index c14ae469ac..7d87e26889 100644 --- a/static/js/info_overlay.js +++ b/static/js/info_overlay.js @@ -22,7 +22,7 @@ exports.set_up_toggler = function () { const elem = exports.toggler.get(); elem.addClass('large allow-overflow'); - const modals = _.map(opts.values, function (item) { + const modals = opts.values.map(item => { const key = item.key; // e.g. message-formatting const modal = $('#' + key).find('.modal-body'); return modal; diff --git a/static/js/message_events.js b/static/js/message_events.js index caf6811cb5..c1df884790 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -34,7 +34,7 @@ function maybe_add_narrowed_messages(messages, msg_list) { // edited in between when they sent the message and when // we hear back from the server and can echo the new // message. Arguably, it's counterproductive complexity. - new_messages = _.map(new_messages, message_store.add_message_metadata); + new_messages = new_messages.map(message_store.add_message_metadata); message_util.add_new_messages(new_messages, msg_list); unread_ops.process_visible(); @@ -54,7 +54,7 @@ function maybe_add_narrowed_messages(messages, msg_list) { exports.insert_new_messages = function insert_new_messages(messages, sent_by_this_client) { - messages = _.map(messages, message_store.add_message_metadata); + messages = messages.map(message_store.add_message_metadata); unread.process_loaded_messages(messages); diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index 0e5dde2009..477cf1803f 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -26,7 +26,7 @@ function process_result(data, opts) { } _.each(messages, message_store.set_message_booleans); - messages = _.map(messages, message_store.add_message_metadata); + messages = messages.map(message_store.add_message_metadata); // In case any of the newly fetched messages are new, add them to // our unread data structures. It's important that this run even @@ -118,7 +118,7 @@ function handle_operators_supporting_id_based_api(data) { } data.narrow = JSON.parse(data.narrow); - data.narrow = _.map(data.narrow, function (filter) { + data.narrow = data.narrow.map(filter => { if (operators_supporting_ids.includes(filter.operator)) { filter.operand = people.emails_strings_to_user_ids_array(filter.operand); } diff --git a/static/js/message_flags.js b/static/js/message_flags.js index e1b5207e72..8c58b08de3 100644 --- a/static/js/message_flags.js +++ b/static/js/message_flags.js @@ -19,9 +19,7 @@ exports.send_read = (function () { const real_msgs = _.filter(queue, function (msg) { return !msg.locally_echoed; }); - const real_msg_ids = _.map(real_msgs, function (msg) { - return msg.id; - }); + const real_msg_ids = real_msgs.map(msg => msg.id); if (real_msg_ids.length === 0) { setTimeout(start, 100); diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 23679dcdea..b38b6dbc88 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -684,7 +684,7 @@ MessageListView.prototype = { // all messages lists. To prevent having both list views overwriting // each others data we will make a new message object to add data to // for rendering. - const message_containers = _.map(messages, function (message) { + const message_containers = messages.map(message => { if (message.starred) { message.starred_status = i18n.t("Unstar"); } else { @@ -793,9 +793,7 @@ MessageListView.prototype = { if (message_actions.append_messages.length > 0) { last_message_row = table.find('.message_row').last().expectOne(); last_group_row = rows.get_message_recipient_row(last_message_row); - dom_messages = $(_.map(message_actions.append_messages, function (message_container) { - return self._get_message_template(message_container); - }).join('')).filter('.message_row'); + dom_messages = $(message_actions.append_messages.map(message_container => self._get_message_template(message_container)).join('')).filter('.message_row'); self._post_process(dom_messages); last_group_row.append(dom_messages); @@ -1233,9 +1231,7 @@ MessageListView.prototype = { const self = this; // Convert messages to list messages - let message_containers = _.map(messages, function (message) { - return self.message_containers[message.id]; - }); + let message_containers = messages.map(message => self.message_containers[message.id]); // We may not have the message_container if the stream or topic was muted message_containers = _.reject(message_containers, function (message_container) { return message_container === undefined; diff --git a/static/js/message_store.js b/static/js/message_store.js index 8d1476f33b..83899a2625 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -39,7 +39,7 @@ exports.get_pm_emails = function (message) { } const user_ids = people.pm_with_user_ids(message); - const emails = _.map(user_ids, email).sort(); + const emails = user_ids.map(email).sort(); return emails.join(', '); }; @@ -56,7 +56,7 @@ exports.get_pm_full_names = function (message) { } const user_ids = people.pm_with_user_ids(message); - const names = _.map(user_ids, name).sort(); + const names = user_ids.map(name).sort(); return names.join(', '); }; diff --git a/static/js/narrow.js b/static/js/narrow.js index 46724cad79..46613a870a 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -115,8 +115,7 @@ exports.activate = function (raw_operators, opts) { notifications.hide_history_limit_message(); $(".all-messages-search-caution").hide(); - blueslip.debug("Narrowed", {operators: _.map(operators, - function (e) { return e.operator; }), + blueslip.debug("Narrowed", {operators: operators.map(e => e.operator), trigger: opts ? opts.trigger : undefined, previous_id: current_msg_list.selected_id()}); diff --git a/static/js/people.js b/static/js/people.js index 4f40692350..bc76c8132f 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -38,9 +38,7 @@ exports.init = function () { exports.init(); function split_to_ints(lst) { - return _.map(lst.split(','), function (s) { - return parseInt(s, 10); - }); + return lst.split(',').map(s => parseInt(s, 10)); } exports.get_by_user_id = function (user_id) { @@ -137,9 +135,7 @@ exports.huddle_string = function (message) { return; } - let user_ids = _.map(message.display_recipient, function (recip) { - return recip.id; - }); + let user_ids = message.display_recipient.map(recip => recip.id); function is_huddle_recip(user_id) { return user_id && @@ -161,11 +157,9 @@ exports.huddle_string = function (message) { exports.user_ids_string_to_emails_string = function (user_ids_string) { const user_ids = split_to_ints(user_ids_string); - let emails = _.map(user_ids, function (user_id) { + let emails = user_ids.map(user_id => { const person = people_by_user_id_dict.get(user_id); - if (person) { - return person.email; - } + return person && person.email; }); if (!_.all(emails)) { @@ -173,9 +167,7 @@ exports.user_ids_string_to_emails_string = function (user_ids_string) { return; } - emails = _.map(emails, function (email) { - return email.toLowerCase(); - }); + emails = emails.map(email => email.toLowerCase()); emails.sort(); @@ -184,9 +176,7 @@ exports.user_ids_string_to_emails_string = function (user_ids_string) { exports.user_ids_string_to_ids_array = function (user_ids_string) { const user_ids = user_ids_string.split(','); - const ids = _.map(user_ids, function (id) { - return Number(id); - }); + const ids = user_ids.map(id => Number(id)); return ids; }; @@ -206,11 +196,9 @@ exports.reply_to_to_user_ids_string = function (emails_string) { // invalid data. const emails = emails_string.split(','); - let user_ids = _.map(emails, function (email) { + let user_ids = emails.map(email => { const person = exports.get_by_email(email); - if (person) { - return person.user_id; - } + return person && person.user_id; }); if (!_.all(user_ids)) { @@ -264,11 +252,9 @@ exports.emails_strings_to_user_ids_string = function (emails_string) { }; exports.email_list_to_user_ids_string = function (emails) { - let user_ids = _.map(emails, function (email) { + let user_ids = emails.map(email => { const person = exports.get_by_email(email); - if (person) { - return person.user_id; - } + return person && person.user_id; }); if (!_.all(user_ids)) { @@ -282,11 +268,9 @@ exports.email_list_to_user_ids_string = function (emails) { }; exports.safe_full_names = function (user_ids) { - let names = _.map(user_ids, function (user_id) { + let names = user_ids.map(user_id => { const person = people_by_user_id_dict.get(user_id); - if (person) { - return person.full_name; - } + return person && person.full_name; }); names = _.filter(names); @@ -309,7 +293,7 @@ exports.get_recipients = function (user_ids_string) { return exports.my_full_name(); } - const names = _.map(other_ids, exports.get_full_name).sort(); + const names = other_ids.map(exports.get_full_name).sort(); return names.join(', '); }; @@ -330,7 +314,7 @@ exports.pm_reply_to = function (message) { return; } - const emails = _.map(user_ids, function (user_id) { + const emails = user_ids.map(user_id => { const person = people_by_user_id_dict.get(user_id); if (!person) { blueslip.error('Unknown user id in message: ' + user_id); @@ -386,9 +370,7 @@ exports.all_user_ids_in_pm = function (message) { return; } - let user_ids = _.map(message.display_recipient, function (recip) { - return recip.id; - }); + let user_ids = message.display_recipient.map(recip => recip.id); user_ids = sort_numerically(user_ids); return user_ids; @@ -404,9 +386,7 @@ exports.pm_with_user_ids = function (message) { return; } - const user_ids = _.map(message.display_recipient, function (recip) { - return recip.id; - }); + const user_ids = message.display_recipient.map(recip => recip.id); return sorted_other_user_ids(user_ids); }; @@ -421,9 +401,7 @@ exports.group_pm_with_user_ids = function (message) { return; } - const user_ids = _.map(message.display_recipient, function (recip) { - return recip.id; - }); + const user_ids = message.display_recipient.map(recip => recip.id); const is_user_present = _.some(user_ids, function (user_id) { return exports.is_my_user_id(user_id); }); @@ -488,9 +466,7 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) { // and we don't warn on any errors. let emails = reply_to.split(','); - const persons = _.map(emails, function (email) { - return people_dict.get(email.trim()); - }); + const persons = emails.map(email => people_dict.get(email.trim())); if (!_.all(persons)) { return reply_to; @@ -504,7 +480,7 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) { return reply_to; } - emails = _.map(persons, function (person) { + emails = persons.map(person => { if (person.user_id === user_id) { return new_email; } @@ -516,10 +492,8 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) { exports.pm_with_operand_ids = function (operand) { let emails = operand.split(','); - emails = _.map(emails, function (email) { return email.trim(); }); - let persons = _.map(emails, function (email) { - return people_dict.get(email); - }); + emails = emails.map(email => email.trim()); + let persons = emails.map(email => people_dict.get(email)); // If your email is included in a PM group with other people, just ignore it if (persons.length > 1) { @@ -530,9 +504,7 @@ exports.pm_with_operand_ids = function (operand) { return; } - let user_ids = _.map(persons, function (person) { - return person.user_id; - }); + let user_ids = persons.map(person => person.user_id); user_ids = sort_numerically(user_ids); @@ -788,9 +760,7 @@ exports.get_message_people = function () { semantics */ const message_people = _.compact( - _.map(message_store.user_ids(), (user_id) => { - return people_by_user_id_dict.get(user_id); - }) + message_store.user_ids().map(user_id => people_by_user_id_dict.get(user_id)) ); return message_people; @@ -835,7 +805,7 @@ exports.build_person_matcher = function (query) { query = query.trim(); const termlets = query.toLowerCase().split(/\s+/); - const termlet_matchers = _.map(termlets, exports.build_termlet_matcher); + const termlet_matchers = termlets.map(exports.build_termlet_matcher); return function (user) { const email = user.email.toLowerCase(); @@ -855,9 +825,7 @@ exports.filter_people_by_search_terms = function (users, search_terms) { // Build our matchers outside the loop to avoid some // search overhead that is not user-specific. - const matchers = _.map(search_terms, function (search_term) { - return exports.build_person_matcher(search_term); - }); + const matchers = search_terms.map(search_term => exports.build_person_matcher(search_term)); // Loop through users and populate filtered_users only // if they include search_terms diff --git a/static/js/pm_list_dom.js b/static/js/pm_list_dom.js index 0bf1b4d628..20cc0f392d 100644 --- a/static/js/pm_list_dom.js +++ b/static/js/pm_list_dom.js @@ -26,7 +26,7 @@ exports.pm_ul = (convos) => { ]; return vdom.ul({ attrs: attrs, - keyed_nodes: _.map(convos, exports.keyed_pm_li), + keyed_nodes: convos.map(exports.keyed_pm_li), }); }; diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index 6f5e1c8cf0..2bf4a9f347 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -45,11 +45,9 @@ function format_as_suggestion(terms) { } function compare_by_huddle(huddle) { - huddle = _.map(huddle.slice(0, -1), function (person) { + huddle = huddle.slice(0, -1).map(person => { person = people.get_by_email(person); - if (person) { - return person.user_id; - } + return person && person.user_id; }); // Construct dict for all huddles, so we can lookup each's recency @@ -99,7 +97,7 @@ function get_stream_suggestions(last, operators) { const regex = typeahead_helper.build_highlight_regex(query); const hilite = typeahead_helper.highlight_with_escaping_and_regex; - const objs = _.map(streams, function (stream) { + const objs = streams.map(stream => { const prefix = 'stream'; const highlighted_stream = hilite(regex, stream); const verb = last.negated ? 'exclude ' : ''; @@ -160,7 +158,7 @@ function get_group_suggestions(last, operators) { const highlight_person = make_person_highlighter(last_part); - const suggestions = _.map(persons, function (person) { + const suggestions = persons.map(person => { const term = { operator: 'pm-with', operand: all_but_last_part + ',' + person.email, @@ -240,7 +238,7 @@ function get_person_suggestions(people_getter, last, operators, autocomplete_ope const highlight_person = make_person_highlighter(query); - const objs = _.map(persons, function (person) { + const objs = persons.map(person => { const name = highlight_person(person); const description = prefix + ' ' + name; const terms = [{ @@ -363,7 +361,7 @@ function get_topic_suggestions(last, operators) { // care about case. topics.sort(); - return _.map(topics, function (topic) { + return topics.map(topic => { const topic_term = {operator: 'topic', operand: topic, negated: negated}; const operators = suggest_operators.concat([topic_term]); return format_as_suggestion(operators); @@ -394,13 +392,11 @@ function get_special_filter_suggestions(last, operators, suggestions) { // Negating suggestions on is_search_operand_negated is required for // suggesting negated operators. if (last.negated || is_search_operand_negated) { - suggestions = _.map(suggestions, function (suggestion) { - return { - search_string: '-' + suggestion.search_string, - description: 'exclude ' + suggestion.description, - invalid: suggestion.invalid, - }; - }); + suggestions = suggestions.map(suggestion => ({ + search_string: '-' + suggestion.search_string, + description: 'exclude ' + suggestion.description, + invalid: suggestion.invalid, + })); } const last_string = Filter.unparse([last]).toLowerCase(); @@ -583,7 +579,7 @@ function get_operator_suggestions(last) { return common.phrase_match(last_operand, choice); }); - return _.map(choices, function (choice) { + return choices.map(choice => { const op = [{operator: choice, operand: '', negated: negated}]; return format_as_suggestion(op); }); @@ -848,9 +844,7 @@ exports.finalize_search_result = function (result) { lookup_table[obj.search_string] = obj; } - const strings = _.map(result, function (obj) { - return obj.search_string; - }); + const strings = result.map(obj => obj.search_string); return { strings: strings, lookup_table: lookup_table, diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 744233d2d6..08f8c59ee7 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -373,9 +373,9 @@ exports.populate_realm_domains = function (realm_domains) { return; } - const domains_list = _.map(realm_domains, function (realm_domain) { - return realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain; - }); + const domains_list = realm_domains.map( + realm_domain => realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain + ); let domains = domains_list.join(', '); if (domains.length === 0) { domains = i18n.t("None"); diff --git a/static/js/stream_create.js b/static/js/stream_create.js index e8d1251617..1acff71640 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -101,11 +101,9 @@ function ajaxSubscribeForCreation(stream_name, description, user_ids, invite_onl stream_post_policy, announce, history_public_to_subscribers) { // TODO: We can eliminate the user_ids -> principals conversion // once we upgrade the backend to accept user_ids. - const persons = _.compact(_.map(user_ids, (user_id) => { - return people.get_by_user_id(user_id); - })); + const persons = _.compact(user_ids.map(user_id => people.get_by_user_id(user_id))); - const principals = _.map(persons, (person) => person.email); + const principals = persons.map(person => person.email); // Subscribe yourself and possible other people to a new stream. return channel.post({ diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 2e3a79c397..e547498234 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -344,8 +344,8 @@ exports.get_invite_stream_data = function () { default_stream: exports.get_default_status(sub.name), }; }; - const invite_stream_data = _.map(exports.subscribed_subs(), filter_stream_data); - const default_stream_data = _.map(page_params.realm_default_streams, filter_stream_data); + const invite_stream_data = exports.subscribed_subs().map(filter_stream_data); + const default_stream_data = page_params.realm_default_streams.map(filter_stream_data); // Since, union doesn't work on array of objects we are using filter const is_included = {}; @@ -462,9 +462,7 @@ exports.home_view_stream_names = function () { const home_view_subs = _.filter(exports.subscribed_subs(), function (sub) { return !sub.is_muted; }); - return _.map(home_view_subs, function (sub) { - return sub.name; - }); + return home_view_subs.map(sub => sub.name); }; exports.canonicalized_name = function (stream_name) { @@ -571,7 +569,7 @@ exports.set_realm_default_streams = function (realm_default_streams) { }; exports.get_default_stream_names = function () { - const streams = _.map(Array.from(default_stream_ids), exports.get_sub_by_id); + const streams = Array.from(default_stream_ids).map(exports.get_sub_by_id); const default_stream_names = _.pluck(streams, 'name'); return default_stream_names; }; diff --git a/static/js/stream_sort.js b/static/js/stream_sort.js index 3d1861653a..1a1b7e1cf4 100644 --- a/static/js/stream_sort.js +++ b/static/js/stream_sort.js @@ -15,9 +15,7 @@ function filter_streams_by_search(streams, search_term) { } let search_terms = search_term.toLowerCase().split(","); - search_terms = _.map(search_terms, function (s) { - return s.trim(); - }); + search_terms = search_terms.map(s => s.trim()); const filtered_streams = _.filter(streams, function (stream) { return _.any(search_terms, function (search_term) { diff --git a/static/js/submessage.js b/static/js/submessage.js index 5acec2359e..223b207fca 100644 --- a/static/js/submessage.js +++ b/static/js/submessage.js @@ -15,12 +15,10 @@ exports.get_message_events = function (message) { return parseInt(m1.id, 10) - parseInt(m2.id, 10); }); - const events = _.map(message.submessages, function (obj) { - return { - sender_id: obj.sender_id, - data: JSON.parse(obj.content), - }; - }); + const events = message.submessages.map(obj => ({ + sender_id: obj.sender_id, + data: JSON.parse(obj.content), + })); return events; }; diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js index 4720244533..91d7b4970c 100644 --- a/static/js/tab_bar.js +++ b/static/js/tab_bar.js @@ -61,7 +61,7 @@ function make_tab_data() { if (filter.has_operator("pm-with")) { const emails = filter.operands("pm-with")[0].split(','); - const names = _.map(emails, function (email) { + const names = emails.map(email => { if (!people.get_by_email(email)) { return email; } diff --git a/static/js/topic_data.js b/static/js/topic_data.js index 6a93b5e4e7..04cf4c542f 100644 --- a/static/js/topic_data.js +++ b/static/js/topic_data.js @@ -154,9 +154,7 @@ exports.topic_history = function (stream_id) { return b.message_id - a.message_id; }); - const names = _.map(recents, function (obj) { - return obj.pretty_name; - }); + const names = recents.map(obj => obj.pretty_name); return names; }; diff --git a/static/js/topic_list.js b/static/js/topic_list.js index 2303f01ed8..1d143e8f26 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -136,8 +136,7 @@ exports.widget = function (parent_elem, my_stream_id) { ['class', 'topic-list'], ]; - const nodes = _.map( - list_info.items, exports.keyed_topic_li); + const nodes = list_info.items.map(exports.keyed_topic_li); if (spinner) { nodes.push(exports.spinner_li()); diff --git a/static/js/unread.js b/static/js/unread.js index 7edb614e73..8c4ea59ac6 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -283,7 +283,7 @@ exports.unread_topic_counter = (function () { return topic_dict.has(topic_name); }); - const result = _.map(topic_names, function (topic_name) { + const result = topic_names.map(topic_name => { const msgs = per_stream_bucketer.get_bucket(topic_name); return { diff --git a/static/js/util.js b/static/js/util.js index eb33aca8d8..315f09f734 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -107,8 +107,8 @@ exports.normalize_recipients = function (recipients) { // Converts a string listing emails of message recipients // into a canonical formatting: emails sorted ASCIIbetically // with exactly one comma and no spaces between each. - recipients = _.map(recipients.split(','), function (s) { return s.trim(); }); - recipients = _.map(recipients, function (s) { return s.toLowerCase(); }); + recipients = recipients.split(',').map(s => s.trim()); + recipients = recipients.map(s => s.toLowerCase()); recipients = _.filter(recipients, function (s) { return s.length > 0; }); recipients.sort(); return recipients.join(','); @@ -249,7 +249,7 @@ function to_int(s) { exports.sorted_ids = function (ids) { // This mapping makes sure we are using ints, and // it also makes sure we don't mutate the list. - let id_list = _.map(ids, to_int); + let id_list = ids.map(to_int); id_list.sort(function (a, b) { return a - b; }); diff --git a/static/js/vdom.js b/static/js/vdom.js index b211372747..63a198969a 100644 --- a/static/js/vdom.js +++ b/static/js/vdom.js @@ -39,9 +39,7 @@ exports.render_tag = (tag) => { */ const opts = tag.opts; const tag_name = tag.tag_name; - const attr_str = _.map(opts.attrs, (attr) => { - return ' ' + attr[0] + '="' + util.escape_html(attr[1]) + '"'; - }).join(''); + const attr_str = opts.attrs.map(attr => ' ' + attr[0] + '="' + util.escape_html(attr[1]) + '"').join(''); const start_tag = '<' + tag_name + attr_str + '>'; const end_tag = ''; @@ -51,9 +49,7 @@ exports.render_tag = (tag) => { return; } - const innards = _.map(opts.keyed_nodes, (node) => { - return node.render(); - }).join('\n'); + const innards = opts.keyed_nodes.map(node => node.render()).join('\n'); return start_tag + '\n' + innards + '\n' + end_tag; };