2021-03-11 05:43:45 +01:00
|
|
|
|
import $ from "jquery";
|
2021-02-28 21:33:10 +01:00
|
|
|
|
import SimpleBar from "simplebar/dist/simplebar";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 21:33:10 +01:00
|
|
|
|
import * as common from "./common";
|
2021-04-13 06:51:54 +02:00
|
|
|
|
import {$t} from "./i18n";
|
2021-02-28 21:33:10 +01:00
|
|
|
|
import {localstorage} from "./localstorage";
|
|
|
|
|
import * as message_list from "./message_list";
|
2021-03-30 02:21:21 +02:00
|
|
|
|
import * as message_lists from "./message_lists";
|
2021-02-24 05:00:36 +01:00
|
|
|
|
|
2012-12-03 20:54:29 +01:00
|
|
|
|
// What, if anything, obscures the home tab?
|
2012-11-30 18:28:23 +01:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function replace_emoji_with_text(element) {
|
2013-07-23 00:25:25 +02:00
|
|
|
|
element.find(".emoji").replaceWith(function () {
|
2017-10-14 23:14:45 +02:00
|
|
|
|
if ($(this).is("img")) {
|
|
|
|
|
return $(this).attr("alt");
|
|
|
|
|
}
|
2017-09-27 19:39:42 +02:00
|
|
|
|
return $(this).text();
|
2013-07-23 00:25:25 +02:00
|
|
|
|
});
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2013-07-23 00:25:25 +02:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function get_content_element(element_selector) {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const element = element_selector.expectOne()[0];
|
2019-11-13 21:04:29 +01:00
|
|
|
|
const sb = SimpleBar.instances.get(element);
|
|
|
|
|
if (sb) {
|
|
|
|
|
return $(sb.getContentElement());
|
2019-03-01 01:40:05 +01:00
|
|
|
|
}
|
|
|
|
|
return element_selector;
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2017-08-02 16:06:38 +02:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function get_scroll_element(element_selector) {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const element = element_selector.expectOne()[0];
|
2019-11-13 21:04:29 +01:00
|
|
|
|
const sb = SimpleBar.instances.get(element);
|
|
|
|
|
if (sb) {
|
|
|
|
|
return $(sb.getScrollElement());
|
2020-07-15 01:29:15 +02:00
|
|
|
|
} else if ("simplebar" in element.dataset) {
|
2019-07-26 00:22:43 +02:00
|
|
|
|
// The SimpleBar mutation observer hasn’t processed this element yet.
|
|
|
|
|
// Create the SimpleBar early in case we need to add event listeners.
|
|
|
|
|
return $(new SimpleBar(element).getScrollElement());
|
2019-01-09 14:30:35 +01:00
|
|
|
|
}
|
2019-03-01 01:40:05 +01:00
|
|
|
|
return element_selector;
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2019-01-09 14:30:35 +01:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function reset_scrollbar(element_selector) {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const element = element_selector.expectOne()[0];
|
2019-11-13 21:04:29 +01:00
|
|
|
|
const sb = SimpleBar.instances.get(element);
|
|
|
|
|
if (sb) {
|
|
|
|
|
sb.getScrollElement().scrollTop = 0;
|
2019-03-01 01:40:05 +01:00
|
|
|
|
} else {
|
|
|
|
|
element.scrollTop = 0;
|
2018-03-20 04:10:20 +01:00
|
|
|
|
}
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2017-08-02 16:06:38 +02:00
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
|
function update_message_in_all_views(message_id, callback) {
|
2021-03-30 06:23:09 +02:00
|
|
|
|
for (const list of [message_lists.home, message_list.narrowed]) {
|
2013-12-19 17:03:08 +01:00
|
|
|
|
if (list === undefined) {
|
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-06 06:19:47 +01:00
|
|
|
|
continue;
|
2013-03-27 18:30:02 +01:00
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const row = list.get_row(message_id);
|
2013-03-27 18:30:02 +01:00
|
|
|
|
if (row === undefined) {
|
2013-12-19 17:03:08 +01:00
|
|
|
|
// The row may not exist, e.g. if you do an action on a message in
|
|
|
|
|
// a narrowed view
|
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-06 06:19:47 +01:00
|
|
|
|
continue;
|
2013-03-27 18:30:02 +01:00
|
|
|
|
}
|
2013-12-19 17:03:08 +01:00
|
|
|
|
callback(row);
|
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-06 06:19:47 +01:00
|
|
|
|
}
|
2013-12-19 17:03:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function update_starred_view(message_id, new_value) {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const starred = new_value;
|
2013-12-19 17:03:08 +01:00
|
|
|
|
|
|
|
|
|
// Avoid a full re-render, but update the star in each message
|
|
|
|
|
// table in which it is visible.
|
2020-07-02 01:45:54 +02:00
|
|
|
|
update_message_in_all_views(message_id, (row) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const elt = row.find(".star");
|
2020-07-03 17:49:19 +02:00
|
|
|
|
const star_container = row.find(".star_container");
|
2014-01-23 17:52:28 +01:00
|
|
|
|
if (starred) {
|
2020-07-03 17:49:19 +02:00
|
|
|
|
elt.addClass("fa-star").removeClass("fa-star-o");
|
|
|
|
|
star_container.removeClass("empty-star");
|
2014-01-23 17:52:28 +01:00
|
|
|
|
} else {
|
2020-07-03 17:49:19 +02:00
|
|
|
|
elt.removeClass("fa-star").addClass("fa-star-o");
|
|
|
|
|
star_container.addClass("empty-star");
|
2014-01-23 17:52:28 +01:00
|
|
|
|
}
|
2021-04-13 06:51:54 +02:00
|
|
|
|
const title_state = starred ? $t({defaultMessage: "Unstar"}) : $t({defaultMessage: "Star"});
|
2021-02-07 22:58:41 +01:00
|
|
|
|
elt.attr(
|
|
|
|
|
"title",
|
2021-04-13 06:51:54 +02:00
|
|
|
|
$t(
|
|
|
|
|
{defaultMessage: "{starred_status} this message (Ctrl + s)"},
|
|
|
|
|
{starred_status: title_state},
|
|
|
|
|
),
|
2021-02-07 22:58:41 +01:00
|
|
|
|
);
|
2013-03-27 18:30:02 +01:00
|
|
|
|
});
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2013-03-27 18:30:02 +01:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function show_message_failed(message_id, failed_msg) {
|
2013-12-19 17:03:08 +01:00
|
|
|
|
// Failed to send message, so display inline retry/cancel
|
2020-07-02 01:45:54 +02:00
|
|
|
|
update_message_in_all_views(message_id, (row) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const failed_div = row.find(".message_failed");
|
|
|
|
|
failed_div.toggleClass("notvisible", false);
|
|
|
|
|
failed_div.find(".failed_text").attr("title", failed_msg);
|
2013-12-19 17:03:08 +01:00
|
|
|
|
});
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2013-12-19 17:03:08 +01:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function show_failed_message_success(message_id) {
|
2013-12-19 17:03:08 +01:00
|
|
|
|
// Previously failed message succeeded
|
2020-07-02 01:45:54 +02:00
|
|
|
|
update_message_in_all_views(message_id, (row) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
|
row.find(".message_failed").toggleClass("notvisible", true);
|
2013-12-19 17:03:08 +01:00
|
|
|
|
});
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2013-12-19 17:03:08 +01:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function get_hotkey_deprecation_notice(originalHotkey, replacementHotkey) {
|
2021-04-13 06:51:54 +02:00
|
|
|
|
return $t(
|
|
|
|
|
{
|
|
|
|
|
defaultMessage:
|
|
|
|
|
'We\'ve replaced the "{originalHotkey}" hotkey with "{replacementHotkey}" to make this common shortcut easier to trigger.',
|
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
|
{originalHotkey, replacementHotkey},
|
2018-07-21 02:19:14 +02:00
|
|
|
|
);
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2018-07-21 02:19:14 +02:00
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let shown_deprecation_notices = [];
|
2021-02-28 21:33:10 +01:00
|
|
|
|
|
|
|
|
|
export function maybe_show_deprecation_notice(key) {
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let message;
|
|
|
|
|
const isCmdOrCtrl = common.has_mac_keyboard() ? "Cmd" : "Ctrl";
|
2020-07-15 01:29:15 +02:00
|
|
|
|
if (key === "C") {
|
2021-02-28 21:33:10 +01:00
|
|
|
|
message = get_hotkey_deprecation_notice("C", "x");
|
2020-07-15 01:29:15 +02:00
|
|
|
|
} else if (key === "*") {
|
2021-02-28 21:33:10 +01:00
|
|
|
|
message = get_hotkey_deprecation_notice("*", isCmdOrCtrl + " + s");
|
2018-02-08 15:17:26 +01:00
|
|
|
|
} else {
|
2018-04-02 01:19:47 +02:00
|
|
|
|
blueslip.error("Unexpected deprecation notice for hotkey:", key);
|
2018-02-08 15:17:26 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 01:19:47 +02:00
|
|
|
|
// Here we handle the tracking for showing deprecation notices,
|
|
|
|
|
// whether or not local storage is available.
|
|
|
|
|
if (localstorage.supported()) {
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const notices_from_storage = JSON.parse(localStorage.getItem("shown_deprecation_notices"));
|
2018-04-02 01:19:47 +02:00
|
|
|
|
if (notices_from_storage !== null) {
|
|
|
|
|
shown_deprecation_notices = notices_from_storage;
|
|
|
|
|
} else {
|
|
|
|
|
shown_deprecation_notices = [];
|
|
|
|
|
}
|
2018-02-08 15:17:26 +01:00
|
|
|
|
}
|
2018-04-02 01:19:47 +02:00
|
|
|
|
|
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-08 04:55:06 +01:00
|
|
|
|
if (!shown_deprecation_notices.includes(key)) {
|
2020-07-15 01:29:15 +02:00
|
|
|
|
$("#deprecation-notice-modal").modal("show");
|
|
|
|
|
$("#deprecation-notice-message").text(message);
|
2020-07-20 21:24:26 +02:00
|
|
|
|
$("#close-deprecation-notice").trigger("focus");
|
2018-02-08 15:17:26 +01:00
|
|
|
|
shown_deprecation_notices.push(key);
|
2018-04-02 01:19:47 +02:00
|
|
|
|
if (localstorage.supported()) {
|
2020-07-15 00:34:28 +02:00
|
|
|
|
localStorage.setItem(
|
|
|
|
|
"shown_deprecation_notices",
|
|
|
|
|
JSON.stringify(shown_deprecation_notices),
|
|
|
|
|
);
|
2018-04-02 01:19:47 +02:00
|
|
|
|
}
|
2018-02-08 15:17:26 +01:00
|
|
|
|
}
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2018-02-08 15:17:26 +01:00
|
|
|
|
|
2013-02-18 08:16:57 +01:00
|
|
|
|
// Save the compose content cursor position and restore when we
|
|
|
|
|
// shift-tab back in (see hotkey.js).
|
2019-11-02 00:06:25 +01:00
|
|
|
|
let saved_compose_cursor = 0;
|
2013-02-18 08:16:57 +01:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function set_compose_textarea_handlers() {
|
2020-07-20 21:26:58 +02:00
|
|
|
|
$("#compose-textarea").on("blur", function () {
|
2016-06-14 22:49:41 +02:00
|
|
|
|
saved_compose_cursor = $(this).caret();
|
2013-02-18 08:16:57 +01:00
|
|
|
|
});
|
2017-04-13 22:33:26 +02:00
|
|
|
|
|
|
|
|
|
// on the end of the modified-message fade in, remove the fade-in-message class.
|
2019-11-02 00:06:25 +01:00
|
|
|
|
const animationEnd = "webkitAnimationEnd oanimationend msAnimationEnd animationend";
|
2017-04-13 22:33:26 +02:00
|
|
|
|
$("body").on(animationEnd, ".fade-in-message", function () {
|
|
|
|
|
$(this).removeClass("fade-in-message");
|
|
|
|
|
});
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2013-02-18 08:16:57 +01:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function restore_compose_cursor() {
|
2020-07-20 21:24:26 +02:00
|
|
|
|
$("#compose-textarea").trigger("focus").caret(saved_compose_cursor);
|
2021-02-28 21:33:10 +01:00
|
|
|
|
}
|
2017-08-08 02:16:35 +02:00
|
|
|
|
|
2021-02-28 21:33:10 +01:00
|
|
|
|
export function initialize() {
|
|
|
|
|
set_compose_textarea_handlers();
|
|
|
|
|
}
|