2022-02-25 19:34:01 +01:00
|
|
|
import * as internal_url from "../shared/js/internal_url";
|
|
|
|
|
2022-04-27 08:56:19 +02:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:07:13 +01:00
|
|
|
import * as people from "./people";
|
|
|
|
import * as stream_data from "./stream_data";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 01:07:13 +01:00
|
|
|
export function get_hash_category(hash) {
|
2018-12-04 23:48:07 +01:00
|
|
|
// given "#streams/subscribed", returns "streams"
|
|
|
|
return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-12-04 23:48:07 +01:00
|
|
|
|
2021-02-28 01:07:13 +01:00
|
|
|
export function get_hash_section(hash) {
|
2021-06-17 18:42:31 +02:00
|
|
|
// given "#settings/profile", returns "profile"
|
2018-12-05 20:33:52 +01:00
|
|
|
// given '#streams/5/social", returns "5"
|
|
|
|
if (!hash) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return "";
|
2018-12-05 20:33:52 +01:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const parts = hash.replace(/\/$/, "").split(/\//);
|
2018-12-05 20:33:52 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
return parts[1] || "";
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-12-05 20:33:52 +01:00
|
|
|
|
2021-03-23 05:14:54 +01:00
|
|
|
export function get_current_hash_category() {
|
|
|
|
return get_hash_category(window.location.hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function get_current_hash_section() {
|
|
|
|
return get_hash_section(window.location.hash);
|
|
|
|
}
|
|
|
|
|
2021-03-04 13:36:30 +01:00
|
|
|
export function build_reload_url() {
|
|
|
|
let hash = window.location.hash;
|
|
|
|
if (hash.length !== 0 && hash[0] === "#") {
|
|
|
|
hash = hash.slice(1);
|
|
|
|
}
|
|
|
|
return "+oldhash=" + encodeURIComponent(hash);
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:07:13 +01:00
|
|
|
export function encode_operand(operator, operand) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
|
2019-11-02 00:06:25 +01:00
|
|
|
const slug = people.emails_to_slug(operand);
|
2017-03-19 00:43:14 +01:00
|
|
|
if (slug) {
|
|
|
|
return slug;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (operator === "stream") {
|
2021-02-28 01:07:13 +01:00
|
|
|
return encode_stream_name(operand);
|
2018-02-15 21:02:47 +01:00
|
|
|
}
|
|
|
|
|
2022-02-25 19:34:01 +01:00
|
|
|
return internal_url.encodeHashComponent(operand);
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-02-15 21:02:47 +01:00
|
|
|
|
2021-02-28 01:07:13 +01:00
|
|
|
export function encode_stream_name(operand) {
|
2018-02-15 21:02:47 +01:00
|
|
|
// stream_data prefixes the stream id, but it does not do the
|
|
|
|
// URI encoding piece
|
|
|
|
operand = stream_data.name_to_slug(operand);
|
|
|
|
|
2022-02-25 19:34:01 +01:00
|
|
|
return internal_url.encodeHashComponent(operand);
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2017-03-19 00:43:14 +01:00
|
|
|
|
2021-02-28 01:07:13 +01:00
|
|
|
export function decode_operand(operator, operand) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
|
2019-11-02 00:06:25 +01:00
|
|
|
const emails = people.slug_to_emails(operand);
|
2017-03-19 00:43:14 +01:00
|
|
|
if (emails) {
|
|
|
|
return emails;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 19:34:01 +01:00
|
|
|
operand = internal_url.decodeHashComponent(operand);
|
2018-02-15 21:02:47 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (operator === "stream") {
|
2018-02-15 21:02:47 +01:00
|
|
|
return stream_data.slug_to_name(operand);
|
|
|
|
}
|
|
|
|
|
|
|
|
return operand;
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2017-03-19 00:43:14 +01:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
export function by_stream_url(stream_id) {
|
|
|
|
// Wrapper for web use of internal_url.by_stream_url
|
|
|
|
return internal_url.by_stream_url(stream_id, stream_data.maybe_get_stream_name);
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-08-04 16:19:38 +02:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
export function by_stream_topic_url(stream_id, topic) {
|
|
|
|
// Wrapper for web use of internal_url.by_stream_topic_url
|
|
|
|
return internal_url.by_stream_topic_url(stream_id, topic, stream_data.maybe_get_stream_name);
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-08-04 16:19:38 +02:00
|
|
|
|
2018-08-04 16:33:28 +02:00
|
|
|
// Encodes an operator list into the
|
|
|
|
// corresponding hash: the # component
|
|
|
|
// of the narrow URL
|
2021-02-28 01:07:13 +01:00
|
|
|
export function operators_to_hash(operators) {
|
2020-07-15 01:29:15 +02:00
|
|
|
let hash = "#";
|
2018-08-04 16:33:28 +02:00
|
|
|
|
|
|
|
if (operators !== undefined) {
|
2020-07-15 01:29:15 +02:00
|
|
|
hash = "#narrow";
|
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 elem of operators) {
|
2018-08-04 16:33:28 +02:00
|
|
|
// Support legacy tuples.
|
2019-11-02 00:06:25 +01:00
|
|
|
const operator = elem.operator;
|
|
|
|
const operand = elem.operand;
|
2018-08-04 16:33:28 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const sign = elem.negated ? "-" : "";
|
2020-07-15 00:34:28 +02:00
|
|
|
hash +=
|
|
|
|
"/" +
|
|
|
|
sign +
|
2022-02-25 19:34:01 +01:00
|
|
|
internal_url.encodeHashComponent(operator) +
|
2020-07-15 00:34:28 +02:00
|
|
|
"/" +
|
2021-02-28 01:07:13 +01:00
|
|
|
encode_operand(operator, operand);
|
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
|
|
|
}
|
2018-08-04 16:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-08-04 16:33:28 +02:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
export function by_sender_url(reply_to) {
|
2021-02-28 01:07:13 +01:00
|
|
|
return operators_to_hash([{operator: "sender", operand: reply_to}]);
|
|
|
|
}
|
2018-08-04 17:19:03 +02:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
export function pm_with_url(reply_to) {
|
2020-01-12 23:18:35 +01:00
|
|
|
const slug = people.emails_to_slug(reply_to);
|
|
|
|
return "#narrow/pm-with/" + slug;
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-08-04 16:19:38 +02:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
export function huddle_with_url(user_ids_string) {
|
2018-08-04 16:52:37 +02:00
|
|
|
// This method is convenient for callers
|
|
|
|
// that have already converted emails to a comma-delimited
|
|
|
|
// list of user_ids. We should be careful to keep this
|
|
|
|
// consistent with hash_util.decode_operand.
|
2020-07-15 01:29:15 +02:00
|
|
|
return "#narrow/pm-with/" + user_ids_string + "-group";
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-08-04 16:52:37 +02:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
export function by_conversation_and_time_url(message) {
|
2020-07-15 00:34:28 +02:00
|
|
|
const absolute_url =
|
|
|
|
window.location.protocol +
|
|
|
|
"//" +
|
|
|
|
window.location.host +
|
|
|
|
"/" +
|
2020-07-15 01:29:15 +02:00
|
|
|
window.location.pathname.split("/")[1];
|
2018-10-18 22:05:43 +02:00
|
|
|
|
2022-02-25 19:34:01 +01:00
|
|
|
const suffix = "/near/" + internal_url.encodeHashComponent(message.id);
|
2018-08-05 00:40:37 +02:00
|
|
|
|
2018-08-04 17:25:50 +02:00
|
|
|
if (message.type === "stream") {
|
2022-03-01 19:14:26 +01:00
|
|
|
return absolute_url + by_stream_topic_url(message.stream_id, message.topic) + suffix;
|
2018-08-04 17:25:50 +02:00
|
|
|
}
|
|
|
|
|
2018-10-18 22:05:43 +02:00
|
|
|
return absolute_url + people.pm_perma_link(message) + suffix;
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-08-04 17:25:50 +02:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
export function stream_edit_url(sub) {
|
2022-02-25 19:34:01 +01:00
|
|
|
const hash = `#streams/${sub.stream_id}/${internal_url.encodeHashComponent(sub.name)}`;
|
2018-12-02 19:42:34 +01:00
|
|
|
return hash;
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2018-12-02 19:42:34 +01:00
|
|
|
|
2022-08-21 17:18:00 +02:00
|
|
|
export function group_edit_url(group) {
|
|
|
|
const hash = `#groups/${group.id}/${internal_url.encodeHashComponent(group.name)}`;
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2021-11-29 07:48:17 +01:00
|
|
|
export function search_public_streams_notice_url(operators) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const public_operator = {operator: "streams", operand: "public"};
|
2021-02-28 01:07:13 +01:00
|
|
|
return operators_to_hash([public_operator].concat(operators));
|
|
|
|
}
|
2020-06-20 05:48:18 +02:00
|
|
|
|
2021-02-28 01:07:13 +01:00
|
|
|
export function parse_narrow(hash) {
|
2022-02-25 19:27:25 +01:00
|
|
|
// This will throw an exception when passed an invalid hash
|
|
|
|
// at the decodeHashComponent call, handle appropriately.
|
2019-11-02 00:06:25 +01:00
|
|
|
let i;
|
|
|
|
const operators = [];
|
2018-12-04 23:24:03 +01:00
|
|
|
for (i = 1; i < hash.length; i += 2) {
|
|
|
|
// We don't construct URLs with an odd number of components,
|
|
|
|
// but the user might write one.
|
2022-02-25 19:34:01 +01:00
|
|
|
let operator = internal_url.decodeHashComponent(hash[i]);
|
2018-12-04 23:29:43 +01:00
|
|
|
// Do not parse further if empty operator encountered.
|
2020-07-15 01:29:15 +02:00
|
|
|
if (operator === "") {
|
2018-12-04 23:29:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const raw_operand = hash[i + 1];
|
2018-12-04 23:29:43 +01:00
|
|
|
|
|
|
|
if (!raw_operand) {
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-12-04 23:24:03 +01:00
|
|
|
}
|
2018-12-04 23:29:43 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let negated = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
if (operator[0] === "-") {
|
2018-12-04 23:29:43 +01:00
|
|
|
negated = true;
|
|
|
|
operator = operator.slice(1);
|
|
|
|
}
|
2020-03-20 19:56:01 +01:00
|
|
|
|
2021-02-28 01:07:13 +01:00
|
|
|
const operand = decode_operand(operator, raw_operand);
|
2020-07-20 22:18:43 +02:00
|
|
|
operators.push({negated, operator, operand});
|
2018-12-04 23:24:03 +01:00
|
|
|
}
|
|
|
|
return operators;
|
2021-02-28 01:07:13 +01:00
|
|
|
}
|
2021-03-22 16:09:12 +01:00
|
|
|
|
|
|
|
export function is_overlay_hash(hash) {
|
|
|
|
// Hash changes within this list are overlays and should not unnarrow (etc.)
|
|
|
|
const overlay_list = [
|
|
|
|
"streams",
|
|
|
|
"drafts",
|
2022-08-21 16:34:56 +02:00
|
|
|
"groups",
|
2021-03-22 16:09:12 +01:00
|
|
|
"settings",
|
|
|
|
"organization",
|
|
|
|
"invite",
|
|
|
|
"keyboard-shortcuts",
|
|
|
|
"message-formatting",
|
|
|
|
"search-operators",
|
2021-02-09 11:16:52 +01:00
|
|
|
"about-zulip",
|
2021-03-22 16:09:12 +01:00
|
|
|
];
|
|
|
|
const main_hash = get_hash_category(hash);
|
|
|
|
|
|
|
|
return overlay_list.includes(main_hash);
|
|
|
|
}
|
2021-03-15 06:57:14 +01:00
|
|
|
|
|
|
|
// this finds the stream that is actively open in the settings and focused in
|
|
|
|
// the left side.
|
2021-12-20 20:40:42 +01:00
|
|
|
export function is_editing_stream(desired_stream_id) {
|
2021-03-15 06:57:14 +01:00
|
|
|
const hash_components = window.location.hash.slice(1).split(/\//);
|
|
|
|
|
2021-12-20 20:40:42 +01:00
|
|
|
if (hash_components[0] !== "streams") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hash_components[2]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-15 06:57:14 +01:00
|
|
|
// if the string casted to a number is valid, and another component
|
|
|
|
// after exists then it's a stream name/id pair.
|
2021-12-20 20:40:42 +01:00
|
|
|
const stream_id = Number.parseFloat(hash_components[1]);
|
2021-03-15 06:57:14 +01:00
|
|
|
|
2021-12-20 20:40:42 +01:00
|
|
|
return stream_id === desired_stream_id;
|
2021-03-15 06:57:14 +01:00
|
|
|
}
|
2021-03-15 09:24:10 +01:00
|
|
|
|
|
|
|
export function is_create_new_stream_narrow() {
|
|
|
|
return window.location.hash === "#streams/new";
|
|
|
|
}
|
2021-05-19 05:34:35 +02:00
|
|
|
|
|
|
|
export const allowed_web_public_narrows = [
|
|
|
|
"streams",
|
|
|
|
"stream",
|
|
|
|
"topic",
|
|
|
|
"sender",
|
|
|
|
"has",
|
|
|
|
"search",
|
|
|
|
"near",
|
|
|
|
"id",
|
|
|
|
];
|
|
|
|
|
2021-09-04 04:03:07 +02:00
|
|
|
export function is_spectator_compatible(hash) {
|
2020-10-05 10:50:51 +02:00
|
|
|
// Defines which views are supported for spectators.
|
|
|
|
// This implementation should agree with the similar function in zerver/lib/narrow.py.
|
2021-05-19 05:34:35 +02:00
|
|
|
const web_public_allowed_hashes = [
|
|
|
|
"",
|
2021-09-04 04:03:07 +02:00
|
|
|
"narrow", // full #narrow hash handled in narrow.is_spectator_compatible
|
2021-05-19 05:34:35 +02:00
|
|
|
"recent_topics",
|
|
|
|
"keyboard-shortcuts",
|
|
|
|
"message-formatting",
|
|
|
|
"search-operators",
|
|
|
|
"all_messages",
|
|
|
|
"about-zulip",
|
|
|
|
];
|
|
|
|
|
|
|
|
const main_hash = get_hash_category(hash);
|
|
|
|
|
|
|
|
if (main_hash === "narrow") {
|
|
|
|
const hash_section = get_hash_section(hash);
|
|
|
|
if (!allowed_web_public_narrows.includes(hash_section)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return web_public_allowed_hashes.includes(main_hash);
|
|
|
|
}
|
2021-06-23 15:21:25 +02:00
|
|
|
|
|
|
|
export function current_hash_as_next() {
|
2021-11-27 09:46:26 +01:00
|
|
|
return `next=/${encodeURIComponent(window.location.hash)}`;
|
2021-06-23 15:21:25 +02:00
|
|
|
}
|
2022-04-27 08:56:19 +02:00
|
|
|
|
|
|
|
export function build_login_link() {
|
|
|
|
let login_link = "/login/?" + current_hash_as_next();
|
|
|
|
if (page_params.development_environment) {
|
|
|
|
login_link = "/devlogin/?" + current_hash_as_next();
|
|
|
|
}
|
|
|
|
return login_link;
|
|
|
|
}
|