650 lines
17 KiB
TypeScript
650 lines
17 KiB
TypeScript
// Metro module 12771 (f12772).
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildMemberStore from "../../stores/GuildMemberStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import RelationshipStore from "../../stores/RelationshipStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { MessageFlags } from "../../Constants";
|
|
import { createMessageRecord, updateMessageRecord } from "./MessageRecordUtils";
|
|
import * as _Module1384 from "../../_bundle/Module1384";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { HermesBuiltin } from "../../_hermes/prelude";
|
|
let c8802_8;
|
|
const updateGuildState = function updateGuildState(a0, a1) {
|
|
const r6 = c8802_8[a0];
|
|
if (r6 != null) {
|
|
const r10 = {
|
|
...c8802_8
|
|
};
|
|
r10[a0] = {
|
|
...r6,
|
|
...a1(r6)
|
|
};
|
|
c8802_8 = r10;
|
|
}
|
|
};
|
|
const handleChannelDelete = function handleChannelDelete({ channel }) {
|
|
const guild_id = channel.guild_id;
|
|
if (guild_id == null) {
|
|
return false;
|
|
}
|
|
const r28 = c8802_8[guild_id];
|
|
if (r28 == null) {
|
|
return false;
|
|
}
|
|
const ids = [];
|
|
const messages = {
|
|
...r28.messages
|
|
};
|
|
for (const id3 of r28.ids) {
|
|
if (r28.messages[id3]?.channel_id === channel.id) {
|
|
delete messages[id3];
|
|
} else {
|
|
ids.push(id3);
|
|
}
|
|
}
|
|
if (ids.length === r28.ids.length) {
|
|
return false;
|
|
}
|
|
updateGuildState(guild_id, () => ({
|
|
ids,
|
|
messages
|
|
}));
|
|
};
|
|
const handleRelationshipUpdate = function handleRelationshipUpdate() {
|
|
const r1 = {};
|
|
let r4 = false;
|
|
for (const item of Object.keys(c8802_8)) {
|
|
const r45 = c8802_8[item];
|
|
let messages4 = null;
|
|
for (const id3 of r45.ids) {
|
|
const r56 = r45.messages[id3];
|
|
if (r56 != null) {
|
|
const isBlockedForMessage = RelationshipStore.isBlockedForMessage(r56);
|
|
const isIgnoredForMessage = RelationshipStore.isIgnoredForMessage(r56);
|
|
if (!(r56.blocked === isBlockedForMessage && r56.ignored === isIgnoredForMessage)) {
|
|
if (messages4 == null) {
|
|
messages4 = {
|
|
...r45.messages
|
|
};
|
|
}
|
|
messages4[id3] = r56.merge({
|
|
blocked: isBlockedForMessage,
|
|
ignored: isIgnoredForMessage
|
|
});
|
|
}
|
|
}
|
|
}
|
|
if (messages4 == null) {
|
|
r1[item] = r45;
|
|
continue;
|
|
}
|
|
r1[item] = {
|
|
...r45,
|
|
messages: messages4
|
|
};
|
|
r4 = true;
|
|
}
|
|
if (r4) {
|
|
c8802_8 = r1;
|
|
return void 0;
|
|
}
|
|
return false;
|
|
};
|
|
c8802_8 = {};
|
|
class GuildOfficialMessagesStore extends Module589.Store {
|
|
static displayName = "GuildOfficialMessagesStore";
|
|
initialize() {
|
|
this.waitFor(ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore);
|
|
}
|
|
getState(a0) {
|
|
return c8802_8[a0];
|
|
}
|
|
getMessage(a0, a1) {
|
|
const r5 = c8802_8[a0];
|
|
return r5 == null ? void 0 : r5.messages[a1];
|
|
}
|
|
getMessages(a0) {
|
|
const r5 = c8802_8[a0];
|
|
let c20203_0 = r5;
|
|
return r5 == null ? [] : r5.ids.map((id) => c20203_0.messages[id]).filter((item) => item != null);
|
|
}
|
|
isLoading(a0) {
|
|
let r6 = c8802_8[a0]?.loading;
|
|
if (r6 == null) {
|
|
r6 = false;
|
|
}
|
|
return r6;
|
|
}
|
|
isLoaded(a0) {
|
|
let r6 = c8802_8[a0]?.loaded;
|
|
if (r6 == null) {
|
|
r6 = false;
|
|
}
|
|
return r6;
|
|
}
|
|
hasMore(a0) {
|
|
let r6 = c8802_8[a0]?.hasMore;
|
|
if (r6 == null) {
|
|
r6 = false;
|
|
}
|
|
return r6;
|
|
}
|
|
}
|
|
const guildOfficialMessagesStore = new GuildOfficialMessagesStore(Dispatcher, {
|
|
CONNECTION_OPEN: function handleConnectionOpen() {
|
|
c8802_8 = {};
|
|
},
|
|
LOAD_OFFICIAL_MESSAGES: function handleLoadOfficialMessages({ guildId, before: before2 }) {
|
|
const r7 = c8802_8[guildId];
|
|
if (r7?.loading === true) {
|
|
return false;
|
|
}
|
|
if (before2 != null) {
|
|
if (r7 == null) {
|
|
return false;
|
|
}
|
|
const r18 = {
|
|
...c8802_8
|
|
};
|
|
r18[guildId] = {
|
|
...r7,
|
|
loading: true
|
|
};
|
|
c8802_8 = r18;
|
|
} else {
|
|
const r14 = {
|
|
...c8802_8
|
|
};
|
|
r14[guildId] = {
|
|
ids: [],
|
|
messages: {},
|
|
hasMore: false,
|
|
loading: true,
|
|
loaded: false,
|
|
error: false
|
|
};
|
|
c8802_8 = r14;
|
|
}
|
|
},
|
|
LOAD_OFFICIAL_MESSAGES_SUCCESS: function handleLoadOfficialMessagesSuccess({ guildId, messages: messages2, hasMore: hasMore2, before }) {
|
|
if (c8802_8[guildId] == null) {
|
|
return false;
|
|
}
|
|
const r7 = c8802_8[guildId];
|
|
if (r7 != null) {
|
|
const r16 = (a0) => {
|
|
const ids3 = before != null ? [...a0.ids] : [];
|
|
const messages4 = before != null ? {
|
|
...a0.messages
|
|
} : {};
|
|
for (const item of messages2) {
|
|
const messageRecord = createMessageRecord(item);
|
|
if (messages4[messageRecord.id] == null) {
|
|
ids3.push(messageRecord.id);
|
|
}
|
|
messages4[messageRecord.id] = messageRecord;
|
|
}
|
|
return {
|
|
ids: ids3,
|
|
messages: messages4,
|
|
hasMore: hasMore2,
|
|
loading: false,
|
|
loaded: true,
|
|
error: false
|
|
};
|
|
};
|
|
const r17 = {
|
|
...c8802_8
|
|
};
|
|
r17[guildId] = {
|
|
...r7,
|
|
...r16(r7)
|
|
};
|
|
c8802_8 = r17;
|
|
}
|
|
},
|
|
LOAD_OFFICIAL_MESSAGES_FAILURE: function handleLoadOfficialMessagesFailure({ guildId, before: before2 }) {
|
|
if (c8802_8[guildId] == null) {
|
|
return false;
|
|
}
|
|
const r7 = before2 != null ? () => ({
|
|
loading: false
|
|
}) : () => ({
|
|
loading: false,
|
|
error: true
|
|
});
|
|
const r6 = c8802_8[guildId];
|
|
if (r6 != null) {
|
|
const r15 = {
|
|
...c8802_8
|
|
};
|
|
r15[guildId] = {
|
|
...r6,
|
|
...r7(r6)
|
|
};
|
|
c8802_8 = r15;
|
|
}
|
|
},
|
|
GUILD_DELETE: function handleGuildDelete({ guild }) {
|
|
if (c8802_8[guild.id] == null) {
|
|
return false;
|
|
}
|
|
const r9 = {
|
|
...c8802_8
|
|
};
|
|
delete r9[guild.id];
|
|
c8802_8 = r9;
|
|
},
|
|
CHANNEL_DELETE: handleChannelDelete,
|
|
THREAD_DELETE: handleChannelDelete,
|
|
MESSAGE_CREATE: function handleMessageCreate({ message, guildId, optimistic, isPushNotification }) {
|
|
if (!optimistic && !isPushNotification) {
|
|
if (guildId != null) {
|
|
let flags = message.flags;
|
|
if (flags == null) {
|
|
flags = 0;
|
|
}
|
|
if (_Module1384.hasFlag(flags, MessageFlags.IS_GUILD_OFFICIAL)) {
|
|
const r24 = c8802_8[guildId];
|
|
let r1 = r24 != null;
|
|
if (r1) {
|
|
let r2 = r24.messages[message.id] == null;
|
|
if (r2) {
|
|
const messageRecord = createMessageRecord(message);
|
|
const r33 = c8802_8[guildId];
|
|
const r34 = r33 != null;
|
|
r2 = void 0;
|
|
if (r34) {
|
|
const r35 = {
|
|
...c8802_8
|
|
};
|
|
const r37 = {
|
|
...r33
|
|
};
|
|
const ids3 = [messageRecord.id, ...r33.ids];
|
|
const messages4 = {
|
|
...r33.messages
|
|
};
|
|
messages4[messageRecord.id] = messageRecord;
|
|
HermesBuiltin.copyDataProperties(r37, {
|
|
ids: ids3,
|
|
messages: messages4
|
|
});
|
|
r35[guildId] = r37;
|
|
c8802_8 = r35;
|
|
r2 = void 0;
|
|
}
|
|
}
|
|
r1 = r2;
|
|
}
|
|
return r1;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
},
|
|
MESSAGE_UPDATE: function handleMessageUpdate({ message }) {
|
|
let id;
|
|
id = void 0;
|
|
if (message.id == null) {
|
|
return false;
|
|
}
|
|
const channel = ChannelStore.getChannel(message.channel_id);
|
|
const r24 = channel == null ? void 0 : channel.getGuildId();
|
|
if (r24 == null) {
|
|
return false;
|
|
}
|
|
const r27 = c8802_8[r24];
|
|
if (r27 == null) {
|
|
return false;
|
|
}
|
|
const r8 = r27.messages[message.id];
|
|
if (message.author == null) {
|
|
let r106 = r8 != null;
|
|
if (r106) {
|
|
const r112 = updateMessageRecord(r8, message);
|
|
const r114 = c8802_8[r24];
|
|
const r115 = r114 != null;
|
|
r106 = void 0;
|
|
if (r115) {
|
|
const r116 = {
|
|
...c8802_8
|
|
};
|
|
const r120 = {
|
|
...r114
|
|
};
|
|
const messages7 = {
|
|
...r114.messages
|
|
};
|
|
messages7[r112.id] = r112;
|
|
HermesBuiltin.copyDataProperties(r120, {
|
|
messages: messages7
|
|
});
|
|
r116[r24] = r120;
|
|
c8802_8 = r116;
|
|
r106 = void 0;
|
|
}
|
|
}
|
|
return r106;
|
|
}
|
|
let flags = message.flags;
|
|
if (flags == null) {
|
|
flags = 0;
|
|
}
|
|
L21: {
|
|
const hasFlag = _Module1384.hasFlag(flags, MessageFlags.IS_GUILD_OFFICIAL);
|
|
if (hasFlag && r8 == null) {
|
|
const messageRecord = createMessageRecord(message);
|
|
const r84 = c8802_8[r24];
|
|
if (r84 == null) {
|
|
break L21;
|
|
}
|
|
const r85 = {
|
|
...c8802_8
|
|
};
|
|
const r89 = {
|
|
...r84
|
|
};
|
|
const ids3 = [messageRecord.id, ...r84.ids];
|
|
const messages6 = {
|
|
...r84.messages
|
|
};
|
|
messages6[messageRecord.id] = messageRecord;
|
|
HermesBuiltin.copyDataProperties(r89, {
|
|
ids: ids3,
|
|
messages: messages6
|
|
});
|
|
r85[r24] = r89;
|
|
c8802_8 = r85;
|
|
} else if (!hasFlag && r8 != null) {
|
|
id = message.id;
|
|
const r16 = c8802_8[r24];
|
|
if (r16 == null) {
|
|
break L21;
|
|
}
|
|
const r38 = {
|
|
...c8802_8
|
|
};
|
|
const r40 = {
|
|
...r16
|
|
};
|
|
const messages4 = {
|
|
...r16.messages
|
|
};
|
|
delete messages4[id];
|
|
HermesBuiltin.copyDataProperties(r40, {
|
|
ids: r16.ids.filter((a0) => a0 !== id),
|
|
messages: messages4
|
|
});
|
|
r38[r24] = r40;
|
|
c8802_8 = r38;
|
|
} else {
|
|
if (!(hasFlag && r8 != null)) {
|
|
return false;
|
|
}
|
|
const r58 = updateMessageRecord(r8, message);
|
|
const r60 = c8802_8[r24];
|
|
if (r60 == null) {
|
|
break L21;
|
|
}
|
|
const r61 = {
|
|
...c8802_8
|
|
};
|
|
const r65 = {
|
|
...r60
|
|
};
|
|
const messages5 = {
|
|
...r60.messages
|
|
};
|
|
messages5[r58.id] = r58;
|
|
HermesBuiltin.copyDataProperties(r65, {
|
|
messages: messages5
|
|
});
|
|
r61[r24] = r65;
|
|
c8802_8 = r61;
|
|
}
|
|
}
|
|
},
|
|
MESSAGE_REACTION_ADD: function handleMessageReactionAdd({ channelId, messageId, userId, emoji, optimistic, reactionType, colors }) {
|
|
const r22 = UserStore.getCurrentUser()?.id === userId;
|
|
if (optimistic && !r22) {
|
|
return false;
|
|
}
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const guildId2 = channel == null ? void 0 : channel.getGuildId();
|
|
const r29 = guildId2 == null;
|
|
let r30 = null;
|
|
if (!r29) {
|
|
const r32 = c8802_8[guildId2];
|
|
const r33 = r32 == null;
|
|
r30 = null;
|
|
if (!r33) {
|
|
const message = r32.messages[messageId];
|
|
r30 = message == null ? null : {
|
|
guildId: guildId2,
|
|
message
|
|
};
|
|
}
|
|
}
|
|
if (r30 == null) {
|
|
return false;
|
|
}
|
|
const r41 = r30.message.addReaction(emoji, r22, colors, reactionType);
|
|
const guildId = r30.guildId;
|
|
const r44 = c8802_8[guildId];
|
|
if (r44 != null) {
|
|
const r45 = {
|
|
...c8802_8
|
|
};
|
|
const r49 = {
|
|
...r44
|
|
};
|
|
const messages4 = {
|
|
...r44.messages
|
|
};
|
|
messages4[r41.id] = r41;
|
|
HermesBuiltin.copyDataProperties(r49, {
|
|
messages: messages4
|
|
});
|
|
r45[guildId] = r49;
|
|
c8802_8 = r45;
|
|
}
|
|
},
|
|
MESSAGE_REACTION_REMOVE: function handleMessageReactionRemove({ channelId, messageId, userId, emoji, optimistic, reactionType }) {
|
|
const r19 = UserStore.getCurrentUser()?.id === userId;
|
|
if (optimistic && !r19) {
|
|
return false;
|
|
}
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const guildId2 = channel == null ? void 0 : channel.getGuildId();
|
|
const r26 = guildId2 == null;
|
|
let r27 = null;
|
|
if (!r26) {
|
|
const r29 = c8802_8[guildId2];
|
|
const r30 = r29 == null;
|
|
r27 = null;
|
|
if (!r30) {
|
|
const message = r29.messages[messageId];
|
|
r27 = message == null ? null : {
|
|
guildId: guildId2,
|
|
message
|
|
};
|
|
}
|
|
}
|
|
if (r27 == null) {
|
|
return false;
|
|
}
|
|
const r38 = r27.message.removeReaction(emoji, r19, reactionType);
|
|
const guildId = r27.guildId;
|
|
const r41 = c8802_8[guildId];
|
|
if (r41 != null) {
|
|
const r42 = {
|
|
...c8802_8
|
|
};
|
|
const r44 = {
|
|
...r41
|
|
};
|
|
const messages4 = {
|
|
...r41.messages
|
|
};
|
|
messages4[r38.id] = r38;
|
|
HermesBuiltin.copyDataProperties(r44, {
|
|
messages: messages4
|
|
});
|
|
r42[guildId] = r44;
|
|
c8802_8 = r42;
|
|
}
|
|
},
|
|
MESSAGE_REACTION_REMOVE_ALL: function handleMessageReactionRemoveAll({ channelId, messageId }) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const guildId2 = channel == null ? void 0 : channel.getGuildId();
|
|
const r16 = guildId2 == null;
|
|
let r17 = null;
|
|
if (!r16) {
|
|
const r19 = c8802_8[guildId2];
|
|
const r20 = r19 == null;
|
|
r17 = null;
|
|
if (!r20) {
|
|
const message = r19.messages[messageId];
|
|
r17 = message == null ? null : {
|
|
guildId: guildId2,
|
|
message
|
|
};
|
|
}
|
|
}
|
|
if (r17 == null) {
|
|
return false;
|
|
}
|
|
const r10 = r17.message.set("reactions", []);
|
|
const guildId = r17.guildId;
|
|
const r9 = c8802_8[guildId];
|
|
if (r9 != null) {
|
|
const r32 = {
|
|
...c8802_8
|
|
};
|
|
const r34 = {
|
|
...r9
|
|
};
|
|
const messages4 = {
|
|
...r9.messages
|
|
};
|
|
messages4[r10.id] = r10;
|
|
HermesBuiltin.copyDataProperties(r34, {
|
|
messages: messages4
|
|
});
|
|
r32[guildId] = r34;
|
|
c8802_8 = r32;
|
|
}
|
|
},
|
|
MESSAGE_REACTION_REMOVE_EMOJI: function handleMessageReactionRemoveEmoji({ channelId, messageId, emoji }) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const guildId2 = channel == null ? void 0 : channel.getGuildId();
|
|
const r16 = guildId2 == null;
|
|
let r17 = null;
|
|
if (!r16) {
|
|
const r19 = c8802_8[guildId2];
|
|
const r20 = r19 == null;
|
|
r17 = null;
|
|
if (!r20) {
|
|
const message = r19.messages[messageId];
|
|
r17 = message == null ? null : {
|
|
guildId: guildId2,
|
|
message
|
|
};
|
|
}
|
|
}
|
|
if (r17 == null) {
|
|
return false;
|
|
}
|
|
const r10 = r17.message.removeReactionsForEmoji(emoji);
|
|
const guildId = r17.guildId;
|
|
const r30 = c8802_8[guildId];
|
|
if (r30 != null) {
|
|
const r31 = {
|
|
...c8802_8
|
|
};
|
|
const r33 = {
|
|
...r30
|
|
};
|
|
const messages4 = {
|
|
...r30.messages
|
|
};
|
|
messages4[r10.id] = r10;
|
|
HermesBuiltin.copyDataProperties(r33, {
|
|
messages: messages4
|
|
});
|
|
r31[guildId] = r33;
|
|
c8802_8 = r31;
|
|
}
|
|
},
|
|
MESSAGE_DELETE: function handleMessageDelete({ id: id2, guildId }) {
|
|
let r1 = guildId != null;
|
|
if (r1) {
|
|
const r6 = c8802_8[guildId];
|
|
let r18 = (r6 == null ? void 0 : r6.messages[id2]) != null;
|
|
if (r18) {
|
|
const r11 = c8802_8[guildId];
|
|
const r20 = r11 != null;
|
|
r18 = void 0;
|
|
if (r20) {
|
|
const r21 = {
|
|
...c8802_8
|
|
};
|
|
const r23 = {
|
|
...r11
|
|
};
|
|
const messages4 = {
|
|
...r11.messages
|
|
};
|
|
delete messages4[id2];
|
|
HermesBuiltin.copyDataProperties(r23, {
|
|
ids: r11.ids.filter((id) => id !== id2),
|
|
messages: messages4
|
|
});
|
|
r21[guildId] = r23;
|
|
c8802_8 = r21;
|
|
r18 = void 0;
|
|
}
|
|
}
|
|
r1 = r18;
|
|
}
|
|
return r1;
|
|
},
|
|
MESSAGE_DELETE_BULK: function handleMessageDeleteBulk({ ids: ids3, guildId }) {
|
|
let messages3;
|
|
messages3 = void 0;
|
|
if (guildId == null) {
|
|
return false;
|
|
}
|
|
const r24 = c8802_8[guildId];
|
|
if (r24 == null) {
|
|
return false;
|
|
}
|
|
const set = new Set(ids3);
|
|
let c20207_0 = set;
|
|
const ids2 = r24.ids.filter((id) => !c20207_0.has(id));
|
|
if (ids2.length === r24.ids.length) {
|
|
return false;
|
|
}
|
|
messages3 = {
|
|
...r24.messages
|
|
};
|
|
for (const id3 of r24.ids) {
|
|
if (set.has(id3)) {
|
|
delete messages3[id3];
|
|
}
|
|
}
|
|
updateGuildState(guildId, () => ({
|
|
ids: ids2,
|
|
messages: messages3
|
|
}));
|
|
},
|
|
RELATIONSHIP_ADD: handleRelationshipUpdate,
|
|
RELATIONSHIP_REMOVE: handleRelationshipUpdate,
|
|
RELATIONSHIP_UPDATE: handleRelationshipUpdate
|
|
});
|
|
export default guildOfficialMessagesStore;
|