1 line
3.9 KiB
JavaScript
1 line
3.9 KiB
JavaScript
(function(p,o,u,f,S){"use strict";let h,v,A,c,m,E,g=null,y=null,C=null,s=0;const d=6e4,T=function(){h=o.findByStoreName("GuildStore"),v=o.findByStoreName("GuildChannelStore")||o.findByStoreName("ChannelStore"),E=o.findByStoreName("ChannelStore"),c=o.findByStoreName("ReadStateStore"),A=o.findByStoreName("ActiveJoinedThreadsStore")||o.findByProps("getActiveJoinedThreadsForGuild"),m=o.findByProps("dispatch","subscribe")||o.findByStoreName("Dispatcher")},b=function(){const a=[],e=E||v;if(!e)return a;if(e.getPrivateChannels)try{const t=e.getPrivateChannels();t&&typeof t=="object"&&Object.values(t).forEach(function(n){n&&n.id&&a.push(n)})}catch{}if(a.length===0&&e.getSortedPrivateChannels)try{const t=e.getSortedPrivateChannels();Array.isArray(t)&&t.forEach(function(n){n&&n.id&&a.push(n)})}catch{}if(a.length===0&&e.getChannels)try{const t=e.getChannels("@me");t&&t.SELECTABLE&&t.SELECTABLE.forEach(function(n){const i=n.channel||n;i&&i.id&&a.push(i)})}catch{}if(a.length===0&&e.getChannel&&c?.getAllReadStates)try{const t=c.getAllReadStates();Object.keys(t).forEach(function(n){try{const i=e.getChannel(n);i&&(i.type===1||i.type===3||!i.guild_id&&!i.guildId)&&a.push(i)}catch{}})}catch{}return a},_=function(){if(!h||!c)return[];const a=[],e=h.getGuilds();return Object.values(e).forEach(function(t){if(t?.id)try{let n=[];const i=v||E;if(i?.getChannels){const r=i.getChannels(t.id);r?.SELECTABLE&&(n=n.concat(r.SELECTABLE)),r?.VOCAL&&(n=n.concat(r.VOCAL))}if(A?.getActiveJoinedThreadsForGuild)try{const r=A.getActiveJoinedThreadsForGuild(t.id),l=Object.values(r).flatMap(function(L){return Object.values(L||{})});n=n.concat(l)}catch{}n.forEach(function(r){const l=r?.channel||r;if(l?.id)try{c.hasUnread&&c.hasUnread(l.id)&&a.push({channelId:l.id,messageId:c.lastMessageId?.(l.id)||null,readStateType:0})}catch{}})}catch{}}),a},I=function(){const a=[];return b().forEach(function(e){if(e?.id)try{let t=!1;if(c.hasUnread&&(t=c.hasUnread(e.id)),!t&&c.getAllReadStates){const n=c.getAllReadStates()[e.id];n&&(t=n.mentionCount&&n.mentionCount>0||n._unreadCount&&n._unreadCount>0||n.unreadCount&&n.unreadCount>0)}t&&a.push({channelId:e.id,messageId:c.lastMessageId?.(e.id)||null,readStateType:0})}catch{}}),a},B=function(a="all"){if(!h||!c||!m)return!1;let e=[],t="";switch(a){case"server":e=_(),t="server";break;case"dm":e=I(),t="DM";break;case"all":default:e=[..._(),...I()],t="";break}if(e.length===0){const i=a==="all"?"No unread notifications found!":`No unread ${t} notifications found!`;return u.showToast(i,f.getAssetIDByName("ic_message_edit")),!0}m.dispatch({type:"BULK_ACK",context:"APP",channels:e});const n=a==="all"?`Cleared ${e.length} unread notifications!`:`Cleared ${e.length} unread ${t} notifications!`;return u.showToast(n,f.getAssetIDByName("ic_message_edit")),!0},N=function(){const a=Date.now(),e=a-s;if(e<d){const t=Math.ceil((d-e)/1e3);u.showToast(`Please wait ${t}s before using again`,f.getAssetIDByName("ic_close_16px"));return}s=a,B("all")},w=function(){const a=Date.now(),e=a-s;if(e<d){const t=Math.ceil((d-e)/1e3);u.showToast(`Please wait ${t}s before using again`,f.getAssetIDByName("ic_close_16px"));return}s=a,B("server")},P=function(){const a=Date.now(),e=a-s;if(e<d){const t=Math.ceil((d-e)/1e3);u.showToast(`Please wait ${t}s before using again`,f.getAssetIDByName("ic_close_16px"));return}s=a,B("dm")};var D={onLoad:function(){T();try{g=S.registerCommand({name:"read",description:"Clear all unread notifications",applicationId:"-1",execute:function(){N()}}),y=S.registerCommand({name:"read server",description:"Clear server unread notifications only",applicationId:"-1",execute:function(){w()}}),C=S.registerCommand({name:"read dm",description:"Clear DM unread notifications only",applicationId:"-1",execute:function(){P()}})}catch{}},onUnload:function(){if(g)try{g(),g=null}catch{}if(y)try{y(),y=null}catch{}if(C)try{C(),C=null}catch{}}};return p.default=D,Object.defineProperty(p,"__esModule",{value:!0}),p})({},vendetta.metro,vendetta.ui.toasts,vendetta.ui.assets,vendetta.commands);
|