995 lines
31 KiB
TypeScript
995 lines
31 KiB
TypeScript
// Metro module 1372 (f1373).
|
|
import BasicChannelCacheStore from "../modules/app_database/stores/BasicChannelCacheStore";
|
|
import FavoriteStore from "../modules/favorites/FavoriteStore";
|
|
import { castChannelRecord, GUILD_CHANNEL_TYPES, ALL_CHANNEL_TYPES, createChannelRecordFromServer, THREAD_CHANNEL_TYPES, isPrivate } from "../records/ChannelRecord";
|
|
import AuthenticationStore from "./AuthenticationStore";
|
|
import GuildStore from "./GuildStore";
|
|
import UserStore from "./UserStore";
|
|
import { ChannelTypes } from "../Constants";
|
|
import Logger from "../modules/debug/Logger";
|
|
import { isNotNullish } from "../utils/GlobalUtils";
|
|
import DatabaseDaos from "../modules/app_database/DatabaseDaos";
|
|
import { tryLoadOrResetCacheGateway, tryLoadOrResetCacheGatewayAsync } from "../modules/app_database/app/TryLoad";
|
|
import ChannelReader from "../modules/app_database/modules/channels/ChannelReader";
|
|
import Dispatcher from "../Dispatcher";
|
|
import deserializeChannels, { deserializeChannel } from "../modules/cache/deserializeChannels";
|
|
import Module10 from "../_bundle/Module10";
|
|
import SnowflakeUtils from "../utils/SnowflakeUtils";
|
|
import isChangelogUser from "../modules/changelog/utils/isChangelogUser";
|
|
import Module12 from "../_bundle/Module12";
|
|
import Module589 from "../_bundle/Module589";
|
|
function $mk113775($env) {
|
|
return (a0) => !$env[29].has(a0.guildId);
|
|
}
|
|
let deleteGuildChannels, getBasicChannel2, getChannel2, setChannel, setPrivateChannel, setThread, setGuildChannel, handleOneGuildCreate, deleteChannel, addThreadIfMissing, handleFavoritesUpdate, guildChannelCount, c1139_17, c1139_18, c1139_49, c1139_35, c1139_50;
|
|
let $mk69131 = function() {
|
|
return (a0) => isChangelogUser(a0);
|
|
};
|
|
let env1139 = {};
|
|
const ensureGuildLoaded = function ensureGuildLoaded(a0, a1, a2) {
|
|
let c13000_0, c13000_1;
|
|
L17: {
|
|
c13000_0 = a0;
|
|
if (a0 != null && a0 !== "null" && !env1139[29].has(a0)) {
|
|
if (a1 === c1139_35.Basic && BasicChannelCacheStore.hasGuild(a0)) {
|
|
break L17;
|
|
}
|
|
const r7 = DatabaseDaos.database();
|
|
c13000_1 = r7;
|
|
if (r7 != null) {
|
|
c1139_17.verbose(`hydrating guild (guild: ${a0}, trace: ${a2})`);
|
|
const r57 = tryLoadOrResetCacheGateway(`ensureGuildLoaded(${a0})`, () => ChannelReader.getSync(c13000_1, c13000_0), "ensureGuildLoaded");
|
|
if (r57 == null) {
|
|
env1139[29].add(a0);
|
|
BasicChannelCacheStore.restored(a0);
|
|
c1139_17.log(`load returned null; early returning (guild: ${a0}, database: ${r7})`);
|
|
return void 0;
|
|
}
|
|
const [r61, r62] = r57;
|
|
deserializeChannels(r61);
|
|
if (a1 !== c1139_35.Basic) {
|
|
env1139[34] = env1139[34] + 1;
|
|
}
|
|
env1139[29].add(a0);
|
|
BasicChannelCacheStore.restored(a0);
|
|
Module10.mark("❗", `loaded guild channels (guild: ${a0})`, r62);
|
|
for (const item of r61) {
|
|
if (!Object.hasOwn(env1139[19], item.id)) {
|
|
setGuildChannel((0, castChannelRecord)(item));
|
|
}
|
|
}
|
|
c1139_17.verbose(`hydration complete (guild: ${a0}, channels: ${r61.length}, guilds_loaded: ${env1139[34]})`);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
deleteGuildChannels = function deleteGuildChannels(a0) {
|
|
c1139_17.fileOnly(`Deleting guild channels for ${a0}`);
|
|
if (env1139[20][a0] != null) {
|
|
for (const item of SnowflakeUtils.keys(env1139[20][a0])) {
|
|
delete env1139[19][item];
|
|
}
|
|
delete env1139[20][a0];
|
|
}
|
|
if (env1139[24][a0] != null) {
|
|
delete env1139[24][a0];
|
|
}
|
|
};
|
|
getBasicChannel2 = function getBasicChannel(a0) {
|
|
const Basic = c1139_35.Basic;
|
|
if (!Object.hasOwn(env1139[19], a0) && !Object.hasOwn(env1139[21], a0) && !Object.hasOwn(env1139[23], a0) && !Object.hasOwn(env1139[28], a0) && Basic === c1139_35.Full) {
|
|
const basicChannel = BasicChannelCacheStore.getBasicChannel(a0);
|
|
if (basicChannel?.guild_id != null) {
|
|
ensureGuildLoaded(basicChannel.guild_id, Basic, "getBasicChannel");
|
|
}
|
|
}
|
|
let r34 = env1139[19][a0];
|
|
if (r34 == null) {
|
|
r34 = env1139[21][a0];
|
|
}
|
|
if (r34 == null) {
|
|
r34 = env1139[23][a0];
|
|
}
|
|
if (r34 == null) {
|
|
r34 = env1139[28][a0];
|
|
}
|
|
if (r34 == null) {
|
|
r34 = BasicChannelCacheStore.getBasicChannel(a0);
|
|
}
|
|
return r34;
|
|
};
|
|
getChannel2 = function getChannel(a0) {
|
|
const Full = c1139_35.Full;
|
|
if (!Object.hasOwn(env1139[19], a0) && !Object.hasOwn(env1139[21], a0) && !Object.hasOwn(env1139[23], a0) && !Object.hasOwn(env1139[28], a0) && Full === c1139_35.Full) {
|
|
const basicChannel = BasicChannelCacheStore.getBasicChannel(a0);
|
|
if (basicChannel?.guild_id != null) {
|
|
ensureGuildLoaded(basicChannel.guild_id, Full, "getChannel");
|
|
}
|
|
}
|
|
let r34 = env1139[19][a0];
|
|
if (r34 == null) {
|
|
r34 = env1139[21][a0];
|
|
}
|
|
if (r34 == null) {
|
|
r34 = env1139[23][a0];
|
|
}
|
|
if (r34 == null) {
|
|
r34 = env1139[28][a0];
|
|
}
|
|
if (r34 == null) {
|
|
r34 = env1139[32][a0];
|
|
}
|
|
return r34;
|
|
};
|
|
setChannel = function setChannel(a0) {
|
|
if (a0.isPrivate()) {
|
|
delete env1139[32][a0.id];
|
|
if (a0.recipients.find($mk69131()) == null) {
|
|
env1139[21][a0.id] = a0;
|
|
if (a0.type === ChannelTypes.DM) {
|
|
env1139[25][a0.getRecipientId()] = a0.id;
|
|
}
|
|
env1139[26] = env1139[26] + 1;
|
|
}
|
|
} else if (a0.isThread()) {
|
|
const r11 = env1139[19][a0.parent_id];
|
|
env1139[23][a0.id] = a0.merge.call(a0, {
|
|
nsfw: r11?.nsfw === true,
|
|
parentChannelThreadType: r11?.type
|
|
});
|
|
if (a0.isScheduledForDeletion()) {
|
|
Dispatcher.dispatch({
|
|
type: "THREAD_DELETE",
|
|
channel: a0
|
|
});
|
|
}
|
|
} else if (GUILD_CHANNEL_TYPES.has(a0.type)) {
|
|
const { id, guild_id } = a0;
|
|
env1139[19][id] = a0;
|
|
const r9 = env1139[20];
|
|
let r20 = r9[guild_id];
|
|
if (r20 == null) {
|
|
r20 = {};
|
|
}
|
|
r9[guild_id] = r20;
|
|
env1139[20][guild_id][id] = a0;
|
|
const r23 = env1139[27];
|
|
let r24 = r23[guild_id];
|
|
if (r24 == null) {
|
|
r24 = 0;
|
|
}
|
|
r23[guild_id] = r24 + 1;
|
|
if (a0.linkedLobby != null) {
|
|
const r29 = env1139[24];
|
|
let r30 = r29[guild_id];
|
|
if (r30 == null) {
|
|
r30 = {};
|
|
}
|
|
r29[guild_id] = r30;
|
|
env1139[24][guild_id][id] = a0;
|
|
} else {
|
|
const r28 = env1139[24][guild_id];
|
|
if (r28 != null) {
|
|
delete r28[id];
|
|
}
|
|
}
|
|
}
|
|
};
|
|
setPrivateChannel = function setPrivateChannel(a0) {
|
|
if (a0.recipients.find($mk69131()) != null) {
|
|
return false;
|
|
}
|
|
env1139[21][a0.id] = a0;
|
|
if (a0.type === ChannelTypes.DM) {
|
|
env1139[25][a0.getRecipientId()] = a0.id;
|
|
}
|
|
env1139[26] = env1139[26] + 1;
|
|
};
|
|
setThread = function setThread(a0) {
|
|
const r10 = env1139[19][a0.parent_id];
|
|
env1139[23][a0.id] = a0.merge.call(a0, {
|
|
nsfw: r10?.nsfw === true,
|
|
parentChannelThreadType: r10?.type
|
|
});
|
|
if (a0.isScheduledForDeletion()) {
|
|
Dispatcher.dispatch({
|
|
type: "THREAD_DELETE",
|
|
channel: a0
|
|
});
|
|
}
|
|
};
|
|
setGuildChannel = function setGuildChannel(a0) {
|
|
const { id, guild_id } = a0;
|
|
env1139[19][id] = a0;
|
|
const r8 = env1139[20];
|
|
let r9 = r8[guild_id];
|
|
if (r9 == null) {
|
|
r9 = {};
|
|
}
|
|
r8[guild_id] = r9;
|
|
env1139[20][guild_id][id] = a0;
|
|
const r12 = env1139[27];
|
|
let r13 = r12[guild_id];
|
|
if (r13 == null) {
|
|
r13 = 0;
|
|
}
|
|
r12[guild_id] = r13 + 1;
|
|
if (a0.linkedLobby != null) {
|
|
const r18 = env1139[24];
|
|
let r19 = r18[guild_id];
|
|
if (r19 == null) {
|
|
r19 = {};
|
|
}
|
|
r18[guild_id] = r19;
|
|
env1139[24][guild_id][id] = a0;
|
|
} else {
|
|
const r17 = env1139[24][guild_id];
|
|
if (r17 != null) {
|
|
delete r17[id];
|
|
}
|
|
}
|
|
};
|
|
handleOneGuildCreate = function handleOneGuildCreate({ id, channels, threads }) {
|
|
const op = channels.op;
|
|
if (op === "full_sync") {
|
|
c1139_17.fileOnly(`ConnectionOpen contained full channels for ${id} #:${channels.items.length}`);
|
|
deleteGuildChannels(id);
|
|
env1139[29].add(id);
|
|
BasicChannelCacheStore.restored(id);
|
|
for (const item of channels.items) {
|
|
setGuildChannel(item);
|
|
}
|
|
} else if (op === "update") {
|
|
if (channels.writes.length > 0 || channels.deletes.length > 0) {
|
|
BasicChannelCacheStore.invalidate(id);
|
|
}
|
|
for (const delete2 of channels.deletes) {
|
|
deleteChannel(env1139[19][delete2]);
|
|
}
|
|
for (const write of channels.writes) {
|
|
setGuildChannel(write);
|
|
}
|
|
}
|
|
if (threads != null) {
|
|
for (const item2 of threads) {
|
|
setThread(item2);
|
|
}
|
|
}
|
|
};
|
|
const handleThreadCreateOrUpdate = function handleThreadCreateOrUpdate(a0) {
|
|
let channel;
|
|
if (ALL_CHANNEL_TYPES.has(a0.channel.type)) {
|
|
const channel2 = getChannel2(a0.channel.id);
|
|
if (channel2 == null) {
|
|
channel = a0.channel;
|
|
} else {
|
|
const r20 = {
|
|
...a0.channel.toJS()
|
|
};
|
|
let bitrate = a0.channel.bitrate;
|
|
if (bitrate == null) {
|
|
bitrate = channel2.bitrate;
|
|
}
|
|
r20.bitrate = bitrate;
|
|
channel = channel2.merge(r20);
|
|
}
|
|
setChannel(channel);
|
|
return void 0;
|
|
}
|
|
return false;
|
|
};
|
|
const handleLoadArchivedThreadsSuccess = function handleLoadArchivedThreadsSuccess(a0) {
|
|
a0.threads.forEach((thread) => {
|
|
if (ALL_CHANNEL_TYPES.has(thread.type)) {
|
|
setChannel((0, createChannelRecordFromServer)(thread));
|
|
}
|
|
});
|
|
};
|
|
deleteChannel = function deleteChannel(a0) {
|
|
L23: {
|
|
if (a0 != null) {
|
|
const guild_id = a0.guild_id;
|
|
if (a0.id in env1139[21]) {
|
|
delete env1139[21][a0.id];
|
|
}
|
|
if (a0.id in env1139[19]) {
|
|
delete env1139[19][a0.id];
|
|
}
|
|
if (a0.id in env1139[23]) {
|
|
delete env1139[23][a0.id];
|
|
}
|
|
if (guild_id != null) {
|
|
if (env1139[20][guild_id] != null && a0.id in env1139[20][guild_id]) {
|
|
delete env1139[20][guild_id][a0.id];
|
|
}
|
|
if (env1139[24][guild_id] != null && a0.id in env1139[24][guild_id]) {
|
|
delete env1139[24][guild_id][a0.id];
|
|
}
|
|
}
|
|
if (a0.guild_id != null && !THREAD_CHANNEL_TYPES.has(a0.type)) {
|
|
const r50 = env1139[27];
|
|
const guild_id2 = a0.guild_id;
|
|
let r53 = env1139[27][a0.guild_id];
|
|
if (r53 == null) {
|
|
r53 = 0;
|
|
}
|
|
r50[guild_id2] = r53 + 1;
|
|
break L23;
|
|
}
|
|
if ((0, isPrivate)(a0.type)) {
|
|
env1139[26] = env1139[26] + 1;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
const handleDeleteChannel = function handleDeleteChannel({ channel }) {
|
|
let r8 = env1139[19][channel.id];
|
|
if (r8 == null) {
|
|
r8 = env1139[21][channel.id];
|
|
}
|
|
if (r8 == null) {
|
|
r8 = env1139[23][channel.id];
|
|
}
|
|
if (r8 == null) {
|
|
return false;
|
|
}
|
|
deleteChannel(r8);
|
|
if (!("basicPermissions" in r8) && r8.type === ChannelTypes.DM) {
|
|
const recipientId = r8.getRecipientId();
|
|
if (env1139[25][recipientId] === r8.id) {
|
|
delete env1139[25][recipientId];
|
|
}
|
|
}
|
|
};
|
|
const handleLoadMessages = function handleLoadMessages(a0) {
|
|
for (const message of a0.messages) {
|
|
if (message.thread != null && !(message.thread.id in env1139[23]) && ALL_CHANNEL_TYPES.has(message.thread.type)) {
|
|
setThread((0, createChannelRecordFromServer)(message.thread));
|
|
}
|
|
}
|
|
};
|
|
const handleSearchMessagesSuccess = function handleSearchMessagesSuccess(a0) {
|
|
a0.data.forEach(({ messages, threads, channels }) => {
|
|
messages.forEach((message) => {
|
|
message.forEach((item) => {
|
|
addThreadIfMissing(item.thread);
|
|
});
|
|
});
|
|
threads.forEach(addThreadIfMissing);
|
|
channels.forEach((channel) => {
|
|
let r2, r9;
|
|
L6: {
|
|
L3: {
|
|
r9 = (0, createChannelRecordFromServer)(channel);
|
|
r2 = getChannel2(channel.id) != null;
|
|
const r14 = env1139[32][channel.id] != null;
|
|
if (r9.isPrivate()) {
|
|
if (r2 && !r14) {
|
|
break L3;
|
|
}
|
|
env1139[32][r9.id] = r9;
|
|
break L6;
|
|
}
|
|
}
|
|
if (!r2) {
|
|
setChannel(r9);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
addThreadIfMissing = function addThreadIfMissing(a0) {
|
|
if (a0 != null && !(a0.id in env1139[23]) && ALL_CHANNEL_TYPES.has(a0.type)) {
|
|
const channel = (0, createChannelRecordFromServer)(a0);
|
|
const r10 = env1139[19][channel.parent_id];
|
|
env1139[23][channel.id] = channel.merge({
|
|
nsfw: r10?.nsfw === true,
|
|
parentChannelThreadType: r10?.type
|
|
});
|
|
if (channel.isScheduledForDeletion()) {
|
|
Dispatcher.dispatch({
|
|
type: "THREAD_DELETE",
|
|
channel
|
|
});
|
|
}
|
|
}
|
|
};
|
|
handleFavoritesUpdate = function handleFavoritesUpdate() {
|
|
env1139[28] = {};
|
|
const favoriteChannels = FavoriteStore.getFavoriteChannels();
|
|
for (const key in favoriteChannels) {
|
|
const categoryRecord = FavoriteStore.getCategoryRecord(key);
|
|
if (categoryRecord != null) {
|
|
env1139[28][key] = categoryRecord;
|
|
}
|
|
}
|
|
};
|
|
guildChannelCount = function guildChannelCount(a0) {
|
|
return env1139[20][a0] != null ? Object.keys(env1139[20][a0]).length : null;
|
|
};
|
|
c1139_17 = new Logger("ChannelStore");
|
|
c1139_18 = {};
|
|
env1139[19] = {};
|
|
env1139[20] = {};
|
|
env1139[21] = {};
|
|
env1139[22] = null;
|
|
env1139[23] = {};
|
|
env1139[24] = {};
|
|
env1139[25] = {};
|
|
env1139[26] = 0;
|
|
env1139[27] = {};
|
|
env1139[28] = {};
|
|
env1139[29] = new Set();
|
|
env1139[30] = {};
|
|
env1139[31] = 0;
|
|
env1139[32] = {};
|
|
env1139[33] = 0;
|
|
env1139[34] = 0;
|
|
c1139_49 = void 0;
|
|
export class ChannelLoader {
|
|
constructor() {
|
|
return {
|
|
__proto__: new.target.prototype
|
|
};
|
|
}
|
|
static loadAllMissingChannels() {
|
|
return this.loadGuildIds(GuildStore.getGuildIds().filter((item) => !env1139[29].has(item)));
|
|
}
|
|
static loadGuildFromChannelId(a0) {
|
|
return a0 == null ? null : c1139_49.loadGuildIds([getBasicChannel2(a0)?.guild_id]);
|
|
}
|
|
static loadGuildIds(a0) {
|
|
let env13001 = {
|
|
$parent: env1139
|
|
};
|
|
const r12 = a0.filter.call(a0, isNotNullish);
|
|
env13001[0] = r12;
|
|
if (r12.length === 0) {
|
|
return null;
|
|
}
|
|
const r18 = DatabaseDaos.database();
|
|
env13001[1] = r18;
|
|
if (r18 == null) {
|
|
return null;
|
|
}
|
|
if (r12.some((item) => !env1139[29].has(item))) {
|
|
env13001[2] = env1139[31];
|
|
return tryLoadOrResetCacheGatewayAsync("loadChannels", async () => {
|
|
let r34;
|
|
let c24400_0, c24400_1, c24400_2, c24400_3, c24400_4;
|
|
let c24400_5 = 0;
|
|
const r14 = env13001;
|
|
L14: {
|
|
try {
|
|
let env28883;
|
|
c24400_3 = r14;
|
|
const r44 = env28883 = {
|
|
$parent: r14
|
|
};
|
|
c24400_2 = r44;
|
|
env28883[0] = void 0;
|
|
env28883[1] = void 0;
|
|
env28883[2] = void 0;
|
|
env28883[3] = void 0;
|
|
const r51 = env13001[0].map((item) => {
|
|
const guildId = item;
|
|
if (env1139[29].has(item)) {
|
|
return null;
|
|
}
|
|
if (env1139[30][item] != null) {
|
|
c1139_17.fileOnly(`Skipping loading ${item} because a load is pending`);
|
|
return null;
|
|
}
|
|
const promise = ChannelReader.getAsync(env13001[1], item).then((result) => {
|
|
c1139_17.fileOnly(`Lazy loaded channels for ${guildId} #:${result.length}`);
|
|
return {
|
|
guildId,
|
|
channels: result
|
|
};
|
|
});
|
|
env1139[30][item] = promise;
|
|
return {
|
|
guildId: item,
|
|
promise
|
|
};
|
|
}).filter(isNotNullish);
|
|
env28883[0] = r51;
|
|
const r54 = r51.map((item) => item.promise);
|
|
c24400_5 = 1;
|
|
const r63 = await Promise.all(r54);
|
|
const r79 = c24400_3;
|
|
env28883[1] = r63;
|
|
if (r79.$parent[31] !== env13001[2]) {
|
|
c1139_17.fileOnly("lastResetTime has changed, skipping loads for " + env28883[0].map((item) => item.guildId));
|
|
c24400_5 = 0;
|
|
break L14;
|
|
}
|
|
env28883[2] = env28883[1].filter($mk113775(env13001.$parent));
|
|
await Dispatcher.dispatch({
|
|
type: "LOAD_CHANNELS",
|
|
channels: env28883[2]
|
|
});
|
|
c24400_5 = 0;
|
|
} catch ($e) {
|
|
const r42 = $e;
|
|
let r7 = r42;
|
|
c24400_4 = r42;
|
|
let r43 = c24400_5;
|
|
if (r43 !== 0) {
|
|
while (true) {
|
|
if (r43 === 1) {
|
|
try {
|
|
const r137 = c24400_4;
|
|
c24400_5 = 0;
|
|
env28883[4] = r137;
|
|
c1139_17.error("Failed to load channels from disk for " + env28883[0].map((item) => item.guildId), env28883[4]);
|
|
const r149 = env28883[0];
|
|
c24400_1 = r149;
|
|
const r151 = r149[Symbol.iterator]();
|
|
c24400_1 = r151.next;
|
|
c24400_0 = r151;
|
|
while (true) {
|
|
const r153 = c24400_1;
|
|
let r154 = c24400_0;
|
|
const r155 = r154 === void 0 ? void 0 : (r34 = r153.call(r154)).done ? r154 = void 0 : r34.value;
|
|
c24400_0 = r154;
|
|
if (r154 === void 0) {
|
|
throw env28883[4];
|
|
}
|
|
const r159 = c24400_3;
|
|
c24400_5 = 2;
|
|
env28883[3] = r155;
|
|
delete r159.$parent[30][env28883[3].guildId];
|
|
c24400_5 = 0;
|
|
}
|
|
} catch (r134) {
|
|
r7 = r134;
|
|
c24400_4 = r134;
|
|
r43 = c24400_5;
|
|
if (r43 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
try {
|
|
const r129 = c24400_4;
|
|
c24400_5 = 0;
|
|
const r131 = c24400_0;
|
|
if (r131 !== void 0 && typeof r131.return === "function") {
|
|
try {
|
|
r131.return();
|
|
} catch {}
|
|
}
|
|
throw r129;
|
|
} catch (r128) {
|
|
r7 = r128;
|
|
c24400_4 = r128;
|
|
r43 = c24400_5;
|
|
if (r43 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
return null;
|
|
}
|
|
return null;
|
|
});
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
c1139_49 = ChannelLoader;
|
|
c1139_35 = {
|
|
Basic: 0,
|
|
0: "Basic",
|
|
Full: 1,
|
|
1: "Full"
|
|
};
|
|
class ChannelStore extends Module589.Store {
|
|
static displayName = "ChannelStore";
|
|
constructor() {
|
|
super(...arguments);
|
|
}
|
|
initialize() {
|
|
this.waitFor(AuthenticationStore, BasicChannelCacheStore, FavoriteStore, GuildStore, UserStore);
|
|
this.syncWith([FavoriteStore], handleFavoritesUpdate);
|
|
}
|
|
hasChannel(a0) {
|
|
return getBasicChannel2(a0) != null;
|
|
}
|
|
getBasicChannel(a0) {
|
|
if (a0 != null) {
|
|
return getBasicChannel2(a0);
|
|
}
|
|
}
|
|
getChannel(a0) {
|
|
if (a0 != null) {
|
|
return getChannel2(a0);
|
|
}
|
|
}
|
|
loadAllGuildAndPrivateChannelsFromDisk() {
|
|
for (const item of GuildStore.getGuildIds()) {
|
|
ensureGuildLoaded(item, c1139_35.Full, "loadAllGuildAndPrivateChannelsFromDisk");
|
|
}
|
|
return {
|
|
...env1139[19],
|
|
...env1139[21]
|
|
};
|
|
}
|
|
getChannelIds(a0) {
|
|
let r19;
|
|
ensureGuildLoaded(a0, c1139_35.Basic, "getChannelIds");
|
|
if (a0 == null) {
|
|
r19 = SnowflakeUtils.keys(env1139[21]);
|
|
} else {
|
|
let r17 = BasicChannelCacheStore.getGuildBasicChannels(a0);
|
|
if (r17 == null) {
|
|
r17 = env1139[20][a0];
|
|
}
|
|
if (r17 == null) {
|
|
r17 = c1139_18;
|
|
}
|
|
r19 = SnowflakeUtils.keys(r17);
|
|
}
|
|
return r19;
|
|
}
|
|
getMutablePrivateChannels() {
|
|
return env1139[21];
|
|
}
|
|
getMutableBasicGuildChannelsForGuild(a0) {
|
|
ensureGuildLoaded(a0, c1139_35.Basic, "getMutableBasicGuildChannelsForGuild");
|
|
let r10 = BasicChannelCacheStore.getGuildBasicChannels(a0);
|
|
if (r10 == null) {
|
|
r10 = env1139[20][a0];
|
|
}
|
|
if (r10 == null) {
|
|
r10 = c1139_18;
|
|
}
|
|
return r10;
|
|
}
|
|
getMutableGuildChannelsForGuild(a0) {
|
|
ensureGuildLoaded(a0, c1139_35.Full, "getMutableGuildChannelsForGuild");
|
|
let r9 = env1139[20][a0];
|
|
if (r9 == null) {
|
|
r9 = c1139_18;
|
|
}
|
|
return r9;
|
|
}
|
|
getSortedLinkedChannelsForGuild(a0) {
|
|
let r9 = env1139[24][a0];
|
|
if (r9 == null) {
|
|
r9 = c1139_18;
|
|
}
|
|
return Module12.values(r9).sort((a, b) => SnowflakeUtils.compare(a.id, b.id));
|
|
}
|
|
getSortedPrivateChannels() {
|
|
return Module12(env1139[21]).values().sort((a, b) => SnowflakeUtils.compare(a.lastMessageId, b.lastMessageId)).reverse().value();
|
|
}
|
|
getDMFromUserId(a0) {
|
|
if (a0 != null) {
|
|
return env1139[25][a0];
|
|
}
|
|
}
|
|
getDMChannelFromUserId(a0) {
|
|
if (a0 != null) {
|
|
return this.getChannel(env1139[25][a0]);
|
|
}
|
|
}
|
|
getMutableDMsByUserIds() {
|
|
return env1139[25];
|
|
}
|
|
getDMUserIds() {
|
|
return SnowflakeUtils.keys(env1139[25]);
|
|
}
|
|
getPrivateChannelsVersion() {
|
|
return env1139[26];
|
|
}
|
|
getGuildChannelsVersion(a0) {
|
|
let r5 = env1139[27][a0];
|
|
if (r5 == null) {
|
|
r5 = 0;
|
|
}
|
|
return r5;
|
|
}
|
|
getAllThreadsForParent(c13002_0) {
|
|
return Module12.values(env1139[23]).filter((item) => item.parent_id === c13002_0);
|
|
}
|
|
getAllThreadsForGuild(c13003_0) {
|
|
return Module12.values(env1139[23]).filter((item) => item.guild_id === c13003_0);
|
|
}
|
|
getInitialOverlayState() {
|
|
return {
|
|
...env1139[19],
|
|
...env1139[21],
|
|
...env1139[23]
|
|
};
|
|
}
|
|
getDebugInfo() {
|
|
return {
|
|
loadedGuildIds: Array.from(env1139[29]).sort(SnowflakeUtils.compare),
|
|
pendingGuildLoads: Object.keys(env1139[30]).sort(SnowflakeUtils.compare),
|
|
guildSizes: Object.keys(env1139[20]).sort(SnowflakeUtils.compare).map((item) => `${item}: ${env1139[20][item] != null ? Object.keys(env1139[20][item]).length : null}`)
|
|
};
|
|
}
|
|
}
|
|
c1139_50 = ChannelStore;
|
|
const r163 = new ChannelStore(Dispatcher, {
|
|
BACKGROUND_SYNC: function handleBackgroundSync({ guilds }) {
|
|
let c13004_0 = env1139[20];
|
|
env1139[19] = {};
|
|
env1139[20] = {};
|
|
env1139[27] = {};
|
|
env1139[24] = {};
|
|
guilds.forEach((guild) => {
|
|
if (guild.data_mode === "unavailable") {
|
|
const { id: id3, id: id4 } = guild;
|
|
c1139_17.fileOnly(`Restoring guild channels b/c unavailable in bg sync, for ${id3} #:${env1139[20][id4] != null ? Object.keys(env1139[20][id4]).length : null}`);
|
|
Module12.forEach(c13004_0[guild.id], setGuildChannel);
|
|
} else if (guild.data_mode === "partial") {
|
|
const { id: id2, id } = guild;
|
|
c1139_17.fileOnly(`Restoring guild channels b/c partial in bg sync, for ${id2} #:${env1139[20][id] == null ? null : Object.keys(env1139[20][id]).length}`);
|
|
Module12.forEach(c13004_0[guild.id], setGuildChannel);
|
|
let deleted_channel_ids = guild.partial_updates.deleted_channel_ids;
|
|
if (deleted_channel_ids == null) {
|
|
deleted_channel_ids = [];
|
|
}
|
|
if (deleted_channel_ids.length > 0) {
|
|
ensureGuildLoaded(guild.id, c1139_35.Full, "handleBackgroundSync");
|
|
deleted_channel_ids.forEach((deleted_channel_id) => {
|
|
deleteChannel(env1139[19][deleted_channel_id]);
|
|
});
|
|
}
|
|
const channels = guild.partial_updates.channels;
|
|
if (channels != null) {
|
|
channels.forEach((channel) => {
|
|
const r12 = (0, createChannelRecordFromServer)(channel, guild.id);
|
|
const { id, guild_id } = r12;
|
|
env1139[19][id] = r12;
|
|
const r9 = env1139[20];
|
|
let r15 = r9[guild_id];
|
|
if (r15 == null) {
|
|
r15 = {};
|
|
}
|
|
r9[guild_id] = r15;
|
|
env1139[20][guild_id][id] = r12;
|
|
const r18 = env1139[27];
|
|
let r19 = r18[guild_id];
|
|
if (r19 == null) {
|
|
r19 = 0;
|
|
}
|
|
r18[guild_id] = r19 + 1;
|
|
if (r12.linkedLobby != null) {
|
|
const r24 = env1139[24];
|
|
let r25 = r24[guild_id];
|
|
if (r25 == null) {
|
|
r25 = {};
|
|
}
|
|
r24[guild_id] = r25;
|
|
env1139[24][guild_id][id] = r12;
|
|
} else {
|
|
const r23 = env1139[24][guild_id];
|
|
if (r23 != null) {
|
|
delete r23[id];
|
|
}
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
c1139_17.fileOnly(`BG sync contained full channels for ${guild.id} #:${guild.channels.length}`);
|
|
deleteGuildChannels(guild.id);
|
|
env1139[29].add(guild.id);
|
|
BasicChannelCacheStore.restored(guild.id);
|
|
guild.channels.forEach((channel) => {
|
|
const r12 = (0, createChannelRecordFromServer)(channel, guild.id);
|
|
const { id, guild_id } = r12;
|
|
env1139[19][id] = r12;
|
|
const r9 = env1139[20];
|
|
let r15 = r9[guild_id];
|
|
if (r15 == null) {
|
|
r15 = {};
|
|
}
|
|
r9[guild_id] = r15;
|
|
env1139[20][guild_id][id] = r12;
|
|
const r18 = env1139[27];
|
|
let r19 = r18[guild_id];
|
|
if (r19 == null) {
|
|
r19 = 0;
|
|
}
|
|
r18[guild_id] = r19 + 1;
|
|
if (r12.linkedLobby != null) {
|
|
const r24 = env1139[24];
|
|
let r25 = r24[guild_id];
|
|
if (r25 == null) {
|
|
r25 = {};
|
|
}
|
|
r24[guild_id] = r25;
|
|
env1139[24][guild_id][id] = r12;
|
|
} else {
|
|
const r23 = env1139[24][guild_id];
|
|
if (r23 != null) {
|
|
delete r23[id];
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
},
|
|
CACHE_LOADED_LAZY: function handleLazyCacheLoaded(a0) {
|
|
env1139[33] = Math.max(env1139[33], a0.guilds.length);
|
|
for (const guildChannel of a0.guildChannels) {
|
|
const [r12, r11] = guildChannel;
|
|
c1139_17.fileOnly(`Lazy cache contained full guild channels for ${r12} #:${r11.length}`);
|
|
env1139[29].add(r12);
|
|
for (const item of r11) {
|
|
setChannel((0, castChannelRecord)(item));
|
|
}
|
|
}
|
|
},
|
|
CACHE_LOADED: function handleCacheLoaded(a0) {
|
|
env1139[33] = Math.max(env1139[33], a0.guilds.length);
|
|
const { privateChannels, initialGuildChannels } = a0;
|
|
for (const item of [privateChannels, initialGuildChannels]) {
|
|
for (const item2 of item) {
|
|
setChannel(deserializeChannel((0, castChannelRecord)(item2)));
|
|
}
|
|
}
|
|
const guild_id = initialGuildChannels[0]?.guild_id;
|
|
if (guild_id != null) {
|
|
c1139_17.fileOnly(`Early cache contained full guild channels for ${guild_id}`);
|
|
env1139[29].add(guild_id);
|
|
}
|
|
},
|
|
CHANNEL_CREATE: function handleChannelCreate(a0) {
|
|
setChannel(a0.channel);
|
|
},
|
|
CHANNEL_DELETE: handleDeleteChannel,
|
|
CHANNEL_RECIPIENT_ADD: function handleAddRecipient(a0) {
|
|
const channel2 = getChannel2(a0.channelId);
|
|
const id = AuthenticationStore.getId();
|
|
let r15 = !!(channel2 == null ? void 0 : channel2.isPrivate());
|
|
if (r15) {
|
|
setChannel(channel2.addRecipient(a0.user.id, a0.nick, id));
|
|
r15 = true;
|
|
}
|
|
return r15;
|
|
},
|
|
CHANNEL_RECIPIENT_REMOVE: function handleRemoveRecipient(a0) {
|
|
const channel2 = getChannel2(a0.channelId);
|
|
let r12 = !!(channel2 == null ? void 0 : channel2.isPrivate());
|
|
if (r12) {
|
|
setChannel(channel2.removeRecipient(a0.user.id));
|
|
r12 = true;
|
|
}
|
|
return r12;
|
|
},
|
|
CHANNEL_UPDATES: function handleUpdateChannels(a0) {
|
|
const r19 = a0.channels.some((channel) => {
|
|
const channel2 = getChannel2(channel.id);
|
|
return channel.nsfw !== channel2?.nsfw || channel.type !== channel2?.type;
|
|
});
|
|
for (const channel of a0.channels) {
|
|
setChannel(channel);
|
|
}
|
|
if (r19) {
|
|
Object.values(env1139[23]).forEach((item) => {
|
|
setChannel(item);
|
|
});
|
|
}
|
|
},
|
|
CONNECTION_OPEN_SUPPLEMENTAL: function handleConnectionOpenSupplemental({ lazyPrivateChannels }) {
|
|
if (env1139[22] != null) {
|
|
env1139[21] = {};
|
|
env1139[22].forEach(setPrivateChannel);
|
|
}
|
|
lazyPrivateChannels.forEach(setPrivateChannel);
|
|
},
|
|
CONNECTION_OPEN: function handleConnectionOpen(a0) {
|
|
const r9 = env1139[20];
|
|
env1139[25] = {};
|
|
env1139[19] = {};
|
|
env1139[20] = {};
|
|
env1139[24] = {};
|
|
env1139[23] = {};
|
|
env1139[27] = {};
|
|
env1139[32] = {};
|
|
env1139[30] = {};
|
|
env1139[31] = Date.now();
|
|
env1139[22] = a0.initialPrivateChannels;
|
|
a0.initialPrivateChannels.forEach(setPrivateChannel);
|
|
for (const guild of a0.guilds) {
|
|
if (guild.dataMode === "partial") {
|
|
Module12.forEach(r9[guild.id], setGuildChannel);
|
|
c1139_17.fileOnly(`Restoring guild channels for ${guild.id} #:${guildChannelCount(guild.id)}`);
|
|
}
|
|
handleOneGuildCreate(guild);
|
|
}
|
|
handleFavoritesUpdate();
|
|
},
|
|
CHANNEL_PERMISSIONS_PUT_OVERWRITE_SUCCESS: function handlePutOverwriteSuccess({ channelId, overwrite }) {
|
|
const channel2 = getChannel2(channelId);
|
|
if (channel2 == null) {
|
|
return false;
|
|
}
|
|
const r12 = {
|
|
...channel2.permissionOverwrites
|
|
};
|
|
r12[overwrite.id] = overwrite;
|
|
setChannel(channel2.set("permissionOverwrites", r12));
|
|
},
|
|
CHANNEL_PERMISSIONS_DELETE_OVERWRITE_SUCCESS: function handleDeleteOverwriteSuccess({ channelId, overwriteId }) {
|
|
const channel2 = getChannel2(channelId);
|
|
if (channel2 == null) {
|
|
return false;
|
|
}
|
|
const r10 = {
|
|
...channel2.permissionOverwrites
|
|
};
|
|
delete r10[overwriteId];
|
|
setChannel(channel2.set("permissionOverwrites", r10));
|
|
},
|
|
GUILD_CREATE: function handleCreateGuild(a0) {
|
|
handleOneGuildCreate(a0.guild);
|
|
},
|
|
GUILD_DELETE: function handleGuildDelete(a0) {
|
|
c1139_17.fileOnly(`GuildDelete of ${a0.guild.id}`);
|
|
deleteGuildChannels(a0.guild.id);
|
|
env1139[29].delete(a0.guild.id);
|
|
BasicChannelCacheStore.invalidate(a0.guild.id);
|
|
},
|
|
LOAD_ARCHIVED_THREADS_SUCCESS: handleLoadArchivedThreadsSuccess,
|
|
LOAD_CHANNELS: function handleLoadChannels(a0) {
|
|
for (const channel of a0.channels) {
|
|
const { guildId: guildId2, channels } = channel;
|
|
c1139_17.fileOnly(`Lazy loaded guild channels for ${guildId2}`);
|
|
deserializeChannels(channels);
|
|
env1139[29].add(guildId2);
|
|
BasicChannelCacheStore.restored(guildId2);
|
|
for (const item of channels) {
|
|
if (!Object.hasOwn(env1139[19], item.id)) {
|
|
setGuildChannel((0, castChannelRecord)(item));
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
LOAD_MESSAGES_AROUND_SUCCESS: handleLoadMessages,
|
|
LOAD_MESSAGES_SUCCESS: handleLoadMessages,
|
|
LOAD_THREADS_SUCCESS: handleLoadArchivedThreadsSuccess,
|
|
LOGOUT: function handleLogout() {
|
|
c1139_17.fileOnly("initializeClear()");
|
|
env1139[25] = {};
|
|
env1139[19] = {};
|
|
env1139[20] = {};
|
|
env1139[27] = {};
|
|
env1139[24] = {};
|
|
env1139[21] = {};
|
|
env1139[32] = {};
|
|
env1139[23] = {};
|
|
env1139[29] = new Set();
|
|
env1139[30] = {};
|
|
env1139[31] = Date.now();
|
|
},
|
|
OVERLAY_INITIALIZE: function handleInitialize(a0) {
|
|
for (const channel of a0.channels) {
|
|
setChannel(deserializeChannel((0, castChannelRecord)(channel)));
|
|
}
|
|
},
|
|
SEARCH_MESSAGES_SUCCESS: handleSearchMessagesSuccess,
|
|
MOD_VIEW_SEARCH_MESSAGES_SUCCESS: handleSearchMessagesSuccess,
|
|
THREAD_CREATE: handleThreadCreateOrUpdate,
|
|
THREAD_DELETE: handleDeleteChannel,
|
|
THREAD_LIST_SYNC: function handleThreadListSync(a0) {
|
|
a0.threads.forEach((thread) => {
|
|
if (ALL_CHANNEL_TYPES.has(thread.type)) {
|
|
setChannel(thread);
|
|
}
|
|
});
|
|
},
|
|
THREAD_UPDATE: handleThreadCreateOrUpdate
|
|
});
|
|
export default r163;
|