// Metro module 7853 (f7854). import ExperimentStore from "../../experiments/ExperimentStore"; import ApexExperimentStore from "../../experiments/apex/ApexExperimentStore"; import UserAffinitiesV2Store from "../../user_affinities/UserAffinitiesV2Store"; import UserSettingsProtoStore from "../../user_settings/UserSettingsProtoStore"; import ConsentStore from "../../../stores/ConsentStore"; import RelationshipStore from "../../../stores/RelationshipStore"; import { Consents } from "../../../Constants"; import { categorizeFriendAnniversariesByAffinity, isFriendAnniversary, pruneTimestampMap, yearsSince } from "./shared/FriendAnniversaryUtils"; import { EnableFriendAnniversaryNotifications } from "../../user_settings/UserSettings"; import { getFriendAnniversaryGateConfig } from "./FriendAnniversaryGate.native"; import Module12 from "../../../_bundle/Module12"; import Module589 from "../../../_bundle/Module589"; import Dispatcher from "../../../Dispatcher"; let c4958_10, c4958_11, highestAffinity, highAffinity, c4958_14, c4958_15, c4958_16, date, categorizeTopAffinityFriendAnniversaries, updateFriendAnniversaries, resetFriendAnniversaries, generateFriendAnniversaries, $mk79328 = function() { return (a0) => UserAffinitiesV2Store.getUserAffinity(a0)?.dmProbability; }; const getCurrentTime = function getCurrentTime() { let r4 = date; if (r4 == null) { r4 = Date.now(); } return r4; }; categorizeTopAffinityFriendAnniversaries = function categorizeTopAffinityFriendAnniversaries() { const r0 = void 0 === void 0 ? false : void 0; const r11 = categorizeFriendAnniversariesByAffinity(c4958_11, $mk79328(), r0); const { highestAffinity: highestAffinity2, highAffinity: highAffinity2 } = r11; highestAffinity = highestAffinity2; highAffinity = highAffinity2; }; updateFriendAnniversaries = function updateFriendAnniversaries() { let r26; if (c4958_15 == null) { resetFriendAnniversaries(); if (ConsentStore.hasConsented(Consents.PERSONALIZATION) && EnableFriendAnniversaryNotifications.getSetting()) { let r47 = RelationshipStore.getFriendIDs()[Symbol.iterator](); const next = r47.next; while (true) { const r14 = r47 === void 0 ? void 0 : (r26 = next.call(r47)).done ? r47 = void 0 : r26.value; if (r47 === void 0) { if (c4958_11.length === 0) { break; } if (getFriendAnniversaryGateConfig({ location: "PremiumGiftingIntentStore updateFriendAnniversaries" }).enabled) { c4958_11.sort((a, b) => UserAffinitiesV2Store.compareByDmProbability(a, b)); categorizeTopAffinityFriendAnniversaries(); break; } resetFriendAnniversaries(); break; } try { const since = RelationshipStore.getSince(r14); const userAffinity = UserAffinitiesV2Store.getUserAffinity(r14); if (RelationshipStore.isFriend(r14) && userAffinity != null && userAffinity.dmProbability > 0 && since != null) { const date2 = new Date(since); if (isFriendAnniversary(date2)) { c4958_11.push(r14); c4958_14[r14] = { friendsSince: date2 }; } } } catch (r80) { if (r47 !== void 0 && typeof r47.return === "function") { try { r47.return(); } catch {} } throw r80; } } } } else { generateFriendAnniversaries(c4958_15); } }; resetFriendAnniversaries = function resetFriendAnniversaries() { c4958_11.length = 0; highestAffinity = new Set(); highAffinity = new Set(); c4958_14 = {}; }; generateFriendAnniversaries = function generateFriendAnniversaries(total) { c4958_11.length = 0; highestAffinity = new Set(); highAffinity = new Set(); c4958_14 = {}; if (getFriendAnniversaryGateConfig({ location: "PremiumGiftingIntentStore generateFriendAnniversaries" }).enabled && EnableFriendAnniversaryNotifications.getSetting()) { let c16042_0; c4958_15 = total; const r40 = RelationshipStore.getFriendIDs().filter((item) => !RelationshipStore.isIgnored(item)); c16042_0 = new Set(r40); const r57 = c4958_16 != null && (c4958_16.length === total && c4958_16.every((item) => c16042_0.has(item))) ? c4958_16 : Module12.sampleSize(r40, total); c4958_16 = r57; r57.forEach((item) => { const since = RelationshipStore.getSince(item); if (since != null) { const date2 = new Date(since); c4958_11.push(item); c4958_14[item] = { friendsSince: date2 }; } }); c4958_11.sort((a, b) => UserAffinitiesV2Store.compareByDmProbability(a, b)); const r69 = categorizeFriendAnniversariesByAffinity(c4958_11, $mk79328(), true); const { highestAffinity: highestAffinity2, highAffinity: highAffinity2 } = r69; highestAffinity = highestAffinity2; highAffinity = highAffinity2; } }; c4958_10 = { messageGiftIntentLastShownMap: {}, lastShownFriendsListGiftIntents: [], friendsTabBadgeLastDismissedTime: null, lastKnownGiftIntentDismissedAtMs: 0 }; c4958_11 = []; highestAffinity = new Set(); highAffinity = new Set(); c4958_14 = {}; c4958_15 = null; c4958_16 = null; date = null; class PremiumGiftingIntentStore extends Module589.PersistedStore { static displayName = "PremiumGiftingIntentStore"; static persistKey = "PremiumGiftingIntentStore"; static migrations = [(a0) => { let r1 = a0; if (a0 != null) { let friendsTabBadgeLastDismissedTime = a0.friendsTabBadgeLastDismissedTime; if (friendsTabBadgeLastDismissedTime == null) { friendsTabBadgeLastDismissedTime = null; } let lastShownFriendsListGiftIntents = a0.lastShownFriendsListGiftIntents; if (lastShownFriendsListGiftIntents == null) { lastShownFriendsListGiftIntents = []; } r1 = { friendsTabBadgeLastDismissedTime, lastShownFriendsListGiftIntents, messageGiftIntentLastShownMap: {} }; } return r1; }, (a0) => { let r1 = a0; if (a0 != null) { let lastShownFriendsListGiftIntents = a0.lastShownFriendsListGiftIntents; if (lastShownFriendsListGiftIntents == null) { lastShownFriendsListGiftIntents = []; } let messageGiftIntentLastShownMap = a0.messageGiftIntentLastShownMap; if (messageGiftIntentLastShownMap == null) { messageGiftIntentLastShownMap = {}; } r1 = { friendsTabBadgeLastDismissedTime: null, lastShownFriendsListGiftIntents, messageGiftIntentLastShownMap, giftUnreadNotificationLastDismissedTimes: [] }; } return r1; }, (a0) => { let r1 = a0; if (a0 != null) { let lastShownFriendsListGiftIntents = a0.lastShownFriendsListGiftIntents; if (lastShownFriendsListGiftIntents == null) { lastShownFriendsListGiftIntents = []; } let messageGiftIntentLastShownMap = a0.messageGiftIntentLastShownMap; if (messageGiftIntentLastShownMap == null) { messageGiftIntentLastShownMap = {}; } let giftUnreadNotificationLastDismissedTimes = a0.giftUnreadNotificationLastDismissedTimes; if (giftUnreadNotificationLastDismissedTimes == null) { giftUnreadNotificationLastDismissedTimes = []; } r1 = { friendsTabBadgeLastDismissedTime: null, lastShownFriendsListGiftIntents, messageGiftIntentLastShownMap, giftUnreadNotificationLastDismissedTimes, profilePopoutGiftIntentsDismissMap: {} }; } return r1; }, (a0) => { let r2 = a0; if (a0 != null) { let lastKnownGiftIntentDismissedAtMs = a0.lastKnownGiftIntentDismissedAtMs; if (lastKnownGiftIntentDismissedAtMs == null) { lastKnownGiftIntentDismissedAtMs = 0; } r2 = { ...a0, lastKnownGiftIntentDismissedAtMs }; } return r2; }, (a0) => { if (a0 != null) { delete a0["profilePopoutGiftIntentsDismissMap"]; } return a0; }, (a0) => { if (a0 == null) { return a0; } const r2 = { ...a0 }; delete r2["giftUnreadNotificationLastDismissedTimes"]; return r2; }]; initialize(a0) { c4958_10 = { messageGiftIntentLastShownMap: {}, lastShownFriendsListGiftIntents: [], friendsTabBadgeLastDismissedTime: null, lastKnownGiftIntentDismissedAtMs: 0 }; if (a0 != null) { c4958_10.friendsTabBadgeLastDismissedTime = a0.friendsTabBadgeLastDismissedTime; c4958_10.lastShownFriendsListGiftIntents = Array.from(a0.lastShownFriendsListGiftIntents); c4958_10.messageGiftIntentLastShownMap = { ...a0.messageGiftIntentLastShownMap }; const r23 = c4958_10; let lastKnownGiftIntentDismissedAtMs = a0.lastKnownGiftIntentDismissedAtMs; if (lastKnownGiftIntentDismissedAtMs == null) { lastKnownGiftIntentDismissedAtMs = 0; } r23.lastKnownGiftIntentDismissedAtMs = lastKnownGiftIntentDismissedAtMs; } this.syncWith([RelationshipStore, UserAffinitiesV2Store, ConsentStore, ExperimentStore, ApexExperimentStore, UserSettingsProtoStore], updateFriendAnniversaries); const r36 = c4958_10; const messageGiftIntentLastShownMap = c4958_10.messageGiftIntentLastShownMap; let r44 = date; if (r44 == null) { r44 = Date.now(); } r36.messageGiftIntentLastShownMap = pruneTimestampMap(messageGiftIntentLastShownMap, r44, 1209600000); } getState() { return c4958_10; } getFriendAnniversaries() { return c4958_11; } canShowFriendsTabBadge() { return Array.from(highAffinity).some((item) => !c4958_10.lastShownFriendsListGiftIntents.includes(item)); } getFriendAnniversaryYears(a0) { const r5 = c4958_14[a0]; return r5 == null ? 0 : yearsSince(r5.friendsSince); } isGiftIntentMessageInCooldown(a0) { return c4958_10.messageGiftIntentLastShownMap[a0] != null; } getDevToolTotalFriendAnniversaries() { return c4958_15; } getDevToolCurrentDate() { return date; } getHighestAffinityFriendAnniversaries() { return Array.from(highestAffinity); } getHighAffinityFriendAnniversaries() { return Array.from(highAffinity); } getMessageGiftIntentLastShownMap() { return c4958_10.messageGiftIntentLastShownMap; } getLastKnownGiftIntentDismissedAtMs() { return c4958_10.lastKnownGiftIntentDismissedAtMs; } } const premiumGiftingIntentStore = new PremiumGiftingIntentStore(Dispatcher, { CONNECTION_OPEN: function handleConnectionOpen() { c4958_11.length = 0; highestAffinity = new Set(); highAffinity = new Set(); c4958_14 = {}; }, LOGOUT: function handleLogout() { c4958_10 = { messageGiftIntentLastShownMap: {}, lastShownFriendsListGiftIntents: [], friendsTabBadgeLastDismissedTime: null, lastKnownGiftIntentDismissedAtMs: 0 }; c4958_11.length = 0; highestAffinity = new Set(); highAffinity = new Set(); c4958_14 = {}; }, MESSAGE_GIFT_INTENT_SHOWN: function handleMessageGiftIntentShown({ recipientUserId }) { if (c4958_10.messageGiftIntentLastShownMap[recipientUserId] == null) { const messageGiftIntentLastShownMap = c4958_10.messageGiftIntentLastShownMap; let r11 = date; if (r11 == null) { r11 = Date.now(); } messageGiftIntentLastShownMap[recipientUserId] = r11; } }, FRIENDS_LIST_GIFT_INTENTS_SHOWN: function handleFriendsListGiftIntentsShown() { c4958_10.lastShownFriendsListGiftIntents = Array.from(c4958_11); }, GIFT_INTENT_FLOW_PURCHASED_GIFT: function handleGiftIntentFlowPurchasedGift({ recipientUserId }) { if (c4958_10.messageGiftIntentLastShownMap[recipientUserId] == null) { const messageGiftIntentLastShownMap = c4958_10.messageGiftIntentLastShownMap; let r11 = date; if (r11 == null) { r11 = Date.now(); } messageGiftIntentLastShownMap[recipientUserId] = r11; } }, GIFT_INTENT_DISMISSALS_FETCH_SUCCESS: function handleGiftIntentDismissalsFetchSuccess({ dismissals, settingsTimestampMs }) { const r8 = { ...c4958_10.messageGiftIntentLastShownMap }; for (const item of dismissals) { const { targetId, dismissedAtMs } = item; const r36 = r8[targetId]; r8[targetId] = r36 == null ? dismissedAtMs : Math.max(r36, dismissedAtMs); } c4958_10.messageGiftIntentLastShownMap = pruneTimestampMap(r8, getCurrentTime(), 1296000000); c4958_10.lastKnownGiftIntentDismissedAtMs = settingsTimestampMs; }, DEV_TOOLS_FRIENDS_LIST_GIFT_INTENTS_SHOWN_RESET: function handleDevToolResetFriendsListGiftIntentsShown() { c4958_10.lastShownFriendsListGiftIntents = []; }, DEV_TOOLS_GIFT_MESSAGE_COOLDOWN_RESET: function handleDevToolResetGiftMessageCooldown() { c4958_10.messageGiftIntentLastShownMap = {}; }, DEV_TOOLS_SET_FRIEND_ANNIVERSARY_COUNT: function handleDevToolSetFriendAnniversaryCount({ total }) { if (total == null) { c4958_15 = null; c4958_16 = null; updateFriendAnniversaries(); return void 0; } generateFriendAnniversaries(total); }, DEV_TOOLS_RESAMPLE_FRIEND_ANNIVERSARIES: function handleDevToolResampleFriendAnniversaries() { let r1 = c4958_15 != null; if (r1) { c4958_16 = null; generateFriendAnniversaries(c4958_15); r1 = true; } return r1; }, DEV_TOOLS_SET_CURRENT_DATE: function handleDevToolSetCurrentDate(a0) { date = a0.date; }, DEV_TOOLS_RESET_CURRENT_DATE: function handleDevToolResetCurrentDate() { date = null; } }); export default premiumGiftingIntentStore; export const FRIENDS_LIST_ANNIVERSARY_DISPLAY_LIMIT = 5; export const FRIENDS_TAB_BADGE_COOLDOWN_MS = 604800000;