Module 507104

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