2020-03-12 17:40:38 +01:00
|
|
|
const render_stream_specific_notification_row = require('../templates/settings/stream_specific_notification_row.hbs');
|
2020-03-28 18:03:43 +01:00
|
|
|
const settings_config = require("./settings_config");
|
2020-03-12 17:40:38 +01:00
|
|
|
|
2020-03-28 18:03:43 +01:00
|
|
|
exports.get_notifications_table_row_data = function (notify_settings) {
|
2020-04-01 19:43:34 +02:00
|
|
|
return settings_config.general_notifications_table_labels.realm.map((column, index) => {
|
2020-03-23 08:29:48 +01:00
|
|
|
const setting_name = notify_settings[index];
|
|
|
|
if (setting_name === undefined) {
|
|
|
|
return {
|
|
|
|
setting_name: "",
|
|
|
|
is_disabled: true,
|
|
|
|
is_checked: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const checkbox = {
|
|
|
|
setting_name: setting_name,
|
|
|
|
is_disabled: false,
|
|
|
|
};
|
|
|
|
if (column === "mobile") {
|
|
|
|
checkbox.is_disabled = !page_params.realm_push_notifications_enabled;
|
|
|
|
}
|
|
|
|
checkbox.is_checked = page_params[setting_name];
|
|
|
|
return checkbox;
|
|
|
|
});
|
2019-06-13 10:27:55 +02:00
|
|
|
};
|
|
|
|
|
2019-06-29 22:00:44 +02:00
|
|
|
exports.desktop_icon_count_display_values = {
|
|
|
|
messages: {
|
|
|
|
code: 1,
|
|
|
|
description: i18n.t("All unreads"),
|
|
|
|
},
|
|
|
|
notifiable: {
|
|
|
|
code: 2,
|
|
|
|
description: i18n.t("Private messages and mentions"),
|
|
|
|
},
|
2019-08-19 23:33:11 +02:00
|
|
|
none: {
|
|
|
|
code: 3,
|
|
|
|
description: i18n.t("None"),
|
|
|
|
},
|
2019-06-29 22:00:44 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unmatched_streams = stream_data.get_unmatched_streams_for_notification_settings();
|
|
|
|
|
|
|
|
list_render.create(unmatched_streams_table, unmatched_streams, {
|
|
|
|
name: "unmatched-streams-list",
|
|
|
|
modifier: function (unmatched_streams) {
|
|
|
|
return render_stream_specific_notification_row({
|
|
|
|
stream: unmatched_streams,
|
2020-03-28 18:03:43 +01:00
|
|
|
stream_specific_notification_settings:
|
|
|
|
settings_config.stream_specific_notification_settings,
|
|
|
|
is_disabled: settings_config.all_notifications().show_push_notifications_tooltip,
|
2020-03-12 17:40:38 +01:00
|
|
|
});
|
|
|
|
},
|
2020-04-13 11:55:25 +02:00
|
|
|
}).init();
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 23:08:42 +01:00
|
|
|
function change_notification_setting(setting, setting_data, status_element) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
2018-03-07 23:08:42 +01:00
|
|
|
data[setting] = JSON.stringify(setting_data);
|
2018-03-11 10:47:36 +01:00
|
|
|
settings_ui.do_settings_change(channel.patch, '/json/settings/notifications', 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() {
|
|
|
|
$("#desktop_icon_count_display").val(page_params.desktop_icon_count_display);
|
2019-11-02 00:06:25 +01:00
|
|
|
const count = unread.get_notifiable_count();
|
2019-07-20 14:45:56 +02:00
|
|
|
notifications.update_title_count(count);
|
2019-06-29 22:00:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 08:45:46 +02:00
|
|
|
exports.set_enable_digest_emails_visibility = function () {
|
|
|
|
if (page_params.realm_digest_emails_enabled) {
|
|
|
|
$('#enable_digest_emails_label').parent().show();
|
|
|
|
} else {
|
|
|
|
$('#enable_digest_emails_label').parent().hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-07 23:08:42 +01:00
|
|
|
exports.set_up = function () {
|
2020-03-22 16:51:22 +01:00
|
|
|
$('#notification-settings').on('change', 'input, select', function (e) {
|
|
|
|
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) {
|
|
|
|
stream_edit.stream_setting_clicked(e);
|
|
|
|
return;
|
|
|
|
}
|
2020-03-22 16:51:22 +01:00
|
|
|
const setting_name = input_elem.attr("name");
|
|
|
|
change_notification_setting(setting_name,
|
|
|
|
settings_org.get_input_element_value(this),
|
|
|
|
input_elem.closest('.subsection-parent').find('.alert-notification'));
|
|
|
|
});
|
2017-07-21 01:04:12 +02:00
|
|
|
|
2019-06-29 22:00:44 +02:00
|
|
|
update_desktop_icon_count_display();
|
|
|
|
|
2018-01-11 21:36:11 +01:00
|
|
|
$("#play_notification_sound").click(function () {
|
|
|
|
$("#notifications-area").find("audio")[0].play();
|
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const notification_sound_dropdown = $("#notification_sound");
|
2018-01-11 21:36:11 +01:00
|
|
|
notification_sound_dropdown.val(page_params.notification_sound);
|
|
|
|
|
2019-06-11 08:47:49 +02:00
|
|
|
$("#enable_sounds, #enable_stream_audible_notifications").change(function () {
|
|
|
|
if ($("#enable_stream_audible_notifications").prop("checked") || $("#enable_sounds").prop("checked")) {
|
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");
|
|
|
|
}
|
|
|
|
});
|
2019-05-10 08:45:46 +02:00
|
|
|
exports.set_enable_digest_emails_visibility();
|
2020-03-12 17:40:38 +01:00
|
|
|
rerender_ui();
|
2017-04-06 16:01:07 +02:00
|
|
|
};
|
|
|
|
|
2018-05-30 18:06:59 +02:00
|
|
|
exports.update_page = function () {
|
2020-03-28 18:03:43 +01:00
|
|
|
for (const setting of settings_config.all_notification_settings) {
|
2019-04-30 05:56:23 +02:00
|
|
|
if (setting === 'enable_offline_push_notifications'
|
|
|
|
&& !page_params.realm_push_notifications_enabled) {
|
|
|
|
// 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;
|
2019-06-29 22:00:44 +02:00
|
|
|
} else if (setting === 'desktop_icon_count_display') {
|
|
|
|
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;
|
2019-04-30 05:56:23 +02:00
|
|
|
}
|
2019-06-29 22:00:44 +02:00
|
|
|
|
2017-06-04 19:43:10 +02:00
|
|
|
$("#" + setting).prop('checked', page_params[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();
|
2017-04-06 16:01:07 +02:00
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.settings_notifications = exports;
|