2017-12-16 22:02:58 +01:00
|
|
|
exports.mark_all_as_read = function (cont) {
|
2017-03-18 01:41:56 +01:00
|
|
|
unread.declare_bankruptcy();
|
|
|
|
unread_ui.update_unread_counts();
|
|
|
|
|
|
|
|
channel.post({
|
2018-12-18 19:34:45 +01:00
|
|
|
url: '/json/mark_all_as_read',
|
2017-03-18 01:41:56 +01:00
|
|
|
idempotent: true,
|
2018-12-18 19:34:45 +01:00
|
|
|
success: cont});
|
2017-03-18 01:41:56 +01:00
|
|
|
};
|
|
|
|
|
2017-08-03 00:14:36 +02:00
|
|
|
function process_newly_read_message(message, options) {
|
|
|
|
home_msg_list.show_message_as_read(message, options);
|
|
|
|
message_list.all.show_message_as_read(message, options);
|
|
|
|
if (message_list.narrowed) {
|
|
|
|
message_list.narrowed.show_message_as_read(message, options);
|
|
|
|
}
|
|
|
|
notifications.close_notification(message);
|
2020-05-22 17:11:19 +02:00
|
|
|
recent_topics.update_topic_unread_count(message);
|
2017-08-03 00:14:36 +02:00
|
|
|
}
|
|
|
|
|
2017-08-03 00:28:16 +02:00
|
|
|
exports.process_read_messages_event = function (message_ids) {
|
|
|
|
/*
|
2018-04-04 21:32:45 +02:00
|
|
|
This code has a lot in common with notify_server_messages_read,
|
2017-08-03 00:28:16 +02:00
|
|
|
but there are subtle differences due to the fact that the
|
|
|
|
server can tell us about unread messages that we didn't
|
|
|
|
actually read locally (and which we may not have even
|
|
|
|
loaded locally).
|
|
|
|
*/
|
2019-11-02 00:06:25 +01:00
|
|
|
const options = {from: 'server'};
|
2017-08-03 00:28:16 +02:00
|
|
|
|
2017-12-16 16:53:27 +01:00
|
|
|
message_ids = unread.get_unread_message_ids(message_ids);
|
|
|
|
if (message_ids.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-03 00:28:16 +02:00
|
|
|
|
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
|
|
|
for (const message_id of message_ids) {
|
2017-08-03 00:28:16 +02:00
|
|
|
if (current_msg_list === message_list.narrowed) {
|
|
|
|
// I'm not sure this entirely makes sense for all server
|
|
|
|
// notifications.
|
2018-08-04 08:42:57 +02:00
|
|
|
unread.set_messages_read_in_narrow(true);
|
2017-08-03 00:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unread.mark_as_read(message_id);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = message_store.get(message_id);
|
2017-08-03 00:28:16 +02:00
|
|
|
|
|
|
|
if (message) {
|
|
|
|
process_newly_read_message(message, options);
|
|
|
|
}
|
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
|
|
|
}
|
2017-08-03 00:28:16 +02:00
|
|
|
|
2017-12-16 16:53:27 +01:00
|
|
|
unread_ui.update_unread_counts();
|
2017-08-03 00:28:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-16 20:44:12 +01:00
|
|
|
// Takes a list of messages and marks them as read.
|
|
|
|
// Skips any messages that are already marked as read.
|
2018-04-04 21:32:45 +02:00
|
|
|
exports.notify_server_messages_read = function (messages, options) {
|
2017-03-18 01:41:56 +01:00
|
|
|
options = options || {};
|
2017-12-16 16:53:27 +01:00
|
|
|
messages = unread.get_unread_messages(messages);
|
|
|
|
if (messages.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-18 01:41:56 +01:00
|
|
|
|
2017-12-21 17:51:52 +01:00
|
|
|
message_flags.send_read(messages);
|
|
|
|
|
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
|
|
|
for (const message of messages) {
|
2017-03-18 01:41:56 +01:00
|
|
|
if (current_msg_list === message_list.narrowed) {
|
2018-08-04 08:42:57 +02:00
|
|
|
unread.set_messages_read_in_narrow(true);
|
2017-03-18 01:41:56 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 21:40:01 +02:00
|
|
|
unread.mark_as_read(message.id);
|
2017-08-03 00:14:36 +02:00
|
|
|
process_newly_read_message(message, options);
|
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
|
|
|
}
|
2017-03-18 01:41:56 +01:00
|
|
|
|
2017-12-16 16:53:27 +01:00
|
|
|
unread_ui.update_unread_counts();
|
2017-03-18 01:41:56 +01:00
|
|
|
};
|
|
|
|
|
2018-04-04 21:32:45 +02:00
|
|
|
exports.notify_server_message_read = function (message, options) {
|
|
|
|
exports.notify_server_messages_read([message], options);
|
2017-03-18 01:41:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// If we ever materially change the algorithm for this function, we
|
|
|
|
// may need to update notifications.received_messages as well.
|
2017-12-16 22:02:58 +01:00
|
|
|
exports.process_visible = function () {
|
2020-06-17 15:38:32 +02:00
|
|
|
if (overlays.is_active() || !notifications.window_has_focus()) {
|
2017-03-18 01:41:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-10 02:03:41 +02:00
|
|
|
if (message_viewport.bottom_message_visible() &&
|
|
|
|
current_msg_list.can_mark_messages_read()) {
|
2018-07-06 15:46:06 +02:00
|
|
|
exports.mark_current_list_as_read();
|
2017-03-18 01:41:56 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-16 22:02:58 +01:00
|
|
|
exports.mark_current_list_as_read = function (options) {
|
2018-04-04 21:32:45 +02:00
|
|
|
exports.notify_server_messages_read(current_msg_list.all_messages(), options);
|
2017-03-18 01:41:56 +01:00
|
|
|
};
|
|
|
|
|
2017-12-16 22:02:58 +01:00
|
|
|
exports.mark_stream_as_read = function (stream_id, cont) {
|
2017-03-18 01:41:56 +01:00
|
|
|
channel.post({
|
2018-05-06 21:43:17 +02:00
|
|
|
url: '/json/mark_stream_as_read',
|
2017-03-18 01:41:56 +01:00
|
|
|
idempotent: true,
|
2018-05-06 21:43:17 +02:00
|
|
|
data: {stream_id: stream_id},
|
|
|
|
success: cont,
|
|
|
|
});
|
2017-03-18 01:41:56 +01:00
|
|
|
};
|
|
|
|
|
2017-12-16 22:02:58 +01:00
|
|
|
exports.mark_topic_as_read = function (stream_id, topic, cont) {
|
2017-03-18 01:41:56 +01:00
|
|
|
channel.post({
|
2018-05-06 21:43:17 +02:00
|
|
|
url: '/json/mark_topic_as_read',
|
|
|
|
idempotent: true,
|
|
|
|
data: {stream_id: stream_id, topic_name: topic},
|
|
|
|
success: cont,
|
|
|
|
});
|
2017-03-18 01:41:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.unread_ops = exports;
|