Module 732071

2,395 characters · in no known chunk
Dependencies
Required by (2)
Lazily required by (0)none
Lazily requires (0)none
Source Raw
function(e,t,n){"use strict";n.d(t,{A:()=>m,K:()=>f}),n(321073);var r=n(635377),i=n.n(r),s=n(439372),a=n(954571),o=n(652215);let l=6e4,u=1e3,c=10,d=2e3,_=500;var f=function(e){return e.ANNOUNCEMENT="announcement",e.APP_EMBED="app_embed",e}({});function p(e){if("announcement"===e.type)return{event:o.HAw.ANNOUNCEMENT_MESSAGE_VIEWED,properties:{message_id:e.messageId,channel_id:e.channelId,guild_id:e.guildId,source_channel_id:e.sourceChannelId,source_guild_id:e.sourceGuildId}};if("app_embed"===e.type)return{event:o.HAw.APP_EMBED_VIEWED,properties:{application_id:e.applicationId,link_type:e.linkType,message_id:e.messageId,channel_id:e.channelId,guild_id:e.guildId}};throw Error("Invalid message type for message view tracking")}class h extends s.A{currentlyVisibleMessageTimers={};viewsInCurrentChannel=new Set;recentViewTimes=new(i())({max:_,maxAge:l});batchBuffer=[];batchTimerId=null;actions={CHANNEL_SELECT:()=>this.handleChannelSelect()};handleMessageBecameVisible(e){let{type:t,messageId:n}=e,r=`${n}-${t}`;if(null!=this.currentlyVisibleMessageTimers[r]||this.viewsInCurrentChannel.has(r))return;let i=this.recentViewTimes.get(r);if(null!=i&&Date.now()-i<l)return;let s=setTimeout(()=>{delete this.currentlyVisibleMessageTimers[r],this.viewsInCurrentChannel.add(r),this.recentViewTimes.set(r,Date.now()),this.bufferViewTrack(e)},u);this.currentlyVisibleMessageTimers[r]=s}handleMessageLostVisibility(e,t){let n=`${e}-${t}`,r=this.currentlyVisibleMessageTimers[n];null!=r&&(clearTimeout(r),delete this.currentlyVisibleMessageTimers[n])}handleMessageListVisibilityChange(e){for(let t of e)this.handleMessageBecameVisible(t);let t=new Set(e.map(e=>`${e.messageId}-${e.type}`));for(let e of Object.keys(this.currentlyVisibleMessageTimers))if(!t.has(e)){let[t,n]=e.split("-");this.handleMessageLostVisibility(t,n)}}handleChannelSelect(){for(let e of Object.values(this.currentlyVisibleMessageTimers))clearTimeout(e);this.currentlyVisibleMessageTimers={},this.viewsInCurrentChannel.clear(),this.drainBuffer()}drainBuffer(){for(let e of this.batchBuffer){let t=p(e);a.default.track(t.event,t.properties)}this.batchBuffer=[],null!=this.batchTimerId&&(clearTimeout(this.batchTimerId),this.batchTimerId=null)}bufferViewTrack(e){this.batchBuffer.length>=c&&this.drainBuffer(),this.batchBuffer.push(e),null==this.batchTimerId&&(this.batchTimerId=setTimeout(()=>this.drainBuffer(),d))}}let m=new h}