2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:18:48 +01:00
|
|
|
import render_stream_specific_notification_row from "../templates/settings/stream_specific_notification_row.hbs";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 01:18:48 +01:00
|
|
|
import * as channel from "./channel";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t} from "./i18n";
|
2021-02-28 01:18:48 +01:00
|
|
|
import * as notifications from "./notifications";
|
2021-08-03 09:26:35 +02:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:18:48 +01:00
|
|
|
import * as settings_config from "./settings_config";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as settings_org from "./settings_org";
|
2021-02-28 01:18:48 +01:00
|
|
|
import * as settings_ui from "./settings_ui";
|
|
|
|
import * as stream_edit from "./stream_edit";
|
2021-04-04 15:15:18 +02:00
|
|
|
import * as stream_settings_data from "./stream_settings_data";
|
2021-02-28 01:18:48 +01:00
|
|
|
import * as unread_ui from "./unread_ui";
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2020-03-12 17:40:38 +01:00
|
|
|
function rerender_ui() {
|
|
|
|
const unmatched_streams_table = $("#stream-specific-notify-table");
|
|
|
|
if (unmatched_streams_table.length === 0) {
|
|
|
|
// If we haven't rendered "notification settings" yet, do nothing.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-09 22:29:53 +02:00
|
|
|
const unmatched_streams =
|
|
|
|
stream_settings_data.get_unmatched_streams_for_notification_settings();
|
2020-03-12 17:40:38 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
unmatched_streams_table.find(".stream-row").remove();
|
2020-07-09 16:05:26 +02:00
|
|
|
|
|
|
|
for (const stream of unmatched_streams) {
|
|
|
|
unmatched_streams_table.append(
|
|
|
|
render_stream_specific_notification_row({
|
2020-07-20 22:18:43 +02:00
|
|
|
stream,
|
2020-03-28 18:03:43 +01:00
|
|
|
stream_specific_notification_settings:
|
2020-07-15 00:34:28 +02:00
|
|
|
settings_config.stream_specific_notification_settings,
|
2020-03-28 18:03:43 +01:00
|
|
|
is_disabled: settings_config.all_notifications().show_push_notifications_tooltip,
|
2020-07-09 16:05:26 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
2020-03-12 17:40:38 +01:00
|
|
|
|
|
|
|
if (unmatched_streams.length === 0) {
|
|
|
|
unmatched_streams_table.css("display", "none");
|
|
|
|
} else {
|
|
|
|
unmatched_streams_table.css("display", "table-row-group");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 18:11:59 +02:00
|
|
|
function change_notification_setting(setting, value, status_element) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
2021-05-04 18:11:59 +02:00
|
|
|
data[setting] = value;
|
2021-07-11 11:16:32 +02:00
|
|
|
settings_ui.do_settings_change(channel.patch, "/json/settings", data, status_element);
|
2018-03-07 23:08:42 +01:00
|
|
|
}
|
2017-04-06 16:01:07 +02:00
|
|
|
|
2019-06-29 22:00:44 +02:00
|
|
|
function update_desktop_icon_count_display() {
|
2021-08-26 10:10:41 +02:00
|
|
|
const container = $("#user-notification-settings");
|
|
|
|
container
|
|
|
|
.find(".setting_desktop_icon_count_display")
|
|
|
|
.val(user_settings.desktop_icon_count_display);
|
2020-10-21 04:07:35 +02:00
|
|
|
unread_ui.update_unread_counts();
|
2019-06-29 22:00:44 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:18:48 +01:00
|
|
|
export function set_enable_digest_emails_visibility() {
|
2021-08-09 13:26:49 +02:00
|
|
|
const container = $("#user-notification-settings");
|
2021-08-03 09:26:35 +02:00
|
|
|
if (page_params.realm_digest_emails_enabled) {
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".enable_digest_emails_label").parent().show();
|
2019-05-10 08:45:46 +02:00
|
|
|
} else {
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".enable_digest_emails_label").parent().hide();
|
2019-05-10 08:45:46 +02:00
|
|
|
}
|
2021-02-28 01:18:48 +01:00
|
|
|
}
|
2019-05-10 08:45:46 +02:00
|
|
|
|
2021-04-28 00:25:27 +02:00
|
|
|
export function set_enable_marketing_emails_visibility() {
|
2021-08-09 13:26:49 +02:00
|
|
|
const container = $("#user-notification-settings");
|
2021-08-03 09:26:35 +02:00
|
|
|
if (page_params.corporate_enabled) {
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".enable_marketing_emails_label").parent().show();
|
2021-04-28 00:25:27 +02:00
|
|
|
} else {
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".enable_marketing_emails_label").parent().hide();
|
2021-04-28 00:25:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:18:48 +01:00
|
|
|
export function set_up() {
|
2021-08-09 13:26:49 +02:00
|
|
|
const container = $("#user-notification-settings");
|
2021-08-26 10:10:41 +02:00
|
|
|
container.on("change", "input, select", function (e) {
|
2020-03-22 16:51:22 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
const input_elem = $(e.currentTarget);
|
2020-03-12 17:40:38 +01:00
|
|
|
if (input_elem.parents("#stream-specific-notify-table").length) {
|
2020-07-22 00:43:11 +02:00
|
|
|
stream_edit.stream_setting_changed(e, true);
|
2020-03-12 17:40:38 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-03-22 16:51:22 +01:00
|
|
|
const setting_name = input_elem.attr("name");
|
2020-07-15 00:34:28 +02:00
|
|
|
change_notification_setting(
|
|
|
|
setting_name,
|
|
|
|
settings_org.get_input_element_value(this),
|
|
|
|
input_elem.closest(".subsection-parent").find(".alert-notification"),
|
|
|
|
);
|
2020-03-22 16:51:22 +01:00
|
|
|
});
|
2017-07-21 01:04:12 +02:00
|
|
|
|
2019-06-29 22:00:44 +02:00
|
|
|
update_desktop_icon_count_display();
|
|
|
|
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".send_test_notification").on("click", () => {
|
2020-04-27 00:02:36 +02:00
|
|
|
notifications.send_test_notification(
|
2021-04-13 06:51:54 +02:00
|
|
|
$t({defaultMessage: "This is what a Zulip notification looks like."}),
|
2020-04-27 00:02:36 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".play_notification_sound").on("click", () => {
|
2021-07-28 16:00:58 +02:00
|
|
|
if (user_settings.notification_sound !== "none") {
|
2021-08-09 14:57:06 +02:00
|
|
|
$("#user-notification-sound-audio")[0].play();
|
2021-04-28 01:04:06 +02:00
|
|
|
}
|
2018-01-11 21:36:11 +01:00
|
|
|
});
|
|
|
|
|
2021-08-10 12:56:28 +02:00
|
|
|
const notification_sound_dropdown = container.find(".setting_notification_sound");
|
2021-07-28 16:00:58 +02:00
|
|
|
notification_sound_dropdown.val(user_settings.notification_sound);
|
2018-01-11 21:36:11 +01:00
|
|
|
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".enable_sounds, .enable_stream_audible_notifications").on("change", () => {
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
2021-08-09 13:26:49 +02:00
|
|
|
container.find(".enable_stream_audible_notifications").prop("checked") ||
|
|
|
|
container.find(".enable_sounds").prop("checked")
|
2020-07-15 00:34:28 +02:00
|
|
|
) {
|
2018-01-11 21:36:11 +01:00
|
|
|
notification_sound_dropdown.prop("disabled", false);
|
|
|
|
notification_sound_dropdown.parent().removeClass("control-label-disabled");
|
|
|
|
} else {
|
|
|
|
notification_sound_dropdown.prop("disabled", true);
|
|
|
|
notification_sound_dropdown.parent().addClass("control-label-disabled");
|
|
|
|
}
|
|
|
|
});
|
2021-08-14 11:31:31 +02:00
|
|
|
|
|
|
|
const email_notifications_batching_period_dropdown = $("#email_notifications_batching_period");
|
|
|
|
email_notifications_batching_period_dropdown.val(
|
|
|
|
user_settings.email_notifications_batching_period_seconds,
|
|
|
|
);
|
|
|
|
|
2021-02-28 01:18:48 +01:00
|
|
|
set_enable_digest_emails_visibility();
|
2021-04-28 00:25:27 +02:00
|
|
|
set_enable_marketing_emails_visibility();
|
2020-03-12 17:40:38 +01:00
|
|
|
rerender_ui();
|
2021-02-28 01:18:48 +01:00
|
|
|
}
|
2017-04-06 16:01:07 +02:00
|
|
|
|
2021-02-28 01:18:48 +01:00
|
|
|
export function update_page() {
|
2021-08-26 10:10:41 +02:00
|
|
|
const container = $("#user-notification-settings");
|
2020-03-28 18:03:43 +01:00
|
|
|
for (const setting of settings_config.all_notification_settings) {
|
2020-07-15 00:34:28 +02:00
|
|
|
if (
|
|
|
|
setting === "enable_offline_push_notifications" &&
|
2021-08-03 09:26:35 +02:00
|
|
|
!page_params.realm_push_notifications_enabled
|
2020-07-15 00:34:28 +02:00
|
|
|
) {
|
2019-04-30 05:56:23 +02:00
|
|
|
// If push notifications are disabled at the realm level,
|
|
|
|
// we should just leave the checkbox always off.
|
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;
|
2020-07-15 01:29:15 +02:00
|
|
|
} else if (setting === "desktop_icon_count_display") {
|
2019-06-29 22:00:44 +02:00
|
|
|
update_desktop_icon_count_display();
|
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;
|
2021-09-05 13:20:54 +02:00
|
|
|
} else if (setting === "notification_sound") {
|
2021-08-26 10:10:41 +02:00
|
|
|
container.find(".setting_notification_sound").val(user_settings.notification_sound);
|
2019-04-30 05:56:23 +02:00
|
|
|
}
|
2019-06-29 22:00:44 +02:00
|
|
|
|
2021-08-26 10:10:41 +02:00
|
|
|
container.find(`.${CSS.escape(setting)}`).prop("checked", user_settings[setting]);
|
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
|
|
|
}
|
2020-03-12 17:40:38 +01:00
|
|
|
rerender_ui();
|
2021-02-28 01:18:48 +01:00
|
|
|
}
|