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

144 lines
4.7 KiB
TypeScript

// Metro module 5759 (f5760).
import { useMemo, useState, useEffect } from "react";
import ConnectedAccountsStore from "../../stores/ConnectedAccountsStore";
import UserStore from "../../stores/UserStore";
import { PlatformTypes, ACTIVITY_PLATFORM_TYPES } from "../../Constants";
import { KeyboardKeysUpdated } from "../../_bundle/Module5760";
import Durations from "../../utils/Durations";
import { useStateFromStores } from "../../_bundle/Module589";
import { PlayStationVoiceExperiment } from "../game_console/PlayStationVoiceExperiment";
import Module12 from "../../_bundle/Module12";
import Platforms from "../../lib/Platforms";
function $mk76953($env) {
return (a0) => {
let r18;
const r3 = $env;
const type = a0.type;
const r2 = $env.$parent;
if (type === r2[8].PLAYSTATION_STAGING) {
r18 = r3[2];
} else {
const r11 = r3[1];
let r0 = r11 === void 0;
if (!r0) {
const r8 = r2[10][a0.type];
r0 = !(r8 == null ? void 0 : r8.includes(r11.id));
}
r18 = !r0;
if (r0) {
let r21 = !!r3[0];
if (!r21) {
const migrationData = a0.migrationData;
const r24 = migrationData == null ? void 0 : migrationData.getMigrationExperimentEnabled("ConnectionsHooks");
r21 = r24 ? !r24 : a0.enabled;
}
r18 = r21;
}
}
return r18;
};
}
let $mk76952 = function() {
return () => UserStore.getCurrentUser();
};
let env3587 = {};
const PlatformTypes2 = PlatformTypes;
const r36 = {};
r36[PlatformTypes2.INSTAGRAM] = ["1036753656588017764"];
const c3587_10 = r36;
const c3587_11 = new Map([[PlatformTypes2.INSTAGRAM, new Date(2023, 1, 18).getTime()]]);
const c3587_12 = 30 * Durations.Millis.DAY;
const c3587_13 = new Map([[PlatformTypes2.PLAYSTATION, 2], [PlatformTypes2.XBOX, 2], [PlatformTypes2.SPOTIFY, 1], [PlatformTypes2.STEAM, 1], [PlatformTypes2.TWITCH, 1]]);
export function usePlatformAllowed(a0) {
let env15098;
const r1 = env15098 = {
$parent: env3587
};
env15098[0] = a0.forUserProfile;
env15098[1] = void 0;
env15098[2] = void 0;
env15098[1] = useStateFromStores([UserStore], $mk76952());
env15098[2] = PlayStationVoiceExperiment.useConfig({
location: "f2f7ef_1"
}).allowPlayStationStaging;
return $mk76953(r1);
}
export function usePlatforms() {
let c15099_1, memo;
let env15100;
const stateFromStores = useStateFromStores([ConnectedAccountsStore], () => ConnectedAccountsStore.getAccounts());
const r15 = env15100 = {
$parent: env3587
};
env15100[0] = false;
env15100[1] = void 0;
env15100[2] = void 0;
env15100[1] = useStateFromStores([UserStore], $mk76952());
env15100[2] = PlayStationVoiceExperiment.useConfig({
location: "f2f7ef_1"
}).allowPlayStationStaging;
const r28 = $mk76953(r15);
c15099_1 = r28;
memo = useMemo(() => {
const set = new Set();
let c25599_0 = set;
stateFromStores.forEach((stateFromStore) => c25599_0.add(stateFromStore.type));
return set;
}, [stateFromStores]);
return useMemo(() => Module12.sortBy(Platforms.filter(c15099_1), [(a0) => {
let r8 = c3587_11.has(a0.type);
if (r8) {
const r11 = Date.now();
let r14 = c3587_11.get(a0.type);
if (r14 == null) {
r14 = 0;
}
r8 = r11 < r14 + c3587_12;
}
return !r8;
}, (a0) => memo.has(a0.type), (a0) => a0.hasMetadata, (a0) => !ACTIVITY_PLATFORM_TYPES.has(a0.type), (a0) => a0.name]), [memo, r28]);
}
export function useEmptyStatePlatforms() {
let env15102;
const r3 = env15102 = {
$parent: env3587
};
env15102[0] = false;
env15102[1] = useStateFromStores([UserStore], $mk76952());
env15102[2] = PlayStationVoiceExperiment.useConfig({
location: "f2f7ef_1"
}).allowPlayStationStaging;
const r21 = $mk76953(r3);
let c15101_0 = r21;
return useMemo(() => Module12.sortBy(Platforms.filter(c15101_0), [(a0) => {
let r7 = c3587_13.get(a0.type);
if (r7 == null) {
r7 = 0;
}
return -1 * r7;
}, (a0) => a0.name]), [r21]);
}
export function useLegacyPlatformType(a0) {
let handleKeyUp2;
const handleKeyDown2 = function handleKeyDown(a0) {
if (a0.key === KeyboardKeysUpdated.SHIFT) {
setState(true);
}
};
handleKeyUp2 = function handleKeyUp(a0) {
if (a0.key === KeyboardKeysUpdated.SHIFT) {
setState(false);
}
};
const [state, setState] = useState(false);
useEffect(() => {
window.addEventListener("keydown", handleKeyDown2);
window.addEventListener("keyup", handleKeyUp2);
return () => {
window.removeEventListener("keydown", handleKeyDown2);
window.removeEventListener("keyup", handleKeyUp2);
};
}, []);
return state ? a0 === PlatformTypes.TWITTER ? PlatformTypes.TWITTER_LEGACY : a0 : a0;
}