// Metro module 5048 (f5049). import ExperimentStore from "../experiments/ExperimentStore"; import SubscriptionRoleStore from "../guild_role_subscriptions/SubscriptionRoleStore"; import LocaleStore from "../user_settings/LocaleStore"; import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore"; import GuildMemberStore from "../../stores/GuildMemberStore"; import GuildMembershipStore from "../../stores/GuildMembershipStore"; import GuildRoleStore from "../../stores/GuildRoleStore"; import GuildStore from "../../stores/GuildStore"; import SortedGuildStore from "../../stores/SortedGuildStore"; import UserStore from "../../stores/UserStore"; import RawGuildEmojiStore from "./RawGuildEmojiStore"; import TopEmojiStore from "./top_emojis/TopEmojiStore"; import { EmojiIntention, EmojiDisabledReasons } from "./EmojiConstants"; import { NULL_STRING_GUILD_ID } from "../../Constants"; import { EmojiCategories } from "../emoji_picker/EmojiPickerConstants"; import { UserSettingsTypes } from "../user_settings/UserSettingsConstants"; import UnicodeEmojis from "./UnicodeEmojis"; import { isPurchasableRoleSubscriptionEmoji } from "../guild_role_subscriptions/RoleSubscriptionEmojiUtils"; import SnowflakeUtils from "../../utils/SnowflakeUtils"; import Module12 from "../../_bundle/Module12"; import Durations from "../../utils/Durations"; import DatabaseDaos from "../app_database/DatabaseDaos"; import { tryLoadOrResetCacheGatewayAsync } from "../app_database/app/TryLoad"; import Module10 from "../../_bundle/Module10"; import GuildEmojis2 from "../app_database/modules/GuildEmojis"; import Dispatcher from "../../Dispatcher"; import Frecency from "../../lib/Frecency"; import Module38 from "../../_bundle/Module38"; import RegexUtils from "../../utils/RegexUtils"; import { isNotNullish } from "../../utils/GlobalUtils"; import dedupeEmojisByNameOrId from "./utils/dedupeEmojisByNameOrId"; import EmojiTerms from "../emoji_terms/EmojiTerms"; import { canUseRoleSubscriptionIAP } from "../guild_role_subscriptions/feature_gating/IAPEligibility"; import { isSubscriptionRole } from "../guild_role_subscriptions/PremiumRoleUtils"; import Module3771 from "../../_bundle/Module3771"; import Module589 from "../../_bundle/Module589"; import EmojiSearchRankingTweaksExperiment from "./EmojiSearchRankingTweaksExperiment"; import EmojiUtils from "../../utils/EmojiUtils"; import { EmojiTypes } from "./EmojiTypes"; import { HermesBuiltin } from "../../_hermes/prelude"; function $mk75316() { return () => 100; } function $mk75318($env) { return () => { (0, $env[0])(); const r13 = $env.$parent; const r6 = r13[22]; r13[31] = [...r6]; if (!(0, r13[1])(r13[2][21]).some(r13[32], (a0) => a0.usableEmojis.length > 0)) { r13[31].splice(r6.indexOf(r13[20].CUSTOM), 1); } }; } let loadSavedEmojis, deleteEverything, rebuildEmojis, updateGuildEmoji, handleUserSettingsProtoStoreChange, trackUsage, c3044_22, c3044_25, c3044_26, c3044_27, c3044_28, c3044_29, c3044_31, c3044_34, c3044_46, c3044_47, EmojiDisambiguations, resetFrequentlyUsed2, c3044_39, resetFrequentlyUsedReactionEmojis2, c3044_40, c3044_48; let env3044, $mk75317 = function() { return (a0) => { let r13 = UnicodeEmojis.getByName(a0); if (r13 == null) { const r7 = getEmojiToGroupId()[a0]; const r3 = r7 != null; let r16 = void 0; if (r3) { const r8 = env3044[32][r7]; let r19 = r8 == null ? void 0 : r8.getUsableEmoji(a0); if (r19 == null) { r19 = void 0; } r16 = r19; } r13 = r16; } return r13; }; }; let env3045; let env3046; const r12 = env3044 = {}; const getEmojiToGroupId = function getEmojiToGroupId() { loadSavedEmojis(); if (env3044[33] == null) { env3044[33] = {}; const r7 = env3044[32]; for (const key in r7) { for (const item of env3044[32][key].emojiIds()) { env3044[33][item] = key; } } } return env3044[33]; }; loadSavedEmojis = async function loadSavedEmojis() { let c25323_0, c25323_1; L15: { L14: { let env29447; const r10 = env3044; c25323_1 = r10; const r24 = env29447 = { $parent: r10 }; c25323_0 = r24; env29447[0] = void 0; env29447[1] = void 0; if (env3044[30] !== c3044_29.Unloaded) { break L15; } const r32 = DatabaseDaos.database(); env29447[0] = r32; if (r32 != null) { env3044[30] = c3044_29.Loading; env29447[1] = await tryLoadOrResetCacheGatewayAsync("EmojiStore.loadSavedEmojis", () => Module10.timeAsync("💾", "loadSavedEmojis", () => GuildEmojis2.getAsync(env29447[0]))); env3044[30] = c3044_29.Loaded; if (env29447[1] == null) { break L14; } Dispatcher.dispatch({ type: "CACHED_EMOJIS_LOADED", emojis: env29447[1] }); break L14; } break L15; } return void 0; } }; deleteEverything = function deleteEverything() { env3044[32] = {}; env3044[33] = {}; EmojiDisambiguations.reset(); c3044_34.clear(); env3044[30] = c3044_29.Unloaded; }; rebuildEmojis = function rebuildEmojis() { env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } }; updateGuildEmoji = function updateGuildEmoji(a0) { if (env3044[32][a0] != null) { delete env3044[32][a0]; } EmojiDisambiguations.clear(a0); const guildEmojis = RawGuildEmojiStore.getGuildEmojis(a0); if (guildEmojis != null) { const currentUser = UserStore.getCurrentUser(); if (currentUser != null) { let _canSeeServerSubIAP = canUseRoleSubscriptionIAP(a0); const r25 = env3044[32]; const id = currentUser.id; if (_canSeeServerSubIAP === void 0) { _canSeeServerSubIAP = false; } const r30 = { __proto__: GuildEmojis.prototype, _emojis: null, _emoticons: null, _usableEmojis: null, _hiddenEmojiIds: null, _canSeeServerSubIAP: false }; r30.id = a0; r30._userId = id; r30._emojiMap = guildEmojis; r30._canSeeServerSubIAP = _canSeeServerSubIAP; r25[a0] = r30; } } }; handleUserSettingsProtoStoreChange = function handleUserSettingsProtoStoreChange() { const textAndImages = UserSettingsProtoStore.settings.textAndImages; const r8 = textAndImages == null ? void 0 : textAndImages.diversitySurrogate?.value; if (r8 != null) { UnicodeEmojis.setDefaultDiversitySurrogate(r8); } EmojiDisambiguations.reset(); const frecencyWithoutFetchingLatest = UserSettingsProtoStore.frecencyWithoutFetchingLatest; let r28 = frecencyWithoutFetchingLatest.emojiFrecency?.emojis; if (r28 == null) { r28 = {}; } let r31 = frecencyWithoutFetchingLatest.emojiReactionFrecency?.emojis; if (r31 == null) { r31 = {}; } c3044_39.overwriteHistory(Module12.mapValues(r28, (a0) => ({ ...a0, recentUses: a0.recentUses.map(Number).filter((item) => item > 0) })), env3044[23].pendingUsages); c3044_40.overwriteHistory(Module12.mapValues(r31, (a0) => ({ ...a0, recentUses: a0.recentUses.map(Number).filter((item) => item > 0) })), env3044[23].emojiReactionPendingUsages); (function populateInitialFrecencyData(a0, a1) { if (Module12.isEmpty(a0) && Module12.isEmpty(env3044[23].pendingUsages) && UserSettingsProtoStore.hasLoaded(UserSettingsTypes.FRECENCY_AND_FAVORITES_SETTINGS)) { for (const item of ["thumbsup", "eyes", "laughing", "watermelon", "fork_and_knife", "yum", "weary", "tired_face", "poop", "100"]) { c3044_39.track(item); } } if (Module12.isEmpty(a1) && Module12.isEmpty(env3044[23].emojiReactionPendingUsages) && UserSettingsProtoStore.hasLoaded(UserSettingsTypes.FRECENCY_AND_FAVORITES_SETTINGS)) { for (const item2 of ["100", "100", "thumbsup", "thumbsup", "thumbsdown", "thumbsdown", "heart", "point_up", "eyes", "weary", "laughing", "white_check_mark", "x"]) { c3044_40.track(item2); } } })(r28, r31); }; trackUsage = function trackUsage(a0) { if (a0 == null) { return false; } for (const item of a0) { let id = item.id; if (id == null) { id = item.uniqueName; } if (id == null) { id = item.name; } if (id != null) { const key = id; c3044_39.track(key); env3044[23].pendingUsages.push({ key, timestamp: Date.now() }); } } const r44 = a0.length > 0; if (r44 && env3044[30] === c3044_29.Loaded) { c3044_39.compute(); } return r44; }; const handleRoleUpdate = function handleRoleUpdate(a0) { const guildId = a0.guildId; const role = GuildRoleStore.getRole(guildId, a0.role.id); if (role != null && isSubscriptionRole(role)) { updateGuildEmoji(guildId); env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } return void 0; } return false; }; c3044_22 = [EmojiCategories.TOP_GUILD_EMOJI.toString(), EmojiCategories.FAVORITES.toString(), EmojiCategories.RECENT.toString(), EmojiCategories.CUSTOM.toString()].concat(UnicodeEmojis.getCategories()); env3044[23] = { pendingUsages: [], emojiReactionPendingUsages: [], expandedSectionsByGuildIds: new Set() }; class GuildEmojis { constructor(a0, a1, a2, _canSeeServerSubIAP = false) { const r7 = { __proto__: new.target.prototype, _emojis: null, _emoticons: null, _usableEmojis: null, _hiddenEmojiIds: null, _canSeeServerSubIAP: false }; r7.id = a0; r7._userId = a1; r7._emojiMap = a2; r7._canSeeServerSubIAP = _canSeeServerSubIAP; return r7; } getEmoji(a0) { return this._emojiMap[a0]; } getUsableEmoji(a0) { const emoji = this.getEmoji(a0); return emoji != null ? this.isUsable(emoji) ? emoji : void 0 : void 0; } isUsable(a0) { if (a0.roles.length === 0) { return true; } const member = GuildMemberStore.getMember(this.id, this._userId); return member != null && (!!member.roles.some((role) => a0.roles.includes(role)) || !!isPurchasableRoleSubscriptionEmoji(a0) && (this._canSeeServerSubIAP || SubscriptionRoleStore.getUserIsAdmin(a0.guildId))); } emojiIds() { return SnowflakeUtils.keys(this._emojiMap); } get emojis() { if (this._emojis == null) { this._emojis = Object.values(this._emojiMap); } return this._emojis; } get emoticons() { if (this._emoticons == null) { this._emoticons = this.usableEmojis.filter((usableEmoji) => !usableEmoji.require_colons); } return this._emoticons; } _computeEmojiUsability() { if (!(this._usableEmojis != null && this._hiddenEmojiIds != null)) { const r6 = []; const set = new Set(); for (const emoji of this.emojis) { if (this.isUsable(emoji)) { r6.push(emoji); } else { set.add(emoji.id); } } this._usableEmojis = Module12.sortBy(r6, (a0) => a0.name); this._hiddenEmojiIds = set; } } get usableEmojis() { this._computeEmojiUsability(); return this._usableEmojis; } get hiddenEmojiIds() { this._computeEmojiUsability(); return this._hiddenEmojiIds; } } c3044_25 = SnowflakeUtils.fromTimestamp(Date.now() - 60 * Durations.Millis.DAY); c3044_26 = []; c3044_27 = []; c3044_28 = new Set(); c3044_29 = { Unloaded: 0, 0: "Unloaded", Loading: 1, 1: "Loading", Loaded: 2, 2: "Loaded" }; env3044[30] = c3044_29.Unloaded; c3044_31 = [...c3044_22]; env3044[32] = {}; env3044[33] = {}; c3044_34 = new Map(); c3044_46 = void 0; c3044_47 = function() { this.favorites = null; this.favoriteNamesAndIds = null; this.topEmojis = null; this.disambiguatedEmoji = []; this.emoticonRegex = null; this.frequentlyUsed = null; this.frequentlyUsedReactionEmojis = null; this.frequentlyUsedReactionNamesAndIds = null; this.unicodeAliases = new Map(); this.customEmojis = new Map(); this.customEmojisByGroup = new Map(); this.emoticonsByName = new Map(); this.emojisByName = new Map(); this.emojisById = new Map(); this.newlyAddedEmoji = new Map(); this.isFavoriteEmojiWithoutFetchingLatest = (a0) => { if (a0 == null) { return false; } const favoriteNamesAndIds = this.rebuildFavoriteEmojisWithoutFetchingLatest().favoriteNamesAndIds; if (a0.id != null) { return favoriteNamesAndIds.has(a0.id); } let r16 = UnicodeEmojis.convertSurrogateToBase(a0.surrogates); if (r16 == null) { r16 = a0; } return favoriteNamesAndIds.has(r16.name); }; }; c3044_46 = class EmojiDisambiguations { static _lastInstance = null; constructor(a0) { let disambiguateEmoticon2; const _this = this; c3044_47.call(this); this.guildId = a0; let c14586_0 = new Map(); const r38 = []; let c14586_1 = r38; const disambiguateEmoji2 = (a0) => { const name = a0.name; let r11 = c14586_0.get(name); if (r11 == null) { r11 = 0; } c14586_0.set(name, r11 + 1); const r18 = r11 > 0 ? { ...a0, name: `${name}~${r11}`, originalName: name } : a0; _this.emojisByName.set(r18.name, r18); _this.emojisById.set(r18.id, r18); _this.customEmojis.set(r18.name, r18); const guildId = a0.guildId; const r41 = _this.customEmojisByGroup.has(guildId); const customEmojisByGroup = _this.customEmojisByGroup; if (r41) { const r47 = customEmojisByGroup.get(guildId); if (r47 != null) { r47.push(r18); } } else { customEmojisByGroup.set(guildId, [r18]); } if (SnowflakeUtils.compare(a0.id, c3044_25) >= 0) { const r61 = _this.newlyAddedEmoji.has(guildId); const newlyAddedEmoji = _this.newlyAddedEmoji; if (r61) { const r67 = newlyAddedEmoji.get(guildId); if (r67 != null) { r67.push(r18); } } else { newlyAddedEmoji.set(guildId, [r18]); } } _this.disambiguatedEmoji.push(r18); }; disambiguateEmoticon2 = (a0) => { if (!_this.emoticonsByName.has(a0.name)) { c14586_1.push(RegexUtils.escape(a0.name)); _this.emoticonsByName.set(a0.name, a0); } }; UnicodeEmojis.forEach((unicodeEmoji) => { unicodeEmoji.names.slice(1).forEach((item) => _this.unicodeAliases.set(item, unicodeEmoji.name)); let r16 = c14586_0.get(unicodeEmoji.name); if (r16 == null) { r16 = 0; } Module38(r16 === 0, "Expected existing count to be 0"); c14586_0.set(unicodeEmoji.name, r16 + 1); _this.emojisByName.set(unicodeEmoji.name, unicodeEmoji); _this.disambiguatedEmoji.push(unicodeEmoji); }); (function addGuildEmoji(a0) { let r2 = a0; const r1 = env3044[32]; if (a0 == null) { r2 = NULL_STRING_GUILD_ID; } const r9 = r1[r2]; if (r9 != null) { Module12.each(r9.usableEmojis, disambiguateEmoji2); Module12.each(r9.emoticons, disambiguateEmoticon2); } })(this.guildId); for (const item of this.newlyAddedEmoji.keys()) { const r59 = this.newlyAddedEmoji.get(item); if (r59 != null) { this.newlyAddedEmoji.set(item, r59.sort((a, b) => SnowflakeUtils.compare(b.id, a.id)).slice(0, 3)); } else { this.newlyAddedEmoji.set(item, []); } } SortedGuildStore.getFlattenedGuildIds().forEach((item) => { let r4 = item; if (item !== _this.guildId) { const r10 = env3044[32]; if (item == null) { r4 = NULL_STRING_GUILD_ID; } const r11 = r10[r4]; if (r11 != null) { Module12.each(r11.usableEmojis, disambiguateEmoji2); Module12.each(r11.emoticons, disambiguateEmoticon2); } } }); this.escapedEmoticonNames = r38.join("|"); } static get(a0) { const r4 = a0 === void 0 ? null : a0; if (!(c3044_46._lastInstance != null && c3044_46._lastInstance.guildId === r4)) { c3044_46._lastInstance = new c3044_46(r4); } return c3044_46._lastInstance; } static reset() { c3044_46._lastInstance = null; } static resetFrequentlyUsed() { if (c3044_46._lastInstance != null) { c3044_46._lastInstance.frequentlyUsed = null; } } static resetFrequentlyUsedReactionEmojis() { if (c3044_46._lastInstance != null) { c3044_46._lastInstance.frequentlyUsedReactionEmojis = null; c3044_46._lastInstance.frequentlyUsedReactionNamesAndIds = null; } } static clear(a0) { if (c3044_46._lastInstance != null && c3044_46._lastInstance.guildId === a0) { c3044_46._lastInstance = null; } } getDisambiguatedEmoji() { return this.disambiguatedEmoji; } getCustomEmoji() { return this.customEmojis; } getGroupedCustomEmoji() { return this.customEmojisByGroup; } getByName(a0) { const r6 = this.emojisByName.get(a0); if (r6 != null) { return r6; } const r8 = this.unicodeAliases.get(a0); return r8 != null ? this.emojisByName.get(r8) : void 0; } getEmoticonByName(a0) { return this.emoticonsByName.get(a0); } getById(a0) { return this.emojisById.get(a0); } getCustomEmoticonRegex() { if (this.emoticonRegex == null && this.escapedEmoticonNames != null && this.escapedEmoticonNames !== "") { this.emoticonRegex = new RegExp(`^\\b(${this.escapedEmoticonNames})\\b`); } return this.emoticonRegex; } getFrequentlyUsedEmojisWithoutFetchingLatest() { if (this.frequentlyUsed != null) { return this.frequentlyUsed; } this.frequentlyUsed = [...dedupeEmojisByNameOrId(c3044_39.frequently.map((item) => item.id != null ? this.getById(item.id) : UnicodeEmojis.getByName(item.name)).filter(isNotNullish)).values()]; return this.frequentlyUsed; } rebuildFrequentlyUsedReactionsEmojisWithoutFetchingLatest() { if (this.frequentlyUsedReactionEmojis != null && this.frequentlyUsedReactionNamesAndIds != null) { return { frequentlyUsedReactionEmojis: this.frequentlyUsedReactionEmojis, frequentlyUsedReactionNamesAndIds: this.frequentlyUsedReactionNamesAndIds }; } const r27 = dedupeEmojisByNameOrId(c3044_40.frequently.map((item) => item.id != null ? this.getById(item.id) : UnicodeEmojis.getByName(item.name)).filter(isNotNullish)); this.frequentlyUsedReactionEmojis = [...r27.values()]; this.frequentlyUsedReactionNamesAndIds = new Set(r27.keys()); return { frequentlyUsedReactionEmojis: this.frequentlyUsedReactionEmojis, frequentlyUsedReactionNamesAndIds: this.frequentlyUsedReactionNamesAndIds }; } getFrequentlyUsedReactionEmojisWithoutFetchingLatest() { return this.rebuildFrequentlyUsedReactionsEmojisWithoutFetchingLatest().frequentlyUsedReactionEmojis; } isFrequentlyUsedReactionEmojiWithoutFetchingLatest(a0) { const frequentlyUsedReactionNamesAndIds = this.rebuildFrequentlyUsedReactionsEmojisWithoutFetchingLatest().frequentlyUsedReactionNamesAndIds; if (a0.id != null) { return frequentlyUsedReactionNamesAndIds.has(a0.id); } let r15 = UnicodeEmojis.convertSurrogateToBase(a0.surrogates); if (r15 == null) { r15 = a0; } return frequentlyUsedReactionNamesAndIds.has(r15.name); } rebuildFavoriteEmojisWithoutFetchingLatest() { if (this.favorites != null && this.favoriteNamesAndIds != null) { return { favorites: this.favorites, favoriteNamesAndIds: this.favoriteNamesAndIds }; } let r8 = UserSettingsProtoStore.frecencyWithoutFetchingLatest.favoriteEmojis?.emojis; if (r8 == null) { r8 = []; } const r30 = dedupeEmojisByNameOrId(r8.map((item) => { let r6 = this.getById(item); if (r6 == null) { r6 = UnicodeEmojis.getByName(item); } return r6; }).filter(isNotNullish)); this.favorites = [...r30.values()]; this.favoriteNamesAndIds = new Set(r30.keys()); return { favorites: this.favorites, favoriteNamesAndIds: this.favoriteNamesAndIds }; } get favoriteEmojisWithoutFetchingLatest() { return this.rebuildFavoriteEmojisWithoutFetchingLatest().favorites; } getEmojiInPriorityOrderWithoutFetchingLatest() { const frequentlyUsedReactionEmojisWithoutFetchingLatest = this.getFrequentlyUsedReactionEmojisWithoutFetchingLatest(); let c14590_0 = new Set(); return this.favoriteEmojisWithoutFetchingLatest.concat(frequentlyUsedReactionEmojisWithoutFetchingLatest).filter((item) => { const r6 = c14590_0.has(item); let r0 = !r6; if (!r6) { c14590_0.add(item); r0 = true; } return r0; }); } getTopEmojiWithoutFetchingLatest(a0) { let c14591_0, c14591_1; if (this.topEmojis == null) { const r12 = c3044_34.get(a0); const topEmojiIdsByGuildId = TopEmojiStore.getTopEmojiIdsByGuildId(a0); if (r12 == null && topEmojiIdsByGuildId == null) { return c3044_26; } let r15 = r12?.emojiIds; if (r15 == null) { r15 = topEmojiIdsByGuildId; } const r10 = r15.map((item) => { let r8 = this.getById(item); if (r8 == null) { r8 = UnicodeEmojis.getByName(UnicodeEmojis.convertSurrogateToName(item, false)); } return r8; }); const r18 = []; c14591_1 = r18; r10.forEach((item) => { if (item != null) { c14591_1.push(item); } }); c14591_0 = this.getNewlyAddedEmojiForGuild(a0).map((item) => item.id); this.topEmojis = r18.filter((item) => !c14591_0.includes(item.id)); } return this.topEmojis; } getNewlyAddedEmojiForGuild(a0) { if (this.newlyAddedEmoji == null) { return c3044_26; } let r7 = this.newlyAddedEmoji.get(a0); if (r7 == null) { r7 = c3044_26; } return r7; } getEscapedCustomEmoticonNames() { return this.escapedEmoticonNames; } nameMatchesChain(c14592_0) { return Module12(this.getDisambiguatedEmoji()).filter(({ names, name }) => { let r11 = names != null && Module12.some(names, c14592_0); const r16 = name != null && c14592_0(name); const r19 = name != null && Module12.some(EmojiTerms.getTermsForEmoji(name), c14592_0); if (!r11) { r11 = r16; } if (!r11) { r11 = r19; } return r11; }); } }; EmojiDisambiguations = c3044_46; const resetFrequentlyUsed3 = c3044_46.resetFrequentlyUsed; const r206 = {}; const r207 = env3045 = { $parent: r12 }; resetFrequentlyUsed2 = resetFrequentlyUsed3; HermesBuiltin.copyDataProperties(r206, { computeBonus: $mk75316(), lookupKey: $mk75317(), afterCompute: $mk75318(r207), numFrequentlyItems: 42 }); c3044_39 = new Frecency(r206); const resetFrequentlyUsedReactionEmojis3 = c3044_46.resetFrequentlyUsedReactionEmojis; const r222 = {}; const r223 = env3046 = { $parent: r12 }; resetFrequentlyUsedReactionEmojis2 = resetFrequentlyUsedReactionEmojis3; HermesBuiltin.copyDataProperties(r222, { computeBonus: $mk75316(), lookupKey: $mk75317(), afterCompute: $mk75318(r223), numFrequentlyItems: 42 }); r222.computeFrecency = (a0, a1, a2) => { if (a2.maxTotalUse == null) { return 0; } return Math.trunc(1000 * (a0 / a2.maxTotalUse * 0.2 + a1 / 1000 * 0.8)); }; r222.calculateMaxTotalUse = true; c3044_40 = new Frecency(r222); class EmojiStore extends Module589.PersistedStore { static displayName = "EmojiStore"; static persistKey = "EmojiStoreV2"; static migrations = [(a0) => ({ ...a0 })]; constructor() { super(...arguments); } initialize(a0) { this.waitFor(ExperimentStore, GuildMemberStore, GuildMembershipStore, GuildRoleStore, GuildStore, LocaleStore, RawGuildEmojiStore, SortedGuildStore, SubscriptionRoleStore, TopEmojiStore, UserSettingsProtoStore, UserStore); if (a0 != null) { if (a0.pendingUsages != null) { env3044[23].pendingUsages = a0.pendingUsages; } if (a0.emojiReactionPendingUsages != null) { env3044[23].emojiReactionPendingUsages = a0.emojiReactionPendingUsages; } if (a0.expandedSectionsByGuildIds != null) { env3044[23].expandedSectionsByGuildIds = new Set(a0.expandedSectionsByGuildIds); } } this.syncWith([UserSettingsProtoStore], handleUserSettingsProtoStoreChange); } getState() { return env3044[23]; } get loadState() { return env3044[30]; } hasPendingUsage() { return env3044[23].pendingUsages.length > 0 || env3044[23].emojiReactionPendingUsages.length > 0; } get expandedSectionsByGuildIds() { return env3044[23].expandedSectionsByGuildIds; } get categories() { return c3044_31; } get diversitySurrogate() { let r7 = UnicodeEmojis.getDefaultDiversitySurrogate(); if (r7 == null) { r7 = ""; } return r7; } get emojiFrecencyWithoutFetchingLatest() { return c3044_39; } get emojiReactionFrecencyWithoutFetchingLatest() { return c3044_40; } getGuildEmoji(a0) { loadSavedEmojis(); let r10 = (a0 == null ? void 0 : env3044[32][a0])?.emojis; if (r10 == null) { r10 = c3044_27; } return r10; } getHiddenEmojiIds(a0) { loadSavedEmojis(); let r10 = (a0 == null ? void 0 : env3044[32][a0])?.hiddenEmojiIds; if (r10 == null) { r10 = c3044_28; } return r10; } getUsableGuildEmoji(a0) { loadSavedEmojis(); let r9 = env3044[32][a0]?.usableEmojis; if (r9 == null) { r9 = c3044_27; } return r9; } getGuilds() { return env3044[32]; } getDisambiguatedEmojiContext(a0) { loadSavedEmojis(); return EmojiDisambiguations.get(a0); } getSearchResultsOrder(a0, a1, a2, c14593_0, c14593_1) { let boostFavorites, boostAtEnd, boostsIgnoreDisambiguators, c14593_6, c14593_7, c14593_8; const r9 = a1.toLowerCase(); let c14593_2 = r9; const r20 = RegexUtils.escape(r9); const r19 = RegexUtils.escape(r9.slice(0, 1).toUpperCase() + r9.slice(1)); const length = a0.length; let r43 = a0; if (length > 0) { const config = EmojiSearchRankingTweaksExperiment.getConfig({ location: "getSearchResultsOrder" }); boostFavorites = config.boostFavorites; const boostCapitalizedWords = config.boostCapitalizedWords; boostAtEnd = config.boostAtEnd; boostsIgnoreDisambiguators = config.boostsIgnoreDisambiguators; const regExp = new RegExp(`^${r20}`, "i"); const regExp2 = new RegExp(`${r20}\$`, "i"); let r71 = new RegExp(`(^|_|[A-Z])${r20}s?([A-Z]|_|\$)`); const regExp3 = new RegExp(`(^|_|[A-Z])${r20}s?([A-Z]|_|\$)|(^|_|[a-z])${r19}s?([A-Z]|_|\$)`); if (boostCapitalizedWords) { r71 = regExp3; } c14593_6 = r71.test.bind(r71); c14593_7 = regExp.test.bind(regExp); c14593_8 = regExp2.test.bind(regExp2); r43 = Module12.orderBy(a0, [(a0) => { let r12; const r8 = a0.uniqueName != null; if (r8) { r12 = a0.names[0]; } else { const name = a0.name; r12 = boostsIgnoreDisambiguators ? name.split("~")[0] : name; } const r20 = r8 ? r12 : a0.id; const r21 = r12 == null; let r4 = 0; if (!r21) { const r22 = r20 == null; r4 = 0; if (!r22) { const r24 = r12.toLowerCase(); const r5 = r24 === c14593_2 ? 4 : 0; const r6 = c14593_6(r24) ? 2 : c14593_6(r12) ? 2 : 0; const r2 = c14593_7(r12) ? 1 : boostAtEnd ? c14593_8(r12) ? 0.75 : 0 : 0; const r36 = boostFavorites ? c14593_1.isFavoriteEmojiWithoutFetchingLatest(a0) ? 0.5 : 0 : 0; const r46 = c14593_0 === EmojiIntention.REACTION ? c3044_40.getScore(r20) : c3044_39.getScore(r20); const r52 = 1 + r5 + r6 + r2 + r36; r4 = r46 != null ? r52 * (r46 / 100) : r52; } } return r4; }, (a0) => a0.names != null ? a0.names[0] : a0.name], ["desc", "asc"]); } return a2 > 0 ? r43.slice(0, a2) : r43; } searchWithoutFetchingLatest(a0) { let c14594_4; const { channel, query, count = 0, intention, includeExternalGuilds = true } = a0; const forceIncludeExternalGuilds = includeExternalGuilds; let matchComparator = a0.matchComparator; const showOnlyUnicode = a0.showOnlyUnicode; c14594_4 = void 0; loadSavedEmojis(); const r33 = RegexUtils.escape(query.toLowerCase().replaceAll(/[ _]/g, "")); if (matchComparator == null) { c14594_4 = new RegExp(`${r33}`, "i"); matchComparator = (a0) => c14594_4.test(a0.replaceAll("_", "")); } const r47 = EmojiDisambiguations.get(channel != null ? channel.getGuildId() : null); const r55 = r47.nameMatchesChain(matchComparator).reduce((acc, item) => { const emojiUnavailableReason = EmojiUtils.getEmojiUnavailableReason({ emoji: item, channel, intention, forceIncludeExternalGuilds }); if (emojiUnavailableReason === EmojiDisabledReasons.PREMIUM_LOCKED && !showOnlyUnicode) { acc.locked.push(item); } else { let r22 = emojiUnavailableReason != null; if (!r22) { let r23 = showOnlyUnicode; if (showOnlyUnicode) { r23 = item.type !== EmojiTypes.UNICODE; } r22 = r23; } if (!r22) { acc.unlocked.push(item); } } return acc; }, { unlocked: [], locked: [] }); return { unlocked: this.getSearchResultsOrder(r55.unlocked, query, count, intention, r47), locked: this.getSearchResultsOrder(r55.locked, query, 0, intention, r47) }; } getUsableCustomEmojiById(a0) { loadSavedEmojis(); const r6 = getEmojiToGroupId()[a0]; const r3 = r6 != null; let r12 = void 0; if (r3) { const r7 = env3044[32][r6]; let r15 = r7 == null ? void 0 : r7.getUsableEmoji(a0); if (r15 == null) { r15 = void 0; } r12 = r15; } return r12; } getCustomEmojiById(a0) { loadSavedEmojis(); const r6 = getEmojiToGroupId()[a0]; const r3 = r6 != null; let r12 = void 0; if (r3) { const r7 = env3044[32][r6]; let r15 = r7 == null ? void 0 : r7.getEmoji(a0); if (r15 == null) { r15 = void 0; } r12 = r15; } return r12; } getTopEmoji(a0) { let r10; if (a0 == null) { r10 = c3044_26; } else { loadSavedEmojis(); r10 = EmojiDisambiguations.get(a0).getTopEmojiWithoutFetchingLatest(a0); } return r10; } getNewlyAddedEmoji(a0) { let r10; if (a0 == null) { r10 = c3044_26; } else { loadSavedEmojis(); r10 = EmojiDisambiguations.get(a0).getNewlyAddedEmojiForGuild(a0); } return r10; } getTopEmojisMetadata(a0) { return c3044_34.get(a0); } hasUsableEmojiInAnyGuild() { loadSavedEmojis(); return SnowflakeUtils.keys(env3044[32]).some((item) => env3044[32][item].usableEmojis.length > 0); } hasFavoriteEmojis(a0) { const r7 = EmojiDisambiguations.get(a0); return r7 != null && r7.favoriteEmojisWithoutFetchingLatest.length > 0; } } c3044_48 = EmojiStore; const r314 = new EmojiStore(Dispatcher, { LOGOUT: function handleLogout() { env3044[23].pendingUsages = []; env3044[23].emojiReactionPendingUsages = []; }, BACKGROUND_SYNC: function handleBackgroundSync() { env3044[32] = {}; env3044[33] = {}; EmojiDisambiguations.reset(); c3044_34.clear(); env3044[30] = c3044_29.Unloaded; }, CONNECTION_OPEN: function handleConnectionOpen(a0) { deleteEverything(); for (const guild of a0.guilds) { updateGuildEmoji(guild.id); } env3044[30] = a0.unavailableGuilds.length === 0 && a0.guilds.every((guild) => guild.emojis.op === "full_sync") ? c3044_29.Loaded : c3044_29.Unloaded; rebuildEmojis(); }, OVERLAY_INITIALIZE: function handleOverlayInitialize(a0) { env3044[32] = {}; env3044[33] = {}; EmojiDisambiguations.reset(); c3044_34.clear(); env3044[30] = c3044_29.Unloaded; const emojis2 = a0.emojis; for (const key in emojis2) { updateGuildEmoji(key); } env3044[30] = c3044_29.Loaded; env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } }, CACHED_EMOJIS_LOADED: function handleCachedEmojisLoaded(a0) { for (const emoji of a0.emojis) { const [r9] = emoji; if (GuildMembershipStore.isMember(r9)) { updateGuildEmoji(r9); } } rebuildEmojis(); }, GUILD_MEMBER_UPDATE: function handleGuildMemberUpdate(a0) { const guildId = a0.guildId; if (a0.user.id === UserStore.getCurrentUser()?.id) { updateGuildEmoji(guildId); env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } } }, GUILD_CREATE: function handleGuildCreate(a0) { updateGuildEmoji(a0.guild.id); env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } }, GUILD_UPDATE: function handleGuildUpdate(a0) { updateGuildEmoji(a0.guild.id); env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } }, GUILD_EMOJIS_UPDATE: function handleGuildEmojiUpdated(a0) { updateGuildEmoji(a0.guildId); env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } }, GUILD_DELETE: function handleGuildDelete({ guild }) { const id = guild.id; if (env3044[32][id] != null) { delete env3044[32][id]; } c3044_34.delete(guild.id); env3044[33] = null; EmojiDisambiguations.reset(); if (env3044[30] === c3044_29.Loaded) { c3044_39.compute(); c3044_40.compute(); } }, MESSAGE_REACTION_ADD: function handleAddReaction(a0) { if (a0.optimistic) { const r24 = a0.emoji.id != null && a0.emoji.id !== "0" ? a0.emoji : UnicodeEmojis.getByName(UnicodeEmojis.convertSurrogateToName(a0.emoji.name, false)); if (r24 == null) { return false; } (function trackReactionUsage(a0) { for (const item of a0) { let id = item.id; if (id == null) { id = item.uniqueName; } if (id == null) { id = item.name; } if (id != null) { const key = id; c3044_40.track(key); env3044[23].emojiReactionPendingUsages.push({ key, timestamp: Date.now() }); } } const r44 = a0.length > 0; if (r44 && env3044[30] === c3044_29.Loaded) { c3044_40.compute(); } return r44; })([r24]); trackUsage([r24]); return void 0; } return false; }, EMOJI_TRACK_USAGE: function handleTrackUsage(a0) { trackUsage(a0.emojiUsed); }, USER_SETTINGS_PROTO_UPDATE: function handleUserSettingsProtoUpdate(a0) { const type = a0.settings.type; const wasSaved = a0.wasSaved; EmojiTerms.setEmojiLocale(LocaleStore.locale); if (type === UserSettingsTypes.FRECENCY_AND_FAVORITES_SETTINGS && wasSaved) { env3044[23].pendingUsages = []; env3044[23].emojiReactionPendingUsages = []; return void 0; } return false; }, GUILD_ROLE_CREATE: handleRoleUpdate, GUILD_ROLE_UPDATE: handleRoleUpdate, TOP_EMOJIS_FETCH_SUCCESS: function handleTopEmojisLoaded(a0) { c3044_34.set(a0.guildId, { emojiIds: a0.topEmojisMetadata.map((item) => item.emojiId), topEmojisTTL: Module3771(Module3771()).add(1, "days").valueOf() }); }, TOGGLE_GUILD_EXPANDED_STATE: function toggleGuildExpandedState({ guildId }) { const set = new Set(env3044[23].expandedSectionsByGuildIds); if (env3044[23].expandedSectionsByGuildIds.has(guildId)) { set.delete(guildId); } else { set.add(guildId); } env3044[23] = { ...env3044[23], expandedSectionsByGuildIds: set }; } }); export default r314; export { c3044_29 as LoadState }; export { c3044_46 as EmojiDisambiguations };