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

70 lines
2.4 KiB
TypeScript

// Metro module 15019 (f15020).
import { setGetVisibleChannelIds, setGetVisibleGuildIds } from "../../../guild_sidebar/SidebarVisibilityMethodStore";
import GuildStore from "../../../../stores/GuildStore";
import SortedGuildStore, { GuildsNodeType } from "../../../../stores/SortedGuildStore";
export function registerGuildVisibilityMethod({ current }) {
if (current != null) {
setGetVisibleGuildIds(function() {
if (current == null) {
return [];
}
const items = current.getItems();
const scrollPosition = current.getScrollPosition();
const containerSize = current.containerSize;
const guilds = GuildStore.getGuilds();
const guildsTree = SortedGuildStore.getGuildsTree();
const set = new Set();
let c27886_4 = set;
items.forEach((item) => {
const node = guildsTree.getNode(item.recyclerKey);
if (node !== void 0) {
const layoutStart = item.layoutStart;
if (layoutStart + item.layoutSize >= scrollPosition && layoutStart <= scrollPosition + containerSize) {
(node.type === GuildsNodeType.FOLDER ? node.children : [node]).forEach((item) => {
if (item.type === GuildsNodeType.GUILD && item.id in guilds) {
c27886_4.add(item.id);
}
});
}
}
});
return Array.from(set);
});
}
}
export function registerFastListChannelVisibilityMethod({ current: current2 }, c21529_0) {
if (current2 != null) {
setGetVisibleChannelIds(function() {
if (current2 == null) {
return [];
}
const items = current2.getItems();
const scrollPosition2 = current2.getScrollPosition();
const containerSize2 = current2.containerSize;
const r9 = [];
let c27887_2 = r9;
items.forEach((item) => {
let r2 = void 0;
try {
try {
r2 = c21529_0.getChannelFromSectionRow(item.section, item.item)?.channel;
} catch ($e) {}
} catch (r28) {
if (r2 == null) {
return void 0;
}
throw r28;
}
if (r2 == null) {
return void 0;
}
const layoutStart = item.layoutStart;
if (layoutStart + item.layoutSize >= scrollPosition2 && layoutStart <= scrollPosition2 + containerSize2) {
c27887_2.push(r2.id);
}
});
return r9;
});
}
}