// Metro module 4409 (f4410). import InteractionRecord from "../../records/InteractionRecord"; import MessageRecord, { MessageSnapshotRecord, MinimalMessageRecord } from "../../records/MessageRecord"; import UserRecord from "../../records/UserRecord"; import AuthenticationStore from "../../stores/AuthenticationStore"; import RelationshipStore from "../../stores/RelationshipStore"; import UserStore from "../../stores/UserStore"; import { MessageTypesSets, MessageTypes, MessageFlags } from "../../Constants"; import { transformComponents } from "../interaction_components/InteractionComponentUtils"; import findCodedLinks from "../coded_links/findCodedLinks"; import { getMessageAuthor } from "./useMessageAuthor"; import SnowflakeUtils from "../../utils/SnowflakeUtils"; import isMessageMentioned, { isMentioned } from "./isMessageMentioned"; import { isGiftCodeEmbed, findGiftCodes } from "../../utils/GiftCodeUtils"; import transformMessagPoll from "../polls/transformMessagPoll"; import Module3771 from "../../_bundle/Module3771"; import { mergeEmbedsOnURL } from "../../utils/EmbedUtils"; import { getMessageStickers } from "../stickers/StickersUtils"; import { HermesBuiltin } from "../../_hermes/prelude"; function $mk74557($env) { return (a0) => { const r1 = $env.$parent; const r5 = (0, r1[0])(r1[2][15]); const r9 = $env[0]; return r5.sanitizeEmbed(r9.channel_id, r9.id, a0); }; } function $mk74559() { return (a0) => { const r2 = { ...a0 }; if (r2.count_details != null) { let burst = r2.count_details.burst; if (burst == null) { burst = 0; } r2.burst_count = burst; let normal = r2.count_details.normal; if (normal == null) { normal = 0; } r2.count = normal; } if (r2.count < 0) { r2.count = 0; } if (r2.burst_count < 0) { r2.burst_count = 0; } return r2; }; } let createMessageRecord, c2639_14; let $mk74560 = function() { return ({ message, moderator_report }) => new MessageSnapshotRecord({ message: createMinimalMessageRecord(message), moderator_report }); }; let env2639 = {}; const createMinimalMessageRecord = function createMinimalMessageRecord(a0) { const r2 = { ...a0, timestamp: new Date(a0.timestamp), editedTimestamp: a0.edited_timestamp != null ? new Date(a0.edited_timestamp) : null }; let attachments = a0.attachments; if (attachments == null) { attachments = []; } let env14259; r2.attachments = attachments; const r25 = env14259 = { $parent: env2639 }; env14259[0] = a0; r2.embeds = a0.embeds == null ? [] : mergeEmbedsOnURL(a0.embeds.map($mk74557(r25))); let components = a0.components; if (components == null) { components = []; } r2.components = transformComponents(components); r2.codedLinks = MessageTypesSets.NON_PARSED.has(a0.type) ? [] : findCodedLinks(a0.content); return new MinimalMessageRecord(r2); }; createMessageRecord = function createMessageRecord(a0, r4 = {}) { let author, reactions2; let reactions = r4.reactions; let interactionData = r4.interactionData; const minimalMessageRecord = createMinimalMessageRecord(a0); const mentions = a0.mentions; let mentions2 = mentions == null ? void 0 : mentions.map((mention) => mention.id); if (mentions2 == null) { mentions2 = []; } let mention_roles = a0.mention_roles; if (mention_roles == null) { mention_roles = []; } let mention_channels = a0.mention_channels; if (mention_channels == null) { mention_channels = []; } let mention_games = a0.mention_games; if (mention_games == null) { mention_games = []; } const message_reference = a0.message_reference; if (a0.author == null) { author = c2639_14; } else if (a0.webhook_id != null) { author = new UserRecord(a0.author); } else { author = UserStore.getUser(a0.author.id); if (author == null) { author = new UserRecord(a0.author); } } const messageAuthor = getMessageAuthor({ channel_id: a0.channel_id, author }); const gift_info = a0?.gift_info; const gifting_prompt = a0.gifting_prompt; const interaction = a0.interaction != null ? InteractionRecord.createFromServer(a0.interaction) : null; const type = a0.type; const THREAD_STARTER_MESSAGE = MessageTypes.THREAD_STARTER_MESSAGE; let r28 = void 0; if (type === THREAD_STARTER_MESSAGE) { const referenced_message = a0.referenced_message; r28 = referenced_message == null ? void 0 : referenced_message.author?.id; } let content = a0.content; const type2 = a0.type; const PREMIUM_REFERRAL = MessageTypes.PREMIUM_REFERRAL; let referralTrialOfferId = void 0; if (type2 === PREMIUM_REFERRAL) { const r75 = SnowflakeUtils.isProbablyAValidSnowflake(a0.content) ? a0.content : void 0; content = ""; referralTrialOfferId = r75; } const type3 = a0.type; const PREMIUM_GROUP_INVITE = MessageTypes.PREMIUM_GROUP_INVITE; let premiumGroupInviteId = void 0; if (type3 === PREMIUM_GROUP_INVITE) { const r85 = SnowflakeUtils.isProbablyAValidSnowflake(a0.content) ? a0.content : void 0; content = ""; premiumGroupInviteId = r85; } const r87 = { ...a0, ...messageAuthor, ...minimalMessageRecord.toJS(), author, webhookId: a0.webhook_id, blocked: RelationshipStore.isBlockedForMessage(a0) || r28 != null && RelationshipStore.isBlocked(r28), ignored: RelationshipStore.isIgnoredForMessage(a0) || r28 != null && RelationshipStore.isIgnored(r28), mentionEveryone: a0.mention_everyone, mentions: mentions2, mentionRoles: mention_roles, mentionChannels: mention_channels, mentionGames: mention_games, messageReference: message_reference }; const r113 = { userId: AuthenticationStore.getId(), channelId: a0.channel_id, mentionEveryone: null, mentionUsers: null, mentionRoles: null }; let mention_everyone = a0.mention_everyone; if (mention_everyone == null) { mention_everyone = false; } r113.mentionEveryone = mention_everyone; r113.mentionUsers = mentions2; r113.mentionRoles = mention_roles; r87.mentioned = isMentioned(r113); r87.giftCodes = isGiftCodeEmbed(a0) ? findGiftCodes(a0 == null ? void 0 : a0.embeds[0].url) : findGiftCodes(a0.content); r87.content = content; r87.referralTrialOfferId = referralTrialOfferId; r87.premiumGroupInviteId = premiumGroupInviteId; const call = a0.call; const timestamp = minimalMessageRecord.timestamp; const r132 = call != null; let call2 = null; if (r132) { const endedTimestamp = call.ended_timestamp != null ? Module3771(new Date(call.ended_timestamp)) : null; call2 = { participants: call.participants, endedTimestamp, duration: endedTimestamp != null ? Module3771.duration(endedTimestamp.diff(timestamp)) : null }; } r87.call = call2; r87.messageSnapshots = a0.message_snapshots == null ? [] : a0.message_snapshots.map($mk74560()); if (reactions == null) { reactions = a0.reactions; } const poll = a0.poll; if (reactions == null && poll?.results == null) { reactions2 = []; } else { const r165 = poll == null; let r166 = void 0; if (!r165) { const results = poll.results; r166 = results == null ? void 0 : results.answer_counts.map((answer_count) => ({ count_details: { vote: answer_count.count }, me_vote: answer_count.me_voted, emoji: { id: answer_count.id.toString(), name: "", animated: false }, me: false, me_burst: false, count: answer_count.count, burst_count: 0 })); } if (reactions == null) { reactions = []; } const r172 = []; const r175 = HermesBuiltin.arraySpread(r172, reactions, 0); if (r166 == null) { r166 = []; } HermesBuiltin.arraySpread(r172, r166, r175); reactions2 = r172.map($mk74559()); } r87.reactions = reactions2; r87.interaction = interaction; if (interactionData == null) { interactionData = a0.interaction_data; } r87.interactionData = interactionData; r87.interactionMetadata = a0.interaction_metadata; r87.roleSubscriptionData = a0.role_subscription_data; r87.purchaseNotification = a0.purchase_notification; r87.poll = a0.poll == null ? void 0 : transformMessagPoll(a0.poll); r87.sharedClientTheme = a0.shared_client_theme; r87.giftInfo = gift_info == null ? void 0 : gift_info; r87.giftingPrompt = gifting_prompt; r87.boostingPrompt = a0.boosting_prompt; return new MessageRecord(r87); }; c2639_14 = new UserRecord({ id: "???", username: "???" }); export { createMessageRecord }; export function updateServerMessage(a0, a1) { return a1.edited_timestamp != null ? { ...a1, reactions: a0.reactions, interaction_data: a0.interaction_data } : { ...a0, ...a1 }; } export function updateMessageRecord(a0, a1) { let r149; if (a1.edited_timestamp != null) { return createMessageRecord(a1, { reactions: a0.reactions, interactionData: a0.interactionData }); } const call2 = a1.call; let r11 = a0; if (call2 != null) { const set = a0.set; const call = a1.call; const timestamp = a0.timestamp; const r1 = call != null; let r8 = null; if (r1) { const endedTimestamp = call.ended_timestamp != null ? Module3771(new Date(call.ended_timestamp)) : null; r8 = { participants: call.participants, endedTimestamp, duration: endedTimestamp != null ? Module3771.duration(endedTimestamp.diff(timestamp)) : null }; } r11 = set.call(a0, "call", r8); } const r45 = a1.attachments != null ? r11.set("attachments", a1.attachments) : r11; const r50 = a1.application != null ? r45.set("application", a1.application) : r45; const r55 = a1.activity != null ? r50.set("activity", a1.activity) : r50; const r63 = a1.content != null && a1.content !== "" ? r55.set("content", a1.content) : r55; const embeds = a1.embeds; let r68 = r63; if (embeds != null) { let env14260; const r70 = env14260 = { $parent: env2639 }; env14260[0] = a1; r68 = r63.set("embeds", a1.embeds == null ? [] : mergeEmbedsOnURL(a1.embeds.map($mk74557(r70)))); } const r85 = a1.message_snapshots != null ? r68.set.call(r68, "messageSnapshots", a1.message_snapshots == null ? [] : a1.message_snapshots.map($mk74560())) : r68; const r95 = a1.pinned !== r85.pinned ? r85.set("pinned", a1.pinned) : r85; const r102 = r95.webhookId != null && a1.author != null ? r95.set("author", new UserRecord(a1.author)) : r95; const r115 = a1.flags != null && a1.flags !== r102.flags ? r102.set("flags", a1.flags) : r102; const r120 = a1.components != null ? r115.set("components", transformComponents(a1.components)) : r115; const r132 = a1.role_subscription_data != null ? r120.set("roleSubscriptionData", a1.role_subscription_data) : r120; const reactions = a1.reactions; let r137 = r132; if (reactions != null) { let reactions2 = a0.reactions; if (reactions2 == null) { reactions2 = a1.reactions; } if (reactions2 == null) { r149 = []; } else { if (reactions2 == null) { reactions2 = []; } r149 = [...reactions2, ...[]].map($mk74559()); } r137 = r132.set("reactions", r149); } const r152 = a1.poll != null ? r137.set("poll", transformMessagPoll(a1.poll)) : r137; const r3 = a1.mentions != null; let r163 = false; let r164 = r152; if (r3) { r164 = r152.set("mentions", a1.mentions.map((mention) => mention.id)); r163 = true; } const mention_everyone = a1.mention_everyone; let r173 = r164; if (mention_everyone != null) { r173 = r164.set("mentionEveryone", a1.mention_everyone); r163 = true; } const mention_roles = a1.mention_roles; let message = r173; if (mention_roles != null) { message = r173.set("mentionRoles", a1.mention_roles); r163 = true; } return r163 ? message.set("mentioned", isMessageMentioned({ message, userId: AuthenticationStore.getId() })) : message; } export function canEditMessageWithStickers(a0) { return getMessageStickers(a0).length === 0 || a0.content !== ""; } export function hasEphemeralAppearance(a0) { return a0.hasFlag(MessageFlags.EPHEMERAL) && a0.type !== MessageTypes.IN_GAME_MESSAGE_NUX; }