Build 574548stable
Module 140069
4,638 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{A:()=>K});var i,r,s=n(17928),a=n(713402),o=n(228366),l=n(380335),u=n(567249),c=n(734057),d=n(232835),_=n(763827),h=n(568548),f=n(309010),E=n(543465),p=n(645959),m=n(927813),g=n(935208),A=n(206885),I=n(41984),T=n(956753),S=n(489277),N=n(222506),C=n(614455),y=((i={}).PRIVATE_CHANNELS="PRIVATE_CHANNELS",i.GUILD_CHANNELS="GUILD_CHANNELS",i),O=((r={})[r.READ=0]="READ",r[r.UNREAD=1]="UNREAD",r[r.MENTION=2]="MENTION",r);function R(e,t){return String(Math.max(0,Math.min(Math.floor(e),Number.MAX_SAFE_INTEGER))).padStart(t,"0")}let v=new a.J(function(e){return[e.isPrivateChannel?y.PRIVATE_CHANNELS:y.GUILD_CHANNELS]},function(e){let t=e.isPrivateChannel?"0":"1",n=e.mentionCount>0?O.MENTION:e.hasUnread?O.UNREAD:O.READ,i=String(O.MENTION-n),r=R(Number.MAX_SAFE_INTEGER-e.mentionCount,16),s=R(Number.MAX_SAFE_INTEGER-e.lastActivityAtMs,16);return`${t}\0${i}\0${r}\0${s}\0${e.channelId}`}),b=null,L=null,D=!1,w=null,P=30*m.A.Millis.MINUTE;function M(e){let t=c.A.getChannel(e),n=t?.lastMessageId;return null!=n?g.default.extractTimestamp(n):Date.now()}function x(e,t,n,i,r){let s;return{channelId:e,source:t,addedOnMs:n,lastActivityAtMs:i,lastMessageId:r,isPrivateChannel:(s=c.A.getChannel(e),s?.isPrivate()??!1),mentionCount:h.Ay.getMentionCount(e),hasUnread:h.Ay.hasUnread(e)}}function U(){v.clear(),b=null,L=null,D=!1,w=null}function k(){let e=Date.now();U(),L=e,w=_.A.getChannelId()??null,function(e){let t=f.A.getChannelId();if(null!=t&&null!=c.A.getChannel(t)){if(b=t,!v.has(t)){let n=M(t),i=c.A.getChannel(t)?.lastMessageId??void 0,r=x(t,I.B9.MANUAL,e,n,i);v.set(t,r)}}}(e),function(e){let t=p.A.getPrivateChannelIds(),n=0;for(let i of t){if(n>=3)return;if(v.has(i))continue;let t=c.A.getChannel(i);if(null==t||!t.isPrivate()||E.Ay.isChannelMuted(null,i)||l.A.isMessageRequest(i))continue;let r=t.lastMessageId;if(null==r)continue;let s=g.default.extractTimestamp(r);if(e-s>P)continue;let a=x(i,I.B9.MANUAL,e,s,r);v.set(i,a),n++}}(e),F()}function G(){return _.A.getChannelId()??null}function V(e){if(null==e)return v.values()[0]?.channelId??null;for(let t of v.values())if(t.channelId!==e)return t.channelId;return null}function F(){let e=G();return null!=e&&!D&&null==b&&(b=e,!0)}function B(){let e,t=function(){if(null==b)return!1;let e=G();return e!==b&&w===b&&e!==b&&(b=V(w),!0)}(),n=null==(e=G())?(w=null,!!D&&(D=!1,!0)):w!==e&&(w=e,!!D&&(D=!1,!0)),i=F();return t||n||i}function H(e){let t=v.get(e);if(null==t)return!1;let n=h.Ay.getMentionCount(e),i=h.Ay.hasUnread(e);return(t.mentionCount!==n||t.hasUnread!==i)&&(v.set(e,{...t,mentionCount:n,hasUnread:i}),!0)}function j(e){let{channelId:t}=e;return H(t)}class W extends s.Ay.Store{static displayName="Overlay-v3-Text-Chat-Store";initialize(){this.waitFor(C.A,N.A,S.A,u.A,c.A,d.A,l.A,_.A,p.A,h.Ay,f.A,E.Ay),k()}isChannelTracked(e){return v.has(e)}getSessionEntries(e){return[null!=e?v.values(e):v.values(),v.version]}getSelectedChannelId(){return b}getVoiceChatMinimized(){return D}}function Y(e){return(0,T.U5)(e,"OverlayTextChatStore")}let K=new W(o.h,__OVERLAY__||!A.O&&!A.e?{}:{OVERLAY_MOUNTED:Y(function(e){return null==L&&(k(),!0)}),OVERLAY_V3_NATIVE_DESTROY_HOST_WINDOW:Y(function(){return U(),!0}),MESSAGE_ACK:Y(function(e){let{channelId:t}=e;return H(t)}),CHANNEL_ACK:Y(j),CHANNEL_LOCAL_ACK:Y(j),BULK_ACK:Y(function(e){let{channels:t}=e,n=!1;for(let{channelId:e}of t)H(e)&&(n=!0);return n}),VOICE_STATE_UPDATES:Y(B),VOICE_CHANNEL_SELECT:Y(B),OVERLAY_TEXT_CHAT_SELECT_CHANNEL:Y(function(e){let{channelId:t,source:n}=e;return function(e,t){if(null==e)return!1;null==L&&(L=Date.now()),b!==e&&(b=e);let n=G();if(null!=n&&e===n&&D&&(D=!1),null!=b&&!v.has(b)){let e=Date.now(),n=M(b),i=c.A.getChannel(b)?.lastMessageId??void 0,r=x(b,t,e,n,i);v.set(b,r)}return!0}(t??null,n)}),OVERLAY_TEXT_CHAT_ADD_OR_UPDATE_CHANNEL:Y(function(e){let t=function(e){let{channelId:t,source:n,lastActivityAtMs:i,lastMessageId:r}=e,s=v.get(t)??null,a=null==s?i:Math.max(s.lastActivityAtMs,i),o=r??s?.lastMessageId,l=x(t,n,s?.addedOnMs??i,a,o);return v.set(t,l)}({channelId:e.channelId,source:e.source,lastActivityAtMs:e.lastActivityAtMs,lastMessageId:e.lastMessageId}),n=!1;return null==b&&(b=e.channelId,n=!0),t||n}),OVERLAY_TEXT_CHAT_REMOVE_CHANNEL:Y(function(e){let t=v.delete(e.channelId),n=!1;if(b===e.channelId){let e=G();b=V(e)??(D||null==e?null:e),n=!0}return t||n}),OVERLAY_TEXT_CHAT_REMOVE_ALL_CHANNELS:Y(function(){let e=v.size()>0;v.clear();let t=G();return b=D||null==t?null:t,e}),OVERLAY_TEXT_CHAT_SET_VOICE_CHAT_MINIMIZED:Y(function(e){let{minimized:t}=e;if(D===t)return!1;if(D=t,!t)return F(),!0;let n=G();return null!=n&&b===n&&(b=V(n)),!0})})}