Files
discord-decomp/modules/go_live/useFetchStreamPreview.tsx
T
2026-11-01 12:12:55 +02:00

56 lines
2.2 KiB
TypeScript

// Metro module 10853 (f10854).
import { useEffect } from "react";
import ApplicationStreamPreviewStore from "../../stores/ApplicationStreamPreviewStore";
import ChannelStore from "../../stores/ChannelStore";
import PermissionStore from "../../stores/PermissionStore";
import SelectedChannelStore from "../../stores/SelectedChannelStore";
import { BasicPermissions } from "../../_bundle/Module505";
import { useStateFromStores, useStateFromStoresObject } from "../../_bundle/Module589";
import { fetchStreamPreview } from "../../actions/StreamActionCreators";
export default function useFetchStreamPreview(a0, a1, a2) {
let shouldFetchPreview, stateFromStores2;
const r0 = a1 == null || a2 == null;
let c18313_3 = r0;
const stateFromStores = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(a1));
let r24 = useStateFromStores([PermissionStore], () => stateFromStores != null && PermissionStore.canBasicChannel(BasicPermissions.CONNECT, stateFromStores));
const stateFromStores3 = useStateFromStores([SelectedChannelStore], () => SelectedChannelStore.getVoiceChannelId() === a1);
const stateFromStoresObject = useStateFromStoresObject([ApplicationStreamPreviewStore], () => {
let isLoading = !c18313_3;
const shouldFetchPreview2 = c18313_3 ? isLoading : ApplicationStreamPreviewStore.shouldFetchPreview(a0, a1, a2);
const previewUrl = c18313_3 ? null : ApplicationStreamPreviewStore.getPreviewURL(a0, a1, a2);
if (!c18313_3) {
isLoading = ApplicationStreamPreviewStore.getIsPreviewLoading(a0, a1, a2);
}
return {
shouldFetchPreview: shouldFetchPreview2,
previewUrl,
isLoading
};
});
shouldFetchPreview = stateFromStoresObject.shouldFetchPreview;
const { previewUrl, isLoading } = stateFromStoresObject;
if (!r24) {
r24 = stateFromStores3;
}
stateFromStores2 = r24;
useEffect(() => {
let r2 = shouldFetchPreview;
if (shouldFetchPreview) {
r2 = !c18313_3;
}
if (r2) {
r2 = stateFromStores2;
}
if (r2) {
fetchStreamPreview(a0, a1, a2);
}
}, [shouldFetchPreview, a1, a0, a2, r0, stateFromStores2]);
return !r0 && stateFromStores2 ? {
previewUrl,
isLoading
} : {
previewUrl: void 0,
isLoading: false
};
};