177 lines
5.8 KiB
TypeScript
177 lines
5.8 KiB
TypeScript
// Metro module 9883 (f9884).
|
|
import LocaleStore from "../modules/user_settings/LocaleStore";
|
|
import ChannelStore from "./ChannelStore";
|
|
import GuildMemberStore from "./GuildMemberStore";
|
|
import GuildStore from "./GuildStore";
|
|
import MessageStore from "./MessageStore";
|
|
import RelationshipStore from "./RelationshipStore";
|
|
import UserStore from "./UserStore";
|
|
import { createMessageRecord, updateMessageRecord } from "../modules/messages/MessageRecordUtils";
|
|
import Module12 from "../_bundle/Module12";
|
|
import { handleExplicitMediaScanTimeoutForMessage } from "../modules/explicit_media_redaction/ExplicitMediaRedactionUtils";
|
|
import Module589 from "../_bundle/Module589";
|
|
import Dispatcher from "../Dispatcher";
|
|
let c6554_10, c6554_11;
|
|
const handleChannelDelete = function handleChannelDelete(a0) {
|
|
delete c6554_11[a0.channel.id];
|
|
};
|
|
const handleRelationshipUpdate = function handleRelationshipUpdate() {
|
|
Module12.forEach(c6554_11, (a0) => {
|
|
a0.items.forEach(({ message }) => {
|
|
message.set("blocked", RelationshipStore.isBlockedForMessage(message));
|
|
message.set("ignored", RelationshipStore.isIgnoredForMessage(message));
|
|
});
|
|
a0.items = a0.items.slice();
|
|
});
|
|
};
|
|
c6554_10 = {
|
|
LOADING: "LOADING",
|
|
LOADED_HAS_MORE: "LOADED_HAS_MORE",
|
|
LOADED_FINISHED: "LOADING_FINISHED",
|
|
FAILED: "FAILED"
|
|
};
|
|
c6554_11 = {};
|
|
class ChannelPinsStore extends Module589.Store {
|
|
static displayName = "ChannelPinsStore";
|
|
initialize() {
|
|
this.waitFor(ChannelStore, GuildMemberStore, GuildStore, LocaleStore, MessageStore, RelationshipStore, UserStore);
|
|
}
|
|
getPins(a0) {
|
|
return c6554_11[a0];
|
|
}
|
|
}
|
|
const channelPinsStore = new ChannelPinsStore(Dispatcher, {
|
|
CONNECTION_OPEN: function handleConnectionOpen() {
|
|
c6554_11 = {};
|
|
},
|
|
LOAD_PINNED_MESSAGES: function handleLoadStart(a0) {
|
|
const channelId = a0.channelId;
|
|
if (!a0.reset && c6554_11[channelId] != null) {
|
|
c6554_11[channelId].state = c6554_10.LOADING;
|
|
} else {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
let guildId = channel == null ? void 0 : channel.getGuildId();
|
|
if (guildId == null) {
|
|
guildId = void 0;
|
|
}
|
|
c6554_11[channelId] = {
|
|
id: channelId,
|
|
items: [],
|
|
state: c6554_10.LOADING,
|
|
guildId
|
|
};
|
|
}
|
|
},
|
|
LOAD_PINNED_MESSAGES_SUCCESS: function handleLoadSuccess({ channelId, pins, hasMore }) {
|
|
const r12 = c6554_11[channelId];
|
|
if (r12 == null) {
|
|
return false;
|
|
}
|
|
r12.items = [...r12.items, ...pins.map(({ pinned_at, message }) => ({
|
|
pinnedAt: new Date(Date.parse(pinned_at)),
|
|
message: createMessageRecord(message)
|
|
}))];
|
|
r12.state = hasMore ? c6554_10.LOADED_HAS_MORE : c6554_10.LOADED_FINISHED;
|
|
},
|
|
LOAD_PINNED_MESSAGES_FAILURE: function handleLoadFail(a0) {
|
|
const r5 = c6554_11[a0.channelId];
|
|
if (r5 == null) {
|
|
return false;
|
|
}
|
|
r5.state = c6554_10.FAILED;
|
|
},
|
|
CHANNEL_DELETE: handleChannelDelete,
|
|
THREAD_DELETE: handleChannelDelete,
|
|
GUILD_DELETE: function handleGuildDelete({ guild }) {
|
|
c6554_11 = Module12(c6554_11).filter((item) => item.guildId !== guild.id).keyBy("id").value();
|
|
},
|
|
MESSAGE_DELETE: function handleMessageDelete({ id, channelId }) {
|
|
const r13 = c6554_11[channelId];
|
|
let r14 = r13 != null;
|
|
if (r14) {
|
|
let r21 = Module12.remove(r13.items, (a0) => a0.message.id === id).length !== 0;
|
|
if (r21) {
|
|
r13.items = r13.items.slice();
|
|
c6554_11[channelId] = r13;
|
|
r21 = void 0;
|
|
}
|
|
r14 = r21;
|
|
}
|
|
return r14;
|
|
},
|
|
MESSAGE_DELETE_BULK: function handleMessageDeleteBulk(a0) {
|
|
const ids = a0.ids;
|
|
const r8 = c6554_11[a0.channelId];
|
|
if (r8 == null) {
|
|
return false;
|
|
}
|
|
r8.items = r8.items.filter((item) => !ids.includes(item.message.id));
|
|
},
|
|
MESSAGE_UPDATE: function handleMessageUpdate(a0) {
|
|
const id2 = a0.message.id;
|
|
const channel_id = a0.message.channel_id;
|
|
if (channel_id == null) {
|
|
return false;
|
|
}
|
|
const r19 = c6554_11[channel_id];
|
|
if (r19 == null) {
|
|
return false;
|
|
}
|
|
if (a0.message.author != null) {
|
|
if (a0.message.pinned) {
|
|
r19.items = r19.items.slice();
|
|
const r72 = Module12.findIndex(r19.items, (a0) => a0.message.id === id2);
|
|
if (r72 === -1) {
|
|
r19.items.unshift({
|
|
message: createMessageRecord(a0.message),
|
|
pinnedAt: new Date()
|
|
});
|
|
} else {
|
|
r19.items[r72].message = updateMessageRecord(r19.items[r72].message, a0.message);
|
|
}
|
|
} else {
|
|
const r51 = Module12.findIndex(r19.items, (a0) => a0.message.id === id2);
|
|
if (r51 === -1) {
|
|
return false;
|
|
}
|
|
r19.items = r19.items.slice();
|
|
r19.items.splice(r51, 1);
|
|
}
|
|
} else {
|
|
const r25 = Module12.findIndex(r19.items, (a0) => a0.message.id === id2);
|
|
if (r25 === -1) {
|
|
return void 0;
|
|
}
|
|
const r27 = r19.items[r25];
|
|
const { pinnedAt, message } = r27;
|
|
const message2 = updateMessageRecord(message, a0.message);
|
|
if (message2 !== message) {
|
|
const items = r19.items.slice();
|
|
items[r25] = {
|
|
pinnedAt,
|
|
message: message2
|
|
};
|
|
c6554_11[channel_id].items = items;
|
|
}
|
|
}
|
|
},
|
|
RELATIONSHIP_ADD: handleRelationshipUpdate,
|
|
RELATIONSHIP_REMOVE: handleRelationshipUpdate,
|
|
RELATIONSHIP_UPDATE: handleRelationshipUpdate,
|
|
MESSAGE_EXPLICIT_CONTENT_SCAN_TIMEOUT: function handleScanTimeout(a0) {
|
|
const messageId = a0.messageId;
|
|
const r11 = c6554_11[a0.channelId];
|
|
if (r11 == null) {
|
|
return false;
|
|
}
|
|
const r17 = Module12.findIndex(r11.items, (a0) => a0.message.id === messageId);
|
|
if (r17 === -1) {
|
|
return false;
|
|
}
|
|
r11.items = r11.items.slice();
|
|
r11.items[r17].message = handleExplicitMediaScanTimeoutForMessage(r11.items[r17].message);
|
|
}
|
|
});
|
|
export default channelPinsStore;
|
|
export { c6554_10 as FetchState };
|