2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2021-02-28 21:31:02 +01:00
|
|
|
import _ from "lodash";
|
|
|
|
|
2022-11-02 17:38:38 +01:00
|
|
|
import render_filter_topics from "../templates/filter_topics.hbs";
|
2021-02-28 21:31:02 +01:00
|
|
|
import render_stream_privacy from "../templates/stream_privacy.hbs";
|
|
|
|
import render_stream_sidebar_row from "../templates/stream_sidebar_row.hbs";
|
2022-02-20 21:32:14 +01:00
|
|
|
import render_stream_subheader from "../templates/streams_subheader.hbs";
|
2022-08-15 21:32:10 +02:00
|
|
|
import render_subscribe_to_more_streams from "../templates/subscribe_to_more_streams.hbs";
|
2021-02-28 21:31:02 +01:00
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-03-24 17:54:23 +01:00
|
|
|
import * as color_class from "./color_class";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as hash_util from "./hash_util";
|
2022-02-20 21:32:14 +01:00
|
|
|
import {$t} from "./i18n";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as keydown_util from "./keydown_util";
|
|
|
|
import {ListCursor} from "./list_cursor";
|
2021-02-28 21:31:57 +01:00
|
|
|
import * as narrow from "./narrow";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as narrow_state from "./narrow_state";
|
2022-09-13 13:15:57 +02:00
|
|
|
import * as pm_list from "./pm_list";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as popovers from "./popovers";
|
|
|
|
import * as resize from "./resize";
|
|
|
|
import * as scroll_util from "./scroll_util";
|
2022-08-15 21:32:10 +02:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as stream_data from "./stream_data";
|
|
|
|
import * as stream_popover from "./stream_popover";
|
|
|
|
import * as stream_sort from "./stream_sort";
|
2021-04-15 17:02:54 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as topic_list from "./topic_list";
|
|
|
|
import * as topic_zoom from "./topic_zoom";
|
2021-02-28 21:33:10 +01:00
|
|
|
import * as ui from "./ui";
|
2021-04-09 16:40:09 +02:00
|
|
|
import * as ui_util from "./ui_util";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as unread from "./unread";
|
|
|
|
|
|
|
|
export let stream_cursor;
|
2021-02-10 16:50:12 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let has_scrolled = false;
|
2018-07-06 20:23:20 +02:00
|
|
|
|
2022-08-05 22:45:20 +02:00
|
|
|
export function update_count_in_dom($stream_li, count, stream_has_any_unread_mention_messages) {
|
2022-02-08 00:13:33 +01:00
|
|
|
// The subscription_block properly excludes the topic list,
|
2021-04-14 23:46:28 +02:00
|
|
|
// and it also has sensitive margins related to whether the
|
|
|
|
// count is there or not.
|
2022-01-25 11:36:19 +01:00
|
|
|
const $subscription_block = $stream_li.find(".subscription_block");
|
2017-01-15 17:02:29 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
ui_util.update_unread_count_in_dom($subscription_block, count);
|
2022-08-05 22:45:20 +02:00
|
|
|
ui_util.update_unread_mention_info_in_dom(
|
|
|
|
$subscription_block,
|
|
|
|
stream_has_any_unread_mention_messages,
|
|
|
|
);
|
2017-01-15 17:02:29 +01:00
|
|
|
|
2021-04-14 23:46:28 +02:00
|
|
|
if (count === 0) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$subscription_block.removeClass("stream-with-count");
|
2021-04-14 23:46:28 +02:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
$subscription_block.addClass("stream-with-count");
|
2017-01-15 17:02:29 +01:00
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-06-14 00:03:00 +02:00
|
|
|
|
2020-07-23 02:44:02 +02:00
|
|
|
class StreamSidebar {
|
|
|
|
rows = new Map(); // stream id -> row widget
|
2016-11-11 14:20:19 +01:00
|
|
|
|
2020-07-23 02:44:02 +02:00
|
|
|
set_row(stream_id, widget) {
|
|
|
|
this.rows.set(stream_id, widget);
|
|
|
|
}
|
2016-11-11 14:20:19 +01:00
|
|
|
|
2020-07-23 02:44:02 +02:00
|
|
|
get_row(stream_id) {
|
|
|
|
return this.rows.get(stream_id);
|
|
|
|
}
|
2016-11-11 14:20:19 +01:00
|
|
|
|
2020-07-23 02:44:02 +02:00
|
|
|
has_row_for(stream_id) {
|
|
|
|
return this.rows.has(stream_id);
|
|
|
|
}
|
2016-11-11 14:20:19 +01:00
|
|
|
|
2020-07-23 02:44:02 +02:00
|
|
|
remove_row(stream_id) {
|
2017-04-18 19:59:35 +02:00
|
|
|
// This only removes the row from our data structure.
|
|
|
|
// Our caller should use build_stream_list() to re-draw
|
|
|
|
// the sidebar, so that we don't have to deal with edge
|
|
|
|
// cases like removing the last pinned stream (and removing
|
|
|
|
// the divider).
|
2017-04-10 22:09:54 +02:00
|
|
|
|
2020-07-23 02:44:02 +02:00
|
|
|
this.rows.delete(stream_id);
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
export const stream_sidebar = new StreamSidebar();
|
2016-11-11 14:20:19 +01:00
|
|
|
|
2017-04-18 17:08:59 +02:00
|
|
|
function get_search_term() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $search_box = $(".stream-list-filter");
|
|
|
|
const search_term = $search_box.expectOne().val().trim();
|
2017-04-18 17:08:59 +02:00
|
|
|
return search_term;
|
|
|
|
}
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function add_sidebar_row(sub) {
|
|
|
|
create_sidebar_row(sub);
|
|
|
|
build_stream_list();
|
|
|
|
stream_cursor.redraw();
|
|
|
|
}
|
2020-06-18 13:53:44 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function remove_sidebar_row(stream_id) {
|
|
|
|
stream_sidebar.remove_row(stream_id);
|
|
|
|
build_stream_list();
|
|
|
|
stream_cursor.redraw();
|
|
|
|
}
|
2017-02-17 18:45:14 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function create_initial_sidebar_rows() {
|
Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.
Now there is a clear separation of concerns, with these methods
being called in succession:
stream_data.initialize_from_page_params();
stream_list.create_initial_sidebar_rows();
The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict. Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.
Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
2016-10-17 19:34:58 +02:00
|
|
|
// This code is slightly opaque, but it ends up building
|
|
|
|
// up list items and attaching them to the "sub" data
|
|
|
|
// structures that are kept in stream_data.js.
|
2019-11-02 00:06:25 +01:00
|
|
|
const subs = stream_data.subscribed_subs();
|
Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.
Now there is a clear separation of concerns, with these methods
being called in succession:
stream_data.initialize_from_page_params();
stream_list.create_initial_sidebar_rows();
The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict. Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.
Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
2016-10-17 19:34:58 +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 sub of subs) {
|
2021-02-28 21:31:02 +01:00
|
|
|
create_sidebar_row(sub);
|
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
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.
Now there is a clear separation of concerns, with these methods
being called in succession:
stream_data.initialize_from_page_params();
stream_list.create_initial_sidebar_rows();
The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict. Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.
Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
2016-10-17 19:34:58 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function build_stream_list(force_rerender) {
|
2022-02-20 21:32:14 +01:00
|
|
|
// The stream list in the left sidebar contains 3 sections:
|
|
|
|
// pinned, normal, and dormant streams, with headings above them
|
|
|
|
// as appropriate.
|
|
|
|
//
|
|
|
|
// Within the first two sections, muted streams are sorted to the
|
|
|
|
// bottom; we skip that for dormant streams to simplify discovery.
|
2020-07-09 15:08:01 +02:00
|
|
|
const streams = stream_data.subscribed_stream_ids();
|
2022-01-25 11:36:19 +01:00
|
|
|
const $parent = $("#stream_filters");
|
2013-05-06 23:36:22 +02:00
|
|
|
if (streams.length === 0) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$parent.empty();
|
2013-05-06 23:36:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-18 17:08:59 +02:00
|
|
|
// The main logic to build the list is in stream_sort.js, and
|
2022-02-20 21:32:14 +01:00
|
|
|
// we get five lists of streams (pinned/normal/muted_pinned/muted_normal/dormant).
|
2019-12-27 21:45:28 +01:00
|
|
|
const stream_groups = stream_sort.sort_groups(streams, get_search_term());
|
2017-04-18 17:08:59 +02:00
|
|
|
|
2020-08-13 14:36:41 +02:00
|
|
|
if (stream_groups.same_as_before && !force_rerender) {
|
2017-04-18 17:08:59 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const elems = [];
|
2013-05-06 23:36:22 +02:00
|
|
|
|
2020-07-09 15:08:01 +02:00
|
|
|
function add_sidebar_li(stream_id) {
|
2021-02-28 21:31:02 +01:00
|
|
|
const sidebar_row = stream_sidebar.get_row(stream_id);
|
2017-04-18 19:59:35 +02:00
|
|
|
sidebar_row.update_whether_active();
|
2017-07-18 13:30:14 +02:00
|
|
|
elems.push(sidebar_row.get_li());
|
2016-07-01 07:26:09 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 19:16:01 +02:00
|
|
|
topic_list.clear();
|
2022-01-25 11:36:19 +01:00
|
|
|
$parent.empty();
|
2016-07-01 07:26:09 +02:00
|
|
|
|
2022-11-23 15:03:42 +01:00
|
|
|
const any_pinned_streams =
|
|
|
|
stream_groups.pinned_streams.length > 0 || stream_groups.muted_pinned_streams.length > 0;
|
|
|
|
const any_normal_streams =
|
|
|
|
stream_groups.normal_streams.length > 0 || stream_groups.muted_active_streams.length > 0;
|
2022-02-20 21:32:14 +01:00
|
|
|
const any_dormant_streams = stream_groups.dormant_streams.length > 0;
|
2022-11-23 15:03:42 +01:00
|
|
|
|
2022-09-04 18:37:13 +02:00
|
|
|
const need_section_subheaders =
|
|
|
|
(any_pinned_streams ? 1 : 0) +
|
|
|
|
(any_normal_streams ? 1 : 0) +
|
|
|
|
(any_dormant_streams ? 1 : 0) >=
|
|
|
|
2;
|
2022-02-20 21:32:14 +01:00
|
|
|
|
2022-09-04 18:37:13 +02:00
|
|
|
if (any_pinned_streams && need_section_subheaders) {
|
2022-02-20 21:32:14 +01:00
|
|
|
elems.push(
|
|
|
|
render_stream_subheader({
|
|
|
|
subheader_name: $t({
|
|
|
|
defaultMessage: "Pinned",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const stream_id of stream_groups.pinned_streams) {
|
|
|
|
add_sidebar_li(stream_id);
|
|
|
|
}
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
for (const stream_id of stream_groups.muted_pinned_streams) {
|
|
|
|
add_sidebar_li(stream_id);
|
|
|
|
}
|
2017-11-13 17:17:34 +01:00
|
|
|
|
2022-09-04 18:37:13 +02:00
|
|
|
if (any_normal_streams && need_section_subheaders) {
|
2022-02-20 21:32:14 +01:00
|
|
|
elems.push(
|
|
|
|
render_stream_subheader({
|
|
|
|
subheader_name: $t({
|
|
|
|
defaultMessage: "Active",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2017-04-18 17:08:59 +02:00
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const stream_id of stream_groups.normal_streams) {
|
|
|
|
add_sidebar_li(stream_id);
|
|
|
|
}
|
2016-07-01 07:26:09 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
for (const stream_id of stream_groups.muted_active_streams) {
|
|
|
|
add_sidebar_li(stream_id);
|
|
|
|
}
|
|
|
|
|
2022-09-04 18:37:13 +02:00
|
|
|
if (any_dormant_streams && need_section_subheaders) {
|
2022-02-20 21:32:14 +01:00
|
|
|
elems.push(
|
|
|
|
render_stream_subheader({
|
|
|
|
subheader_name: $t({
|
|
|
|
defaultMessage: "Inactive",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2017-04-19 18:18:29 +02:00
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const stream_id of stream_groups.dormant_streams) {
|
|
|
|
add_sidebar_li(stream_id);
|
|
|
|
}
|
2016-07-01 07:26:09 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$parent.append(elems);
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function get_stream_li(stream_id) {
|
|
|
|
const row = stream_sidebar.get_row(stream_id);
|
2017-06-03 00:13:57 +02:00
|
|
|
if (!row) {
|
2017-06-03 14:16:45 +02:00
|
|
|
// Not all streams are in the sidebar, so we don't report
|
|
|
|
// an error here, and it's up for the caller to error if
|
|
|
|
// they expected otherwise.
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-06-03 00:13:57 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $li = row.get_li();
|
|
|
|
if (!$li) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Cannot find li for id " + stream_id);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-06-03 00:13:57 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($li.length > 1) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("stream_li has too many elements for " + stream_id);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-06-03 00:13:57 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
return $li;
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-05-13 16:56:29 +02:00
|
|
|
|
2022-08-15 21:32:10 +02:00
|
|
|
export function update_subscribe_to_more_streams_link() {
|
|
|
|
const can_subscribe_stream_count = stream_data
|
|
|
|
.unsubscribed_subs()
|
|
|
|
.filter((sub) => stream_data.can_toggle_subscription(sub)).length;
|
|
|
|
|
|
|
|
const can_create_streams =
|
|
|
|
settings_data.user_can_create_private_streams() ||
|
|
|
|
settings_data.user_can_create_public_streams() ||
|
|
|
|
settings_data.user_can_create_web_public_streams();
|
|
|
|
|
|
|
|
$("#subscribe-to-more-streams").html(
|
|
|
|
render_subscribe_to_more_streams({
|
|
|
|
can_subscribe_stream_count,
|
|
|
|
can_create_streams,
|
2022-09-16 01:22:39 +02:00
|
|
|
exactly_one_unsubscribed_stream: can_subscribe_stream_count === 1,
|
2022-08-15 21:32:10 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function stream_id_for_elt($elt) {
|
|
|
|
return Number.parseInt($elt.attr("data-stream-id"), 10);
|
2019-12-30 12:51:16 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function zoom_in_topics(options) {
|
2018-09-10 14:52:58 +02:00
|
|
|
// This only does stream-related tasks related to zooming
|
|
|
|
// in to more topics, which is basically hiding all the
|
|
|
|
// other streams.
|
|
|
|
|
2015-12-11 08:24:00 +01:00
|
|
|
$("#streams_list").expectOne().removeClass("zoom-out").addClass("zoom-in");
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
// Hide stream list titles and pinned stream splitter
|
|
|
|
$(".stream-filters-label").each(function () {
|
|
|
|
$(this).hide();
|
|
|
|
});
|
2022-02-20 21:32:14 +01:00
|
|
|
$(".streams_subheader").each(function () {
|
2016-07-01 07:26:09 +02:00
|
|
|
$(this).hide();
|
|
|
|
});
|
|
|
|
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
$("#stream_filters li.narrow-filter").each(function () {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elt = $(this);
|
2019-12-30 12:51:16 +01:00
|
|
|
const stream_id = options.stream_id;
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if (stream_id_for_elt($elt) === stream_id) {
|
|
|
|
$elt.show();
|
2022-11-02 17:38:38 +01:00
|
|
|
// Add search box for topics list.
|
|
|
|
$elt.children("div.bottom_left_row").append(render_filter_topics());
|
|
|
|
$("#filter-topic-input").trigger("focus");
|
|
|
|
$("#clear_search_topic_button").hide();
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
$elt.hide();
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
}
|
|
|
|
});
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-08-10 12:04:01 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function zoom_out_topics() {
|
2016-07-01 07:26:09 +02:00
|
|
|
// Show stream list titles and pinned stream splitter
|
|
|
|
$(".stream-filters-label").each(function () {
|
|
|
|
$(this).show();
|
|
|
|
});
|
2022-02-20 21:32:14 +01:00
|
|
|
$(".streams_subheader").each(function () {
|
2016-07-01 07:26:09 +02:00
|
|
|
$(this).show();
|
|
|
|
});
|
|
|
|
|
2015-12-11 08:24:00 +01:00
|
|
|
$("#streams_list").expectOne().removeClass("zoom-in").addClass("zoom-out");
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
$("#stream_filters li.narrow-filter").show();
|
2022-11-02 17:38:38 +01:00
|
|
|
// Remove search box for topics list from DOM.
|
|
|
|
$(".filter-topics").remove();
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function set_in_home_view(stream_id, in_home) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $li = get_stream_li(stream_id);
|
|
|
|
if (!$li) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("passed in bad stream id " + stream_id);
|
2017-06-03 00:13:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-12 00:07:35 +02:00
|
|
|
if (in_home) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$li.removeClass("out_of_home_view");
|
2013-06-12 00:07:35 +02:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
$li.addClass("out_of_home_view");
|
2013-06-12 00:07:35 +02:00
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2013-06-12 00:07:35 +02:00
|
|
|
|
2016-11-11 02:39:22 +01:00
|
|
|
function build_stream_sidebar_li(sub) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const name = sub.name;
|
|
|
|
const args = {
|
2020-07-20 22:18:43 +02:00
|
|
|
name,
|
2018-05-06 21:43:17 +02:00
|
|
|
id: sub.stream_id,
|
2022-03-01 19:14:26 +01:00
|
|
|
uri: hash_util.by_stream_url(sub.stream_id),
|
2019-05-21 09:33:21 +02:00
|
|
|
is_muted: stream_data.is_muted(sub.stream_id) === true,
|
2018-05-06 21:43:17 +02:00
|
|
|
invite_only: sub.invite_only,
|
2019-04-07 20:29:25 +02:00
|
|
|
is_web_public: sub.is_web_public,
|
2019-12-27 21:52:21 +01:00
|
|
|
color: sub.color,
|
2018-05-06 21:43:17 +02:00
|
|
|
pin_to_top: sub.pin_to_top,
|
|
|
|
};
|
2021-03-24 17:54:23 +01:00
|
|
|
args.dark_background = color_class.get_css_class(args.color);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $list_item = $(render_stream_sidebar_row(args));
|
|
|
|
return $list_item;
|
2013-05-06 22:18:01 +02:00
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2020-07-23 02:47:43 +02:00
|
|
|
class StreamSidebarRow {
|
|
|
|
constructor(sub) {
|
|
|
|
this.sub = sub;
|
2022-01-25 11:36:19 +01:00
|
|
|
this.$list_item = build_stream_sidebar_li(sub);
|
2020-07-23 02:47:43 +02:00
|
|
|
this.update_unread_count();
|
|
|
|
}
|
2016-11-11 02:39:22 +01:00
|
|
|
|
2020-07-23 02:47:43 +02:00
|
|
|
update_whether_active() {
|
|
|
|
if (stream_data.is_active(this.sub) || this.sub.pin_to_top === true) {
|
2022-01-25 11:36:19 +01:00
|
|
|
this.$list_item.removeClass("inactive_stream");
|
2016-11-11 02:39:22 +01:00
|
|
|
} else {
|
2022-01-25 11:36:19 +01:00
|
|
|
this.$list_item.addClass("inactive_stream");
|
2016-11-11 02:39:22 +01:00
|
|
|
}
|
2020-07-23 02:47:43 +02:00
|
|
|
}
|
2016-11-11 02:39:22 +01:00
|
|
|
|
2020-07-23 02:47:43 +02:00
|
|
|
get_li() {
|
2022-01-25 11:36:19 +01:00
|
|
|
return this.$list_item;
|
2020-07-23 02:47:43 +02:00
|
|
|
}
|
2016-11-11 15:09:08 +01:00
|
|
|
|
2020-07-23 02:47:43 +02:00
|
|
|
remove() {
|
2022-01-25 11:36:19 +01:00
|
|
|
this.$list_item.remove();
|
2020-07-23 02:47:43 +02:00
|
|
|
}
|
2017-01-15 17:09:16 +01:00
|
|
|
|
2020-07-23 02:47:43 +02:00
|
|
|
update_unread_count() {
|
|
|
|
const count = unread.num_unread_for_stream(this.sub.stream_id);
|
2022-08-05 22:45:20 +02:00
|
|
|
const stream_has_any_unread_mention_messages = unread.stream_has_any_unread_mentions(
|
|
|
|
this.sub.stream_id,
|
|
|
|
);
|
|
|
|
update_count_in_dom(this.$list_item, count, stream_has_any_unread_mention_messages);
|
2020-07-23 02:47:43 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-15 17:09:16 +01:00
|
|
|
|
2020-07-23 02:47:43 +02:00
|
|
|
function build_stream_sidebar_row(sub) {
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_sidebar.set_row(sub.stream_id, new StreamSidebarRow(sub));
|
2016-11-11 02:39:22 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function create_sidebar_row(sub) {
|
|
|
|
if (stream_sidebar.has_row_for(sub.stream_id)) {
|
2013-10-21 22:26:19 +02:00
|
|
|
// already exists
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.warn("Dup try to build sidebar row for stream " + sub.stream_id);
|
2016-10-17 20:02:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-11-11 02:39:22 +01:00
|
|
|
build_stream_sidebar_row(sub);
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2014-01-16 21:38:40 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function redraw_stream_privacy(sub) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $li = get_stream_li(sub.stream_id);
|
|
|
|
if (!$li) {
|
2018-01-06 12:25:03 +01:00
|
|
|
// We don't want to raise error here, if we can't find stream in subscription
|
|
|
|
// stream list. Cause we allow org admin to update stream privacy
|
|
|
|
// even if they don't subscribe to public stream.
|
2017-06-03 00:13:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $div = $li.find(".stream-privacy");
|
2021-03-24 17:54:23 +01:00
|
|
|
const dark_background = color_class.get_css_class(sub.color);
|
2014-01-17 18:23:39 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const args = {
|
2014-01-17 18:23:39 +01:00
|
|
|
invite_only: sub.invite_only,
|
2020-11-10 15:57:14 +01:00
|
|
|
is_web_public: sub.is_web_public,
|
2020-07-20 22:18:43 +02:00
|
|
|
dark_background,
|
2014-01-17 18:23:39 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const html = render_stream_privacy(args);
|
2022-01-25 11:36:19 +01:00
|
|
|
$div.html(html);
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2014-01-17 18:23:39 +01:00
|
|
|
|
2022-08-05 22:45:20 +02:00
|
|
|
function set_stream_unread_count(stream_id, count, stream_has_any_unread_mention_messages) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = get_stream_li(stream_id);
|
|
|
|
if (!$stream_li) {
|
2017-06-03 14:16:45 +02:00
|
|
|
// This can happen for legitimate reasons, but we warn
|
|
|
|
// just in case.
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.warn("stream id no longer in sidebar: " + stream_id);
|
2017-06-03 00:13:57 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-08-05 22:45:20 +02:00
|
|
|
update_count_in_dom($stream_li, count, stream_has_any_unread_mention_messages);
|
2017-05-13 16:47:45 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function update_streams_sidebar(force_rerender) {
|
|
|
|
build_stream_list(force_rerender);
|
2021-01-31 13:57:52 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor.redraw();
|
2018-02-12 22:56:37 +01:00
|
|
|
|
2018-06-04 21:09:11 +02:00
|
|
|
if (!narrow_state.active()) {
|
2013-05-06 02:54:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const filter = narrow_state.filter();
|
2017-05-14 20:58:11 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
update_stream_sidebar_for_narrow(filter);
|
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function update_dom_with_unread_counts(counts) {
|
2013-05-14 03:58:07 +02:00
|
|
|
// counts.stream_count maps streams to counts
|
2020-02-03 09:26:53 +01:00
|
|
|
for (const [stream_id, count] of counts.stream_count) {
|
2022-08-05 22:45:20 +02:00
|
|
|
const stream_has_any_unread_mention_messages =
|
|
|
|
counts.streams_with_mentions.includes(stream_id);
|
|
|
|
set_stream_unread_count(stream_id, count, stream_has_any_unread_mention_messages);
|
2020-02-03 09:26:53 +01:00
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2013-05-14 03:58:07 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function rename_stream(sub) {
|
2016-12-02 14:06:06 +01:00
|
|
|
// The sub object is expected to already have the updated name
|
2016-11-11 02:39:22 +01:00
|
|
|
build_stream_sidebar_row(sub);
|
2021-02-28 21:31:02 +01:00
|
|
|
update_streams_sidebar(true); // big hammer
|
|
|
|
}
|
2013-10-21 22:26:19 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function refresh_pinned_or_unpinned_stream(sub) {
|
2016-10-26 06:56:10 +02:00
|
|
|
// Pinned/unpinned streams require re-ordering.
|
|
|
|
// We use kind of brute force now, which is probably fine.
|
2016-11-11 02:39:22 +01:00
|
|
|
build_stream_sidebar_row(sub);
|
2021-02-28 21:31:02 +01:00
|
|
|
update_streams_sidebar();
|
2017-05-02 01:22:18 +02:00
|
|
|
|
|
|
|
// Only scroll pinned topics into view. If we're unpinning
|
|
|
|
// a topic, we may be literally trying to get it out of
|
|
|
|
// our sight.
|
|
|
|
if (sub.pin_to_top) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = get_stream_li(sub.stream_id);
|
|
|
|
if (!$stream_li) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("passed in bad stream id " + sub.stream_id);
|
2017-06-03 00:13:57 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
scroll_stream_into_view($stream_li);
|
2017-05-02 01:22:18 +02:00
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2016-07-01 07:26:09 +02:00
|
|
|
|
2022-02-20 21:32:14 +01:00
|
|
|
export function refresh_muted_or_unmuted_stream(sub) {
|
|
|
|
build_stream_sidebar_row(sub);
|
|
|
|
update_streams_sidebar();
|
|
|
|
}
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function get_sidebar_stream_topic_info(filter) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const result = {
|
2017-08-10 18:31:17 +02:00
|
|
|
stream_id: undefined,
|
|
|
|
topic_selected: false,
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const op_stream = filter.operands("stream");
|
2017-08-10 18:31:17 +02:00
|
|
|
if (op_stream.length === 0) {
|
|
|
|
return result;
|
2017-05-14 20:30:15 +02:00
|
|
|
}
|
2017-08-10 18:31:17 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_name = op_stream[0];
|
|
|
|
const stream_id = stream_data.get_stream_id(stream_name);
|
2017-08-10 18:31:17 +02:00
|
|
|
|
|
|
|
if (!stream_id) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-11-23 00:41:09 +01:00
|
|
|
if (!stream_data.is_subscribed(stream_id)) {
|
2017-08-10 18:31:17 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.stream_id = stream_id;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const op_topic = filter.operands("topic");
|
2018-11-13 16:23:44 +01:00
|
|
|
result.topic_selected = op_topic.length === 1;
|
2017-08-10 18:31:17 +02:00
|
|
|
|
|
|
|
return result;
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-08-10 18:31:17 +02:00
|
|
|
|
2017-08-12 16:48:34 +02:00
|
|
|
function deselect_stream_items() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("ul#stream_filters li").removeClass("active-filter");
|
2017-08-12 16:48:34 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function update_stream_sidebar_for_narrow(filter) {
|
|
|
|
const info = get_sidebar_stream_topic_info(filter);
|
2017-08-10 18:31:17 +02:00
|
|
|
|
2017-08-12 16:48:34 +02:00
|
|
|
deselect_stream_items();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = info.stream_id;
|
2017-08-10 18:31:17 +02:00
|
|
|
|
|
|
|
if (!stream_id) {
|
2018-09-10 23:15:55 +02:00
|
|
|
topic_zoom.clear_topics();
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-08-10 18:31:17 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = get_stream_li(stream_id);
|
2017-08-10 18:31:17 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if (!$stream_li) {
|
2020-04-06 19:39:56 +02:00
|
|
|
// This is a sanity check. When we narrow to a subscribed
|
2017-08-10 18:31:17 +02:00
|
|
|
// stream, there will always be a stream list item
|
2020-04-06 19:39:56 +02:00
|
|
|
// corresponding to that stream in our sidebar. This error
|
|
|
|
// stopped appearing from March 2018 until at least
|
|
|
|
// April 2020, so if it appears again, something regressed.
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("No stream_li for subscribed stream " + stream_id);
|
2018-09-10 23:15:55 +02:00
|
|
|
topic_zoom.clear_topics();
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-08-10 18:31:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!info.topic_selected) {
|
2022-01-25 11:36:19 +01:00
|
|
|
$stream_li.addClass("active-filter");
|
2017-08-10 18:31:17 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 00:30:23 +02:00
|
|
|
if (stream_id !== topic_list.active_stream_id()) {
|
2018-09-10 23:15:55 +02:00
|
|
|
topic_zoom.clear_topics();
|
2017-08-11 00:30:23 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
topic_list.rebuild($stream_li, stream_id);
|
2017-08-10 18:31:17 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
return $stream_li;
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-05-14 20:30:15 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function handle_narrow_activated(filter) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = update_stream_sidebar_for_narrow(filter);
|
|
|
|
if ($stream_li) {
|
|
|
|
scroll_stream_into_view($stream_li);
|
2017-08-12 16:49:10 +02:00
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-08-12 16:49:10 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function handle_narrow_deactivated() {
|
2017-08-12 16:49:10 +02:00
|
|
|
deselect_stream_items();
|
2018-09-10 23:15:55 +02:00
|
|
|
topic_zoom.clear_topics();
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-08-12 16:49:10 +02:00
|
|
|
|
2018-04-15 12:29:17 +02:00
|
|
|
function focus_stream_filter(e) {
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor.reset();
|
2018-04-15 12:29:17 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function keydown_enter_key() {
|
2021-02-28 21:31:02 +01:00
|
|
|
const stream_id = stream_cursor.get_key();
|
2018-04-24 16:59:01 +02:00
|
|
|
|
|
|
|
if (stream_id === undefined) {
|
|
|
|
// This can happen for empty searches, no need to warn.
|
|
|
|
return;
|
|
|
|
}
|
2018-04-15 12:29:17 +02:00
|
|
|
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2018-04-15 12:29:17 +02:00
|
|
|
|
2018-04-24 16:59:01 +02:00
|
|
|
if (sub === undefined) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Unknown stream_id for search/enter: " + stream_id);
|
2018-04-24 16:59:01 +02:00
|
|
|
return;
|
2018-04-15 12:29:17 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
clear_and_hide_search();
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow.by("stream", sub.name, {trigger: "sidebar enter key"});
|
2018-04-15 12:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function actually_update_streams_for_search() {
|
2021-02-28 21:31:02 +01:00
|
|
|
update_streams_sidebar();
|
2018-04-15 12:29:17 +02:00
|
|
|
resize.resize_page_components();
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor.reset();
|
2018-04-15 12:29:17 +02:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const update_streams_for_search = _.throttle(actually_update_streams_for_search, 50);
|
2018-04-15 12:29:17 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function initialize() {
|
|
|
|
create_initial_sidebar_rows();
|
2019-03-22 17:26:51 +01:00
|
|
|
|
|
|
|
// We build the stream_list now. It may get re-built again very shortly
|
|
|
|
// when new messages come in, but it's fairly quick.
|
2021-02-28 21:31:02 +01:00
|
|
|
build_stream_list();
|
2022-08-15 21:32:10 +02:00
|
|
|
update_subscribe_to_more_streams_link();
|
2021-02-28 21:31:02 +01:00
|
|
|
set_event_handlers();
|
|
|
|
}
|
2019-03-22 17:26:51 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function set_event_handlers() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream_filters").on("click", "li .subscription_block", (e) => {
|
2013-11-22 22:25:31 +01:00
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
const stream_id = stream_id_for_elt($(e.target).parents("li"));
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2016-12-19 23:38:19 +01:00
|
|
|
popovers.hide_all();
|
2020-07-15 01:29:15 +02:00
|
|
|
narrow.by("stream", sub.name, {trigger: "sidebar"});
|
2013-11-22 22:25:31 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
clear_and_hide_search();
|
2018-01-25 20:44:30 +01:00
|
|
|
|
2013-11-22 22:25:31 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
$("#clear_search_stream_button").on("click", clear_search);
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#streams_header")
|
|
|
|
.expectOne()
|
2020-07-20 21:26:58 +02:00
|
|
|
.on("click", (e) => {
|
2021-06-05 16:07:11 +02:00
|
|
|
e.preventDefault();
|
2022-02-11 19:58:26 +01:00
|
|
|
if (e.target.id === "streams_inline_icon") {
|
2021-06-05 16:07:11 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
toggle_filter_displayed(e);
|
2020-07-15 00:34:28 +02:00
|
|
|
});
|
2018-04-24 16:59:01 +02:00
|
|
|
|
2022-09-13 13:15:57 +02:00
|
|
|
function toggle_pm_header_icon() {
|
|
|
|
if (pm_list.is_private_messages_collapsed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const scroll_position = $(
|
|
|
|
"#left_sidebar_scroll_container .simplebar-content-wrapper",
|
|
|
|
).scrollTop();
|
|
|
|
const pm_list_height = $("#private_messages_list").height();
|
|
|
|
if (scroll_position > pm_list_height) {
|
|
|
|
$("#toggle_private_messages_section_icon").addClass("fa-caret-right");
|
|
|
|
$("#toggle_private_messages_section_icon").removeClass("fa-caret-down");
|
|
|
|
} else {
|
|
|
|
$("#toggle_private_messages_section_icon").addClass("fa-caret-down");
|
|
|
|
$("#toggle_private_messages_section_icon").removeClass("fa-caret-right");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 20:23:20 +02:00
|
|
|
// check for user scrolls on streams list for first time
|
2022-09-13 13:15:57 +02:00
|
|
|
ui.get_scroll_element($("#left_sidebar_scroll_container")).on("scroll", () => {
|
2018-07-06 20:23:20 +02:00
|
|
|
has_scrolled = true;
|
2022-09-13 13:15:57 +02:00
|
|
|
toggle_pm_header_icon();
|
2018-07-06 20:23:20 +02:00
|
|
|
});
|
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor = new ListCursor({
|
2018-04-24 16:59:01 +02:00
|
|
|
list: {
|
2022-09-13 13:15:57 +02:00
|
|
|
scroll_container_sel: "#left_sidebar_scroll_container",
|
2020-07-20 22:18:43 +02:00
|
|
|
find_li(opts) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = opts.key;
|
2021-02-28 21:31:02 +01:00
|
|
|
const li = get_stream_li(stream_id);
|
2018-04-24 16:59:01 +02:00
|
|
|
return li;
|
|
|
|
},
|
|
|
|
first_key: stream_sort.first_stream_id,
|
|
|
|
prev_key: stream_sort.prev_stream_id,
|
|
|
|
next_key: stream_sort.next_stream_id,
|
|
|
|
},
|
2020-07-15 01:29:15 +02:00
|
|
|
highlight_class: "highlighted_stream",
|
2018-04-24 16:59:01 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const $search_input = $(".stream-list-filter").expectOne();
|
2018-04-24 16:59:01 +02:00
|
|
|
|
|
|
|
keydown_util.handle({
|
2022-01-25 11:36:19 +01:00
|
|
|
$elem: $search_input,
|
2018-04-24 16:59:01 +02:00
|
|
|
handlers: {
|
2021-05-26 19:51:07 +02:00
|
|
|
Enter() {
|
2018-04-24 16:59:01 +02:00
|
|
|
keydown_enter_key();
|
|
|
|
return true;
|
|
|
|
},
|
2021-05-26 19:51:07 +02:00
|
|
|
ArrowUp() {
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor.prev();
|
2018-04-24 16:59:01 +02:00
|
|
|
return true;
|
|
|
|
},
|
2021-05-26 19:51:07 +02:00
|
|
|
ArrowDown() {
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor.next();
|
2018-04-24 16:59:01 +02:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$search_input.on("click", focus_stream_filter);
|
2021-02-28 21:31:02 +01:00
|
|
|
$search_input.on("focusout", () => stream_cursor.clear());
|
2020-07-15 01:29:15 +02:00
|
|
|
$search_input.on("input", update_streams_for_search);
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function searching() {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".stream-list-filter").expectOne().is(":focus");
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function escape_search() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $filter = $(".stream-list-filter").expectOne();
|
|
|
|
if ($filter.val() === "") {
|
2021-02-28 21:31:02 +01:00
|
|
|
clear_and_hide_search();
|
2016-06-13 22:06:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter.val("");
|
2016-06-13 22:06:12 +02:00
|
|
|
update_streams_for_search();
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function clear_search(e) {
|
2019-02-23 15:10:12 +01:00
|
|
|
e.stopPropagation();
|
2022-01-25 11:36:19 +01:00
|
|
|
const $filter = $(".stream-list-filter").expectOne();
|
|
|
|
if ($filter.val() === "") {
|
2021-02-28 21:31:02 +01:00
|
|
|
clear_and_hide_search();
|
2017-04-05 14:18:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter.val("");
|
|
|
|
$filter.trigger("blur");
|
2017-04-05 14:18:35 +02:00
|
|
|
update_streams_for_search();
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-04-05 14:18:35 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function show_search_section() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".stream_search_section").expectOne().removeClass("notdisplayed");
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
resize.resize_stream_filters_container();
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function hide_search_section() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".stream_search_section").expectOne().addClass("notdisplayed");
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
resize.resize_stream_filters_container();
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function initiate_search() {
|
|
|
|
show_search_section();
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $filter = $(".stream-list-filter").expectOne();
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
|
2020-09-23 13:11:57 +02:00
|
|
|
if (
|
|
|
|
// Check if left column is a popover and is not visible.
|
|
|
|
$("#streamlist-toggle").is(":visible") &&
|
|
|
|
!$(".app-main .column-left").hasClass("expanded")
|
|
|
|
) {
|
2017-10-12 05:07:12 +02:00
|
|
|
popovers.hide_all();
|
|
|
|
stream_popover.show_streamlist_sidebar();
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter.trigger("focus");
|
2018-02-12 22:56:37 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor.reset();
|
|
|
|
}
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function clear_and_hide_search() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $filter = $(".stream-list-filter");
|
|
|
|
if ($filter.val() !== "") {
|
|
|
|
$filter.val("");
|
2016-06-13 22:06:12 +02:00
|
|
|
update_streams_for_search();
|
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
stream_cursor.clear();
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter.trigger("blur");
|
bug fix: Move stream search out of scroll container.
We want the search widget, when visible, to be
outside the scroll container for the stream list.
One obvious use case is if you start scrolling, and
then realize it might be less effort to search.
Also, for user search, it already worked this way.
We have to add a couple resizing hooks here, but
it's not necessary to change the actual resize
calculation, since we move the section inside
of #streams_header, which is already accounted
for.
The only markup change here is to add
a `stream_search_section` class. I don't
know why we use `notdisplayed` here instead of
jQuery, or what `input-append` is for, but I
considered them outside the scope of this change.
We can also remove some crufty CSS that was
compensating for it being inside the container.
2019-02-09 19:09:56 +01:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
hide_search_section();
|
|
|
|
}
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function toggle_filter_displayed(e) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if ($(".stream_search_section.notdisplayed").length === 0) {
|
2021-02-28 21:31:02 +01:00
|
|
|
clear_and_hide_search();
|
2016-06-13 22:06:12 +02:00
|
|
|
} else {
|
2021-02-28 21:31:02 +01:00
|
|
|
initiate_search();
|
2016-06-13 22:06:12 +02:00
|
|
|
}
|
|
|
|
e.preventDefault();
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2016-06-13 22:06:12 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
export function scroll_stream_into_view($stream_li) {
|
2022-09-13 13:15:57 +02:00
|
|
|
const $container = $("#left_sidebar_scroll_container");
|
2017-05-02 01:08:31 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if ($stream_li.length !== 1) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("Invalid stream_li was passed in");
|
2017-05-02 01:08:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-10-05 09:43:57 +02:00
|
|
|
const stream_header_height = $("#streams_header").outerHeight();
|
|
|
|
scroll_util.scroll_element_into_container($stream_li, $container, stream_header_height);
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2017-05-02 01:08:31 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function maybe_scroll_narrow_into_view() {
|
2018-07-06 20:23:20 +02:00
|
|
|
// we don't want to interfere with user scrolling once the page loads
|
|
|
|
if (has_scrolled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = get_current_stream_li();
|
|
|
|
if ($stream_li) {
|
|
|
|
scroll_stream_into_view($stream_li);
|
2018-07-06 20:23:20 +02:00
|
|
|
}
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|
2018-07-06 20:23:20 +02:00
|
|
|
|
2021-02-28 21:31:02 +01:00
|
|
|
export function get_current_stream_li() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = topic_list.active_stream_id();
|
2018-07-06 20:23:20 +02:00
|
|
|
|
|
|
|
if (!stream_id) {
|
|
|
|
// stream_id is undefined in non-stream narrows
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-07-06 20:23:20 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = get_stream_li(stream_id);
|
2018-07-06 20:23:20 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
if (!$stream_li) {
|
2018-07-06 20:23:20 +02:00
|
|
|
// This code path shouldn't ever be reached.
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.warn("No active stream_li found for defined id " + stream_id);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-07-06 20:23:20 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
return $stream_li;
|
2021-02-28 21:31:02 +01:00
|
|
|
}
|