133 lines
4.5 KiB
TypeScript
133 lines
4.5 KiB
TypeScript
// Metro module 16641 (f16642).
|
|
import "../channel/GatedChannelStore";
|
|
import "../../stores/AuthenticationStore";
|
|
import "../../stores/GuildMemberStore";
|
|
import "./MediaPostEmbedStore";
|
|
import "../../Constants";
|
|
import { MessageEmbedTypes } from "../../_bundle/Module693";
|
|
import AutomaticLifecycleManager from "../../lib/AutomaticLifecycleManager";
|
|
import setupLoadFromMessageManagerHandlers from "../messages/setupLoadFromMessageManagerHandlers";
|
|
import { $callWithNewTarget } from "../../_hermes/prelude";
|
|
function $mk100205($env) {
|
|
return (a0) => {
|
|
if (a0.url != null) {
|
|
const r7 = $env.$parent;
|
|
const r6 = r7[0];
|
|
const r14 = r7[2];
|
|
const mediaPostEmbedChannelPath = r6(r14[6]).getMediaPostEmbedChannelPath(a0.url);
|
|
if (mediaPostEmbedChannelPath != null && mediaPostEmbedChannelPath?.threadId != null && mediaPostEmbedChannelPath?.channelId != null && r7[6].getEmbedFetchState(mediaPostEmbedChannelPath.threadId) === r7[7].NOT_FETCHED) {
|
|
const r26 = r7[9];
|
|
if (!r26.has(mediaPostEmbedChannelPath.threadId)) {
|
|
r26.add(mediaPostEmbedChannelPath.threadId);
|
|
const id = r7[4].getId();
|
|
const r11 = r7[5];
|
|
const guildId = mediaPostEmbedChannelPath?.guildId;
|
|
const r38 = $env;
|
|
const isMember = r11.isMember(guildId, id);
|
|
const isChannelGated = r7[3].isChannelGated(mediaPostEmbedChannelPath.guildId, mediaPostEmbedChannelPath.channelId);
|
|
const r45 = r6(r14[7]);
|
|
let flags = r38[0].flags;
|
|
if (flags == null) {
|
|
flags = 0;
|
|
}
|
|
const hasFlag = r45.hasFlag(flags, r7[8].IS_CROSSPOST);
|
|
if (!(isMember && isChannelGated === false || (isMember ? !isMember : hasFlag))) {
|
|
r6(r14[8]).fetchMediaPostEmbed(mediaPostEmbedChannelPath.threadId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
function $mk100206($env) {
|
|
return () => c11980_9.clear();
|
|
}
|
|
let c11980_9, c11980_11;
|
|
let env11980, $mk100204 = function() {
|
|
return (a0) => a0.type === MessageEmbedTypes.POST_PREVIEW;
|
|
};
|
|
const r8 = env11980 = {};
|
|
const resolveMediaPostEmbeds = function resolveMediaPostEmbeds(a0) {
|
|
let env23356;
|
|
const r4 = env23356 = {
|
|
$parent: env11980
|
|
};
|
|
env23356[0] = a0;
|
|
const embeds = a0.embeds;
|
|
const r6 = embeds == null ? void 0 : embeds.filter($mk100204());
|
|
if (r6 != null && r6.length !== 0) {
|
|
r6.forEach($mk100205(r4));
|
|
}
|
|
};
|
|
c11980_9 = new Set();
|
|
class MediaPostEmbedManager extends AutomaticLifecycleManager {
|
|
constructor() {
|
|
const r5 = env11980;
|
|
super();
|
|
this.actions = {
|
|
LOAD_THREADS_SUCCESS: this.handleLoadThreadsSuccess,
|
|
LOAD_ARCHIVED_THREADS_SUCCESS: this.handleLoadThreadsSuccess,
|
|
LOAD_FORUM_POSTS: this.handleLoadForumPosts
|
|
};
|
|
setupLoadFromMessageManagerHandlers(this, resolveMediaPostEmbeds, {
|
|
onBeforeBatch: $mk100206(r5)
|
|
});
|
|
}
|
|
handleLoadThreadsSuccess({ firstMessages }) {
|
|
if (firstMessages == null) {
|
|
return false;
|
|
}
|
|
c11980_9.clear();
|
|
if (firstMessages != null) {
|
|
firstMessages.forEach((firstMessage) => {
|
|
let env28476;
|
|
const r4 = env28476 = {
|
|
$parent: env11980
|
|
};
|
|
env28476[0] = firstMessage;
|
|
const embeds = firstMessage.embeds;
|
|
const r6 = embeds == null ? void 0 : embeds.filter($mk100204());
|
|
if (r6 != null && r6.length !== 0) {
|
|
r6.forEach($mk100205(r4));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
handleLoadForumPosts({ threads }) {
|
|
c11980_9.clear();
|
|
Object.values(threads).map(({ first_message }) => {
|
|
let r2 = first_message != null;
|
|
if (r2) {
|
|
let env28477;
|
|
const r10 = env28477 = {
|
|
$parent: env11980
|
|
};
|
|
env28477[0] = first_message;
|
|
const embeds = first_message.embeds;
|
|
const r7 = embeds == null ? void 0 : embeds.filter($mk100204());
|
|
const r13 = r7 != null && r7.length !== 0;
|
|
r2 = void 0;
|
|
if (r13) {
|
|
r7.forEach($mk100205(r10));
|
|
r2 = void 0;
|
|
}
|
|
}
|
|
return r2;
|
|
});
|
|
}
|
|
}
|
|
c11980_11 = MediaPostEmbedManager;
|
|
const prototypeOf = Object.getPrototypeOf(MediaPostEmbedManager);
|
|
const r45 = Object.create(MediaPostEmbedManager.prototype);
|
|
const r47 = $callWithNewTarget(prototypeOf, r45, MediaPostEmbedManager);
|
|
const r48 = r47 instanceof Object ? r47 : r45;
|
|
r48.actions = {
|
|
LOAD_THREADS_SUCCESS: r48.handleLoadThreadsSuccess,
|
|
LOAD_ARCHIVED_THREADS_SUCCESS: r48.handleLoadThreadsSuccess,
|
|
LOAD_FORUM_POSTS: r48.handleLoadForumPosts
|
|
};
|
|
setupLoadFromMessageManagerHandlers(r48, resolveMediaPostEmbeds, {
|
|
onBeforeBatch: $mk100206(r8)
|
|
});
|
|
export default r48;
|