mirror of https://github.com/zulip/zulip.git
js: Convert static/js/stream_list.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
727208b84c
commit
3e8ddc229b
|
@ -147,7 +147,6 @@
|
|||
"pointer": false,
|
||||
"realm_night_logo": false,
|
||||
"settings_profile_fields": false,
|
||||
"stream_list": false,
|
||||
"StripeCheckout": false,
|
||||
"subs": false,
|
||||
"ui": false,
|
||||
|
|
|
@ -35,7 +35,9 @@ const settings_org = {__esModule: true};
|
|||
rewiremock("../../static/js/settings_org").with(settings_org);
|
||||
const settings_streams = {__esModule: true};
|
||||
rewiremock("../../static/js/settings_streams").with(settings_streams);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const stream_list = {__esModule: true};
|
||||
|
||||
rewiremock("../../static/js/stream_list").with(stream_list);
|
||||
|
||||
const server_events_dispatch = zrequire("server_events_dispatch");
|
||||
|
||||
|
|
|
@ -100,7 +100,8 @@ const reactions = {__esModule: true};
|
|||
rewiremock("../../static/js/reactions").with(reactions);
|
||||
const search = {__esModule: true};
|
||||
rewiremock("../../static/js/search").with(search);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const stream_list = {__esModule: true};
|
||||
rewiremock("../../static/js/stream_list").with(stream_list);
|
||||
const subs = set_global("subs", {});
|
||||
|
||||
set_global("current_msg_list", {
|
||||
|
|
|
@ -18,7 +18,8 @@ rewiremock("../../static/js/notifications").with(notifications);
|
|||
const page_params = set_global("page_params", {});
|
||||
const pm_list = {__esModule: true};
|
||||
rewiremock("../../static/js/pm_list").with(pm_list);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const stream_list = {__esModule: true};
|
||||
rewiremock("../../static/js/stream_list").with(stream_list);
|
||||
const unread_ui = {__esModule: true};
|
||||
|
||||
rewiremock("../../static/js/unread_ui").with(unread_ui);
|
||||
|
|
|
@ -47,9 +47,12 @@ const pm_list = {__esModule: true};
|
|||
rewiremock("../../static/js/pm_list").with(pm_list);
|
||||
const server_events = {__esModule: true};
|
||||
rewiremock("../../static/js/server_events").with(server_events);
|
||||
const stream_list = set_global("stream_list", {
|
||||
const stream_list = {
|
||||
__esModule: true,
|
||||
maybe_scroll_narrow_into_view: () => {},
|
||||
});
|
||||
};
|
||||
|
||||
rewiremock("../../static/js/stream_list").with(stream_list);
|
||||
|
||||
rewiremock.enable();
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ rewiremock("../../static/js/notifications").with(notifications);
|
|||
set_global("page_params", {});
|
||||
const search = {__esModule: true};
|
||||
rewiremock("../../static/js/search").with(search);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const stream_list = {__esModule: true};
|
||||
rewiremock("../../static/js/stream_list").with(stream_list);
|
||||
const message_view_header = {__esModule: true};
|
||||
rewiremock("../../static/js/message_view_header").with(message_view_header);
|
||||
const top_left_corner = {__esModule: true};
|
||||
|
|
|
@ -13,7 +13,7 @@ const noop = () => {};
|
|||
rewiremock("../../static/js/top_left_corner").with({
|
||||
narrow_to_recent_topics: noop,
|
||||
});
|
||||
set_global("stream_list", {
|
||||
rewiremock("../../static/js/stream_list").with({
|
||||
handle_narrow_deactivated: noop,
|
||||
});
|
||||
set_global("compose_actions", {
|
||||
|
|
|
@ -23,7 +23,8 @@ const message_util = {__esModule: true};
|
|||
rewiremock("../../static/js/message_util").with(message_util);
|
||||
const stream_color = {__esModule: true};
|
||||
rewiremock("../../static/js/stream_color").with(stream_color);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const stream_list = {__esModule: true};
|
||||
rewiremock("../../static/js/stream_list").with(stream_list);
|
||||
const stream_muting = {__esModule: true};
|
||||
rewiremock("../../static/js/stream_muting").with(stream_muting);
|
||||
rewiremock("../../static/js/recent_topics").with({
|
||||
|
|
|
@ -675,10 +675,10 @@ test_ui("rename_stream", () => {
|
|||
});
|
||||
|
||||
let count_updated;
|
||||
stream_list.update_count_in_dom = (li) => {
|
||||
stream_list.__Rewire__("update_count_in_dom", (li) => {
|
||||
assert.equal(li, li_stub);
|
||||
count_updated = true;
|
||||
};
|
||||
});
|
||||
|
||||
stream_list.rename_stream(sub);
|
||||
assert(count_updated);
|
||||
|
@ -706,14 +706,14 @@ test_ui("refresh_pin", () => {
|
|||
|
||||
stub_templates(() => ({to_$: () => li_stub}));
|
||||
|
||||
stream_list.update_count_in_dom = noop;
|
||||
stream_list.__Rewire__("update_count_in_dom", noop);
|
||||
$("#stream_filters").append = noop;
|
||||
|
||||
let scrolled;
|
||||
stream_list.scroll_stream_into_view = (li) => {
|
||||
stream_list.__Rewire__("scroll_stream_into_view", (li) => {
|
||||
assert.equal(li, li_stub);
|
||||
scrolled = true;
|
||||
};
|
||||
});
|
||||
|
||||
stream_list.refresh_pinned_or_unpinned_stream(pinned_sub);
|
||||
assert(scrolled);
|
||||
|
@ -724,14 +724,14 @@ test_ui("create_initial_sidebar_rows", () => {
|
|||
|
||||
const html_dict = new Map();
|
||||
|
||||
stream_list.stream_sidebar = {
|
||||
stream_list.__Rewire__("stream_sidebar", {
|
||||
has_row_for: () => false,
|
||||
set_row(stream_id, widget) {
|
||||
html_dict.set(stream_id, widget.get_li().html());
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
stream_list.update_count_in_dom = noop;
|
||||
stream_list.__Rewire__("update_count_in_dom", noop);
|
||||
|
||||
stub_templates((template_name, data) => {
|
||||
assert.equal(template_name, "stream_sidebar_row");
|
||||
|
|
|
@ -35,14 +35,14 @@ function expand_sidebar() {
|
|||
function make_cursor_helper() {
|
||||
const events = [];
|
||||
|
||||
stream_list.stream_cursor = {
|
||||
stream_list.__Rewire__("stream_cursor", {
|
||||
reset: () => {
|
||||
events.push("reset");
|
||||
},
|
||||
clear: () => {
|
||||
events.push("clear");
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
events,
|
||||
|
@ -102,9 +102,9 @@ run_test("basics", () => {
|
|||
|
||||
function verify_list_updated(f) {
|
||||
let updated;
|
||||
stream_list.update_streams_sidebar = () => {
|
||||
stream_list.__Rewire__("update_streams_sidebar", () => {
|
||||
updated = true;
|
||||
};
|
||||
});
|
||||
|
||||
f();
|
||||
assert(updated);
|
||||
|
|
|
@ -39,7 +39,8 @@ const overlays = {__esModule: true};
|
|||
rewiremock("../../static/js/overlays").with(overlays);
|
||||
const resize = {__esModule: true};
|
||||
rewiremock("../../static/js/resize").with(resize);
|
||||
let stream_list = set_global("stream_list", {});
|
||||
let stream_list = {__esModule: true};
|
||||
rewiremock("../../static/js/stream_list").with(stream_list);
|
||||
let unread_ops = {__esModule: true};
|
||||
rewiremock("../../static/js/unread_ops").with(unread_ops);
|
||||
const unread_ui = {__esModule: true};
|
||||
|
@ -696,6 +697,7 @@ run_test("unread_ops", (override) => {
|
|||
|
||||
*/
|
||||
|
||||
rewiremock("../../static/js/stream_list").disable();
|
||||
stream_list = zrequire("stream_list");
|
||||
|
||||
const social_stream = {
|
||||
|
|
|
@ -115,7 +115,6 @@ const upload = zrequire("upload");
|
|||
const compose = zrequire("compose");
|
||||
zrequire("composebox_typeahead");
|
||||
zrequire("narrow");
|
||||
zrequire("stream_list");
|
||||
|
||||
run_test("initialize_everything", () => {
|
||||
util.is_mobile = () => false;
|
||||
|
|
|
@ -16,7 +16,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";
|
|||
import "../i18n";
|
||||
import "../fold_dict";
|
||||
import "../setup";
|
||||
import "../stream_list";
|
||||
import "../widgetize";
|
||||
import "../message_list";
|
||||
import "../narrow";
|
||||
|
|
|
@ -30,6 +30,7 @@ import * as server_events from "./server_events";
|
|||
import * as settings_panel_menu from "./settings_panel_menu";
|
||||
import * as settings_toggle from "./settings_toggle";
|
||||
import * as stream_edit from "./stream_edit";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as stream_popover from "./stream_popover";
|
||||
import * as ui_util from "./ui_util";
|
||||
import * as unread_ops from "./unread_ops";
|
||||
|
|
|
@ -11,6 +11,7 @@ import * as popovers from "./popovers";
|
|||
import * as recent_topics from "./recent_topics";
|
||||
import * as rows from "./rows";
|
||||
import * as sent_messages from "./sent_messages";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as stream_topic_history from "./stream_topic_history";
|
||||
import * as transmit from "./transmit";
|
||||
import * as util from "./util";
|
||||
|
|
|
@ -18,7 +18,6 @@ declare let narrow: any;
|
|||
declare let page_params: any;
|
||||
declare let pointer: any;
|
||||
declare let settings_profile_fields: any;
|
||||
declare let stream_list: any;
|
||||
declare let subs: any;
|
||||
declare let ui: any;
|
||||
declare let widgetize: any;
|
||||
|
|
|
@ -24,6 +24,7 @@ import * as popovers from "./popovers";
|
|||
import * as reactions from "./reactions";
|
||||
import * as recent_topics from "./recent_topics";
|
||||
import * as search from "./search";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as stream_popover from "./stream_popover";
|
||||
import * as topic_zoom from "./topic_zoom";
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ const recent_senders = require("./recent_senders");
|
|||
const recent_topics = require("./recent_topics");
|
||||
const resize = require("./resize");
|
||||
const stream_data = require("./stream_data");
|
||||
const stream_list = require("./stream_list");
|
||||
const stream_topic_history = require("./stream_topic_history");
|
||||
const unread = require("./unread");
|
||||
const unread_ops = require("./unread_ops");
|
||||
|
|
|
@ -9,6 +9,7 @@ import * as pm_list from "./pm_list";
|
|||
import * as recent_topics from "./recent_topics";
|
||||
import * as server_events from "./server_events";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as ui_report from "./ui_report";
|
||||
|
||||
const consts = {
|
||||
|
|
|
@ -9,6 +9,7 @@ import * as overlays from "./overlays";
|
|||
import * as recent_topics from "./recent_topics";
|
||||
import * as settings_muting from "./settings_muting";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as stream_popover from "./stream_popover";
|
||||
import * as unread_ui from "./unread_ui";
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ const search = require("./search");
|
|||
const search_pill = require("./search_pill");
|
||||
const search_pill_widget = require("./search_pill_widget");
|
||||
const stream_data = require("./stream_data");
|
||||
const stream_list = require("./stream_list");
|
||||
const stream_topic_history = require("./stream_topic_history");
|
||||
const top_left_corner = require("./top_left_corner");
|
||||
const topic_generator = require("./topic_generator");
|
||||
|
|
|
@ -16,6 +16,7 @@ import * as panels from "./panels";
|
|||
import * as people from "./people";
|
||||
import * as recent_senders from "./recent_senders";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as timerender from "./timerender";
|
||||
import * as top_left_corner from "./top_left_corner";
|
||||
import * as unread from "./unread";
|
||||
|
|
|
@ -41,6 +41,7 @@ import * as settings_users from "./settings_users";
|
|||
import * as starred_messages from "./starred_messages";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_events from "./stream_events";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as stream_topic_history from "./stream_topic_history";
|
||||
import * as submessage from "./submessage";
|
||||
import * as typing_events from "./typing_events";
|
||||
|
|
|
@ -8,6 +8,7 @@ import * as recent_topics from "./recent_topics";
|
|||
import * as settings_notifications from "./settings_notifications";
|
||||
import * as stream_color from "./stream_color";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as stream_muting from "./stream_muting";
|
||||
|
||||
// In theory, this function should apply the account-level defaults,
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
"use strict";
|
||||
import _ from "lodash";
|
||||
|
||||
const _ = require("lodash");
|
||||
import render_stream_privacy from "../templates/stream_privacy.hbs";
|
||||
import render_stream_sidebar_row from "../templates/stream_sidebar_row.hbs";
|
||||
|
||||
const render_stream_privacy = require("../templates/stream_privacy.hbs");
|
||||
const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs");
|
||||
import * as hash_util from "./hash_util";
|
||||
import * as keydown_util from "./keydown_util";
|
||||
import {ListCursor} from "./list_cursor";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as popovers from "./popovers";
|
||||
import * as resize from "./resize";
|
||||
import * as scroll_util from "./scroll_util";
|
||||
import * as stream_color from "./stream_color";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_popover from "./stream_popover";
|
||||
import * as stream_sort from "./stream_sort";
|
||||
import * as topic_list from "./topic_list";
|
||||
import * as topic_zoom from "./topic_zoom";
|
||||
import * as unread from "./unread";
|
||||
|
||||
const hash_util = require("./hash_util");
|
||||
const keydown_util = require("./keydown_util");
|
||||
const {ListCursor} = require("./list_cursor");
|
||||
const narrow_state = require("./narrow_state");
|
||||
const popovers = require("./popovers");
|
||||
const resize = require("./resize");
|
||||
const scroll_util = require("./scroll_util");
|
||||
const stream_color = require("./stream_color");
|
||||
const stream_data = require("./stream_data");
|
||||
const stream_popover = require("./stream_popover");
|
||||
const stream_sort = require("./stream_sort");
|
||||
const topic_list = require("./topic_list");
|
||||
const topic_zoom = require("./topic_zoom");
|
||||
const unread = require("./unread");
|
||||
export let stream_cursor;
|
||||
|
||||
let has_scrolled = false;
|
||||
|
||||
exports.update_count_in_dom = function (unread_count_elem, count) {
|
||||
export function update_count_in_dom(unread_count_elem, count) {
|
||||
const count_span = unread_count_elem.find(".count");
|
||||
const value_span = count_span.find(".value");
|
||||
|
||||
|
@ -41,7 +41,7 @@ exports.update_count_in_dom = function (unread_count_elem, count) {
|
|||
count_span.parent(".subscription_block").addClass("stream-with-count");
|
||||
}
|
||||
value_span.text(count);
|
||||
};
|
||||
}
|
||||
|
||||
class StreamSidebar {
|
||||
rows = new Map(); // stream id -> row widget
|
||||
|
@ -68,7 +68,7 @@ class StreamSidebar {
|
|||
this.rows.delete(stream_id);
|
||||
}
|
||||
}
|
||||
exports.stream_sidebar = new StreamSidebar();
|
||||
export const stream_sidebar = new StreamSidebar();
|
||||
|
||||
function get_search_term() {
|
||||
const search_box = $(".stream-list-filter");
|
||||
|
@ -76,30 +76,30 @@ function get_search_term() {
|
|||
return search_term;
|
||||
}
|
||||
|
||||
exports.add_sidebar_row = function (sub) {
|
||||
exports.create_sidebar_row(sub);
|
||||
exports.build_stream_list();
|
||||
exports.stream_cursor.redraw();
|
||||
};
|
||||
export function add_sidebar_row(sub) {
|
||||
create_sidebar_row(sub);
|
||||
build_stream_list();
|
||||
stream_cursor.redraw();
|
||||
}
|
||||
|
||||
exports.remove_sidebar_row = function (stream_id) {
|
||||
exports.stream_sidebar.remove_row(stream_id);
|
||||
exports.build_stream_list();
|
||||
exports.stream_cursor.redraw();
|
||||
};
|
||||
export function remove_sidebar_row(stream_id) {
|
||||
stream_sidebar.remove_row(stream_id);
|
||||
build_stream_list();
|
||||
stream_cursor.redraw();
|
||||
}
|
||||
|
||||
exports.create_initial_sidebar_rows = function () {
|
||||
export function create_initial_sidebar_rows() {
|
||||
// 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.
|
||||
const subs = stream_data.subscribed_subs();
|
||||
|
||||
for (const sub of subs) {
|
||||
exports.create_sidebar_row(sub);
|
||||
create_sidebar_row(sub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.build_stream_list = function (force_rerender) {
|
||||
export function build_stream_list(force_rerender) {
|
||||
// This function assumes we have already created the individual
|
||||
// sidebar rows. Our job here is to build the bigger widget,
|
||||
// which largely is a matter of arranging the individual rows in
|
||||
|
@ -121,7 +121,7 @@ exports.build_stream_list = function (force_rerender) {
|
|||
const elems = [];
|
||||
|
||||
function add_sidebar_li(stream_id) {
|
||||
const sidebar_row = exports.stream_sidebar.get_row(stream_id);
|
||||
const sidebar_row = stream_sidebar.get_row(stream_id);
|
||||
sidebar_row.update_whether_active();
|
||||
elems.push(sidebar_row.get_li());
|
||||
}
|
||||
|
@ -154,10 +154,10 @@ exports.build_stream_list = function (force_rerender) {
|
|||
}
|
||||
|
||||
parent.append(elems);
|
||||
};
|
||||
}
|
||||
|
||||
exports.get_stream_li = function (stream_id) {
|
||||
const row = exports.stream_sidebar.get_row(stream_id);
|
||||
export function get_stream_li(stream_id) {
|
||||
const row = stream_sidebar.get_row(stream_id);
|
||||
if (!row) {
|
||||
// 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
|
||||
|
@ -177,13 +177,13 @@ exports.get_stream_li = function (stream_id) {
|
|||
}
|
||||
|
||||
return li;
|
||||
};
|
||||
}
|
||||
|
||||
function stream_id_for_elt(elt) {
|
||||
return Number.parseInt(elt.attr("data-stream-id"), 10);
|
||||
}
|
||||
|
||||
exports.zoom_in_topics = function (options) {
|
||||
export function zoom_in_topics(options) {
|
||||
// This only does stream-related tasks related to zooming
|
||||
// in to more topics, which is basically hiding all the
|
||||
// other streams.
|
||||
|
@ -208,9 +208,9 @@ exports.zoom_in_topics = function (options) {
|
|||
elt.hide();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.zoom_out_topics = function () {
|
||||
export function zoom_out_topics() {
|
||||
// Show stream list titles and pinned stream splitter
|
||||
$(".stream-filters-label").each(function () {
|
||||
$(this).show();
|
||||
|
@ -221,10 +221,10 @@ exports.zoom_out_topics = function () {
|
|||
|
||||
$("#streams_list").expectOne().removeClass("zoom-in").addClass("zoom-out");
|
||||
$("#stream_filters li.narrow-filter").show();
|
||||
};
|
||||
}
|
||||
|
||||
exports.set_in_home_view = function (stream_id, in_home) {
|
||||
const li = exports.get_stream_li(stream_id);
|
||||
export function set_in_home_view(stream_id, in_home) {
|
||||
const li = get_stream_li(stream_id);
|
||||
if (!li) {
|
||||
blueslip.error("passed in bad stream id " + stream_id);
|
||||
return;
|
||||
|
@ -235,7 +235,7 @@ exports.set_in_home_view = function (stream_id, in_home) {
|
|||
} else {
|
||||
li.addClass("out_of_home_view");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function build_stream_sidebar_li(sub) {
|
||||
const name = sub.name;
|
||||
|
@ -279,25 +279,25 @@ class StreamSidebarRow {
|
|||
|
||||
update_unread_count() {
|
||||
const count = unread.num_unread_for_stream(this.sub.stream_id);
|
||||
exports.update_count_in_dom(this.list_item, count);
|
||||
update_count_in_dom(this.list_item, count);
|
||||
}
|
||||
}
|
||||
|
||||
function build_stream_sidebar_row(sub) {
|
||||
exports.stream_sidebar.set_row(sub.stream_id, new StreamSidebarRow(sub));
|
||||
stream_sidebar.set_row(sub.stream_id, new StreamSidebarRow(sub));
|
||||
}
|
||||
|
||||
exports.create_sidebar_row = function (sub) {
|
||||
if (exports.stream_sidebar.has_row_for(sub.stream_id)) {
|
||||
export function create_sidebar_row(sub) {
|
||||
if (stream_sidebar.has_row_for(sub.stream_id)) {
|
||||
// already exists
|
||||
blueslip.warn("Dup try to build sidebar row for stream " + sub.stream_id);
|
||||
return;
|
||||
}
|
||||
build_stream_sidebar_row(sub);
|
||||
};
|
||||
}
|
||||
|
||||
exports.redraw_stream_privacy = function (sub) {
|
||||
const li = exports.get_stream_li(sub.stream_id);
|
||||
export function redraw_stream_privacy(sub) {
|
||||
const li = get_stream_li(sub.stream_id);
|
||||
if (!li) {
|
||||
// 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
|
||||
|
@ -315,23 +315,23 @@ exports.redraw_stream_privacy = function (sub) {
|
|||
|
||||
const html = render_stream_privacy(args);
|
||||
div.html(html);
|
||||
};
|
||||
}
|
||||
|
||||
function set_stream_unread_count(stream_id, count) {
|
||||
const unread_count_elem = exports.get_stream_li(stream_id);
|
||||
const unread_count_elem = get_stream_li(stream_id);
|
||||
if (!unread_count_elem) {
|
||||
// This can happen for legitimate reasons, but we warn
|
||||
// just in case.
|
||||
blueslip.warn("stream id no longer in sidebar: " + stream_id);
|
||||
return;
|
||||
}
|
||||
exports.update_count_in_dom(unread_count_elem, count);
|
||||
update_count_in_dom(unread_count_elem, count);
|
||||
}
|
||||
|
||||
exports.update_streams_sidebar = function (force_rerender) {
|
||||
exports.build_stream_list(force_rerender);
|
||||
export function update_streams_sidebar(force_rerender) {
|
||||
build_stream_list(force_rerender);
|
||||
|
||||
exports.stream_cursor.redraw();
|
||||
stream_cursor.redraw();
|
||||
|
||||
if (!narrow_state.active()) {
|
||||
return;
|
||||
|
@ -339,42 +339,42 @@ exports.update_streams_sidebar = function (force_rerender) {
|
|||
|
||||
const filter = narrow_state.filter();
|
||||
|
||||
exports.update_stream_sidebar_for_narrow(filter);
|
||||
};
|
||||
update_stream_sidebar_for_narrow(filter);
|
||||
}
|
||||
|
||||
exports.update_dom_with_unread_counts = function (counts) {
|
||||
export function update_dom_with_unread_counts(counts) {
|
||||
// counts.stream_count maps streams to counts
|
||||
for (const [stream_id, count] of counts.stream_count) {
|
||||
set_stream_unread_count(stream_id, count);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.rename_stream = function (sub) {
|
||||
export function rename_stream(sub) {
|
||||
// The sub object is expected to already have the updated name
|
||||
build_stream_sidebar_row(sub);
|
||||
exports.update_streams_sidebar(true); // big hammer
|
||||
};
|
||||
update_streams_sidebar(true); // big hammer
|
||||
}
|
||||
|
||||
exports.refresh_pinned_or_unpinned_stream = function (sub) {
|
||||
export function refresh_pinned_or_unpinned_stream(sub) {
|
||||
// Pinned/unpinned streams require re-ordering.
|
||||
// We use kind of brute force now, which is probably fine.
|
||||
build_stream_sidebar_row(sub);
|
||||
exports.update_streams_sidebar();
|
||||
update_streams_sidebar();
|
||||
|
||||
// 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) {
|
||||
const stream_li = exports.get_stream_li(sub.stream_id);
|
||||
const stream_li = get_stream_li(sub.stream_id);
|
||||
if (!stream_li) {
|
||||
blueslip.error("passed in bad stream id " + sub.stream_id);
|
||||
return;
|
||||
}
|
||||
exports.scroll_stream_into_view(stream_li);
|
||||
scroll_stream_into_view(stream_li);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.get_sidebar_stream_topic_info = function (filter) {
|
||||
export function get_sidebar_stream_topic_info(filter) {
|
||||
const result = {
|
||||
stream_id: undefined,
|
||||
topic_selected: false,
|
||||
|
@ -402,14 +402,14 @@ exports.get_sidebar_stream_topic_info = function (filter) {
|
|||
result.topic_selected = op_topic.length === 1;
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
function deselect_stream_items() {
|
||||
$("ul#stream_filters li").removeClass("active-filter");
|
||||
}
|
||||
|
||||
exports.update_stream_sidebar_for_narrow = function (filter) {
|
||||
const info = exports.get_sidebar_stream_topic_info(filter);
|
||||
export function update_stream_sidebar_for_narrow(filter) {
|
||||
const info = get_sidebar_stream_topic_info(filter);
|
||||
|
||||
deselect_stream_items();
|
||||
|
||||
|
@ -420,7 +420,7 @@ exports.update_stream_sidebar_for_narrow = function (filter) {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const stream_li = exports.get_stream_li(stream_id);
|
||||
const stream_li = get_stream_li(stream_id);
|
||||
|
||||
if (!stream_li) {
|
||||
// This is a sanity check. When we narrow to a subscribed
|
||||
|
@ -444,27 +444,27 @@ exports.update_stream_sidebar_for_narrow = function (filter) {
|
|||
topic_list.rebuild(stream_li, stream_id);
|
||||
|
||||
return stream_li;
|
||||
};
|
||||
}
|
||||
|
||||
exports.handle_narrow_activated = function (filter) {
|
||||
const stream_li = exports.update_stream_sidebar_for_narrow(filter);
|
||||
export function handle_narrow_activated(filter) {
|
||||
const stream_li = update_stream_sidebar_for_narrow(filter);
|
||||
if (stream_li) {
|
||||
exports.scroll_stream_into_view(stream_li);
|
||||
scroll_stream_into_view(stream_li);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.handle_narrow_deactivated = function () {
|
||||
export function handle_narrow_deactivated() {
|
||||
deselect_stream_items();
|
||||
topic_zoom.clear_topics();
|
||||
};
|
||||
}
|
||||
|
||||
function focus_stream_filter(e) {
|
||||
exports.stream_cursor.reset();
|
||||
stream_cursor.reset();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function keydown_enter_key() {
|
||||
const stream_id = exports.stream_cursor.get_key();
|
||||
const stream_id = stream_cursor.get_key();
|
||||
|
||||
if (stream_id === undefined) {
|
||||
// This can happen for empty searches, no need to warn.
|
||||
|
@ -478,28 +478,28 @@ function keydown_enter_key() {
|
|||
return;
|
||||
}
|
||||
|
||||
exports.clear_and_hide_search();
|
||||
clear_and_hide_search();
|
||||
narrow.by("stream", sub.name, {trigger: "sidebar enter key"});
|
||||
}
|
||||
|
||||
function actually_update_streams_for_search() {
|
||||
exports.update_streams_sidebar();
|
||||
update_streams_sidebar();
|
||||
resize.resize_page_components();
|
||||
exports.stream_cursor.reset();
|
||||
stream_cursor.reset();
|
||||
}
|
||||
|
||||
const update_streams_for_search = _.throttle(actually_update_streams_for_search, 50);
|
||||
|
||||
exports.initialize = function () {
|
||||
exports.create_initial_sidebar_rows();
|
||||
export function initialize() {
|
||||
create_initial_sidebar_rows();
|
||||
|
||||
// We build the stream_list now. It may get re-built again very shortly
|
||||
// when new messages come in, but it's fairly quick.
|
||||
exports.build_stream_list();
|
||||
exports.set_event_handlers();
|
||||
};
|
||||
build_stream_list();
|
||||
set_event_handlers();
|
||||
}
|
||||
|
||||
exports.set_event_handlers = function () {
|
||||
export function set_event_handlers() {
|
||||
$("#stream_filters").on("click", "li .subscription_block", (e) => {
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
return;
|
||||
|
@ -509,18 +509,18 @@ exports.set_event_handlers = function () {
|
|||
popovers.hide_all();
|
||||
narrow.by("stream", sub.name, {trigger: "sidebar"});
|
||||
|
||||
exports.clear_and_hide_search();
|
||||
clear_and_hide_search();
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
$("#clear_search_stream_button").on("click", exports.clear_search);
|
||||
$("#clear_search_stream_button").on("click", clear_search);
|
||||
|
||||
$("#streams_header")
|
||||
.expectOne()
|
||||
.on("click", (e) => {
|
||||
exports.toggle_filter_displayed(e);
|
||||
toggle_filter_displayed(e);
|
||||
});
|
||||
|
||||
// check for user scrolls on streams list for first time
|
||||
|
@ -530,12 +530,12 @@ exports.set_event_handlers = function () {
|
|||
$(this).off("scroll");
|
||||
});
|
||||
|
||||
exports.stream_cursor = new ListCursor({
|
||||
stream_cursor = new ListCursor({
|
||||
list: {
|
||||
scroll_container_sel: "#stream-filters-container",
|
||||
find_li(opts) {
|
||||
const stream_id = opts.key;
|
||||
const li = exports.get_stream_li(stream_id);
|
||||
const li = get_stream_li(stream_id);
|
||||
return li;
|
||||
},
|
||||
first_key: stream_sort.first_stream_id,
|
||||
|
@ -555,59 +555,59 @@ exports.set_event_handlers = function () {
|
|||
return true;
|
||||
},
|
||||
up_arrow() {
|
||||
exports.stream_cursor.prev();
|
||||
stream_cursor.prev();
|
||||
return true;
|
||||
},
|
||||
down_arrow() {
|
||||
exports.stream_cursor.next();
|
||||
stream_cursor.next();
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
$search_input.on("click", focus_stream_filter);
|
||||
$search_input.on("focusout", () => exports.stream_cursor.clear());
|
||||
$search_input.on("focusout", () => stream_cursor.clear());
|
||||
$search_input.on("input", update_streams_for_search);
|
||||
};
|
||||
}
|
||||
|
||||
exports.searching = function () {
|
||||
export function searching() {
|
||||
return $(".stream-list-filter").expectOne().is(":focus");
|
||||
};
|
||||
}
|
||||
|
||||
exports.escape_search = function () {
|
||||
export function escape_search() {
|
||||
const filter = $(".stream-list-filter").expectOne();
|
||||
if (filter.val() === "") {
|
||||
exports.clear_and_hide_search();
|
||||
clear_and_hide_search();
|
||||
return;
|
||||
}
|
||||
filter.val("");
|
||||
update_streams_for_search();
|
||||
};
|
||||
}
|
||||
|
||||
exports.clear_search = function (e) {
|
||||
export function clear_search(e) {
|
||||
e.stopPropagation();
|
||||
const filter = $(".stream-list-filter").expectOne();
|
||||
if (filter.val() === "") {
|
||||
exports.clear_and_hide_search();
|
||||
clear_and_hide_search();
|
||||
return;
|
||||
}
|
||||
filter.val("");
|
||||
filter.trigger("blur");
|
||||
update_streams_for_search();
|
||||
};
|
||||
}
|
||||
|
||||
exports.show_search_section = function () {
|
||||
export function show_search_section() {
|
||||
$(".stream_search_section").expectOne().removeClass("notdisplayed");
|
||||
resize.resize_stream_filters_container();
|
||||
};
|
||||
}
|
||||
|
||||
exports.hide_search_section = function () {
|
||||
export function hide_search_section() {
|
||||
$(".stream_search_section").expectOne().addClass("notdisplayed");
|
||||
resize.resize_stream_filters_container();
|
||||
};
|
||||
}
|
||||
|
||||
exports.initiate_search = function () {
|
||||
exports.show_search_section();
|
||||
export function initiate_search() {
|
||||
show_search_section();
|
||||
|
||||
const filter = $(".stream-list-filter").expectOne();
|
||||
|
||||
|
@ -621,31 +621,31 @@ exports.initiate_search = function () {
|
|||
}
|
||||
filter.trigger("focus");
|
||||
|
||||
exports.stream_cursor.reset();
|
||||
};
|
||||
stream_cursor.reset();
|
||||
}
|
||||
|
||||
exports.clear_and_hide_search = function () {
|
||||
export function clear_and_hide_search() {
|
||||
const filter = $(".stream-list-filter");
|
||||
if (filter.val() !== "") {
|
||||
filter.val("");
|
||||
update_streams_for_search();
|
||||
}
|
||||
exports.stream_cursor.clear();
|
||||
stream_cursor.clear();
|
||||
filter.trigger("blur");
|
||||
|
||||
exports.hide_search_section();
|
||||
};
|
||||
hide_search_section();
|
||||
}
|
||||
|
||||
exports.toggle_filter_displayed = function (e) {
|
||||
export function toggle_filter_displayed(e) {
|
||||
if ($(".stream_search_section.notdisplayed").length === 0) {
|
||||
exports.clear_and_hide_search();
|
||||
clear_and_hide_search();
|
||||
} else {
|
||||
exports.initiate_search();
|
||||
initiate_search();
|
||||
}
|
||||
e.preventDefault();
|
||||
};
|
||||
}
|
||||
|
||||
exports.scroll_stream_into_view = function (stream_li) {
|
||||
export function scroll_stream_into_view(stream_li) {
|
||||
const container = $("#stream-filters-container");
|
||||
|
||||
if (stream_li.length !== 1) {
|
||||
|
@ -654,21 +654,21 @@ exports.scroll_stream_into_view = function (stream_li) {
|
|||
}
|
||||
|
||||
scroll_util.scroll_element_into_container(stream_li, container);
|
||||
};
|
||||
}
|
||||
|
||||
exports.maybe_scroll_narrow_into_view = function () {
|
||||
export function maybe_scroll_narrow_into_view() {
|
||||
// we don't want to interfere with user scrolling once the page loads
|
||||
if (has_scrolled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stream_li = exports.get_current_stream_li();
|
||||
const stream_li = get_current_stream_li();
|
||||
if (stream_li) {
|
||||
exports.scroll_stream_into_view(stream_li);
|
||||
scroll_stream_into_view(stream_li);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.get_current_stream_li = function () {
|
||||
export function get_current_stream_li() {
|
||||
const stream_id = topic_list.active_stream_id();
|
||||
|
||||
if (!stream_id) {
|
||||
|
@ -676,7 +676,7 @@ exports.get_current_stream_li = function () {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const stream_li = exports.get_stream_li(stream_id);
|
||||
const stream_li = get_stream_li(stream_id);
|
||||
|
||||
if (!stream_li) {
|
||||
// This code path shouldn't ever be reached.
|
||||
|
@ -685,6 +685,4 @@ exports.get_current_stream_li = function () {
|
|||
}
|
||||
|
||||
return stream_li;
|
||||
};
|
||||
|
||||
window.stream_list = exports;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as message_util from "./message_util";
|
|||
import * as message_viewport from "./message_viewport";
|
||||
import * as navigate from "./navigate";
|
||||
import * as overlays from "./overlays";
|
||||
import * as stream_list from "./stream_list";
|
||||
|
||||
export function update_is_muted(sub, value) {
|
||||
sub.is_muted = value;
|
||||
|
|
|
@ -22,6 +22,7 @@ const search_util = require("./search_util");
|
|||
const stream_create = require("./stream_create");
|
||||
const stream_data = require("./stream_data");
|
||||
const stream_edit = require("./stream_edit");
|
||||
const stream_list = require("./stream_list");
|
||||
const stream_muting = require("./stream_muting");
|
||||
const stream_ui_updates = require("./stream_ui_updates");
|
||||
const typeahead_helper = require("./typeahead_helper");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as popovers from "./popovers";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as topic_list from "./topic_list";
|
||||
|
||||
let zoomed_in = false;
|
||||
|
|
|
@ -56,6 +56,7 @@ import * as starred_messages from "./starred_messages";
|
|||
import * as stream_color from "./stream_color";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_edit from "./stream_edit";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as timerender from "./timerender";
|
||||
import * as topic_list from "./topic_list";
|
||||
import * as topic_zoom from "./topic_zoom";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as activity from "./activity";
|
||||
import * as notifications from "./notifications";
|
||||
import * as pm_list from "./pm_list";
|
||||
import * as stream_list from "./stream_list";
|
||||
import * as top_left_corner from "./top_left_corner";
|
||||
import * as topic_list from "./topic_list";
|
||||
import * as unread from "./unread";
|
||||
|
|
Loading…
Reference in New Issue