Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp
28.9 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later

import {Routes} from '@app/app/Routes';
import Accessibility from '@app/features/accessibility/state/Accessibility';
import {GenericErrorModal} from '@app/features/app/components/alerts/GenericErrorModal';
import {ChannelItem} from '@app/features/app/components/layout/ChannelItem';
import channelItemStyles from '@app/features/app/components/layout/ChannelItem.module.css';
import {ChannelItemContent} from '@app/features/app/components/layout/ChannelItemContent';
import styles from '@app/features/app/components/layout/ChannelListContent.module.css';
import {
	CollapsedCategoryVoiceParticipants,
	CollapsedChannelAvatarStack,
} from '@app/features/app/components/layout/CollapsedCategoryVoiceParticipants';
import {GenericChannelItem} from '@app/features/app/components/layout/GenericChannelItem';
import {GuildDetachedBanner} from '@app/features/app/components/layout/GuildDetachedBanner';
import {NullSpaceDropIndicator} from '@app/features/app/components/layout/NullSpaceDropIndicator';
import {ScrollIndicatorOverlay} from '@app/features/app/components/layout/ScrollIndicatorOverlay';
import {type DragItem, DragItemType, type DropResult} from '@app/features/app/components/layout/types/DndTypes';
import {
	shouldShowCategoryWhenHidingMutedChannels,
	shouldShowChannelInCollapsedCategory,
	shouldShowChannelWhenHidingMutedChannels,
} from '@app/features/app/components/layout/utils/ChannelListVisibility';
import {createChannelMoveOperation} from '@app/features/app/components/layout/utils/ChannelMoveOperation';
import {organizeChannels} from '@app/features/app/components/layout/utils/ChannelOrganization';
import {
	type ChannelUnreadState,
	getChannelUnreadState,
} from '@app/features/app/components/layout/utils/ChannelUnreadState';
import {VoiceParticipantsList} from '@app/features/app/components/layout/VoiceParticipantsList';
import {
	type RememberedSkeletonGuildChannelGroup,
	type RememberedSkeletonGuildChannelRow,
	reportSkeletonGuildChannelList,
} from '@app/features/app/components/skeleton/SkeletonLayoutMemory';
import type {GuildBannerPresentation} from '@app/features/app/hooks/useGuildBannerPresentation';
import {useRovingFocusList} from '@app/features/app/hooks/useRovingFocusList';
import {
	measureSkeletonTextWidthPx,
	useSkeletonLayoutReport,
} from '@app/features/app/hooks/useSkeletonLayoutMemoryCapture';
import type {Channel} from '@app/features/channel/models/Channel';
import Channels from '@app/features/channel/state/Channels';
import {hasForumUnread} from '@app/features/forum/state/ForumReadState';
import * as GuildCommands from '@app/features/guild/commands/GuildCommands';
import type {Guild} from '@app/features/guild/models/Guild';
import {MEMBERS_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import {isKeyboardActivationKey} from '@app/features/input/utils/KeyboardUtils';
import * as RouterUtils from '@app/features/navigation/utils/RouterUtils';
import Permission from '@app/features/permissions/state/Permission';
import {useLocation} from '@app/features/platform/components/router/RouterReact';
import {failureCode} from '@app/features/platform/utils/ResponseInspection';
import ReadStates from '@app/features/read_state/state/ReadStates';
import {remFromPx} from '@app/features/theme/layout/RemFromPx';
import {SidebarThreadList} from '@app/features/threads/components/SidebarThreadList';
import ThreadGuilds from '@app/features/threads/state/ThreadGuilds';
import {getSidebarThreadActivity} from '@app/features/threads/utils/SidebarThreadActivity';
import {ChannelListContextMenu} from '@app/features/ui/action_menu/ChannelListContextMenu';
import * as ContextMenuCommands from '@app/features/ui/commands/ContextMenuCommands';
import * as DimensionCommands from '@app/features/ui/commands/DimensionCommands';
import * as ModalCommands from '@app/features/ui/commands/ModalCommands';
import type {ScrollerHandle} from '@app/features/ui/components/Scroller';
import {Scroller} from '@app/features/ui/components/Scroller';
import {useDragAutoScroll} from '@app/features/ui/hooks/useDragAutoScroll';
import Dimension from '@app/features/ui/state/Dimension';
import KeyboardMode from '@app/features/ui/state/KeyboardMode';
import MobileLayout from '@app/features/ui/state/MobileLayout';
import * as UserGuildSettingsCommands from '@app/features/user/commands/UserGuildSettingsCommands';
import UserGuildSettings from '@app/features/user/state/UserGuildSettings';
import MediaEngine from '@app/features/voice/engine/MediaEngineFacade';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {Permissions} from '@fluxer/constants/src/ChannelConstants';
import {MAX_CHANNELS_PER_CATEGORY} from '@fluxer/constants/src/LimitConstants';
import {msg} from '@lingui/core/macro';
import {useLingui} from '@lingui/react/macro';
import {UsersIcon} from '@phosphor-icons/react';
import {clsx} from 'clsx';
import type {MotionValue} from 'framer-motion';
import {observer} from 'mobx-react-lite';
import React, {useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
import {useDragLayer} from 'react-dnd';

const CATEGORY_FULL_DESCRIPTOR = msg({
	message: 'Category full',
	comment: 'Short label in the app layout channel list content.',
});
const THIS_CATEGORY_ALREADY_CONTAINS_THE_MAXIMUM_OF_CHANNELS_DESCRIPTOR = msg({
	message: 'This category already contains the maximum of {maxChannelsPerCategory} channels.',
	comment:
		'Modal body shown when a category cannot accept another channel because the per-category limit is reached. Limit is interpolated.',
});
const CHANNELS_DESCRIPTOR = msg({
	message: '{guildName} channels',
	comment: 'Short label in the app layout channel list content. Preserve {guildName}; it is inserted by code.',
});
const MEMBERS_SELECTED_DESCRIPTOR = msg({
	message: 'Members, selected',
	comment: 'Short label in the app layout channel list content.',
});
const NEW_MESSAGES_DESCRIPTOR = msg({
	message: 'New messages',
	comment: 'Short label in the app layout channel list content.',
});
const MEMBERS_PAGE_PERMISSIONS =
	Permissions.MANAGE_GUILD |
	Permissions.MANAGE_ROLES |
	Permissions.MANAGE_NICKNAMES |
	Permissions.BAN_MEMBERS |
	Permissions.MODERATE_MEMBERS |
	Permissions.KICK_MEMBERS;
const EMPTY_ARRAY: ReadonlyArray<never> = Object.freeze([]);

interface ResolvedChannelGroup {
	readonly key: string;
	readonly category: Channel | undefined;
	readonly isCollapsed: boolean;
	readonly connectedChannelInGroup: boolean;
	readonly filteredVoiceChannels: Array<Channel>;
	readonly visibleTextChannels: ReadonlyArray<Channel>;
	readonly visibleVoiceChannels: ReadonlyArray<Channel>;
	readonly showTextChannels: boolean;
	readonly showVoiceChannels: boolean;
}

function createChannelListProjectionKey(
	groups: ReadonlyArray<ResolvedChannelGroup>,
	membersRowVisible: boolean,
): string {
	const groupKeys = groups.map((group) => {
		const channelKeys = [...group.visibleTextChannels, ...group.visibleVoiceChannels].map(
			(channel) => `${channel.id}~${channel.name}`,
		);
		return `${group.category?.id ?? ''}~${group.category?.name ?? ''}~${group.isCollapsed}~${channelKeys.join(',')}`;
	});
	return `${membersRowVisible}|${groupKeys.join('|')}`;
}

function createRememberedChannelGroups(
	groups: ReadonlyArray<ResolvedChannelGroup>,
	container: HTMLElement | null,
): ReadonlyArray<RememberedSkeletonGuildChannelGroup> {
	const categoryNameElements = container?.querySelectorAll(`.${channelItemStyles.categoryName}`);
	const channelNameElements = container?.querySelectorAll(`.${channelItemStyles.channelName}`);
	let categoryNameIndex = 0;
	let channelNameIndex = 0;
	const readNextChannelWidth = (): number => {
		const width = measureSkeletonTextWidthPx(channelNameElements?.item(channelNameIndex) ?? null);
		channelNameIndex += 1;
		return width;
	};
	return groups.map((group) => {
		let categoryNameWidthPx = measureSkeletonTextWidthPx(null);
		if (group.category != null) {
			categoryNameWidthPx = measureSkeletonTextWidthPx(categoryNameElements?.item(categoryNameIndex) ?? null);
			categoryNameIndex += 1;
		}
		const channels: Array<RememberedSkeletonGuildChannelRow> = [];
		for (const _textChannel of group.visibleTextChannels) {
			channels.push({voice: false, nameWidthPx: readNextChannelWidth()});
		}
		for (const _voiceChannel of group.visibleVoiceChannels) {
			channels.push({voice: true, nameWidthPx: readNextChannelWidth()});
		}
		return {
			categoryHeaderVisible: group.category != null,
			collapsed: group.isCollapsed,
			categoryNameWidthPx,
			channels,
		};
	});
}
interface ChannelListContentProps {
	readonly guild: Guild;
	readonly scrollY: MotionValue<number>;
	readonly banner: GuildBannerPresentation;
}
export const ChannelListContent = observer(({guild, scrollY, banner}: ChannelListContentProps) => {
	const threadsActive = ThreadGuilds.isActive(guild.id);
	const {i18n} = useLingui();
	const channels = Channels.getGuildChannels(guild.id);
	const location = useLocation();
	const userGuildSettings = UserGuildSettings.getSettingsForScope(guild.id);
	const isDraggingAnything = useDragLayer((monitor) => {
		if (!monitor.isDragging()) return false;
		const itemType = monitor.getItemType();
		return (
			itemType === DragItemType.CHANNEL ||
			itemType === DragItemType.CATEGORY ||
			itemType === DragItemType.VOICE_PARTICIPANT
		);
	});
	const [activeDragItem, setActiveDragItem] = useState<DragItem | null>(null);
	const scrollerRef = useRef<ScrollerHandle>(null);
	const showIntegratedBanner = banner.collapsible;
	const channelGroupsContainerRef = useRef<HTMLDivElement | null>(null);
	const stickToBottomRef = useRef(false);
	const pendingScrollTopRef = useRef<number | null>(null);
	const scrollPersistRafRef = useRef<number | null>(null);
	const channelListNavigationRef = useRovingFocusList<HTMLDivElement>({
		focusableSelector: '[data-channel-list-focus-item="true"]',

		enabled: KeyboardMode.keyboardModeEnabled,
		restoreFocusOnWindowFocus: false,
	});
	const connectedChannelId = MediaEngine.channelId;
	const hideMutedChannels = userGuildSettings?.hide_muted_channels ?? false;
	const showFadedUnreadOnMutedChannels = Accessibility.showFadedUnreadOnMutedChannels;
	const isMobile = MobileLayout.enabled;
	const canViewMembers =
		!isMobile && ((Permission.getGuildPermissions(guild.id) ?? 0n) & MEMBERS_PAGE_PERMISSIONS) !== 0n;
	const guildPrefix = `/channels/${guild.id}/`;
	let selectedChannelInGuildId: string | null = null;
	let isMembersSelected = false;
	if (location.pathname.startsWith(guildPrefix)) {
		const tail = location.pathname.slice(guildPrefix.length);
		const slash = tail.indexOf('/');
		const segment = slash === -1 ? tail : tail.slice(0, slash);
		if (segment === 'members') {
			isMembersSelected = true;
		} else if (segment.length > 0) {
			selectedChannelInGuildId = segment;
		}
	}
	const handleMembersClick = useCallback(() => {
		RouterUtils.transitionTo(Routes.guildMembers(guild.id));
	}, [guild.id]);
	const handleMembersKeyDown = useCallback(
		(event: React.KeyboardEvent) => {
			if (!isKeyboardActivationKey(event.key)) return;
			event.preventDefault();
			handleMembersClick();
		},
		[handleMembersClick],
	);
	const collapsedCategories = useMemo(() => {
		const overrides = userGuildSettings?.channel_overrides;
		if (!overrides) return null;
		let collapsed: Set<string> | null = null;
		for (const channelId in overrides) {
			if (overrides[channelId as keyof typeof overrides].collapsed) {
				if (!collapsed) collapsed = new Set<string>();
				collapsed.add(channelId);
			}
		}
		return collapsed;
	}, [userGuildSettings]);
	const toggleCategory = useCallback(
		(categoryId: string) => {
			UserGuildSettingsCommands.toggleChannelCollapsed(guild.id, categoryId);
		},
		[guild.id],
	);
	const channelGroups = useMemo(() => organizeChannels(channels), [channels]);
	const showTrailingDropZone = channelGroups.length > 0;
	const channelIndicatorDependencies = useMemo(
		() => [channels.length, ReadStates.version, userGuildSettings, hideMutedChannels, showFadedUnreadOnMutedChannels],
		[channels.length, ReadStates.version, userGuildSettings, hideMutedChannels, showFadedUnreadOnMutedChannels],
	);
	const getChannelScrollContainer = useCallback(() => scrollerRef.current?.getViewportElement() ?? null, [scrollerRef]);
	useDragAutoScroll({active: isDraggingAnything, getScrollElement: getChannelScrollContainer});
	const handleChannelDrop = useCallback(
		(item: DragItem, result: DropResult) => {
			if (!result) return;
			const guildChannels = Channels.getGuildChannels(guild.id);
			const operation = createChannelMoveOperation({
				channels: guildChannels,
				dragItem: item,
				dropResult: result,
			});
			if (!operation) return;
			void (async () => {
				try {
					await GuildCommands.moveChannel(guild.id, operation);
				} catch (error) {
					if (failureCode(error) === APIErrorCodes.MAX_CATEGORY_CHANNELS) {
						ModalCommands.push(
							ModalCommands.modal(() => (
								<GenericErrorModal
									title={i18n._(CATEGORY_FULL_DESCRIPTOR)}
									message={i18n._(THIS_CATEGORY_ALREADY_CONTAINS_THE_MAXIMUM_OF_CHANNELS_DESCRIPTOR, {
										maxChannelsPerCategory: MAX_CHANNELS_PER_CATEGORY,
									})}
									data-flx="app.channel-list-content.handle-channel-drop.confirm-modal"
								/>
							)),
						);
						return;
					}
					throw error;
				}
			})();
		},
		[guild.id],
	);
	const handleScroll = useCallback(
		(event: React.UIEvent<HTMLDivElement>) => {
			const scrollTop = event.currentTarget.scrollTop;
			const scrollHeight = event.currentTarget.scrollHeight;
			const offsetHeight = event.currentTarget.offsetHeight;
			stickToBottomRef.current = scrollHeight - (scrollTop + offsetHeight) <= 8;
			scrollY.set(scrollTop);
			pendingScrollTopRef.current = scrollTop;
			if (scrollPersistRafRef.current != null) return;
			scrollPersistRafRef.current = requestAnimationFrame(() => {
				scrollPersistRafRef.current = null;
				const pendingScrollTop = pendingScrollTopRef.current;
				if (pendingScrollTop == null) return;
				DimensionCommands.updateChannelListScroll(guild.id, pendingScrollTop);
			});
		},
		[scrollY, guild.id],
	);
	useEffect(() => {
		return () => {
			if (scrollPersistRafRef.current != null) {
				cancelAnimationFrame(scrollPersistRafRef.current);
				scrollPersistRafRef.current = null;
			}
		};
	}, [guild.id]);
	const handleResize = useCallback((_entry: ResizeObserverEntry, _type: 'container' | 'content') => {
		if (stickToBottomRef.current && scrollerRef.current) {
			scrollerRef.current.jumpToEndEdge({animate: false});
		}
	}, []);
	useLayoutEffect(() => {
		const guildDimensions = Dimension.guildDimensionsFor(guild.id);
		if (guildDimensions.scrollTo) {
			const element = document.querySelector(`[data-channel-id="${guildDimensions.scrollTo}"]`);
			if (element && scrollerRef.current) {
				scrollerRef.current.revealElement({node: element as HTMLElement, preferStartEdge: false});
			}
			DimensionCommands.clearChannelListScrollTo(guild.id);
		} else if (guildDimensions.scrollTop && guildDimensions.scrollTop > 0 && scrollerRef.current) {
			scrollerRef.current.scrollTo({to: guildDimensions.scrollTop, animate: false});
		}
		scrollY.set(scrollerRef.current?.getViewportElement()?.scrollTop ?? 0);
	}, [guild.id, scrollY]);
	const handleContextMenu = useCallback(
		(event: React.MouseEvent) => {
			ContextMenuCommands.openFromEvent(event, ({onClose}) => (
				<ChannelListContextMenu
					guild={guild}
					onClose={onClose}
					data-flx="app.channel-list-content.handle-context-menu.channel-list-context-menu"
				/>
			));
		},
		[guild],
	);
	const getUnreadStateInChannel = (channelId: string): ChannelUnreadState => {
		const channel = Channels.getChannel(channelId);
		const unreadCount = ReadStates.getUnreadCount(channelId);
		const hasUnread = channel?.isThreadOnly() ? hasForumUnread(channel) : ReadStates.hasUnread(channelId);
		const mentionCount = ReadStates.getMentionCount(channelId);
		const isMuted = UserGuildSettings.isChannelDirectlyMuted(guild.id, channelId);
		const unreadBadgesLevel = channel
			? UserGuildSettings.resolvedUnreadBadgesLevel({
					id: channel.id,
					guildId: channel.guildId ?? undefined,
					parentId: channel.parentId ?? undefined,
					type: channel.type,
				})
			: null;
		return getChannelUnreadState({
			hasUnread,
			unreadCount,
			mentionCount,
			isMuted,
			showFadedUnreadOnMutedChannels,
			unreadBadgesLevel,
		});
	};
	const resolvedGroups: Array<ResolvedChannelGroup> = [];
	for (const group of channelGroups) {
		const isCollapsed = group.category ? (collapsedCategories?.has(group.category.id) ?? false) : false;
		const isNullSpace = !group.category;
		const isCategoryMuted = group.category
			? UserGuildSettings.isChannelDirectlyMuted(guild.id, group.category.id)
			: false;
		let filteredTextChannels: Array<Channel>;
		let filteredVoiceChannels: Array<Channel>;
		if (hideMutedChannels) {
			filteredTextChannels = [];
			for (const ch of group.textChannels) {
				const isChannelMuted = UserGuildSettings.isChannelDirectlyMuted(guild.id, ch.id);
				const isMuted = isCategoryMuted || isChannelMuted;
				if (
					shouldShowChannelWhenHidingMutedChannels({
						isCategoryMuted,
						isChannelMuted,
						isSelected: ch.id === selectedChannelInGuildId,
						isConnected: false,
						hasVisibleUnread: isMuted && getUnreadStateInChannel(ch.id).hasVisibleUnread,
					})
				) {
					filteredTextChannels.push(ch);
				}
			}
			filteredVoiceChannels = [];
			for (const ch of group.voiceChannels) {
				const isChannelMuted = UserGuildSettings.isChannelDirectlyMuted(guild.id, ch.id);
				const isMuted = isCategoryMuted || isChannelMuted;
				if (
					shouldShowChannelWhenHidingMutedChannels({
						isCategoryMuted,
						isChannelMuted,
						isSelected: ch.id === selectedChannelInGuildId,
						isConnected: ch.id === connectedChannelId,
						hasVisibleUnread: isMuted && getUnreadStateInChannel(ch.id).hasVisibleUnread,
					})
				) {
					filteredVoiceChannels.push(ch);
				}
			}
		} else {
			filteredTextChannels = group.textChannels;
			filteredVoiceChannels = group.voiceChannels;
		}
		let visibleTextChannels: ReadonlyArray<Channel> = filteredTextChannels;
		let visibleVoiceChannels: ReadonlyArray<Channel> = filteredVoiceChannels;
		let connectedChannelInGroup = false;
		if (isCollapsed) {
			const showTextSelected = selectedChannelInGuildId;
			const showSet = new Set<string>();
			for (const ch of filteredTextChannels) {
				const unreadState = getUnreadStateInChannel(ch.id);
				const threadActivity = threadsActive ? getSidebarThreadActivity(ch.id) : null;
				if (
					shouldShowChannelInCollapsedCategory({
						isCategoryMuted,
						isSelected: ch.id === showTextSelected,
						isConnected: false,
						hasVisibleUnread: unreadState.hasVisibleUnread || threadActivity?.hasActivity === true,
						hasMentions: unreadState.hasMentions || threadActivity?.hasMentions === true,
					})
				) {
					showSet.add(ch.id);
				}
			}
			if (showSet.size === 0) {
				visibleTextChannels = EMPTY_ARRAY;
			} else if (showSet.size === filteredTextChannels.length) {
				visibleTextChannels = filteredTextChannels;
			} else {
				const next: Array<Channel> = [];
				for (const ch of filteredTextChannels) if (showSet.has(ch.id)) next.push(ch);
				visibleTextChannels = next;
			}
			const voiceSet = new Set<string>();
			if (selectedChannelInGuildId) voiceSet.add(selectedChannelInGuildId);
			if (connectedChannelId) {
				for (const ch of filteredVoiceChannels) {
					if (ch.id === connectedChannelId) {
						connectedChannelInGroup = true;
						voiceSet.add(connectedChannelId);
						break;
					}
				}
			}
			for (const ch of filteredVoiceChannels) {
				const unreadState = getUnreadStateInChannel(ch.id);
				if (
					shouldShowChannelInCollapsedCategory({
						isCategoryMuted,
						isSelected: ch.id === selectedChannelInGuildId,
						isConnected: ch.id === connectedChannelId,
						hasVisibleUnread: unreadState.hasVisibleUnread,
						hasMentions: unreadState.hasMentions,
					})
				) {
					voiceSet.add(ch.id);
				}
			}
			if (voiceSet.size === 0) {
				visibleVoiceChannels = EMPTY_ARRAY;
			} else {
				const next: Array<Channel> = [];
				let connectedRow: Channel | null = null;
				for (const ch of filteredVoiceChannels) {
					if (!voiceSet.has(ch.id)) continue;
					if (ch.id === connectedChannelId) {
						connectedRow = ch;
					} else {
						next.push(ch);
					}
				}
				visibleVoiceChannels = connectedRow ? [connectedRow, ...next] : next;
			}
		}
		if (isNullSpace && filteredTextChannels.length === 0 && filteredVoiceChannels.length === 0) {
			continue;
		}
		if (
			hideMutedChannels &&
			group.category &&
			!shouldShowCategoryWhenHidingMutedChannels({
				hasChannels: group.textChannels.length > 0 || group.voiceChannels.length > 0,
				hasVisibleChannels: filteredTextChannels.length > 0 || filteredVoiceChannels.length > 0,
			})
		) {
			continue;
		}
		resolvedGroups.push({
			key: group.category?.id || 'null-space',
			category: group.category,
			isCollapsed,
			connectedChannelInGroup,
			filteredVoiceChannels,
			visibleTextChannels,
			visibleVoiceChannels,
			showTextChannels: !isCollapsed || visibleTextChannels.length > 0,
			showVoiceChannels: !isCollapsed || visibleVoiceChannels.length > 0,
		});
	}
	useSkeletonLayoutReport(
		() => {
			reportSkeletonGuildChannelList(guild.id, {
				membersRowVisible: canViewMembers,
				groups: createRememberedChannelGroups(resolvedGroups, channelGroupsContainerRef.current),
			});
		},
		`${guild.id}|${createChannelListProjectionKey(resolvedGroups, canViewMembers)}`,
	);
	return (
		<div
			className={styles.channelListScrollerWrapper}
			data-flx="app.channel-list-content.channel-list-scroller-wrapper"
		>
			<Scroller
				ref={scrollerRef}
				className={clsx(styles.channelListScroller, showIntegratedBanner && styles.channelListScrollerOverBanner)}
				onScroll={handleScroll}
				onResize={handleResize}
				key={guild.id}
				data-flx="app.channel-list-content.channel-list-scroller"
			>
				<div
					className={styles.navigationContainer}
					onContextMenu={handleContextMenu}
					role="navigation"
					aria-label={i18n._(CHANNELS_DESCRIPTOR, {guildName: guild.name})}
					ref={channelListNavigationRef}
					data-flx="app.channel-list-content.navigation-container.context-menu"
				>
					{showIntegratedBanner && (
						<div
							ref={banner.hoverRef}
							className={styles.bannerSpacer}
							style={{height: banner.collapseDistance}}
							data-flx="app.channel-list-content.banner-spacer"
						/>
					)}
					<GuildDetachedBanner guild={guild} data-flx="app.channel-list-content.guild-detached-banner" />
					<div className={styles.topDropZone} data-flx="app.channel-list-content.top-drop-zone">
						<NullSpaceDropIndicator
							isDraggingAnything={isDraggingAnything}
							onChannelDrop={handleChannelDrop}
							variant="top"
							data-flx="app.channel-list-content.null-space-drop-indicator"
						/>
					</div>
					{canViewMembers && (
						<>
							<div className={styles.membersSection} data-flx="app.channel-list-content.members-section">
								<GenericChannelItem
									containerClassName={channelItemStyles.container}
									className={clsx(
										channelItemStyles.channelItem,
										channelItemStyles.channelItemRegular,
										isMembersSelected && channelItemStyles.channelItemSelected,
										!isMembersSelected && channelItemStyles.channelItemHoverable,
									)}
									isSelected={isMembersSelected}
									aria-label={isMembersSelected ? i18n._(MEMBERS_SELECTED_DESCRIPTOR) : i18n._(MEMBERS_DESCRIPTOR)}
									aria-current={isMembersSelected ? 'page' : undefined}
									onClick={handleMembersClick}
									onKeyDown={handleMembersKeyDown}
									data-flx="app.channel-list-content.generic-channel-item.members-click"
								>
									<ChannelItemContent
										icon={
											<UsersIcon
												size={remFromPx(20)}
												className={clsx(
													channelItemStyles.channelItemIcon,
													isMembersSelected
														? channelItemStyles.channelItemIconSelected
														: channelItemStyles.channelItemIconUnselected,
												)}
												data-flx="app.channel-list-content.users-icon"
											/>
										}
										name={i18n._(MEMBERS_DESCRIPTOR)}
										data-flx="app.channel-list-content.channel-item-content"
									/>
								</GenericChannelItem>
							</div>
							<div className={styles.membersSeparator} data-flx="app.channel-list-content.members-separator" />
						</>
					)}
					<div
						ref={channelGroupsContainerRef}
						className={styles.channelGroupsContainer}
						data-flx="app.channel-list-content.channel-groups-container"
					>
						{resolvedGroups.map((group) => (
							<div key={group.key} className={styles.channelGroup} data-flx="app.channel-list-content.channel-group">
								{group.category && (
									<ChannelItem
										guild={guild}
										channel={group.category}
										isCollapsed={group.isCollapsed}
										onToggle={() => toggleCategory(group.category!.id)}
										isDraggingAnything={isDraggingAnything}
										activeDragItem={activeDragItem}
										onChannelDrop={handleChannelDrop}
										onDragStateChange={setActiveDragItem}
										isSelectedByPath={selectedChannelInGuildId === group.category.id}
										isOnMembersRoute={isMembersSelected}
										data-flx="app.channel-list-content.channel-item"
									/>
								)}
								{group.isCollapsed && group.category && !group.connectedChannelInGroup && (
									<CollapsedCategoryVoiceParticipants
										guild={guild}
										voiceChannels={group.filteredVoiceChannels}
										data-flx="app.channel-list-content.collapsed-category-voice-participants"
									/>
								)}
								{group.showTextChannels &&
									!threadsActive &&
									group.visibleTextChannels.map((ch) => (
										<ChannelItem
											key={ch.id}
											guild={guild}
											channel={ch}
											isDraggingAnything={isDraggingAnything}
											activeDragItem={activeDragItem}
											onChannelDrop={handleChannelDrop}
											onDragStateChange={setActiveDragItem}
											isSelectedByPath={selectedChannelInGuildId === ch.id}
											isOnMembersRoute={isMembersSelected}
											data-flx="app.channel-list-content.channel-item--2"
										/>
									))}
								{group.showTextChannels &&
									threadsActive &&
									group.visibleTextChannels.map((ch) => (
										<React.Fragment key={ch.id}>
											<ChannelItem
												guild={guild}
												channel={ch}
												isDraggingAnything={isDraggingAnything}
												activeDragItem={activeDragItem}
												onChannelDrop={handleChannelDrop}
												onDragStateChange={setActiveDragItem}
												isSelectedByPath={selectedChannelInGuildId === ch.id}
												isOnMembersRoute={isMembersSelected}
												data-flx="app.channel-list-content.channel-item--4"
											/>
											<SidebarThreadList
												guildId={guild.id}
												parentId={ch.id}
												collapsed={group.isCollapsed}
												data-flx="app.channel-list-content.sidebar-thread-list"
											/>
										</React.Fragment>
									))}
								{group.showVoiceChannels &&
									group.visibleVoiceChannels.map((ch) => {
										const channelRow = (
											<ChannelItem
												key={ch.id}
												guild={guild}
												channel={ch}
												isDraggingAnything={isDraggingAnything}
												activeDragItem={activeDragItem}
												onChannelDrop={handleChannelDrop}
												onDragStateChange={setActiveDragItem}
												isSelectedByPath={selectedChannelInGuildId === ch.id}
												isOnMembersRoute={isMembersSelected}
												data-flx="app.channel-list-content.channel-item--3"
											/>
										);
										if (group.isCollapsed && connectedChannelId && ch.id === connectedChannelId) {
											return (
												<React.Fragment key={ch.id}>
													{channelRow}
													<CollapsedChannelAvatarStack
														guild={guild}
														channel={ch}
														data-flx="app.channel-list-content.collapsed-channel-avatar-stack"
													/>
												</React.Fragment>
											);
										}
										return (
											<React.Fragment key={ch.id}>
												{channelRow}
												{!group.isCollapsed && (
													<VoiceParticipantsList
														guild={guild}
														channel={ch}
														data-flx="app.channel-list-content.voice-participants-list"
													/>
												)}
											</React.Fragment>
										);
									})}
							</div>
						))}
					</div>
					{showTrailingDropZone && (
						<div className={styles.bottomDropZone} data-flx="app.channel-list-content.bottom-drop-zone">
							<NullSpaceDropIndicator
								isDraggingAnything={isDraggingAnything}
								onChannelDrop={handleChannelDrop}
								variant="bottom"
								data-flx="app.channel-list-content.null-space-drop-indicator--2"
							/>
						</div>
					)}
					<div className={styles.bottomSpacer} data-flx="app.channel-list-content.bottom-spacer" />
				</div>
			</Scroller>
			<ScrollIndicatorOverlay
				getScrollContainer={getChannelScrollContainer}
				scrollContainerIdentity={guild.id}
				dependencies={channelIndicatorDependencies}
				label={i18n._(NEW_MESSAGES_DESCRIPTOR)}
				data-flx="app.channel-list-content.scroll-indicator-overlay"
			/>
		</div>
	);
});