// Metro module 5873 (f5874). import ReferencedMessageStore, { ReferencedMessageState } from "../replies/ReferencedMessageStore"; import AuthenticationStore from "../../stores/AuthenticationStore"; import ChannelSectionStore from "../../stores/ChannelSectionStore"; import ChannelStore from "../../stores/ChannelStore"; import MessageStore from "../../stores/MessageStore"; import SelectedChannelStore from "../../stores/SelectedChannelStore"; import SelectedGuildStore from "../../stores/SelectedGuildStore"; import ExplicitMediaSearchStore from "./ExplicitMediaSearchStore"; import { MessageTypesWithLazyLoadedReferences } from "../../Constants"; import { UserSettingsTypes } from "../user_settings/UserSettingsConstants"; import { TimeoutCancelSource, trackExplicitMediaScanComplete, trackScanTiming, trackScanningTimedOut, trackExplicitMediaRedactableMessagedLoaded, trackRedactableMessageLoaded, hasMessageSnapshotsWithAttachmentsOrEmbeds } from "./ExplicitMediaRedactionUtils"; import { isMediaFlaggedForHarmType, isEligibleForScanning, hasUnscannedMedia, getUnscannedMediaIds, getEnabledHarmTypesForMessage, getChannelIdAndAuthorIdFromMessage } from "./ObscuredMediaUtils"; import { ContentHarmType } from "./HarmTypeConfiguration"; import { ObscuredMediaTypes } from "./ExplicitMediaRedactionModels"; import Dispatcher from "../../Dispatcher"; import { sendMultiChannelMessagesForScanning, sendMessagesForScanning } from "./ExplicitMediaRedactionActionCreators"; import MonitoringAgent from "../monitoring/MonitoringAgent"; import { MetricEvents } from "../../_bundle/Module5872"; import { hasAttachmentsEmbedsComponentsOrSnapshots } from "./ExplicitMediaManagerUtils"; import uniqWith from "../../_bundle/uniqWith"; import SnowflakeUtils from "../../utils/SnowflakeUtils"; import { updateMessageRecord } from "../messages/MessageRecordUtils"; import flatten from "../../_bundle/flatten"; import AutomaticLifecycleManager from "../../lib/AutomaticLifecycleManager"; function $mk77264() { return (a0) => a0.id; } function $mk77270($env) { return (a0) => { const r5 = $env; const r12 = r5[0]; if (r12[a0.channel_id] == null) { r12[a0.channel_id] = { numOfAttachments: 0, numOfAttachmentsPendingScan: 0, numOfEmbeds: 0, numOfEmbedsPendingScan: 0 }; } const r15 = r5[1]; if (r15[a0.id] == null) { r15[a0.id] = { channelId: a0.channel_id, numOfAttachments: 0, numOfSelfHarmAttachments: 0, numOfGoreAttachments: 0, numOfExplicitAttachments: 0, numOfEmbeds: 0, numOfSelfHarmEmbeds: 0, numOfGoreEmbeds: 0, numOfExplicitEmbeds: 0 }; } let r9 = a0.attachments?.length; if (r9 == null) { r9 = 0; } let r23 = a0.embeds?.length; if (r23 == null) { r23 = 0; } const r24 = $env.$parent; const unscannedMediaIds = (0, r24[0])(r24[2][11]).getUnscannedMediaIds(a0); const { attachmentIds, embedIds } = unscannedMediaIds; const r32 = r12[a0.channel_id]; r32.numOfAttachments = r32.numOfAttachments + r9; r32.numOfEmbeds = r32.numOfEmbeds + r23; r32.numOfAttachmentsPendingScan = r32.numOfAttachmentsPendingScan + attachmentIds.length; r32.numOfEmbedsPendingScan = r32.numOfEmbedsPendingScan + embedIds.length; const r44 = r15[a0.id]; r44.numOfAttachments = r44.numOfAttachments + r9; r44.numOfEmbeds = r44.numOfEmbeds + r23; const attachments = a0.attachments; let numOfExplicitAttachments = attachments == null ? void 0 : attachments.filter($mk104760(r24)).length; if (numOfExplicitAttachments == null) { numOfExplicitAttachments = 0; } r44.numOfExplicitAttachments = numOfExplicitAttachments; const embeds = a0.embeds; let numOfExplicitEmbeds = embeds == null ? void 0 : embeds.filter($mk104761(r24)).length; if (numOfExplicitEmbeds == null) { numOfExplicitEmbeds = 0; } r44.numOfExplicitEmbeds = numOfExplicitEmbeds; const attachments2 = a0.attachments; let numOfGoreAttachments = attachments2 == null ? void 0 : attachments2.filter($mk104762(r24)).length; if (numOfGoreAttachments == null) { numOfGoreAttachments = 0; } r44.numOfGoreAttachments = numOfGoreAttachments; const embeds2 = a0.embeds; let numOfGoreEmbeds = embeds2 == null ? void 0 : embeds2.filter($mk104763(r24)).length; if (numOfGoreEmbeds == null) { numOfGoreEmbeds = 0; } r44.numOfGoreEmbeds = numOfGoreEmbeds; const attachments3 = a0.attachments; let numOfSelfHarmAttachments = attachments3 == null ? void 0 : attachments3.filter($mk104764(r24)).length; if (numOfSelfHarmAttachments == null) { numOfSelfHarmAttachments = 0; } r44.numOfSelfHarmAttachments = numOfSelfHarmAttachments; const embeds3 = a0.embeds; let numOfSelfHarmEmbeds = embeds3 == null ? void 0 : embeds3.filter($mk104765(r24)).length; if (numOfSelfHarmEmbeds == null) { numOfSelfHarmEmbeds = 0; } r44.numOfSelfHarmEmbeds = numOfSelfHarmEmbeds; }; } function $mk104760($env) { return (a0) => { const r1 = $env; const r6 = r1[0]; const r5 = r1[2]; return r6(r5[11]).isMediaFlaggedForHarmType(r6(r5[12]).ContentHarmType.EXPLICIT, { type: r6(r5[13]).ObscuredMediaTypes.Attachment, media: a0 }); }; } function $mk104761($env) { return (a0) => { const r1 = $env; const r6 = r1[0]; const r5 = r1[2]; return r6(r5[11]).isMediaFlaggedForHarmType(r6(r5[12]).ContentHarmType.EXPLICIT, { type: r6(r5[13]).ObscuredMediaTypes.Embed, media: a0 }); }; } function $mk104762($env) { return (a0) => { const r1 = $env; const r6 = r1[0]; const r5 = r1[2]; return r6(r5[11]).isMediaFlaggedForHarmType(r6(r5[12]).ContentHarmType.GORE, { type: r6(r5[13]).ObscuredMediaTypes.Attachment, media: a0 }); }; } function $mk104763($env) { return (a0) => { const r1 = $env; const r6 = r1[0]; const r5 = r1[2]; return r6(r5[11]).isMediaFlaggedForHarmType(r6(r5[12]).ContentHarmType.GORE, { type: r6(r5[13]).ObscuredMediaTypes.Embed, media: a0 }); }; } function $mk104764($env) { return (a0) => { const r1 = $env; const r6 = r1[0]; const r5 = r1[2]; return r6(r5[11]).isMediaFlaggedForHarmType(r6(r5[12]).ContentHarmType.SELF_HARM, { type: r6(r5[13]).ObscuredMediaTypes.Attachment, media: a0 }); }; } function $mk104765($env) { return (a0) => { const r1 = $env; const r6 = r1[0]; const r5 = r1[2]; return r6(r5[11]).isMediaFlaggedForHarmType(r6(r5[12]).ContentHarmType.SELF_HARM, { type: r6(r5[13]).ObscuredMediaTypes.Embed, media: a0 }); }; } let maybeCancelTimeout, withoutScheduledTimeout, handleUnscannedMessages, processMessagesFromAction, handleMessageUpdate, handleMessageCreate, handleMessagesLoad, handleSearchMessagesSuccess, handleLoadPinnedMessages, handleForumPostsLoad, handleThreadsLoad, handleSidebarViewChannel, handleChannelSelect, handleUserSettingsUpdate, handleVoiceChannelChatOpen, maybeScanMessagesForChannelId, c3675_32; let env3675 = {}; const resetManager = function resetManager() { Object.values(env3675[14]).forEach((item) => { clearTimeout(item.timeout); }); env3675[14] = {}; }; maybeCancelTimeout = function maybeCancelTimeout(a0, a1) { if (a0.id != null && a0.channel_id != null) { const r22 = `${a0.channel_id}:${a0.id}`; if (env3675[14][r22] != null) { const r26 = env3675[14][r22]; const { timeout, setAt } = r26; if (a1 === TimeoutCancelSource.UPDATE) { let attachments = a0.attachments; if (attachments == null) { attachments = []; } let embeds = a0.embeds; if (embeds == null) { embeds = []; } trackExplicitMediaScanComplete({ messageId: a0.id, channelId: a0.channel_id, numOfAttachments: attachments.length, numOfEmbeds: embeds.length, numOfExplicitAttachments: attachments.filter((attachment) => isMediaFlaggedForHarmType(ContentHarmType.EXPLICIT, { type: ObscuredMediaTypes.Attachment, media: attachment })).length, numOfExplicitEmbeds: embeds.filter((embed) => isMediaFlaggedForHarmType(ContentHarmType.EXPLICIT, { type: ObscuredMediaTypes.Embed, media: embed })).length }); } trackScanTiming(setAt, a1); clearTimeout(timeout); delete env3675[14][r22]; return true; } return false; } return false; }; withoutScheduledTimeout = function withoutScheduledTimeout(a0) { return env3675[14][`${a0.channel_id}:${a0.id}`] == null; }; handleUnscannedMessages = function handleUnscannedMessages(a0, a1) { const r3 = a1 == null ? {} : a1; const forceBatchScan = r3.forceBatchScan; let r4 = forceBatchScan !== void 0 && forceBatchScan; const jitter = r3.jitter; const r7 = jitter !== void 0 && jitter; const isMessageUpdate = a1?.isMessageUpdate; const filter = a0.filter; const r21 = isMessageUpdate ? filter.call(a0, (a0) => isEligibleForScanning(a0) && hasUnscannedMedia(a0)).filter(withoutScheduledTimeout) : filter.call(a0, (a0) => isEligibleForScanning(a0)).filter(withoutScheduledTimeout); let c15224_1; let c15224_0 = r21; r21.forEach((item) => { const r13 = `${item.channel_id}:${item.id}`; if (env3675[14][r13] == null) { MonitoringAgent.increment({ name: MetricEvents.EXPLICIT_MEDIA_SCAN_CLIENT_TIMEOUT_CREATE }); env3675[14][r13] = { setAt: Date.now(), timeout: setTimeout(() => { if (maybeCancelTimeout(item, TimeoutCancelSource.TIMEOUT)) { const message = MessageStore.getMessage(item.channel_id, item.id); if (message != null) { const unscannedMediaIds = getUnscannedMediaIds(message); trackScanningTimedOut({ channelId: item.channel_id, messageId: item.id, attachmentIds: unscannedMediaIds.attachmentIds, embedIds: unscannedMediaIds.embedIds }); } Dispatcher.dispatch({ type: "MESSAGE_EXPLICIT_CONTENT_SCAN_TIMEOUT", messageId: item.id, channelId: item.channel_id }); } }, 3000) }; } }); if (!r4) { r4 = new Set(r21.map((item) => item.channel_id)).size > 1; } c15224_1 = r4; if (r7) { setTimeout(() => { const r8 = c15224_0.filter((item) => env3675[14][`${item.channel_id}:${item.id}`] != null); if (r8.length !== 0) { if (c15224_1) { sendMultiChannelMessagesForScanning(r8); } else { sendMessagesForScanning(r8[0].channel_id, r8.map($mk77264())); } } }, 800 * Math.random()); } else if (r21.length !== 0) { if (r4) { sendMultiChannelMessagesForScanning(r21); } else { sendMessagesForScanning(r21[0].channel_id, r21.map($mk77264())); } } }; processMessagesFromAction = function processMessagesFromAction(a0, a1) { const r7 = a0.filter((item) => { let r9 = hasAttachmentsEmbedsComponentsOrSnapshots(item); const enabledHarmTypesForMessage = getEnabledHarmTypesForMessage(item); if (r9) { r9 = enabledHarmTypesForMessage !== 0; } return r9; }); const r21 = a0.map((item) => { if (item != null && "referenced_message" in item && item.referenced_message != null) { if (hasAttachmentsEmbedsComponentsOrSnapshots(item.referenced_message) && getEnabledHarmTypesForMessage(item.referenced_message) !== 0) { return item.referenced_message; } } }).filter(function(item) { return item != null; }); const r9 = r21.length > 0 ? [...r7, ...r21] : r7; let env15225; const r12 = uniqWith(r9, (a0, a1) => a0.id === a1.id && a0.channel_id === a1.channel_id); const r34 = r12.filter((item) => hasUnscannedMedia(item)); const r35 = env15225 = { $parent: env3675 }; const r11 = {}; env15225[0] = r11; const r36 = {}; env15225[1] = r36; r12.forEach($mk77270(r35)); SnowflakeUtils.entries(r11).forEach((item) => { const [channelId, r22] = item; trackExplicitMediaRedactableMessagedLoaded({ channelId, numOfAttachments: r22.numOfAttachments, numOfAttachmentsPendingScan: r22.numOfAttachmentsPendingScan, numOfEmbeds: r22.numOfEmbeds, numOfEmbedsPendingScan: r22.numOfEmbedsPendingScan }); }); SnowflakeUtils.entries(r36).forEach((item) => { const [messageId, r22] = item; trackRedactableMessageLoaded({ messageId, channelId: r22.channelId, numOfAttachments: r22.numOfAttachments, numOfGoreAttachments: r22.numOfGoreAttachments, numOfExplicitAttachments: r22.numOfExplicitAttachments, numOfSelfHarmAttachments: r22.numOfSelfHarmAttachments, numOfEmbeds: r22.numOfEmbeds, numOfGoreEmbeds: r22.numOfGoreEmbeds, numOfExplicitEmbeds: r22.numOfExplicitEmbeds, numOfSelfHarmEmbeds: r22.numOfSelfHarmEmbeds }); }); let r54 = r34.length > 0; if (r54) { handleUnscannedMessages(r34, a1); r54 = true; } return r54; }; handleMessageUpdate = function handleMessageUpdate({ message }) { if (message.channel_id != null && message.id != null) { if (getChannelIdAndAuthorIdFromMessage(message).authorId !== AuthenticationStore.getId()) { if (message.embeds == null && message.attachments == null && !hasMessageSnapshotsWithAttachmentsOrEmbeds(message)) { return false; } if (message.embeds?.length === 0) { if (message.attachments?.length === 0 && !hasMessageSnapshotsWithAttachmentsOrEmbeds(message)) { return false; } } if (!hasUnscannedMedia(message)) { let r46 = MessageStore.getMessage(message.channel_id, message.id); if (r46 == null) { r46 = ExplicitMediaSearchStore.getMessage(message.id, message.channel_id); } if (r46 == null) { r46 = ReferencedMessageStore.getMessage(message.channel_id, message.id)?.message; } if (!(r46 == null || hasUnscannedMedia(updateMessageRecord(r46, message)))) { maybeCancelTimeout(r46, TimeoutCancelSource.UPDATE); } } const channelId = SelectedChannelStore.getChannelId(); const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(channelId); if (message.channel_id !== channelId && message.channel_id !== currentSidebarChannelId) { return false; } const message2 = MessageStore.getMessage(message.channel_id, message.id); return message2 != null && processMessagesFromAction([message2], { isMessageUpdate: true }); } } return false; }; handleMessageCreate = function handleMessageCreate({ channelId, message, optimistic, isPushNotification }) { if (!optimistic && !isPushNotification && channelId != null && getChannelIdAndAuthorIdFromMessage(message).authorId !== AuthenticationStore.getId()) { const channelId2 = SelectedChannelStore.getChannelId(); const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(channelId2); const channel = ChannelStore.getChannel(channelId); let r1 = channelId === channelId2 || channelId === currentSidebarChannelId; if (r1) { const r31 = [message]; let jitter = channel == null ? void 0 : channel.isPrivate(); if (jitter == null) { jitter = true; } if (jitter) { jitter = channel?.memberCount == null || channel?.memberCount > 100; } r1 = processMessagesFromAction(r31, { jitter }); } return r1; } return false; }; handleMessagesLoad = function handleMessagesLoad({ channelId, messages }) { if (channelId != null && messages != null) { const channelId2 = SelectedChannelStore.getChannelId(); const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(channelId2); return (channelId === channelId2 || channelId === currentSidebarChannelId) && processMessagesFromAction(messages); } return false; }; handleSearchMessagesSuccess = function handleSearchMessagesSuccess({ data }) { let c15226_0 = false; data.forEach((item) => { c15226_0 = processMessagesFromAction(uniqWith(flatten(item.messages), (a0, a1) => a0.id === a1.id && a0.channel_id === a1.channel_id)) || c15226_0; }); return c15226_0; }; handleLoadPinnedMessages = function handleLoadPinnedMessages(a0) { return processMessagesFromAction(a0.pins.map((pin) => pin.message)); }; handleForumPostsLoad = function handleForumPostsLoad({ guildId, threads }) { return threads != null && (SelectedGuildStore.getGuildId() === guildId && processMessagesFromAction(SnowflakeUtils.keys(threads).map((item) => threads[item].first_message))); }; handleThreadsLoad = function handleThreadsLoad({ guildId, firstMessages }) { return firstMessages != null && (!(SelectedGuildStore.getGuildId() !== guildId) && processMessagesFromAction(firstMessages, { forceBatchScan: true })); }; handleSidebarViewChannel = function handleSidebarViewChannel({ channelId }) { return channelId != null && maybeScanMessagesForChannelId(channelId); }; handleChannelSelect = function handleChannelSelect({ channelId }) { return channelId != null && (!(channelId !== SelectedChannelStore.getChannelId()) && maybeScanMessagesForChannelId(channelId)); }; handleUserSettingsUpdate = function handleUserSettingsUpdate(a0) { const settings = a0.settings; if (a0.local && settings.type === UserSettingsTypes.PRELOADED_USER_SETTINGS) { const channelId = SelectedChannelStore.getChannelId(); return channelId != null && maybeScanMessagesForChannelId(channelId); } return false; }; handleVoiceChannelChatOpen = function handleVoiceChannelChatOpen(a0) { const channelId = a0.channelId; return !!a0.chatOpen && maybeScanMessagesForChannelId(channelId); }; maybeScanMessagesForChannelId = function maybeScanMessagesForChannelId(a0) { const messages = MessageStore.getMessages(a0); let r3 = messages.length !== 0; if (r3) { const r20 = messages.filter((message) => hasAttachmentsEmbedsComponentsOrSnapshots(message) && getEnabledHarmTypesForMessage(message) !== 0); const r26 = messages.map((message) => { if (MessageTypesWithLazyLoadedReferences.has(message.type) && message.messageReference != null) { const messageByReference = ReferencedMessageStore.getMessageByReference(message.messageReference); if (messageByReference.state === ReferencedMessageState.LOADED && messageByReference.message != null) { if (hasAttachmentsEmbedsComponentsOrSnapshots(messageByReference.message) && getEnabledHarmTypesForMessage(messageByReference.message) !== 0) { return messageByReference.message; } } } }).filter(function(item) { return item != null; }); const r10 = r26.length > 0 ? [...r20, ...r26] : r20; let env15228; const r13 = uniqWith(r10, (a0, a1) => a0.id === a1.id && a0.channel_id === a1.channel_id); const r39 = r13.filter((item) => hasUnscannedMedia(item)); const r40 = env15228 = { $parent: env3675 }; const r12 = {}; env15228[0] = r12; const r41 = {}; env15228[1] = r41; r13.forEach($mk77270(r40)); SnowflakeUtils.entries(r12).forEach((item) => { const [channelId, r22] = item; trackExplicitMediaRedactableMessagedLoaded({ channelId, numOfAttachments: r22.numOfAttachments, numOfAttachmentsPendingScan: r22.numOfAttachmentsPendingScan, numOfEmbeds: r22.numOfEmbeds, numOfEmbedsPendingScan: r22.numOfEmbedsPendingScan }); }); SnowflakeUtils.entries(r41).forEach((item) => { const [messageId, r22] = item; trackRedactableMessageLoaded({ messageId, channelId: r22.channelId, numOfAttachments: r22.numOfAttachments, numOfGoreAttachments: r22.numOfGoreAttachments, numOfSelfHarmAttachments: r22.numOfSelfHarmAttachments, numOfExplicitAttachments: r22.numOfExplicitAttachments, numOfEmbeds: r22.numOfEmbeds, numOfGoreEmbeds: r22.numOfGoreEmbeds, numOfExplicitEmbeds: r22.numOfExplicitEmbeds, numOfSelfHarmEmbeds: r22.numOfSelfHarmEmbeds }); }); let r59 = r39.length > 0; if (r59) { handleUnscannedMessages(r39); r59 = true; } r3 = r59; } return r3; }; env3675[14] = {}; class ExplicitMediaManager extends AutomaticLifecycleManager { constructor() { super(...arguments); this.actions = { LOAD_MESSAGES_SUCCESS: handleMessagesLoad, LOAD_FORUM_POSTS: handleForumPostsLoad, LOAD_THREADS_SUCCESS: handleThreadsLoad, LOAD_ARCHIVED_THREADS_SUCCESS: handleThreadsLoad, SIDEBAR_VIEW_CHANNEL: handleSidebarViewChannel, MESSAGE_CREATE: handleMessageCreate, MESSAGE_UPDATE: handleMessageUpdate, LOGOUT: resetManager, SEARCH_MESSAGES_SUCCESS: handleSearchMessagesSuccess, MOD_VIEW_SEARCH_MESSAGES_SUCCESS: handleSearchMessagesSuccess, CHANNEL_SELECT: handleChannelSelect, LOAD_PINNED_MESSAGES_SUCCESS: handleLoadPinnedMessages, USER_SETTINGS_PROTO_UPDATE: handleUserSettingsUpdate, CHANNEL_RTC_UPDATE_CHAT_OPEN: handleVoiceChannelChatOpen }; } } c3675_32 = ExplicitMediaManager; const r63 = new ExplicitMediaManager(); export default r63; export const MESSAGE_SCAN_TIMEOUT = 3000; export const MAX_TIMEOUT_FOR_JITTER = 800;