Files
discord-decomp/stores/VoiceStateStore.tsx
T
2026-11-01 12:12:55 +02:00

452 lines
12 KiB
TypeScript

// Metro module 4205 (f4206).
import _slicedToArray from "../_bundle/_slicedToArray";
import VoiceStateRecord from "../records/VoiceStateRecord";
import { ME } from "../Constants";
import { VoicePlatforms } from "../modules/calls/CallConstants";
import Module12 from "../_bundle/Module12";
import Module589 from "../_bundle/Module589";
import { isMetaQuest } from "../modules/device/MetaQuestUtils.android";
import Dispatcher from "../Dispatcher";
function $mk73816($env) {
return (a0, a1) => {
if (a0.channelId === $env[0]) {
const r8 = $env.$parent;
(0, r8[18])(r8[7], a1, () => null);
}
};
}
function $mk73817($env) {
return (a0) => {
const r7 = $env[0];
if (r7.channelId == null) {
return null;
}
const r3 = {
channelId: r7.channelId,
deaf: r7.deaf,
mute: r7.mute,
requestToSpeakTimestamp: r7.requestToSpeakTimestamp,
selfDeaf: r7.selfDeaf,
selfMute: r7.selfMute,
selfStream: r7.selfStream,
selfVideo: r7.selfVideo,
sessionId: r7.sessionId,
suppress: r7.suppress,
userId: r7.userId,
discoverable: r7.discoverable,
connectedAt: r7.connectedAt
};
return a0 != null ? a0.merge(r3) : new $env.$parent[6](r3);
};
}
let mergeVoiceState, c2425_12, c2425_13, c2425_17, c2425_20;
let env2425 = {};
const updateVoiceState = function updateVoiceState(a0, a1, a2) {
let r98;
let r7 = a0;
const r8 = env2425[11];
const r6 = a0 == null ? ME : a0;
let r4 = r8[r6];
if (r4 == null) {
const r5 = {};
r8[r6] = r5;
r4 = r5;
}
const r19 = r4[a1];
const r20 = a2(r19);
if (r19 === r20) {
r98 = [false, r20, r19];
} else {
if (r19 != null) {
delete r4[a1];
if (r19.channelId != null) {
const r12 = env2425[14];
const channelId2 = r19.channelId;
let r22 = r12[channelId2];
if (r22 == null) {
const r10 = {};
r12[channelId2] = r10;
r22 = r10;
}
delete r22[a1];
const r24 = env2425[15];
const channelId3 = r19.channelId;
let r26 = r24[channelId3];
if (r26 == null) {
const r27 = {};
r24[channelId3] = r27;
r26 = r27;
}
delete r26[a1];
}
if (r19.sessionId != null) {
const r30 = env2425[16];
let r31 = r30[a1];
if (r31 == null) {
const r32 = {};
r30[a1] = r32;
r31 = r32;
}
delete r31[r19.sessionId];
}
const r35 = a0 == null ? ME : a0;
let r38 = c2425_13.get(r35);
if (r38 == null) {
r38 = new Set();
}
const r43 = r38.has(a1);
const r44 = r38;
if (r43) {
const set = new Set(r44);
set.delete(a1);
if (set.size === 0) {
c2425_13.delete(r35);
} else {
c2425_13.set(r35, set);
}
}
}
if (r20 != null) {
r4[a1] = r20;
if (r20.channelId != null) {
const r59 = env2425[14];
const channelId4 = r20.channelId;
let r61 = r59[channelId4];
if (r61 == null) {
const r62 = {};
r59[channelId4] = r62;
r61 = r62;
}
r61[a1] = r20;
if (r20.selfVideo) {
const r64 = env2425[15];
const channelId5 = r20.channelId;
let r66 = r64[channelId5];
if (r66 == null) {
const r67 = {};
r64[channelId5] = r67;
r66 = r67;
}
r66[a1] = r20;
if (a0 == null) {
r7 = ME;
}
const r70 = c2425_13.get(r7);
const r71 = r7;
let r72 = r70;
if (r72 == null) {
r72 = new Set();
}
const r79 = r72.has(a1);
const r80 = r72;
if (!r79) {
const set2 = new Set(r80);
set2.add(a1);
c2425_13.set(r71, set2);
}
}
}
if (r20.sessionId != null) {
const r93 = env2425[16];
let r94 = r93[a1];
if (r94 == null) {
const r95 = {};
r93[a1] = r95;
r94 = r95;
}
r94[r20.sessionId] = r20;
}
}
r98 = [true, r20, r19];
}
return r98;
};
mergeVoiceState = function mergeVoiceState(a0, a1) {
let env13976;
const r1 = env13976 = {
$parent: env2425
};
env13976[0] = a1;
return updateVoiceState(a0, a1.userId, $mk73817(r1));
};
const handleGuildCreateOrDelete = function handleGuildCreateOrDelete({ guild }) {
Module12.forEach(env2425[11][guild.id], (a0) => {
updateVoiceState(guild.id, a0.userId, () => null);
});
delete env2425[11][guild.id];
};
env2425[9] = 0;
env2425[10] = 0;
env2425[11] = {};
c2425_12 = new Set();
c2425_13 = new Map();
env2425[14] = {};
env2425[15] = {};
env2425[16] = {};
c2425_17 = {};
class VoiceStateStore extends Module589.Store {
static displayName = "VoiceStateStore";
constructor() {
super(...arguments);
}
getAllVoiceStates() {
return env2425[11];
}
getVoiceStateVersion() {
return env2425[10];
}
getVoiceStates(a0) {
let r4 = a0;
const r3 = env2425[11];
if (a0 == null) {
r4 = ME;
}
let r5 = r3[r4];
if (r5 == null) {
const r2 = {};
r3[r4] = r2;
r5 = r2;
}
return r5;
}
getVoiceStatesForChannel(a0) {
const r3 = env2425[14];
let r5 = r3[a0];
if (r5 == null) {
const r2 = {};
r3[a0] = r2;
r5 = r2;
}
return r5;
}
getVideoVoiceStatesForChannel(a0) {
const r3 = env2425[15];
let r5 = r3[a0];
if (r5 == null) {
const r2 = {};
r3[a0] = r2;
r5 = r2;
}
return r5;
}
getVoiceState(a0, a1) {
return this.getVoiceStates(a0)[a1];
}
getDiscoverableVoiceState(a0, a1) {
const voiceState = this.getVoiceState(a0, a1);
return voiceState == null ? null : voiceState.discoverable !== false ? voiceState : null;
}
getVoiceStateForChannel(a0, r3 = env2425[3]) {
const r5 = env2425[14];
let r7 = r5[a0];
if (r7 == null) {
const r4 = {};
r5[a0] = r4;
r7 = r4;
}
return r7 == null ? void 0 : r7[r3];
}
getVoiceStateForUser(a0) {
const r3 = Object;
const r5 = env2425[16];
let r8 = r5[a0];
if (r8 == null) {
const r4 = {};
r5[a0] = r4;
r8 = r4;
}
return r3.values(r8)[0];
}
getDiscoverableVoiceStateForUser(a0) {
const r3 = Object;
const r5 = env2425[16];
let r8 = r5[a0];
if (r8 == null) {
const r4 = {};
r5[a0] = r4;
r8 = r4;
}
return r3.values(r8).find((item) => item.discoverable !== false);
}
getVoiceStateForSession(a0, a1) {
const r1 = a1 != null;
let r2 = null;
if (r1) {
const r6 = env2425[16];
let r4 = r6[a0];
if (r4 == null) {
const r8 = {};
r6[a0] = r8;
r4 = r8;
}
r2 = r4 == null ? void 0 : r4[a1];
}
return r2;
}
getUserVoiceChannelId(a0, a1) {
return this.getVoiceState(a0, a1)?.channelId;
}
getCurrentClientVoiceChannelId(a0) {
const voiceState = this.getVoiceState(a0, env2425[3]);
return voiceState != null ? env2425[4] != null ? voiceState.sessionId === env2425[4] ? voiceState.channelId : null : null : null;
}
getUsersWithVideo(a0) {
let r5 = c2425_13.get(a0);
if (r5 == null) {
r5 = c2425_12;
}
return r5;
}
isCurrentClientInVoiceChannel() {
let r0 = env2425[4] != null;
if (r0) {
const r7 = env2425[16][env2425[3]];
r0 = (r7 == null ? void 0 : r7[env2425[4]]) != null;
}
return r0;
}
isInChannel(a0, r7 = env2425[3]) {
if (a0 == null) {
return false;
}
const voiceStateForChannel = this.getVoiceStateForChannel(a0, r7);
return voiceStateForChannel != null && (r7 !== env2425[3] || env2425[4] != null && voiceStateForChannel.sessionId === env2425[4]);
}
hasVideo(a0) {
const r4 = Object;
const r6 = env2425[15];
let r9 = r6[a0];
if (r9 == null) {
const r5 = {};
r6[a0] = r5;
r9 = r5;
}
return r4.values(r9).length > 0;
}
getVoicePlatformForChannel(a0, a1) {
let r10 = env2425[4] != null;
if (r10) {
const r7 = env2425[16][env2425[3]];
r10 = r7 == null ? void 0 : r7[env2425[4]]?.channelId;
}
return a1 === env2425[3] && a0 === r10 ? isMetaQuest() ? VoicePlatforms.QUEST : VoicePlatforms.MOBILE : c2425_17[`${a1}:${a0}`];
}
get userHasBeenMovedVersion() {
return env2425[9];
}
}
c2425_20 = VoiceStateStore;
const r101 = new VoiceStateStore(Dispatcher, {
CONNECTION_OPEN: function handleConnectionOpen({ user, sessionId }) {
const r8 = env2425[3] != null && env2425[3] !== user.id;
if (r8) {
env2425[11] = {};
env2425[14] = {};
env2425[16] = {};
env2425[15] = {};
c2425_13.clear();
}
env2425[3] = user.id;
env2425[4] = sessionId;
return r8;
},
CONNECTION_OPEN_SUPPLEMENTAL: function handleConnectionOpenSupplemental() {
env2425[11] = {};
env2425[14] = {};
env2425[16] = {};
env2425[15] = {};
c2425_13.clear();
},
OVERLAY_INITIALIZE: function handleOverlayInitialize({ voiceStates, user, sessionId }) {
let c13978_0, c13978_1;
c13978_0 = void 0;
c13978_1 = void 0;
env2425[11] = {};
env2425[14] = {};
env2425[16] = {};
env2425[15] = {};
for (const item of Object.entries(voiceStates)) {
let r12;
[c13978_0, r12] = item;
const _loop = function _loop(c24972_0) {
updateVoiceState(c13978_0, c13978_1, () => new VoiceStateRecord(c24972_0));
};
for (const item2 of Object.entries(r12)) {
const r51 = _slicedToArray(item2, 2);
c13978_1 = r51[0];
_loop(r51[1]);
}
}
env2425[3] = user.id;
env2425[4] = sessionId;
},
VOICE_CHANNEL_SELECT: function handleVoiceChannelSelect({ guildId, channelId }) {
return _slicedToArray(updateVoiceState(guildId, env2425[3], (a0) => a0 == null ? void 0 : a0.set("channelId", channelId)), 1)[0];
},
VOICE_STATE_UPDATES: function handleVoiceStateUpdates(a0) {
return a0.voiceStates.reduce((r3, voiceState) => {
let env24973;
const guildId = voiceState.guildId;
const r5 = env24973 = {
$parent: env2425
};
env24973[0] = voiceState;
const [r15, r16, r17] = updateVoiceState(guildId, voiceState.userId, $mk73817(r5));
if (r15) {
if (voiceState.sessionId === env2425[4] && r16 != null && r17 != null && r17.channelId !== r16.channelId) {
env2425[9] = env2425[9] + 1;
}
env2425[10] = env2425[10] + 1;
r3 = true;
}
return r3;
}, false);
},
GUILD_DELETE: handleGuildCreateOrDelete,
GUILD_CREATE: handleGuildCreateOrDelete,
CHANNEL_DELETE: function handleChannelDelete(a0) {
let env13980;
const id = a0.channel.id;
const r6 = env13980 = {
$parent: env2425
};
env13980[0] = id;
let r8 = env2425[11][ME];
if (r8 == null) {
r8 = {};
}
Module12.each(r8, $mk73816(r6));
},
CALL_DELETE: function handleCallDelete({ channelId: channelId2 }) {
let env13981;
const r5 = env13981 = {
$parent: env2425
};
env13981[0] = channelId2;
let r7 = env2425[11][ME];
if (r7 == null) {
r7 = {};
}
Module12.each(r7, $mk73816(r5));
},
PASSIVE_UPDATE_V2: function handlePassiveUpdateV2(a0) {
let r0 = false;
for (const voiceState of a0.voiceStates) {
const [r33] = mergeVoiceState(a0.guildId, voiceState);
r0 = r0 || r33;
}
for (const removedVoiceStateUser of a0.removedVoiceStateUsers) {
updateVoiceState(a0.guildId, removedVoiceStateUser, () => null);
r0 = true;
}
if (r0) {
env2425[10] = env2425[10] + 1;
}
return r0;
},
RTC_CONNECTION_PLATFORM: function handleRTCConnectionPlatform(a0) {
c2425_17[`${a0.userId}:${a0.channelId}`] = a0.platform;
}
});
export default r101;