Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
left_sidebar: Show channel folders in left sidebar.
Evy Kassirere6fecfc8eb03
diff --git a/web/src/channel_folders.ts b/web/src/channel_folders.tsindex a25a1a995ca..7d6b66e69f7 100644--- a/web/src/channel_folders.ts+++ b/web/src/channel_folders.ts@@ -37,6 +37,10 @@ export function get_channel_folders(include_archived = false): ChannelFolder[] {});}+export function get_all_folder_ids(): number[] {+ return [...channel_folder_by_id_dict.keys()];+}+export function is_valid_folder_id(folder_id: number): boolean {return channel_folder_by_id_dict.has(folder_id);}diff --git a/web/src/left_sidebar_navigation_area.ts b/web/src/left_sidebar_navigation_area.tsindex 0b73dc398ce..075da59d8ed 100644--- a/web/src/left_sidebar_navigation_area.ts+++ b/web/src/left_sidebar_navigation_area.ts@@ -2,6 +2,7 @@ import $ from "jquery";import _ from "lodash";import assert from "minimalistic-assert";+import * as channel_folders from "./channel_folders.ts";import type {Filter} from "./filter.ts";import {localstorage} from "./localstorage.ts";import * as message_reminder from "./message_reminder.ts";@@ -110,6 +111,7 @@ export function update_dom_with_unread_counts(unmuted: 0,muted: 0,};+ const folder_unread_counts = new Map<number, SectionUnreadCount>();const normal_section_unread_counts: SectionUnreadCount = {unmuted: 0,muted: 0,@@ -125,6 +127,16 @@ export function update_dom_with_unread_counts(if (sub.pin_to_top) {pinned_unread_counts.unmuted += stream_count_info.unmuted_count;pinned_unread_counts.muted += stream_count_info.muted_count;+ } else if (sub.folder_id !== null) {+ const unread_counts = folder_unread_counts.get(sub.folder_id) ?? {+ unmuted: 0,+ muted: 0,+ };+ if (!folder_unread_counts.has(sub.folder_id)) {+ folder_unread_counts.set(sub.folder_id, unread_counts);+ }+ unread_counts.unmuted += stream_count_info.unmuted_count;+ unread_counts.muted += stream_count_info.muted_count;} else if (stream_list_sort.has_recent_activity(sub)) {normal_section_unread_counts.unmuted += stream_count_info.unmuted_count;normal_section_unread_counts.muted += stream_count_info.muted_count;@@ -167,6 +179,15 @@ export function update_dom_with_unread_counts(inactive_section_unread_counts.muted,);+ for (const folder_id of channel_folders.get_all_folder_ids()) {+ const unread_counts = folder_unread_counts.get(folder_id);+ update_section_unread_count(+ $(`#stream-list-${folder_id}-container .stream-list-subsection-header`),+ unread_counts?.unmuted ?? 0,+ unread_counts?.muted ?? 0,+ );+ }+if (!skip_animations) {animate_mention_changes($mentioned_li, counts.mentioned_message_count);}diff --git a/web/src/stream_list.ts b/web/src/stream_list.tsindex c39ee65cd53..09e3e9b5dcb 100644--- a/web/src/stream_list.ts+++ b/web/src/stream_list.ts@@ -270,8 +270,7 @@ export let stream_list_section_container_html = function (return render_stream_list_section_container({id: section.id,section_title: section.section_title,- show_plus_icon:- can_create_streams && !["pinned-streams", "dormant-streams"].includes(section.id),+ plus_icon_url: can_create_streams ? get_section_channel_plus_icon_url(section) : undefined,});};@@ -281,6 +280,15 @@ export function rewire_stream_list_section_container_html(stream_list_section_container_html = value;}+function get_section_channel_plus_icon_url(section: StreamListSection): string | undefined {+ if (section.id === "normal-streams") {+ return "#channels/new";+ } else if (!["pinned-streams", "dormant-streams"].includes(section.id)) {+ return `#channels/folders/${section.id}/new`;+ }+ return undefined;+}+export function build_stream_list(force_rerender: boolean): void {// The stream list in the left sidebar contains 3 sections:// pinned, normal, and dormant streams, with headings above them@@ -289,8 +297,7 @@ export function build_stream_list(force_rerender: boolean): void {// Within the first two sections, muted streams are sorted to the// bottom; we skip that for dormant streams to simplify discovery.//- // The main logic to build the list is in stream_list_sort.ts, and- // we get five lists of streams (pinned/normal/muted_pinned/muted_normal/dormant).+ // The main logic to build the list is in stream_list_sort.tsconst streams = stream_data.subscribed_stream_ids();const stream_groups = stream_list_sort.sort_groups(streams, get_search_term());diff --git a/web/src/stream_list_sort.ts b/web/src/stream_list_sort.tsindex 4e0ba29dad6..598d570c5aa 100644--- a/web/src/stream_list_sort.ts+++ b/web/src/stream_list_sort.ts@@ -1,5 +1,6 @@import assert from "minimalistic-assert";+import * as channel_folders from "./channel_folders.ts";import {$t} from "./i18n.ts";import * as settings_config from "./settings_config.ts";import * as stream_data from "./stream_data.ts";@@ -123,7 +124,7 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLi};const normal_section: StreamListSection = {id: "normal-streams",- section_title: $t({defaultMessage: "ACTIVE CHANNELS"}),+ section_title: $t({defaultMessage: "OTHER CHANNELS"}),streams: [],muted_streams: [],};@@ -134,6 +135,8 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLimuted_streams: [], // Not used for the dormant section};+ const folder_sections = new Map<number, StreamListSection>();+for (const stream_id of stream_ids) {const sub = sub_store.get(stream_id);assert(sub);@@ -146,6 +149,23 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLi} else {pinned_section.streams.push(stream_id);}+ } else if (sub.folder_id) {+ const folder = channel_folders.get_channel_folder_by_id(sub.folder_id);+ let section = folder_sections.get(sub.folder_id);+ if (!section) {+ section = {+ id: sub.folder_id.toString(),+ section_title: folder.name.toUpperCase(),+ streams: [],+ muted_streams: [],+ };+ folder_sections.set(sub.folder_id, section);+ }+ if (sub.is_muted) {+ section.muted_streams.push(stream_id);+ } else {+ section.streams.push(stream_id);+ }} else if (is_normal(sub)) {if (sub.is_muted) {normal_section.muted_streams.push(stream_id);@@ -157,8 +177,21 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLi}}+ const folder_sections_sorted = [...folder_sections.values()].sort((section_a, section_b) =>+ util.strcmp(section_a.section_title, section_b.section_title),+ );+// This needs to have the same ordering as the order they're displayed in the sidebar.- const new_sections = [pinned_section, normal_section, dormant_section];+ const new_sections = [pinned_section, ...folder_sections_sorted, normal_section, dormant_section];++ // Don't call it "other channels" if there's nothing above it.+ if (+ folder_sections_sorted.length === 0 &&+ pinned_section.streams.length === 0 &&+ pinned_section.muted_streams.length === 0+ ) {+ normal_section.section_title = $t({defaultMessage: "CHANNELS"});+ }for (const section of new_sections) {section.streams.sort(compare_function);diff --git a/web/src/stream_settings_ui.ts b/web/src/stream_settings_ui.tsindex 0c6cb96a89b..9a4457f7a5b 100644--- a/web/src/stream_settings_ui.ts+++ b/web/src/stream_settings_ui.ts@@ -40,6 +40,7 @@ import * as stream_edit from "./stream_edit.ts";import * as stream_edit_subscribers from "./stream_edit_subscribers.ts";import * as stream_edit_toggler from "./stream_edit_toggler.ts";import * as stream_list from "./stream_list.ts";+import * as stream_list_sort from "./stream_list_sort.ts";import * as stream_settings_api from "./stream_settings_api.ts";import * as stream_settings_components from "./stream_settings_components.ts";import * as stream_settings_containers from "./stream_settings_containers.ts";@@ -243,6 +244,13 @@ export function update_is_default_stream(): void {export function update_channel_folder(sub: StreamSubscription, folder_id: number | null): void {stream_data.update_channel_folder(sub, folder_id);stream_ui_updates.update_channel_folder_dropdown(sub);+ stream_list.build_stream_list(false);+ const $stream_li = stream_list.get_stream_li(sub.stream_id);+ if ($stream_li) {+ stream_list.scroll_stream_into_view($stream_li);+ }+ const section_id = stream_list_sort.current_section_id_for_stream(sub.stream_id);+ stream_list.maybe_hide_topic_bracket(section_id);}export function update_subscribers_ui(sub: StreamSubscription): void {diff --git a/web/templates/stream_list_section_container.hbs b/web/templates/stream_list_section_container.hbsindex 22a0220a664..130a4bc1cea 100644--- a/web/templates/stream_list_section_container.hbs+++ b/web/templates/stream_list_section_container.hbs@@ -4,8 +4,8 @@<h4 class="left-sidebar-title">{{section_title}}</h4>- {{#if show_plus_icon}}- <a href="#channels/new" class="add-stream-tooltip add-stream-icon-container hidden-for-spectators" data-tippy-content="{{t 'Create a channel' }}">+ {{#if plus_icon_url}}+ <a href="{{plus_icon_url}}" class="add-stream-tooltip add-stream-icon-container hidden-for-spectators" data-tippy-content="{{t 'Create a channel' }}"><i class="add_stream_icon zulip-icon zulip-icon-square-plus" aria-hidden="true" ></i></a>{{/if}}diff --git a/web/tests/stream_list_sort.test.cjs b/web/tests/stream_list_sort.test.cjsindex 132c1d65d1b..045754bc5c4 100644--- a/web/tests/stream_list_sort.test.cjs+++ b/web/tests/stream_list_sort.test.cjs@@ -110,7 +110,7 @@ test("no_subscribed_streams", () => {{id: "normal-streams",muted_streams: [],- section_title: "translated: ACTIVE CHANNELS",+ section_title: "translated: CHANNELS",streams: [],},{