All checks were successful
check / check (push) Successful in 2m18s
- Server: add LIST, WHO, WHOIS command handlers in dispatchCommand with proper IRC numerics (322/323, 352/315, 311/312/319/318) - SPA: add /list, /who, /whois command parsing and numeric display - CLI: add /motd, /who, /whois commands for feature parity - Rebuild SPA dist from source
3 lines
28 KiB
JavaScript
3 lines
28 KiB
JavaScript
var ie,T,He,pt,G,Pe,Ue,De,Re,ve,me,he,mt,ee={},Le=[],ht=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_e=Array.isArray;function J(e,t){for(var n in t)e[n]=t[n];return e}function be(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function m(e,t,n){var o,s,a,_={};for(a in t)a=="key"?o=t[a]:a=="ref"?s=t[a]:_[a]=t[a];if(arguments.length>2&&(_.children=arguments.length>3?ie.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(a in e.defaultProps)_[a]===void 0&&(_[a]=e.defaultProps[a]);return ae(e,_,o,s,null)}function ae(e,t,n,o,s){var a={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:s??++He,__i:-1,__u:0};return s==null&&T.vnode!=null&&T.vnode(a),a}function le(e){return e.children}function se(e,t){this.props=e,this.context=t}function Y(e,t){if(t==null)return e.__?Y(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?Y(e):null}function We(e){var t,n;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null){e.__e=e.__c.base=n.__e;break}return We(e)}}function $e(e){(!e.__d&&(e.__d=!0)&&G.push(e)&&!ce.__r++||Pe!=T.debounceRendering)&&((Pe=T.debounceRendering)||Ue)(ce)}function ce(){for(var e,t,n,o,s,a,_,u=1;G.length;)G.length>u&&G.sort(De),e=G.shift(),u=G.length,e.__d&&(n=void 0,o=void 0,s=(o=(t=e).__v).__e,a=[],_=[],t.__P&&((n=J({},o)).__v=o.__v+1,T.vnode&&T.vnode(n),ke(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[s]:null,a,s??Y(o),!!(32&o.__u),_),n.__v=o.__v,n.__.__k[n.__i]=n,je(a,n,_),o.__e=o.__=null,n.__e!=s&&We(n)));ce.__r=0}function Fe(e,t,n,o,s,a,_,u,y,f,b){var c,h,v,C,E,A,g,w=o&&o.__k||Le,U=t.length;for(y=yt(n,t,w,y,U),c=0;c<U;c++)(v=n.__k[c])!=null&&(h=v.__i==-1?ee:w[v.__i]||ee,v.__i=c,A=ke(e,v,h,s,a,_,u,y,f,b),C=v.__e,v.ref&&h.ref!=v.ref&&(h.ref&&ge(h.ref,null,v),b.push(v.ref,v.__c||C,v)),E==null&&C!=null&&(E=C),(g=!!(4&v.__u))||h.__k===v.__k?y=Je(v,y,e,g):typeof v.type=="function"&&A!==void 0?y=A:C&&(y=C.nextSibling),v.__u&=-7);return n.__e=E,y}function yt(e,t,n,o,s){var a,_,u,y,f,b=n.length,c=b,h=0;for(e.__k=new Array(s),a=0;a<s;a++)(_=t[a])!=null&&typeof _!="boolean"&&typeof _!="function"?(typeof _=="string"||typeof _=="number"||typeof _=="bigint"||_.constructor==String?_=e.__k[a]=ae(null,_,null,null,null):_e(_)?_=e.__k[a]=ae(le,{children:_},null,null,null):_.constructor===void 0&&_.__b>0?_=e.__k[a]=ae(_.type,_.props,_.key,_.ref?_.ref:null,_.__v):e.__k[a]=_,y=a+h,_.__=e,_.__b=e.__b+1,u=null,(f=_.__i=vt(_,n,y,c))!=-1&&(c--,(u=n[f])&&(u.__u|=2)),u==null||u.__v==null?(f==-1&&(s>b?h--:s<b&&h++),typeof _.type!="function"&&(_.__u|=4)):f!=y&&(f==y-1?h--:f==y+1?h++:(f>y?h--:h++,_.__u|=4))):e.__k[a]=null;if(c)for(a=0;a<b;a++)(u=n[a])!=null&&(2&u.__u)==0&&(u.__e==o&&(o=Y(u)),qe(u,u));return o}function Je(e,t,n,o){var s,a;if(typeof e.type=="function"){for(s=e.__k,a=0;s&&a<s.length;a++)s[a]&&(s[a].__=e,t=Je(s[a],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=Y(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function vt(e,t,n,o){var s,a,_,u=e.key,y=e.type,f=t[n],b=f!=null&&(2&f.__u)==0;if(f===null&&u==null||b&&u==f.key&&y==f.type)return n;if(o>(b?1:0)){for(s=n-1,a=n+1;s>=0||a<t.length;)if((f=t[_=s>=0?s--:a++])!=null&&(2&f.__u)==0&&u==f.key&&y==f.type)return _}return-1}function Ee(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||ht.test(t)?n:n+"px"}function oe(e,t,n,o,s){var a,_;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||Ee(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||Ee(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")a=t!=(t=t.replace(Re,"$1")),_=t.toLowerCase(),t=_ in e||t=="onFocusOut"||t=="onFocusIn"?_.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+a]=n,n?o?n.u=o.u:(n.u=ve,e.addEventListener(t,a?he:me,a)):e.removeEventListener(t,a?he:me,a);else{if(s=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Me(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=ve++;else if(t.t<n.u)return;return n(T.event?T.event(t):t)}}}function ke(e,t,n,o,s,a,_,u,y,f){var b,c,h,v,C,E,A,g,w,U,M,z,R,B,j,V,Q,P=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(y=!!(32&n.__u),a=[u=t.__e=n.__e]),(b=T.__b)&&b(t);e:if(typeof P=="function")try{if(g=t.props,w="prototype"in P&&P.prototype.render,U=(b=P.contextType)&&o[b.__c],M=b?U?U.props.value:b.__:o,n.__c?A=(c=t.__c=n.__c).__=c.__E:(w?t.__c=c=new P(g,M):(t.__c=c=new se(g,M),c.constructor=P,c.render=kt),U&&U.sub(c),c.state||(c.state={}),c.__n=o,h=c.__d=!0,c.__h=[],c._sb=[]),w&&c.__s==null&&(c.__s=c.state),w&&P.getDerivedStateFromProps!=null&&(c.__s==c.state&&(c.__s=J({},c.__s)),J(c.__s,P.getDerivedStateFromProps(g,c.__s))),v=c.props,C=c.state,c.__v=t,h)w&&P.getDerivedStateFromProps==null&&c.componentWillMount!=null&&c.componentWillMount(),w&&c.componentDidMount!=null&&c.__h.push(c.componentDidMount);else{if(w&&P.getDerivedStateFromProps==null&&g!==v&&c.componentWillReceiveProps!=null&&c.componentWillReceiveProps(g,M),t.__v==n.__v||!c.__e&&c.shouldComponentUpdate!=null&&c.shouldComponentUpdate(g,c.__s,M)===!1){for(t.__v!=n.__v&&(c.props=g,c.state=c.__s,c.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(W){W&&(W.__=t)}),z=0;z<c._sb.length;z++)c.__h.push(c._sb[z]);c._sb=[],c.__h.length&&_.push(c);break e}c.componentWillUpdate!=null&&c.componentWillUpdate(g,c.__s,M),w&&c.componentDidUpdate!=null&&c.__h.push(function(){c.componentDidUpdate(v,C,E)})}if(c.context=M,c.props=g,c.__P=e,c.__e=!1,R=T.__r,B=0,w){for(c.state=c.__s,c.__d=!1,R&&R(t),b=c.render(c.props,c.state,c.context),j=0;j<c._sb.length;j++)c.__h.push(c._sb[j]);c._sb=[]}else do c.__d=!1,R&&R(t),b=c.render(c.props,c.state,c.context),c.state=c.__s;while(c.__d&&++B<25);c.state=c.__s,c.getChildContext!=null&&(o=J(J({},o),c.getChildContext())),w&&!h&&c.getSnapshotBeforeUpdate!=null&&(E=c.getSnapshotBeforeUpdate(v,C)),V=b,b!=null&&b.type===le&&b.key==null&&(V=Ve(b.props.children)),u=Fe(e,_e(V)?V:[V],t,n,o,s,a,_,u,y,f),c.base=t.__e,t.__u&=-161,c.__h.length&&_.push(c),A&&(c.__E=c.__=null)}catch(W){if(t.__v=null,y||a!=null)if(W.then){for(t.__u|=y?160:128;u&&u.nodeType==8&&u.nextSibling;)u=u.nextSibling;a[a.indexOf(u)]=null,t.__e=u}else{for(Q=a.length;Q--;)be(a[Q]);ye(t)}else t.__e=n.__e,t.__k=n.__k,W.then||ye(t);T.__e(W,t,n)}else a==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):u=t.__e=bt(n.__e,t,n,o,s,a,_,y,f);return(b=T.diffed)&&b(t),128&t.__u?void 0:u}function ye(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(ye)}function je(e,t,n){for(var o=0;o<n.length;o++)ge(n[o],n[++o],n[++o]);T.__c&&T.__c(t,e),e.some(function(s){try{e=s.__h,s.__h=[],e.some(function(a){a.call(s)})}catch(a){T.__e(a,s.__v)}})}function Ve(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:_e(e)?e.map(Ve):J({},e)}function bt(e,t,n,o,s,a,_,u,y){var f,b,c,h,v,C,E,A=n.props||ee,g=t.props,w=t.type;if(w=="svg"?s="http://www.w3.org/2000/svg":w=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),a!=null){for(f=0;f<a.length;f++)if((v=a[f])&&"setAttribute"in v==!!w&&(w?v.localName==w:v.nodeType==3)){e=v,a[f]=null;break}}if(e==null){if(w==null)return document.createTextNode(g);e=document.createElementNS(s,w,g.is&&g),u&&(T.__m&&T.__m(t,a),u=!1),a=null}if(w==null)A===g||u&&e.data==g||(e.data=g);else{if(a=a&&ie.call(e.childNodes),!u&&a!=null)for(A={},f=0;f<e.attributes.length;f++)A[(v=e.attributes[f]).name]=v.value;for(f in A)if(v=A[f],f!="children"){if(f=="dangerouslySetInnerHTML")c=v;else if(!(f in g)){if(f=="value"&&"defaultValue"in g||f=="checked"&&"defaultChecked"in g)continue;oe(e,f,null,v,s)}}for(f in g)v=g[f],f=="children"?h=v:f=="dangerouslySetInnerHTML"?b=v:f=="value"?C=v:f=="checked"?E=v:u&&typeof v!="function"||A[f]===v||oe(e,f,v,A[f],s);if(b)u||c&&(b.__html==c.__html||b.__html==e.innerHTML)||(e.innerHTML=b.__html),t.__k=[];else if(c&&(e.innerHTML=""),Fe(t.type=="template"?e.content:e,_e(h)?h:[h],t,n,o,w=="foreignObject"?"http://www.w3.org/1999/xhtml":s,a,_,a?a[0]:n.__k&&Y(n,0),u,y),a!=null)for(f=a.length;f--;)be(a[f]);u||(f="value",w=="progress"&&C==null?e.removeAttribute("value"):C!=null&&(C!==e[f]||w=="progress"&&!C||w=="option"&&C!=A[f])&&oe(e,f,C,A[f],s),f="checked",E!=null&&E!=e[f]&&oe(e,f,E,A[f],s))}return e}function ge(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(s){T.__e(s,n)}}function qe(e,t,n){var o,s;if(T.unmount&&T.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||ge(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(a){T.__e(a,t)}o.base=o.__P=null}if(o=e.__k)for(s=0;s<o.length;s++)o[s]&&qe(o[s],t,n||typeof e.type!="function");n||be(e.__e),e.__c=e.__=e.__e=void 0}function kt(e,t,n){return this.constructor(e,n)}function Be(e,t,n){var o,s,a,_;t==document&&(t=document.documentElement),T.__&&T.__(e,t),s=(o=typeof n=="function")?null:n&&n.__k||t.__k,a=[],_=[],ke(t,e=(!o&&n||t).__k=m(le,null,[e]),s||ee,ee,t.namespaceURI,!o&&n?[n]:s?null:t.firstChild?ie.call(t.childNodes):null,a,!o&&n?n:s?s.__e:t.firstChild,o,_),je(a,e,_)}ie=Le.slice,T={__e:function(e,t,n,o){for(var s,a,_;t=t.__;)if((s=t.__c)&&!s.__)try{if((a=s.constructor)&&a.getDerivedStateFromError!=null&&(s.setState(a.getDerivedStateFromError(e)),_=s.__d),s.componentDidCatch!=null&&(s.componentDidCatch(e,o||{}),_=s.__d),_)return s.__E=s}catch(u){e=u}throw e}},He=0,pt=function(e){return e!=null&&e.constructor===void 0},se.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=J({},this.state),typeof e=="function"&&(e=e(J({},n),this.props)),e&&J(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),$e(this))},se.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),$e(this))},se.prototype.render=le,G=[],Ue=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},ce.__r=0,Re=/(PointerCapture)$|Capture$/i,ve=0,me=Me(!1),he=Me(!0),mt=0;var te,I,Se,Ke,ne=0,tt=[],O=T,Ge=O.__b,ze=O.__r,Qe=O.diffed,Ye=O.__c,Xe=O.unmount,Ze=O.__;function Te(e,t){O.__h&&O.__h(I,e,ne||t),ne=0;var n=I.__H||(I.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function $(e){return ne=1,gt(ot,e)}function gt(e,t,n){var o=Te(te++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):ot(void 0,t),function(u){var y=o.__N?o.__N[0]:o.__[0],f=o.t(y,u);y!==f&&(o.__N=[f,o.__[1]],o.__c.setState({}))}],o.__c=I,!I.__f)){var s=function(u,y,f){if(!o.__c.__H)return!0;var b=o.__c.__H.__.filter(function(h){return!!h.__c});if(b.every(function(h){return!h.__N}))return!a||a.call(this,u,y,f);var c=o.__c.props!==u;return b.forEach(function(h){if(h.__N){var v=h.__[0];h.__=h.__N,h.__N=void 0,v!==h.__[0]&&(c=!0)}}),a&&a.call(this,u,y,f)||c};I.__f=!0;var a=I.shouldComponentUpdate,_=I.componentWillUpdate;I.componentWillUpdate=function(u,y,f){if(this.__e){var b=a;a=void 0,s(u,y,f),a=b}_&&_.call(this,u,y,f)},I.shouldComponentUpdate=s}return o.__N||o.__}function H(e,t){var n=Te(te++,3);!O.__s&&rt(n.__H,t)&&(n.__=e,n.u=t,I.__H.__h.push(n))}function L(e){return ne=5,nt(function(){return{current:e}},[])}function nt(e,t){var n=Te(te++,7);return rt(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function X(e,t){return ne=8,nt(function(){return e},t)}function St(){for(var e;e=tt.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(ue),e.__H.__h.forEach(we),e.__H.__h=[]}catch(t){e.__H.__h=[],O.__e(t,e.__v)}}O.__b=function(e){I=null,Ge&&Ge(e)},O.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ze&&Ze(e,t)},O.__r=function(e){ze&&ze(e),te=0;var t=(I=e.__c).__H;t&&(Se===I?(t.__h=[],I.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(ue),t.__h.forEach(we),t.__h=[],te=0)),Se=I},O.diffed=function(e){Qe&&Qe(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(tt.push(t)!==1&&Ke===O.requestAnimationFrame||((Ke=O.requestAnimationFrame)||wt)(St)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Se=I=null},O.__c=function(e,t){t.some(function(n){try{n.__h.forEach(ue),n.__h=n.__h.filter(function(o){return!o.__||we(o)})}catch(o){t.some(function(s){s.__h&&(s.__h=[])}),t=[],O.__e(o,n.__v)}}),Ye&&Ye(e,t)},O.unmount=function(e){Xe&&Xe(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ue(o)}catch(s){t=s}}),n.__H=void 0,t&&O.__e(t,n.__v))};var et=typeof requestAnimationFrame=="function";function wt(e){var t,n=function(){clearTimeout(o),et&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);et&&(t=requestAnimationFrame(n))}function ue(e){var t=I,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),I=t}function we(e){var t=I;e.__c=e.__(),I=t}function rt(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function ot(e,t){return typeof t=="function"?t(e):t}var Tt="/api/v1",xt=15,Ct=3e3,It=1e4,Ce="ACTION ",Ie="";function x(e,t={}){let n=localStorage.getItem("neoirc_token"),o={"Content-Type":"application/json",...t.headers||{}};n&&(o.Authorization=`Bearer ${n}`);let{signal:s,...a}=t;return fetch(Tt+e,{...a,headers:o,signal:s}).then(async _=>{let u=await _.json().catch(()=>null);if(!_.ok)throw{status:_.status,data:u};return u})}function At(e){return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1})}function xe(e){let t=0;for(let o=0;o<e.length;o++)t=e.charCodeAt(o)+((t<<5)-t);return`hsl(${Math.abs(t)%360}, 60%, 65%)`}function Ot(e){return e.startsWith(Ce)&&e.endsWith(Ie)}function Nt(e){return e.slice(Ce.length,-Ie.length)}function Pt({onLogin:e}){let[t,n]=$(""),[o,s]=$(""),[a,_]=$(""),[u,y]=$("NeoIRC"),f=L();return H(()=>{x("/server").then(h=>{h.name&&y(h.name),h.motd&&_(h.motd)}).catch(()=>{}),localStorage.getItem("neoirc_token")&&x("/state").then(h=>e(h.nick,!0)).catch(()=>localStorage.removeItem("neoirc_token")),f.current?.focus()},[]),m("div",{class:"login-screen"},m("div",{class:"login-box"},m("h1",null,u),a&&m("pre",{class:"motd"},a),m("form",{onSubmit:async c=>{c.preventDefault(),s("");try{let h=await x("/session",{method:"POST",body:JSON.stringify({nick:t.trim()})});localStorage.setItem("neoirc_token",h.token),e(h.nick)}catch(h){s(h.data?.error||"Connection failed")}}},m("label",null,"Nickname:"),m("input",{ref:f,type:"text",placeholder:"Enter nickname",value:t,onInput:c=>n(c.target.value),maxLength:32,autoFocus:!0}),m("button",{type:"submit"},"Connect")),o&&m("div",{class:"error"},o)))}function $t({msg:e,myNick:t}){let n=At(e.ts);return e.system?m("div",{class:"message system-message"},m("span",{class:"timestamp"},"[",n,"]"),m("span",{class:"system-text"}," * ",e.text)):e.isAction?m("div",{class:"message action-message"},m("span",{class:"timestamp"},"[",n,"]"),m("span",{class:"action-text"}," ","* ",m("span",{style:{color:xe(e.from)}},e.from)," ",e.text)):m("div",{class:"message"},m("span",{class:"timestamp"},"[",n,"]")," ",m("span",{class:"nick",style:{color:xe(e.from)}},"<",e.from,">")," ",m("span",{class:"content"},e.text))}function Et({members:e,onNickClick:t}){let n=[],o=[],s=[];for(let u of e){let y=u.mode||"";y==="o"?n.push(u):y==="v"?o.push(u):s.push(u)}let a=(u,y)=>u.nick.toLowerCase().localeCompare(y.nick.toLowerCase());n.sort(a),o.sort(a),s.sort(a);let _=(u,y)=>m("div",{class:"nick-entry",onClick:()=>t(u.nick),title:u.nick},m("span",{class:"nick-prefix"},y),m("span",{class:"nick-name",style:{color:xe(u.nick)}},u.nick));return m("div",{class:"user-list"},m("div",{class:"user-list-header"},e.length," user",e.length!==1?"s":""),m("div",{class:"user-list-entries"},n.map(u=>_(u,"@")),o.map(u=>_(u,"+")),s.map(u=>_(u,""))))}function Mt(){let[e,t]=$(!1),[n,o]=$(""),[s,a]=$([{type:"server",name:"Server"}]),[_,u]=$(0),[y,f]=$({Server:[]}),[b,c]=$({}),[h,v]=$({}),[C,E]=$({}),[A,g]=$(""),[w,U]=$(!0),[M,z]=$([]),[R,B]=$(-1),j=L(0),V=L(new Set),Q=L(null),P=L(s),W=L(_),re=L(n),Ae=L(),Z=L();H(()=>{P.current=s},[s]),H(()=>{W.current=_},[_]),H(()=>{re.current=n},[n]),H(()=>{let r=s.filter(i=>i.type==="channel").map(i=>i.name);localStorage.setItem("neoirc_channels",JSON.stringify(r))},[s]),H(()=>{let r=s[_];r&&E(i=>({...i,[r.name]:0}))},[_,s]);let N=X((r,i)=>{if(i.id&&V.current.has(i.id))return;i.id&&V.current.add(i.id),f(l=>({...l,[r]:[...l[r]||[],i]}));let d=P.current[W.current];(!d||d.name!==r)&&E(l=>({...l,[r]:(l[r]||0)+1}))},[]),S=X((r,i)=>{f(d=>({...d,[r]:[...d[r]||[],{id:"sys-"+Date.now()+"-"+Math.random(),ts:new Date().toISOString(),text:i,system:!0}]}))},[]),K=X(r=>{let i=r.replace("#","");x(`/channels/${i}/members`).then(d=>{c(l=>({...l,[r]:d}))}).catch(()=>{})},[]),fe=X(r=>{let i=Array.isArray(r.body)?r.body.join(`
|
||
`):"",d={id:r.id,ts:r.ts,from:r.from,to:r.to,command:r.command};switch(r.command){case"PRIVMSG":case"NOTICE":{let l=i,p=!1;Ot(l)&&(l=Nt(l),p=!0);let k={...d,text:l,system:!1,isAction:p},F=r.to;if(F&&F.startsWith("#"))N(F,k);else{let D=r.from===re.current?r.to:r.from;a(pe=>pe.find(Ne=>Ne.type==="dm"&&Ne.name===D)?pe:[...pe,{type:"dm",name:D}]),N(D,k)}break}case"JOIN":{let l=`${r.from} has joined ${r.to}`;r.to&&N(r.to,{...d,text:l,system:!0}),r.to&&r.to.startsWith("#")&&K(r.to);break}case"PART":{let l=i?" ("+i+")":"",p=`${r.from} has parted ${r.to}${l}`;r.to&&N(r.to,{...d,text:p,system:!0}),r.to&&r.to.startsWith("#")&&K(r.to);break}case"QUIT":{let l=i?" ("+i+")":"",p=`${r.from} has quit${l}`;P.current.forEach(k=>{k.type==="channel"&&N(k.name,{...d,text:p,system:!0})});break}case"NICK":{let l=Array.isArray(r.body)?r.body[0]:i,p=`${r.from} is now known as ${l}`;P.current.forEach(k=>{k.type==="channel"&&N(k.name,{...d,text:p,system:!0})}),r.from===re.current&&l&&o(l),P.current.forEach(k=>{k.type==="channel"&&K(k.name)});break}case"TOPIC":{let l=`${r.from} has changed the topic to: ${i}`;r.to&&(N(r.to,{...d,text:l,system:!0}),v(p=>({...p,[r.to]:i})));break}case"353":{if(Array.isArray(r.params)&&r.params.length>=2&&r.body){let l=r.params[1],F=(Array.isArray(r.body)?r.body[0]:String(r.body)).split(/\s+/).filter(Boolean).map(D=>D.startsWith("@")?{nick:D.slice(1),mode:"o"}:D.startsWith("+")?{nick:D.slice(1),mode:"v"}:{nick:D,mode:""});c(D=>({...D,[l]:F}))}break}case"332":{if(Array.isArray(r.params)&&r.params.length>=1){let l=r.params[0],p=Array.isArray(r.body)?r.body[0]:i;p&&v(k=>({...k,[l]:p}))}break}case"322":{if(Array.isArray(r.params)&&r.params.length>=2){let l=r.params[0],p=r.params[1];N("Server",{...d,text:`${l} (${p} users): ${(i||"").trim()}`,system:!0})}break}case"323":N("Server",{...d,text:i||"End of channel list",system:!0});break;case"352":{if(Array.isArray(r.params)&&r.params.length>=5){let l=r.params[0],p=r.params[4],k=r.params.length>5?r.params[5]:"";N("Server",{...d,text:`${l} ${p} ${k}`,system:!0})}break}case"315":N("Server",{...d,text:i||"End of /WHO list",system:!0});break;case"311":{if(Array.isArray(r.params)&&r.params.length>=1){let l=r.params[0];N("Server",{...d,text:`${l} (${i})`,system:!0})}break}case"312":{if(Array.isArray(r.params)&&r.params.length>=2){let l=r.params[0],p=r.params[1];N("Server",{...d,text:`${l} on ${p}`,system:!0})}break}case"319":{if(Array.isArray(r.params)&&r.params.length>=1){let l=r.params[0];N("Server",{...d,text:`${l} is on: ${i}`,system:!0})}break}case"318":N("Server",{...d,text:i||"End of /WHOIS list",system:!0});break;case"375":case"372":case"376":N("Server",{...d,text:i,system:!0});break;default:i&&N("Server",{...d,text:i,system:!0})}},[N,K]);H(()=>{if(!e)return;let r=!0;return(async()=>{for(;r;)try{let d=new AbortController;Q.current=d;let l=await x(`/messages?after=${j.current}&timeout=${xt}`,{signal:d.signal});if(!r)break;if(U(!0),l.messages)for(let p of l.messages)fe(p);l.last_id>j.current&&(j.current=l.last_id)}catch(d){if(!r)break;if(d.name==="AbortError")continue;U(!1),await new Promise(l=>setTimeout(l,Ct))}})(),()=>{r=!1,Q.current?.abort()}},[e,fe]),H(()=>{if(!e)return;let r=s[_];if(!r||r.type!=="channel")return;K(r.name);let i=setInterval(()=>K(r.name),It);return()=>clearInterval(i)},[e,_,s,K]),H(()=>{Ae.current?.scrollIntoView({behavior:"smooth"})},[y,_]),H(()=>{Z.current?.focus()},[_]),H(()=>{let r=i=>{i.key==="/"&&document.activeElement!==Z.current&&!i.ctrlKey&&!i.altKey&&!i.metaKey&&(i.preventDefault(),Z.current?.focus())};return document.addEventListener("keydown",r),Z.current?.focus(),()=>document.removeEventListener("keydown",r)},[]),H(()=>{if(!e)return;let r=s[_];!r||r.type!=="channel"||x("/channels").then(i=>{let d=i.find(l=>l.name===r.name);d&&d.topic&&v(l=>({...l,[r.name]:d.topic}))}).catch(()=>{})},[e,_,s]);let at=X(async(r,i)=>{if(o(r),t(!0),S("Server",`Connected as ${r}`),i)try{await x("/messages",{method:"POST",body:JSON.stringify({command:"MOTD"})})}catch{}let d=JSON.parse(localStorage.getItem("neoirc_channels")||"[]");for(let l of d)try{await x("/messages",{method:"POST",body:JSON.stringify({command:"JOIN",to:l})}),a(p=>p.find(k=>k.type==="channel"&&k.name===l)?p:[...p,{type:"channel",name:l}])}catch{}},[S]),st=async r=>{if(r){r=r.trim(),r.startsWith("#")||(r="#"+r);try{await x("/messages",{method:"POST",body:JSON.stringify({command:"JOIN",to:r})}),a(d=>d.find(l=>l.type==="channel"&&l.name===r)?d:[...d,{type:"channel",name:r}]);let i=P.current.length;u(i);try{let d=await x(`/history?target=${encodeURIComponent(r)}&limit=50`);if(Array.isArray(d))for(let l of d)fe(l)}catch{}}catch(i){S("Server",`Failed to join ${r}: ${i.data?.error||"error"}`)}}},Oe=async(r,i)=>{try{await x("/messages",{method:"POST",body:JSON.stringify(i?{command:"PART",to:r,body:[i]}:{command:"PART",to:r})})}catch{}a(d=>d.filter(l=>!(l.type==="channel"&&l.name===r))),u(0)},ct=r=>{let i=s[r];i.type==="channel"?Oe(i.name):i.type==="dm"&&(a(d=>d.filter((l,p)=>p!==r)),_>=r&&u(Math.max(0,_-1)))},de=r=>{if(r===re.current)return;a(d=>d.find(l=>l.type==="dm"&&l.name===r)?d:[...d,{type:"dm",name:r}]);let i=s.findIndex(d=>d.type==="dm"&&d.name===r);u(i>=0?i:s.length)},it=async r=>{let i=r.split(" "),d=i[0].toLowerCase(),l=s[_];switch(d){case"/join":{i[1]?st(i[1]):S("Server","Usage: /join #channel");break}case"/part":{if(l.type==="channel"){let p=i.slice(1).join(" ")||void 0;Oe(l.name,p)}else S("Server","You are not in a channel");break}case"/msg":{if(i[1]&&i.slice(2).join(" ")){let p=i[1],k=i.slice(2).join(" ");try{await x("/messages",{method:"POST",body:JSON.stringify({command:"PRIVMSG",to:p,body:[k]})}),de(p)}catch(F){S("Server",`Message failed: ${F.data?.error||"error"}`)}}else S("Server","Usage: /msg <nick> <message>");break}case"/me":{if(l.type==="server"){S("Server","Cannot use /me in server window");break}let p=i.slice(1).join(" ");if(p)try{await x("/messages",{method:"POST",body:JSON.stringify({command:"PRIVMSG",to:l.name,body:[Ce+p+Ie]})})}catch(k){S(l.name,`Action failed: ${k.data?.error||"error"}`)}else S("Server","Usage: /me <action>");break}case"/nick":{if(i[1])try{await x("/messages",{method:"POST",body:JSON.stringify({command:"NICK",body:[i[1]]})})}catch(p){S("Server",`Nick change failed: ${p.data?.error||"error"}`)}else S("Server","Usage: /nick <newnick>");break}case"/topic":{if(l.type!=="channel"){S("Server","You are not in a channel");break}let p=i.slice(1).join(" ");if(p)try{await x("/messages",{method:"POST",body:JSON.stringify({command:"TOPIC",to:l.name,body:[p]})})}catch(k){S("Server",`Topic change failed: ${k.data?.error||"error"}`)}else S("Server",`Current topic for ${l.name}: ${h[l.name]||"(none)"}`);break}case"/mode":{if(l.type!=="channel"){S("Server","You are not in a channel");break}let p=i.slice(1);if(p.length>0)try{await x("/messages",{method:"POST",body:JSON.stringify({command:"MODE",to:l.name,params:p})})}catch(k){S("Server",`Mode change failed: ${k.data?.error||"error"}`)}else S("Server","Usage: /mode <+/-mode> [params]");break}case"/quit":{let p=i.slice(1).join(" ")||void 0;try{await x("/messages",{method:"POST",body:JSON.stringify(p?{command:"QUIT",body:[p]}:{command:"QUIT"})})}catch{}localStorage.removeItem("neoirc_token"),localStorage.removeItem("neoirc_channels"),window.location.reload();break}case"/motd":{try{await x("/messages",{method:"POST",body:JSON.stringify({command:"MOTD"})})}catch(p){S("Server",`Failed to request MOTD: ${p.data?.error||"error"}`)}break}case"/query":{if(i[1]){let p=i[1];de(p);let k=i.slice(2).join(" ");if(k)try{await x("/messages",{method:"POST",body:JSON.stringify({command:"PRIVMSG",to:p,body:[k]})})}catch(F){S("Server",`Message failed: ${F.data?.error||"error"}`)}}else S("Server","Usage: /query <nick> [message]");break}case"/list":{try{await x("/messages",{method:"POST",body:JSON.stringify({command:"LIST"})})}catch(p){S("Server",`Failed to list channels: ${p.data?.error||"error"}`)}break}case"/who":{let p=i[1]||(l.type==="channel"?l.name:"");if(p)try{await x("/messages",{method:"POST",body:JSON.stringify({command:"WHO",to:p})})}catch(k){S("Server",`WHO failed: ${k.data?.error||"error"}`)}else S("Server","Usage: /who #channel");break}case"/whois":{if(i[1])try{await x("/messages",{method:"POST",body:JSON.stringify({command:"WHOIS",to:i[1]})})}catch(p){S("Server",`WHOIS failed: ${p.data?.error||"error"}`)}else S("Server","Usage: /whois <nick>");break}case"/clear":{let p=l.name;f(k=>({...k,[p]:[]}));break}case"/help":{let p=["Available commands:"," /join #channel \u2014 Join a channel"," /part [reason] \u2014 Part the current channel"," /msg nick message \u2014 Send a private message"," /query nick [message] \u2014 Open a DM tab (optionally send a message)"," /me action \u2014 Send an action"," /nick newnick \u2014 Change your nickname"," /topic [text] \u2014 View or set channel topic"," /mode +/-flags \u2014 Set channel modes"," /motd \u2014 Display the message of the day"," /list \u2014 List all channels"," /who [#channel] \u2014 List users in a channel"," /whois nick \u2014 Show info about a user"," /clear \u2014 Clear messages in the current tab"," /quit [reason] \u2014 Disconnect from server"," /help \u2014 Show this help"];for(let k of p)S("Server",k);break}default:S("Server",`Unknown command: ${d}`)}},_t=async()=>{let r=A.trim();if(!r)return;z(d=>{let l=[...d,r];return l.length>100&&l.shift(),l}),B(-1),g("");let i=s[_];if(i){if(r.startsWith("/")){await it(r);return}if(i.type==="server"){S("Server","Cannot send messages to the server window. Use /join #channel first.");return}try{await x("/messages",{method:"POST",body:JSON.stringify({command:"PRIVMSG",to:i.name,body:[r]})})}catch(d){S(i.name,`Send failed: ${d.data?.error||"error"}`)}}},lt=r=>{if(r.key==="Enter")_t();else if(r.key==="ArrowUp"){if(r.preventDefault(),M.length>0){let i=R===-1?M.length-1:Math.max(0,R-1);B(i),g(M[i])}}else if(r.key==="ArrowDown"&&(r.preventDefault(),R>=0)){let i=R+1;i>=M.length?(B(-1),g("")):(B(i),g(M[i]))}};if(!e)return m(Pt,{onLogin:at});let q=s[_]||s[0],ut=y[q.name]||[],ft=b[q.name]||[],dt=h[q.name]||"";return m("div",{class:"irc-app"},m("div",{class:"tab-bar"},m("div",{class:"tabs"},s.map((r,i)=>m("div",{class:`tab ${i===_?"active":""} ${C[r.name]>0&&i!==_?"has-unread":""}`,onClick:()=>u(i),key:r.name},m("span",{class:"tab-label"},(r.type==="dm",r.name)),C[r.name]>0&&i!==_&&m("span",{class:"unread-count"},"(",C[r.name],")"),r.type!=="server"&&m("span",{class:"tab-close",onClick:d=>{d.stopPropagation(),ct(i)}},"\xD7")))),m("div",{class:"status-area"},!w&&m("span",{class:"status-warn"},"\u25CF Reconnecting"),m("span",{class:"status-nick"},n))),q.type==="channel"&&m("div",{class:"topic-bar"},m("span",{class:"topic-label"},"Topic:")," ",m("span",{class:"topic-text"},dt||"(no topic set)")),m("div",{class:"main-area"},m("div",{class:"messages-panel"},m("div",{class:"messages-scroll"},ut.map(r=>m($t,{msg:r,myNick:n,key:r.id})),m("div",{ref:Ae}))),q.type==="channel"&&m(Et,{members:ft,onNickClick:de})),m("div",{class:"input-line"},m("span",{class:"input-prompt"},"[",n,"]",q.type!=="server"?` ${q.name}`:""," >"),m("input",{ref:Z,type:"text",value:A,onInput:r=>g(r.target.value),onKeyDown:lt,placeholder:q.type==="server"?"Type /help for commands":"",spellCheck:!1,autoComplete:"off"})))}Be(m(Mt,null),document.getElementById("root"));
|