Files
discord-decomp/modules/guilds_bar/native/hooks/useGuildsBarProps.tsx
T
2026-11-01 12:12:55 +02:00

584 lines
25 KiB
TypeScript

// Metro module 14950 (f14951).
import { useEffect, useMemo, useCallback } from "react";
import GatewayConnectionStore from "../../../gateway/GatewayConnectionStore";
import LurkingStore from "../../../lurker_mode/LurkingStore";
import MessageRequestStore from "../../../message_request/MessageRequestStore";
import SpamMessageRequestStore from "../../../message_request/SpamMessageRequestStore";
import GeoRestrictedGuildStore from "../../../../stores/GeoRestrictedGuildStore";
import GuildAvailabilityStore from "../../../../stores/GuildAvailabilityStore";
import GuildMemberStore from "../../../../stores/GuildMemberStore";
import GuildStore from "../../../../stores/GuildStore";
import PrivateChannelReadStateStore from "../../../../stores/PrivateChannelReadStateStore";
import SelectedGuildStore from "../../../../stores/SelectedGuildStore";
import SortedGuildStore, { GuildsNodeType } from "../../../../stores/SortedGuildStore";
import GuildsBarDnDStore from "../GuildsBarDnDStore";
import { FastListRenderSections, useGuildWrapperSize } from "../GuildsBarConstants";
import GuildsBarGuildFolder from "../GuildsBarGuildFolder";
import GuildsBarPendingGuildFolder from "../GuildsBarPendingGuildFolder";
import GuildsBarMessages from "../GuildsBarMessages";
import GuildsBarFavorites from "../GuildsBarFavorites";
import GuildsBarGuild from "../GuildsBarGuild";
import GuildsBarDirectMessage from "../GuildsBarDirectMessage";
import GuildsBarSeparator from "../GuildsBarSeparator";
import GuildsBarPendingGuild from "../GuildsBarPendingGuild";
import GuildsBarGeoRestrictedGuild from "../GuildsBarGeoRestrictedGuild";
import GuildsBarFooterWrapper from "../GuildsBarFooterWrapper";
import GuildsBarItemUnavailableGuilds from "../GuildsBarItemUnavailableGuilds";
import GuildsBarItemEmptyNUX from "../GuildsBarItemEmptyNUX";
import GuildsBarCreateJoinButton from "../GuildsBarCreateJoinButton";
import GuildsBarUnreadBars from "../GuildsBarUnreadBars";
import { useToken } from "../../../../design/tokens/native/useToken";
import Module712 from "../../../../_bundle/Module712";
import useSafeAreaInsets_native from "../../../safe_area/useSafeAreaInsets.native";
import { useMobileQuestDockHeight } from "../../../quests/native/QuestHooks.native";
import { useYouBarTotalHeight } from "../../../main_tabs_v2/native/you_bar/hooks/useYouBarTotalHeight";
import useIsFavoritesGuildVisible from "../../../favorites/hooks/useIsFavoritesGuildVisible";
import { useStateFromStoresArray, useStateFromStores } from "../../../../_bundle/Module589";
import { filterOutMessageRequestsAndSpamById } from "../../../message_request/MessageRequestUtils";
import areGuildsBarFastListStatesEqual from "../utils/areGuildsBarFastListStatesEqual";
import useGuildsBarCreatePendingFolderNode from "./useGuildsBarCreatePendingFolderNode";
import { getWindowDimensions } from "../../../screen/useWindowDimensions.native";
import useGuildsBarSelectedGuildScroller from "../../hooks/useGuildsBarSelectedGuildScroller";
import { FastListItemTypes } from "../../../../lib/native/FastList";
let c10577_21, isAnchorIdEqual;
const findGuildSectionIndex = function findGuildSectionIndex(guildId) {
const fastListGuildFolders = SortedGuildStore.getFastListGuildFolders();
let r29 = -1;
let item3 = 0;
let r31 = false;
for (const item of fastListGuildFolders) {
r29 = r29 + 1;
item3 = 0;
if (!(item.type === GuildsNodeType.GUILD && item.id === guildId)) {
if (item.type === GuildsNodeType.FOLDER) {
for (const item2 of item.children) {
if (item2.type !== GuildsNodeType.GUILD) {
continue;
}
if (item2.id !== guildId) {
item3 = item3 + 1;
continue;
}
if (!item.expanded) {
item3 = 0;
}
r31 = true;
break;
}
}
if (r31) {
break;
}
continue;
}
r31 = true;
break;
}
return r31 ? {
section: r29 + FastListRenderSections.GUILDS,
item: item3
} : null;
};
isAnchorIdEqual = function isAnchorIdEqual(a0, id, a2) {
return a2 != null && id === `${a0}:${a2}`;
};
c10577_21 = {
MESSAGES: "section-messages",
FAVORITES: "section-favorites",
PENDING_JOIN_REQUESTS: "section-pending-join-requests",
LURKING_GUILDS: "section-lurking-guilds",
GUEST_GUILDS: "section-guest-guilds",
UNREAD_PRIVATE_CHANNELS: "section-private-channels",
SEPARATOR: "section-separator",
GUILDS: "section-guilds"
};
export default function useGuildsBarProps(a0) {
let c21479_8, stateFromStoresArray, stateFromStores, stateFromStoresArray2, stateFromStores2, stateFromStoresArray3, guildsNFolders, expanded, pendingFolderNode, stateFromStores3, memo, memo2;
let c21479_0 = a0;
const guildWrapperSize = useGuildWrapperSize();
const token = useToken(Module712.modules.mobile.GUILD_BAR_ITEM_MARGIN);
const safeAreaInsets_native = useSafeAreaInsets_native();
const { top, bottom } = safeAreaInsets_native;
const mobileQuestDockHeight = useMobileQuestDockHeight();
const youBarTotalHeight = useYouBarTotalHeight();
const youBarTotalHeight2 = useYouBarTotalHeight(4);
useEffect(() => {
GuildsBarDnDStore.getState().listInsets.set({
start: top,
end: mobileQuestDockHeight + youBarTotalHeight
});
}, [mobileQuestDockHeight, top, youBarTotalHeight]);
const r60 = useIsFavoritesGuildVisible("useGuildsBarProps") ? 1 : 0;
c21479_8 = r60;
stateFromStoresArray = useStateFromStoresArray([PrivateChannelReadStateStore, MessageRequestStore, SpamMessageRequestStore], () => filterOutMessageRequestsAndSpamById(PrivateChannelReadStateStore.getUnreadPrivateChannelIds(), [MessageRequestStore, SpamMessageRequestStore]), []);
stateFromStores = useStateFromStores([GatewayConnectionStore], () => GatewayConnectionStore.isConnected());
stateFromStoresArray2 = useStateFromStoresArray([GeoRestrictedGuildStore], () => GeoRestrictedGuildStore.getGeoRestrictedGuilds());
stateFromStores2 = useStateFromStores([LurkingStore], () => LurkingStore.lurkingGuildIds());
stateFromStoresArray3 = useStateFromStoresArray([GuildStore, GuildMemberStore], () => GuildStore.getGuildIds().filter((item) => GuildMemberStore.isCurrentUserGuest(item)));
const stateFromStores4 = useStateFromStores([SortedGuildStore], () => ({
guildsNFolders: SortedGuildStore.getFastListGuildFolders(),
version: SortedGuildStore.getGuildsTree().version
}), [], areGuildsBarFastListStatesEqual);
guildsNFolders = stateFromStores4.guildsNFolders;
const version = stateFromStores4.version;
const guildsBarCreatePendingFolderNode = useGuildsBarCreatePendingFolderNode();
expanded = guildsBarCreatePendingFolderNode.expanded;
pendingFolderNode = guildsBarCreatePendingFolderNode.pendingFolderNode;
stateFromStores3 = useStateFromStores([GuildAvailabilityStore], () => GuildAvailabilityStore.totalUnavailableGuilds);
memo = useMemo(() => ({
scrollIndicatorInsets: {
top: 3 * token,
bottom: youBarTotalHeight > 0 ? youBarTotalHeight - 16 : bottom + 3 * token
},
insetStart: top,
insetEnd: mobileQuestDockHeight + 2 * token + youBarTotalHeight2,
chunkBase: getWindowDimensions().height
}), [top, mobileQuestDockHeight, bottom, youBarTotalHeight, youBarTotalHeight2, token]);
useGuildsBarSelectedGuildScroller(useCallback((a0, a1) => {
if (a0 != null) {
const r14 = findGuildSectionIndex(a0);
if (r14 == null) {
return void 0;
}
const current2 = c21479_0.current;
if (current2 != null) {
current2.scrollToLocation({
...r14,
orientation: "visible",
paddingStart: memo.insetStart,
paddingEnd: memo.insetEnd
});
}
} else {
const current = c21479_0.current;
if (current != null) {
current.scrollTo(0, a1);
}
}
}, [memo.insetStart, memo.insetEnd, a0]));
memo2 = useMemo(() => {
const guildId = SelectedGuildStore.getGuildId();
const r8 = guildId != null ? findGuildSectionIndex(guildId) : void 0;
if (r8 != null) {
return {
initialScrollItem: r8.item,
initialScrollSection: r8.section
};
}
}, []);
return {
listProps: memo,
listDataProps: useMemo(() => {
const sections = [1, c21479_8, pendingFolderNode == null ? 0 : expanded ? pendingFolderNode.children.length : 1, stateFromStores2.length, stateFromStoresArray3.length, Math.min(stateFromStoresArray.length, 10), 1];
for (const guildsNFolder of guildsNFolders) {
const r46 = guildsNFolder;
if (guildsNFolder.type === GuildsNodeType.GUILD) {
sections.push(1);
} else if (r46.type === GuildsNodeType.FOLDER) {
if (r46.expanded) {
sections.push(r46.children.length);
} else {
sections.push(1);
}
}
}
if (stateFromStoresArray2.length > 0) {
sections.push(stateFromStoresArray2.length);
}
const r69 = [];
let c27871_0 = r69;
if (stateFromStores3 > 0) {
r69.push("unavailable-guilds");
}
let r74 = stateFromStores;
if (stateFromStores) {
r74 = guildsNFolders.length === 0;
}
if (r74) {
r74 = stateFromStores3 === 0;
}
if (r74) {
r69.push("empty-nux");
}
r69.push("create-join-guild");
return {
...memo2,
sections,
sectionSize: (a0) => {
let r10;
L7: {
if (a0 === FastListRenderSections.PENDING_JOIN_REQUESTS) {
r10 = guildWrapperSize;
if (pendingFolderNode != null) {
break L7;
}
}
const r12 = a0 >= FastListRenderSections.GUILDS;
r10 = 0;
if (r12) {
const r15 = guildsNFolders[a0 - FastListRenderSections.GUILDS];
r10 = r15 == null ? 0 : r15.type === GuildsNodeType.FOLDER ? guildWrapperSize : 0;
}
}
return r10;
},
itemSize: (a0, a1) => {
let r16, r29;
L31: {
const MESSAGES = FastListRenderSections.MESSAGES;
r16 = guildWrapperSize;
if (MESSAGES !== a0) {
const FAVORITES = FastListRenderSections.FAVORITES;
r16 = guildWrapperSize;
if (FAVORITES !== a0) {
const LURKING_GUILDS = FastListRenderSections.LURKING_GUILDS;
r16 = guildWrapperSize;
if (LURKING_GUILDS !== a0) {
const GUEST_GUILDS = FastListRenderSections.GUEST_GUILDS;
r16 = guildWrapperSize;
if (GUEST_GUILDS !== a0) {
let r20 = a1;
if (FastListRenderSections.UNREAD_PRIVATE_CHANNELS === a0) {
if (a1 == null) {
r20 = -1;
}
r16 = stateFromStoresArray[r20] == null ? 0 : guildWrapperSize;
} else if (FastListRenderSections.SEPARATOR === a0) {
r16 = 1 + 2 * token;
} else if (FastListRenderSections.PENDING_JOIN_REQUESTS === a0) {
r16 = a1 != null ? pendingFolderNode != null ? pendingFolderNode.expanded ? pendingFolderNode.children[a1] != null ? guildWrapperSize : 0 : 0 : 0 : 0;
} else {
const r3 = a1 == null;
r16 = 0;
if (!r3) {
const r24 = a0 - FastListRenderSections.GUILDS;
if (guildsNFolders.length >= r24) {
const r26 = stateFromStoresArray2[a1];
r16 = guildWrapperSize;
if (r26 != null) {
break L31;
}
}
L18: {
const r27 = guildsNFolders[r24];
const r28 = r27 == null;
r29 = 0;
if (!r28) {
const type = r27.type;
const ROOT = GuildsNodeType.ROOT;
r29 = 0;
if (type !== ROOT) {
if (r27.type === GuildsNodeType.GUILD) {
const r35 = a1 > 0;
r29 = 0;
if (r35) {
break L18;
}
}
if (r27.type === GuildsNodeType.FOLDER) {
const expanded2 = r27.expanded;
r29 = 0;
if (!expanded2) {
break L18;
}
const r41 = r27.children[a1] == null;
r29 = 0;
if (r41) {
break L18;
}
}
r29 = guildWrapperSize;
}
}
}
r16 = r29;
}
}
}
}
}
}
}
return r16;
},
footerSize: () => c27871_0.length * guildWrapperSize + 8,
renderSection: (a0) => {
let r13;
if (a0 >= FastListRenderSections.GUILDS) {
const r23 = guildsNFolders[a0 - FastListRenderSections.GUILDS];
r13 = r23.type === GuildsNodeType.FOLDER ? <GuildsBarGuildFolder id={r23.id} expanded={r23.expanded} name={r23.name} color={r23.color} childNodes={r23.children} /> : null;
} else {
r13 = a0 === FastListRenderSections.PENDING_JOIN_REQUESTS ? pendingFolderNode != null ? <GuildsBarPendingGuildFolder id={pendingFolderNode.id} expanded={pendingFolderNode.expanded} childNodes={pendingFolderNode.children} /> : null : null;
}
return r13;
},
renderItem: (a0, a1) => {
let r27;
L39: {
if (FastListRenderSections.MESSAGES === a0) {
r27 = <GuildsBarMessages />;
} else if (FastListRenderSections.FAVORITES === a0) {
r27 = <GuildsBarFavorites />;
} else if (FastListRenderSections.LURKING_GUILDS === a0) {
const guildId2 = stateFromStores2[a1];
r27 = guildId2 != null ? <GuildsBarGuild guildId={guildId2} /> : null;
} else if (FastListRenderSections.GUEST_GUILDS === a0) {
const guildId = stateFromStoresArray3[a1];
r27 = guildId != null ? <GuildsBarGuild guildId={guildId} /> : null;
} else if (FastListRenderSections.UNREAD_PRIVATE_CHANNELS === a0) {
const channelId = stateFromStoresArray[a1];
r27 = channelId != null ? <GuildsBarDirectMessage channelId={channelId} /> : null;
} else if (FastListRenderSections.SEPARATOR === a0) {
r27 = <GuildsBarSeparator />;
} else if (FastListRenderSections.PENDING_JOIN_REQUESTS === a0) {
const r59 = pendingFolderNode == null;
r27 = null;
if (!r59) {
const r61 = pendingFolderNode.children[a1];
r27 = r61 == null ? null : r61.type === GuildsNodeType.GUILD ? <GuildsBarPendingGuild guildId={r61.id} /> : null;
}
} else {
const r24 = a0 - FastListRenderSections.GUILDS;
if (r24 >= guildsNFolders.length) {
const restrictedGuild = stateFromStoresArray2[a1];
r27 = restrictedGuild != null ? <GuildsBarGeoRestrictedGuild restrictedGuild={restrictedGuild} /> : null;
} else {
const r26 = guildsNFolders[r24];
const r2 = r26 == null;
r27 = null;
if (!r2) {
const type = r26.type;
const ROOT = GuildsNodeType.ROOT;
r27 = null;
if (type !== ROOT) {
if (r26.type === GuildsNodeType.GUILD) {
const r32 = a1 > 0;
r27 = null;
if (r32) {
break L39;
}
}
const r15 = r26.type === GuildsNodeType.FOLDER ? r26.children[a1] : r26;
r27 = r15 == null ? null : r15.type === GuildsNodeType.GUILD ? <GuildsBarGuild guildId={r15.id} /> : null;
}
}
}
}
}
return r27;
},
renderFooter: () => <GuildsBarFooterWrapper>
{c27871_0.map((item) => {
if (item === "unavailable-guilds") {
return <GuildsBarItemUnavailableGuilds key={item} />;
}
if (item === "empty-nux") {
return <GuildsBarItemEmptyNUX key={item} />;
}
if (item === "create-join-guild") {
return <GuildsBarCreateJoinButton key={item} />;
}
})}
</GuildsBarFooterWrapper>,
getRecyclerKey: (a0, a1, a2) => {
if (FastListItemTypes.ITEM !== a0 && FastListItemTypes.SECTION !== a0) {
return void 0;
}
L13: {
if (!(a1 < FastListRenderSections.GUILDS)) {
const r22 = guildsNFolders[a1 - FastListRenderSections.GUILDS];
if (r22 != null && r22.type !== GuildsNodeType.ROOT) {
const type = r22.type;
const FOLDER = GuildsNodeType.FOLDER;
let r28 = r22;
if (type === FOLDER) {
if (a2 == null) {
return `${r22.id}`;
}
r28 = r22.children[a2];
}
if (r28.type === GuildsNodeType.GUILD && a2 == null) {
break L13;
}
return `${r28.id}`;
}
}
}
},
renderAccessory: (a0) => <GuildsBarUnreadBars fastList={a0} />,
getAnchorIdFromIndex: (a0, a1) => {
let MESSAGES;
if (GuildsBarDnDStore.getState().dropSpecs == null && GuildsBarDnDStore.getState().dragSpecs == null) {
if (FastListRenderSections.MESSAGES === a0) {
MESSAGES = c10577_21.MESSAGES;
} else if (FastListRenderSections.FAVORITES === a0) {
MESSAGES = c10577_21.FAVORITES;
} else if (FastListRenderSections.PENDING_JOIN_REQUESTS === a0) {
if (a1 == null) {
MESSAGES = c10577_21.PENDING_JOIN_REQUESTS;
} else {
const r83 = pendingFolderNode == null ? void 0 : pendingFolderNode.children[a1]?.id;
MESSAGES = r83 != null ? `${c10577_21.PENDING_JOIN_REQUESTS}:${r83}` : void 0;
}
} else if (FastListRenderSections.LURKING_GUILDS === a0) {
MESSAGES = a1 == null ? c10577_21.LURKING_GUILDS : `${c10577_21.LURKING_GUILDS}:${stateFromStores2[a1]}`;
} else if (FastListRenderSections.GUEST_GUILDS === a0) {
MESSAGES = a1 == null ? c10577_21.GUEST_GUILDS : `${c10577_21.GUEST_GUILDS}:${stateFromStoresArray3[a1]}`;
} else if (FastListRenderSections.UNREAD_PRIVATE_CHANNELS === a0) {
MESSAGES = a1 == null ? c10577_21.UNREAD_PRIVATE_CHANNELS : `${c10577_21.UNREAD_PRIVATE_CHANNELS}:${stateFromStoresArray[a1]}`;
} else if (FastListRenderSections.SEPARATOR === a0) {
MESSAGES = c10577_21.SEPARATOR;
} else {
FastListRenderSections.GUILDS;
const r30 = a0 - FastListRenderSections.GUILDS;
const r31 = guildsNFolders[r30];
const r13 = r31 == null ? r30 >= guildsNFolders.length ? a1 != null ? stateFromStoresArray2[a1]?.id : void 0 : void 0 : a1 == null ? r31.id : r31.children[a1]?.id;
MESSAGES = r13 != null ? `${c10577_21.GUILDS}:${r13}` : void 0;
}
return MESSAGES;
}
},
getAnchorIndexFromId: (a0) => (function getAnchorIndexFromId({ id, lurkingGuildsIds, guestGuildIds, privateChannelIds, guildsNFolders: guildsNFolders2, pendingFolderNode: pendingFolderNode2, geoRestrictedGuilds }) {
let r152;
if (c10577_21.MESSAGES === id) {
return {
section: FastListRenderSections.MESSAGES
};
}
if (c10577_21.FAVORITES === id) {
return {
section: FastListRenderSections.FAVORITES
};
}
if (c10577_21.PENDING_JOIN_REQUESTS === id) {
return {
section: FastListRenderSections.PENDING_JOIN_REQUESTS
};
}
if (c10577_21.LURKING_GUILDS === id) {
return {
section: FastListRenderSections.LURKING_GUILDS
};
}
if (c10577_21.GUEST_GUILDS === id) {
return {
section: FastListRenderSections.GUEST_GUILDS
};
}
if (c10577_21.UNREAD_PRIVATE_CHANNELS === id) {
return {
section: FastListRenderSections.UNREAD_PRIVATE_CHANNELS
};
}
if (c10577_21.SEPARATOR === id) {
return {
section: FastListRenderSections.SEPARATOR
};
}
if (id.startsWith(c10577_21.LURKING_GUILDS)) {
let item13 = 0;
for (const item7 of lurkingGuildsIds) {
if (!isAnchorIdEqual(c10577_21.LURKING_GUILDS, id, item7)) {
item13 = item13 + 1;
continue;
}
return {
section: FastListRenderSections.LURKING_GUILDS,
item: item13
};
}
} else {
if (id.startsWith(c10577_21.PENDING_JOIN_REQUESTS) && pendingFolderNode2 != null) {
let item8 = 0;
for (const item of pendingFolderNode2.children) {
if (!isAnchorIdEqual(c10577_21.PENDING_JOIN_REQUESTS, id, item.id)) {
item8 = item8 + 1;
continue;
}
return {
section: 0 + FastListRenderSections.PENDING_JOIN_REQUESTS,
item: item8
};
}
}
if (id.startsWith(c10577_21.GUEST_GUILDS)) {
let item12 = 0;
for (const item6 of guestGuildIds) {
if (!isAnchorIdEqual(c10577_21.GUEST_GUILDS, id, item6)) {
item12 = item12 + 1;
continue;
}
return {
section: FastListRenderSections.GUEST_GUILDS,
item: item12
};
}
} else {
if (id.startsWith(c10577_21.UNREAD_PRIVATE_CHANNELS)) {
let item9 = 0;
for (const item2 of privateChannelIds) {
if (!isAnchorIdEqual(c10577_21.UNREAD_PRIVATE_CHANNELS, id, item2)) {
item9 = item9 + 1;
continue;
}
return {
section: FastListRenderSections.UNREAD_PRIVATE_CHANNELS,
item: item9
};
}
}
if (id.startsWith(c10577_21.GUILDS)) {
let r118 = 0;
let item10 = 0;
for (const item3 of guildsNFolders2) {
if (!isAnchorIdEqual(c10577_21.GUILDS, id, item3.id)) {
done139: {
for (const item4 of item3.children) {
if (!isAnchorIdEqual(c10577_21.GUILDS, id, item4.id)) {
item10 = item10 + 1;
continue;
}
r152 = {
section: r118 + FastListRenderSections.GUILDS,
item: item10
};
break done139;
}
r118 = r118 + 1;
item10 = 0;
continue;
}
return r152;
}
return {
section: r118 + FastListRenderSections.GUILDS
};
}
let item11 = 0;
for (const item5 of geoRestrictedGuilds) {
if (!isAnchorIdEqual(c10577_21.GUILDS, id, item5.id)) {
item11 = item11 + 1;
continue;
}
return {
section: r118 + FastListRenderSections.GUILDS,
item: item11
};
}
}
}
}
})({
id: a0,
lurkingGuildsIds: stateFromStores2,
guestGuildIds: stateFromStoresArray3,
privateChannelIds: stateFromStoresArray,
guildsNFolders,
pendingFolderNode,
geoRestrictedGuilds: stateFromStoresArray2
})
};
}, [r60, pendingFolderNode, stateFromStores2, stateFromStoresArray3, stateFromStoresArray, stateFromStoresArray2, stateFromStores3, stateFromStores, guildsNFolders, memo2, version, expanded, token, guildWrapperSize])
};
};