509 lines
18 KiB
TypeScript
509 lines
18 KiB
TypeScript
// Metro module 1931 (f1932).
|
|
import { THREAD_CHANNEL_TYPES, isGuildTextChannelType } from "../records/ChannelRecord";
|
|
import AuthenticationStore from "./AuthenticationStore";
|
|
import ChannelStore from "./ChannelStore";
|
|
import GuildChannelStore from "./GuildChannelStore";
|
|
import GuildStore from "./GuildStore";
|
|
import MediaEngineStore from "./MediaEngineStore";
|
|
import PermissionStore from "./PermissionStore";
|
|
import SelectedGuildStore from "./SelectedGuildStore";
|
|
import { Permissions, Routes, ME, ChannelTypes } from "../Constants";
|
|
import "../modules/channel/ChannelConstants";
|
|
import { Storage } from "../_bundle/Module595";
|
|
import Module12 from "../_bundle/Module12";
|
|
import { isNotNullish } from "../utils/GlobalUtils";
|
|
import { combine } from "../_bundle/HighLow";
|
|
import Module589 from "../_bundle/Module589";
|
|
import Dispatcher from "../Dispatcher";
|
|
function $mk70646($env) {
|
|
return (a0, a1) => {
|
|
let r1 = a0 != null;
|
|
if (r1) {
|
|
const r3 = $env.$parent;
|
|
r1 = r3[14].hasChannel(a0) || a0 === r3[6] || r3[28].has(a0) || (0, r3[23])(a0);
|
|
}
|
|
if (!r1) {
|
|
const r12 = $env;
|
|
const r14 = $env.$parent;
|
|
delete r14[25][a1];
|
|
delete r14[26][a1];
|
|
r12[0] = true;
|
|
}
|
|
};
|
|
}
|
|
function $mk70647($env) {
|
|
return (a0, a1) => {
|
|
let r1 = a0 != null;
|
|
if (r1) {
|
|
const r3 = $env.$parent;
|
|
r1 = r3[14].hasChannel(a0) || r3[28].has(a0);
|
|
}
|
|
if (!r1) {
|
|
const r9 = $env;
|
|
delete $env.$parent[27][a1];
|
|
r9[0] = true;
|
|
}
|
|
};
|
|
}
|
|
let navigateAwayFromChannel, c1617_24, c1617_30;
|
|
let $mk70645 = function() {
|
|
return (a0) => {
|
|
const basicChannel = ChannelStore.getBasicChannel(a0);
|
|
return env1617[28].has(a0) || basicChannel != null && THREAD_CHANNEL_TYPES.has(basicChannel.type);
|
|
};
|
|
}, $mk70648 = function() {
|
|
return (a0) => {
|
|
const r9 = env1617[25][a0.id];
|
|
if (env1617[27][a0.id] == null) {
|
|
const id = a0.id;
|
|
if (id != null && r9 != null && env1617[27][id] !== r9) {
|
|
const channel = ChannelStore.getChannel(r9);
|
|
const r17 = channel != null && (0, isGuildTextChannelType)(channel.type);
|
|
const r20 = channel == null ? void 0 : channel.getGuildId();
|
|
if (!(r17 ? !(r20 === id) : !r17)) {
|
|
env1617[27][id] = r9;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
let env1617 = {};
|
|
export function handleConnectionOpen(a0) {
|
|
env1617[4] = a0.sessionId;
|
|
if (env1617[8] != null) {
|
|
const channel = ChannelStore.getChannel(env1617[8]);
|
|
if (!(channel != null && (channel.isPrivate() || PermissionStore.can(combine(Permissions.VIEW_CHANNEL, Permissions.CONNECT), channel)))) {
|
|
env1617[8] = null;
|
|
}
|
|
}
|
|
let env13348;
|
|
const r29 = env13348 = {
|
|
$parent: env1617
|
|
};
|
|
env13348[0] = false;
|
|
const guildsArray = GuildStore.getGuildsArray();
|
|
Module12.each(env1617[25], $mk70646(r29));
|
|
Module12.each(env1617[27], $mk70647(r29));
|
|
guildsArray.forEach($mk70648());
|
|
if (env1617[9] != null && Date.now() - env1617[9] >= 300000) {
|
|
env1617[8] = null;
|
|
env13348[0] = true;
|
|
}
|
|
if (env13348[0]) {
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
}
|
|
}
|
|
navigateAwayFromChannel = function navigateAwayFromChannel(a0, a1) {
|
|
env1617[28].delete(a0);
|
|
let r5 = a1;
|
|
if (a1 == null) {
|
|
const guildId = SelectedGuildStore.getGuildId();
|
|
r5 = env1617[25][String(guildId)] === a0 ? guildId : a1;
|
|
}
|
|
GuildStore.getGuild(r5);
|
|
const r25 = env1617[8];
|
|
let r26 = false;
|
|
if (r25 === a0) {
|
|
env1617[8] = null;
|
|
r26 = true;
|
|
}
|
|
if (r26) {
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
}
|
|
};
|
|
const handleChannelDelete = function handleChannelDelete(a0) {
|
|
a0.type;
|
|
const channel = a0.channel;
|
|
navigateAwayFromChannel(channel.id, channel.guild_id, channel.parent_id);
|
|
};
|
|
Routes;
|
|
c1617_24 = "SelectedChannelStore";
|
|
env1617[25] = {};
|
|
env1617[26] = {};
|
|
env1617[27] = {};
|
|
env1617[28] = new Set();
|
|
class SelectedChannelStore extends Module589.Store {
|
|
static displayName = "SelectedChannelStore";
|
|
constructor() {
|
|
super(...arguments);
|
|
}
|
|
initialize() {
|
|
let r23 = Storage.get(c1617_24);
|
|
if (r23 == null) {
|
|
r23 = {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27]
|
|
};
|
|
}
|
|
if (r23.knownThreadIds != null) {
|
|
env1617[28] = new Set(r23.knownThreadIds);
|
|
}
|
|
env1617[8] = r23.selectedVoiceChannelId;
|
|
env1617[7] = r23.lastChannelFollowingDestination;
|
|
env1617[9] = r23.lastConnectedTime;
|
|
let mostRecentSelectedTextChannelIds = r23.mostRecentSelectedTextChannelIds;
|
|
if (mostRecentSelectedTextChannelIds == null) {
|
|
mostRecentSelectedTextChannelIds = {};
|
|
}
|
|
env1617[27] = mostRecentSelectedTextChannelIds;
|
|
if (r23.selectedChannelIds != null) {
|
|
env1617[25] = r23.selectedChannelIds;
|
|
}
|
|
this.mustEmitChanges((a0) => a0.type !== "CONNECTION_OPEN" && a0.type !== "VOICE_STATE_UPDATES");
|
|
this.waitFor(AuthenticationStore, ChannelStore, GuildChannelStore, GuildStore, MediaEngineStore, PermissionStore, SelectedGuildStore);
|
|
}
|
|
getChannelId(a0, r3 = true) {
|
|
let r15;
|
|
let r4 = a0;
|
|
let r5 = null;
|
|
if (a0 !== ME) {
|
|
if (a0 == null) {
|
|
r4 = SelectedGuildStore.getGuildId();
|
|
}
|
|
if (r4 == null) {
|
|
r4 = null;
|
|
}
|
|
r5 = r4;
|
|
}
|
|
const r12 = String(r5);
|
|
const r14 = env1617[25][r12];
|
|
if (r3) {
|
|
let r16 = r14;
|
|
if (r14 == null) {
|
|
const r2 = r12 != null;
|
|
let r17 = void 0;
|
|
if (r2) {
|
|
const defaultChannel = GuildChannelStore.getDefaultChannel(r12);
|
|
r17 = defaultChannel != null ? defaultChannel.id : void 0;
|
|
}
|
|
r16 = r17;
|
|
}
|
|
r15 = r16;
|
|
} else {
|
|
r15 = r14;
|
|
}
|
|
return r15;
|
|
}
|
|
getVoiceChannelId() {
|
|
return MediaEngineStore.isSupported() ? env1617[8] : null;
|
|
}
|
|
getMostRecentSelectedTextChannelId(a0) {
|
|
const r1 = a0 == null;
|
|
let r2 = null;
|
|
if (!r1) {
|
|
let r6 = env1617[27][a0];
|
|
if (r6 == null) {
|
|
r6 = null;
|
|
}
|
|
r2 = r6;
|
|
}
|
|
return r2;
|
|
}
|
|
getCurrentlySelectedChannelId(a0) {
|
|
return a0 != null ? env1617[25][a0] : env1617[6];
|
|
}
|
|
getLastSelectedChannelId(a0) {
|
|
return a0 != null ? env1617[26][a0] : env1617[5];
|
|
}
|
|
getLastSelectedChannels(a0) {
|
|
return env1617[26][a0];
|
|
}
|
|
getLastChannelFollowingDestination() {
|
|
return env1617[7];
|
|
}
|
|
}
|
|
c1617_30 = SelectedChannelStore;
|
|
const r91 = new SelectedChannelStore(Dispatcher, {
|
|
CONNECTION_OPEN: handleConnectionOpen,
|
|
OVERLAY_INITIALIZE: function handleOverlayInitialize(a0) {
|
|
env1617[4] = a0.sessionId;
|
|
env1617[8] = a0.selectedVoiceChannelId;
|
|
env1617[25] = {};
|
|
env1617[26] = {};
|
|
env1617[6] = a0.selectedChannelId;
|
|
env1617[25][a0.selectedGuildId] = a0.selectedChannelId;
|
|
const selectedGuildId = a0.selectedGuildId;
|
|
const r20 = env1617[6];
|
|
if (selectedGuildId != null && r20 != null && env1617[27][selectedGuildId] !== r20) {
|
|
const channel = ChannelStore.getChannel(r20);
|
|
const r25 = channel != null && (0, isGuildTextChannelType)(channel.type);
|
|
const r28 = channel == null ? void 0 : channel.getGuildId();
|
|
if (!(r25 ? !(r28 === selectedGuildId) : !r25)) {
|
|
env1617[27][selectedGuildId] = r20;
|
|
}
|
|
}
|
|
let env13349;
|
|
const r32 = env13349 = {
|
|
$parent: env1617
|
|
};
|
|
env13349[0] = false;
|
|
const guildsArray = GuildStore.getGuildsArray();
|
|
Module12.each(env1617[25], $mk70646(r32));
|
|
Module12.each(env1617[27], $mk70647(r32));
|
|
guildsArray.forEach($mk70648());
|
|
if (env1617[9] != null && Date.now() - env1617[9] >= 300000) {
|
|
env1617[8] = null;
|
|
env13349[0] = true;
|
|
}
|
|
},
|
|
CONNECTION_CLOSED: function handleConnectionClosed() {
|
|
env1617[4] = null;
|
|
},
|
|
CHANNEL_SELECT: function handleChannelSelect(a0) {
|
|
const guildId = a0.guildId;
|
|
let channelId = a0.channelId;
|
|
if (guildId === void 0) {
|
|
return false;
|
|
}
|
|
if (channelId == null) {
|
|
const r2 = guildId != null;
|
|
let r16 = void 0;
|
|
if (r2) {
|
|
const defaultChannel = GuildChannelStore.getDefaultChannel(guildId);
|
|
r16 = defaultChannel != null ? defaultChannel.id : void 0;
|
|
}
|
|
channelId = r16;
|
|
}
|
|
if (env1617[6] != null && channelId !== env1617[6]) {
|
|
env1617[5] = env1617[6];
|
|
}
|
|
env1617[6] = channelId;
|
|
if (guildId != null && channelId != null && env1617[27][guildId] !== channelId) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const r27 = channel != null && (0, isGuildTextChannelType)(channel.type);
|
|
const r31 = channel == null ? void 0 : channel.getGuildId();
|
|
if (!(r27 ? !(r31 === guildId) : !r27)) {
|
|
env1617[27][guildId] = channelId;
|
|
}
|
|
}
|
|
if (env1617[25][String(guildId)] !== channelId) {
|
|
env1617[26][String(guildId)] = env1617[25][String(guildId)];
|
|
env1617[25][String(guildId)] = env1617[6];
|
|
}
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
},
|
|
CHANNEL_CREATE: function handleChannelCreate({ channel }) {
|
|
const type = channel.type;
|
|
if (!(ChannelTypes.GUILD_ANNOUNCEMENT !== type && ChannelTypes.GUILD_TEXT !== type)) {
|
|
const guild_id = channel.guild_id;
|
|
if (guild_id != null && env1617[27][guild_id] == null) {
|
|
env1617[27][guild_id] = channel.id;
|
|
}
|
|
if (guild_id != null && env1617[25][guild_id] == null) {
|
|
const r18 = env1617[25];
|
|
const r2 = guild_id != null;
|
|
let r19 = void 0;
|
|
if (r2) {
|
|
const defaultChannel = GuildChannelStore.getDefaultChannel(guild_id);
|
|
r19 = defaultChannel != null ? defaultChannel.id : void 0;
|
|
}
|
|
r18[guild_id] = r19;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
CHANNEL_DELETE: handleChannelDelete,
|
|
CHANNEL_UPDATES: function handleChannelUpdates(a0) {
|
|
for (const channel of a0.channels) {
|
|
if (channel.isScheduledForDeletion()) {
|
|
THREAD_CHANNEL_TYPES.has(channel.type);
|
|
navigateAwayFromChannel(channel.id, channel.guild_id, channel.parent_id);
|
|
}
|
|
}
|
|
},
|
|
THREAD_DELETE: handleChannelDelete,
|
|
GUILD_CREATE: function handleGuildCreate({ guild }) {
|
|
if (env1617[25][guild.id] == null) {
|
|
const id = guild.id;
|
|
const r2 = id != null;
|
|
let r17 = void 0;
|
|
if (r2) {
|
|
const defaultChannel = GuildChannelStore.getDefaultChannel(id);
|
|
r17 = defaultChannel != null ? defaultChannel.id : void 0;
|
|
}
|
|
env1617[25][guild.id] = r17;
|
|
const id2 = guild.id;
|
|
if (id2 != null && r17 != null && env1617[27][id2] !== r17) {
|
|
const channel = ChannelStore.getChannel(r17);
|
|
const r28 = channel != null && (0, isGuildTextChannelType)(channel.type);
|
|
const r32 = channel == null ? void 0 : channel.getGuildId();
|
|
if (!(r28 ? !(r32 === id2) : !r28)) {
|
|
env1617[27][id2] = r17;
|
|
}
|
|
}
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
}
|
|
},
|
|
GUILD_DELETE: function handleGuildDelete({ guild }) {
|
|
const { id, unavailable } = guild;
|
|
if (env1617[8] === env1617[25][id]) {
|
|
env1617[8] = null;
|
|
}
|
|
if (unavailable) {
|
|
return false;
|
|
}
|
|
delete env1617[27][id];
|
|
delete env1617[25][id];
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
},
|
|
VOICE_CHANNEL_SELECT: function handleVoiceChannelSelect({ channelId }) {
|
|
if (channelId == null) {
|
|
const guild_id = ChannelStore.getChannel(env1617[8])?.guild_id;
|
|
if (guild_id != null && guild_id !== SelectedGuildStore.getGuildId() && env1617[25][guild_id] === env1617[8]) {
|
|
const r26 = env1617[25];
|
|
const r27 = guild_id != null;
|
|
let r28 = void 0;
|
|
if (r27) {
|
|
const defaultChannel = GuildChannelStore.getDefaultChannel(guild_id);
|
|
r28 = defaultChannel != null ? defaultChannel.id : void 0;
|
|
}
|
|
r26[guild_id] = r28;
|
|
}
|
|
}
|
|
env1617[8] = channelId;
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
},
|
|
VOICE_STATE_UPDATES: function handleVoiceStateUpdates(a0) {
|
|
return a0.voiceStates.reduce((acc, voiceState) => {
|
|
if (voiceState.sessionId === env1617[4]) {
|
|
clearInterval(env1617[10]);
|
|
const channel3 = ChannelStore.getChannel(env1617[8]);
|
|
if (!(voiceState.guildId !== (channel3 == null ? void 0 : channel3.getGuildId()) && voiceState.channelId == null)) {
|
|
env1617[8] = voiceState.channelId;
|
|
}
|
|
env1617[9] = Date.now();
|
|
if (env1617[8] != null) {
|
|
env1617[10] = setInterval(() => {
|
|
env1617[9] = Date.now();
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
}, 60000);
|
|
}
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
} else {
|
|
if (voiceState.userId !== AuthenticationStore.getId()) {
|
|
return acc;
|
|
}
|
|
clearInterval(env1617[10]);
|
|
env1617[10] = void 0;
|
|
env1617[9] = 0;
|
|
const channel = ChannelStore.getChannel(env1617[8]);
|
|
const r28 = channel == null ? void 0 : channel.getGuildId();
|
|
const channel2 = ChannelStore.getChannel(voiceState.channelId);
|
|
const r34 = channel2 == null ? void 0 : channel2.getGuildId();
|
|
if (r28 != null && r34 === r28 || env1617[8] === voiceState.channelId) {
|
|
env1617[8] = null;
|
|
}
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
}
|
|
return true;
|
|
}, false);
|
|
},
|
|
CHANNEL_FOLLOWER_CREATED: function handleChannelFollowingDestinationUpdate({ channelId, guildId }) {
|
|
if (!(env1617[7] != null && channelId === env1617[7].channelId)) {
|
|
env1617[7] = {
|
|
channelId,
|
|
guildId
|
|
};
|
|
Storage.set(c1617_24, {
|
|
selectedChannelId: env1617[6],
|
|
selectedVoiceChannelId: env1617[8],
|
|
lastChannelFollowingDestination: env1617[7],
|
|
lastConnectedTime: env1617[9],
|
|
selectedChannelIds: env1617[25],
|
|
mostRecentSelectedTextChannelIds: env1617[27],
|
|
knownThreadIds: Module12(env1617[25]).values().concat(Module12.values(env1617[27])).filter(isNotNullish).uniq().filter($mk70645()).value()
|
|
});
|
|
}
|
|
},
|
|
LOGOUT: function handleLogout() {
|
|
env1617[25] = {};
|
|
env1617[6] = null;
|
|
env1617[5] = void 0;
|
|
env1617[27] = {};
|
|
env1617[7] = {};
|
|
env1617[8] = null;
|
|
Storage.remove(c1617_24);
|
|
}
|
|
});
|
|
export default r91;
|
|
export function findFirstVoiceChannelId(a0) {
|
|
return Module12.find(ChannelStore.getMutableBasicGuildChannelsForGuild(a0), (a0) => a0.type === ChannelTypes.GUILD_VOICE)?.id;
|
|
}
|