most-box 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/out/about/index.html +2 -2
  2. package/out/admin/index.html +0 -0
  3. package/out/app/index.html +0 -0
  4. package/out/assets/{AccountMenu-D-wa5tux.js → AccountMenu-B26qus-Q.js} +1 -1
  5. package/out/assets/{AppShell-BdRKZIZ9.js → AppShell-BiYQsNO8.js} +1 -1
  6. package/out/assets/{AppTop-BE5kKBYH.js → AppTop-D-qYC0ep.js} +1 -1
  7. package/out/assets/ChatRestoringIndicator-CLV78gNW.js +1 -0
  8. package/out/assets/{CopyButton-DnFqfCN9.js → CopyButton-BrEkzqEq.js} +1 -1
  9. package/out/assets/{MarketingHeader-8gNzHawY.js → MarketingHeader-CJXpogPY.js} +1 -1
  10. package/out/assets/{MarketingLayout-BPdjpEfc.js → MarketingLayout-Ch4sw5Qm.js} +1 -1
  11. package/out/assets/{MilkdownEditor-C388llV6.js → MilkdownEditor-DfhuT9eU.js} +1 -1
  12. package/out/assets/{OpenSidebarButton-OP8zl7ad.js → OpenSidebarButton-Bvwr7B6k.js} +1 -1
  13. package/out/assets/{chatJoinInvite-CeC6H6t8.js → chatJoinInvite-7tuD-STm.js} +1 -1
  14. package/out/assets/i18n-DKsg67mH.js +1 -0
  15. package/out/assets/index-FEwag7ej.css +1 -0
  16. package/out/assets/{index-D1mozno-.js → index-mjFWLwue.js} +3 -3
  17. package/out/assets/{index.lazy-B1iJsXQ8.js → index.lazy-8GSHLIGt.js} +1 -1
  18. package/out/assets/{index.lazy-CX2l1_Gi.js → index.lazy-B3jH9yBA.js} +1 -1
  19. package/out/assets/index.lazy-B5JMiv3z.js +1 -0
  20. package/out/assets/{index.lazy-CVFcovqX.js → index.lazy-BAr7-dhf.js} +1 -1
  21. package/out/assets/index.lazy-BMFwyE_Z.js +3 -0
  22. package/out/assets/{index.lazy-Bz77Jlzu.js → index.lazy-BbA_1LnY.js} +1 -1
  23. package/out/assets/{index.lazy-m9XAzMt1.js → index.lazy-BmpOpQqg.js} +1 -1
  24. package/out/assets/{index.lazy-FvXAYdEO.js → index.lazy-CB3C6kMj.js} +1 -1
  25. package/out/assets/{index.lazy-ClrSkRx5.js → index.lazy-CVOAOO0_.js} +1 -1
  26. package/out/assets/{index.lazy-CflWbocP.js → index.lazy-CyFSwJuo.js} +1 -1
  27. package/out/assets/{index.lazy-DzaN9qwA.js → index.lazy-D3iEq2ZW.js} +2 -2
  28. package/out/assets/{index.lazy-CsTaY5WS.js → index.lazy-F3iHN_Ao.js} +1 -1
  29. package/out/assets/{index.lazy-D7E1pb1S.js → index.lazy-PnZR3z1V.js} +1 -1
  30. package/out/assets/{index.lazy-59kmyNMW.js → index.lazy-qDpRLqXu.js} +1 -1
  31. package/out/assets/{index.lazy-C_J9afOY.js → index.lazy-s6Ok77GI.js} +1 -1
  32. package/out/assets/{saveLocalFile-2CNt4X0T.js → saveLocalFile-BLTn3Z18.js} +1 -1
  33. package/out/assets/useChannelMessages-DKlO_2oW.js +4 -0
  34. package/out/assets/{useGameRoom-asr2gyY6.js → useGameRoom-DLN636mz.js} +1 -1
  35. package/out/chat/index.html +0 -0
  36. package/out/chat/join/demo/index.html +0 -0
  37. package/out/chat/join/index.html +0 -0
  38. package/out/download/index.html +2 -2
  39. package/out/game/gandengyan/index.html +0 -0
  40. package/out/game/index.html +0 -0
  41. package/out/game/zhajinhua/index.html +0 -0
  42. package/out/index.html +2 -2
  43. package/out/note/index.html +0 -0
  44. package/out/ping/index.html +2 -2
  45. package/out/profile/index.html +0 -0
  46. package/out/web3/index.html +0 -0
  47. package/package.json +1 -1
  48. package/server/src/index.js +191 -76
  49. package/out/assets/i18n-C6yaqRst.js +0 -1
  50. package/out/assets/index-C6IjeTBh.css +0 -1
  51. package/out/assets/index.lazy-CazlK1-Y.js +0 -3
  52. package/out/assets/index.lazy-JwrS2vDI.js +0 -1
  53. package/out/assets/useChannelMessages-DDBqKBXU.js +0 -4
@@ -1,3 +0,0 @@
1
- import{n as e,o as t,t as n}from"./jsx-runtime-Bt-cYkS5.js";import{B as r,E as i,H as a,c as o,n as s,o as c,t as l}from"./useAppStore-DNhyhD20.js";import{a as u}from"./i18n-C6yaqRst.js";import{t as ee}from"./circle-alert-DXVkx8p8.js";import{a as te,o as d,r as f,t as ne}from"./chatNoteDraft-DTy6In5R.js";import{t as re}from"./OpenSidebarButton-OP8zl7ad.js";import{a as p,i as m,n as ie,o as ae,r as oe,t as se}from"./saveLocalFile-2CNt4X0T.js";import{t as h}from"./arrow-right-BsHzC0ZL.js";import{n as ce,t as g}from"./trash-2-B9gno5q6.js";import{t as _}from"./download-Cy2BlfKM.js";import{t as le}from"./external-link-D_AQSgxW.js";import{t as ue}from"./file-text-zvTER2mN.js";import{t as de}from"./loader-C4pED_QP.js";import{r as fe,t as pe}from"./AppShell-BdRKZIZ9.js";import{t as me}from"./message-square-CfApq8Ou.js";import{t as v}from"./music-Br2x8TKX.js";import{t as he}from"./search-DLBOUfny.js";import{A as ge,C as _e,M as ve,O as ye,S as be,T as xe,g as Se,j as Ce,n as we,r as Te,w as Ee}from"./index-D1mozno-.js";import{t as De}from"./AppTop-BE5kKBYH.js";import{t as Oe}from"./LogoIcon-B2fFe0l1.js";import{t as ke}from"./format-CAKfypjK.js";import{a as Ae,i as je,n as y,o as Me,r as Ne,t as Pe}from"./downloadValidation-Dd43i9_9.js";import{t as b}from"./channelApi-C5eHetoJ.js";import{t as Fe}from"./useChannelMessages-DDBqKBXU.js";var Ie=r(`calendar`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}]]),Le=r(`hash`,[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]),Re=r(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),ze=r(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),Be=r(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),x=t(e(),1),S=n();function Ve(e){return String(e||``).split(`/`).pop()||e}function He(e){return e===`image`?(0,S.jsx)(m,{size:20}):e===`video`?(0,S.jsx)(p,{size:20}):e===`audio`?(0,S.jsx)(v,{size:20}):(0,S.jsx)(ue,{size:20})}function Ue({attachment:e,status:t=`idle`,message:n,pending:r=!1,onOpen:i}){let{t:a}=u(),o=t===`checking`,s=t===`downloading`,c=r||o||s,l=`ui-file-action chat-attachment-action ${t===`error`?`error`:t===`available`?`available`:``}`.trim(),te=Number.isFinite(e.size)&&e.size>0?ke(e.size):a(`chat.mostboxFile`),d=r?a(`chat.sending`):n||te,f=a(r?`chat.sending`:o?`chat.checking`:s?`chat.attachment.downloading`:t===`available`?`chat.attachment.preview`:t===`error`?`chat.attachment.retry`:`chat.attachment.download`);return(0,S.jsxs)(`button`,{type:`button`,className:`ui-file-card chat-attachment-card`,onClick:()=>i?.(e),disabled:c,title:e.link,translate:`no`,children:[(0,S.jsx)(`span`,{className:`ui-file-icon chat-attachment-icon ${e.kind}`,children:c?(0,S.jsx)(de,{size:20,className:`ui-spinner chat-attachment-spinner`}):He(e.kind)}),(0,S.jsxs)(`span`,{className:`ui-file-info chat-attachment-info`,children:[(0,S.jsx)(`span`,{className:`ui-file-name chat-attachment-name`,translate:`no`,children:Ve(e.fileName)}),(0,S.jsx)(`span`,{className:`ui-file-meta chat-attachment-meta`,translate:`yes`,children:d})]}),(0,S.jsxs)(`span`,{className:l,translate:`yes`,children:[c?(0,S.jsx)(de,{size:15,className:`ui-spinner chat-attachment-spinner`}):t===`available`?(0,S.jsx)(ve,{size:16}):t===`error`?(0,S.jsx)(ee,{size:17}):(0,S.jsx)(_,{size:16}),(0,S.jsx)(`span`,{className:`chat-attachment-action-label`,children:f})]})]})}var C=[{key:`image`,labelKey:`chat.attachment.image`,accept:`image/*`,icon:m},{key:`video`,labelKey:`chat.attachment.video`,accept:`video/*`,icon:p},{key:`file`,labelKey:`chat.attachment.file`,accept:``,icon:ue}],w={key:`voice`,labelKey:`chat.voice.menu`,icon:Ce},We=C.map(e=>e.accept).join(`,`);function Ge({children:e}){return(0,S.jsx)(`div`,{className:`message-bubble`,translate:`no`,children:e})}function Ke({children:e}){return(0,S.jsx)(`div`,{className:`message-bubble has-attachment`,children:e})}function qe({children:e}){return(0,S.jsx)(`div`,{className:`chat-system-message`,children:e})}function Je({variant:e,pending:t=!1,avatarSrc:n,isOnline:r=!1,author:i,time:a,children:o}){return(0,S.jsxs)(`div`,{className:[`chat-message`,e,t?`pending`:``].filter(Boolean).join(` `),children:[(0,S.jsxs)(`span`,{className:`chat-avatar-wrap`,children:[(0,S.jsx)(`img`,{className:`msg-avatar`,src:n,alt:`avatar`}),r&&(0,S.jsx)(`span`,{className:`chat-online-dot`,"aria-hidden":`true`})]}),(0,S.jsxs)(`div`,{className:`msg-content`,children:[(0,S.jsx)(`span`,{className:`message-header`,children:(0,S.jsx)(`span`,{className:`message-author`,translate:`no`,children:i})}),o,(0,S.jsx)(`span`,{className:`message-time`,children:a})]})]})}function Ye({active:e=!1,pinned:t=!1,unread:n=!1,title:r,menuClassName:i,onSelect:a,onTogglePin:o,onRename:s,onLeave:c}){let{t:l}=u(),ee=!!(o||s||c);return(0,S.jsxs)(`div`,{className:[`sidebar-nav-btn`,e?`active`:``,t?`pinned`:``,n?`unread`:``].filter(Boolean).join(` `),onClick:a,role:`button`,tabIndex:0,onKeyDown:e=>{e.target===e.currentTarget&&e.key===`Enter`&&a?.()},children:[(0,S.jsxs)(`span`,{className:`chat-channel-icon-wrap`,children:[(0,S.jsx)(me,{size:16}),n&&(0,S.jsx)(`span`,{className:`chat-channel-unread-dot`,title:l(`chat.unread`),"aria-hidden":`true`})]}),(0,S.jsx)(`span`,{className:`chat-channel-title`,children:(0,S.jsx)(`span`,{className:`chat-channel-title-text`,translate:`no`,children:r})}),ee&&(0,S.jsx)(be,{ariaLabel:l(`chat.channelActions`),className:`channel-actions-anchor`,menuClassName:i,placement:`bottom-end`,items:[{key:`pin`,label:l(t?`chat.unpin`:`chat.pin`),icon:t?(0,S.jsx)(Re,{size:16}):(0,S.jsx)(ze,{size:16}),onSelect:()=>o?.()},{key:`rename`,label:l(`chat.rename`),icon:(0,S.jsx)(ae,{size:16}),onSelect:()=>s?.()},{key:`delete`,label:l(`chat.delete`),icon:(0,S.jsx)(g,{size:16}),onSelect:()=>c?.()}],renderTrigger:e=>(0,S.jsx)(`button`,{...e,className:`leave-channel-btn channel-actions-trigger`,title:l(`common.moreActions`),"aria-label":l(`common.moreActions`),children:(0,S.jsx)(d,{size:16})})})]})}function Xe({members:e}){let{t}=u();return e.length===0?(0,S.jsx)(`div`,{className:`ui-empty-inline channel-members-empty`,children:t(`chat.noMembers`)}):(0,S.jsx)(`div`,{className:`channel-members-grid`,children:e.map(e=>(0,S.jsxs)(`div`,{className:`channel-member`,children:[(0,S.jsxs)(`span`,{className:`channel-member-avatar-wrap`,children:[(0,S.jsx)(`img`,{className:`channel-member-avatar`,src:e.avatarSrc,alt:`avatar`}),e.online&&(0,S.jsx)(`span`,{className:`chat-online-dot`,"aria-hidden":`true`})]}),(0,S.jsx)(`span`,{className:`channel-member-name`,translate:`no`,children:e.name})]},e.id))})}function Ze({message:e,placeholder:t,disabled:n=!1,isPublishingAttachment:r=!1,attachmentButtonTitle:i,attachmentInputRef:a,attachmentMenuClassName:o,showVoiceRoom:s=!0,onMessageChange:c,onSend:l,onOpenVoiceRoom:ee,onSelectAttachmentFiles:d}){let{t:f}=u(),ne=n||r,re=n||!e.trim(),p=i||f(`chat.attachment.add`);function m(e,t){let n=e.currentTarget.files?Array.from(e.currentTarget.files):null;t?.(n),e.currentTarget.value=``}function ie(t){t.key===`Enter`&&(t.shiftKey||t.nativeEvent.isComposing||(t.preventDefault(),e.trim()&&l()))}function ae(e){if(ne)return;let t=a?.current;t&&(t.accept=e,t.click())}return(0,S.jsxs)(`div`,{className:`chat-input-area`,children:[(0,S.jsx)(`input`,{ref:a,type:`file`,accept:We,className:`chat-file-input`,onChange:e=>m(e,d)}),(0,S.jsx)(be,{ariaLabel:f(`chat.attachmentType`),placement:`top-start`,disabled:ne,menuClassName:o,items:[...C.map(e=>{let t=e.icon;return{key:e.key,label:f(e.labelKey),icon:(0,S.jsx)(t,{size:16}),onSelect:()=>ae(e.accept)}}),...s?[{key:w.key,label:f(w.labelKey),icon:(0,S.jsx)(Ce,{size:16}),onSelect:()=>ee?.()}]:[]],renderTrigger:e=>(0,S.jsx)(`button`,{...e,className:`btn btn-circle chat-tool-btn`,"aria-label":p,children:r?(0,S.jsx)(de,{size:18,className:`ui-spinner chat-attachment-spinner`}):(0,S.jsx)(te,{size:18})})}),(0,S.jsx)(`textarea`,{className:`textarea chat-composer-input`,placeholder:t,value:e,disabled:n,rows:1,onChange:e=>c(e.target.value),onKeyDown:ie}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-circle btn-primary send-btn`,onClick:l,disabled:re,title:f(`chat.sendMessage`),children:(0,S.jsx)(h,{size:18})})]})}var Qe=`mostbox.chat.lastReadAt`;function T(e){return Date.parse(e?.lastMessageAt||``)||Date.parse(e?.createdAt||``)||0}function $e(e){let t=String(e||``).trim().toLowerCase();return t?`${Qe}:${t}`:``}function et(e,t=Date.now()){let n=Number(e);return Math.max(0,Math.floor(Number.isFinite(n)&&n>0?n:t))}function tt(e,t=st()){if(!e||!t)return{};try{let n=t.getItem(e);if(!n)return{};let r=JSON.parse(n);return!r||typeof r!=`object`?{}:Object.entries(r).reduce((e,[t,n])=>{let r=Number(n);return t&&Number.isFinite(r)&&r>=0&&(e[t]=r),e},{})}catch{return{}}}function nt(e,t,n=st()){if(!(!e||!n))try{n.setItem(e,JSON.stringify(t))}catch{}}function rt(e,t,n=Date.now(),r=Date.now()){if(!t)return{changed:!1,value:e};let i=et(n,r);return(e[t]||0)>=i?{changed:!1,value:e}:{changed:!0,value:{...e,[t]:i}}}function it(e,t,n=Date.now()){let r=!1,i={...e};for(let e of t){let t=e?.channelKey||e?.name;!t||i[t]!==void 0||(i[t]=et(T(e),n),r=!0)}return{changed:r,value:r?i:e}}function at(e,{channelName:t,messageTime:n,activeChannelName:r=``,messageAuthor:i=``,userAddress:a=``,now:o=Date.now()}){if(!t)return{changed:!1,notify:!1,value:e};let s=et(n,o),c=t===r;if(String(i||``).toLowerCase()===String(a||``).toLowerCase())return{...rt(e,t,s,o),notify:!1};if(c)return{...rt(e,t,s,o),notify:!0};let l=e[t]||0;if(l<s)return{changed:!1,notify:!0,value:e};let u=Math.max(0,s-1);return l===u?{changed:!1,notify:!0,value:e}:{changed:!0,notify:!0,value:{...e,[t]:u}}}function ot(e,t){let n=e?.channelKey||e?.name;return T(e)>(t[n]||0)}function st(){if(!(typeof window>`u`))return window.localStorage}var ct=3,lt=30,ut=/^[a-zA-Z0-9_-]+$/,dt=1e4,ft=12e3,pt=1200,mt=800,ht=`channel.member.joined`;function E(e){return e?.channelKey||e?.name||``}function gt(e){return e?.channelId||e?.name||``}function D(e){return e&&typeof e==`object`?e:{}}function _t(e){let t=D(e),n=new Set,r=e=>{let t=String(e||``).trim();t&&n.add(t)};return r(t.channelKey),r(t.channel),Array.isArray(t.channels)&&t.channels.forEach(e=>{let t=D(e);r(t.channelKey),r(t.channel),r(t.name)}),[...n]}function O(e){return e?.remark||gt(e)}function vt(e){return e.type===`system`&&e.event===ht}function yt(){return typeof window>`u`?``:(new URLSearchParams(window.location.search).get(`channel`)||``).trim()}function bt(e){let t=new Date(e||Date.now());return Number.isNaN(t.getTime())?String(Date.now()):t.toISOString().slice(0,16).replace(`T`,` `).replace(`:`,`-`)}function k(e){return e.replace(/\\/g,`\\\\`).replace(/\[/g,`\\[`).replace(/\]/g,`\\]`)}function xt(e,t){return`[${k(e)}](<${t.replace(/>/g,`%3E`)}>)`}function St(e){let t=String(e||``).trim().split(/\r?\n/);return t.length>0?t.map(e=>`> ${e}`).join(`
2
- `):`> `}var Ct=`chat-file`;function wt(e,t){return e.type.startsWith(`image/`)?`image`:e.type.startsWith(`video/`)?`video`:e.type.startsWith(`audio/`)?`audio`:e.type.startsWith(`text/`)?`text`:oe(t)}function Tt(e){return e?`${e.slice(0,6)}...${e.slice(-4)}`:`Unknown`}function Et(e){return/#[a-fA-F0-9]{4}$/.test(String(e||``).trim())}function A(e){return String(e||``).trim().toLowerCase()}function Dt(){if(typeof window>`u`)return;let e=window;return e.AudioContext||e.webkitAudioContext}function j(){let e=l(e=>e.hasBackend),t=l(e=>e.isDarkMode),n=l(e=>e.addToast),r=l(e=>e.openConnectModal),a=i(e=>e.identity),ee=i(e=>e.openLoginModal),[d,p]=(0,x.useState)([]),[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(``),[ue,v]=(0,x.useState)(!1),[ve,be]=(0,x.useState)(``),[Ce,ke]=(0,x.useState)(``),[Re,ze]=fe(!1),[He,C]=(0,x.useState)(``),[w,We]=(0,x.useState)(!1),[Qe,et]=(0,x.useState)(!1),[st,ht]=fe(!1),[D,k]=(0,x.useState)(null),[j,M]=(0,x.useState)(null),[Ot,N]=(0,x.useState)(!1),[kt,At]=(0,x.useState)(``),[jt,Mt]=(0,x.useState)(!1),[Nt,Pt]=(0,x.useState)(null),[Ft,It]=(0,x.useState)(!1),[P,F]=(0,x.useState)({}),[I,L]=(0,x.useState)(null),[Lt,Rt]=(0,x.useState)(!1),[zt,Bt]=(0,x.useState)(!1),[Vt,Ht]=(0,x.useState)(!1),[Ut,R]=(0,x.useState)({}),[Wt,Gt]=(0,x.useState)([]),z=a?.theme===`sparkbit`,Kt=z&&a?.data?a.data:``,qt=z&&a?.logo||``,Jt=z&&t&&a?.logo_dark||``,Yt=Jt||qt,Xt=Jt&&qt&&Jt!==qt?qt:``,Zt=Yt&&!zt?Yt:Xt&&!Vt?Xt:``,Qt=(0,x.useRef)(null),$t=(0,x.useRef)(null),B=(0,x.useRef)(``),en=(0,x.useRef)(new Set),tn=(0,x.useRef)(new Set),V=(0,x.useRef)(null),nn=(0,x.useRef)(!1),rn=(0,x.useRef)(0),an=(0,x.useRef)(async()=>[]),on=(0,x.useRef)(new Map),H=(0,x.useRef)(new Map),U=(0,x.useRef)(new Set),W=e===!0,{t:G,compareStrings:sn,formatDate:cn,formatTime:ln}=u(),K=we(),q=(0,x.useCallback)(async(e,t)=>{n(await c(e,t),`error`)},[n]),J=(0,x.useMemo)(()=>$e(a?.address),[a?.address]),un=(0,x.useCallback)((e,t=Date.now())=>{e&&R(n=>{let r=rt(n,e,t);return r.changed?(nt(J,r.value),r.value):n})},[J]),dn=(0,x.useCallback)(()=>{if(nn.current||typeof window>`u`)return;let e=Dt();if(e)try{let t=V.current||new e;V.current=t,t.state===`suspended`&&t.resume().catch(()=>{}),nn.current=!0}catch{}},[]),fn=(0,x.useCallback)(()=>{if(!nn.current)return;let e=Date.now();if(e-rn.current<pt)return;rn.current=e;let t=Dt();if(t)try{let e=V.current||new t;if(V.current=e,e.state===`suspended`){e.resume().catch(()=>{});return}let n=e.createGain();n.gain.setValueAtTime(1e-4,e.currentTime),n.gain.exponentialRampToValueAtTime(.08,e.currentTime+.015),n.gain.exponentialRampToValueAtTime(1e-4,e.currentTime+.18),n.connect(e.destination),[740,980].forEach((t,r)=>{let i=e.createOscillator();i.type=`sine`,i.frequency.setValueAtTime(t,e.currentTime),i.connect(n),i.start(e.currentTime+r*.035),i.stop(e.currentTime+.16+r*.035)})}catch{}},[]),pn=(0,x.useCallback)(async(e=m)=>{let t=E(e);if(!t||!W){Gt([]);return}try{let e=await b.getChannelPresence(t);if(B.current!==t)return;Gt(e)}catch(e){console.warn(`[Chat] Failed to fetch channel presence:`,e instanceof Error?e.message:e)}},[m,W]),mn=(0,x.useCallback)((e=``)=>{let t=B.current;if(!e||e!==t||!W)return;let n=on.current,r=n.get(e);r&&window.clearTimeout(r);let i=window.setTimeout(()=>{n.delete(e),an.current(e)},mt);n.set(e,i)},[W]);function hn(e,t){switch(e){case`channel:message`:{let e=t?.channelKey||t?.channel,n=t?.message,r=Number(n?.timestamp)||Date.now();if(e){p(t=>t.map(t=>E(t)===e?{...t,lastMessageAt:new Date(r).toISOString()}:t));let t=e===B.current;R(i=>{let o=at(i,{channelName:e,messageTime:r,activeChannelName:t?e:``,messageAuthor:n?.author,userAddress:a?.address});return o.changed&&nt(J,o.value),o.notify&&fn(),o.changed?o.value:i})}break}case`channel:peer:online`:case`channel:sync:available`:{let e=_t(t),n=B.current;$(),e.includes(n)&&(mn(n),m&&pn(m));break}case`channel:presence`:{let e=t?.channelKey||t?.channel;m&&(!e||e===E(m))&&pn(m);break}case`channel:joined`:case`channel:left`:$();break;case`user:metadata:updated`:t?.scope===`channels`&&$();break;case`download:success`:{let e=H.current.get(t.taskId);e&&(H.current.delete(t.taskId),U.current.delete(e.cid),F(t=>({...t,[e.cid]:{status:`available`,message:G(`chat.attachment.previewAvailable`)}})),n(G(`chat.attachment.downloadCompleted`,{fileName:t.fileName||Ve(e.fileName)}),`success`),Dn(e,t.fileName||e.fileName));break}case`download:error`:case`download:cancelled`:{let r=H.current.get(t.taskId);r&&(H.current.delete(t.taskId),U.current.delete(r.cid),F(n=>({...n,[r.cid]:{status:`error`,message:e===`download:cancelled`?G(`chat.attachment.downloadCancelled`):t.error||G(`chat.attachment.downloadFailed`)}})),n(e===`download:cancelled`?G(`chat.attachment.downloadCancelled`):t.error||G(`chat.attachment.downloadFailed`),`error`));break}}}let gn=(0,x.useMemo)(()=>d.map(e=>E(e)),[d]),_n=(0,x.useMemo)(()=>a?{...Te(a),profileUpdatedAt:a.profileUpdatedAt}:{},[a?.avatar,a?.displayName,a?.profileUpdatedAt,a?.username]),Y=(0,x.useMemo)(()=>m?{channelName:E(m),title:O(m)}:null,[m]),{clearMessages:vn,messages:X,sendMessage:yn,syncMessages:bn}=Fe({isReady:W,enabled:!!a,channelName:E(m),extraSubscribedChannelNames:gn,peerId:He,waitForPeerId:!0,onSyncError:e=>q(e,G(`chat.error.messages`)),onSocketEvent:hn,onReconnect:()=>{$(),m&&pn(m)},presenceEnabled:!!(m&&a),presenceProfile:_n});(0,x.useEffect)(()=>{an.current=bn},[bn]),(0,x.useEffect)(()=>{let e=on.current;return()=>{for(let t of e.values())window.clearTimeout(t);e.clear()}},[]);let xn=(0,x.useMemo)(()=>{let e=new Map;return X.forEach((t,n)=>{let r=String(t.author||``).trim();if(!r)return;let i=r.toLowerCase(),a=Number(t.timestamp)||0,o=String(t.authorName||``).trim(),s=String(t.avatar||``).trim(),c=e.get(i);if(!c){e.set(i,{address:r,displayName:o,...s?{avatar:s}:{},firstSeenAt:a,lastSeenAt:a,index:n});return}a>=c.lastSeenAt&&(c.lastSeenAt=a,o&&(c.displayName=o),s&&(c.avatar=s))}),[...e.values()].sort((e,t)=>e.firstSeenAt-t.firstSeenAt||e.index-t.index)},[X]),Sn=(0,x.useMemo)(()=>new Map(xn.map(e=>[A(e.address),e])),[xn]),Cn=(0,x.useMemo)(()=>{let e=new Map;return Wt.forEach(t=>{let n=A(t.address);!n||!t.online||e.set(n,t)}),e},[Wt]),wn=(0,x.useMemo)(()=>{let e=new Map(Sn);return Wt.forEach((t,n)=>{let r=A(t.address);!r||e.has(r)||e.set(r,{address:t.address,displayName:t.displayName||``,...t.avatar?{avatar:t.avatar}:{},firstSeenAt:t.lastSeen||Date.now(),lastSeenAt:t.lastSeen||Date.now(),index:xn.length+n})}),[...e.values()]},[xn,Wt,Sn]),Tn=(0,x.useMemo)(()=>new Set(Cn.keys()),[Cn]);function Z(){return W?!0:(r(),!1)}function Q(){return a?!0:(ee(),!1)}(0,x.useEffect)(()=>{let e=()=>{_(yt())};return e(),window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]),(0,x.useEffect)(()=>{a&&_(yt())},[a?.address]),(0,x.useEffect)(()=>{Bt(!1),Ht(!1)},[Yt,Xt]),(0,x.useEffect)(()=>{B.current=E(m)},[m]),(0,x.useEffect)(()=>(K.setPreviewRoom(a&&Y?Y:null),()=>{K.setPreviewRoom(null)}),[Y,a,K.setPreviewRoom]),(0,x.useEffect)(()=>{R(tt(J))},[J]),(0,x.useEffect)(()=>{!J||d.length===0||R(e=>{let t=it(e,d);return t.changed&&nt(J,t.value),t.changed?t.value:e})},[J,d]),(0,x.useEffect)(()=>(window.addEventListener(`pointerdown`,dn,{passive:!0}),window.addEventListener(`keydown`,dn),()=>{window.removeEventListener(`pointerdown`,dn),window.removeEventListener(`keydown`,dn)}),[dn]),(0,x.useEffect)(()=>()=>{V.current?.close().catch(()=>{}),V.current=null,nn.current=!1},[]),(0,x.useEffect)(()=>{Qt.current?.scrollIntoView({behavior:`smooth`})},[X]),(0,x.useEffect)(()=>{if(!W){C(``);return}s.get(`/api/node-id`).json().then(e=>C(e.id)).catch(e=>{console.warn(`[Chat] Failed to fetch node ID:`,e.message),q(e,G(`chat.error.nodeId`))})},[W,q,G]),(0,x.useEffect)(()=>{W&&a?(v(!1),$()):v(!1)},[e,W,a?.address]),(0,x.useEffect)(()=>{if(m){if(W){let e=E(m);Gt([]),bn(e,{replace:!0}),pn(m)}}else Gt([])},[m,W,pn,bn]),(0,x.useEffect)(()=>{if(!g)return;if(!a){tn.current.has(g)||(tn.current.add(g),ee());return}if(!W||!ue)return;let e=d.find(e=>E(e)===g)||d.find(e=>gt(e)===g);if(e&&(!m||E(m)!==E(e))){Mn(e);return}if(e&&m&&E(m)===E(e)&&(m.createdAt!==e.createdAt||m.coreKey!==e.coreKey||m.lastMessageAt!==e.lastMessageAt||m.pinned!==e.pinned||m.remark!==e.remark||m.type!==e.type)){h(e);return}if(e)return;let t=`${a.address}:${g}`;if(en.current.has(t)||w)return;let r=En(g);if(en.current.add(t),r){n(r,`error`);return}Fn(g)},[d,m,g,ue,W,w,a?.address]),(0,x.useEffect)(()=>{a||(p([]),v(!1),h(null),_(yt()),M(null),vn(),ke(``),C(``),N(!1),Pt(null),F({}),R({}),U.current.clear(),H.current.clear())},[vn,a?.address]);function En(e){return e.length<ct?G(`chat.validation.nameMin`,{count:ct}):e.length>lt?G(`chat.validation.nameMax`,{count:lt}):e.includes(`.`)?G(`chat.validation.dotReserved`):ut.test(e)?``:G(`chat.validation.allowedChars`)}async function $(){if(!W){v(!1);return}try{p(await b.getChannels()),v(!0)}catch(e){p([]),v(!1),await q(e,G(`chat.error.channelList`))}}function Dn(e,t=e.fileName){let n=oe(t);Pt({cid:e.cid,fileName:t,subtype:n===`file`?e.kind:n})}async function On(e){if(Q()&&Z())try{n((await se({cid:e.cid,fileName:e.fileName,getFileDownloadUrl:y.getFileDownloadUrl,getRequestHeaders:o,loadFailedMessage:G(`app.toast.getFileFailed`)})).method===`picker`?G(`app.toast.fileSaved`):G(`app.toast.fileDownloaded`),`success`)}catch(e){e.name!==`AbortError`&&n(G(`app.saveFailedWithError`,{error:e.message}),`error`)}}async function kn(e){let t=Pe(e.link,G);if(t)return F(n=>({...n,[e.cid]:{status:`error`,message:t}})),!1;try{F(t=>({...t,[e.cid]:{status:`checking`}}));let t=await y.checkDownload(e.link,{timeout:dt,requestTimeout:ft});return F(n=>({...n,[e.cid]:{status:t.alreadyExists?`available`:`ready`,message:t.alreadyExists?G(`chat.attachment.localAvailable`):G(`chat.attachment.downloadAvailable`)}})),!0}catch(t){let n=await Ne(t);return F(t=>({...t,[e.cid]:{status:`error`,message:n}})),!1}}async function An(e){L(null),await kn(e)&&await jn(e)}async function jn(e){if(!U.current.has(e.cid)){U.current.add(e.cid),F(t=>({...t,[e.cid]:{status:`downloading`,message:G(`chat.attachment.downloading`)}}));try{let t=await y.downloadFile(e.link);if(t.alreadyExists||t.fileName){U.current.delete(e.cid),F(t=>({...t,[e.cid]:{status:`available`,message:G(`chat.attachment.previewAvailable`)}})),Dn({...e,fileName:t.fileName||e.fileName},t.fileName||e.fileName);return}t.taskId&&(H.current.set(t.taskId,e),n(G(`chat.attachment.downloadStarted`),`success`))}catch(t){let n=await Ne(t);U.current.delete(e.cid),F(t=>({...t,[e.cid]:{status:`error`,message:n}}))}}}async function Mn(e){if(!Q()||!Z())return;let t=E(e);un(t,Math.max(T(e),Date.now())),h(e),_(t),window.history.pushState({},``,`?channel=${encodeURIComponent(t)}`)}async function Nn(e,t){if(t&&t.stopPropagation(),Q()&&Z()&&!Qe){et(!0);try{if(await b.leaveChannel(e),E(m)===e){h(null),_(``),vn();let e=new URL(window.location.href);e.searchParams.delete(`channel`),window.history.pushState({},``,e.pathname)}$(),ht.close(),k(null)}catch(e){await q(e,G(`chat.error.leave`))}finally{et(!1)}}}async function Pn(e){if(!Q()||!Z())return;let t=!e.pinned,n=E(e);try{let e=await b.setChannelPinned(n,t);p(t=>t.map(t=>E(t)===n?{...t,pinned:e.pinned}:t)),h(t=>t&&E(t)===n?{...t,pinned:e.pinned}:t)}catch(e){await q(e,G(t?`chat.error.pin`:`chat.error.unpin`))}}async function Fn(e){let t=e.trim();if(!t||w)return;let r=En(t);if(r){n(r,`error`);return}if(Q()&&Z()){We(!0);try{let e=await b.createChannel(t,`public`,Te(a)),n=e.channelKey||e.key||e.name||t,r=d.find(e=>E(e)===n),i={...r,name:e.name||t,channelId:e.channelId||e.name||t,channelKey:e.channelKey||e.key||r?.channelKey,type:e.type||r?.type||`public`,createdAt:e.createdAt||r?.createdAt,coreKey:e.coreKey||e.key||r?.coreKey,localWriterCoreKey:e.localWriterCoreKey||r?.localWriterCoreKey,writerCoreKeys:e.writerCoreKeys||r?.writerCoreKeys,remark:e.remark||r?.remark},o=E(i);p(e=>e.some(e=>E(e)===o)?e.map(e=>E(e)===o?{...e,...i}:e):[...e,i]),ze.close(),await Mn(i),$()}catch(e){await q(e,G(`chat.error.join`))}finally{We(!1)}}}async function In(e,t){if(!e.trim()||!m||!Q()||!Z())return!1;let n=e.trim(),r=E(m);try{let e=await yn({channelName:r,content:n,attachment:t});return p(t=>t.map(t=>E(t)===r?{...t,lastMessageAt:new Date(Number(e?.timestamp)||Date.now()).toISOString()}:t)),e&&un(r,Number(e.timestamp)||Date.now()),!0}catch(e){return await q(e,G(`chat.error.send`)),!1}}async function Ln(){if(!Ce.trim())return;let e=Ce.trim();ke(``),await In(e)}function Rn(e,t){return`${Ct}/${e}/${t}`}async function zn(e){if(!e||e.length===0||!m||!Q()||!Z()||Ft)return;It(!0);let t=``;try{let r=await y.getNodePolicy().catch(()=>null);for(let i of Array.from(e)){t=i.name;let e=Ae(i,r,G);if(e){n(e,`error`);continue}let a=Rn(gt(m),i.name),o=await y.publishFile(i,a),s=o.fileName||a,c=o.link||Me(o.cid,s);await In(c,{kind:wt(i,s),cid:o.cid,fileName:s,link:c,mimeType:i.type||void 0,size:i.size})}}catch(e){n(await je(e,G(`chat.error.attachmentSend`),G,t),`error`)}finally{It(!1)}}async function Bn(e){if(!Q()||!Z())return;let t=P[e.cid];if(!(t?.status===`checking`||t?.status===`downloading`)){if(t?.status===`error`){L(e);return}if(t?.status===`ready`||t?.status===`available`){await jn(e);return}if(!t){await kn(e)&&await jn(e);return}}}function Vn(e){let t=A(e.author),n=Cn.get(t),r=Sn.get(t);return Xn(n?.displayName||r?.displayName||e.authorName,e.author)}function Hn(e){return e.type!==`system`&&!e.pending&&(!!e.attachment||!!e.content.trim())}function Un(e,t){let n=Vn(t),r=`${cn(t.timestamp)} ${ln(t.timestamp)}`,i=t.content.trim();e.push(`## ${r} ${n}`,``),i&&(!t.attachment||i!==t.attachment.link)&&e.push(St(i),``),t.attachment&&e.push(`**${G(`chat.noteDraft.attachment`)}**`,``,`- ${G(`chat.noteDraft.file`)}: ${xt(Ve(t.attachment.fileName),t.attachment.link)}`,`- CID: \`${t.attachment.cid}\``,``)}function Wn(e){let t=m?O(m):``,n=`${cn(Date.now())} ${ln(Date.now())}`,r=[`# ${G(`chat.noteDraft.heading`)}`,``,`- ${G(`chat.noteDraft.room`)}: ${t}`,`- ${G(`chat.noteDraft.exportedAt`)}: ${n}`,`- ${G(`chat.noteDraft.messageCount`)}: ${e.length}`,``];return e.forEach(e=>Un(r,e)),`${r.join(`
3
- `).trimEnd()}\n`}function Gn(){let e=X.filter(Hn);if(e.length===0){n(G(`chat.noteDraft.empty`),`warning`);return}let t=ne({title:G(`chat.noteDraft.historyTitle`,{room:m?O(m):G(`chat.title`),time:bt()}),content:Wn(e)});if(!t){n(G(`chat.noteDraft.saveFailed`),`error`);return}N(!1),window.location.assign(f(t.id))}async function Kn(e,t){if(!Q()||!Z())return;let n=E(e),r=await b.setChannelRemark(n,t);return p(e=>e.map(e=>E(e)===n?{...e,remark:r.remark}:e)),h(e=>e&&E(e)===n?{...e,remark:r.remark}:e),r.remark}async function qn(){if(m)try{await Kn(m,kt)}catch(e){await q(e,G(`chat.error.remark`))}}async function Jn(e){if(!(!j||jt)){Mt(!0);try{await Kn(j,e),M(null)}catch(e){await q(e,G(`chat.error.rename`))}finally{Mt(!1)}}}function Yn(e){if(!e.attachment)return(0,S.jsx)(Ge,{children:e.content});let t=e.attachment,n=P[t.cid],r=n?.status;return(0,S.jsx)(Ke,{children:(0,S.jsx)(Ue,{attachment:t,status:r,message:n?.message,pending:e.pending,onOpen:Bn})})}function Xn(e,t){let n=String(e||``).trim();return n?Lt?Et(n)?n:t?`${n}#${t.slice(-4).toUpperCase()}`:n:n.replace(/#[a-fA-F0-9]{4}$/,``):Tt(t)}function Zn(){return(0,S.jsx)(Xe,{members:wn.map(e=>{let t=Cn.get(A(e.address)),n=t?.displayName||e.displayName,r=t?.avatar||e.avatar;return{id:e.address,name:Xn(n,e.address),avatarSrc:Se(e.address,r),online:Tn.has(A(e.address))}})})}let Qn=z&&!!g&&!m,$n=[`chat-app-layout`,z?`sparkbit-chat-layout`:``].filter(Boolean).join(` `),er=z?`sparkbit-chat-action-menu`:void 0,tr=m?(0,S.jsx)(`h2`,{className:`header-title`,translate:`no`,children:O(m)}):(0,S.jsx)(`h2`,{className:`header-title`,children:G(`chat.title`)}),nr=!!(Y&&K.room?.channelName===Y.channelName),rr=K.participants.filter(e=>!e.local).length,ir=K.joined?rr:K.participants.length,ar=!z&&nr&&(K.joined||K.participants.length>0),or=K.joined?G(`chat.voice.bannerJoined`,{count:ir}):G(`chat.voice.bannerActive`,{count:ir});function sr(){Y&&K.openRoom(Y)}let cr=ve.trim().toLowerCase(),lr=(0,x.useMemo)(()=>[...d].sort((e,t)=>{let n=Number(!!t.pinned)-Number(!!e.pinned);if(n!==0)return n;let r=T(t)-T(e);return r===0?sn(O(e),O(t)):r}),[d,sn]),ur=cr?lr.filter(e=>[O(e),gt(e),E(e)].some(e=>e.toLowerCase().includes(cr))):lr;return(0,S.jsxs)(pe,{className:$n,defaultHide:z,hideAccountMenu:z,sidebar:({closeSidebar:e})=>(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(De,{onNavigate:e}),(0,S.jsx)(`div`,{className:`chat-channel-search`,children:(0,S.jsxs)(`div`,{className:`ui-input-control`,children:[(0,S.jsx)(he,{className:`ui-input-icon`,size:15}),(0,S.jsx)(`input`,{type:`search`,className:`input input-compact`,placeholder:G(`chat.search.placeholder`),value:ve,onChange:e=>be(e.target.value),"aria-label":G(`chat.search.placeholder`)})]})}),(0,S.jsx)(`nav`,{className:`sidebar-nav`,children:d.length===0?(0,S.jsx)(`div`,{className:`sidebar-empty-state`,children:(0,S.jsx)(`p`,{children:G(`chat.empty.noChannels`)})}):ur.length===0?(0,S.jsx)(`div`,{className:`sidebar-empty-state`,children:(0,S.jsx)(`p`,{children:G(`chat.empty.noMatches`)})}):ur.map(t=>(0,S.jsx)(Ye,{active:E(m)===E(t),pinned:!!t.pinned,unread:ot(t,Ut),title:O(t),menuClassName:er,onSelect:()=>{Mn(t),e()},onTogglePin:()=>void Pn(t),onRename:()=>M(t),onLeave:()=>{k(t),ht.open()}},E(t)))}),(0,S.jsxs)(`button`,{className:`ui-action-dashed create-channel-btn`,onClick:()=>{!Q()||!Z()||ze.open()},children:[(0,S.jsx)(te,{size:16}),G(`chat.joinChannel`)]})]}),headerTitle:tr,sidebarToggleReplacement:z?(0,S.jsx)(`span`,{className:`sidebar-toggle-static-logo`,"aria-hidden":`true`,children:Zt?(0,S.jsx)(`img`,{className:`sidebar-toggle-static-logo-img`,src:Zt,alt:``,onError:()=>{if(Zt===Xt){Ht(!0);return}Bt(!0)}}):(0,S.jsx)(Oe,{size:18})}):void 0,headerRight:(0,S.jsx)(`div`,{className:`header-right-actions`,children:m&&(0,S.jsx)(`button`,{className:`btn btn-icon`,onClick:()=>N(!0),title:G(`chat.channelSettings`),children:(0,S.jsx)(Be,{size:16})})}),children:[m?(0,S.jsxs)(S.Fragment,{children:[ar&&(0,S.jsxs)(`button`,{type:`button`,className:`chat-voice-banner`,onClick:sr,title:G(`chat.voice.expand`),children:[(0,S.jsx)(`span`,{className:`chat-voice-banner-icon`,children:(0,S.jsx)(ge,{size:18})}),(0,S.jsx)(`span`,{className:`chat-voice-banner-label`,children:or}),(0,S.jsx)(ce,{size:18})]}),(0,S.jsxs)(`div`,{className:`chat-messages`,children:[X.length===0?(0,S.jsxs)(`div`,{className:`ui-empty-state chat-messages-empty`,children:[(0,S.jsx)(`div`,{className:`ui-empty-icon empty-icon`,children:(0,S.jsx)(me,{size:28})}),(0,S.jsx)(`p`,{children:G(`chat.empty.noMessages`)})]}):X.map(e=>{if(vt(e))return(0,S.jsx)(qe,{children:G(`chat.system.memberJoined`,{name:Vn(e)})},e.id||`${e.author}-${e.timestamp}`);let t=e.author?.toLowerCase()===a?.address.toLowerCase(),n=Cn.get(A(e.author)),r=Sn.get(A(e.author)),i=Tn.has(A(e.author)),o=n?.avatar||r?.avatar||e.avatar||(t?a.avatar:void 0),s=Vn(e);return(0,S.jsx)(Je,{variant:t?`self`:`other`,pending:e.pending,isOnline:i,avatarSrc:Se(e.author,o),author:s,time:ln(e.timestamp),children:Yn(e)},e.id||`${e.author}-${e.timestamp}`)}),(0,S.jsx)(`div`,{ref:Qt})]}),(0,S.jsx)(Ze,{message:Ce,placeholder:G(a?`chat.composer.placeholder`:`chat.composer.signInPlaceholder`),disabled:!a,isPublishingAttachment:Ft,attachmentInputRef:$t,attachmentMenuClassName:er,showVoiceRoom:!z,onMessageChange:ke,onSend:Ln,onOpenVoiceRoom:sr,onSelectAttachmentFiles:e=>{zn(e)}})]}):Qn?(0,S.jsxs)(`div`,{className:`ui-empty-state chat-welcome`,children:[(0,S.jsx)(`div`,{className:`ui-empty-icon ui-empty-icon-lg welcome-icon`,children:(0,S.jsx)(de,{size:36,className:`ui-spinner`})}),(0,S.jsx)(`h2`,{className:`ui-empty-title`,children:G(`chat.restoring.title`)}),(0,S.jsx)(`p`,{className:`ui-empty-desc`,children:G(`chat.restoring.desc`)})]}):(0,S.jsx)(S.Fragment,{children:(0,S.jsxs)(`div`,{className:`ui-empty-state chat-welcome`,children:[(0,S.jsx)(`div`,{className:`ui-empty-icon ui-empty-icon-lg welcome-icon`,children:(0,S.jsx)(me,{size:36})}),(0,S.jsx)(`h2`,{className:`ui-empty-title`,children:G(`chat.select.title`)}),(0,S.jsx)(`p`,{className:`ui-empty-desc`,children:G(`chat.select.desc`)}),(0,S.jsx)(re,{label:G(`chat.openChannelList`)})]})}),Re&&(0,S.jsx)(_e,{title:G(`chat.joinChannel`),placeholder:G(`chat.join.placeholder`),confirmText:G(`chat.join.confirm`),validate:En,onConfirm:Fn,onClose:()=>ze.close(),isLoading:w,loadingText:G(`chat.join.joining`)}),j&&(0,S.jsx)(_e,{title:G(`chat.renameChannel`),placeholder:G(`chat.remark.placeholder`),defaultValue:j.remark||``,confirmText:G(`chat.remark.save`),onConfirm:Jn,onClose:()=>{jt||M(null)},isLoading:jt,loadingText:G(`chat.remark.saving`),allowEmpty:!0,validate:e=>e.length>50?G(`chat.remark.tooLong`):``}),st&&D&&(0,S.jsx)(Ee,{title:G(`chat.leaveChannel`),message:G(`chat.leaveConfirm`,{channel:O(D)}),confirmText:G(Qe?`chat.leaving`:`chat.leaveChannel`),onConfirm:()=>Nn(E(D),void 0),danger:!0,onClose:()=>{ht.close(),k(null)}}),I&&(0,S.jsx)(xe,{onClose:()=>L(null),children:(0,S.jsxs)(`div`,{className:`confirm-modal`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`modal-header`,children:[(0,S.jsx)(`h3`,{children:G(`chat.attachment.noSeedsTitle`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-icon`,onClick:()=>L(null),"aria-label":G(`common.close`),children:(0,S.jsx)(ye,{size:18})})]}),(0,S.jsx)(`p`,{children:P[I.cid]?.message||G(`chat.attachment.noSeedsFallback`)}),(0,S.jsxs)(`div`,{className:`modal-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,onClick:()=>L(null),children:G(`common.cancel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>An(I),disabled:P[I.cid]?.status===`checking`,children:P[I.cid]?.status===`checking`?G(`app.checking`):G(`chat.attachment.retryCheck`)})]})]})}),Nt&&(0,S.jsx)(ie,{item:Nt,isBackendReady:W,getFileDownloadUrl:y.getFileDownloadUrl,onSaveAs:On,onClose:()=>Pt(null)}),Ot&&m&&(0,S.jsx)(`div`,{className:`channel-detail-overlay`,onClick:()=>N(!1),children:(0,S.jsxs)(`div`,{className:`channel-detail-drawer`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`channel-detail-header`,children:[(0,S.jsx)(`h3`,{children:G(`chat.details.title`)}),(0,S.jsx)(`button`,{className:`btn btn-icon`,onClick:()=>N(!1),children:(0,S.jsx)(ye,{size:18})})]}),(0,S.jsxs)(`div`,{className:`channel-detail-body`,children:[(0,S.jsxs)(`div`,{className:`channel-detail-section channel-members-section`,children:[(0,S.jsx)(`div`,{className:`channel-detail-label`,children:(0,S.jsx)(`span`,{children:G(`chat.details.members`,{count:wn.length})})}),Zn()]}),Kt&&(0,S.jsx)(`div`,{className:`channel-detail-section`,children:(0,S.jsxs)(`a`,{className:`btn btn-primary btn-block`,href:Kt,target:`_blank`,rel:`noreferrer`,children:[(0,S.jsx)(le,{size:16}),G(`chat.ticket.create`)]})}),!z&&(0,S.jsx)(`div`,{className:`channel-detail-section`,children:(0,S.jsxs)(`label`,{className:`setting-switch`,children:[(0,S.jsx)(`span`,{children:G(`chat.details.showAddressSuffix`)}),(0,S.jsx)(`input`,{type:`checkbox`,checked:Lt,onChange:e=>Rt(e.target.checked)})]})}),!z&&(0,S.jsxs)(`div`,{className:`channel-detail-section`,children:[(0,S.jsxs)(`div`,{className:`channel-detail-label`,children:[(0,S.jsx)(Le,{size:14}),(0,S.jsx)(`span`,{children:G(`chat.details.channelId`)})]}),(0,S.jsx)(`div`,{className:`ui-meta-box channel-detail-value channel-detail-mono`,translate:`no`,children:gt(m)})]}),!z&&(0,S.jsxs)(`div`,{className:`channel-detail-section`,children:[(0,S.jsxs)(`div`,{className:`channel-detail-label`,children:[(0,S.jsx)(ae,{size:14}),(0,S.jsx)(`span`,{children:G(`chat.remark.placeholder`)})]}),(0,S.jsx)(`input`,{type:`text`,className:`input input-compact`,placeholder:G(`chat.remark.placeholder`),value:kt,onChange:e=>At(e.target.value),onFocus:()=>At(m.remark||``),onBlur:()=>qn(),onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},maxLength:50})]}),(0,S.jsxs)(`div`,{className:`channel-detail-section`,children:[(0,S.jsxs)(`div`,{className:`channel-detail-label`,children:[(0,S.jsx)(Ie,{size:14}),(0,S.jsx)(`span`,{children:G(`chat.channel.createdAt`)})]}),(0,S.jsx)(`div`,{className:`ui-meta-box channel-detail-value`,children:m.createdAt?cn(m.createdAt):`-`})]}),!z&&(0,S.jsxs)(`div`,{className:`channel-detail-section`,children:[(0,S.jsx)(`div`,{className:`channel-detail-label`,children:(0,S.jsx)(`span`,{children:G(`chat.noteDraft.settingsTitle`)})}),(0,S.jsx)(`p`,{className:`channel-detail-hint`,children:G(`chat.noteDraft.saveAllDesc`)}),(0,S.jsx)(`button`,{className:`btn btn-secondary btn-block`,onClick:Gn,children:G(`chat.noteDraft.saveAll`)})]})]}),!z&&(0,S.jsx)(`div`,{className:`channel-detail-footer`,children:(0,S.jsx)(`button`,{className:`btn btn-secondary btn-block`,onClick:()=>{N(!1),k(m),ht.open()},children:G(`chat.leaveChannel`)})})]})})]})}var M=a(`/chat/`)({component:j});export{M as Route};
@@ -1 +0,0 @@
1
- import{n as e,o as t,t as n}from"./jsx-runtime-Bt-cYkS5.js";import{D as r,E as i,H as a,a as o,d as s,m as c,p as l,r as u,t as d}from"./useAppStore-DNhyhD20.js";import{a as f,i as p}from"./i18n-C6yaqRst.js";import{t as m}from"./circle-alert-DXVkx8p8.js";import{t as h}from"./refresh-cw-CfkUlTK9.js";import{L as g,r as _}from"./index-D1mozno-.js";import{t as v}from"./channelApi-C5eHetoJ.js";import{r as y,t as b}from"./chatJoinInvite-CeC6H6t8.js";var x=t(e(),1),S=n();function C({children:e,className:t=``}){return(0,S.jsx)(`main`,{className:t,children:e})}function w(e){return String(e||``).trim().replace(/\/+$/,``)}function T(e){return String(e||``).trim()}function E({inviteNodeUrl:e,inviteNodeInvite:t,hasBackend:n,activeBackendUrl:r,activeRemoteUrl:i,activeRemoteInvite:a}){let o=w(e),s=w(i),c=w(r);return!!o&&!!s&&n===!0&&c===s&&s===o&&T(a)===T(t)}function D(e){return!!w(e.inviteNodeUrl)&&!E(e)}var O=`data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"%3E%3Crect width="64" height="64" rx="16" fill="%232f7dd1"/%3E%3Ccircle cx="32" cy="25" r="11" fill="%23f8fbff"/%3E%3Cpath d="M14 56c3-12 12-18 18-18s15 6 18 18" fill="%23f8fbff"/%3E%3C/svg%3E`,k=`data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"%3E%3Crect width="64" height="64" rx="16" fill="%230f9f7a"/%3E%3Cpath d="M18 20h28v22H18z" rx="6" fill="%23f7fff9"/%3E%3Ccircle cx="27" cy="31" r="3" fill="%230f9f7a"/%3E%3Ccircle cx="37" cy="31" r="3" fill="%230f9f7a"/%3E%3Cpath d="M29 39h6" stroke="%230f9f7a" stroke-width="4" stroke-linecap="round"/%3E%3Cpath d="M32 12v8" stroke="%23f7fff9" stroke-width="5" stroke-linecap="round"/%3E%3C/svg%3E`,A=Object.freeze({id:`chatjoin_support`,name:`User / Service 测试频道`}),j=Object.freeze([Object.freeze({uid:`user`,theme:`sparkbit`,name:`测试用户`,avatar:O}),Object.freeze({uid:`service`,name:`测试客服`,avatar:k})]),M=Object.freeze(j.map(e=>Object.freeze({locale:`zh-CN`,uid:e.uid,theme:e.theme,avatar:e.avatar,name:e.name,channels:[A]})));function N(e){let t=String(e||``).trim();return M.find(e=>e.uid===t)||null}var P=50,F=b;function I(e){try{return JSON.parse(e)}catch{return null}}function L(e,t,n){if(t&&typeof t==`object`&&`error`in t){let e=t.error;if(typeof e==`string`)return e}return e||n}function R(e){return`/chat?channel=${encodeURIComponent(e)}`}function z(e){return String(e||``).trim().slice(0,P)}function B(){let{t:e,setLocale:t}=f(),n=g({select:e=>e.searchStr}),{token:a,pub:b,fixture:w}=(0,x.useMemo)(()=>{let e=new URLSearchParams(n);return{token:e.get(`token`)||``,pub:e.get(`pub`)||``,fixture:e.get(`fixture`)||``}},[n]),T=d(e=>e.hasBackend),E=d(e=>e.setIsDarkMode),O=i(e=>e.setUserIdentity),[k,A]=(0,x.useState)(``),[j,M]=(0,x.useState)(!0),[P,B]=(0,x.useState)(0),V=(0,x.useRef)(``);function H(){V.current=``,A(``),M(!0),B(e=>e+1)}return(0,x.useEffect)(()=>{let n=N(w);if(w&&!n){A(e(`chatJoin.error.unknownFixture`,{fixture:w})),M(!1);return}if(!n&&!a){A(e(`chatJoin.error.missingToken`)),M(!1);return}if(!n&&!b){A(e(`chatJoin.error.missingPub`)),M(!1);return}if(T===null)return;let i=n?`fixture:${w}`:`${a}:${b}`;if(V.current===i)return;V.current=i;async function f(n){let i=(t,r)=>n.locale?p(t,n.locale,r):e(t,r);n.locale&&t(n.locale),n.appearance===`dark`&&E(!0),n.appearance===`light`&&E(!1);let a=c(),f=l(),m=s();if(D({inviteNodeUrl:n.node_url,inviteNodeInvite:n.node_invite,hasBackend:T,activeBackendUrl:m,activeRemoteUrl:a,activeRemoteInvite:f})){if(!(await u({url:n.node_url,invite:n.node_invite||``})).ok)throw Error(i(`chatJoin.error.remoteConnectFailed`));o({url:n.node_url,invite:n.node_invite||``}),d.setState({hasBackend:!0})}else if(!T)throw Error(i(`chatJoin.error.noBackend`));let h=r(n.uid,``),g={...h,theme:n.theme,displayName:n.name||h.displayName,logo:n.logo,logo_dark:n.logo_dark,data:n.data,avatar:n.avatar};O(g);let y=``;for(let e of n.channels){let t=await v.createChannel(e.id,`public`,_(g)),n=t.channelKey||t.key||e.id;y||=n;let r=z(e.name);r&&await v.setChannelRemark(n,r)}let b=n.channels[0];window.location.href=R(y||b.id)}async function m(){try{if(n){await f(n);return}let t=await fetch(`${F}/api/chat.join.decrypt`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:a,pub:b})}),r=await t.text(),i=I(r);if(!t.ok)A(L(r,i,e(`chatJoin.error.decrypt`)));else{let t=y(i);if(!t){A(e(`chatJoin.error.invalidInvite`));return}await f(t)}}catch(t){A(e(`chatJoin.error.request`,{message:t instanceof Error?t.message:String(t)}))}finally{M(!1)}}m()},[w,T,b,P,E,t,O,e,a]),(0,S.jsx)(C,{className:`chat-join-loading-page`,children:(0,S.jsx)(`div`,{className:`chat-join-loading-panel`,children:j?(0,S.jsx)(`div`,{className:`chat-join-loading`,children:(0,S.jsx)(`span`,{className:`chat-join-status-spinner`,"aria-hidden":`true`})}):k?(0,S.jsxs)(`div`,{className:`chat-join-error`,children:[(0,S.jsx)(m,{size:32}),(0,S.jsx)(`p`,{children:k}),(0,S.jsx)(`div`,{className:`chat-join-actions`,children:(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary`,onClick:H,children:[(0,S.jsx)(h,{size:16}),e(`chatJoin.action.retry`)]})})]}):(0,S.jsx)(`div`,{className:`chat-join-success`,children:(0,S.jsx)(`span`,{className:`chat-join-status-spinner`,"aria-hidden":`true`})})})})}function V(){return(0,S.jsx)(x.Suspense,{children:(0,S.jsx)(B,{})})}var H=a(`/chat/join/`)({component:V});export{H as Route};
@@ -1,4 +0,0 @@
1
- import{n as e,o as t}from"./jsx-runtime-Bt-cYkS5.js";import{E as n,u as r}from"./useAppStore-DNhyhD20.js";import{a as i}from"./index-D1mozno-.js";import{t as a}from"./channelApi-C5eHetoJ.js";var o=t(e(),1);function s(e=``,t=[]){let n=[e,...t];return[...new Set(n.filter(Boolean))]}function c(e=[]){return s(``,e).join(`
2
- `)}function l(e,t){let n=new Set(e),r=new Set(t);return{subscribe:[...r].filter(e=>!n.has(e)),unsubscribe:[...n].filter(e=>!r.has(e))}}var ee=15*1e3;function te(e){return String(e.id||`${e.author||``}-${e.timestamp||``}-${e.content||``}`)}function u(e){let t=Number(e.timestamp);return Number.isFinite(t)?t:0}function d(e){return e.map((e,t)=>({message:e,index:t})).sort((e,t)=>{let n=u(e.message)-u(t.message);return n===0?e.index-t.index:n}).map(e=>e.message)}function ne(){return`presence-${Date.now()}-${Math.random().toString(36).slice(2)}`}function f({isReady:e,enabled:t=!0,channelName:u=``,extraSubscribedChannelNames:f=[],peerId:p=``,waitForPeerId:m=!1,limit:h=100,reconnectBaseDelay:g=2500,acceptMessage:_,getMessageKey:v=te,onSyncError:y,onSocketEvent:b,onReconnect:x,presenceEnabled:S=!1,presenceProfile:C={}}){let w=n(e=>e.identity),[re,T]=(0,o.useState)([]),[E,D]=(0,o.useState)(!1),O=(0,o.useMemo)(()=>c(f),[f]),k=(0,o.useRef)(null),A=(0,o.useRef)(u),j=(0,o.useRef)(f),M=(0,o.useRef)(null),N=(0,o.useRef)(0),P=(0,o.useRef)(_),F=(0,o.useRef)(v),I=(0,o.useRef)(b),L=(0,o.useRef)(y),R=(0,o.useRef)(x),z=(0,o.useRef)(p),B=(0,o.useRef)(new Set),V=(0,o.useRef)(S),H=(0,o.useRef)(C),U=(0,o.useRef)(ne()),W=(0,o.useRef)(``);(0,o.useEffect)(()=>{j.current=O?O.split(`
3
- `):[]},[O]),(0,o.useEffect)(()=>{P.current=_},[_]),(0,o.useEffect)(()=>{F.current=v},[v]),(0,o.useEffect)(()=>{I.current=b},[b]),(0,o.useEffect)(()=>{L.current=y},[y]),(0,o.useEffect)(()=>{R.current=x},[x]),(0,o.useEffect)(()=>{V.current=S},[S]),(0,o.useEffect)(()=>{H.current=C},[C]);let G=(0,o.useCallback)(e=>{let t=P.current;return t?e.filter(t):e},[]),K=(0,o.useCallback)((e,t,n=!0)=>{let r=[...e];for(let e of G(t)){let t=F.current(e);if(n){let n=r.findIndex(t=>t.pending&&t.author?.toLowerCase()===e.author?.toLowerCase()&&t.content===e.content);if(n!==-1){r[n]={...e,id:e.id||t};continue}}r.some(e=>F.current(e)===t)||r.push({...e,id:e.id||t})}return d(r)},[G]),q=(0,o.useCallback)((e,t)=>{k.current?.readyState===WebSocket.OPEN&&k.current.send(JSON.stringify({event:e,data:t}))},[]),J=(0,o.useCallback)(e=>({channel:e,sessionId:U.current,...H.current}),[]),Y=(0,o.useCallback)((e=W.current)=>{e&&(q(`channel:presence:leave`,{channel:e,sessionId:U.current}),W.current===e&&(W.current=``))},[q]),X=(0,o.useCallback)(e=>{!e||!V.current||!w||(q(`channel:presence:join`,J(e)),W.current=e)},[J,w,q]),Z=(0,o.useCallback)(e=>{let t=new Set(e.filter(Boolean)),n=l(B.current,t);for(let e of n.unsubscribe)q(`channel:unsubscribe`,{channel:e});for(let e of n.subscribe)q(`channel:subscribe`,{channel:e});B.current=t},[q]),Q=(0,o.useCallback)(()=>s(A.current,j.current),[]),$=(0,o.useCallback)(async(t=A.current,n={})=>{if(!t||!e)return[];try{let e=G(await a.getChannelMessages(t,h));return T(t=>n.replace?d(e):K(t,e,!1)),e}catch(e){return n.replace&&T([]),await L.current?.(e),[]}},[G,e,h,K]);(0,o.useEffect)(()=>{z.current=p,p&&(q(`register`,{peerId:p}),m&&(Z(Q()),A.current&&$(A.current,{replace:!0})))},[Q,p,Z,$,m,q]);let ie=(0,o.useCallback)(()=>{T([])},[]),ae=(0,o.useCallback)(async({channelName:e=A.current,content:t,attachment:n,optimisticId:r})=>{let o=t.trim();if(!e||!o||!w)return null;let s=i(w),c={id:r||`${s.author}-${Date.now()}-${Math.random().toString(36).slice(2)}`,...s,content:o,timestamp:Date.now(),pending:!0,attachment:n};T(e=>d([...e,c]));try{let t=await a.sendChannelMessage({channelName:e,content:o,...s,attachment:n});return T(e=>d(e.map(e=>e.id===c.id?{...t.message,id:t.message.id||F.current(t.message)}:e))),t.message}catch(e){throw T(e=>e.filter(e=>e.id!==c.id)),e}},[w]);return(0,o.useEffect)(()=>{A.current=u,!(!e||!t)&&(u&&$(u,{replace:!0}),(!m||z.current)&&Z(Q()))},[u,t,O,Q,e,Z,$,m]),(0,o.useEffect)(()=>{if(!E||!S||!w||!u){Y();return}let e=W.current;e&&e!==u&&Y(e),W.current!==u&&X(u)},[u,E,X,Y,S,w]),(0,o.useEffect)(()=>{let e=W.current;!E||!S||!e||!w||q(`channel:presence:profile`,J(e))},[E,J,S,(0,o.useMemo)(()=>[C.displayName||``,C.avatar||``,C.profileUpdatedAt||``].join(`
4
- `),[C.avatar,C.displayName,C.profileUpdatedAt]),w,q]),(0,o.useEffect)(()=>{if(!E||!S||!w)return;let e=window.setInterval(()=>{let e=W.current;e&&q(`channel:presence:heartbeat`,{channel:e,sessionId:U.current})},ee);return()=>window.clearInterval(e)},[E,S,w,q]),(0,o.useEffect)(()=>{!e||!t||m&&!z.current||Z(Q())},[t,Q,e,Z,m]),(0,o.useEffect)(()=>{if(!e||!t){D(!1);return}let n=!1;N.current=0;async function i(){let e=new WebSocket(await r(`/ws`));if(n){e.close();return}e.onopen=()=>{D(!0),N.current=0,z.current&&e.send(JSON.stringify({event:`register`,data:{peerId:z.current}})),(!m||z.current)&&(B.current.clear(),Z(Q()),A.current&&$(A.current,{replace:!0}),R.current?.())},e.onmessage=e=>{try{let t=JSON.parse(e.data);I.current?.(t.event,t.data),t.event===`channel:message`&&t.data?.channel===A.current&&t.data?.message&&T(e=>K(e,[t.data.message])),t.event===`user:metadata:updated`&&t.data?.scope===`channels`&&A.current&&$(A.current,{replace:!0})}catch{}},e.onclose=()=>{if(D(!1),W.current=``,n)return;let e=N.current;if(e>=20)return;let t=Math.min(g*2**e,3e4);N.current=e+1,M.current=setTimeout(i,t)},e.onerror=()=>e.close(),k.current=e}return i(),()=>{n=!0,M.current&&clearTimeout(M.current),Y(),k.current?.close(),k.current=null,B.current.clear()}},[t,Q,e,Y,K,g,Z,$,m]),{clearMessages:ie,connected:E,messages:re,sendMessage:ae,setMessages:T,syncMessages:$}}export{f as t};