// Metro module 10003 (f10004). import { useCallback, useMemo } from "react"; import ChannelStore from "../../stores/ChannelStore"; import GuildCategoryStore from "../../stores/GuildCategoryStore"; import ReadStateStore from "../../stores/ReadStateStore"; import RelationshipStore from "../../stores/RelationshipStore"; import UserStore from "../../stores/UserStore"; import { ChannelTypes, Routes } from "../../Constants"; import { ChannelFlags, StaticChannelRoute } from "../channel/ChannelConstants"; import { ChannelListGuildActionRow } from "../guild_sidebar/GuildSidebarConstants"; import { ReadStateTypes } from "../read_states/ReadStateConstants"; import { useCanSeeOnboardingHome } from "../guild_onboarding_home/OnboardingHomeUtils"; import fuzzysearch from "../../_bundle/fuzzysearch"; import { computeChannelName } from "../channel/useChannelName"; import getFlattedChannelList from "../channel/getFlattedChannelList"; import * as _ChannelListState from "../guild_sidebar/ChannelListState"; import { SECTION_INDEX_GUILD_ACTIONS } from "../guild_sidebar/ChannelListState"; import { bulkClearRecents } from "../recent_channels/RecentChannelsActionCreators"; import { bulkAck } from "../../actions/ReadStateActionCreators"; import { transitionTo } from "../routing/router_utils"; import { useIsDismissibleContentDismissed_UNSAFE } from "../dismissible_content/DismissibleContentUnsafeUtils"; import { DismissibleContent } from "../../_bundle/Module1358"; import { useStateFromStoresObject, useStateFromStores } from "../../_bundle/Module589"; import { t, intl } from "../../intl/index.native"; import Module3771 from "../../_bundle/Module3771"; import SnowflakeUtils from "../../utils/SnowflakeUtils"; const setIndex = function setIndex(a0, a1) { a0.index = a1; }; export function useFilterCategoriesByQuery(a0, a1, a2, a3) { let c17611_0 = a1; let c17611_2 = a3; const r5 = a3.toLowerCase(); c17611_2 = r5; const canSeeOnboardingHome = useCanSeeOnboardingHome(a0); const callback = useCallback((a0, a1) => (canSeeOnboardingHome ? !a0.channel.hasFlag(ChannelFlags.IS_GUILD_RESOURCE_CHANNEL) : !canSeeOnboardingHome) && (a0.channel.type !== ChannelTypes.GUILD_DIRECTORY && (a1.length === 0 || (fuzzysearch(a1, computeChannelName(a0.channel, UserStore, RelationshipStore).toLowerCase()) || a0.channel.topic.toLowerCase().includes(a1)))), [canSeeOnboardingHome]); return useMemo(() => { const r1 = { null: [], _categories: [] }; let c26593_0 = r1; a2[ChannelTypes.GUILD_CATEGORY].forEach(({ channel }) => { if (channel.id === "null") { c26593_0.null = c17611_0.null.filter((item) => callback(item, c17611_2)); } c26593_0[channel.id] = c17611_0[channel.id].filter((item) => callback(item, c17611_2)); }); r1._categories = c17611_0._categories.filter((_category) => _category.channel.id === "null" || c17611_2.length === 0 || c26593_0[_category.channel.id].length > 0); getFlattedChannelList(r1._categories, r1).forEach(setIndex); return r1; }, [a1, a2, callback, r5]); } export function getFirstRouteFor(a0) { const sections = a0.getSections(false); if (sections[SECTION_INDEX_GUILD_ACTIONS] > 0) { const row = a0.getGuildActionSection().getRow(0); if (ChannelListGuildActionRow.GUILD_HOME === row) { return StaticChannelRoute.GUILD_HOME; } if (ChannelListGuildActionRow.GUILD_ROLE_SUBSCRIPTIONS === row) { return StaticChannelRoute.ROLE_SUBSCRIPTIONS; } if (ChannelListGuildActionRow.GUILD_MOD_DASH_MEMBER_SAFETY === row) { return StaticChannelRoute.MEMBER_SAFETY; } } let SECTION_INDEX_UNCATEGORIZED_CHANNELS = _ChannelListState.SECTION_INDEX_UNCATEGORIZED_CHANNELS; while (SECTION_INDEX_UNCATEGORIZED_CHANNELS < a0.voiceChannelsSectionNumber) { const r27 = sections[SECTION_INDEX_UNCATEGORIZED_CHANNELS]; const r28 = SECTION_INDEX_UNCATEGORIZED_CHANNELS; if (r27 > 0) { const channel = a0.getChannelFromSectionRow(r28, 0)?.channel; if (channel != null) { return channel.id; } } SECTION_INDEX_UNCATEGORIZED_CHANNELS = r28 + 1; } return null; } export function clearRecentChannels(a0, a1, r7 = null) { bulkClearRecents(a0, a1); bulkAck(a1.map((item) => ({ channelId: item, readStateType: ReadStateTypes.CHANNEL, messageId: ReadStateStore.lastMessageId(item) }))); if (r7 != null) { transitionTo(Routes.CHANNEL(a0, r7)); } } export function useChannelBrowserSections(a0, a1, rowHeight, a3) { let r16 = useIsDismissibleContentDismissed_UNSAFE(DismissibleContent.CHANNEL_BROWSER_NUX); const stateFromStoresObject = useStateFromStoresObject([ChannelStore], () => { const r5 = {}; const mutableGuildChannelsForGuild = ChannelStore.getMutableGuildChannelsForGuild(a0); for (const key in mutableGuildChannelsForGuild) { const parent_id = mutableGuildChannelsForGuild[key].parent_id; if (parent_id != null) { let r18 = r5[parent_id]; if (r18 == null) { r18 = 0; } r5[parent_id] = r18 + 1; } } return r5; }, [a0]); const r28 = a1._categories.map((_category) => { const r7 = a1[_category.channel.id]; return { rowCount: _category.channel.id !== "null" ? stateFromStoresObject[_category.channel.id] !== 0 ? r7.length : 1 : r7.length, rowHeight: r7.length !== 0 ? rowHeight : 0 }; }); if (!r16) { r16 = a3 == null; } if (!r16) { r28.unshift({ rowCount: 1, rowHeight: a3 }); } return r28; } export function useChannelBrowserChannelCount(c17613_0) { const stateFromStores = useStateFromStores([GuildCategoryStore], () => GuildCategoryStore.getCategories(c17613_0)); const length = stateFromStores._categories.length; const r23 = stateFromStores._categories[stateFromStores._categories.length - 1]; if (r23 == null) { return 0; } let r25 = r23.channel?.id; if (r25 == null) { r25 = "null"; } const r26 = stateFromStores[r25]; return r26 == null ? 0 : r26.length === 0 ? r23.index + 2 - length : r26[r26.length - 1].index + 2 - length; } export function getActiveAgoTimestamp(a0) { const r15 = t["8N0BHR"]; let r22 = ReadStateStore.lastMessageId(a0); if (r22 == null) { r22 = a0; } return intl.formatToPlainString(r15, { timeAgo: Module3771(SnowflakeUtils.extractTimestamp(r22)).fromNow() }); }