494 lines
18 KiB
TypeScript
494 lines
18 KiB
TypeScript
// Metro module 5877 (f5878).
|
|
import DevSettingsStore from "../devtools/dev_settings/DevSettingsStore";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import MessageStore from "../../stores/MessageStore";
|
|
import RelationshipStore from "../../stores/RelationshipStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import ExplicitMediaStore from "./ExplicitMediaStore";
|
|
import { CONTENT_SCAN_TYPE_REGISTRY, ContentHarmTypeBitMask, ContentHarmType } from "./HarmTypeConfiguration";
|
|
import { isNotNullish } from "../../utils/GlobalUtils";
|
|
import { ObscuredMediaTypes, ContentHarmTypeChannel } from "./ExplicitMediaRedactionModels";
|
|
import { ComponentType, UnfurledMediaLoadingState } from "../../flow/Server";
|
|
import { toUnfurledMediaItem } from "../media/MediaTypes";
|
|
import { hasFlag } from "../../_bundle/Module1384";
|
|
import { ExplicitContentRedaction } from "../../_bundle/Module1306";
|
|
import isForwardMessage, { isForwardServerMessage } from "../forwarding/isForwardMessage";
|
|
function $mk77285() {
|
|
return (a0) => {
|
|
let r5 = a0.isEligible == null;
|
|
if (!r5) {
|
|
const isEligible = a0.isEligible;
|
|
r5 = isEligible == null ? void 0 : isEligible.call(a0);
|
|
}
|
|
return r5;
|
|
};
|
|
}
|
|
function $mk77286($env) {
|
|
return (a0) => {
|
|
const r6 = a0.getUserSettingsWithDefaults()[$env[0]];
|
|
let r12 = r6 != null;
|
|
if (r12) {
|
|
const r4 = $env.$parent;
|
|
const r7 = r4[0];
|
|
const r13 = r4[2];
|
|
r12 = [r7(r13[13]).ExplicitContentRedaction.BLOCK, r7(r13[13]).ExplicitContentRedaction.BLUR].includes(r6);
|
|
}
|
|
return r12 ? a0.harmType : null;
|
|
};
|
|
}
|
|
function $mk77291($env) {
|
|
return (a0) => (0, $env.$parent[16])(a0, $env[0]);
|
|
}
|
|
function $mk77292($env) {
|
|
return (a0) => CONTENT_SCAN_TYPE_REGISTRY[a0].obscureReason;
|
|
}
|
|
let getEnabledHarmTypesForMessage, getEnabledHarmTypesForChannelAndAuthorId, messageHasObscurableMediaForBitmask, findComponentMedia, isMediaScanPending, isMediaFlaggedForHarmType, contentHarmTypesToFlags, getHarmTypeFromBitmask, getChannelTypeById, getChannelIdAndAuthorIdFromMessage, hasUnscannedMedia;
|
|
let $mk77289 = function() {
|
|
return (a0) => {
|
|
const type = a0.type;
|
|
if (ComponentType.MEDIA_GALLERY === type) {
|
|
return a0.items.map((item) => item.media);
|
|
}
|
|
if (ComponentType.THUMBNAIL === type) {
|
|
return a0.media;
|
|
}
|
|
if (ComponentType.FILE === type) {
|
|
return a0.file;
|
|
}
|
|
if (ComponentType.SECTION !== type && ComponentType.ACTION_ROW !== type && ComponentType.CONTAINER !== type) {
|
|
return [];
|
|
}
|
|
return a0.components.flatMap(findComponentMedia);
|
|
};
|
|
}, $mk77290 = function() {
|
|
return (a0) => "proxy_url" in a0 ? toUnfurledMediaItem(a0) : a0;
|
|
};
|
|
let env3679 = {};
|
|
export function getEligibleHarmTypesConfigsForContext() {
|
|
return Object.values(CONTENT_SCAN_TYPE_REGISTRY).filter($mk77285());
|
|
}
|
|
getEnabledHarmTypesForMessage = function getEnabledHarmTypesForMessage(a0) {
|
|
const channelIdAndAuthorIdFromMessage = getChannelIdAndAuthorIdFromMessage(a0);
|
|
const { channelId, authorId } = channelIdAndAuthorIdFromMessage;
|
|
return channelId != null && a0 != null ? getEnabledHarmTypesForChannelAndAuthorId(channelId, authorId) : ContentHarmTypeBitMask.NONE;
|
|
};
|
|
getEnabledHarmTypesForChannelAndAuthorId = function getEnabledHarmTypesForChannelAndAuthorId(a0, a1) {
|
|
let NONE2;
|
|
const currentUser = UserStore.getCurrentUser();
|
|
if (currentUser != null && a1 !== currentUser.id) {
|
|
const channelTypeById = getChannelTypeById(a0, a1, [ChannelStore, RelationshipStore]);
|
|
if (channelTypeById == null) {
|
|
NONE2 = ContentHarmTypeBitMask.NONE;
|
|
} else {
|
|
let env15231;
|
|
const r16 = env15231 = {
|
|
$parent: env3679
|
|
};
|
|
env15231[0] = channelTypeById;
|
|
const r26 = Object.values(CONTENT_SCAN_TYPE_REGISTRY).filter($mk77285());
|
|
NONE2 = channelTypeById == null ? ContentHarmTypeBitMask.NONE : contentHarmTypesToFlags(r26.map($mk77286(r16)).filter(isNotNullish));
|
|
}
|
|
return NONE2;
|
|
}
|
|
return ContentHarmTypeBitMask.NONE;
|
|
};
|
|
messageHasObscurableMediaForBitmask = function messageHasObscurableMediaForBitmask(a0, a1) {
|
|
if (a1 !== ContentHarmTypeBitMask.NONE && a0 != null) {
|
|
const attachments = a0.attachments;
|
|
if (attachments == null ? void 0 : attachments.some((attachment) => {
|
|
let r26;
|
|
let env25636;
|
|
const r2 = env3679;
|
|
const r7 = {
|
|
type: ObscuredMediaTypes.Attachment,
|
|
media: attachment
|
|
};
|
|
const r13 = env25636 = {
|
|
$parent: r2
|
|
};
|
|
env25636[0] = r7;
|
|
if (a1 === ContentHarmTypeBitMask.NONE) {
|
|
r26 = [];
|
|
} else {
|
|
const harmTypeFromBitmask = getHarmTypeFromBitmask(a1);
|
|
r26 = harmTypeFromBitmask.length === 0 ? [] : harmTypeFromBitmask.filter($mk77291(r13)).map($mk77292(r2));
|
|
}
|
|
return r26.length > 0;
|
|
})) {
|
|
return true;
|
|
}
|
|
const embeds = a0.embeds;
|
|
if (embeds == null ? void 0 : embeds.some((embed) => {
|
|
let r26;
|
|
let env25637;
|
|
const r2 = env3679;
|
|
const r7 = {
|
|
type: ObscuredMediaTypes.Embed,
|
|
media: embed
|
|
};
|
|
const r13 = env25637 = {
|
|
$parent: r2
|
|
};
|
|
env25637[0] = r7;
|
|
if (a1 === ContentHarmTypeBitMask.NONE) {
|
|
r26 = [];
|
|
} else {
|
|
const harmTypeFromBitmask = getHarmTypeFromBitmask(a1);
|
|
r26 = harmTypeFromBitmask.length === 0 ? [] : harmTypeFromBitmask.filter($mk77291(r13)).map($mk77292(r2));
|
|
}
|
|
return r26.length > 0;
|
|
})) {
|
|
return true;
|
|
}
|
|
const r38 = "messageSnapshots" in a0 ? a0.messageSnapshots : "message_snapshots" in a0 ? a0.message_snapshots : null;
|
|
if (r38 != null && r38.length !== 0) {
|
|
for (const item of r38) {
|
|
if (!messageHasObscurableMediaForBitmask(item.message, a1)) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
};
|
|
findComponentMedia = function findComponentMedia(a0) {
|
|
return (Array.isArray(a0) ? a0 : [a0]).flatMap($mk77289()).map($mk77290());
|
|
};
|
|
isMediaScanPending = function isMediaScanPending(a0, a1) {
|
|
let r95;
|
|
if (a1 === ContentHarmTypeBitMask.NONE) {
|
|
return false;
|
|
}
|
|
if (DevSettingsStore.get("explicit_media_redaction_ignore_pending_scan")) {
|
|
return false;
|
|
}
|
|
const harmTypeFromBitmask = getHarmTypeFromBitmask(a1);
|
|
if (harmTypeFromBitmask.length === 0) {
|
|
return false;
|
|
}
|
|
const type = a0.type;
|
|
if (ObscuredMediaTypes.Embed === type) {
|
|
let media3;
|
|
L82: {
|
|
media3 = a0.media;
|
|
const length3 = harmTypeFromBitmask.length;
|
|
r95 = false;
|
|
if (length3 !== 0) {
|
|
const r97 = media3 == null;
|
|
r95 = false;
|
|
if (!r97) {
|
|
const length4 = harmTypeFromBitmask.filter((item) => !isMediaFlaggedForHarmType(item, {
|
|
type: ObscuredMediaTypes.Embed,
|
|
media: media3
|
|
})).length;
|
|
r95 = false;
|
|
if (length4 !== 0) {
|
|
if ("video" in media3 && media3.video != null) {
|
|
if (media3.video?.width === 0) {
|
|
const height = media3.video?.height;
|
|
r95 = false;
|
|
if (height === 0) {
|
|
break L82;
|
|
}
|
|
}
|
|
}
|
|
if ("thumbnail" in media3 && media3.thumbnail != null) {
|
|
if (media3.thumbnail?.width === 0) {
|
|
const height2 = media3.thumbnail?.height;
|
|
r95 = false;
|
|
if (height2 === 0) {
|
|
break L82;
|
|
}
|
|
}
|
|
}
|
|
if ("image" in media3 && media3.image != null) {
|
|
if (media3.image?.width === 0) {
|
|
const height3 = media3.image?.height;
|
|
r95 = false;
|
|
if (height3 === 0) {
|
|
break L82;
|
|
}
|
|
}
|
|
}
|
|
if ("images" in media3) {
|
|
const images = media3.images;
|
|
const r133 = images == null ? void 0 : images.some((image) => image != null && image.width === 0 && image.height === 0);
|
|
r95 = false;
|
|
if (r133) {
|
|
break L82;
|
|
}
|
|
}
|
|
const r140 = media3.content_scan_version != null ? media3.content_scan_version : media3.contentScanVersion != null ? media3.contentScanVersion : media3.contentScanVersion != null ? media3.contentScanVersion : null;
|
|
r95 = r140 !== -1 && (!harmTypeFromBitmask.includes(ContentHarmType.GORE) && !harmTypeFromBitmask.includes(ContentHarmType.SELF_HARM) ? r140 == null : r140 == null || r140 < ExplicitMediaStore.validContentScanVersion);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return r95;
|
|
}
|
|
if (ObscuredMediaTypes.Attachment === type) {
|
|
const media2 = a0.media;
|
|
let r67 = harmTypeFromBitmask.length !== 0;
|
|
if (r67) {
|
|
let r72 = harmTypeFromBitmask.filter((item) => !isMediaFlaggedForHarmType(item, {
|
|
type: ObscuredMediaTypes.Attachment,
|
|
media: media2
|
|
})).length !== 0;
|
|
if (r72) {
|
|
let content_scan_version = media2.content_scan_version;
|
|
if (content_scan_version == null) {
|
|
content_scan_version = media2.contentScanVersion;
|
|
}
|
|
r72 = content_scan_version !== -1 && (!harmTypeFromBitmask.includes(ContentHarmType.GORE) && !harmTypeFromBitmask.includes(ContentHarmType.SELF_HARM) ? content_scan_version == null : content_scan_version == null || content_scan_version < ExplicitMediaStore.validContentScanVersion);
|
|
}
|
|
r67 = r72;
|
|
}
|
|
return r67;
|
|
}
|
|
if (ObscuredMediaTypes.GenericMedia === type) {
|
|
const media = a0.media;
|
|
const length = harmTypeFromBitmask.length;
|
|
let r42 = false;
|
|
if (length !== 0) {
|
|
const length2 = harmTypeFromBitmask.filter((item) => !isMediaFlaggedForHarmType(item, {
|
|
type: ObscuredMediaTypes.GenericMedia,
|
|
media
|
|
})).length;
|
|
r42 = false;
|
|
if (length2 !== 0) {
|
|
const version = media.contentScanMetadata?.version;
|
|
r42 = version !== -1 && (!harmTypeFromBitmask.includes(ContentHarmType.GORE) && !harmTypeFromBitmask.includes(ContentHarmType.SELF_HARM) ? version == null : version == null || version < ExplicitMediaStore.validContentScanVersion);
|
|
}
|
|
}
|
|
return r42;
|
|
}
|
|
return false;
|
|
};
|
|
isMediaFlaggedForHarmType = function isMediaFlaggedForHarmType(a0, a1) {
|
|
if (a0 == null) {
|
|
return false;
|
|
}
|
|
const r14 = CONTENT_SCAN_TYPE_REGISTRY[a0];
|
|
if (r14.devSettingKey != null && DevSettingsStore.get(r14.devSettingKey)) {
|
|
return true;
|
|
}
|
|
const type = a1.type;
|
|
if (ObscuredMediaTypes.Embed === type) {
|
|
let flags2 = a1.media.flags;
|
|
if (flags2 == null) {
|
|
flags2 = 0;
|
|
}
|
|
return hasFlag(flags2, r14.embedFlag);
|
|
}
|
|
if (ObscuredMediaTypes.Attachment === type) {
|
|
let flags = a1.media.flags;
|
|
if (flags == null) {
|
|
flags = 0;
|
|
}
|
|
return hasFlag(flags, r14.attachmentFlag);
|
|
}
|
|
if (ObscuredMediaTypes.GenericMedia === type) {
|
|
let r37 = a1.media.contentScanMetadata?.flags;
|
|
if (r37 == null) {
|
|
r37 = 0;
|
|
}
|
|
return hasFlag(r37, r14.genericMediaFlag);
|
|
}
|
|
return false;
|
|
};
|
|
contentHarmTypesToFlags = function contentHarmTypesToFlags(a0) {
|
|
let NONE2 = ContentHarmTypeBitMask.NONE;
|
|
for (const item of a0) {
|
|
if (ContentHarmType.EXPLICIT === item) {
|
|
NONE2 = NONE2 | require(dependencyMap[7]).ContentHarmTypeBitMask.EXPLICIT;
|
|
} else if (require(dependencyMap[7]).ContentHarmType.GORE === item) {
|
|
NONE2 = NONE2 | require(dependencyMap[7]).ContentHarmTypeBitMask.GORE;
|
|
} else if (require(dependencyMap[7]).ContentHarmType.SELF_HARM === item) {
|
|
NONE2 = NONE2 | require(dependencyMap[7]).ContentHarmTypeBitMask.SELF_HARM;
|
|
}
|
|
}
|
|
return NONE2;
|
|
};
|
|
getHarmTypeFromBitmask = function getHarmTypeFromBitmask(a0) {
|
|
if (a0 === ContentHarmTypeBitMask.NONE) {
|
|
return [];
|
|
}
|
|
const r24 = [];
|
|
for (const item of getEligibleHarmTypesConfigsForContext()) {
|
|
if ((a0 & item.bitmask) > 0) {
|
|
r24.push(item.harmType);
|
|
}
|
|
}
|
|
return r24;
|
|
};
|
|
getChannelTypeById = function getChannelTypeById(a0, a1, r5 = [ExplicitMediaStore, p]) {
|
|
const [r15, r8] = r5;
|
|
const channel = r15.getChannel(a0);
|
|
const currentUser = UserStore.getCurrentUser();
|
|
return currentUser == null ? null : a1 !== currentUser.id ? channel == null ? null : !channel.isDM() && !channel.isGroupDM() ? ContentHarmTypeChannel.GUILD : a1 != null && r8.getFriendIDs().includes(a1) ? ContentHarmTypeChannel.FRIEND_DM : ContentHarmTypeChannel.NON_FRIEND_DM : null;
|
|
};
|
|
getChannelIdAndAuthorIdFromMessage = function getChannelIdAndAuthorIdFromMessage(a0) {
|
|
let authorId;
|
|
if (a0 == null) {
|
|
return {
|
|
channelId: null,
|
|
authorId: null
|
|
};
|
|
}
|
|
const channelId = "channel_id" in a0 ? a0.channel_id : null;
|
|
const r6 = "messageReference" in a0 ? [a0.messageReference, isForwardMessage(a0)] : "message_reference" in a0 ? [a0.message_reference, isForwardServerMessage(a0)] : [];
|
|
L22: {
|
|
const [r33, r34] = r6;
|
|
if (r33 != null && r34) {
|
|
if (r33.message_id == null) {
|
|
return {
|
|
channelId,
|
|
authorId: null
|
|
};
|
|
}
|
|
const message = MessageStore.getMessage(r33.channel_id, r33.message_id);
|
|
const r48 = message != null;
|
|
authorId = null;
|
|
if (!r48) {
|
|
break L22;
|
|
}
|
|
authorId = message.author?.id;
|
|
} else {
|
|
authorId = "author" in a0 ? a0.author?.id : "author_id" in a0 ? a0.author_id : null;
|
|
}
|
|
}
|
|
return {
|
|
channelId,
|
|
authorId
|
|
};
|
|
};
|
|
export { getEnabledHarmTypesForMessage };
|
|
export { getEnabledHarmTypesForChannelAndAuthorId };
|
|
export function getEnabledHarmTypesBitmaskForChannelType(a0) {
|
|
let env15232;
|
|
const r2 = env15232 = {
|
|
$parent: env3679
|
|
};
|
|
env15232[0] = a0;
|
|
const r16 = Object.values(CONTENT_SCAN_TYPE_REGISTRY).filter($mk77285());
|
|
return a0 == null ? ContentHarmTypeBitMask.NONE : contentHarmTypesToFlags(r16.map($mk77286(r2)).filter(isNotNullish));
|
|
}
|
|
export function messageHasObscurableMedia(a0) {
|
|
const channelIdAndAuthorIdFromMessage = getChannelIdAndAuthorIdFromMessage(a0);
|
|
const { channelId, authorId } = channelIdAndAuthorIdFromMessage;
|
|
return messageHasObscurableMediaForBitmask(a0, channelId != null && a0 != null ? getEnabledHarmTypesForChannelAndAuthorId(channelId, authorId) : ContentHarmTypeBitMask.NONE);
|
|
}
|
|
export { messageHasObscurableMediaForBitmask };
|
|
hasUnscannedMedia = function hasUnscannedMedia(a0, a1) {
|
|
const r3 = a1 == null ? getEnabledHarmTypesForMessage(a0) : a1;
|
|
let c15238_0 = r3;
|
|
if (r3 === ContentHarmTypeBitMask.NONE) {
|
|
return false;
|
|
}
|
|
const attachments = a0.attachments;
|
|
if (attachments == null ? void 0 : attachments.some((attachment) => isMediaScanPending({
|
|
type: ObscuredMediaTypes.Attachment,
|
|
media: attachment
|
|
}, c15238_0))) {
|
|
return true;
|
|
}
|
|
const embeds = a0.embeds;
|
|
if (embeds == null ? void 0 : embeds.some((embed) => isMediaScanPending({
|
|
type: ObscuredMediaTypes.Embed,
|
|
media: embed
|
|
}, c15238_0))) {
|
|
return true;
|
|
}
|
|
if (a0.components != null && findComponentMedia(a0.components).some((item) => isMediaScanPending({
|
|
type: ObscuredMediaTypes.GenericMedia,
|
|
media: item
|
|
}, c15238_0))) {
|
|
return true;
|
|
}
|
|
const r47 = "messageSnapshots" in a0 ? a0.messageSnapshots : "message_snapshots" in a0 ? a0.message_snapshots : null;
|
|
if (r47 != null && r47.length !== 0) {
|
|
for (const item of r47) {
|
|
if (!hasUnscannedMedia(item.message, r3)) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
};
|
|
export { hasUnscannedMedia };
|
|
export function isEligibleForScanning(a0) {
|
|
let r6 = a0.components == null;
|
|
if (!r6) {
|
|
const components = a0.components;
|
|
r6 = !(Array.isArray(components) ? components : [components]).flatMap($mk77289()).map($mk77290()).some((item) => item.loadingState === UnfurledMediaLoadingState.LOADING);
|
|
}
|
|
return r6;
|
|
}
|
|
export function getUnscannedMediaIds(a0) {
|
|
const channelIdAndAuthorIdFromMessage = getChannelIdAndAuthorIdFromMessage(a0);
|
|
const { channelId, authorId } = channelIdAndAuthorIdFromMessage;
|
|
const NONE = channelId != null && a0 != null ? getEnabledHarmTypesForChannelAndAuthorId(channelId, authorId) : ContentHarmTypeBitMask.NONE;
|
|
if (NONE === ContentHarmTypeBitMask.NONE) {
|
|
return {
|
|
attachmentIds: [],
|
|
embedIds: []
|
|
};
|
|
}
|
|
const attachments = a0.attachments;
|
|
const r24 = attachments == null ? void 0 : attachments.filter((attachment) => isMediaScanPending({
|
|
type: ObscuredMediaTypes.Attachment,
|
|
media: attachment
|
|
}, NONE));
|
|
const embeds = a0.embeds;
|
|
const r29 = embeds == null ? void 0 : embeds.filter((embed) => isMediaScanPending({
|
|
type: ObscuredMediaTypes.Embed,
|
|
media: embed
|
|
}, NONE));
|
|
let attachmentIds = r24 == null ? void 0 : r24.map((item) => item.id).filter(Boolean);
|
|
if (attachmentIds == null) {
|
|
attachmentIds = [];
|
|
}
|
|
let embedIds = r29 == null ? void 0 : r29.map((item, index) => `embed_${index}`).filter(Boolean);
|
|
if (embedIds == null) {
|
|
embedIds = [];
|
|
}
|
|
return {
|
|
attachmentIds,
|
|
embedIds
|
|
};
|
|
}
|
|
export function getMediaObscuredReasonFromBitmask(a0, a1) {
|
|
let env15234;
|
|
const r2 = env3679;
|
|
const r3 = env15234 = {
|
|
$parent: env3679
|
|
};
|
|
env15234[0] = a0;
|
|
if (a1 === ContentHarmTypeBitMask.NONE) {
|
|
return [];
|
|
}
|
|
const harmTypeFromBitmask = getHarmTypeFromBitmask(a1);
|
|
return harmTypeFromBitmask.length === 0 ? [] : harmTypeFromBitmask.filter($mk77291(r3)).map($mk77292(r2));
|
|
}
|
|
export function isMediaObscuredForHarmTypes(c15240_0, a1) {
|
|
if (a1 === ContentHarmTypeBitMask.NONE) {
|
|
return false;
|
|
}
|
|
const harmTypeFromBitmask = getHarmTypeFromBitmask(a1);
|
|
return harmTypeFromBitmask.length !== 0 && harmTypeFromBitmask.filter((item) => isMediaFlaggedForHarmType(item, c15240_0)).length > 0;
|
|
}
|
|
export { isMediaScanPending };
|
|
export { isMediaFlaggedForHarmType };
|
|
export { contentHarmTypesToFlags };
|
|
export { getHarmTypeFromBitmask };
|
|
export { getChannelTypeById };
|
|
export function shouldRedactForSettingValue(a0) {
|
|
return a0 != null && [ExplicitContentRedaction.BLOCK, ExplicitContentRedaction.BLUR].includes(a0);
|
|
}
|
|
export { getChannelIdAndAuthorIdFromMessage };
|