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

152 lines
5.5 KiB
TypeScript

// Metro module 15909 (f15910).
import { useState, useEffect, useContext } from "react";
import ChannelRTCStore from "../../../calls/ChannelRTCStore";
import AuthenticationStore from "../../../../stores/AuthenticationStore";
import ChannelStore from "../../../../stores/ChannelStore";
import RTCConnectionStore from "../../../../stores/RTCConnectionStore";
import VoiceStateStore from "../../../../stores/VoiceStateStore";
import SortedVoiceStateStore from "../../../../stores/views/SortedVoiceStateStore";
import { VoicePanelCTACard, VoicePanelCardItemType } from "../../VoicePanelConstants";
import { RTCConnectionStates } from "../../../../Constants";
import useIsConnectedToVoiceChannel from "./useIsConnectedToVoiceChannel";
import { useStateFromStores, useStateFromStoresArray } from "../../../../_bundle/Module589";
import { useDesyncedChannelParticipants } from "../../../voice_calls/RTCConnectionDesyncHooks";
import VoicePanelStateContext from "../VoicePanelStateContext";
import { useManagerSubscription } from "../card/VoicePanelCardLayoutManager";
let c11393_14;
const getMemoizedParticipant = function getMemoizedParticipant(item, a1) {
const r10 = `${item.type}-${item.id}`;
let r12 = a1.get(r10);
if (r12 == null) {
a1.set(r10, item);
r12 = item;
}
return r12;
};
c11393_14 = [];
export default function useVoicePanelCards(a0, a1) {
let stateFromStores, desyncedChannelParticipants;
const id = AuthenticationStore.getId();
const channel = ChannelStore.getChannel(a0);
let r13 = channel == null ? void 0 : channel.isDM();
if (r13 == null) {
r13 = false;
}
let c22594_3 = r13;
const isConnectedToVoiceChannel = useIsConnectedToVoiceChannel(a0);
let c22594_4 = isConnectedToVoiceChannel;
const [state] = useState(() => new Map());
useEffect(() => () => state.clear(), [state]);
stateFromStores = useStateFromStores([RTCConnectionStore], () => RTCConnectionStore.getState() === RTCConnectionStates.RTC_CONNECTED);
desyncedChannelParticipants = useDesyncedChannelParticipants(a0);
return {
items: useStateFromStoresArray([ChannelRTCStore, SortedVoiceStateStore], () => {
let r6 = void 0;
if (!c22594_4) {
let r33 = SortedVoiceStateStore.getVoiceStatesForChannelAlt(a0, a1).map((item) => {
const r2 = {
type: VoicePanelCardItemType.PARTICIPANT,
id: item.user.id
};
const r17 = `${r2.type}-${r2.id}`;
let r19 = state.get(r17);
if (r19 == null) {
state.set(r17, r2);
r19 = r2;
}
return r19;
});
if (!(r33.length > 0)) {
r33 = c11393_14;
}
return r33;
}
let r38 = ChannelRTCStore.getVoiceParticipantsHidden(a0);
const r39 = [];
for (const item of ChannelRTCStore.getFilteredParticipants(a0)) {
r39.push(item);
}
if (!r38 && desyncedChannelParticipants != null) {
for (const desyncedChannelParticipant of desyncedChannelParticipants) {
r39.push(desyncedChannelParticipant);
}
}
let r61 = [];
for (const item2 of r39) {
const memoizedParticipant = getMemoizedParticipant({
type: VoicePanelCardItemType.PARTICIPANT,
id: item2.id
}, state);
if (c22594_3 && memoizedParticipant.id === id) {
r6 = memoizedParticipant;
continue;
}
r61.push(memoizedParticipant);
}
if (r6 != null) {
r61.push(r6);
}
if (c22594_3 && stateFromStores && r61.length === 1) {
r61.push(getMemoizedParticipant({
type: VoicePanelCardItemType.CTA,
id: VoicePanelCTACard.CALLER_DISCONNECTED
}, state));
}
if (r38) {
r38 = r39.length === 0;
}
if (r38) {
r61.push(getMemoizedParticipant({
type: VoicePanelCardItemType.CTA,
id: VoicePanelCTACard.NO_VIDEO_PARTICIPANTS
}, state));
}
if (!(r61.length > 0)) {
r61 = c11393_14;
}
return r61;
}, [isConnectedToVoiceChannel, desyncedChannelParticipants, a0, a1, state, r13, id, stateFromStores]),
isConnected: isConnectedToVoiceChannel
};
};
export function useChunkedParticipants(a0, a1) {
const id2 = AuthenticationStore.getId();
const layoutManager = useContext(VoicePanelStateContext).layoutManager;
const managerSubscription = useManagerSubscription(layoutManager);
const [state2] = useState(() => new Map());
useEffect(() => () => state2.clear(), [state2]);
return useStateFromStoresArray([VoiceStateStore, ChannelRTCStore], () => {
if (managerSubscription < 0) {
return c11393_14;
}
const isInChannel = VoiceStateStore.isInChannel(a0, id2);
let r25 = [];
if (!isInChannel) {
return r25;
}
for (const item of new Set((() => {
const r2 = [];
let start = a1.start;
if (start <= a1.end) {
do {
r2.push.apply(r2, [...Array.from(layoutManager.getChunk(start))]);
start = start + 1;
} while (start <= a1.end);
}
return r2;
})())) {
r25.push(getMemoizedParticipant(item, state2));
}
if (ChannelRTCStore.getVoiceParticipantsHidden(a0) && r25.length === 0) {
r25.push(getMemoizedParticipant({
type: VoicePanelCardItemType.CTA,
id: VoicePanelCTACard.NO_VIDEO_PARTICIPANTS
}, state2));
}
if (!(r25.length > 0)) {
r25 = c11393_14;
}
return r25;
}, [a0, state2, layoutManager, a1, managerSubscription, id2]);
}