mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
js: Convert _.map(a, …) to a.map(…).
And convert the corresponding function expressions to arrow style
while we’re here.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitCallExpression(path) {
const { callee, arguments: args } = path.node;
if (
n.MemberExpression.check(callee) &&
!callee.computed &&
n.Identifier.check(callee.object) &&
callee.object.name === "_" &&
n.Identifier.check(callee.property) &&
callee.property.name === "map" &&
args.length === 2 &&
checkExpression(args[0]) &&
checkExpression(args[1])
) {
const [arr, fn] = args;
path.replace(
b.callExpression(b.memberExpression(arr, b.identifier("map")), [
n.FunctionExpression.check(fn) ||
n.ArrowFunctionExpression.check(fn)
? b.arrowFunctionExpression(
fn.params,
n.BlockStatement.check(fn.body) &&
fn.body.body.length === 1 &&
n.ReturnStatement.check(fn.body.body[0])
? fn.body.body[0].argument || b.identifier("undefined")
: fn.body
)
: fn,
])
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
719546641f
commit
ac7b09d57e
@@ -35,7 +35,7 @@ people.add(steve);
|
|||||||
people.initialize_current_user(me.user_id);
|
people.initialize_current_user(me.user_id);
|
||||||
|
|
||||||
function assert_same_operators(result, terms) {
|
function assert_same_operators(result, terms) {
|
||||||
terms = _.map(terms, function (term) {
|
terms = terms.map(term => {
|
||||||
// If negated flag is undefined, we explicitly
|
// If negated flag is undefined, we explicitly
|
||||||
// set it to false.
|
// set it to false.
|
||||||
let negated = term.negated;
|
let negated = term.negated;
|
||||||
@@ -508,9 +508,10 @@ run_test('canonicalizations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function get_predicate(operators) {
|
function get_predicate(operators) {
|
||||||
operators = _.map(operators, function (op) {
|
operators = operators.map(op => ({
|
||||||
return {operator: op[0], operand: op[1]};
|
operator: op[0],
|
||||||
});
|
operand: op[1],
|
||||||
|
}));
|
||||||
return new Filter(operators).predicate();
|
return new Filter(operators).predicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ run_test('sorting', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function html_for(people) {
|
function html_for(people) {
|
||||||
return _.map(people, opts.modifier).join('');
|
return people.map(opts.modifier).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
list_render.create(container, list, opts);
|
list_render.create(container, list, opts);
|
||||||
|
|||||||
@@ -132,9 +132,9 @@ function config_process_results(messages) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function message_range(start, end) {
|
function message_range(start, end) {
|
||||||
return _.map(_.range(start, end), function (idx) {
|
return _.range(start, end).map(idx => ({
|
||||||
return { id: idx };
|
id: idx,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialize_data = {
|
const initialize_data = {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function make_msg(msg_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function make_msgs(msg_ids) {
|
function make_msgs(msg_ids) {
|
||||||
return _.map(msg_ids, make_msg);
|
return msg_ids.map(make_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_contents(mld, msg_ids) {
|
function assert_contents(mld, msg_ids) {
|
||||||
|
|||||||
@@ -167,9 +167,7 @@ run_test('merge_message_groups', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function extract_message_ids(lst) {
|
function extract_message_ids(lst) {
|
||||||
return _.map(lst, (item) => {
|
return lst.map(item => item.msg.id);
|
||||||
return item.msg.id;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_message_list_equal(list1, list2) {
|
function assert_message_list_equal(list1, list2) {
|
||||||
@@ -184,8 +182,8 @@ run_test('merge_message_groups', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function assert_message_groups_list_equal(list1, list2) {
|
function assert_message_groups_list_equal(list1, list2) {
|
||||||
const ids1 = _.map(list1, extract_group);
|
const ids1 = list1.map(extract_group);
|
||||||
const ids2 = _.map(list2, extract_group);
|
const ids2 = list2.map(extract_group);
|
||||||
assert(ids1.length);
|
assert(ids1.length);
|
||||||
assert.deepEqual(ids1, ids2);
|
assert.deepEqual(ids1, ids2);
|
||||||
}
|
}
|
||||||
@@ -547,11 +545,9 @@ run_test('render_windows', () => {
|
|||||||
let messages;
|
let messages;
|
||||||
|
|
||||||
function reset_list(opts) {
|
function reset_list(opts) {
|
||||||
messages = _.map(_.range(opts.count), function (i) {
|
messages = _.range(opts.count).map(i => ({
|
||||||
return {
|
|
||||||
id: i,
|
id: i,
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
list.selected_idx = function () { return 0; };
|
list.selected_idx = function () { return 0; };
|
||||||
list.clear();
|
list.clear();
|
||||||
|
|
||||||
|
|||||||
@@ -68,13 +68,11 @@ global.people.initialize_current_user(me.user_id);
|
|||||||
|
|
||||||
function convert_recipients(people) {
|
function convert_recipients(people) {
|
||||||
// Display_recipient uses `id` for user_ids.
|
// Display_recipient uses `id` for user_ids.
|
||||||
return _.map(people, (p) => {
|
return people.map(p => ({
|
||||||
return {
|
|
||||||
email: p.email,
|
email: p.email,
|
||||||
id: p.user_id,
|
id: p.user_id,
|
||||||
full_name: p.full_name,
|
full_name: p.full_name,
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test('add_message_metadata', () => {
|
run_test('add_message_metadata', () => {
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ set_global('page_params', {
|
|||||||
zrequire('narrow');
|
zrequire('narrow');
|
||||||
|
|
||||||
function set_filter(operators) {
|
function set_filter(operators) {
|
||||||
operators = _.map(operators, function (op) {
|
operators = operators.map(op => ({
|
||||||
return {operator: op[0], operand: op[1]};
|
operator: op[0],
|
||||||
});
|
operand: op[1],
|
||||||
|
}));
|
||||||
narrow_state.set_current_filter(new Filter(operators));
|
narrow_state.set_current_filter(new Filter(operators));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ set_global('blueslip', global.make_zblueslip());
|
|||||||
set_global('page_params', {});
|
set_global('page_params', {});
|
||||||
|
|
||||||
function set_filter(operators) {
|
function set_filter(operators) {
|
||||||
operators = _.map(operators, function (op) {
|
operators = operators.map(op => ({
|
||||||
return {operator: op[0], operand: op[1]};
|
operator: op[0],
|
||||||
});
|
operand: op[1],
|
||||||
|
}));
|
||||||
narrow_state.set_current_filter(new Filter(operators));
|
narrow_state.set_current_filter(new Filter(operators));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,9 +82,7 @@ run_test('get_list_info unreads', () => {
|
|||||||
// Going forward, we just stub get_recent_names
|
// Going forward, we just stub get_recent_names
|
||||||
// for simpler test setup.
|
// for simpler test setup.
|
||||||
topic_data.get_recent_names = () => {
|
topic_data.get_recent_names = () => {
|
||||||
return _.map(_.range(15), (i) => {
|
return _.range(15).map(i => 'topic ' + i);
|
||||||
return 'topic ' + i;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const unread_cnt = {};
|
const unread_cnt = {};
|
||||||
@@ -111,7 +109,7 @@ run_test('get_list_info unreads', () => {
|
|||||||
assert.equal(list_info.num_possible_topics, 15);
|
assert.equal(list_info.num_possible_topics, 15);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
_.map(list_info.items, (li) => li.topic_name),
|
list_info.items.map(li => li.topic_name),
|
||||||
[
|
[
|
||||||
'topic 0',
|
'topic 0',
|
||||||
'topic 1',
|
'topic 1',
|
||||||
@@ -131,7 +129,7 @@ run_test('get_list_info unreads', () => {
|
|||||||
assert.equal(list_info.num_possible_topics, 15);
|
assert.equal(list_info.num_possible_topics, 15);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
_.map(list_info.items, (li) => li.topic_name),
|
list_info.items.map(li => li.topic_name),
|
||||||
[
|
[
|
||||||
'topic 0',
|
'topic 0',
|
||||||
'topic 1',
|
'topic 1',
|
||||||
@@ -158,7 +156,7 @@ run_test('get_list_info unreads', () => {
|
|||||||
assert.equal(list_info.num_possible_topics, 15);
|
assert.equal(list_info.num_possible_topics, 15);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
_.map(list_info.items, (li) => li.topic_name),
|
list_info.items.map(li => li.topic_name),
|
||||||
[
|
[
|
||||||
'topic 0',
|
'topic 0',
|
||||||
'topic 1',
|
'topic 1',
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ let next_id = 0;
|
|||||||
|
|
||||||
function assertSameEmails(lst1, lst2) {
|
function assertSameEmails(lst1, lst2) {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
_.map(lst1, (r) => r.email),
|
lst1.map(r => r.email),
|
||||||
_.map(lst2, (r) => r.email)
|
lst2.map(r => r.email)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,9 +209,7 @@ function get_typeahead_result(query, current_stream, current_topic) {
|
|||||||
current_stream,
|
current_stream,
|
||||||
current_topic
|
current_topic
|
||||||
);
|
);
|
||||||
return _.map(result, function (person) {
|
return result.map(person => person.email);
|
||||||
return person.email;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test('sort_recipients', () => {
|
run_test('sort_recipients', () => {
|
||||||
@@ -363,9 +361,7 @@ run_test('sort_recipients dup bots', () => {
|
|||||||
const dup_objects = matches.concat([a_bot]);
|
const dup_objects = matches.concat([a_bot]);
|
||||||
|
|
||||||
const recipients = th.sort_recipients(dup_objects, "b", "", "");
|
const recipients = th.sort_recipients(dup_objects, "b", "", "");
|
||||||
const recipients_email = _.map(recipients, function (person) {
|
const recipients_email = recipients.map(person => person.email);
|
||||||
return person.email;
|
|
||||||
});
|
|
||||||
const expected = [
|
const expected = [
|
||||||
'b_bot@example.com',
|
'b_bot@example.com',
|
||||||
'b_user_3@zulip.net',
|
'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.
|
// b_user_2 is a subscriber and b_user_1 is not.
|
||||||
const small_matches = [b_user_2, b_user_1];
|
const small_matches = [b_user_2, b_user_1];
|
||||||
const recipients = th.sort_recipients(small_matches, "b", "Dev", "Dev Topic");
|
const recipients = th.sort_recipients(small_matches, "b", "Dev", "Dev Topic");
|
||||||
const recipients_email = _.map(recipients, function (person) {
|
const recipients_email = recipients.map(person => person.email);
|
||||||
return person.email;
|
|
||||||
});
|
|
||||||
const expected = [
|
const expected = [
|
||||||
'b_user_2@zulip.net',
|
'b_user_2@zulip.net',
|
||||||
'b_user_1@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.
|
// both are not subscribered to the stream Linux.
|
||||||
const small_matches = [b_user_3, b_user_2];
|
const small_matches = [b_user_3, b_user_2];
|
||||||
const recipients = th.sort_recipients(small_matches, "b", "Linux", "Linux Topic");
|
const recipients = th.sort_recipients(small_matches, "b", "Linux", "Linux Topic");
|
||||||
const recipients_email = _.map(recipients, function (person) {
|
const recipients_email = recipients.map(person => person.email);
|
||||||
return person.email;
|
|
||||||
});
|
|
||||||
const expected = [
|
const expected = [
|
||||||
'b_user_3@zulip.net',
|
'b_user_3@zulip.net',
|
||||||
'b_user_2@zulip.net',
|
'b_user_2@zulip.net',
|
||||||
@@ -438,7 +430,7 @@ run_test('sort broadcast mentions', () => {
|
|||||||
'');
|
'');
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
_.map(results, (r) => r.email),
|
results.map(r => r.email),
|
||||||
['all', 'everyone', 'stream']
|
['all', 'everyone', 'stream']
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -455,7 +447,7 @@ run_test('sort broadcast mentions', () => {
|
|||||||
'');
|
'');
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
_.map(results2, (r) => r.email),
|
results2.map(r => r.email),
|
||||||
['all',
|
['all',
|
||||||
'everyone',
|
'everyone',
|
||||||
'stream',
|
'stream',
|
||||||
@@ -715,9 +707,7 @@ run_test('sort_slash_commands', () => {
|
|||||||
|
|
||||||
run_test('sort_recipientbox_typeahead', () => {
|
run_test('sort_recipientbox_typeahead', () => {
|
||||||
let recipients = th.sort_recipientbox_typeahead("b, a", matches, ""); // search "a"
|
let recipients = th.sort_recipientbox_typeahead("b, a", matches, ""); // search "a"
|
||||||
let recipients_email = _.map(recipients, function (person) {
|
let recipients_email = recipients.map(person => person.email);
|
||||||
return person.email;
|
|
||||||
});
|
|
||||||
assert.deepEqual(recipients_email, [
|
assert.deepEqual(recipients_email, [
|
||||||
'a_user@zulip.org', // matches "a"
|
'a_user@zulip.org', // matches "a"
|
||||||
'a_bot@zulip.com', // 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 = th.sort_recipientbox_typeahead("b, a, b", matches, ""); // search "b"
|
||||||
recipients_email = _.map(recipients, function (person) {
|
recipients_email = recipients.map(person => person.email);
|
||||||
return person.email;
|
|
||||||
});
|
|
||||||
assert.deepEqual(recipients_email, [
|
assert.deepEqual(recipients_email, [
|
||||||
'b_bot@example.com',
|
'b_bot@example.com',
|
||||||
'b_user_3@zulip.net',
|
'b_user_3@zulip.net',
|
||||||
|
|||||||
@@ -97,9 +97,7 @@ function make_child(i, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function make_children(lst) {
|
function make_children(lst) {
|
||||||
return _.map(lst, (i) => {
|
return lst.map(i => make_child(i, 'foo' + i));
|
||||||
return make_child(i, 'foo' + i);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test('children', () => {
|
run_test('children', () => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ exports.t = function (str, context) {
|
|||||||
*/
|
*/
|
||||||
const keyword_regex = /__(- )?(\w)+__/g;
|
const keyword_regex = /__(- )?(\w)+__/g;
|
||||||
const keys_in_str = str.match(keyword_regex) || [];
|
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;
|
let prefix_length;
|
||||||
if (key.startsWith("__- ")) {
|
if (key.startsWith("__- ")) {
|
||||||
prefix_length = 4;
|
prefix_length = 4;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ function diff_strings(string_0, string_1) {
|
|||||||
const emphasize_codes = (string) => {
|
const emphasize_codes = (string) => {
|
||||||
return "\u001b[34m" + string.slice(0, 1) + "\u001b[0m" + string.slice(1);
|
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");
|
return output_lines.join("\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -524,13 +524,9 @@ exports.make_zjquery = function (opts) {
|
|||||||
|
|
||||||
zjquery.state = function () {
|
zjquery.state = function () {
|
||||||
// useful for debugging
|
// useful for debugging
|
||||||
let res = _.map(elems, function (v) {
|
let res = elems.map(v => v.debug());
|
||||||
return v.debug();
|
|
||||||
});
|
|
||||||
|
|
||||||
res = _.map(res, function (v) {
|
res = res.map(v => [v.selector, v.value, v.shown]);
|
||||||
return [v.selector, v.value, v.shown];
|
|
||||||
});
|
|
||||||
|
|
||||||
res.sort();
|
res.sort();
|
||||||
|
|
||||||
|
|||||||
@@ -128,15 +128,13 @@ exports.get_huddles = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function huddle_split(huddle) {
|
function huddle_split(huddle) {
|
||||||
return _.map(huddle.split(','), function (s) {
|
return huddle.split(',').map(s => parseInt(s, 10));
|
||||||
return parseInt(s, 10);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.full_huddle_name = function (huddle) {
|
exports.full_huddle_name = function (huddle) {
|
||||||
const user_ids = huddle_split(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);
|
const person = people.get_by_user_id(user_id);
|
||||||
return person.full_name;
|
return person.full_name;
|
||||||
});
|
});
|
||||||
@@ -148,7 +146,7 @@ exports.short_huddle_name = function (huddle) {
|
|||||||
const user_ids = huddle_split(huddle);
|
const user_ids = huddle_split(huddle);
|
||||||
|
|
||||||
const num_to_show = 3;
|
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);
|
const person = people.get_by_user_id(user_id);
|
||||||
return person.full_name;
|
return person.full_name;
|
||||||
});
|
});
|
||||||
@@ -246,15 +244,13 @@ exports.update_huddles = function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const group_pms = _.map(huddles, function (huddle) {
|
const group_pms = huddles.map(huddle => ({
|
||||||
return {
|
|
||||||
user_ids_string: huddle,
|
user_ids_string: huddle,
|
||||||
name: exports.full_huddle_name(huddle),
|
name: exports.full_huddle_name(huddle),
|
||||||
href: hash_util.huddle_with_uri(huddle),
|
href: hash_util.huddle_with_uri(huddle),
|
||||||
fraction_present: buddy_data.huddle_fraction_present(huddle),
|
fraction_present: buddy_data.huddle_fraction_present(huddle),
|
||||||
short_name: exports.short_huddle_name(huddle),
|
short_name: exports.short_huddle_name(huddle),
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
const html = render_group_pms({group_pms: group_pms});
|
const html = render_group_pms({group_pms: group_pms});
|
||||||
ui.get_content_element($('#group-pms')).html(html);
|
ui.get_content_element($('#group-pms')).html(html);
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ exports.add = function bot_data__add(bot) {
|
|||||||
const clean_bot = _.pick(bot, bot_fields);
|
const clean_bot = _.pick(bot, bot_fields);
|
||||||
bots.set(bot.user_id, clean_bot);
|
bots.set(bot.user_id, clean_bot);
|
||||||
set_can_admin(clean_bot);
|
set_can_admin(clean_bot);
|
||||||
const clean_services = _.map(bot.services, function (service) {
|
const clean_services = bot.services.map(service => _.pick(service, services_fields));
|
||||||
return _.pick(service, services_fields);
|
|
||||||
});
|
|
||||||
services.set(bot.user_id, clean_services);
|
services.set(bot.user_id, clean_services);
|
||||||
|
|
||||||
send_change_event();
|
send_change_event();
|
||||||
|
|||||||
@@ -118,13 +118,9 @@ function filter_user_ids(filter_text, user_ids) {
|
|||||||
user_ids = _.reject(user_ids, people.is_my_user_id);
|
user_ids = _.reject(user_ids, people.is_my_user_id);
|
||||||
|
|
||||||
let search_terms = filter_text.toLowerCase().split(/[|,]+/);
|
let search_terms = filter_text.toLowerCase().split(/[|,]+/);
|
||||||
search_terms = _.map(search_terms, function (s) {
|
search_terms = search_terms.map(s => s.trim());
|
||||||
return s.trim();
|
|
||||||
});
|
|
||||||
|
|
||||||
const persons = _.map(user_ids, function (user_id) {
|
const persons = user_ids.map(user_id => people.get_by_user_id(user_id));
|
||||||
return people.get_by_user_id(user_id);
|
|
||||||
});
|
|
||||||
|
|
||||||
const user_id_dict = people.filter_people_by_search_terms(persons, search_terms);
|
const user_id_dict = people.filter_people_by_search_terms(persons, search_terms);
|
||||||
return Array.from(user_id_dict.keys());
|
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) {
|
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);
|
compose_fade.update_user_info(user_info, fade_config);
|
||||||
return user_info;
|
return user_info;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ exports.compute_placeholder_text = function (opts) {
|
|||||||
// For Private Messages
|
// For Private Messages
|
||||||
if (opts.private_message_recipient) {
|
if (opts.private_message_recipient) {
|
||||||
const recipient_list = opts.private_message_recipient.split(",");
|
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);
|
const user = people.get_by_email(recipient);
|
||||||
return user.full_name;
|
return user.full_name;
|
||||||
}).join(", ");
|
}).join(", ");
|
||||||
|
|||||||
@@ -325,19 +325,22 @@ exports.tokenize_compose_str = function (s) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.broadcast_mentions = function () {
|
exports.broadcast_mentions = function () {
|
||||||
return _.map(['all', 'everyone', 'stream'], function (mention, idx) {
|
return ['all', 'everyone', 'stream'].map((mention, idx) => ({
|
||||||
return {
|
|
||||||
special_item_text: i18n.t("__wildcard_mention_token__ (Notify stream)",
|
special_item_text: i18n.t("__wildcard_mention_token__ (Notify stream)",
|
||||||
{wildcard_mention_token: mention}),
|
{wildcard_mention_token: mention}),
|
||||||
|
|
||||||
email: mention,
|
email: mention,
|
||||||
|
|
||||||
// Always sort above, under the assumption that names will
|
// Always sort above, under the assumption that names will
|
||||||
// be longer and only contain "all" as a substring.
|
// be longer and only contain "all" as a substring.
|
||||||
pm_recipient_count: Infinity,
|
pm_recipient_count: Infinity,
|
||||||
|
|
||||||
full_name: mention,
|
full_name: mention,
|
||||||
is_broadcast: true,
|
is_broadcast: true,
|
||||||
idx: idx, // used for sorting
|
|
||||||
};
|
// used for sorting
|
||||||
});
|
idx: idx,
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
function filter_mention_name(current_token) {
|
function filter_mention_name(current_token) {
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ exports.format_draft = function (draft) {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const emails = util.extract_pm_recipients(draft.private_message_recipient);
|
const emails = util.extract_pm_recipients(draft.private_message_recipient);
|
||||||
const recipients = _.map(emails, function (email) {
|
const recipients = emails.map(email => {
|
||||||
email = email.trim();
|
email = email.trim();
|
||||||
const person = people.get_by_email(email);
|
const person = people.get_by_email(email);
|
||||||
if (person !== undefined) {
|
if (person !== undefined) {
|
||||||
@@ -305,7 +305,7 @@ exports.launch = function () {
|
|||||||
return draft_b.updatedAt - draft_a.updatedAt;
|
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;
|
return sorted_formatted_drafts;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ exports.build_display_recipient = function (message) {
|
|||||||
const emails = util.extract_pm_recipients(message.private_message_recipient);
|
const emails = util.extract_pm_recipients(message.private_message_recipient);
|
||||||
|
|
||||||
let sender_in_display_recipients = false;
|
let sender_in_display_recipients = false;
|
||||||
const display_recipient = _.map(emails, function (email) {
|
const display_recipient = emails.map(email => {
|
||||||
email = email.trim();
|
email = email.trim();
|
||||||
const person = people.get_by_email(email);
|
const person = people.get_by_email(email);
|
||||||
if (person === undefined) {
|
if (person === undefined) {
|
||||||
|
|||||||
@@ -42,9 +42,7 @@ function wrap_quote(text) {
|
|||||||
// beginning of each line
|
// beginning of each line
|
||||||
for (const paragraph of paragraphs) {
|
for (const paragraph of paragraphs) {
|
||||||
const lines = paragraph.split('\n');
|
const lines = paragraph.split('\n');
|
||||||
quoted_paragraphs.push(_.map(
|
quoted_paragraphs.push(_.reject(lines, function (line) { return line === ''; }).map(line => '> ' + line).join('\n'));
|
||||||
_.reject(lines, function (line) { return line === ''; }),
|
|
||||||
function (line) { return '> ' + line; }).join('\n'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return quoted_paragraphs.join('\n\n');
|
return quoted_paragraphs.join('\n\n');
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ Filter.parse = function (str) {
|
|||||||
might need to support multiple operators of the same type.
|
might need to support multiple operators of the same type.
|
||||||
*/
|
*/
|
||||||
Filter.unparse = function (operators) {
|
Filter.unparse = function (operators) {
|
||||||
const parts = _.map(operators, function (elem) {
|
const parts = operators.map(elem => {
|
||||||
|
|
||||||
if (elem.operator === 'search') {
|
if (elem.operator === 'search') {
|
||||||
// Search terms are the catch-all case.
|
// Search terms are the catch-all case.
|
||||||
@@ -481,13 +481,11 @@ Filter.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_canonicalize_operators: function (operators_mixed_case) {
|
_canonicalize_operators: function (operators_mixed_case) {
|
||||||
return _.map(operators_mixed_case, function (tuple) {
|
return operators_mixed_case.map(tuple => Filter.canonicalize_term(tuple));
|
||||||
return Filter.canonicalize_term(tuple);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
filter_with_new_topic: function (new_topic) {
|
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);
|
const new_term = _.clone(term);
|
||||||
if (new_term.operator === 'topic' && !new_term.negated) {
|
if (new_term.operator === 'topic' && !new_term.negated) {
|
||||||
new_term.operand = new_topic;
|
new_term.operand = new_topic;
|
||||||
@@ -503,7 +501,7 @@ Filter.prototype = {
|
|||||||
|
|
||||||
sorted_term_types: function () {
|
sorted_term_types: function () {
|
||||||
const terms = this._operators;
|
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);
|
const sorted_terms = Filter.sorted_term_types(term_types);
|
||||||
return sorted_terms;
|
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 operand = elem.operand;
|
||||||
const canonicalized_operator = Filter.canonicalize_operator(elem.operator);
|
const canonicalized_operator = Filter.canonicalize_operator(elem.operator);
|
||||||
if (canonicalized_operator === 'is') {
|
if (canonicalized_operator === 'is') {
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ exports.relevant_recipient_bars = function () {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = _.map(elems, function (elem, i) {
|
const items = elems.map((elem, i) => {
|
||||||
let date_html;
|
let date_html;
|
||||||
let need_frb;
|
let need_frb;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ exports.set_up_toggler = function () {
|
|||||||
const elem = exports.toggler.get();
|
const elem = exports.toggler.get();
|
||||||
elem.addClass('large allow-overflow');
|
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 key = item.key; // e.g. message-formatting
|
||||||
const modal = $('#' + key).find('.modal-body');
|
const modal = $('#' + key).find('.modal-body');
|
||||||
return modal;
|
return modal;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {
|
|||||||
// edited in between when they sent the message and when
|
// edited in between when they sent the message and when
|
||||||
// we hear back from the server and can echo the new
|
// we hear back from the server and can echo the new
|
||||||
// message. Arguably, it's counterproductive complexity.
|
// 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);
|
message_util.add_new_messages(new_messages, msg_list);
|
||||||
unread_ops.process_visible();
|
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) {
|
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);
|
unread.process_loaded_messages(messages);
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function process_result(data, opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_.each(messages, message_store.set_message_booleans);
|
_.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
|
// In case any of the newly fetched messages are new, add them to
|
||||||
// our unread data structures. It's important that this run even
|
// 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 = JSON.parse(data.narrow);
|
||||||
data.narrow = _.map(data.narrow, function (filter) {
|
data.narrow = data.narrow.map(filter => {
|
||||||
if (operators_supporting_ids.includes(filter.operator)) {
|
if (operators_supporting_ids.includes(filter.operator)) {
|
||||||
filter.operand = people.emails_strings_to_user_ids_array(filter.operand);
|
filter.operand = people.emails_strings_to_user_ids_array(filter.operand);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,7 @@ exports.send_read = (function () {
|
|||||||
const real_msgs = _.filter(queue, function (msg) {
|
const real_msgs = _.filter(queue, function (msg) {
|
||||||
return !msg.locally_echoed;
|
return !msg.locally_echoed;
|
||||||
});
|
});
|
||||||
const real_msg_ids = _.map(real_msgs, function (msg) {
|
const real_msg_ids = real_msgs.map(msg => msg.id);
|
||||||
return msg.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (real_msg_ids.length === 0) {
|
if (real_msg_ids.length === 0) {
|
||||||
setTimeout(start, 100);
|
setTimeout(start, 100);
|
||||||
|
|||||||
@@ -684,7 +684,7 @@ MessageListView.prototype = {
|
|||||||
// all messages lists. To prevent having both list views overwriting
|
// all messages lists. To prevent having both list views overwriting
|
||||||
// each others data we will make a new message object to add data to
|
// each others data we will make a new message object to add data to
|
||||||
// for rendering.
|
// for rendering.
|
||||||
const message_containers = _.map(messages, function (message) {
|
const message_containers = messages.map(message => {
|
||||||
if (message.starred) {
|
if (message.starred) {
|
||||||
message.starred_status = i18n.t("Unstar");
|
message.starred_status = i18n.t("Unstar");
|
||||||
} else {
|
} else {
|
||||||
@@ -793,9 +793,7 @@ MessageListView.prototype = {
|
|||||||
if (message_actions.append_messages.length > 0) {
|
if (message_actions.append_messages.length > 0) {
|
||||||
last_message_row = table.find('.message_row').last().expectOne();
|
last_message_row = table.find('.message_row').last().expectOne();
|
||||||
last_group_row = rows.get_message_recipient_row(last_message_row);
|
last_group_row = rows.get_message_recipient_row(last_message_row);
|
||||||
dom_messages = $(_.map(message_actions.append_messages, function (message_container) {
|
dom_messages = $(message_actions.append_messages.map(message_container => self._get_message_template(message_container)).join('')).filter('.message_row');
|
||||||
return self._get_message_template(message_container);
|
|
||||||
}).join('')).filter('.message_row');
|
|
||||||
|
|
||||||
self._post_process(dom_messages);
|
self._post_process(dom_messages);
|
||||||
last_group_row.append(dom_messages);
|
last_group_row.append(dom_messages);
|
||||||
@@ -1233,9 +1231,7 @@ MessageListView.prototype = {
|
|||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
// Convert messages to list messages
|
// Convert messages to list messages
|
||||||
let message_containers = _.map(messages, function (message) {
|
let message_containers = messages.map(message => self.message_containers[message.id]);
|
||||||
return self.message_containers[message.id];
|
|
||||||
});
|
|
||||||
// We may not have the message_container if the stream or topic was muted
|
// We may not have the message_container if the stream or topic was muted
|
||||||
message_containers = _.reject(message_containers, function (message_container) {
|
message_containers = _.reject(message_containers, function (message_container) {
|
||||||
return message_container === undefined;
|
return message_container === undefined;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ exports.get_pm_emails = function (message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user_ids = people.pm_with_user_ids(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(', ');
|
return emails.join(', ');
|
||||||
};
|
};
|
||||||
@@ -56,7 +56,7 @@ exports.get_pm_full_names = function (message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user_ids = people.pm_with_user_ids(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(', ');
|
return names.join(', ');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -115,8 +115,7 @@ exports.activate = function (raw_operators, opts) {
|
|||||||
notifications.hide_history_limit_message();
|
notifications.hide_history_limit_message();
|
||||||
$(".all-messages-search-caution").hide();
|
$(".all-messages-search-caution").hide();
|
||||||
|
|
||||||
blueslip.debug("Narrowed", {operators: _.map(operators,
|
blueslip.debug("Narrowed", {operators: operators.map(e => e.operator),
|
||||||
function (e) { return e.operator; }),
|
|
||||||
trigger: opts ? opts.trigger : undefined,
|
trigger: opts ? opts.trigger : undefined,
|
||||||
previous_id: current_msg_list.selected_id()});
|
previous_id: current_msg_list.selected_id()});
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ exports.init = function () {
|
|||||||
exports.init();
|
exports.init();
|
||||||
|
|
||||||
function split_to_ints(lst) {
|
function split_to_ints(lst) {
|
||||||
return _.map(lst.split(','), function (s) {
|
return lst.split(',').map(s => parseInt(s, 10));
|
||||||
return parseInt(s, 10);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.get_by_user_id = function (user_id) {
|
exports.get_by_user_id = function (user_id) {
|
||||||
@@ -137,9 +135,7 @@ exports.huddle_string = function (message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_ids = _.map(message.display_recipient, function (recip) {
|
let user_ids = message.display_recipient.map(recip => recip.id);
|
||||||
return recip.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
function is_huddle_recip(user_id) {
|
function is_huddle_recip(user_id) {
|
||||||
return 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) {
|
exports.user_ids_string_to_emails_string = function (user_ids_string) {
|
||||||
const user_ids = split_to_ints(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);
|
const person = people_by_user_id_dict.get(user_id);
|
||||||
if (person) {
|
return person && person.email;
|
||||||
return person.email;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!_.all(emails)) {
|
if (!_.all(emails)) {
|
||||||
@@ -173,9 +167,7 @@ exports.user_ids_string_to_emails_string = function (user_ids_string) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emails = _.map(emails, function (email) {
|
emails = emails.map(email => email.toLowerCase());
|
||||||
return email.toLowerCase();
|
|
||||||
});
|
|
||||||
|
|
||||||
emails.sort();
|
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) {
|
exports.user_ids_string_to_ids_array = function (user_ids_string) {
|
||||||
const user_ids = user_ids_string.split(',');
|
const user_ids = user_ids_string.split(',');
|
||||||
const ids = _.map(user_ids, function (id) {
|
const ids = user_ids.map(id => Number(id));
|
||||||
return Number(id);
|
|
||||||
});
|
|
||||||
return ids;
|
return ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -206,11 +196,9 @@ exports.reply_to_to_user_ids_string = function (emails_string) {
|
|||||||
// invalid data.
|
// invalid data.
|
||||||
const emails = emails_string.split(',');
|
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);
|
const person = exports.get_by_email(email);
|
||||||
if (person) {
|
return person && person.user_id;
|
||||||
return person.user_id;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!_.all(user_ids)) {
|
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) {
|
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);
|
const person = exports.get_by_email(email);
|
||||||
if (person) {
|
return person && person.user_id;
|
||||||
return person.user_id;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!_.all(user_ids)) {
|
if (!_.all(user_ids)) {
|
||||||
@@ -282,11 +268,9 @@ exports.email_list_to_user_ids_string = function (emails) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.safe_full_names = function (user_ids) {
|
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);
|
const person = people_by_user_id_dict.get(user_id);
|
||||||
if (person) {
|
return person && person.full_name;
|
||||||
return person.full_name;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
names = _.filter(names);
|
names = _.filter(names);
|
||||||
@@ -309,7 +293,7 @@ exports.get_recipients = function (user_ids_string) {
|
|||||||
return exports.my_full_name();
|
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(', ');
|
return names.join(', ');
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -330,7 +314,7 @@ exports.pm_reply_to = function (message) {
|
|||||||
return;
|
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);
|
const person = people_by_user_id_dict.get(user_id);
|
||||||
if (!person) {
|
if (!person) {
|
||||||
blueslip.error('Unknown user id in message: ' + user_id);
|
blueslip.error('Unknown user id in message: ' + user_id);
|
||||||
@@ -386,9 +370,7 @@ exports.all_user_ids_in_pm = function (message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_ids = _.map(message.display_recipient, function (recip) {
|
let user_ids = message.display_recipient.map(recip => recip.id);
|
||||||
return recip.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
user_ids = sort_numerically(user_ids);
|
user_ids = sort_numerically(user_ids);
|
||||||
return user_ids;
|
return user_ids;
|
||||||
@@ -404,9 +386,7 @@ exports.pm_with_user_ids = function (message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user_ids = _.map(message.display_recipient, function (recip) {
|
const user_ids = message.display_recipient.map(recip => recip.id);
|
||||||
return recip.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
return sorted_other_user_ids(user_ids);
|
return sorted_other_user_ids(user_ids);
|
||||||
};
|
};
|
||||||
@@ -421,9 +401,7 @@ exports.group_pm_with_user_ids = function (message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user_ids = _.map(message.display_recipient, function (recip) {
|
const user_ids = message.display_recipient.map(recip => recip.id);
|
||||||
return recip.id;
|
|
||||||
});
|
|
||||||
const is_user_present = _.some(user_ids, function (user_id) {
|
const is_user_present = _.some(user_ids, function (user_id) {
|
||||||
return exports.is_my_user_id(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.
|
// and we don't warn on any errors.
|
||||||
let emails = reply_to.split(',');
|
let emails = reply_to.split(',');
|
||||||
|
|
||||||
const persons = _.map(emails, function (email) {
|
const persons = emails.map(email => people_dict.get(email.trim()));
|
||||||
return people_dict.get(email.trim());
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!_.all(persons)) {
|
if (!_.all(persons)) {
|
||||||
return reply_to;
|
return reply_to;
|
||||||
@@ -504,7 +480,7 @@ exports.update_email_in_reply_to = function (reply_to, user_id, new_email) {
|
|||||||
return reply_to;
|
return reply_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
emails = _.map(persons, function (person) {
|
emails = persons.map(person => {
|
||||||
if (person.user_id === user_id) {
|
if (person.user_id === user_id) {
|
||||||
return new_email;
|
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) {
|
exports.pm_with_operand_ids = function (operand) {
|
||||||
let emails = operand.split(',');
|
let emails = operand.split(',');
|
||||||
emails = _.map(emails, function (email) { return email.trim(); });
|
emails = emails.map(email => email.trim());
|
||||||
let persons = _.map(emails, function (email) {
|
let persons = emails.map(email => people_dict.get(email));
|
||||||
return people_dict.get(email);
|
|
||||||
});
|
|
||||||
|
|
||||||
// If your email is included in a PM group with other people, just ignore it
|
// If your email is included in a PM group with other people, just ignore it
|
||||||
if (persons.length > 1) {
|
if (persons.length > 1) {
|
||||||
@@ -530,9 +504,7 @@ exports.pm_with_operand_ids = function (operand) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_ids = _.map(persons, function (person) {
|
let user_ids = persons.map(person => person.user_id);
|
||||||
return person.user_id;
|
|
||||||
});
|
|
||||||
|
|
||||||
user_ids = sort_numerically(user_ids);
|
user_ids = sort_numerically(user_ids);
|
||||||
|
|
||||||
@@ -788,9 +760,7 @@ exports.get_message_people = function () {
|
|||||||
semantics
|
semantics
|
||||||
*/
|
*/
|
||||||
const message_people = _.compact(
|
const message_people = _.compact(
|
||||||
_.map(message_store.user_ids(), (user_id) => {
|
message_store.user_ids().map(user_id => people_by_user_id_dict.get(user_id))
|
||||||
return people_by_user_id_dict.get(user_id);
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return message_people;
|
return message_people;
|
||||||
@@ -835,7 +805,7 @@ exports.build_person_matcher = function (query) {
|
|||||||
query = query.trim();
|
query = query.trim();
|
||||||
|
|
||||||
const termlets = query.toLowerCase().split(/\s+/);
|
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) {
|
return function (user) {
|
||||||
const email = user.email.toLowerCase();
|
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
|
// Build our matchers outside the loop to avoid some
|
||||||
// search overhead that is not user-specific.
|
// search overhead that is not user-specific.
|
||||||
const matchers = _.map(search_terms, function (search_term) {
|
const matchers = search_terms.map(search_term => exports.build_person_matcher(search_term));
|
||||||
return exports.build_person_matcher(search_term);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Loop through users and populate filtered_users only
|
// Loop through users and populate filtered_users only
|
||||||
// if they include search_terms
|
// if they include search_terms
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ exports.pm_ul = (convos) => {
|
|||||||
];
|
];
|
||||||
return vdom.ul({
|
return vdom.ul({
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
keyed_nodes: _.map(convos, exports.keyed_pm_li),
|
keyed_nodes: convos.map(exports.keyed_pm_li),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,11 +45,9 @@ function format_as_suggestion(terms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function compare_by_huddle(huddle) {
|
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);
|
person = people.get_by_email(person);
|
||||||
if (person) {
|
return person && person.user_id;
|
||||||
return person.user_id;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Construct dict for all huddles, so we can lookup each's recency
|
// 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 regex = typeahead_helper.build_highlight_regex(query);
|
||||||
const hilite = typeahead_helper.highlight_with_escaping_and_regex;
|
const hilite = typeahead_helper.highlight_with_escaping_and_regex;
|
||||||
|
|
||||||
const objs = _.map(streams, function (stream) {
|
const objs = streams.map(stream => {
|
||||||
const prefix = 'stream';
|
const prefix = 'stream';
|
||||||
const highlighted_stream = hilite(regex, stream);
|
const highlighted_stream = hilite(regex, stream);
|
||||||
const verb = last.negated ? 'exclude ' : '';
|
const verb = last.negated ? 'exclude ' : '';
|
||||||
@@ -160,7 +158,7 @@ function get_group_suggestions(last, operators) {
|
|||||||
|
|
||||||
const highlight_person = make_person_highlighter(last_part);
|
const highlight_person = make_person_highlighter(last_part);
|
||||||
|
|
||||||
const suggestions = _.map(persons, function (person) {
|
const suggestions = persons.map(person => {
|
||||||
const term = {
|
const term = {
|
||||||
operator: 'pm-with',
|
operator: 'pm-with',
|
||||||
operand: all_but_last_part + ',' + person.email,
|
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 highlight_person = make_person_highlighter(query);
|
||||||
|
|
||||||
const objs = _.map(persons, function (person) {
|
const objs = persons.map(person => {
|
||||||
const name = highlight_person(person);
|
const name = highlight_person(person);
|
||||||
const description = prefix + ' ' + name;
|
const description = prefix + ' ' + name;
|
||||||
const terms = [{
|
const terms = [{
|
||||||
@@ -363,7 +361,7 @@ function get_topic_suggestions(last, operators) {
|
|||||||
// care about case.
|
// care about case.
|
||||||
topics.sort();
|
topics.sort();
|
||||||
|
|
||||||
return _.map(topics, function (topic) {
|
return topics.map(topic => {
|
||||||
const topic_term = {operator: 'topic', operand: topic, negated: negated};
|
const topic_term = {operator: 'topic', operand: topic, negated: negated};
|
||||||
const operators = suggest_operators.concat([topic_term]);
|
const operators = suggest_operators.concat([topic_term]);
|
||||||
return format_as_suggestion(operators);
|
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
|
// Negating suggestions on is_search_operand_negated is required for
|
||||||
// suggesting negated operators.
|
// suggesting negated operators.
|
||||||
if (last.negated || is_search_operand_negated) {
|
if (last.negated || is_search_operand_negated) {
|
||||||
suggestions = _.map(suggestions, function (suggestion) {
|
suggestions = suggestions.map(suggestion => ({
|
||||||
return {
|
|
||||||
search_string: '-' + suggestion.search_string,
|
search_string: '-' + suggestion.search_string,
|
||||||
description: 'exclude ' + suggestion.description,
|
description: 'exclude ' + suggestion.description,
|
||||||
invalid: suggestion.invalid,
|
invalid: suggestion.invalid,
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const last_string = Filter.unparse([last]).toLowerCase();
|
const last_string = Filter.unparse([last]).toLowerCase();
|
||||||
@@ -583,7 +579,7 @@ function get_operator_suggestions(last) {
|
|||||||
return common.phrase_match(last_operand, choice);
|
return common.phrase_match(last_operand, choice);
|
||||||
});
|
});
|
||||||
|
|
||||||
return _.map(choices, function (choice) {
|
return choices.map(choice => {
|
||||||
const op = [{operator: choice, operand: '', negated: negated}];
|
const op = [{operator: choice, operand: '', negated: negated}];
|
||||||
return format_as_suggestion(op);
|
return format_as_suggestion(op);
|
||||||
});
|
});
|
||||||
@@ -848,9 +844,7 @@ exports.finalize_search_result = function (result) {
|
|||||||
lookup_table[obj.search_string] = obj;
|
lookup_table[obj.search_string] = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
const strings = _.map(result, function (obj) {
|
const strings = result.map(obj => obj.search_string);
|
||||||
return obj.search_string;
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
strings: strings,
|
strings: strings,
|
||||||
lookup_table: lookup_table,
|
lookup_table: lookup_table,
|
||||||
|
|||||||
@@ -373,9 +373,9 @@ exports.populate_realm_domains = function (realm_domains) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const domains_list = _.map(realm_domains, function (realm_domain) {
|
const domains_list = realm_domains.map(
|
||||||
return realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain;
|
realm_domain => realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain
|
||||||
});
|
);
|
||||||
let domains = domains_list.join(', ');
|
let domains = domains_list.join(', ');
|
||||||
if (domains.length === 0) {
|
if (domains.length === 0) {
|
||||||
domains = i18n.t("None");
|
domains = i18n.t("None");
|
||||||
|
|||||||
@@ -101,11 +101,9 @@ function ajaxSubscribeForCreation(stream_name, description, user_ids, invite_onl
|
|||||||
stream_post_policy, announce, history_public_to_subscribers) {
|
stream_post_policy, announce, history_public_to_subscribers) {
|
||||||
// TODO: We can eliminate the user_ids -> principals conversion
|
// TODO: We can eliminate the user_ids -> principals conversion
|
||||||
// once we upgrade the backend to accept user_ids.
|
// once we upgrade the backend to accept user_ids.
|
||||||
const persons = _.compact(_.map(user_ids, (user_id) => {
|
const persons = _.compact(user_ids.map(user_id => people.get_by_user_id(user_id)));
|
||||||
return 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.
|
// Subscribe yourself and possible other people to a new stream.
|
||||||
return channel.post({
|
return channel.post({
|
||||||
|
|||||||
@@ -344,8 +344,8 @@ exports.get_invite_stream_data = function () {
|
|||||||
default_stream: exports.get_default_status(sub.name),
|
default_stream: exports.get_default_status(sub.name),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const invite_stream_data = _.map(exports.subscribed_subs(), filter_stream_data);
|
const invite_stream_data = exports.subscribed_subs().map(filter_stream_data);
|
||||||
const default_stream_data = _.map(page_params.realm_default_streams, 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
|
// Since, union doesn't work on array of objects we are using filter
|
||||||
const is_included = {};
|
const is_included = {};
|
||||||
@@ -462,9 +462,7 @@ exports.home_view_stream_names = function () {
|
|||||||
const home_view_subs = _.filter(exports.subscribed_subs(), function (sub) {
|
const home_view_subs = _.filter(exports.subscribed_subs(), function (sub) {
|
||||||
return !sub.is_muted;
|
return !sub.is_muted;
|
||||||
});
|
});
|
||||||
return _.map(home_view_subs, function (sub) {
|
return home_view_subs.map(sub => sub.name);
|
||||||
return sub.name;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.canonicalized_name = function (stream_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 () {
|
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');
|
const default_stream_names = _.pluck(streams, 'name');
|
||||||
return default_stream_names;
|
return default_stream_names;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ function filter_streams_by_search(streams, search_term) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let search_terms = search_term.toLowerCase().split(",");
|
let search_terms = search_term.toLowerCase().split(",");
|
||||||
search_terms = _.map(search_terms, function (s) {
|
search_terms = search_terms.map(s => s.trim());
|
||||||
return s.trim();
|
|
||||||
});
|
|
||||||
|
|
||||||
const filtered_streams = _.filter(streams, function (stream) {
|
const filtered_streams = _.filter(streams, function (stream) {
|
||||||
return _.any(search_terms, function (search_term) {
|
return _.any(search_terms, function (search_term) {
|
||||||
|
|||||||
@@ -15,12 +15,10 @@ exports.get_message_events = function (message) {
|
|||||||
return parseInt(m1.id, 10) - parseInt(m2.id, 10);
|
return parseInt(m1.id, 10) - parseInt(m2.id, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
const events = _.map(message.submessages, function (obj) {
|
const events = message.submessages.map(obj => ({
|
||||||
return {
|
|
||||||
sender_id: obj.sender_id,
|
sender_id: obj.sender_id,
|
||||||
data: JSON.parse(obj.content),
|
data: JSON.parse(obj.content),
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ function make_tab_data() {
|
|||||||
|
|
||||||
if (filter.has_operator("pm-with")) {
|
if (filter.has_operator("pm-with")) {
|
||||||
const emails = filter.operands("pm-with")[0].split(',');
|
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)) {
|
if (!people.get_by_email(email)) {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,9 +154,7 @@ exports.topic_history = function (stream_id) {
|
|||||||
return b.message_id - a.message_id;
|
return b.message_id - a.message_id;
|
||||||
});
|
});
|
||||||
|
|
||||||
const names = _.map(recents, function (obj) {
|
const names = recents.map(obj => obj.pretty_name);
|
||||||
return obj.pretty_name;
|
|
||||||
});
|
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -136,8 +136,7 @@ exports.widget = function (parent_elem, my_stream_id) {
|
|||||||
['class', 'topic-list'],
|
['class', 'topic-list'],
|
||||||
];
|
];
|
||||||
|
|
||||||
const nodes = _.map(
|
const nodes = list_info.items.map(exports.keyed_topic_li);
|
||||||
list_info.items, exports.keyed_topic_li);
|
|
||||||
|
|
||||||
if (spinner) {
|
if (spinner) {
|
||||||
nodes.push(exports.spinner_li());
|
nodes.push(exports.spinner_li());
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ exports.unread_topic_counter = (function () {
|
|||||||
return topic_dict.has(topic_name);
|
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);
|
const msgs = per_stream_bucketer.get_bucket(topic_name);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ exports.normalize_recipients = function (recipients) {
|
|||||||
// Converts a string listing emails of message recipients
|
// Converts a string listing emails of message recipients
|
||||||
// into a canonical formatting: emails sorted ASCIIbetically
|
// into a canonical formatting: emails sorted ASCIIbetically
|
||||||
// with exactly one comma and no spaces between each.
|
// with exactly one comma and no spaces between each.
|
||||||
recipients = _.map(recipients.split(','), function (s) { return s.trim(); });
|
recipients = recipients.split(',').map(s => s.trim());
|
||||||
recipients = _.map(recipients, function (s) { return s.toLowerCase(); });
|
recipients = recipients.map(s => s.toLowerCase());
|
||||||
recipients = _.filter(recipients, function (s) { return s.length > 0; });
|
recipients = _.filter(recipients, function (s) { return s.length > 0; });
|
||||||
recipients.sort();
|
recipients.sort();
|
||||||
return recipients.join(',');
|
return recipients.join(',');
|
||||||
@@ -249,7 +249,7 @@ function to_int(s) {
|
|||||||
exports.sorted_ids = function (ids) {
|
exports.sorted_ids = function (ids) {
|
||||||
// This mapping makes sure we are using ints, and
|
// This mapping makes sure we are using ints, and
|
||||||
// it also makes sure we don't mutate the list.
|
// 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) {
|
id_list.sort(function (a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,9 +39,7 @@ exports.render_tag = (tag) => {
|
|||||||
*/
|
*/
|
||||||
const opts = tag.opts;
|
const opts = tag.opts;
|
||||||
const tag_name = tag.tag_name;
|
const tag_name = tag.tag_name;
|
||||||
const attr_str = _.map(opts.attrs, (attr) => {
|
const attr_str = opts.attrs.map(attr => ' ' + attr[0] + '="' + util.escape_html(attr[1]) + '"').join('');
|
||||||
return ' ' + attr[0] + '="' + util.escape_html(attr[1]) + '"';
|
|
||||||
}).join('');
|
|
||||||
|
|
||||||
const start_tag = '<' + tag_name + attr_str + '>';
|
const start_tag = '<' + tag_name + attr_str + '>';
|
||||||
const end_tag = '</' + tag_name + '>';
|
const end_tag = '</' + tag_name + '>';
|
||||||
@@ -51,9 +49,7 @@ exports.render_tag = (tag) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const innards = _.map(opts.keyed_nodes, (node) => {
|
const innards = opts.keyed_nodes.map(node => node.render()).join('\n');
|
||||||
return node.render();
|
|
||||||
}).join('\n');
|
|
||||||
return start_tag + '\n' + innards + '\n' + end_tag;
|
return start_tag + '\n' + innards + '\n' + end_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user