Anders Kaseorg
2248d4d9a4
stats: Convert data from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
0e3acb5ce6
settings_account: Convert all_field_template_types from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
7844be6d3a
sent_messages: Convert messages from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
bf0a3d9d14
search_suggestion: Convert prev from object to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
e848bc2a21
search_suggestion: Convert huddle_dict from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
7c6ec51e5d
search_suggestions: Convert lookup_table from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
d4434a54e0
integrations_dev_panel: Convert loaded_fixtures from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
9b1f55c020
integrations: Convert CATEGORIES from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
230b701acc
integrations: Convert INTEGRATIONS from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
50b54563fe
help: Convert html_map from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
0ce06d45a1
message_list_view: Convert message_containers from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
86dd98d481
message_list_view: Convert _rows from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
a6a19c6ace
message_list_data: Convert id_set from object to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
9fa9f37521
message_list_data: Convert msg_ids_to_remove from object to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
dde035faf3
message_list_data: Convert _local_only from object to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
2d18424da0
message_list_data: Convert _hash from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
bf32dfcb9f
markdown: Convert realm_filter_map from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
0d6d36ae16
local_message: Convert already_used from object to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
ec1ebc936b
gear_menu: Convert scroll_positions from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
02fb1d4dd1
emoji_picker: Convert intermediate complete_emoji_catalog to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
0936381cfd
echo: Convert waiting_for_ack from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
c42aca3cfb
echo: Convert waiting_for_id from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
278420f908
debug: Convert sections from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
99bcd78273
debug: Convert ids from object to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
265cca4756
blueslip: Convert reported_errors, last_report_attempt from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
2ddd3d046a
echo: Further reduce local_id string vs. number confusion.
...
New rule: local_id is always a string, local_id_float is always a
number.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
2834b051d2
js: Read zid with rows.id.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:39:01 -08:00
Anders Kaseorg
d7d8632525
pygments_data: Replace JS module with JSON module.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:09:12 -08:00
Anders Kaseorg
e257253e64
emoji_codes: Replace JS module with JSON module.
...
webpack optimizes JSON modules using JSON.parse("{…}"), which is
faster than the normal JavaScript parser.
Update the backend to use emoji_codes.json too instead of the three
separate JSON files.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:09:12 -08:00
Anders Kaseorg
72dddb7af6
zjsunit: Use assert in strict mode.
...
This makes assert.equal and assert.deepEqual compare using === rather
than ==, to catch more bugs.
https://nodejs.org/api/assert.html#assert_strict_mode
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 08:16:26 -05:00
Steve Howell
483f1d153d
minor: Remove "spread operator" todo comment.
...
This comment was addressed in
59d55d1e06
2020-02-12 06:10:32 -05:00
Anders Kaseorg
59d55d1e06
js: Use modern spread arguments syntax.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-11 17:43:35 -08:00
Hashir Sarwar
6e14c39468
top_left_corner: Don't export `should_expand_pm_list()`.
...
We don't need to export `should_expand_pm_list` function
since we are not using it anywhere else.
2020-02-11 14:14:59 -08:00
Anders Kaseorg
e66c4ea474
settings_invites: Convert invited_as_values from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 15:57:20 -08:00
Anders Kaseorg
ed032817c7
hotspots: Convert HOTSPOT_LOCATIONS from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 15:57:20 -08:00
Anders Kaseorg
ee68ef516d
js: Convert _.isString to typeof.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 15:57:20 -08:00
Anders Kaseorg
a3e5fef663
js: Convert _.isObject to typeof.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 15:57:20 -08:00
Anders Kaseorg
9f07cf6b0e
js: Convert _.values to Object.values.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 15:57:20 -08:00
Anders Kaseorg
7ca52f1e80
js: Convert _.keys to Object.keys.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 15:57:20 -08:00
Steve Howell
14396c3e32
presence: Prep for upcoming changes to server data.
...
In the next commit we're going to change what the
server sends for the following:
- page_params
- server responses to /json/users/me/presence
We will **not** yet be changing the format of the data
that we get in events when users update their presence.
It's also just a bit in flux what our final formats
will be for various presence payloads, and different
optimizations may lead us to use different data
structures in different payloads.
So for now we decouple these two things:
raw_info: this is intended to represent a
snapshot of the latest data from the
server, including some data like
timestamps that are only used
in downstream calculations and not
user-facing
exports.presence_info: this is calculated
info for modules like buddy_data that
just need to know active vs. idle and
last_active_date
Another change that happens here is we rename
set_info_for_user to update_info_for_event,
which just makes it clear that the function
expects data in the "event" format (as opposed
to the format for page_params or server
responses).
As of now keeping the intermediate raw_info data
around feels slightly awkward, because we just
immediately calculate presence_info for any kind
of update. This may be sorta surprising if you
just skim the code and see the various timeout
constants. You would think we might be automatically
expiring "active" statuses in the client due to
the simple passage of time, but in fact the precise
places we do this are all triggered by new data
from the server and we re-calculate statuses
immediately.
(There are indirect ways that clients
have timing logic, since they ask the
server for new data at various intervals, but a
smarter client could simply expire users on its
own, or at least with a more efficient transfer
of info between it and the server. One of
the thing that complicates client-side logic
is that server and client clocks may be out
of sync. Also, it's not inherently super expensive
to get updates from the server.)
2020-02-10 14:37:44 -08:00
Steve Howell
75dbc4a2b1
presence: Extract presence.initialize().
2020-02-10 14:37:44 -08:00
Anders Kaseorg
bafdf5229a
js: Convert _.flatten(a, true) to [].concat(...a).
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
62ad436c64
js: Convert _.compact(a) to a.filter(Boolean).
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
d0b0a64af3
js: Convert _.isEmpty(a) to a.length !== 0.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
8abf5da717
js: Convert _.isArray to Array.isArray.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
e1cf5e4630
js: Convert _.reduce to less convoluted code.
...
reduce is almost never a better solution than the alternatives. Avoid
it.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
612b237cec
js: Convert remaining _.each(a, …) to a.forEach(…).
...
The _.each calls with an inline function expression have already been
converted to for…of loops. We could do that here, but using .forEach
when we’re just reusing an existing function seems like a good
guideline.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
b566d11d69
js: Convert _.findIndex(a, …) to a.findIndex(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
336a279005
js: Convert _.find(a, …) to a.find(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
cdd774b790
js: Convert _.all(a, …), _.every(a, …) to a.every(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
70ff164f89
js: Convert _.any(a, …), _.some(a, …) to a.some(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
2285ee922e
js: Convert _.contains(a, …) to a.includes(…).
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
ef50346a29
js: Convert _.reject(a, … => …) to a.filter(… => !…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
4948240619
js: Convert _.filter(a, …) to a.filter(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
ac7b09d57e
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>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
719546641f
js: Convert a.indexOf(…) !== -1 to a.includes(…).
...
Babel polyfills this for us for Internet Explorer.
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, {
visitBinaryExpression(path) {
const { operator, left, right } = path.node;
if (
n.CallExpression.check(left) &&
n.MemberExpression.check(left.callee) &&
!left.callee.computed &&
n.Identifier.check(left.callee.property) &&
left.callee.property.name === "indexOf" &&
left.arguments.length === 1 &&
checkExpression(left.arguments[0]) &&
((["===", "!==", "==", "!=", ">", "<="].includes(operator) &&
n.UnaryExpression.check(right) &&
right.operator == "-" &&
n.Literal.check(right.argument) &&
right.argument.value === 1) ||
([">=", "<"].includes(operator) &&
n.Literal.check(right) &&
right.value === 0))
) {
const test = b.callExpression(
b.memberExpression(left.callee.object, b.identifier("includes")),
[left.arguments[0]]
);
path.replace(
["!==", "!=", ">", ">="].includes(operator)
? test
: b.unaryExpression("!", test)
);
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>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
788c5afbcf
js: Convert _.indexOf(a, …) to a.indexOf(…).
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
29dbf8ec77
schema: Convert _.find used as loop to for…of.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
13b8bf830f
message_viewport: Convert _.every used as loop to for…of.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
4fbee73d1a
emoji_picker: Convert _.any used as loop to for…of.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
2f314a0854
js: Convert _.map on jQuery collections to Array.from.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
7b0dea0351
js: Convert jQuery.each to for…of.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
22f3ec44bc
blueslip: Use modern spread arguments syntax.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
b5bf677717
submessage: Move submessages === undefined check up.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
4fa1075840
popovers: Check for undefined message.edit_history.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
d671d00cbd
settings_profile_fields: Iterate over field_types with Object.values.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
56ab5b4cf4
schema: Iterate over fields with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Chris Heald
86faebc2e5
lightbox: Don't blow up for messages not in the message store.
...
This should somewhat reduce the gravity of the failure mode for cases
where the message the user clicked cannot be found (which would be a
significant bug on its own merit in any case).
2020-02-10 14:00:40 -08:00
Chris Heald
c802a1393f
lightbox: Cast zid to an int before looking it up in message_store.
...
The keys for message_store are since the recent Map migration intended
to be integer message IDs, not strings (and likely were always
intended to be integers; the failure mode may simply have shifted).
This may just be a new bug, but this max also fix #9549 ; certainly
we'll want to redo any investigation with this fix in place.
Fixes #9549 .
2020-02-10 13:56:49 -08:00
Steve Howell
fa1059aa2e
stream_data: Remove stream_name param from add_sub().
...
We just get the stream_name from the sub struct now.
This mostly affects node tests.
The only place in real code where we called add_sub()
was when we initialized data from the server.
2020-02-09 22:08:50 -08:00
Vishnu KS
4572be8c27
api: Rename subject_links to topic_links.
...
Fixes #13588
2020-02-07 14:35:22 -08:00
Steve Howell
e9c6653852
node tests: Always enforce blueslip warn/error/fatal.
...
We now require all of our unit tests to handle
blueslip errors for warn/error/fatal. This
simplifies the zblueslip code to not have any
options passed in.
Most of the places changed here fell into two
categories:
- We were just missing a random piece of
setup data in a happy path test.
- We were testing error handling in just
a lazy way to ensure 100% coverage. Often
these error codepaths were fairly
contrived.
The one place where we especially lazy was
the stream_data tests, and those are now
more thorough.
2020-02-07 14:15:44 -08:00
Steve Howell
996d054fe9
messages: Send stream_id for stream messages.
...
This saves a tiny bit of bandwidth, but more
importantly, it protects us against races for
stream name changes. There's some argument that
if the user is thinking they're sending to
old_stream_name, and unbeknownst to them, the
stream has changed to new_stream_name, then we
should fail. But I think 99% of the time the
user just wants the message to go that stream
despite any renames.
In order to verify the blueslip error, we
had to turn on error checking, which required
a tiny fix to a place where we left out
a stream_id for add_sub.
2020-02-07 14:15:44 -08:00
Anders Kaseorg
02511bff1c
js: Automatically convert _.each to for…of.
...
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
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 { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
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);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.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;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
b3f63262af
lint: Delegate console.log check to ESLint.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
c48eb3d827
extract_people_from_message: Add missing default case.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
f912572887
settings_profile_fields: Iterate over field_data with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
dd10108c24
user_status: Iterate over page_params.user_status with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
91d3d5d9df
settings_org: Iterate over auth_methods with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
a9f5730270
drafts: Iterate over drafts with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
0d05decbe4
presence: Iterate over presence info with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
10edd2d0a1
server_events_dispatch: Iterate over event data with Object.entries.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
8bb515dbd9
emoji: Iterate over emoji_codes data with Object.{entries,values}.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
5de013b11e
emoji: Iterate over realm_emoji with Object.values.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Anders Kaseorg
07602c4aac
message_edit: Convert currently_echoing_messages from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
b8c8ba544d
message_edit: Convert currently_editing_messages from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
52a8449a0e
widgetize: Convert widget_contents from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
56436188a4
widgetize: Convert widgets from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
88c73602e0
vdom: Convert new_dict, old_dict from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
737efd1fac
presence: Convert presence_info from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
cbe476721c
message_store: Convert stored_messages from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
442ff64836
notifications: Convert notice_memory from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
44b3b7cf4a
emoji: Convert default_emoji_aliases from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
362ab8838b
emoji: Convert active_realm_emojis from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
419666fc31
emoji: Convert all_realm_emojis from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Anders Kaseorg
ab93385106
emoji: Convert emojis_by_name from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 17:24:43 -08:00
Steve Howell
58859ab115
unread: Remove topic counts.
...
We no longer use topic counts from unread.get_counts().
The topic list widget instead calls
unread.num_unread_for_topic().
2020-02-05 13:04:16 -08:00
Steve Howell
f0e18b3b3e
topic list: Use vdom techniques.
...
We avoid complicated code to update unread counts
by just using vdom.js.
One small change here is that if click on "more
topics", we replace it with the spinner instead
of putting the spinner after it. This saves us
a redraw under the new scheme.
2020-02-05 13:04:16 -08:00
Steve Howell
3a533dbe8f
vdom: Add replace_content/find parameters.
...
This will give us a bit more flexibility for
updating DOM when we have widgets that
get appended to other containers.
2020-02-05 13:04:16 -08:00
Steve Howell
b8f01f9cda
people: Rename method to get_by_user_id().
...
This name is consistent with:
get_by_email()
get_by_name()
2020-02-05 12:04:56 -08:00
Anders Kaseorg
ea9212a92d
babel: Enable loose mode.
...
Due to try-catch deoptimization, Babel strict mode for…of loops run
about 5× slower in Firefox than Babel loose mode for…of, native
for…of, or forEach (which are all about the same speed). Chrome
doesn’t seem to care.
For some reason we need to explicitly add the core-js Symbol polyfill
near the beginning of the common bundle. Otherwise it gets loaded at
the wrong time and the Casper tests fail.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-05 11:52:52 -08:00
Anders Kaseorg
de3146c137
js: Replace [...x] with Array.from(x).
...
Babel strict generates more code for [...x] than you’d like, while
Babel loose mode assumes x is an array.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-05 11:52:52 -08:00
Steve Howell
437961fba3
presence: Eliminate unused mobile-related code.
...
We had a plan at some point to use this to display a phone icon or
something for users who would receive push notifications if you
messaged them. IT's not clear that feature was a good idea in any
case, but it certainly shouldn't be synced as presence data; it would
change >100x less often than the rest of presence and so should likely
be synced differently, maybe as a property on user. So it's best to
delete this prototype.
2020-02-05 11:50:10 -08:00
Anders Kaseorg
91b57be02e
dependencies: Upgrade stacktrace-gps from 3.0.3 to 3.0.4.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 22:13:33 -08:00
Anders Kaseorg
e88fac499f
dependencies: Upgrade emoji-datasource from 4.0.4 to 5.0.1.
...
The “Smileys & People” category has been split into “Smilys & Emotion”
and “People & Body”.
Also, fix generate_sha1sum_emoji to read the emoji-datasource-google
version from yarn.lock, since package.json only gives a version range.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 21:30:51 -08:00
Rohitt Vashishtha
f4b02ce31e
compose: Add fences of unused length in quote-and-reply.
...
When quoting a message with fenced code blocks without a language,
we used to have ambiguity in which '```' fence terminates the quote.
This commit adds explicitly non-interfering fences, which fixes the
above issue as well as makes the raw message easier to quickly read.
Fixes #12446 .
2020-02-04 18:17:47 -08:00
Rohitt Vashishtha
f5990ccbff
compose: Add message info with quote-and-reply.
...
This adds the original message's sender name along with a
link to narrow to that message when using quote-and-reply.
Fixes #11568 .
2020-02-04 18:17:47 -08:00
Ryan Rehman
174b2abcfd
settings: Migrate to stream_post_policy structure.
...
This commit includes a new `stream_post_policy` setting,
by replacing the `is_announcement_only` field from the Stream model,
which is done by mirroring the structure of the existing
`create_stream_policy`.
It includes the necessary schema and database migrations to migrate
the is_announcement_only boolean field to stream_post_policy,
a smallPositiveInteger field similar to many other settings.
This change is done to allow organization administrators to restrict
new members from creating and posting to a stream. However, this does
not affect admins who are new members.
With many tweaks by tabbott to documentation under /help, etc.
Fixes #13616 .
2020-02-04 17:08:08 -08:00
Pragati Agrawal
b975d693bd
stream_edit: Fix realm time sync of notifications setting checkbox.
...
This fixes the buggy behavior for streams which inherits the notification
setting from UserProfile, and are actively opened in "Streams > Stream
settings", if a user has opened two browser windows, and changes the
notification setting from "Settings > Notifications", then the changes
don't reflect such "Streams > Stream settings" notification setting
checkboxes for such stream.
Partially fixes : #12304 .
2020-02-04 13:53:27 -08:00
Pragati Agrawal
e79c28e13c
stream_edit: Use e.currentTarget instead of e.target.
...
Here we have attached our handler to `.sub_setting_checkbox` so
`e.currentTarget` will return element with class `.sub_setting_checkbox`
but `e.target` will return exactly which element we have clicked, which
could be a child of `.sub_setting_checkbox`. So instead of,
```
$(e.target).closest(".sub_setting_checkbox")
```
we can use
```
$(e.currentTarget)
```
which is more clean and intuitive.
- `e.currentTarget` is less popular which could be the reason behind using
two step hack to get the targetted element.
2020-02-04 13:53:27 -08:00
Pragati Agrawal
16abd7ec96
subs: Use single jquery-handlers for multiple events.
...
Rather than defining two different jquery event-handlers for two different
events, we can use a single jquery handler as the function is the same for
both handlers.
2020-02-04 13:53:27 -08:00
Pragati Agrawal
84fd0b0974
stream_edit: Remove separate click handlers from notifications checkboxes.
...
Rather than looping on each setting checkbox (except "Mute stream"), we can
attach single click handler to `.sub_setting_checkbox` class.
2020-02-04 13:53:27 -08:00
Tim Abbott
ceb0879b0d
unread: Add a block comment explaining how it works.
2020-02-04 12:39:58 -08:00
Tim Abbott
02bc630881
presence: Document why we no longer need suspect_offline.
...
Since it took a lot of effort to debug the original issue that caused
us to introduce suspect_offline, it seems worth writing a comment
explaining why we won't see that issue here.
2020-02-04 12:35:51 -08:00
Steve Howell
a672a00677
presence: Add user_id to presence event.
...
In a later commit, we will eliminate email for
clients who have set slim_presence as their
preference.
2020-02-04 12:30:36 -08:00
Steve Howell
36aee9e69c
presence: Remove suspect_offline flag.
...
We now use user_ids for presence, so we don't need
to worry about races related to unknown emails
being sent to us. Now we just update the data
structure based on user_id, and
it will be there when we render the presence
widget for that user_id, or else it will
simply be ignored.
It's not clear to me whether we still need
dont_block here, so I didn't touch that code.
Here is the commit that added the suspect_offline
flag, for easy reference:
f207450cdb
2020-02-04 12:30:36 -08:00
Steve Howell
bf9144ff69
presence: Add slim_presence flag.
...
This flag affects page_params and the
payload you get back from POSTs to this
url:
users/me/presence
The flag does not yet affect the
presence events that get sent to a
client.
2020-02-04 12:30:34 -08:00
Steve Howell
145c17d9d6
presence: Remove obsolete defensive code.
...
If you look at info_for, it clearly never returns
`undefined`, so this defensive code isn't preventing
any bugs.
Also, we are doing a better job now of filtering
user_ids in upstream code.
2020-02-04 12:24:53 -08:00
Steve Howell
ef84d47d88
presence: Add warning for missing user_id.
...
This is defensive code for the scenario that we
have a user_id in presence but not people. This is
unlikely to occur by the time that we actually render
the buddy list, which is the context for this code.
We have previously been reporting an error here via
the people code, but we add an additional warning.
Also, we filter the user_id from the result.
2020-02-04 12:24:53 -08:00
Anders Kaseorg
4480963f5a
dict: Remove each method.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
fac2c71776
dict: Replace items method with @@iterator method.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
9e1343ff8a
dict, lazy_set: Return an iterator from values method.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
45d3be5449
dict, lazy_set: Return an iterator from keys method.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
61de2e8192
dict: Remove is_empty method.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
60fac80c8e
dict, lazy_set: Replace num_items method with size property.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
da633e953e
lazy_set: Convert LazySet to a real class.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
fe54e73c77
dict, lazy_set: Rename del method to delete, for consistency with Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
0e657756f1
dict: Make set method return value consistent with Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:03 -08:00
Anders Kaseorg
ab61222dd5
dict: Reimplement Dict using Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:02 -08:00
Anders Kaseorg
b16222a38b
dict: Remove setdefault method.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:02 -08:00
Anders Kaseorg
8872aca907
dict: Remove clone method.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:02 -08:00
Anders Kaseorg
22555f53ad
dict: Remove Dict.from_array.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:02 -08:00
Anders Kaseorg
52765796c2
dict: Remove Dict.from.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:22:02 -08:00
Anders Kaseorg
5b824702b4
unread: Replace key_to_bucket Map with Dict/FoldDict/IntDict.
...
This reverts commit d84646f091
(which
incorrectly assumed in unread_topic_counter that the messages were
present in the message store), while fixing the type confusion problem
by using IntDict for stream_id keys.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 12:21:29 -08:00
Anders Kaseorg
252910202b
poll_widget: Convert votes from object to Map.
...
Fixes implicity stringification of the user ID keys.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-03 15:59:26 -08:00
Anders Kaseorg
85620df34e
poll_widget: Convert key_to_option from object to Map.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-03 15:59:26 -08:00
Anders Kaseorg
849c7f83a0
blueslip_stacktrace: Handle promises in sourceCache.
...
Fixes “TypeError: sourceContent.split is not a function” at
blueslip_stacktrace.ts:60 when there’s another error during page load.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-03 15:58:57 -08:00
shubhamgupta2956
aaa30df94c
Hotkeys: Change hotkeys behaviour on dropdown open.
...
Disables message_view_only hotkeys when dropdown menu is opened.
Fixes : #11990
2020-02-03 13:45:07 -08:00
shubhamgupta2956
23c5123a55
hotkeys: Change 'q' and 'w' to message_view_only
...
Add message_view_only property to 'q' and 'w' hotkeys
2020-02-03 13:40:48 -08:00
Pragati Agrawal
8e733fb513
settings_org: Extract the function to hide or show the element block.
...
This change leads to some de-duplication of repeated code.
2020-02-03 11:37:40 -08:00
Pragati Agrawal
dd6e616c9b
settings_org: De-duplicate code to set value of normal dropdowns.
...
In the future, any property which doesn't have any dependent setting can be
added to `simple_dropdown_properties` list, which automates setting the
value of dropdowns on saving.
2020-02-03 11:37:40 -08:00
Anders Kaseorg
e4259d48a5
dict: Assert that Dict is only used with string keys.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
b41968c4a7
topic_list: Replace active_widgets Dict with IntDict.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
a7bed2c8a3
stream_list: Replace rows Dict with IntDict.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
b5cd8dcedd
starred_messages: Replace ids Dict with Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
1189747d4c
settings_streams: Replace row_dict Dict with IntDict.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
90ebaa86e9
settings_sections: Replace is_loaded Dict with loaded_groups Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
21b13e656d
recent_senders: Replace topic_senders and stream_senders with IntDict.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
c4e1357e19
pm_conversations: Replace partners Dict with Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00
Anders Kaseorg
052497de1c
muting: Replace muted_topics Dict with IntDict.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-02 20:37:41 -08:00