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

334 lines
10 KiB
TypeScript

// Metro module 15012 (f15013).
import _slicedToArray from "../../../_bundle/_slicedToArray";
import * as Module19 from "react";
import { useState, useMemo, useEffect, useCallback } from "react";
import { View } from "react-native";
import GuildReadStateStore from "../../../stores/GuildReadStateStore";
import SelectedGuildStore from "../../../stores/SelectedGuildStore";
import SortedGuildStore, { GuildsNodeType } from "../../../stores/SortedGuildStore";
import { FastListRenderSections, useGuildWrapperSize, GUILD_LIST_WIDTH } from "./GuildsBarConstants";
import { YOU_BAR_HEIGHT, YOU_BAR_MARGIN } from "../../main_tabs_v2/native/you_bar/YouBarConstants";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import { FastListItemTypes } from "../../../lib/native/FastList";
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 debounce from "../../../_bundle/debounce";
import shallowEqual from "../../../_bundle/shallowEqual";
import { BatchedStoreListener } from "../../../_bundle/Module589";
import * as _ReanimatedRexport from "../../reanimated/ReanimatedRexport";
import { useAnimatedReaction } from "../../reanimated/ReanimatedRexport";
import UnreadBars from "../../../components_native/common/UnreadBars";
let useStyles, c10626_17, c10626_18, findFirstOrLastMentionedItem, __initData, __initData2;
const checkNodeAndIterate = function checkNodeAndIterate(a0) {
let length;
const node = a0.node;
let section = a0.section;
let item = a0.item;
const { direction, selectedGuildId } = a0;
if (node != null) {
if (node.type === GuildsNodeType.GUILD && node.id !== selectedGuildId) {
const node2 = GuildReadStateStore.getMentionCount(node.id) > 0 ? node : void 0;
if (node2 != null) {
if (section == null) {
section = 0;
}
if (item == null) {
item = 0;
}
return {
node: node2,
section,
item
};
}
}
let r14 = direction !== 1 ? node.children.length - 1 : 0;
if (0 <= r14 && r14 < node.children.length) {
do {
const r30 = r14;
const section2 = section ?? r30;
const r34 = checkNodeAndIterate({
node: node.children[r30],
section: section2,
item: section != null ? r30 : void 0,
direction,
selectedGuildId
});
if (r34 != null) {
return node.type === GuildsNodeType.FOLDER ? node.expanded ? r34 : {
node,
section: section2
} : r34;
}
const r35 = r30 + direction;
if (!(r35 >= 0)) {
break;
}
length = node.children.length;
r14 = r35;
} while (r14 < length);
}
}
};
findFirstOrLastMentionedItem = function findFirstOrLastMentionedItem(fastList, a1, a2, top, a4) {
let section;
const guildsTree = SortedGuildStore.getGuildsTree();
const root = guildsTree.root;
let r15 = fastList.getSectionItemFromPosition(fastList.scrollPosValue.get() + a4).item?.layoutStart;
if (r15 == null) {
r15 = fastList.scrollPosValue.get();
}
const r14 = fastList.scrollPosValue.get() + fastList.containerSize - top - (YOU_BAR_HEIGHT + YOU_BAR_MARGIN);
let r58 = -1;
let r59 = -1;
let r60 = false;
loop5: for (const r65 of fastList.state.items) {
const r66 = r65;
if (r65.layoutStart < r15) {
continue;
}
if (r66.type !== FastListItemTypes.ITEM && r66.type !== FastListItemTypes.SECTION) {
continue;
}
if (r66.layoutStart > r14) {
break;
}
if (r66.section < FastListRenderSections.GUILDS) {
if (!a1) {
continue;
}
r60 = true;
break;
}
if (r66.layoutSize === 0) {
continue;
}
if (r58 === -1) {
r58 = r66.section;
r59 = r66.item;
}
const type = r66.type;
if (FastListItemTypes.SECTION === type) {
const node2 = guildsTree.getNode(r66.recyclerKey);
if (node2 == null) {
continue;
}
if (node2.type !== GuildsNodeType.FOLDER) {
continue;
}
if (node2.expanded) {
continue;
}
for (const item of node2.children) {
if (item.type !== GuildsNodeType.GUILD) {
continue;
}
if (!(GuildReadStateStore.getMentionCount(item.id) > 0)) {
continue;
}
r60 = true;
continue loop5;
}
continue;
}
if (FastListItemTypes.ITEM !== type) {
r66.type;
continue;
}
const node = guildsTree.getNode(r66.recyclerKey);
if (node == null) {
continue;
}
if (node.type !== GuildsNodeType.GUILD) {
continue;
}
if (!(GuildReadStateStore.getMentionCount(node.id) > 0)) {
continue;
}
r60 = true;
break;
}
if (r60) {
return c10626_17;
}
const r150 = a1 ? void 0 : checkNodeAndIterate({
node: root,
direction: 1,
selectedGuildId: a2
});
if (!(r150 == null && a1) && r150 == null) {
return c10626_17;
}
if (r150 == null) {
return c10626_18;
}
L59: {
section = r150.section + FastListRenderSections.GUILDS;
if (!(section < r58)) {
if (section === r58) {
let item2 = r150.item;
if (item2 == null) {
item2 = 0;
}
if (item2 < r59) {
break L59;
}
}
const r163 = checkNodeAndIterate({
node: root,
direction: -1,
selectedGuildId: a2
});
return r163 != null ? {
beforeItem: void 0,
afterItem: {
section: r163.section + FastListRenderSections.GUILDS,
row: r163.item,
mention: true
}
} : c10626_17;
}
}
return {
beforeItem: {
section,
row: r150.item,
mention: true
},
afterItem: void 0
};
};
useStyles = createStyles({
wrapper: {
position: "absolute",
top: 0,
left: 0,
bottom: 0,
width: GUILD_LIST_WIDTH
}
});
c10626_17 = {
beforeItem: void 0,
afterItem: void 0
};
c10626_18 = {
beforeItem: {
section: 0,
row: 0,
mention: true
},
afterItem: void 0
};
__initData = {
code: "function GuildsBarUnreadBarsTsx1(){const{scrollPosValue}=this.__closure;return scrollPosValue.get();}"
};
__initData2 = {
code: "function GuildsBarUnreadBarsTsx2(position,lastPosition){const{runOnJS,debouncedUpdate}=this.__closure;if(position!==lastPosition){runOnJS(debouncedUpdate)();}}"
};
const r56 = Module19.memo(function GuildsBarUnreadBars(props) {
let setState, memo, scrollPosValue, paddingStart, paddingEnd;
let styles, top2, mobileQuestDockHeight, youBarTotalHeight;
const fastList = props.fastList;
setState = void 0;
memo = void 0;
scrollPosValue = void 0;
paddingStart = void 0;
paddingEnd = void 0;
const top = useSafeAreaInsets_native().top;
const r0 = useGuildWrapperSize() / 2;
let c21521_2 = r0;
const r28 = _slicedToArray(useState(() => {
const r2 = GuildReadStateStore.getPrivateChannelMentionCount() > 0;
let r18 = SelectedGuildStore.getGuildId();
if (r18 == null) {
r18 = null;
}
return findFirstOrLastMentionedItem(fastList, r2, r18, top, c21521_2);
}), 2);
const r29 = r28[0];
const { beforeItem, afterItem } = r29;
setState = r28[1];
memo = useMemo(() => debounce(() => {
const r2 = GuildReadStateStore.getPrivateChannelMentionCount() > 0;
let r18 = SelectedGuildStore.getGuildId();
if (r18 == null) {
r18 = null;
}
let c30819_0 = findFirstOrLastMentionedItem(fastList, r2, r18, top, c21521_2);
setState((prevState) => {
let r12;
L4: {
if (prevState !== c30819_0) {
const r11 = shallowEqual(prevState.afterItem, c30819_0.afterItem);
r12 = c30819_0;
if (!r11) {
break L4;
}
r12 = shallowEqual(prevState.beforeItem, c30819_0.beforeItem) ? prevState : c30819_0;
} else {
r12 = prevState;
}
}
return r12;
});
}, 100), [fastList, top, r0]);
useEffect(() => {
const batchedStoreListener = new BatchedStoreListener([GuildReadStateStore, SelectedGuildStore, SortedGuildStore], memo);
let c27884_0 = batchedStoreListener;
batchedStoreListener.attach("guild-mention-bars");
return () => {
c27884_0.detach();
};
}, [memo]);
scrollPosValue = fastList.scrollPosValue;
const D = () => scrollPosValue.get();
D.__closure = {
scrollPosValue
};
D.__workletHash = 16367582542434;
D.__initData = __initData;
const O = function O(a0, a1) {
if (a0 !== a1) {
_ReanimatedRexport.runOnJS(memo)();
}
};
O.__closure = {
runOnJS: _ReanimatedRexport.runOnJS,
debouncedUpdate: memo
};
O.__workletHash = 13727289405147;
O.__initData = __initData2;
useAnimatedReaction(D, O);
styles = void 0;
top2 = void 0;
mobileQuestDockHeight = void 0;
youBarTotalHeight = void 0;
styles = useStyles();
top2 = useSafeAreaInsets_native().top;
mobileQuestDockHeight = useMobileQuestDockHeight();
youBarTotalHeight = useYouBarTotalHeight(mobileQuestDockHeight > 0 ? 0 : 8);
const memo2 = useMemo(() => ({
style: [styles.wrapper, {
top: top2,
bottom: mobileQuestDockHeight + youBarTotalHeight
}],
paddingStart: top2,
paddingEnd: mobileQuestDockHeight + 4 + youBarTotalHeight
}), [styles.wrapper, top2, mobileQuestDockHeight, youBarTotalHeight]);
const style = memo2.style;
paddingStart = memo2.paddingStart;
paddingEnd = memo2.paddingEnd;
return <View style={style} collapsable={false} pointerEvents="box-none" testID="guilds-bar-unread-bars">
<UnreadBars beforeItem={beforeItem} afterItem={afterItem} scrollToLocation={useCallback((a0) => {
fastList.scrollToLocation({
...a0,
paddingStart,
paddingEnd,
orientation: "visible"
});
}, [fastList, paddingStart, paddingEnd])} compact />
</View>;
});
export default r56;