@webinex/chatify 2.0.0-alpha4 → 2.0.0-alpha8

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.
@@ -84,7 +84,7 @@
84
84
  max-width: 100%;
85
85
  }
86
86
  .wxchtf-aside .wxchtf-chat-list.ant-menu .ant-menu-item .wxchtf-chat .wxchtf-chat-info {
87
- min-width: 1;
87
+ min-width: 0;
88
88
  }
89
89
  .wxchtf-aside .wxchtf-chat-list.ant-menu .ant-menu-item .wxchtf-chat .wxchtf-chat-name {
90
90
  display: inline-block;
@@ -159,13 +159,13 @@
159
159
  flex: auto;
160
160
  display: flex;
161
161
  flex-flow: row nowrap;
162
- min-width: 1;
162
+ min-width: 0;
163
163
  }
164
164
  .wxchtf-chatify .wxchtf-conversation {
165
165
  flex: auto;
166
166
  display: flex;
167
167
  flex-flow: row nowrap;
168
- min-width: 1;
168
+ min-width: 0;
169
169
  }
170
170
  .wxchtf-chatify .wxchtf-conversation .wxchtf-conversation-main {
171
171
  flex: 1;
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as a from"react";import s,{useContext as i,useState as c,useMemo as r,forwardRef as o,useCallback as d,useRef as l,useEffect as u,memo as h,useLayoutEffect as m}from"react";import{Button as g,Avatar as f,List as v,Tooltip as y,Space as p,Input as b,Skeleton as w,Row as C,Col as x,Form as M,Checkbox as I,Menu as N}from"antd";import O from"@ant-design/icons/SendOutlined";import R from"@ant-design/icons/PaperClipOutlined";import _ from"@ant-design/icons/UserAddOutlined";import S from"@ant-design/icons/UsergroupAddOutlined";import T from"@ant-design/icons/UserDeleteOutlined";import k from"@ant-design/icons/UsergroupDeleteOutlined";import L from"@ant-design/icons/TeamOutlined";import E from"@ant-design/icons/EditOutlined";import j from"@ant-design/icons/CloseOutlined";import F from"@ant-design/icons/EyeInvisibleOutlined";import B from"@ant-design/icons/EyeOutlined";import D from"@ant-design/icons/DeleteOutlined";import A from"@ant-design/icons/DownloadOutlined";import{createApi as q,fakeBaseQuery as U}from"@reduxjs/toolkit/query/react";import*as Q from"@microsoft/signalr";import G from"is-hotkey";import P from"dayjs";const V={saturation:100,lightness:75};function z(e,t={}){t=Object.assign({},V,t);let n=0;for(let t=0;t<e.length;t++)n=e.charCodeAt(t)+((n<<5)-n),n&=n;return`hsl(${n%360}, ${t.saturation}%, ${t.lightness}%)`}const $=s.createContext(null);function H(){return i($)}function K(e){const t=i($);return t?t[e]:void 0}function W(e){const t=K(e.key);return null==t?null:null!=t?t:e.Component}function Y(t,n){const a=s.forwardRef(((a,s)=>{const i=K(t);return null===i?null:e(i||n,Object.assign({},a,{ref:s}))}));return n.displayName=n.displayName||t,a.displayName="Customizable."+n.displayName,Object.assign(a,{key:t,Component:n})}const J={attach:R,send:O,"remove-member":T,"remove-member-delete-history":k,"add-member":_,"add-member-with-history":S,members:L,edit:E,close:j,chat:L,watch:B,unwatch:F,"delete-file":D,"open-file":A},X=Y("Icon",(t=>{const{type:n}=t,a=J[n];return a?e(a,{}):null})),Z=s.createContext(null);function ee(){return i(Z)}function te(t){const{id:n,children:a}=t,[s,i]=c(!1),o=r((()=>({id:n,showMembers:s,onShowMembers:i})),[n,s]);return e(Z.Provider,{value:o,children:a})}const ne=Y("ChatMembersButton",(()=>{const{showMembers:t,onShowMembers:n}=ee();return e(g,{onClick:()=>n(!t),type:"link",icon:e(X,{type:"members"})})})),ae="chatify::system";function se(e){return e.slice(0,36)}function ie(e){const[t,n]=e.split("::",2);return[t,parseInt(n,10)]}function ce(e){var t,n;const a=null!=e.lastReadMessageId?ie(e.lastReadMessageId)[1]:-1;return(null!=(null===(t=e.lastMessage)||void 0===t?void 0:t.id)?ie(null===(n=e.lastMessage)||void 0===n?void 0:n.id)[1]:-1)-a}function re(e){return e.reduce(((e,t)=>e+ce(t)),0)}function oe(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(a=Object.getOwnPropertySymbols(e);s<a.length;s++)t.indexOf(a[s])<0&&Object.prototype.propertyIsEnumerable.call(e,a[s])&&(n[a[s]]=e[a[s]])}return n}function de(e,t,n,a){return new(n||(n=Promise))((function(s,i){function c(e){try{o(a.next(e))}catch(e){i(e)}}function r(e){try{o(a.throw(e))}catch(e){i(e)}}function o(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,r)}o((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class le{constructor(e){this.config=e,this._enqueued=[],this._processing=[],this._timeoutByGroup={},this._subscribers=[],this.subscribe=e=>(this._subscribers.push(e),()=>{this._subscribers=this._subscribers.filter((t=>t!==e))}),this.notify=()=>{this._subscribers.forEach((e=>e(this)))}}get units(){return[...this._enqueued.map((e=>Object.assign(Object.assign({},e),{state:"enqueued"}))),...this._processing.map((e=>Object.assign(Object.assign({},e),{state:"processing"})))]}push(e){const t=this.config.groupBy(e),n=this._enqueued.find((e=>this.config.groupBy(e.value)===t));n?this.config.compare(n.value,e)>=0&&(n.value=e,n.enqueueTime=Date.now()):this._enqueued.push({value:e,enqueueTime:Date.now()}),this._process(t)}_process(e){if(!this._enqueued.some((t=>this.config.groupBy(t.value)===e)))return;let t=this._timeoutByGroup[e];t&&clearTimeout(t),this._processing.some((t=>this.config.groupBy(t.value)===e))||(t=setTimeout((()=>{const t=this._enqueued.find((t=>this.config.groupBy(t.value)===e));this._processing.push(t),this._enqueued.splice(this._enqueued.indexOf(t),1),this.notify(),this.config.callback(t.value).then((()=>{this._processing.splice(this._processing.indexOf(t),1),this.notify(),this._process(e)})).catch((()=>{this._processing.splice(this._processing.indexOf(t),1),this.push(t.value)}))}),this.config.timeout),this._timeoutByGroup[e]=t)}}const ue=20;new le({callback:e=>he.client.readChatMessage({id:e}),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>se(e),timeout:500});const he={me:null,client:null},me=q({baseQuery:U(),reducerPath:"chatify",tagTypes:["chat","account","message","thread","thread-message"],endpoints:e=>({})});var ge,fe={exports:{}},ve={};var ye,pe={};
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as a from"react";import s,{useContext as i,useState as c,useMemo as r,forwardRef as o,useCallback as d,useRef as l,useEffect as u,memo as h,useLayoutEffect as m}from"react";import{Button as g,Avatar as f,List as v,Tooltip as y,Space as p,Input as b,Skeleton as w,Row as C,Col as x,Form as M,Checkbox as I,Menu as N}from"antd";import O from"@ant-design/icons/SendOutlined";import R from"@ant-design/icons/PaperClipOutlined";import _ from"@ant-design/icons/UserAddOutlined";import S from"@ant-design/icons/UsergroupAddOutlined";import T from"@ant-design/icons/UserDeleteOutlined";import k from"@ant-design/icons/UsergroupDeleteOutlined";import L from"@ant-design/icons/TeamOutlined";import E from"@ant-design/icons/EditOutlined";import j from"@ant-design/icons/CloseOutlined";import F from"@ant-design/icons/EyeInvisibleOutlined";import A from"@ant-design/icons/EyeOutlined";import B from"@ant-design/icons/DeleteOutlined";import D from"@ant-design/icons/DownloadOutlined";import{createApi as q,fakeBaseQuery as U}from"@reduxjs/toolkit/query/react";import*as Q from"@microsoft/signalr";import G from"is-hotkey";import P from"dayjs";const V={saturation:100,lightness:75};function $(e,t={}){t=Object.assign({},V,t);let n=0;for(let t=0;t<e.length;t++)n=e.charCodeAt(t)+((n<<5)-n),n&=n;return`hsl(${n%360}, ${t.saturation}%, ${t.lightness}%)`}const z=s.createContext(null);function H(){return i(z)}function K(e){const t=i(z);return t?t[e]:void 0}function W(e){const t=K(e.key);return null==t?null:null!=t?t:e.Component}function Y(t,n){const a=s.forwardRef(((a,s)=>{const i=K(t);return null===i?null:e(i||n,Object.assign({},a,{ref:s}))}));return n.displayName=n.displayName||t,a.displayName="Customizable."+n.displayName,Object.assign(a,{key:t,Component:n})}const J={attach:R,send:O,"remove-member":T,"remove-member-delete-history":k,"add-member":_,"add-member-with-history":S,members:L,edit:E,close:j,chat:L,watch:A,unwatch:F,"delete-file":B,"open-file":D},X=Y("Icon",(t=>{const{type:n}=t,a=J[n];return a?e(a,{}):null})),Z=s.createContext(null);function ee(){return i(Z)}function te(t){const{id:n,children:a}=t,[s,i]=c(!1),o=r((()=>({id:n,showMembers:s,onShowMembers:i})),[n,s]);return e(Z.Provider,{value:o,children:a})}const ne=Y("ChatMembersButton",(()=>{const{showMembers:t,onShowMembers:n}=ee();return e(g,{onClick:()=>n(!t),type:"link",icon:e(X,{type:"members"})})})),ae="chatify::system";function se(e){return e.slice(0,36)}function ie(e){const[t,n]=e.split("::",2);return[t,parseInt(n,10)]}function ce(e){var t,n;const a=null!=e.lastReadMessageId?ie(e.lastReadMessageId)[1]:-1;return(null!=(null===(t=e.lastMessage)||void 0===t?void 0:t.id)?ie(null===(n=e.lastMessage)||void 0===n?void 0:n.id)[1]:-1)-a}function re(e){return e.reduce(((e,t)=>e+ce(t)),0)}function oe(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(a=Object.getOwnPropertySymbols(e);s<a.length;s++)t.indexOf(a[s])<0&&Object.prototype.propertyIsEnumerable.call(e,a[s])&&(n[a[s]]=e[a[s]])}return n}function de(e,t,n,a){return new(n||(n=Promise))((function(s,i){function c(e){try{o(a.next(e))}catch(e){i(e)}}function r(e){try{o(a.throw(e))}catch(e){i(e)}}function o(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,r)}o((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class le{constructor(e){this.config=e,this._enqueued=[],this._processing=[],this._timeoutByGroup={},this._subscribers=[],this.subscribe=e=>(this._subscribers.push(e),()=>{this._subscribers=this._subscribers.filter((t=>t!==e))}),this.notify=()=>{this._subscribers.forEach((e=>e(this)))}}get units(){return[...this._enqueued.map((e=>Object.assign(Object.assign({},e),{state:"enqueued"}))),...this._processing.map((e=>Object.assign(Object.assign({},e),{state:"processing"})))]}push(e){const t=this.config.groupBy(e),n=this._enqueued.find((e=>this.config.groupBy(e.value)===t));n?this.config.compare(n.value,e)>=0&&(n.value=e,n.enqueueTime=Date.now()):this._enqueued.push({value:e,enqueueTime:Date.now()}),this._process(t)}_process(e){if(!this._enqueued.some((t=>this.config.groupBy(t.value)===e)))return;let t=this._timeoutByGroup[e];t&&clearTimeout(t),this._processing.some((t=>this.config.groupBy(t.value)===e))||(t=setTimeout((()=>{const t=this._enqueued.find((t=>this.config.groupBy(t.value)===e));this._processing.push(t),this._enqueued.splice(this._enqueued.indexOf(t),1),this.notify(),this.config.callback(t.value).then((()=>{this._processing.splice(this._processing.indexOf(t),1),this.notify(),this._process(e)})).catch((()=>{this._processing.splice(this._processing.indexOf(t),1),this.push(t.value)}))}),this.config.timeout),this._timeoutByGroup[e]=t)}}const ue=20;new le({callback:e=>he.client.readChatMessage({id:e}),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>se(e),timeout:500});const he={me:null,client:null},me=q({baseQuery:U(),reducerPath:"chatify",tagTypes:["chat","account","message","thread","thread-message"],endpoints:e=>({})});var ge,fe={exports:{}},ve={};var ye,pe={};
2
2
  /**
3
3
  * @license React
4
4
  * use-sync-external-store-with-selector.development.js
@@ -7,5 +7,5 @@ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as a from
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */"production"===process.env.NODE_ENV?fe.exports=function(){if(ge)return ve;ge=1;var e=s,t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=e.useSyncExternalStore,a=e.useRef,i=e.useEffect,c=e.useMemo,r=e.useDebugValue;return ve.useSyncExternalStoreWithSelector=function(e,s,o,d,l){var u=a(null);if(null===u.current){var h={hasValue:!1,value:null};u.current=h}else h=u.current;u=c((function(){function e(e){if(!i){if(i=!0,n=e,e=d(e),void 0!==l&&h.hasValue){var s=h.value;if(l(s,e))return a=s}return a=e}if(s=a,t(n,e))return s;var c=d(e);return void 0!==l&&l(s,c)?s:(n=e,a=c)}var n,a,i=!1,c=void 0===o?null:o;return[function(){return e(s())},null===c?void 0:function(){return e(c())}]}),[s,o,d,l]);var m=n(e,u[0],u[1]);return i((function(){h.hasValue=!0,h.value=m}),[m]),r(m),m},ve}():fe.exports=(ye||(ye=1,"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=s,t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=e.useSyncExternalStore,a=e.useRef,i=e.useEffect,c=e.useMemo,r=e.useDebugValue;pe.useSyncExternalStoreWithSelector=function(e,s,o,d,l){var u,h=a(null);null===h.current?(u={hasValue:!1,value:null},h.current=u):u=h.current;var m=c((function(){var e,n,a=!1,i=function(s){if(!a){a=!0,e=s;var i=d(s);if(void 0!==l&&u.hasValue){var c=u.value;if(l(c,i))return n=c,c}return n=i,i}var r=n;if(t(e,s))return r;var o=d(s);return void 0!==l&&l(r,o)?r:(e=s,n=o,o)},c=void 0===o?null:o;return[function(){return i(s())},null===c?void 0:function(){return i(c())}]}),[s,o,d,l]),g=m[0],f=m[1],v=n(e,g,f);return i((function(){u.hasValue=!0,u.value=v}),[v]),r(v),v},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),pe);var be=fe.exports,we="default"in a?a.default:a,Ce=Symbol.for("react-redux-context"),xe="undefined"!=typeof globalThis?globalThis:{};function Me(){if(!we.createContext)return{};const e=xe[Ce]??(xe[Ce]=new Map);let t=e.get(we.createContext);return t||(t=we.createContext(null),"production"!==process.env.NODE_ENV&&(t.displayName="ReactRedux"),e.set(we.createContext,t)),t}var Ie=Me();function Ne(e=Ie){return function(){const t=we.useContext(e);if("production"!==process.env.NODE_ENV&&!t)throw new Error("could not find react-redux context value; please ensure the component is wrapped in a <Provider>");return t}}var Oe=Ne(),Re=()=>{throw new Error("uSES not initialized!")},_e=(e,t)=>e===t;function Se(e=Ie){const t=e===Ie?Oe:Ne(e),n=(e,n={})=>{const{equalityFn:a=_e,devModeChecks:s={}}="function"==typeof n?{equalityFn:n}:n;if("production"!==process.env.NODE_ENV){if(!e)throw new Error("You must pass a selector to useSelector");if("function"!=typeof e)throw new Error("You must pass a function as a selector to useSelector");if("function"!=typeof a)throw new Error("You must pass a function as an equality function to useSelector")}const{store:i,subscription:c,getServerState:r,stabilityCheck:o,identityFunctionCheck:d}=t(),l=we.useRef(!0),u=we.useCallback({[e.name](t){const n=e(t);if("production"!==process.env.NODE_ENV){const{identityFunctionCheck:i,stabilityCheck:c}={stabilityCheck:o,identityFunctionCheck:d,...s};if("always"===c||"once"===c&&l.current){const s=e(t);if(!a(n,s)){let a;try{throw new Error}catch(e){({stack:a}=e)}console.warn("Selector "+(e.name||"unknown")+" returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",{state:t,selected:n,selected2:s,stack:a})}}if(("always"===i||"once"===i&&l.current)&&n===t){let t;try{throw new Error}catch(e){({stack:t}=e)}console.warn("Selector "+(e.name||"unknown")+" returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",{stack:t})}l.current&&(l.current=!1)}return n}}[e.name],[e,o,s.stabilityCheck]),h=Re(c.addNestedSub,i.getState,r||i.getState,u,a);return we.useDebugValue(h),h};return Object.assign(n,{withTypes:()=>n}),n}var Te,ke=Se(),Le=!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement),Ee="undefined"!=typeof navigator&&"ReactNative"===navigator.product;Le||Ee?we.useLayoutEffect:we.useEffect,Te=be.useSyncExternalStoreWithSelector,Re=Te;const je={hubUri:"/api/chatify/hub",headersFactory:()=>Promise.resolve({})},Fe=["chatify://chat-new-message","chatify://chat-created","chatify://chat-message-read","chatify://chat-member-added","chatify://chat-member-removed","chatify://chat-name-changed","chatify://thread-created","chatify://thread-message-new","chatify://thread-message-read","chatify://thread-watch-added","chatify://thread-watch-removed"];class Be{constructor(e){this._connection=null,this._connectionPromise=null,this._subscribers={},this._reconnectSubscribers=[],this._threadConnectionByThreadId=new Map,this.connect=()=>de(this,void 0,void 0,(function*(){if(!this._connection){if(this._connectionPromise)return yield this._connectionPromise;this._connectionPromise=this.createAndStartConnection(),this._connection=yield this._connectionPromise}})),this.createAndStartConnection=()=>de(this,void 0,void 0,(function*(){const e=yield this._config.signalR.headersFactory(),t=(new Q.HubConnectionBuilder).withUrl(this._config.signalR.hubUri,{accessTokenFactory:this._config.signalR.accessTokenFactory?this._config.signalR.accessTokenFactory:void 0,headers:e}).withAutomaticReconnect().build();return Fe.forEach((e=>{t.on(e,((...t)=>{var n;null===(n=this._subscribers[e])||void 0===n||n.forEach((e=>{try{e(t)}catch(e){console.error("Failed to notify subscriber",e)}}))}))})),t.onreconnected((()=>this._reconnectSubscribers.forEach((e=>e())))),yield t.start(),t})),this.subscribe=(e,t)=>(this.connect().then((()=>{var n;this._subscribers[e]=null!==(n=this._subscribers[e])&&void 0!==n?n:[],this._subscribers[e].push(t)})),()=>this._subscribers[e].filter((e=>e!==t))),this.subscribeReconnect=e=>(this._reconnectSubscribers.push(e),()=>this._reconnectSubscribers.filter((t=>t!==e))),this.accounts=()=>de(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("account");return e})),this.chats=()=>de(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("chat");return e})),this.chat=e=>de(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.get(`chat/${encodeURIComponent(e)}`);return t})),this.addChat=e=>de(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.post("chat",e);return t})),this.chatMessages=e=>de(this,void 0,void 0,(function*(){const{chatId:t,skip:n=0,take:a=20}=e,s=encodeURIComponent(JSON.stringify({skip:n,take:a})),{data:i}=yield this.axios.get(`chat/${encodeURIComponent(t)}/message?pagingRule=${s}`);return i})),this.sendChatMessage=e=>de(this,void 0,void 0,(function*(){const{chatId:t}=e,n=oe(e,["chatId"]);yield this.axios.post(`chat/${encodeURIComponent(t)}/message`,n)})),this.readChatMessage=e=>de(this,void 0,void 0,(function*(){yield this.axios.put("chat/message/read",e)})),this.removeChatMember=e=>de(this,void 0,void 0,(function*(){yield this.axios.delete(`chat/${encodeURIComponent(e.chatId)}/member`,{data:e})})),this.updateChatName=e=>de(this,void 0,void 0,(function*(){yield this.axios.put(`chat/${encodeURIComponent(e.id)}/name`,e)})),this.addChatMember=e=>de(this,void 0,void 0,(function*(){yield this.axios.post(`chat/${encodeURIComponent(e.chatId)}/member`,e)})),this.sendThreadMessage=({body:e,threadId:t})=>de(this,void 0,void 0,(function*(){const{data:n}=yield this.axios.post(`thread/${encodeURIComponent(t)}/message`,{body:e});return n})),this.readThreadMessage=e=>de(this,void 0,void 0,(function*(){yield this.axios.put(`thread/message/${encodeURIComponent(e)}/read`)})),this.watchThreads=()=>de(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("thread/watch");return e})),this.thread=e=>de(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.get(`thread/${encodeURIComponent(e)}`);return t})),this.threadMessages=({threadId:e,skip:t,take:n})=>de(this,void 0,void 0,(function*(){const a=new URLSearchParams;a.append("skip",t.toString()),a.append("take",n.toString());const{data:s}=yield this.axios.get(`thread/${encodeURIComponent(e)}/message?${a.toString()}`);return s})),this.watchThread=(e,t)=>de(this,void 0,void 0,(function*(){yield this.axios.put(`thread/${encodeURIComponent(e)}/watch`,{watch:t})})),this.connectToThread=e=>de(this,void 0,void 0,(function*(){var t;const n=null!==(t=this._threadConnectionByThreadId.get(e))&&void 0!==t?t:0;this._threadConnectionByThreadId.set(e,n+1),0===n&&this.connect().then((()=>this._connection.invoke("ConnectToThread",e)))})),this.disconnectFromThread=e=>de(this,void 0,void 0,(function*(){var t;const n=null!==(t=this._threadConnectionByThreadId.get(e))&&void 0!==t?t:0;this._threadConnectionByThreadId.set(e,Math.max(0,n-1)),1===n&&this.connect().then((()=>this._connection.invoke("DisconnectFromThread",e)))})),this._config=Object.assign(Object.assign({},e),{signalR:Object.assign(Object.assign({},je),e.signalR)})}get axios(){return this._config.axios}}function De(...e){const t=()=>e.forEach((e=>e()));return t.when=e=>e.then(t),t}const Ae=new le({callback:e=>he.client.readThreadMessage(e),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>ie(e)[0],timeout:500}),qe=new le({callback:e=>he.client.readChatMessage({id:e}),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>se(e),timeout:500}),Ue=me.injectEndpoints({endpoints:e=>({getAccountList:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.accounts()}})),providesTags:["account"]}),getChat:e.query({queryFn:({id:e})=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.chat(e)}})),providesTags:["chat","account"],onCacheEntryAdded:({id:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,De(he.client.subscribe("chatify://chat-member-added",(([t,n,s,i,,c])=>t===e&&a((e=>{e.members.push(s),e.lastReadMessageId=c?i.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-member-removed",(([t,n,,s,i])=>e===t&&a((e=>{e.members=e.members.filter((e=>e.id!==n)),e.lastReadMessageId=i?s.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-name-changed",(([t,n,s,i])=>e===t&&a((e=>{e.name=n,e.lastReadMessageId=i?s.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-new-message",(([t])=>e===t.chatId&&a((e=>{e.lastReadMessageId=t.sentBy.id===he.me()?t.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-message-read",(([t])=>t.find((t=>t.chatId===e))&&a((n=>{const a=t.find((t=>t.chatId===e));n.lastReadMessageId=a.newLastReadMessageId}))))).when(t)}))}),addChat:e.mutation({queryFn:({name:e,members:t})=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.addChat({name:e,members:t})}}))}),updateChatName:e.mutation({queryFn:({id:e,name:t})=>de(void 0,void 0,void 0,(function*(){return yield he.client.updateChatName({id:e,name:t}),{data:null}}))}),getChatList:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.chats()}})),providesTags:["chat","account"],onCacheEntryAdded:(e,{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,De(he.client.subscribe("chatify://chat-created",(([e])=>a((t=>{t.push(e)})))),he.client.subscribe("chatify://chat-new-message",(([e])=>a((t=>{const n=t.find((t=>t.id===e.chatId));n&&(n.message=e,e.sentBy.id===he.me()&&(n.lastReadMessageId=e.id,n.totalUnreadCount=0),e.sentBy.id!==he.me()&&n.totalUnreadCount++)})))),he.client.subscribe("chatify://chat-message-read",(([e])=>a((t=>{for(const n of e){const e=t.find((e=>e.id===n.chatId));if(!e)return;e.lastReadMessageId=n.newLastReadMessageId,e.totalUnreadCount=e.totalUnreadCount-n.readCount}})))),he.client.subscribe("chatify://chat-member-added",(([e,t,n,s,,i])=>a((a=>{const c=a.find((t=>t.id===e));n.id!==he.me()||c||a.push({id:e,name:t,message:s,totalUnreadCount:i?0:1,active:!0,lastReadMessageId:i?s.id:null}),c&&(c.message=s,c.active=!0,i?(c.totalUnreadCount=0,c.lastReadMessageId=s.id):c.totalUnreadCount++)})))),he.client.subscribe("chatify://chat-member-removed",(([e,t,n,s,i])=>a((a=>{if(t===he.me()&&n)return a.filter((t=>t.id!==e));const c=a.find((t=>t.id===e));c&&(c.message=s,t===he.me()&&(c.active=!1),i?(c.totalUnreadCount=0,c.lastReadMessageId=s.id):c.totalUnreadCount++)})))),he.client.subscribe("chatify://chat-name-changed",(([e,t,n,s])=>a((a=>{const i=a.find((t=>t.id===e));i&&(i.name=t,i.message=n,s?(i.totalUnreadCount=0,i.lastReadMessageId=n.id):i.totalUnreadCount++)}))))).when(t)}))}),removeChatMember:e.mutation({queryFn:e=>de(void 0,void 0,void 0,(function*(){return yield he.client.removeChatMember(e),{data:null}}))}),addChatMember:e.mutation({queryFn:e=>de(void 0,void 0,void 0,(function*(){return yield he.client.addChatMember(e),{data:null}}))}),getChatMessageList:e.query({queryFn:({chatId:e})=>de(void 0,void 0,void 0,(function*(){const t=yield he.client.chatMessages({chatId:e,skip:0,take:21});return{data:{messages:t.slice(0,ue),hasMore:21===t.length}}})),providesTags:["message","chat","account"],onCacheEntryAdded:({chatId:e},{dispatch:t,cacheEntryRemoved:n,cacheDataLoaded:a})=>de(void 0,void 0,void 0,(function*(){yield a,De(he.client.subscribe("chatify://chat-new-message",(([n])=>{n.chatId===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(n)})))})),he.client.subscribe("chatify://chat-member-added",(([n,,,a])=>{n===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))})),he.client.subscribe("chatify://chat-member-removed",(([n,,,a])=>{n===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))})),he.client.subscribe("chatify://chat-name-changed",(([n,,a])=>{n===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))}))).when(n)}))}),fetchNextChatMessageList:e.mutation({queryFn:({chatId:e},{getState:t})=>de(void 0,void 0,void 0,(function*(){const n=Pe.endpoints.getChatMessageList.select({chatId:e})(t()),a=yield he.client.chatMessages({chatId:e,skip:n.data.messages.length,take:21});return{data:null,meta:{messages:a.slice(0,ue),hasMore:21===a.length}}})),onQueryStarted:({chatId:e},{dispatch:t,queryFulfilled:n})=>de(void 0,void 0,void 0,(function*(){const a=(yield n).meta;t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.hasMore=a.hasMore,e.messages.push(...a.messages)})))}))}),sendChatMessage:e.mutation({queryFn:({chatId:e,text:t,files:n})=>de(void 0,void 0,void 0,(function*(){return yield he.client.sendChatMessage({chatId:e,text:t,files:n}),{data:null}}))}),readChatMessage:e.mutation({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:null}})),onQueryStarted:({id:e},{dispatch:t})=>de(void 0,void 0,void 0,(function*(){qe.push(e),t(Pe.endpoints.getChatMessageReadQueue.initiate(void 0,{forceRefetch:!0}))}))}),getChatMessageReadQueue:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:qe.units}})),onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n})=>de(void 0,void 0,void 0,(function*(){De(qe.subscribe((e=>{t(Pe.util.updateQueryData("getChatMessageReadQueue",void 0,(()=>e.units)))}))).when(n)}))}),getWatchThreadList:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.watchThreads()}})),providesTags:["account","thread"],onCacheEntryAdded:(e,{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,De(he.client.subscribe("chatify://thread-created",(([e,t])=>t&&a((t=>{t.push(e)})))),he.client.subscribe("chatify://thread-message-new",(([e,t,n])=>a((a=>{const s=a.find((t=>t.id===e));s&&(s.lastMessage=t,n===he.me()&&(s.lastReadMessageId=t.id))})))),he.client.subscribe("chatify://thread-message-read",(([e,t])=>a((n=>{const a=n.find((t=>t.id===e));a&&(a.lastReadMessageId=t)})))),he.client.subscribe("chatify://thread-watch-added",(([e])=>a((t=>{t.push(e)})))),he.client.subscribe("chatify://thread-watch-removed",(([e])=>a((t=>{const n=t.findIndex((t=>t.id===e));-1!==n&&t.splice(n,1)}))))).when(t)}))}),getThread:e.query({queryFn:({id:e})=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.thread(e)}})),providesTags:["account","thread"],onCacheEntryAdded:({id:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,De(he.client.subscribe("chatify://thread-message-read",(([t,n])=>e===t&&a((e=>{e.lastReadMessageId=n})))),he.client.subscribe("chatify://thread-message-new",(([t,n,s])=>e===t&&a((e=>{e.lastMessageId=n.id,e.lastReadMessageId=s===he.me()?n.id:e.lastReadMessageId})))),he.client.subscribe("chatify://thread-watch-added",(([t])=>e===t.id&&a((e=>{var n,a,s;e.watch=!0,e.lastMessageId=null!==(a=null===(n=t.lastMessage)||void 0===n?void 0:n.id)&&void 0!==a?a:null,e.lastReadMessageId=null!==(s=t.lastReadMessageId)&&void 0!==s?s:null})))),he.client.subscribe("chatify://thread-watch-removed",(([t])=>e===t&&a((e=>{e.watch=!1}))))).when(t)}))}),watchThread:e.mutation({queryFn:({id:e,watch:t})=>de(void 0,void 0,void 0,(function*(){return yield he.client.watchThread(e,t),{data:null}}))}),getThreadMessageList:e.query({queryFn:e=>de(void 0,void 0,void 0,(function*(){const t=Object.assign({skip:0,take:21},e),n=yield he.client.threadMessages(t);return{data:{messages:n.slice(0,ue),hasMore:21===n.length}}})),providesTags:["account","thread","thread-message"],onCacheEntryAdded:({threadId:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,De(he.client.subscribe("chatify://thread-message-new",(([t,n])=>{e===t&&a((e=>{!e.messages.some((e=>e.id===n.id))&&e.messages.unshift(n)}))}))).when(t)}))}),fetchNextThreadMessageList:e.mutation({queryFn:({threadId:e},{getState:t})=>de(void 0,void 0,void 0,(function*(){const n=Pe.endpoints.getThreadMessageList.select({threadId:e})(t()),a=yield he.client.threadMessages({threadId:e,skip:n.data.messages.length,take:21});return{data:null,meta:{messages:a.slice(0,ue),hasMore:21===a.length}}})),onQueryStarted:({threadId:e},{dispatch:t,queryFulfilled:n})=>de(void 0,void 0,void 0,(function*(){const a=(yield n).meta;t(Pe.util.updateQueryData("getThreadMessageList",{threadId:e},(e=>{e.hasMore=a.hasMore,e.messages.push(...a.messages)})))}))}),sendThreadMessage:e.mutation({queryFn:e=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.sendThreadMessage(e)}}))}),readThreadMessage:e.mutation({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:null}})),onQueryStarted:({id:e},{dispatch:t})=>de(void 0,void 0,void 0,(function*(){Ae.push(e),t(Pe.endpoints.getThreadMessageReadQueue.initiate(void 0,{forceRefetch:!0}))}))}),getThreadMessageReadQueue:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:Ae.units}})),onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n})=>de(void 0,void 0,void 0,(function*(){De(Ae.subscribe((e=>{t(Pe.util.updateQueryData("getThreadMessageReadQueue",void 0,(()=>e.units)))}))).when(n)}))})})});function Qe(e){return ke((t=>{var n;return null!=e?null===(n=Ue.endpoints.getChatList.select()(t).data)||void 0===n?void 0:n.find((t=>t.id===e)):null}))}function Ge(){const e=Pe.useGetWatchThreadListQuery(),{data:t}=e,n=oe(e,["data"]);return[r((()=>null!=t?re(t):null),[t]),n]}const Pe=Object.assign(Ue,{settings:he,useChatListItem:Qe,useUnreadThreadMessageCount:Ge}),Ve=o(((t,n)=>{const{account:a}=t;return e(f,{ref:n,src:a.avatar})}));Ve.displayName="Avatar";const ze=Y("Avatar",Ve);function $e(e,t,n){const[a,s]=Pe.useAddChatMemberMutation();return[d((()=>a({chatId:e,accountId:t,withHistory:n})),[a,e,t,n]),s]}function He(e,t,n){const[a,s]=Pe.useRemoveChatMemberMutation();return[d((()=>a({chatId:e,accountId:t,deleteHistory:n})),[a,e,t,n]),s]}const Ke=Y("ChatMemberListItem",(n=>{const{chatId:a}=n,{data:s}=Pe.useGetChatQuery({id:a}),{data:i}=Pe.useGetAccountListQuery(),c=i.find((e=>e.id===n.id)),r=s.members.some((e=>e.id===c.id)),[o]=$e(a,c.id,!1),[d]=$e(a,c.id,!0),[l]=He(a,c.id,!1),[u]=He(a,c.id,!0);return e(v.Item,{className:"wxchtf-chat-members-list-item",actions:r?[e(y,{title:"Remove (keep history)",children:e(g,{onClick:l,type:"link",icon:e(X,{type:"remove-member"})})},"remove"),e(y,{title:"Remove (delete history)",children:e(g,{onClick:u,type:"link",icon:e(X,{type:"remove-member-delete-history"})})},"remove_delete_history")]:[e(y,{title:"Add (no history)",children:e(g,{onClick:o,type:"link",icon:e(X,{type:"add-member"})})},"add_no_history"),e(y,{title:"Add (share history)",children:e(g,{onClick:d,type:"link",icon:e(X,{type:"add-member-with-history"})})},"add")],children:t(p,{children:[e(ze,{account:c}),e("span",{children:c.name})]})})})),We=Y("ChatMembersPanel",(()=>{const{id:t}=ee(),{data:n}=Pe.useGetChatQuery({id:t}),{data:a}=Pe.useGetAccountListQuery(),s=r((()=>null==a?void 0:a.slice().sort(((e,t)=>((null==n?void 0:n.members.some((t=>t.id===e.id)))?-100:0)-((null==n?void 0:n.members.some((e=>e.id===t.id)))?-100:0)+e.name.localeCompare(t.name)))),[a,n]);return(null==n?void 0:n.members)&&a?e("div",{className:"wxchtf-chat-members-panel",children:e(v,{className:"wxchtf-chat-members-list",dataSource:s,renderItem:n=>e(Ke,{id:n.id,chatId:t})})}):null})),Ye=Y("ChatMembersPreview",(()=>{const{id:t}=ee(),{data:n}=Pe.useGetChatQuery({id:t});return(null==n?void 0:n.members)?e(f.Group,{maxCount:5,children:n.members.map((t=>e(y,{title:t.name,children:e(ze,{account:t})},t.id)))}):null})),Je=Y("InputFileButton",(a=>{const{onUpload:s,onAddedClick:i,accept:c,loading:r,value:o,disabled:h}=a,m=l(null),f=d((()=>{var e;return null===(e=m.current)||void 0===e?void 0:e.click()}),[]),v=l(null);u((()=>{var e;null===(e=v.current)||void 0===e||e.classList.add("active")}),[o]);const y=d((()=>{var e;null===(e=v.current)||void 0===e||e.classList.remove("active")}),[]),p=d((e=>{const t=e.target.files;t&&t.length>0&&s(Array.from(t))}),[s]);return t(n,{children:[e(g,{loading:r,onClick:f,type:"link",disabled:h,icon:e(X,{type:"attach"}),className:"wxchtf-add-files-btn"}),o.length>0&&e(g,{ref:v,className:"wxchtf-add-files-added-btn",onAnimationIteration:y,onClick:i,type:"link",disabled:h,icon:t(n,{children:["+",o.length]})}),e("input",{value:"",accept:c,onChange:p,ref:m,type:"file",multiple:!0,style:{display:"none"}})]})})),Xe=Y("InputFilesBox",(t=>e("div",{className:"wxchtf-add-files-box",children:e(Je,Object.assign({},t))}))),Ze=s.createContext(null);function et(){return i(Ze)}const tt={isToday:e=>P(e).isSame(P(),"day"),timestamp:e=>P(e).format("HH:mm"),dateTime:e=>P(e).format("DD/MM/YYYY HH:mm"),message:{read:()=>"Read",reading:()=>"Reading...",sending:()=>"Sending..."},addChat:{title:()=>"Add chat",name:{label:()=>"Name",required:()=>"Name is required",max250:()=>"Max 250 characters allowed"},members:{label:()=>"Members",required:()=>"Members is required"},submitBtn:()=>"Submit"},system:{"chatify://chat-created":()=>"Chat created","chatify://member-added":()=>"New member added","chatify://member-removed":()=>"Member removed","chatify://chat-name-changed":(e,{newName:t})=>`Chat name changed to '${t}'`},input:{placeholder:()=>"Start typing... (Press Enter to send, and Shift+Enter to start a new line)"},settings:{members:()=>"Members"},size:{bytes:e=>`${e.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2})} bytes`,kb:e=>`${e.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2})} KB`,mb:e=>`${e.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2})} MB`}},nt=G("enter"),at=G("ctrl+enter"),st={maxRows:5,minRows:1},it=Y("InputTextBox",h((t=>{const{value:n,onChange:a,onSend:s,disabled:i,inputRef:c}=t,r=et(),o=d((e=>a(e.target.value)),[a]),l=d((e=>{i?e.preventDefault():(nt(e)||at(e))&&(e.preventDefault(),s(n))}),[s,n,i]);return e("div",{className:"wxchtf-text-input-box",children:e(b.TextArea,{ref:c,value:n,onChange:o,autoSize:st,className:"wxchtf-text-input-textarea",placeholder:r.input.placeholder(),onKeyDown:l})})}))),ct=Y("InputSubmitButtonBox",(t=>{const{onSubmit:n,disabled:a,loading:s}=t;return e("div",{className:"wxchtf-submit-btn-box",children:e(g,{onClick:n,type:"link",icon:e(X,{type:"send"}),className:"wxchtf-submit-btn",disabled:a,loading:s})})})),rt=s.createContext(void 0);function ot(){return s.useContext(rt)}const dt=Y("MessageSkeleton",(a=>{const{count:s=1}=a;return e(n,{children:Array.from(Array(s)).map(((n,a)=>t("div",{className:"wxchtf-message-skeleton",children:[e(w.Avatar,{className:"wxchtf-avatar",active:!0}),e(w.Button,{active:!0,className:"wxchtf-content"})]},a)))})}));function lt(){const e=et();return{size:t=>t<1024?e.size.bytes(t):t<1048576?e.size.kb(t/1024):e.size.mb(t/1024/1024)}}const ut=Y("InputBoxFile",(n=>{const{file:a,disabled:s,onDelete:i}=n,c=lt(),r=d((()=>i(a)),[a,i]);return t("div",{className:"wxchtf-file",children:[t("div",{className:"wxchtf-file-info",children:[e("div",{className:"wxchtf-file-name",title:a.name,children:a.name}),e("div",{className:"wxchtf-file-size",children:c.size(a.bytes)})]}),e("div",{className:"wxchtf-file-actions",children:e(g,{disabled:s,className:"wxchtf-delete",type:"link",icon:e(X,{type:"delete-file"}),onClick:r})})]})})),ht=Y("InputBoxFileList",(t=>{const{files:n,onDelete:a,disabled:s}=t;return e("div",{className:"wxchtf-file-list",children:n.map((t=>e(ut,{file:t,onDelete:a,disabled:s},t.ref)))})}));function mt(){const{onSend:e}=ot(),[t,n]=c(""),[a,s]=c(!1),{onUpload:i,files:r,loading:o,setFiles:l,showFileBox:u,onDeleteFile:h}=function(){const[e,t]=c(!1),[n,a]=c([]),{flippo:s}=H(),i=d((e=>{s&&(t(!0),Promise.all(e.map((e=>s.store(e)))).then((t=>a((n=>[...n,...t.map(((t,n)=>({name:e[n].name,ref:t,bytes:e[n].size})))])))).finally((()=>t(!1))))}),[s]),r=d((e=>{a((t=>t.filter((t=>t!==e))))}),[]);return{onUpload:i,files:n,loading:e,setFiles:a,showFileBox:!!s,onDeleteFile:r}}();return[d((()=>{const a=0===t.trim().length?null:t.trim();!a&&0===r.length||o||(s(!0),Promise.resolve(e({text:a,files:r})).finally((()=>s(!1))).then((()=>{l([]),n("")})))}),[t,e,r,l,o]),{text:t,setText:n,files:r,onUpload:i,loading:o,showFileBox:u,onDeleteFile:h,sending:a}]}const gt=Y("InputBox",(()=>{const[n,{text:a,setText:s,files:i,loading:r,onUpload:o,showFileBox:h,onDeleteFile:g,sending:f}]=mt(),v=l(null),[y,p]=c(!1),b=d((()=>p((e=>!e))),[]),w=l(i.length);return m((()=>{var e;return null===(e=v.current)||void 0===e?void 0:e.focus()}),[]),u((()=>{0===w.current&&i.length>0&&!y&&p(!0),w.current=i.length,0===i.length&&y&&p(!1)}),[i,y]),e("div",{className:"wxchtf-input-form",children:t("div",{className:"wxchtf-input-box",children:[y&&e("div",{className:"wxchtf-file-list-box",children:e(ht,{files:i,onDelete:g,disabled:f})}),t("div",{className:"wxchtf-input-box-row",children:[h&&e(Xe,{onAddedClick:b,onUpload:o,value:i,loading:r,disabled:f}),e(it,{value:a,onSend:n,onChange:s,disabled:f,inputRef:v}),e(ct,{onSubmit:n,disabled:r,loading:f})]})]})})})),ft=Y("MessageAuthor",(t=>{const{sentBy:n}=t.message;return e("div",{className:"wxchtf-message-author",children:e(ze,{account:n})})})),vt=t=>{const{message:a,messageRef:s}=t,{onRead:i,lastReadMessageId:c}=ot(),o=null!=c&&a.id.localeCompare(c)<=0,d=l(o);u((()=>{d.current=d.current||o}),[o]);const h=r((()=>new IntersectionObserver((([e])=>{e.isIntersecting&&!d.current&&(d.current=!0,i(a.id))}))),[]);return u((()=>(h.observe(s.current),()=>h.disconnect())),[h]),e(n,{})};function yt(t){const{noReadTracking:n}=ot();return!0===n?null:e(vt,Object.assign({},t))}const pt=Y("MessageText",(t=>{const{text:n}=t.message;return e("div",{className:"wxchtf-message-text",children:n})}));function bt(e){const t=window.open(e,"_blank");null==t||t.focus()}const wt=Y("MessageFile",(n=>{const{file:a}=n,s=lt(),[i,{isOpenFetching:r}]=function(e){const{file:t}=e,{flippo:n}=H(),[a,s]=c(!1);return[d((()=>n&&Promise.resolve(s(!0)).then((()=>n.getSasUrl(t.ref))).then(bt).finally((()=>s(!1)))),[n,t.ref]),{isOpenFetching:a}]}(n);return t("div",{className:"wxchtf-file",children:[e("div",{className:"wxchtf-icon",children:e(g,{loading:r,onClick:i,type:"link",icon:e(X,{type:"open-file"})})}),t("div",{className:"wxchtf-file-info",children:[e("div",{className:"wxchtf-name",title:a.name,children:a.name}),e("div",{className:"wxchtf-size",children:s.size(a.bytes)})]})]})})),Ct=Y("MessageFileList",(t=>{const{files:n}=t.message;return e("div",{className:"wxchtf-file-list",children:n.map((t=>e(wt,{file:t},t.ref)))})})),xt=Y("MessageContent",(n=>{const{files:a,text:s}=n.message;return t("div",{className:"wxchtf-message-content",children:[s&&e(pt,Object.assign({},n)),a.length>0&&e(Ct,Object.assign({},n))]})})),Mt=Y("MessageInfoBox",(n=>{const{message:a}=n,{id:s,sentBy:i,sentAt:c}=a,{lastReadMessageId:r,isReading:o,noReadTracking:d}=ot(),l=Pe.settings.me(),u=i.id===l,h=et(),m=!(null!=r&&s.localeCompare(r)<=0)&&o(s);return t("div",{className:"wxchtf-message-info-box",children:[!u&&t("div",{className:"wxchtf-message-author-name",children:[i.name,","]}),e("div",{className:"wxchtf-message-sent-at",children:h.timestamp(c)}),!u&&!d&&e("div",{className:"wxchtf-message-read-box",children:m?h.message.reading():h.message.read()})]})})),It=Y("MessageRow",(n=>{const{message:a,containerRef:s}=n,{sentBy:i}=a,c=Pe.settings.me(),r=i.id===c;return t("div",{ref:s,className:"wxchtf-message"+(r?" --my":""),children:[e(ft,Object.assign({},n)),t("div",{children:[e(Mt,Object.assign({},n)),e(xt,Object.assign({},n))]})]})})),Nt=Y("MessageBox",(a=>{const s=l(null);return t(n,{children:[e(yt,Object.assign({messageRef:s},a)),e(It,Object.assign({containerRef:s},a))]})}));function Ot(t){const{onLoad:n,loading:a}=t,[s,i]=c(!1),o=l(null),d=l(),h=r((()=>new IntersectionObserver((([e])=>{e.isIntersecting?d.current=window.setTimeout((()=>i(!0)),200):clearTimeout(d.current)}))),[]);return u((()=>(h.observe(o.current),()=>h.disconnect())),[h]),u((()=>{s&&n()}),[s]),a||s?e(dt,{count:4}):e("div",{className:"wxchtf-next",ref:o})}const Rt=Y("SendingMessageText",(t=>{const{text:n}=t;return e("div",{className:"wxchtf-sending-message-text",children:n})})),_t=Y("SendingMessageInfoBox",(t=>{const n=et();return e("div",{className:"wxchtf-sending-message-info-box",children:e("div",{className:"wxchtf-sending-message-sending-box",children:n.message.sending()})})})),St=Y("SendingMessageContent",(n=>t("div",{className:"wxchtf-sending-message-content",children:[e(Rt,Object.assign({},n)),e(_t,Object.assign({},n))]}))),Tt=Y("SendingMessageBox",(t=>e("div",{className:"wxchtf-sending-message",children:e(St,Object.assign({},t))})));function kt(e,t){const[n,a]=t.split("::",2),s=a?JSON.parse(a):null;return e.system[n](n,s)}const Lt=Y("SystemMessageRow",(n=>{const{message:a,containerRef:s}=n,{text:i,sentAt:c}=a,r=et();return t("div",{ref:s,className:"wxchtf-system-message",children:[e("div",{className:"wxchtf-text",children:i&&kt(r,i)}),e("div",{className:"wxchtf-timestamp",children:r.timestamp(c)})]})})),Et=Y("SystemMessageBox",(a=>{const s=l(null);return t(n,{children:[e(yt,Object.assign({messageRef:s},a)),e(Lt,Object.assign({containerRef:s},a))]})})),jt=Y("ConversationActions",(()=>null)),Ft=Y("ConversationBody",(()=>{const{id:n,messages:a=[],hasMore:s,onNext:i,nextLoading:c}=ot();return t("div",{className:"wxchtf-conversation-body",children:[!a&&e(dt,{count:5}),null==a?void 0:a.map((t=>t.sentBy.id===ae?e(Et,{message:t},t.id):e(Nt,{message:t},t.id))),s&&e(Ot,{onLoad:i,loading:c},a.length+n)]})})),Bt=Y("ConversationName",(()=>{const{name:t}=ot();return e("span",{className:"wxchtf-conversation-name",children:t})})),Dt=Y("ConversationHeader",(()=>{const n=W(jt);return e("div",{className:"wxchtf-conversation-header",children:t(C,{justify:"space-between",align:"middle",children:[e(x,{children:e(Bt,{})}),n&&e(x,{className:"wxchtf-conversation-actions",children:e(n,{})})]})})})),At=Y("Conversation",(n=>{const{value:a,hasMore:s,messages:i,nextLoading:c,onNext:o,onRead:d,onSend:l,isReading:u,noReadTracking:h}=n,{id:m,active:g,name:f,lastReadMessageId:v}=a,y=r((()=>({id:m,name:f,active:g,lastReadMessageId:v,hasMore:s,messages:i,nextLoading:c,onNext:o,onRead:d,onSend:l,isReading:u,noReadTracking:h})),[m,f,g,o,d,l,s,i,c,v,u,h]);return e(rt.Provider,{value:y,children:e("div",{className:"wxchtf-conversation",children:t("div",{className:"wxchtf-conversation-main",children:[e(Dt,{}),e(Ft,{}),g&&e(gt,{})]})})})})),qt=G("escape"),Ut=G("enter");const Qt=Y("ChatEditableHeaderName",(()=>{const{id:t,name:n,active:a}=ot(),[s,i]=c(""),[r,o]=c(!1),d=function(e,t){const[n]=Pe.useUpdateChatNameMutation();return()=>n({id:e,name:t})}(t,s);return u((()=>{r&&i(null!=n?n:"")}),[r,n]),a?e(y,r?{defaultOpen:!0,title:"Press Enter to save new chat name or Escape to cancel editing",children:e(b,{value:s,onChange:e=>i(e.target.value),onBlur:()=>o(!1),onKeyDown:e=>{qt(e)?o(!1):Ut(e)&&(o(!1),s!==n&&""!==s.trim()&&d())},autoFocus:!0})}:{title:"Click to edit name...",children:e("span",{className:"wxchtf-conversation-name --editable",onClick:()=>o(!0),children:n})}):e("span",{className:"wxchtf-conversation-name",children:n})})),Gt=Y("ChatHeaderActions",(()=>{const{active:n}=ot();return n?t("div",{className:"wxchtf-chat-members",children:[e(Ye,{}),e(ne,{})]}):null})),Pt={ConversationName:()=>e(Qt,{}),ConversationActions:()=>e(Gt,{})};function Vt(n){const a=function(e){const{value:t}=e,{id:n,name:a,active:s,lastReadMessageId:i}=t,{data:c}=Pe.useGetChatMessageListQuery({chatId:n}),{messages:o,hasMore:l}=null!=c?c:{},[u,{isLoading:h}]=Pe.useFetchNextChatMessageListMutation(),m=d((()=>u({chatId:n})),[u,n]),[g]=Pe.useReadChatMessageMutation(),f=d((e=>g({id:e})),[g]),[v]=Pe.useSendChatMessageMutation(),y=d((e=>v(Object.assign(Object.assign({},e),{chatId:n})).unwrap()),[n,v]),{data:p}=Pe.useGetChatMessageReadQueueQuery();return r((()=>{if(!n)return null;const e={value:{id:n,name:a,active:s,lastReadMessageId:i},messages:o,hasMore:l,onNext:m,nextLoading:h,onRead:f,onSend:y,isReading:e=>p.some((t=>se(t.value)===se(e)&&e<=t.value))};return e}),[m,f,y,h,n,a,s,o,l,i,p])}(n),{showMembers:s}=ee();return a?t("div",{className:"wxchtf-chat",children:[e(At,Object.assign({},a)),s&&e(We,{})]}):null}const zt=Y("ChatView",(t=>{const{value:n}=t,a=H(),s=r((()=>Object.assign(Object.assign({},null!=a?a:{}),Pt)),[a]);return e($.Provider,{value:s,children:e(te,{id:n.id,children:e(Vt,{value:n})})})}));function $t(t){const{id:n,className:a="",customize:s,localizer:i=tt,style:c}=t,{data:r}=Pe.useGetChatQuery({id:n});return e("div",{className:`wxchtf-chatify wxchtf-chat-panel ${a}`,style:c,children:e(Ze.Provider,{value:i,children:e($.Provider,{value:s,children:r&&e(zt,{value:r},n)})})})}const Ht=Y("CreateChatNameInput",(t=>{const{name:n}=t,a=et();return e(M.Item,{name:n,label:a.addChat.name.label(),rules:[{required:!0,message:a.addChat.name.required()},{max:250,message:a.addChat.name.max250()}],children:e(b,{})})}));function Kt(t){const{value:n,onChange:a}=t,{data:s,isFetching:i}=Pe.useGetAccountListQuery(),c=Pe.settings.me(),o=r((()=>{var e;return null!==(e=null==s?void 0:s.filter((e=>e.id!==c)))&&void 0!==e?e:[]}),[s,c]);return e(v,{rowKey:"id",className:"wxchtf-create-chat-member-input-list",loading:i,dataSource:o,renderItem:t=>{const s=n.includes(t.id);return e(v.Item,{className:s?"--selected":"",children:e(I,{checked:s,onChange:()=>a(n.includes(t.id)?n.filter((e=>e!==t.id)):[...n,t.id]),children:e(v.Item.Meta,{avatar:e(ze,{account:t}),title:t.name})})})}})}const Wt=Y("CreateChatMemberInput",(t=>{const{name:n}=t,a=et();return e(M.Item,{label:a.addChat.members.label(),rules:[{required:!0,message:a.addChat.members.required()}],name:n,children:e(Kt,{})})})),Yt={name:"",members:[]},Jt=Y("CreateChatForm",(n=>{const{value:a=Yt,onSubmit:s,busy:i=!1}=n,c=et();return t(M,{onFinish:s,layout:"vertical",disabled:i,initialValues:a,children:[e(Ht,{name:"name"}),e(Wt,{name:"members"}),e(g,{loading:i,type:"primary",block:!0,htmlType:"submit",children:c.addChat.submitBtn()})]})})),Xt=s.createContext(null);function Zt(){return i(Xt)}function en(t){const{children:n}=t,[a,s]=c({chatId:null,view:null,showMembers:!1}),i=r((()=>Object.assign(Object.assign({},a),{openChat:e=>s((t=>Object.assign(Object.assign({},t),{view:"chat",chatId:e}))),none:()=>s((e=>Object.assign(Object.assign({},e),{view:null,chatId:null}))),toggleMembers:()=>s((e=>Object.assign(Object.assign({},e),{showMembers:!e.showMembers}))),toggleNewChat:()=>s((e=>"new-chat"!==e.view||e.chatId?"new-chat"===e.view&&e.chatId?Object.assign(Object.assign({},e),{view:"chat"}):Object.assign(Object.assign({},e),{view:"new-chat"}):Object.assign(Object.assign({},e),{view:null})))})),[a]);return e(Xt.Provider,{value:i,children:n})}const tn=Y("CreateChatPanel",(()=>{const n=et(),[a,s]=function(){const[e,{isLoading:t}]=Pe.useAddChatMutation(),{openChat:n}=Zt();return[d((t=>e({name:t.name,members:t.members}).unwrap().then((e=>n(e)))),[e,n]),t]}(),{toggleNewChat:i}=Zt();return t("div",{className:"wxchtf-create-chat-panel",children:[e(g,{onClick:()=>i(),className:"wxchtf-create-chat-panel-close",type:"link",icon:e(X,{type:"close"})}),e("h3",{children:n.addChat.title()}),e(Jt,{busy:null!=s&&s,onSubmit:a})]})})),nn=Y("CreateChatButton",(()=>{const{toggleNewChat:t}=Zt();return e("span",{className:"wxchtf-add-btn-wrapper",children:e(g,{className:"wxchtf-add-btn",onClick:t,icon:"+",children:"Add chat"})})})),an=Y("ChatListItemName",(t=>{const{chat:n}=t;return e("div",{className:"wxchtf-chat-name",children:n.name})})),sn=Y("ChatListItemUnreadCount",(t=>{const{totalUnreadCount:n}=t.chat;return n<=0?null:e("div",{className:"wxchtf-unread-count",children:n})})),cn=Y("ChatListItemLastMessageContent",(t=>{const{message:n}=t.chat,a=et();return e("div",{className:"wxchtf-chat-last-message",children:"chatify::system"===n.sentBy.id?n.text&&kt(a,n.text):n.text})})),rn=Y("ChatListItemLastMessageAuthor",(t=>{const{message:n}=t.chat;return"chatify::system"===n.sentBy.id?null:e("div",{className:"wxchtf-chat-last-author",children:n.sentBy.name})})),on=Y("ChatListItemLastMessageSentAt",(t=>{const{chat:{message:{sentAt:n}}}=t,a=et();return e("div",{className:"wxchtf-chat-last-sent-at",children:a.isToday(n)?a.timestamp(n):a.dateTime(n)})})),dn=Y("ChatListItemLastMessage",(n=>t("div",{className:"wxchtf-chat-last",children:[e(rn,Object.assign({},n)),e(cn,Object.assign({},n)),e(on,Object.assign({},n))]}))),ln=Y("ChatListItemAvatar",(t=>{const{id:n}=t.chat;return e("div",{className:"wxchtf-chat-avatar",style:{"--background-color":z(n,{lightness:90}),"--color":z(n,{saturation:60,lightness:65})},children:e(X,{type:"chat"})})})),un=Y("ChatListItemBox",(n=>{const{message:a,lastReadMessageId:s}=n.chat,i=null!=s&&s.localeCompare(a.id)>=0;return t("div",{className:"wxchtf-chat"+(i?"":" --unread"),children:[e(ln,Object.assign({},n)),t("span",{className:"wxchtf-chat-info",children:[e(an,Object.assign({},n)),e(sn,Object.assign({},n)),e(dn,Object.assign({},n))]})]})}));const hn=Y("ChatList",(()=>{const{chatId:t}=Zt(),a=r((()=>t?[t]:[]),[t]),s=function(){const{openChat:e}=Zt();return d((t=>e(t.key)),[e])}(),i=function(){const{data:t}=Pe.useGetChatListQuery();return r((()=>null==t?void 0:t.slice().sort(((e,t)=>-e.message.id.substring(47).localeCompare(t.message.id.substring(47)))).map((t=>({key:t.id,label:e(un,{chat:t})})))),[t])}();return e(n,{children:i&&e(N,{className:"wxchtf-chat-list",selectedKeys:a,onSelect:s,items:i})})})),mn=Y("ChatGroupAside",(()=>t("div",{className:"wxchtf-aside",children:[e(nn,{}),e(hn,{})]}))),gn=Y("ChatGroupHeader",(()=>e("div",{className:"wxchtf-header"}))),fn=Y("ChatGroupFooter",(()=>e("div",{className:"wxchtf-footer"}))),vn=Y("ChatGroupMain",(()=>{const{chatId:n,view:a}=Zt(),s=Pe.useChatListItem(n);return t("div",{className:"wxchtf-main",children:["chat"===a&&s&&e(zt,{value:s},n),"new-chat"===a&&e(tn,{})]})})),yn=Y("ChatGroupBody",(()=>t("div",{className:"wxchtf-body",children:[e(mn,{}),e(vn,{})]})));function pn(n){const{className:a="",style:s}=n,{data:i}=Pe.useGetChatListQuery(),{openChat:c,none:r,chatId:o}=Zt(),d=l(!1);return u((()=>{i&&!i.some((e=>e.id===o))&&(i.length?c(i[0].id):r())}),[i,o]),u((()=>{i&&!d.current&&(d.current=!0,i.length&&c(i[0].id))}),[i]),t("div",{className:a+" wxchtf-chatify wxchtf-chat-group",style:s,children:[e(gn,{}),e(yn,{}),e(fn,{})]})}const bn={ChatGroupHeader:null,ChatGroupFooter:null},wn=t=>{const{localizer:n=tt,customize:a=bn}=t,s=r((()=>Object.assign({},bn,a)),[a]);return e(Ze.Provider,{value:n,children:e($.Provider,{value:s,children:e(en,{children:e(pn,Object.assign({},t))})})})},Cn=s.createContext(null);function xn(){return s.useContext(Cn)}const Mn=Y("ThreadActions",(()=>{const{watch:t,onWatch:n}=xn();return e(y,t?{title:"Unwatch thread",children:e(g,{type:"link",icon:e(X,{type:"unwatch"}),onClick:()=>n(!1)})}:{title:"Watch thread",children:e(g,{type:"link",icon:e(X,{type:"watch"}),onClick:()=>n(!0)})})}));const In={ConversationActions:()=>e(Mn,{})};function Nn(t){const{threadId:n,customize:a,localizer:s=tt,className:i=""}=t,[c,o]=function(e){const{threadId:t}=e,{data:n}=Pe.useGetThreadQuery({id:t}),{data:a}=Pe.useGetThreadMessageListQuery({threadId:t}),{id:s,name:i,archive:c,lastReadMessageId:o,watch:l}=null!=n?n:{},{messages:u,hasMore:h}=null!=a?a:{},[m]=Pe.useReadThreadMessageMutation(),g=d((e=>m({id:e})),[m]),[f,{isLoading:v}]=Pe.useFetchNextThreadMessageListMutation(),y=d((()=>f({threadId:t})),[f,t]),[p]=Pe.useSendThreadMessageMutation(),b=d((e=>p({body:e,threadId:t}).unwrap()),[t,p]),{data:w}=Pe.useGetThreadMessageReadQueueQuery(),C=r((()=>{if(!s)return null;const e={value:{id:s,name:i,active:!c,lastReadMessageId:null!=o?o:null},messages:u,hasMore:h,onNext:y,nextLoading:v,onRead:g,onSend:b,noReadTracking:!l,isReading:e=>w.some((t=>ie(t.value)[0]===ie(e)[0]&&e<=t.value))};return e}),[y,g,b,v,s,i,c,u,h,o,w,l]),[x]=Pe.useWatchThreadMutation();return[C,r((()=>n?{id:n.id,watch:n.watch,onWatch:e=>x({id:n.id,watch:e}).unwrap()}:null),[n,x])]}(t),l=r((()=>Object.assign(Object.assign({},In),a)),[a]);return u((()=>(Pe.settings.client.connectToThread(n),()=>{Pe.settings.client.disconnectFromThread(n)})),[n]),c&&o?e(Ze.Provider,{value:s,children:e(Cn.Provider,{value:o,children:e($.Provider,{value:l,children:e("div",{className:`wxchtf-chatify wxchtf-thread ${i}`,children:c&&e(At,Object.assign({},c))})})})}):null}const On={Thread:Nn,ChatGroup:wn,Chat:$t};export{ze as Avatar,Fe as CHATIFY_SIGNALR_METHODS,te as ChatContext,Qt as ChatEditableHeaderName,mn as ChatGroupAside,yn as ChatGroupBody,en as ChatGroupContext,fn as ChatGroupFooter,gn as ChatGroupHeader,vn as ChatGroupMain,wn as ChatGroupPanel,Gt as ChatHeaderActions,hn as ChatList,ln as ChatListItemAvatar,un as ChatListItemBox,dn as ChatListItemLastMessage,rn as ChatListItemLastMessageAuthor,cn as ChatListItemLastMessageContent,on as ChatListItemLastMessageSentAt,an as ChatListItemName,sn as ChatListItemUnreadCount,ne as ChatMembersButton,We as ChatMembersPanel,Ye as ChatMembersPreview,$t as ChatPanel,zt as ChatView,On as Chatify,Be as ChatifyClient,At as Conversation,jt as ConversationActions,Ft as ConversationBody,rt as ConversationContext,Dt as ConversationHeader,Bt as ConversationName,nn as CreateChatButton,Jt as CreateChatForm,Wt as CreateChatMemberInput,Ht as CreateChatNameInput,tn as CreateChatPanel,$ as CustomizeContext,Pt as DEFAULT_CHAT_VIEW_CUSTOMIZE_VALUE,J as ICONS,X as Icon,gt as InputBox,ut as InputBoxFile,ht as InputBoxFileList,Je as InputFileButton,Xe as InputFilesBox,ct as InputSubmitButtonBox,it as InputTextBox,Ze as LocalizerContext,ft as MessageAuthor,Nt as MessageBox,xt as MessageContent,wt as MessageFile,Ct as MessageFileList,Mt as MessageInfoBox,yt as MessageReadObserver,It as MessageRow,dt as MessageSkeleton,pt as MessageText,Ot as NextMessagesObserver,ae as SYSTEM_ID,Tt as SendingMessageBox,St as SendingMessageContent,_t as SendingMessageInfoBox,Rt as SendingMessageText,Et as SystemMessageBox,Lt as SystemMessageRow,Mn as ThreadActions,Cn as ThreadContext,Nn as ThreadPanel,re as calcThreadListUnreadCount,ce as calcThreadUnreadCount,se as chatId,Pe as chatifyApi,z as color,Y as customize,tt as defaultLocalizer,kt as formatSystemMessage,ie as parseThreadMessageId,De as unsubscribe,ee as useChatContext,Zt as useChatGroupContext,Qe as useChatListItem,ot as useConversation,W as useCustomize,H as useCustomizeContext,et as useLocalizer,xn as useThreadContext,Ge as useUnreadThreadMessageCount};
10
+ */"production"===process.env.NODE_ENV?fe.exports=function(){if(ge)return ve;ge=1;var e=s,t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=e.useSyncExternalStore,a=e.useRef,i=e.useEffect,c=e.useMemo,r=e.useDebugValue;return ve.useSyncExternalStoreWithSelector=function(e,s,o,d,l){var u=a(null);if(null===u.current){var h={hasValue:!1,value:null};u.current=h}else h=u.current;u=c((function(){function e(e){if(!i){if(i=!0,n=e,e=d(e),void 0!==l&&h.hasValue){var s=h.value;if(l(s,e))return a=s}return a=e}if(s=a,t(n,e))return s;var c=d(e);return void 0!==l&&l(s,c)?s:(n=e,a=c)}var n,a,i=!1,c=void 0===o?null:o;return[function(){return e(s())},null===c?void 0:function(){return e(c())}]}),[s,o,d,l]);var m=n(e,u[0],u[1]);return i((function(){h.hasValue=!0,h.value=m}),[m]),r(m),m},ve}():fe.exports=(ye||(ye=1,"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=s,t="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=e.useSyncExternalStore,a=e.useRef,i=e.useEffect,c=e.useMemo,r=e.useDebugValue;pe.useSyncExternalStoreWithSelector=function(e,s,o,d,l){var u,h=a(null);null===h.current?(u={hasValue:!1,value:null},h.current=u):u=h.current;var m=c((function(){var e,n,a=!1,i=function(s){if(!a){a=!0,e=s;var i=d(s);if(void 0!==l&&u.hasValue){var c=u.value;if(l(c,i))return n=c,c}return n=i,i}var r=n;if(t(e,s))return r;var o=d(s);return void 0!==l&&l(r,o)?r:(e=s,n=o,o)},c=void 0===o?null:o;return[function(){return i(s())},null===c?void 0:function(){return i(c())}]}),[s,o,d,l]),g=m[0],f=m[1],v=n(e,g,f);return i((function(){u.hasValue=!0,u.value=v}),[v]),r(v),v},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),pe);var be=fe.exports,we="default"in a?a.default:a,Ce=Symbol.for("react-redux-context"),xe="undefined"!=typeof globalThis?globalThis:{};function Me(){if(!we.createContext)return{};const e=xe[Ce]??(xe[Ce]=new Map);let t=e.get(we.createContext);return t||(t=we.createContext(null),"production"!==process.env.NODE_ENV&&(t.displayName="ReactRedux"),e.set(we.createContext,t)),t}var Ie=Me();function Ne(e=Ie){return function(){const t=we.useContext(e);if("production"!==process.env.NODE_ENV&&!t)throw new Error("could not find react-redux context value; please ensure the component is wrapped in a <Provider>");return t}}var Oe=Ne(),Re=()=>{throw new Error("uSES not initialized!")},_e=(e,t)=>e===t;function Se(e=Ie){const t=e===Ie?Oe:Ne(e),n=(e,n={})=>{const{equalityFn:a=_e,devModeChecks:s={}}="function"==typeof n?{equalityFn:n}:n;if("production"!==process.env.NODE_ENV){if(!e)throw new Error("You must pass a selector to useSelector");if("function"!=typeof e)throw new Error("You must pass a function as a selector to useSelector");if("function"!=typeof a)throw new Error("You must pass a function as an equality function to useSelector")}const{store:i,subscription:c,getServerState:r,stabilityCheck:o,identityFunctionCheck:d}=t(),l=we.useRef(!0),u=we.useCallback({[e.name](t){const n=e(t);if("production"!==process.env.NODE_ENV){const{identityFunctionCheck:i,stabilityCheck:c}={stabilityCheck:o,identityFunctionCheck:d,...s};if("always"===c||"once"===c&&l.current){const s=e(t);if(!a(n,s)){let a;try{throw new Error}catch(e){({stack:a}=e)}console.warn("Selector "+(e.name||"unknown")+" returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",{state:t,selected:n,selected2:s,stack:a})}}if(("always"===i||"once"===i&&l.current)&&n===t){let t;try{throw new Error}catch(e){({stack:t}=e)}console.warn("Selector "+(e.name||"unknown")+" returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",{stack:t})}l.current&&(l.current=!1)}return n}}[e.name],[e,o,s.stabilityCheck]),h=Re(c.addNestedSub,i.getState,r||i.getState,u,a);return we.useDebugValue(h),h};return Object.assign(n,{withTypes:()=>n}),n}var Te,ke=Se(),Le=!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement),Ee="undefined"!=typeof navigator&&"ReactNative"===navigator.product;Le||Ee?we.useLayoutEffect:we.useEffect,Te=be.useSyncExternalStoreWithSelector,Re=Te;const je={hubUri:"/api/chatify/hub",headersFactory:()=>Promise.resolve({})},Fe=["chatify://chat-new-message","chatify://chat-created","chatify://chat-message-read","chatify://chat-member-added","chatify://chat-member-removed","chatify://chat-name-changed","chatify://thread-created","chatify://thread-message-new","chatify://thread-message-read","chatify://thread-watch-added","chatify://thread-watch-removed","chatify://thread-updated"];class Ae{constructor(e){this._connection=null,this._connectionPromise=null,this._subscribers={},this._reconnectSubscribers=[],this._threadConnectionByThreadId=new Map,this.connect=()=>de(this,void 0,void 0,(function*(){if(!this._connection){if(this._connectionPromise)return yield this._connectionPromise;this._connectionPromise=this.createAndStartConnection(),this._connection=yield this._connectionPromise}})),this.createAndStartConnection=()=>de(this,void 0,void 0,(function*(){const e=yield this._config.signalR.headersFactory(),t=(new Q.HubConnectionBuilder).withUrl(this._config.signalR.hubUri,{accessTokenFactory:this._config.signalR.accessTokenFactory?this._config.signalR.accessTokenFactory:void 0,headers:e}).withAutomaticReconnect().build();return Fe.forEach((e=>{t.on(e,((...t)=>{var n;null===(n=this._subscribers[e])||void 0===n||n.forEach((e=>{try{e(t)}catch(e){console.error("Failed to notify subscriber",e)}}))}))})),t.onreconnected((()=>this._reconnectSubscribers.forEach((e=>e())))),yield t.start(),t})),this.subscribe=(e,t)=>(this.connect().then((()=>{var n;this._subscribers[e]=null!==(n=this._subscribers[e])&&void 0!==n?n:[],this._subscribers[e].push(t)})),()=>this._subscribers[e].filter((e=>e!==t))),this.subscribeReconnect=e=>(this._reconnectSubscribers.push(e),()=>this._reconnectSubscribers.filter((t=>t!==e))),this.accounts=()=>de(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("account");return e})),this.updateAccount=e=>de(this,void 0,void 0,(function*(){yield this.axios.put(`account/${encodeURIComponent(e.id)}`,e)})),this.chats=()=>de(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("chat");return e})),this.chat=e=>de(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.get(`chat/${encodeURIComponent(e)}`);return t})),this.addChat=e=>de(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.post("chat",e);return t})),this.chatMessages=e=>de(this,void 0,void 0,(function*(){const{chatId:t,skip:n=0,take:a=20}=e,s=encodeURIComponent(JSON.stringify({skip:n,take:a})),{data:i}=yield this.axios.get(`chat/${encodeURIComponent(t)}/message?pagingRule=${s}`);return i})),this.sendChatMessage=e=>de(this,void 0,void 0,(function*(){const{chatId:t}=e,n=oe(e,["chatId"]);yield this.axios.post(`chat/${encodeURIComponent(t)}/message`,n)})),this.readChatMessage=e=>de(this,void 0,void 0,(function*(){yield this.axios.put("chat/message/read",e)})),this.removeChatMember=e=>de(this,void 0,void 0,(function*(){yield this.axios.delete(`chat/${encodeURIComponent(e.chatId)}/member`,{data:e})})),this.updateChatName=e=>de(this,void 0,void 0,(function*(){yield this.axios.put(`chat/${encodeURIComponent(e.id)}/name`,e)})),this.addChatMember=e=>de(this,void 0,void 0,(function*(){yield this.axios.post(`chat/${encodeURIComponent(e.chatId)}/member`,e)})),this.sendThreadMessage=({body:e,threadId:t})=>de(this,void 0,void 0,(function*(){const{data:n}=yield this.axios.post(`thread/${encodeURIComponent(t)}/message`,{body:e});return n})),this.readThreadMessage=e=>de(this,void 0,void 0,(function*(){yield this.axios.put(`thread/message/${encodeURIComponent(e)}/read`)})),this.watchThreads=()=>de(this,void 0,void 0,(function*(){const{data:e}=yield this.axios.get("thread/watch");return e})),this.thread=e=>de(this,void 0,void 0,(function*(){const{data:t}=yield this.axios.get(`thread/${encodeURIComponent(e)}`);return t})),this.threadMessages=({threadId:e,skip:t,take:n})=>de(this,void 0,void 0,(function*(){const a=new URLSearchParams;a.append("skip",t.toString()),a.append("take",n.toString());const{data:s}=yield this.axios.get(`thread/${encodeURIComponent(e)}/message?${a.toString()}`);return s})),this.watchThread=(e,t)=>de(this,void 0,void 0,(function*(){yield this.axios.put(`thread/${encodeURIComponent(e)}/watch`,{watch:t})})),this.connectToThread=e=>de(this,void 0,void 0,(function*(){var t;const n=null!==(t=this._threadConnectionByThreadId.get(e))&&void 0!==t?t:0;this._threadConnectionByThreadId.set(e,n+1),0===n&&this.connect().then((()=>this._connection.invoke("ConnectToThread",e)))})),this.disconnectFromThread=e=>de(this,void 0,void 0,(function*(){var t;const n=null!==(t=this._threadConnectionByThreadId.get(e))&&void 0!==t?t:0;this._threadConnectionByThreadId.set(e,Math.max(0,n-1)),1===n&&this.connect().then((()=>this._connection.invoke("DisconnectFromThread",e)))})),this._config=Object.assign(Object.assign({},e),{signalR:Object.assign(Object.assign({},je),e.signalR)})}get axios(){return this._config.axios}}function Be(...e){const t=()=>e.forEach((e=>e()));return t.when=e=>e.then(t),t}const De=new le({callback:e=>he.client.readThreadMessage(e),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>ie(e)[0],timeout:500}),qe=new le({callback:e=>he.client.readChatMessage({id:e}),compare:(e,t)=>-e.localeCompare(t),groupBy:e=>se(e),timeout:500}),Ue=me.injectEndpoints({endpoints:e=>({getAccountList:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.accounts()}})),providesTags:["account"]}),getChat:e.query({queryFn:({id:e})=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.chat(e)}})),providesTags:["chat","account"],onCacheEntryAdded:({id:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,Be(he.client.subscribe("chatify://chat-member-added",(([t,n,s,i,,c])=>t===e&&a((e=>{e.members.push(s),e.lastReadMessageId=c?i.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-member-removed",(([t,n,,s,i])=>e===t&&a((e=>{e.members=e.members.filter((e=>e.id!==n)),e.lastReadMessageId=i?s.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-name-changed",(([t,n,s,i])=>e===t&&a((e=>{e.name=n,e.lastReadMessageId=i?s.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-new-message",(([t])=>e===t.chatId&&a((e=>{e.lastReadMessageId=t.sentBy.id===he.me()?t.id:e.lastReadMessageId})))),he.client.subscribe("chatify://chat-message-read",(([t])=>t.find((t=>t.chatId===e))&&a((n=>{const a=t.find((t=>t.chatId===e));n.lastReadMessageId=a.newLastReadMessageId}))))).when(t)}))}),addChat:e.mutation({queryFn:({name:e,members:t})=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.addChat({name:e,members:t})}}))}),updateChatName:e.mutation({queryFn:({id:e,name:t})=>de(void 0,void 0,void 0,(function*(){return yield he.client.updateChatName({id:e,name:t}),{data:null}}))}),getChatList:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.chats()}})),providesTags:["chat","account"],onCacheEntryAdded:(e,{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,Be(he.client.subscribe("chatify://chat-created",(([e])=>a((t=>{t.push(e)})))),he.client.subscribe("chatify://chat-new-message",(([e])=>a((t=>{const n=t.find((t=>t.id===e.chatId));n&&(n.message=e,e.sentBy.id===he.me()&&(n.lastReadMessageId=e.id,n.totalUnreadCount=0),e.sentBy.id!==he.me()&&n.totalUnreadCount++)})))),he.client.subscribe("chatify://chat-message-read",(([e])=>a((t=>{for(const n of e){const e=t.find((e=>e.id===n.chatId));if(!e)return;e.lastReadMessageId=n.newLastReadMessageId,e.totalUnreadCount=e.totalUnreadCount-n.readCount}})))),he.client.subscribe("chatify://chat-member-added",(([e,t,n,s,,i])=>a((a=>{const c=a.find((t=>t.id===e));n.id!==he.me()||c||a.push({id:e,name:t,message:s,totalUnreadCount:i?0:1,active:!0,lastReadMessageId:i?s.id:null}),c&&(c.message=s,c.active=!0,i?(c.totalUnreadCount=0,c.lastReadMessageId=s.id):c.totalUnreadCount++)})))),he.client.subscribe("chatify://chat-member-removed",(([e,t,n,s,i])=>a((a=>{if(t===he.me()&&n)return a.filter((t=>t.id!==e));const c=a.find((t=>t.id===e));c&&(c.message=s,t===he.me()&&(c.active=!1),i?(c.totalUnreadCount=0,c.lastReadMessageId=s.id):c.totalUnreadCount++)})))),he.client.subscribe("chatify://chat-name-changed",(([e,t,n,s])=>a((a=>{const i=a.find((t=>t.id===e));i&&(i.name=t,i.message=n,s?(i.totalUnreadCount=0,i.lastReadMessageId=n.id):i.totalUnreadCount++)}))))).when(t)}))}),removeChatMember:e.mutation({queryFn:e=>de(void 0,void 0,void 0,(function*(){return yield he.client.removeChatMember(e),{data:null}}))}),addChatMember:e.mutation({queryFn:e=>de(void 0,void 0,void 0,(function*(){return yield he.client.addChatMember(e),{data:null}}))}),getChatMessageList:e.query({queryFn:({chatId:e})=>de(void 0,void 0,void 0,(function*(){const t=yield he.client.chatMessages({chatId:e,skip:0,take:21});return{data:{messages:t.slice(0,ue),hasMore:21===t.length}}})),providesTags:["message","chat","account"],onCacheEntryAdded:({chatId:e},{dispatch:t,cacheEntryRemoved:n,cacheDataLoaded:a})=>de(void 0,void 0,void 0,(function*(){yield a,Be(he.client.subscribe("chatify://chat-new-message",(([n])=>{n.chatId===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(n)})))})),he.client.subscribe("chatify://chat-member-added",(([n,,,a])=>{n===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))})),he.client.subscribe("chatify://chat-member-removed",(([n,,,a])=>{n===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))})),he.client.subscribe("chatify://chat-name-changed",(([n,,a])=>{n===e&&t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.messages.unshift(a)})))}))).when(n)}))}),fetchNextChatMessageList:e.mutation({queryFn:({chatId:e},{getState:t})=>de(void 0,void 0,void 0,(function*(){const n=Pe.endpoints.getChatMessageList.select({chatId:e})(t()),a=yield he.client.chatMessages({chatId:e,skip:n.data.messages.length,take:21});return{data:null,meta:{messages:a.slice(0,ue),hasMore:21===a.length}}})),onQueryStarted:({chatId:e},{dispatch:t,queryFulfilled:n})=>de(void 0,void 0,void 0,(function*(){const a=(yield n).meta;t(Pe.util.updateQueryData("getChatMessageList",{chatId:e},(e=>{e.hasMore=a.hasMore,e.messages.push(...a.messages)})))}))}),sendChatMessage:e.mutation({queryFn:({chatId:e,text:t,files:n})=>de(void 0,void 0,void 0,(function*(){return yield he.client.sendChatMessage({chatId:e,text:t,files:n}),{data:null}}))}),readChatMessage:e.mutation({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:null}})),onQueryStarted:({id:e},{dispatch:t})=>de(void 0,void 0,void 0,(function*(){qe.push(e),t(Pe.endpoints.getChatMessageReadQueue.initiate(void 0,{forceRefetch:!0}))}))}),getChatMessageReadQueue:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:qe.units}})),onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n})=>de(void 0,void 0,void 0,(function*(){Be(qe.subscribe((e=>{t(Pe.util.updateQueryData("getChatMessageReadQueue",void 0,(()=>e.units)))}))).when(n)}))}),getWatchThreadList:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.watchThreads()}})),providesTags:["account","thread"],onCacheEntryAdded:(e,{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,Be(he.client.subscribe("chatify://thread-created",(([e,t])=>t&&a((t=>{t.push(e)})))),he.client.subscribe("chatify://thread-message-new",(([e,t,n])=>a((a=>{const s=a.find((t=>t.id===e));s&&(s.lastMessage=t,n===he.me()&&(s.lastReadMessageId=t.id))})))),he.client.subscribe("chatify://thread-message-read",(([e,t])=>a((n=>{const a=n.find((t=>t.id===e));a&&(a.lastReadMessageId=t)})))),he.client.subscribe("chatify://thread-watch-added",(([e])=>a((t=>{t.push(e)})))),he.client.subscribe("chatify://thread-watch-removed",(([e])=>a((t=>{const n=t.findIndex((t=>t.id===e));-1!==n&&t.splice(n,1)})))),he.client.subscribe("chatify://thread-updated",(([e,t])=>a((n=>{const a=n.find((t=>t.id===e));a&&(a.name=t)}))))).when(t)}))}),getThread:e.query({queryFn:({id:e})=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.thread(e)}})),providesTags:["account","thread"],onCacheEntryAdded:({id:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,Be(he.client.subscribe("chatify://thread-message-read",(([t,n])=>e===t&&a((e=>{e.lastReadMessageId=n})))),he.client.subscribe("chatify://thread-message-new",(([t,n,s])=>e===t&&a((e=>{e.lastMessageId=n.id,e.lastReadMessageId=s===he.me()?n.id:e.lastReadMessageId})))),he.client.subscribe("chatify://thread-watch-added",(([t])=>e===t.id&&a((e=>{var n,a,s;e.watch=!0,e.lastMessageId=null!==(a=null===(n=t.lastMessage)||void 0===n?void 0:n.id)&&void 0!==a?a:null,e.lastReadMessageId=null!==(s=t.lastReadMessageId)&&void 0!==s?s:null})))),he.client.subscribe("chatify://thread-watch-removed",(([t])=>e===t&&a((e=>{e.watch=!1})))),he.client.subscribe("chatify://thread-updated",(([t,n])=>e===t&&a((e=>{e.name=n}))))).when(t)}))}),watchThread:e.mutation({queryFn:({id:e,watch:t})=>de(void 0,void 0,void 0,(function*(){return yield he.client.watchThread(e,t),{data:null}}))}),getThreadMessageList:e.query({queryFn:e=>de(void 0,void 0,void 0,(function*(){const t=Object.assign({skip:0,take:21},e),n=yield he.client.threadMessages(t);return{data:{messages:n.slice(0,ue),hasMore:21===n.length}}})),providesTags:["account","thread","thread-message"],onCacheEntryAdded:({threadId:e},{cacheEntryRemoved:t,cacheDataLoaded:n,updateCachedData:a})=>de(void 0,void 0,void 0,(function*(){yield n,Be(he.client.subscribe("chatify://thread-message-new",(([t,n])=>{e===t&&a((e=>{!e.messages.some((e=>e.id===n.id))&&e.messages.unshift(n)}))}))).when(t)}))}),fetchNextThreadMessageList:e.mutation({queryFn:({threadId:e},{getState:t})=>de(void 0,void 0,void 0,(function*(){const n=Pe.endpoints.getThreadMessageList.select({threadId:e})(t()),a=yield he.client.threadMessages({threadId:e,skip:n.data.messages.length,take:21});return{data:null,meta:{messages:a.slice(0,ue),hasMore:21===a.length}}})),onQueryStarted:({threadId:e},{dispatch:t,queryFulfilled:n})=>de(void 0,void 0,void 0,(function*(){const a=(yield n).meta;t(Pe.util.updateQueryData("getThreadMessageList",{threadId:e},(e=>{e.hasMore=a.hasMore,e.messages.push(...a.messages)})))}))}),sendThreadMessage:e.mutation({queryFn:e=>de(void 0,void 0,void 0,(function*(){return{data:yield he.client.sendThreadMessage(e)}}))}),readThreadMessage:e.mutation({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:null}})),onQueryStarted:({id:e},{dispatch:t})=>de(void 0,void 0,void 0,(function*(){De.push(e),t(Pe.endpoints.getThreadMessageReadQueue.initiate(void 0,{forceRefetch:!0}))}))}),getThreadMessageReadQueue:e.query({queryFn:()=>de(void 0,void 0,void 0,(function*(){return{data:De.units}})),onCacheEntryAdded:(e,{dispatch:t,cacheEntryRemoved:n})=>de(void 0,void 0,void 0,(function*(){Be(De.subscribe((e=>{t(Pe.util.updateQueryData("getThreadMessageReadQueue",void 0,(()=>e.units)))}))).when(n)}))})})});function Qe(e){return ke((t=>{var n;return null!=e?null===(n=Ue.endpoints.getChatList.select()(t).data)||void 0===n?void 0:n.find((t=>t.id===e)):null}))}function Ge(){const e=Pe.useGetWatchThreadListQuery(),{data:t}=e,n=oe(e,["data"]);return[r((()=>null!=t?re(t):null),[t]),n]}const Pe=Object.assign(Ue,{settings:he,useChatListItem:Qe,useUnreadThreadMessageCount:Ge}),Ve=o(((t,n)=>{const{account:a}=t;return e(f,{ref:n,src:a.avatar})}));Ve.displayName="Avatar";const $e=Y("Avatar",Ve);function ze(e,t,n){const[a,s]=Pe.useAddChatMemberMutation();return[d((()=>a({chatId:e,accountId:t,withHistory:n})),[a,e,t,n]),s]}function He(e,t,n){const[a,s]=Pe.useRemoveChatMemberMutation();return[d((()=>a({chatId:e,accountId:t,deleteHistory:n})),[a,e,t,n]),s]}const Ke=Y("ChatMemberListItem",(n=>{const{chatId:a}=n,{data:s}=Pe.useGetChatQuery({id:a}),{data:i}=Pe.useGetAccountListQuery(),c=i.find((e=>e.id===n.id)),r=s.members.some((e=>e.id===c.id)),[o]=ze(a,c.id,!1),[d]=ze(a,c.id,!0),[l]=He(a,c.id,!1),[u]=He(a,c.id,!0);return e(v.Item,{className:"wxchtf-chat-members-list-item",actions:r?[e(y,{title:"Remove (keep history)",children:e(g,{onClick:l,type:"link",icon:e(X,{type:"remove-member"})})},"remove"),e(y,{title:"Remove (delete history)",children:e(g,{onClick:u,type:"link",icon:e(X,{type:"remove-member-delete-history"})})},"remove_delete_history")]:[e(y,{title:"Add (no history)",children:e(g,{onClick:o,type:"link",icon:e(X,{type:"add-member"})})},"add_no_history"),e(y,{title:"Add (share history)",children:e(g,{onClick:d,type:"link",icon:e(X,{type:"add-member-with-history"})})},"add")],children:t(p,{children:[e($e,{account:c}),e("span",{children:c.name})]})})})),We=Y("ChatMembersPanel",(()=>{const{id:t}=ee(),{data:n}=Pe.useGetChatQuery({id:t}),{data:a}=Pe.useGetAccountListQuery(),s=r((()=>null==a?void 0:a.slice().sort(((e,t)=>((null==n?void 0:n.members.some((t=>t.id===e.id)))?-100:0)-((null==n?void 0:n.members.some((e=>e.id===t.id)))?-100:0)+e.name.localeCompare(t.name)))),[a,n]);return(null==n?void 0:n.members)&&a?e("div",{className:"wxchtf-chat-members-panel",children:e(v,{className:"wxchtf-chat-members-list",dataSource:s,renderItem:n=>e(Ke,{id:n.id,chatId:t})})}):null})),Ye=Y("ChatMembersPreview",(()=>{const{id:t}=ee(),{data:n}=Pe.useGetChatQuery({id:t});return(null==n?void 0:n.members)?e(f.Group,{maxCount:5,children:n.members.map((t=>e(y,{title:t.name,children:e($e,{account:t})},t.id)))}):null})),Je=Y("InputFileButton",(a=>{const{onUpload:s,onAddedClick:i,accept:c,loading:r,value:o,disabled:h}=a,m=l(null),f=d((()=>{var e;return null===(e=m.current)||void 0===e?void 0:e.click()}),[]),v=l(null);u((()=>{var e;null===(e=v.current)||void 0===e||e.classList.add("active")}),[o]);const y=d((()=>{var e;null===(e=v.current)||void 0===e||e.classList.remove("active")}),[]),p=d((e=>{const t=e.target.files;t&&t.length>0&&s(Array.from(t))}),[s]);return t(n,{children:[e(g,{loading:r,onClick:f,type:"link",disabled:h,icon:e(X,{type:"attach"}),className:"wxchtf-add-files-btn"}),o.length>0&&e(g,{ref:v,className:"wxchtf-add-files-added-btn",onAnimationIteration:y,onClick:i,type:"link",disabled:h,icon:t(n,{children:["+",o.length]})}),e("input",{value:"",accept:c,onChange:p,ref:m,type:"file",multiple:!0,style:{display:"none"}})]})})),Xe=Y("InputFilesBox",(t=>e("div",{className:"wxchtf-add-files-box",children:e(Je,Object.assign({},t))}))),Ze=s.createContext(null);function et(){return i(Ze)}const tt={isToday:e=>P(e).isSame(P(),"day"),timestamp:e=>P(e).format("HH:mm"),dateTime:e=>P(e).format("DD/MM/YYYY HH:mm"),message:{read:()=>"Read",reading:()=>"Reading...",sending:()=>"Sending..."},addChat:{title:()=>"Add chat",name:{label:()=>"Name",required:()=>"Name is required",max250:()=>"Max 250 characters allowed"},members:{label:()=>"Members",required:()=>"Members is required"},submitBtn:()=>"Submit"},system:{"chatify://chat-created":()=>"Chat created","chatify://member-added":()=>"New member added","chatify://member-removed":()=>"Member removed","chatify://chat-name-changed":(e,{newName:t})=>`Chat name changed to '${t}'`},input:{placeholder:()=>"Start typing... (Press Enter to send, and Shift+Enter to start a new line)"},settings:{members:()=>"Members"},size:{bytes:e=>`${e.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2})} bytes`,kb:e=>`${e.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2})} KB`,mb:e=>`${e.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2})} MB`}},nt=G("enter"),at=G("ctrl+enter"),st={maxRows:5,minRows:1},it=Y("InputTextBox",h((t=>{const{value:n,onChange:a,onSend:s,disabled:i,inputRef:c}=t,r=et(),o=d((e=>a(e.target.value)),[a]),l=d((e=>{i?e.preventDefault():(nt(e)||at(e))&&(e.preventDefault(),s(n))}),[s,n,i]);return e("div",{className:"wxchtf-text-input-box",children:e(b.TextArea,{ref:c,value:n,onChange:o,autoSize:st,className:"wxchtf-text-input-textarea",placeholder:r.input.placeholder(),onKeyDown:l})})}))),ct=Y("InputSubmitButtonBox",(t=>{const{onSubmit:n,disabled:a,loading:s}=t;return e("div",{className:"wxchtf-submit-btn-box",children:e(g,{onClick:n,type:"link",icon:e(X,{type:"send"}),className:"wxchtf-submit-btn",disabled:a,loading:s})})})),rt=s.createContext(void 0);function ot(){return s.useContext(rt)}const dt=Y("MessageSkeleton",(a=>{const{count:s=1}=a;return e(n,{children:Array.from(Array(s)).map(((n,a)=>t("div",{className:"wxchtf-message-skeleton",children:[e(w.Avatar,{className:"wxchtf-avatar",active:!0}),e(w.Button,{active:!0,className:"wxchtf-content"})]},a)))})}));function lt(){const e=et();return{size:t=>t<1024?e.size.bytes(t):t<1048576?e.size.kb(t/1024):e.size.mb(t/1024/1024)}}const ut=Y("InputBoxFile",(n=>{const{file:a,disabled:s,onDelete:i}=n,c=lt(),r=d((()=>i(a)),[a,i]);return t("div",{className:"wxchtf-file",children:[t("div",{className:"wxchtf-file-info",children:[e("div",{className:"wxchtf-file-name",title:a.name,children:a.name}),e("div",{className:"wxchtf-file-size",children:c.size(a.bytes)})]}),e("div",{className:"wxchtf-file-actions",children:e(g,{disabled:s,className:"wxchtf-delete",type:"link",icon:e(X,{type:"delete-file"}),onClick:r})})]})})),ht=Y("InputBoxFileList",(t=>{const{files:n,onDelete:a,disabled:s}=t;return e("div",{className:"wxchtf-file-list",children:n.map((t=>e(ut,{file:t,onDelete:a,disabled:s},t.ref)))})}));function mt(){const{onSend:e}=ot(),[t,n]=c(""),[a,s]=c(!1),{onUpload:i,files:r,loading:o,setFiles:l,showFileBox:u,onDeleteFile:h}=function(){const[e,t]=c(!1),[n,a]=c([]),{flippo:s}=H(),i=d((e=>{s&&(t(!0),Promise.all(e.map((e=>s.store(e)))).then((t=>a((n=>[...n,...t.map(((t,n)=>({name:e[n].name,ref:t,bytes:e[n].size})))])))).finally((()=>t(!1))))}),[s]),r=d((e=>{a((t=>t.filter((t=>t!==e))))}),[]);return{onUpload:i,files:n,loading:e,setFiles:a,showFileBox:!!s,onDeleteFile:r}}();return[d((()=>{const a=0===t.trim().length?null:t.trim();!a&&0===r.length||o||(s(!0),Promise.resolve(e({text:a,files:r})).finally((()=>s(!1))).then((()=>{l([]),n("")})))}),[t,e,r,l,o]),{text:t,setText:n,files:r,onUpload:i,loading:o,showFileBox:u,onDeleteFile:h,sending:a}]}const gt=Y("InputBox",(()=>{const[n,{text:a,setText:s,files:i,loading:r,onUpload:o,showFileBox:h,onDeleteFile:g,sending:f}]=mt(),v=l(null),[y,p]=c(!1),b=d((()=>p((e=>!e))),[]),w=l(i.length);return m((()=>{var e;return null===(e=v.current)||void 0===e?void 0:e.focus()}),[]),u((()=>{0===w.current&&i.length>0&&!y&&p(!0),w.current=i.length,0===i.length&&y&&p(!1)}),[i,y]),e("div",{className:"wxchtf-input-form",children:t("div",{className:"wxchtf-input-box",children:[y&&e("div",{className:"wxchtf-file-list-box",children:e(ht,{files:i,onDelete:g,disabled:f})}),t("div",{className:"wxchtf-input-box-row",children:[h&&e(Xe,{onAddedClick:b,onUpload:o,value:i,loading:r,disabled:f}),e(it,{value:a,onSend:n,onChange:s,disabled:f,inputRef:v}),e(ct,{onSubmit:n,disabled:r,loading:f})]})]})})})),ft=Y("MessageAuthor",(t=>{const{sentBy:n}=t.message;return e("div",{className:"wxchtf-message-author",children:e($e,{account:n})})})),vt=t=>{const{message:a,messageRef:s}=t,{onRead:i,lastReadMessageId:c}=ot(),o=null!=c&&a.id.localeCompare(c)<=0,d=l(o);u((()=>{d.current=d.current||o}),[o]);const h=r((()=>new IntersectionObserver((([e])=>{e.isIntersecting&&!d.current&&(d.current=!0,i(a.id))}))),[]);return u((()=>(h.observe(s.current),()=>h.disconnect())),[h]),e(n,{})};function yt(t){const{noReadTracking:n}=ot();return!0===n?null:e(vt,Object.assign({},t))}const pt=Y("MessageText",(t=>{const{text:n}=t.message;return e("div",{className:"wxchtf-message-text",children:n})}));function bt(e){const t=window.open(e,"_blank");null==t||t.focus()}const wt=Y("MessageFile",(n=>{const{file:a}=n,s=lt(),[i,{isOpenFetching:r}]=function(e){const{file:t}=e,{flippo:n}=H(),[a,s]=c(!1);return[d((()=>n&&Promise.resolve(s(!0)).then((()=>n.getSasUrl(t.ref))).then(bt).finally((()=>s(!1)))),[n,t.ref]),{isOpenFetching:a}]}(n);return t("div",{className:"wxchtf-file",children:[e("div",{className:"wxchtf-icon",children:e(g,{loading:r,onClick:i,type:"link",icon:e(X,{type:"open-file"})})}),t("div",{className:"wxchtf-file-info",children:[e("div",{className:"wxchtf-name",title:a.name,children:a.name}),e("div",{className:"wxchtf-size",children:s.size(a.bytes)})]})]})})),Ct=Y("MessageFileList",(t=>{const{files:n}=t.message;return e("div",{className:"wxchtf-file-list",children:n.map((t=>e(wt,{file:t},t.ref)))})})),xt=Y("MessageContent",(n=>{const{files:a,text:s}=n.message;return t("div",{className:"wxchtf-message-content",children:[s&&e(pt,Object.assign({},n)),a.length>0&&e(Ct,Object.assign({},n))]})})),Mt=Y("MessageInfoBox",(n=>{const{message:a}=n,{id:s,sentBy:i,sentAt:c}=a,{lastReadMessageId:r,isReading:o,noReadTracking:d}=ot(),l=Pe.settings.me(),u=i.id===l,h=et(),m=!(null!=r&&s.localeCompare(r)<=0)&&o(s);return t("div",{className:"wxchtf-message-info-box",children:[!u&&t("div",{className:"wxchtf-message-author-name",children:[i.name,","]}),e("div",{className:"wxchtf-message-sent-at",children:h.timestamp(c)}),!u&&!d&&e("div",{className:"wxchtf-message-read-box",children:m?h.message.reading():h.message.read()})]})})),It=Y("MessageRow",(n=>{const{message:a,containerRef:s}=n,{sentBy:i}=a,c=Pe.settings.me(),r=i.id===c;return t("div",{ref:s,className:"wxchtf-message"+(r?" --my":""),children:[e(ft,Object.assign({},n)),t("div",{children:[e(Mt,Object.assign({},n)),e(xt,Object.assign({},n))]})]})})),Nt=Y("MessageBox",(a=>{const s=l(null);return t(n,{children:[e(yt,Object.assign({messageRef:s},a)),e(It,Object.assign({containerRef:s},a))]})}));function Ot(t){const{onLoad:n,loading:a}=t,[s,i]=c(!1),o=l(null),d=l(),h=r((()=>new IntersectionObserver((([e])=>{e.isIntersecting?d.current=window.setTimeout((()=>i(!0)),200):clearTimeout(d.current)}))),[]);return u((()=>(h.observe(o.current),()=>h.disconnect())),[h]),u((()=>{s&&n()}),[s]),a||s?e(dt,{count:4}):e("div",{className:"wxchtf-next",ref:o})}const Rt=Y("SendingMessageText",(t=>{const{text:n}=t;return e("div",{className:"wxchtf-sending-message-text",children:n})})),_t=Y("SendingMessageInfoBox",(t=>{const n=et();return e("div",{className:"wxchtf-sending-message-info-box",children:e("div",{className:"wxchtf-sending-message-sending-box",children:n.message.sending()})})})),St=Y("SendingMessageContent",(n=>t("div",{className:"wxchtf-sending-message-content",children:[e(Rt,Object.assign({},n)),e(_t,Object.assign({},n))]}))),Tt=Y("SendingMessageBox",(t=>e("div",{className:"wxchtf-sending-message",children:e(St,Object.assign({},t))})));function kt(e,t){const[n,a]=t.split("::",2),s=a?JSON.parse(a):null;return e.system[n](n,s)}const Lt=Y("SystemMessageRow",(n=>{const{message:a,containerRef:s}=n,{text:i,sentAt:c}=a,r=et();return t("div",{ref:s,className:"wxchtf-system-message",children:[e("div",{className:"wxchtf-text",children:i&&kt(r,i)}),e("div",{className:"wxchtf-timestamp",children:r.timestamp(c)})]})})),Et=Y("SystemMessageBox",(a=>{const s=l(null);return t(n,{children:[e(yt,Object.assign({messageRef:s},a)),e(Lt,Object.assign({containerRef:s},a))]})})),jt=Y("ConversationActions",(()=>null)),Ft=Y("ConversationBody",(()=>{const{id:n,messages:a=[],hasMore:s,onNext:i,nextLoading:c}=ot();return t("div",{className:"wxchtf-conversation-body",children:[!a&&e(dt,{count:5}),null==a?void 0:a.map((t=>t.sentBy.id===ae?e(Et,{message:t},t.id):e(Nt,{message:t},t.id))),s&&e(Ot,{onLoad:i,loading:c},a.length+n)]})})),At=Y("ConversationName",(()=>{const{name:t}=ot();return e("span",{className:"wxchtf-conversation-name",children:t})})),Bt=Y("ConversationHeader",(()=>{const n=W(jt);return e("div",{className:"wxchtf-conversation-header",children:t(C,{justify:"space-between",align:"middle",children:[e(x,{children:e(At,{})}),n&&e(x,{className:"wxchtf-conversation-actions",children:e(n,{})})]})})})),Dt=Y("Conversation",(n=>{const{value:a,hasMore:s,messages:i,nextLoading:c,onNext:o,onRead:d,onSend:l,isReading:u,noReadTracking:h}=n,{id:m,active:g,name:f,lastReadMessageId:v}=a,y=r((()=>({id:m,name:f,active:g,lastReadMessageId:v,hasMore:s,messages:i,nextLoading:c,onNext:o,onRead:d,onSend:l,isReading:u,noReadTracking:h})),[m,f,g,o,d,l,s,i,c,v,u,h]);return e(rt.Provider,{value:y,children:e("div",{className:"wxchtf-conversation",children:t("div",{className:"wxchtf-conversation-main",children:[e(Bt,{}),e(Ft,{}),g&&e(gt,{})]})})})})),qt=G("escape"),Ut=G("enter");const Qt=Y("ChatEditableHeaderName",(()=>{const{id:t,name:n,active:a}=ot(),[s,i]=c(""),[r,o]=c(!1),d=function(e,t){const[n]=Pe.useUpdateChatNameMutation();return()=>n({id:e,name:t})}(t,s);return u((()=>{r&&i(null!=n?n:"")}),[r,n]),a?e(y,r?{defaultOpen:!0,title:"Press Enter to save new chat name or Escape to cancel editing",children:e(b,{value:s,onChange:e=>i(e.target.value),onBlur:()=>o(!1),onKeyDown:e=>{qt(e)?o(!1):Ut(e)&&(o(!1),s!==n&&""!==s.trim()&&d())},autoFocus:!0})}:{title:"Click to edit name...",children:e("span",{className:"wxchtf-conversation-name --editable",onClick:()=>o(!0),children:n})}):e("span",{className:"wxchtf-conversation-name",children:n})})),Gt=Y("ChatHeaderActions",(()=>{const{active:n}=ot();return n?t("div",{className:"wxchtf-chat-members",children:[e(Ye,{}),e(ne,{})]}):null})),Pt={ConversationName:()=>e(Qt,{}),ConversationActions:()=>e(Gt,{})};function Vt(n){const a=function(e){const{value:t}=e,{id:n,name:a,active:s,lastReadMessageId:i}=t,{data:c}=Pe.useGetChatMessageListQuery({chatId:n}),{messages:o,hasMore:l}=null!=c?c:{},[u,{isLoading:h}]=Pe.useFetchNextChatMessageListMutation(),m=d((()=>u({chatId:n})),[u,n]),[g]=Pe.useReadChatMessageMutation(),f=d((e=>g({id:e})),[g]),[v]=Pe.useSendChatMessageMutation(),y=d((e=>v(Object.assign(Object.assign({},e),{chatId:n})).unwrap()),[n,v]),{data:p}=Pe.useGetChatMessageReadQueueQuery();return r((()=>{if(!n)return null;const e={value:{id:n,name:a,active:s,lastReadMessageId:i},messages:o,hasMore:l,onNext:m,nextLoading:h,onRead:f,onSend:y,isReading:e=>p.some((t=>se(t.value)===se(e)&&e<=t.value))};return e}),[m,f,y,h,n,a,s,o,l,i,p])}(n),{showMembers:s}=ee();return a?t("div",{className:"wxchtf-chat",children:[e(Dt,Object.assign({},a)),s&&e(We,{})]}):null}const $t=Y("ChatView",(t=>{const{value:n}=t,a=H(),s=r((()=>Object.assign(Object.assign({},null!=a?a:{}),Pt)),[a]);return e(z.Provider,{value:s,children:e(te,{id:n.id,children:e(Vt,{value:n})})})}));function zt(t){const{id:n,className:a="",customize:s,localizer:i=tt,style:c}=t,{data:r}=Pe.useGetChatQuery({id:n});return e("div",{className:`wxchtf-chatify wxchtf-chat-panel ${a}`,style:c,children:e(Ze.Provider,{value:i,children:e(z.Provider,{value:s,children:r&&e($t,{value:r},n)})})})}const Ht=Y("CreateChatNameInput",(t=>{const{name:n}=t,a=et();return e(M.Item,{name:n,label:a.addChat.name.label(),rules:[{required:!0,message:a.addChat.name.required()},{max:250,message:a.addChat.name.max250()}],children:e(b,{})})}));function Kt(t){const{value:n,onChange:a}=t,{data:s,isFetching:i}=Pe.useGetAccountListQuery(),c=Pe.settings.me(),o=r((()=>{var e;return null!==(e=null==s?void 0:s.filter((e=>e.id!==c)))&&void 0!==e?e:[]}),[s,c]);return e(v,{rowKey:"id",className:"wxchtf-create-chat-member-input-list",loading:i,dataSource:o,renderItem:t=>{const s=n.includes(t.id);return e(v.Item,{className:s?"--selected":"",children:e(I,{checked:s,onChange:()=>a(n.includes(t.id)?n.filter((e=>e!==t.id)):[...n,t.id]),children:e(v.Item.Meta,{avatar:e($e,{account:t}),title:t.name})})})}})}const Wt=Y("CreateChatMemberInput",(t=>{const{name:n}=t,a=et();return e(M.Item,{label:a.addChat.members.label(),rules:[{required:!0,message:a.addChat.members.required()}],name:n,children:e(Kt,{})})})),Yt={name:"",members:[]},Jt=Y("CreateChatForm",(n=>{const{value:a=Yt,onSubmit:s,busy:i=!1}=n,c=et();return t(M,{onFinish:s,layout:"vertical",disabled:i,initialValues:a,children:[e(Ht,{name:"name"}),e(Wt,{name:"members"}),e(g,{loading:i,type:"primary",block:!0,htmlType:"submit",children:c.addChat.submitBtn()})]})})),Xt=s.createContext(null);function Zt(){return i(Xt)}function en(t){const{children:n}=t,[a,s]=c({chatId:null,view:null,showMembers:!1}),i=r((()=>Object.assign(Object.assign({},a),{openChat:e=>s((t=>Object.assign(Object.assign({},t),{view:"chat",chatId:e}))),none:()=>s((e=>Object.assign(Object.assign({},e),{view:null,chatId:null}))),toggleMembers:()=>s((e=>Object.assign(Object.assign({},e),{showMembers:!e.showMembers}))),toggleNewChat:()=>s((e=>"new-chat"!==e.view||e.chatId?"new-chat"===e.view&&e.chatId?Object.assign(Object.assign({},e),{view:"chat"}):Object.assign(Object.assign({},e),{view:"new-chat"}):Object.assign(Object.assign({},e),{view:null})))})),[a]);return e(Xt.Provider,{value:i,children:n})}const tn=Y("CreateChatPanel",(()=>{const n=et(),[a,s]=function(){const[e,{isLoading:t}]=Pe.useAddChatMutation(),{openChat:n}=Zt();return[d((t=>e({name:t.name,members:t.members}).unwrap().then((e=>n(e)))),[e,n]),t]}(),{toggleNewChat:i}=Zt();return t("div",{className:"wxchtf-create-chat-panel",children:[e(g,{onClick:()=>i(),className:"wxchtf-create-chat-panel-close",type:"link",icon:e(X,{type:"close"})}),e("h3",{children:n.addChat.title()}),e(Jt,{busy:null!=s&&s,onSubmit:a})]})})),nn=Y("CreateChatButton",(()=>{const{toggleNewChat:t}=Zt();return e("span",{className:"wxchtf-add-btn-wrapper",children:e(g,{className:"wxchtf-add-btn",onClick:t,icon:"+",children:"Add chat"})})})),an=Y("ChatListItemName",(t=>{const{chat:n}=t;return e("div",{className:"wxchtf-chat-name",children:n.name})})),sn=Y("ChatListItemUnreadCount",(t=>{const{totalUnreadCount:n}=t.chat;return n<=0?null:e("div",{className:"wxchtf-unread-count",children:n})})),cn=Y("ChatListItemLastMessageContent",(t=>{const{message:n}=t.chat,a=et();return e("div",{className:"wxchtf-chat-last-message",children:"chatify::system"===n.sentBy.id?n.text&&kt(a,n.text):n.text})})),rn=Y("ChatListItemLastMessageAuthor",(t=>{const{message:n}=t.chat;return"chatify::system"===n.sentBy.id?null:e("div",{className:"wxchtf-chat-last-author",children:n.sentBy.name})})),on=Y("ChatListItemLastMessageSentAt",(t=>{const{chat:{message:{sentAt:n}}}=t,a=et();return e("div",{className:"wxchtf-chat-last-sent-at",children:a.isToday(n)?a.timestamp(n):a.dateTime(n)})})),dn=Y("ChatListItemLastMessage",(n=>t("div",{className:"wxchtf-chat-last",children:[e(rn,Object.assign({},n)),e(cn,Object.assign({},n)),e(on,Object.assign({},n))]}))),ln=Y("ChatListItemAvatar",(t=>{const{id:n}=t.chat;return e("div",{className:"wxchtf-chat-avatar",style:{"--background-color":$(n,{lightness:90}),"--color":$(n,{saturation:60,lightness:65})},children:e(X,{type:"chat"})})})),un=Y("ChatListItemBox",(n=>{const{message:a,lastReadMessageId:s}=n.chat,i=null!=s&&s.localeCompare(a.id)>=0;return t("div",{className:"wxchtf-chat"+(i?"":" --unread"),children:[e(ln,Object.assign({},n)),t("span",{className:"wxchtf-chat-info",children:[e(an,Object.assign({},n)),e(sn,Object.assign({},n)),e(dn,Object.assign({},n))]})]})}));const hn=Y("ChatList",(()=>{const{chatId:t}=Zt(),a=r((()=>t?[t]:[]),[t]),s=function(){const{openChat:e}=Zt();return d((t=>e(t.key)),[e])}(),i=function(){const{data:t}=Pe.useGetChatListQuery();return r((()=>null==t?void 0:t.slice().sort(((e,t)=>-e.message.id.substring(47).localeCompare(t.message.id.substring(47)))).map((t=>({key:t.id,label:e(un,{chat:t})})))),[t])}();return e(n,{children:i&&e(N,{className:"wxchtf-chat-list",selectedKeys:a,onSelect:s,items:i})})})),mn=Y("ChatGroupAside",(()=>t("div",{className:"wxchtf-aside",children:[e(nn,{}),e(hn,{})]}))),gn=Y("ChatGroupHeader",(()=>e("div",{className:"wxchtf-header"}))),fn=Y("ChatGroupFooter",(()=>e("div",{className:"wxchtf-footer"}))),vn=Y("ChatGroupMain",(()=>{const{chatId:n,view:a}=Zt(),s=Pe.useChatListItem(n);return t("div",{className:"wxchtf-main",children:["chat"===a&&s&&e($t,{value:s},n),"new-chat"===a&&e(tn,{})]})})),yn=Y("ChatGroupBody",(()=>t("div",{className:"wxchtf-body",children:[e(mn,{}),e(vn,{})]})));function pn(n){const{className:a="",style:s}=n,{data:i}=Pe.useGetChatListQuery(),{openChat:c,none:r,chatId:o}=Zt(),d=l(!1);return u((()=>{i&&!i.some((e=>e.id===o))&&(i.length?c(i[0].id):r())}),[i,o]),u((()=>{i&&!d.current&&(d.current=!0,i.length&&c(i[0].id))}),[i]),t("div",{className:a+" wxchtf-chatify wxchtf-chat-group",style:s,children:[e(gn,{}),e(yn,{}),e(fn,{})]})}const bn={ChatGroupHeader:null,ChatGroupFooter:null},wn=t=>{const{localizer:n=tt,customize:a=bn}=t,s=r((()=>Object.assign({},bn,a)),[a]);return e(Ze.Provider,{value:n,children:e(z.Provider,{value:s,children:e(en,{children:e(pn,Object.assign({},t))})})})},Cn=s.createContext(null);function xn(){return s.useContext(Cn)}const Mn=Y("ThreadActions",(()=>{const{watch:t,onWatch:n}=xn();return e(y,t?{title:"Unwatch thread",children:e(g,{type:"link",icon:e(X,{type:"unwatch"}),onClick:()=>n(!1)})}:{title:"Watch thread",children:e(g,{type:"link",icon:e(X,{type:"watch"}),onClick:()=>n(!0)})})}));const In={ConversationActions:()=>e(Mn,{})};function Nn(t){const{threadId:n,customize:a,localizer:s=tt,className:i=""}=t,[c,o]=function(e){const{threadId:t}=e,{data:n}=Pe.useGetThreadQuery({id:t}),{data:a}=Pe.useGetThreadMessageListQuery({threadId:t}),{id:s,name:i,archive:c,lastReadMessageId:o,watch:l}=null!=n?n:{},{messages:u,hasMore:h}=null!=a?a:{},[m]=Pe.useReadThreadMessageMutation(),g=d((e=>m({id:e})),[m]),[f,{isLoading:v}]=Pe.useFetchNextThreadMessageListMutation(),y=d((()=>f({threadId:t})),[f,t]),[p]=Pe.useSendThreadMessageMutation(),b=d((e=>p({body:e,threadId:t}).unwrap()),[t,p]),{data:w}=Pe.useGetThreadMessageReadQueueQuery(),C=r((()=>{if(!s)return null;const e={value:{id:s,name:i,active:!c,lastReadMessageId:null!=o?o:null},messages:u,hasMore:h,onNext:y,nextLoading:v,onRead:g,onSend:b,noReadTracking:!l,isReading:e=>w.some((t=>ie(t.value)[0]===ie(e)[0]&&e<=t.value))};return e}),[y,g,b,v,s,i,c,u,h,o,w,l]),[x]=Pe.useWatchThreadMutation();return[C,r((()=>n?{id:n.id,watch:n.watch,onWatch:e=>x({id:n.id,watch:e}).unwrap()}:null),[n,x])]}(t),l=r((()=>Object.assign(Object.assign({},In),a)),[a]);return u((()=>(Pe.settings.client.connectToThread(n),()=>{Pe.settings.client.disconnectFromThread(n)})),[n]),c&&o?e(Ze.Provider,{value:s,children:e(Cn.Provider,{value:o,children:e(z.Provider,{value:l,children:e("div",{className:`wxchtf-chatify wxchtf-thread ${i}`,children:c&&e(Dt,Object.assign({},c))})})})}):null}const On={Thread:Nn,ChatGroup:wn,Chat:zt};export{$e as Avatar,Fe as CHATIFY_SIGNALR_METHODS,te as ChatContext,Qt as ChatEditableHeaderName,mn as ChatGroupAside,yn as ChatGroupBody,en as ChatGroupContext,fn as ChatGroupFooter,gn as ChatGroupHeader,vn as ChatGroupMain,wn as ChatGroupPanel,Gt as ChatHeaderActions,hn as ChatList,ln as ChatListItemAvatar,un as ChatListItemBox,dn as ChatListItemLastMessage,rn as ChatListItemLastMessageAuthor,cn as ChatListItemLastMessageContent,on as ChatListItemLastMessageSentAt,an as ChatListItemName,sn as ChatListItemUnreadCount,ne as ChatMembersButton,We as ChatMembersPanel,Ye as ChatMembersPreview,zt as ChatPanel,$t as ChatView,On as Chatify,Ae as ChatifyClient,Dt as Conversation,jt as ConversationActions,Ft as ConversationBody,rt as ConversationContext,Bt as ConversationHeader,At as ConversationName,nn as CreateChatButton,Jt as CreateChatForm,Wt as CreateChatMemberInput,Ht as CreateChatNameInput,tn as CreateChatPanel,z as CustomizeContext,Pt as DEFAULT_CHAT_VIEW_CUSTOMIZE_VALUE,J as ICONS,X as Icon,gt as InputBox,ut as InputBoxFile,ht as InputBoxFileList,Je as InputFileButton,Xe as InputFilesBox,ct as InputSubmitButtonBox,it as InputTextBox,Ze as LocalizerContext,ft as MessageAuthor,Nt as MessageBox,xt as MessageContent,wt as MessageFile,Ct as MessageFileList,Mt as MessageInfoBox,yt as MessageReadObserver,It as MessageRow,dt as MessageSkeleton,pt as MessageText,Ot as NextMessagesObserver,ae as SYSTEM_ID,Tt as SendingMessageBox,St as SendingMessageContent,_t as SendingMessageInfoBox,Rt as SendingMessageText,Et as SystemMessageBox,Lt as SystemMessageRow,Mn as ThreadActions,Cn as ThreadContext,Nn as ThreadPanel,re as calcThreadListUnreadCount,ce as calcThreadUnreadCount,se as chatId,Pe as chatifyApi,$ as color,Y as customize,tt as defaultLocalizer,kt as formatSystemMessage,ie as parseThreadMessageId,Be as unsubscribe,ee as useChatContext,Zt as useChatGroupContext,Qe as useChatListItem,ot as useConversation,W as useCustomize,H as useCustomizeContext,et as useLocalizer,xn as useThreadContext,Ge as useUnreadThreadMessageCount};
11
11
  //# sourceMappingURL=index.js.map