Module 507104

5,728 characters · in no known chunk
Dependencies
Lazily required by (0)none
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";n.d(t,{Ay:()=>F,ZD:()=>S,hb:()=>N}),n(321073);var i=n(735438),r=n.n(i),s=n(17928),a=n(228366),o=n(736056),l=n(710195),u=n(427358),d=n(885386),c=n(617617),_=n(153488),h=n(994500),f=n(70730);function E(e){let{enabled:t}=f.u.getConfig(e);return{enabled:t}}var p=n(689739),m=n(620750),g=n(194537),A=n(174997);function I(e,t,n){let i={};for(let r in e){let s=e[r];t-s<=n&&(i[r]=s)}return i}var T=n(652215);let S=5,N=6048e5;function C(){return{messageGiftIntentLastShownMap:{},lastShownFriendsListGiftIntents:[],friendsTabBadgeLastDismissedTime:null,lastKnownGiftIntentDismissedAtMs:0}}let y=C(),v=[],R=new Set,O=new Set,b={},L=null,D=null,P=null;function w(){return P??Date.now()}function M(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],{highestAffinity:t,highAffinity:n}=function(e,t,n){let i=new Set,r=new Set;if(n){let t=Math.ceil(e.length/2);e.slice(0,t).forEach(e=>{i.add(e)}),e.forEach(e=>{r.add(e)})}else for(let n of e){let e=t(n);null!=e&&e>.7&&i.add(n),null!=e&&e>.5&&r.add(n)}return{highestAffinity:i,highAffinity:r}}(v,e=>u.A.getUserAffinity(e)?.dmProbability,e);R=t,O=n}function x(){if(null!=L)return void G(L);if(U(),!_.A.hasConsented(T.YAq.PERSONALIZATION)||!d.oz.getSetting())return;for(let e of h.A.getFriendIDs()){let t=h.A.getSince(e),n=u.A.getUserAffinity(e);if(h.A.isFriend(e)&&null!=n&&n.dmProbability>0&&null!=t){let n=new Date(t);(function(e){let t=new Date,n=t.getFullYear();for(let i of[-1,0,1]){let r=(0,p.default)(e,n+i);if(!(0,m.default)(r,e)&&7>=Math.abs((0,g.A)(t,r)))return!0}return!1})(n)&&(v.push(e),b[e]={friendsSince:n})}}if(0===v.length)return;let{enabled:e}=E({location:"PremiumGiftingIntentStore updateFriendAnniversaries"});e?(v.sort((e,t)=>u.A.compareByDmProbability(e,t)),M()):U()}function U(){v.length=0,R=new Set,O=new Set,b={}}function k(e){null==y.messageGiftIntentLastShownMap[e]&&(y.messageGiftIntentLastShownMap[e]=w())}function G(e){U();let{enabled:t}=E({location:"PremiumGiftingIntentStore generateFriendAnniversaries"});if(!t||!d.oz.getSetting())return;L=e;let n=h.A.getFriendIDs().filter(e=>!h.A.isIgnored(e)),i=new Set(n),s=null!=D&&D.length===e&&D.every(e=>i.has(e))?D:r().sampleSize(n,e);D=s,s.forEach(e=>{let t=h.A.getSince(e);if(null!=t){let n=new Date(t);v.push(e),b[e]={friendsSince:n}}}),v.sort((e,t)=>u.A.compareByDmProbability(e,t)),M(!0)}class V extends s.Ay.PersistedStore{static displayName="PremiumGiftingIntentStore";static persistKey="PremiumGiftingIntentStore";static migrations=[e=>null==e?e:{friendsTabBadgeLastDismissedTime:e.friendsTabBadgeLastDismissedTime??null,lastShownFriendsListGiftIntents:e.lastShownFriendsListGiftIntents??[],messageGiftIntentLastShownMap:{}},e=>null==e?e:{friendsTabBadgeLastDismissedTime:null,lastShownFriendsListGiftIntents:e.lastShownFriendsListGiftIntents??[],messageGiftIntentLastShownMap:e.messageGiftIntentLastShownMap??{},giftUnreadNotificationLastDismissedTimes:[]},e=>null==e?e:{friendsTabBadgeLastDismissedTime:null,lastShownFriendsListGiftIntents:e.lastShownFriendsListGiftIntents??[],messageGiftIntentLastShownMap:e.messageGiftIntentLastShownMap??{},giftUnreadNotificationLastDismissedTimes:e.giftUnreadNotificationLastDismissedTimes??[],profilePopoutGiftIntentsDismissMap:{}},e=>null==e?e:{...e,lastKnownGiftIntentDismissedAtMs:e.lastKnownGiftIntentDismissedAtMs??0},e=>(null==e||delete e.profilePopoutGiftIntentsDismissMap,e),e=>{if(null==e)return e;let t={...e};return delete t.giftUnreadNotificationLastDismissedTimes,t}];initialize(e){y=C(),null!=e&&(y.friendsTabBadgeLastDismissedTime=e.friendsTabBadgeLastDismissedTime,y.lastShownFriendsListGiftIntents=Array.from(e.lastShownFriendsListGiftIntents),y.messageGiftIntentLastShownMap={...e.messageGiftIntentLastShownMap},y.lastKnownGiftIntentDismissedAtMs=e.lastKnownGiftIntentDismissedAtMs??0),this.syncWith([h.A,u.A,_.A,o.A,l.A,c.A],x),y.messageGiftIntentLastShownMap=I(y.messageGiftIntentLastShownMap,w(),12096e5)}getState(){return y}getFriendAnniversaries(){return v}canShowFriendsTabBadge(){return Array.from(O).some(e=>!y.lastShownFriendsListGiftIntents.includes(e))}getFriendAnniversaryYears(e){var t;let n=b[e];return null==n?0:(t=n.friendsSince,Math.round((0,A.A)(new Date,t)/12))}isGiftIntentMessageInCooldown(e){return null!=y.messageGiftIntentLastShownMap[e]}getDevToolTotalFriendAnniversaries(){return L}getDevToolCurrentDate(){return P}getHighestAffinityFriendAnniversaries(){return Array.from(R)}getHighAffinityFriendAnniversaries(){return Array.from(O)}getMessageGiftIntentLastShownMap(){return y.messageGiftIntentLastShownMap}getLastKnownGiftIntentDismissedAtMs(){return y.lastKnownGiftIntentDismissedAtMs}}let F=new V(a.h,{CONNECTION_OPEN:function(){U()},LOGOUT:function(){y=C(),U()},MESSAGE_GIFT_INTENT_SHOWN:function(e){let{recipientUserId:t}=e;k(t)},FRIENDS_LIST_GIFT_INTENTS_SHOWN:function(){y.lastShownFriendsListGiftIntents=Array.from(v)},GIFT_INTENT_FLOW_PURCHASED_GIFT:function(e){let{recipientUserId:t}=e;k(t)},GIFT_INTENT_DISMISSALS_FETCH_SUCCESS:function(e){let{dismissals:t,settingsTimestampMs:n}=e,i={...y.messageGiftIntentLastShownMap};for(let{targetId:e,dismissedAtMs:n}of t){let t=i[e];i[e]=null==t?n:Math.max(t,n)}y.messageGiftIntentLastShownMap=I(i,w(),1296e6),y.lastKnownGiftIntentDismissedAtMs=n},DEV_TOOLS_FRIENDS_LIST_GIFT_INTENTS_SHOWN_RESET:function(){y.lastShownFriendsListGiftIntents=[]},DEV_TOOLS_GIFT_MESSAGE_COOLDOWN_RESET:function(){y.messageGiftIntentLastShownMap={}},DEV_TOOLS_SET_FRIEND_ANNIVERSARY_COUNT:function(e){let{total:t}=e;if(null==t){L=null,D=null,x();return}G(t)},DEV_TOOLS_RESAMPLE_FRIEND_ANNIVERSARIES:function(){return null!=L&&(D=null,G(L),!0)},DEV_TOOLS_SET_CURRENT_DATE:function(e){let{date:t}=e;P=t},DEV_TOOLS_RESET_CURRENT_DATE:function(){P=null}})}