@amityco/ts-sdk 0.0.1-beta.9 → 0.0.1-c525f8c.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createChannel.d.ts","sourceRoot":"","sources":["../../../src/channel/api/createChannel.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa;;;
|
|
1
|
+
{"version":3,"file":"createChannel.d.ts","sourceRoot":"","sources":["../../../src/channel/api/createChannel.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa;;;gHAoBzB,CAAA"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -4481,12 +4481,17 @@ getChannel.locally = (channelId) => {
|
|
|
4481
4481
|
const createChannel = async (bundle) => {
|
|
4482
4482
|
const client = getActiveClient();
|
|
4483
4483
|
client.log('user/createChannel', bundle);
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4484
|
+
let payload;
|
|
4485
|
+
if ((bundle === null || bundle === void 0 ? void 0 : bundle.type) === 'conversation') {
|
|
4486
|
+
payload = await client.http.post('/api/v3/channels/conversation', Object.assign(Object.assign({}, bundle), { isDistinct: true }));
|
|
4487
|
+
}
|
|
4488
|
+
else {
|
|
4489
|
+
payload = await client.http.post('/api/v3/channels', bundle);
|
|
4490
|
+
}
|
|
4491
|
+
decoratePayload(payload.data);
|
|
4492
|
+
ingestInCache(payload.data);
|
|
4487
4493
|
// no need for event, fired by server
|
|
4488
|
-
|
|
4489
|
-
return channels[0];
|
|
4494
|
+
return payload.data.channels[0];
|
|
4490
4495
|
};
|
|
4491
4496
|
|
|
4492
4497
|
/**
|
package/dist/index.esm.js
CHANGED
|
@@ -4465,12 +4465,17 @@ getChannel.locally = (channelId) => {
|
|
|
4465
4465
|
const createChannel = async (bundle) => {
|
|
4466
4466
|
const client = getActiveClient();
|
|
4467
4467
|
client.log('user/createChannel', bundle);
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4468
|
+
let payload;
|
|
4469
|
+
if ((bundle === null || bundle === void 0 ? void 0 : bundle.type) === 'conversation') {
|
|
4470
|
+
payload = await client.http.post('/api/v3/channels/conversation', Object.assign(Object.assign({}, bundle), { isDistinct: true }));
|
|
4471
|
+
}
|
|
4472
|
+
else {
|
|
4473
|
+
payload = await client.http.post('/api/v3/channels', bundle);
|
|
4474
|
+
}
|
|
4475
|
+
decoratePayload(payload.data);
|
|
4476
|
+
ingestInCache(payload.data);
|
|
4471
4477
|
// no need for event, fired by server
|
|
4472
|
-
|
|
4473
|
-
return channels[0];
|
|
4478
|
+
return payload.data.channels[0];
|
|
4474
4479
|
};
|
|
4475
4480
|
|
|
4476
4481
|
/**
|
package/dist/index.umd.js
CHANGED
|
@@ -16,4 +16,4 @@ var Amity=function(e,t,n,r){"use strict";function o(e){return e&&"object"==typeo
|
|
|
16
16
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
17
|
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
|
-
function em(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}Zh.locally=e=>{var t;const n=null!==(t=y("user",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const tm=async e=>{const t=m();t.log("user/queryUsers",e);const n=null!=e?e:{},{page:r,displayName:o,filter:i="all",sortBy:s="displayName"}=n,a=em(n,["page","displayName","filter","sortBy"]),{data:c}=await t.http.get("/api/v3/users",{params:Object.assign(Object.assign({},a),{keyword:o,filter:i,sortBy:s,options:{token:ae(r,"skiplimit")}})}),{paging:l}=c,u=em(c,["paging"]);$h(u),B(u);const p=ce(l.previous),d=ce(l.next),{users:f}=u;return{data:A(f),prevPage:p,nextPage:d}};tm.locally=e=>{m().log("user/queryUsers.locally",e)};const nm=(e,t)=>{const n=m();return vh(n,e,e,(e=>{$h(e),B(e),t(e.users[0])}))},rm=e=>nm("user.updated",e),om=e=>nm("user.flagged",e),im=e=>nm("user.unflagged",e),sm=e=>nm("user.flagCleared",e),am=async e=>{const t=m();t.log("file/getFile",e);const{data:n}=await t.http.get(`/api/v3/files/${e}`);return Wh(n),B({files:[n]}),n};am.locally=e=>{var t;m().log("file/getFile.locally",e);const[n]=null!==(t=y("file",e))&&void 0!==t?t:[];return n};const cm=async e=>{const t=m();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r,displayName:o,sortBy:i}=n,s=em(n,["page","displayName","sortBy"]),{data:a}=await t.http.get("/api/v3/roles",{params:Object.assign(Object.assign({},s),{keyword:o,sortBy:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const u=ce(c.previous),p=ce(c.next),{roles:d}=l;return{data:A(d),prevPage:u,nextPage:p}};cm.locally=e=>{m().log("role/queryRoles.locally",e)};const lm=async e=>{const t=m();t.log("role/getRole",e);const{data:n}=await t.http.get(`/api/v3/roles/${e}`);return Hh(n),B({roles:n}),n.find((t=>t.roleId===e))};lm.locally=e=>{var t;m().log("role/getRole.locally",e);const[n]=null!==(t=y("role",e))&&void 0!==t?t:[];return n};const um=(e,t)=>{"message"===e?_h("v3.message.didUpdate",{messages:[t]}):"post"===e?_h("post.updated",{posts:[t]}):"comment"===e&&_h("comment.updated",{comments:[t]})},pm=async e=>{const t=m();t.log("message/getMessage",e);const{data:n}=await t.http.get(`/api/v3/messages/${e}`);$h(n),B(n);const{messages:r}=n;return r.find((t=>t.messageId===e))};pm.locally=e=>{var t;m().log("message/getMessage.locally",e);const[n]=null!==(t=y("message",e))&&void 0!==t?t:[];return n};const dm=async e=>{const t=m();t.log("message/getMessages",e);const{data:n}=await t.http.get("/api/v3/messages/list",{params:{messageIds:e}});$h(n),B(n);const{messages:r}=n;return A(r)};dm.locally=e=>{var t;m().log("message/getMessages.locally",e);const n=null!==(t=y("message",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const fm=async e=>{const t=m();t.log("message/queryMessages",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v3/messages",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"afterbefore")}})}),{paging:s}=i,a=em(i,["paging"]);$h(a),B(a);const{messages:c}=a,l=ce(s.next),u=ce(s.previous);return{data:A(c),nextPage:l,prevPage:u}};fm.locally=e=>{var t,n,r,o,i;m().log("message/queryMessages.locally",e);const{channelId:s,page:a}=e,[c]=null!==(t=y("channel",s))&&void 0!==t?t:[];let l=null!==(n=y("message"))&&void 0!==n?n:[];if(l=Vh(l,"channelId",s),l=l.sort(Kh),a){let e,t=0;"after"in a?(t=0!==a.after?l.findIndex((e=>e.channelSegment===(null==a?void 0:a.after)))+1:0,e=t+a.limit):"before"in a&&(e=0!==a.before?l.findIndex((e=>e.channelSegment===(null==a?void 0:a.before)))+1:l.length-1,t=e>a.limit?e-a.limit:0);const n=l.slice(t,e);l=n.length===a.limit?n:[]}const u=(null===(r=l[0])||void 0===r?void 0:r.channelSegment)>0?{before:l[0].channelSegment,limit:null==a?void 0:a.limit}:void 0,p=(null===(o=l[l.length-1])||void 0===o?void 0:o.channelSegment)<(null!==(i=null==c?void 0:c.messageCount)&&void 0!==i?i:0)?{after:l[l.length-1].channelSegment,limit:null==a?void 0:a.limit}:void 0;return{data:A(l),nextPage:p,prevPage:u}};const hm=async e=>{const t=m();t.log("user/createMessage",e);const{data:n}=await t.http.post("/api/v3/messages",e);$h(n),B(n);const{messages:r}=n;return r[0]};hm.optimistically=e=>{var t,n,r;const o=m();if(o.log("user/createMessage.locally",e),!o.cache)return;const[i]=null!==(t=y("channel",e.channelId))&&void 0!==t?t:[];w("channel",Object.assign(Object.assign({},i),{messageCount:(null!==(n=i.messageCount)&&void 0!==n?n:0)+1}));const s=Object.assign(Object.assign({localId:mt(),messageId:Math.random().toString(16),userId:o.userId,channelSegment:(null!==(r=null==i?void 0:i.messageCount)&&void 0!==r?r:0)+1,createdAt:(new Date).toISOString()},e),{syncedAt:-1});return w("message",s),_h("v3.message.didCreate",{messages:[s]}),s};const mm=async(e,t)=>{const n=m();n.log("user/updateMessage",t);const{data:r}=await n.http.put(`/api/v3/messages/${e}`,t);return $h(r),B(r),r.messages.find((t=>t.messageId===e))};mm.optimistically=(e,t)=>{var n;m().log("user/updateMessage",t);const[r]=null!==(n=y("message",e))&&void 0!==n?n:[];if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r),t),{updatedAt:(new Date).toISOString()});return w("message",o),_h("v3.message.didUpdate",{messages:[o]}),o};const gm=async e=>{const t=m();t.log("message/deleteMessage",e),await t.http.delete(`/api/v3/messages/${e}`);return await pm(e)};gm.optimistically=e=>{var t;m().log("message/deleteMessage",e);const[n]=null!==(t=y("message",e))&&void 0!==t?t:[];if(!n)return;const r=Object.assign(Object.assign({},n),{isDeleted:!0,updatedAt:(new Date).toISOString()});return w("message",r),_h("v3.message.didDelete",{messages:[r]}),r};const ym=async e=>{const t=m();t.log("post/queryPosts",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v3/posts",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"skiplimit")}})}),{paging:s}=i,a=em(i,["paging"]);$h(a),B(a);const{posts:c}=a,l=ce(s.next),u=ce(s.previous);return{data:A(c),nextPage:l,prevPage:u}};ym.locally=e=>{m().log("post/queryPosts.locally",e)};const bm=async e=>{const t=m();t.log("post/getPosts",e);const{data:n}=await t.http.get("/api/v3/posts/list",{params:{postIds:e}});$h(n),B(n);const{posts:r}=n;return r};bm.locally=e=>{var t;m().log("post/getPosts.locally",e);const n=null!==(t=y("post",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const vm=async e=>{var t;const n=m();let r;n.log("post/getPost",e);try{r=(await n.http.get(`/api/v3/posts/${e}`)).data}catch(n){throw 400400===(null===(t=n)||void 0===t?void 0:t.code)&&C("post",{postId:e}),n}$h(r),B(r);const{posts:o}=r;return o.find((t=>t.postId===e))};vm.locally=e=>{var t;m().log("post/getPost.locally",e);const[n]=null!==(t=y("post",e))&&void 0!==t?t:[];return n};const _m=async e=>{const t=m();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r,displayName:o,membership:i}=n,s=em(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},s),{keyword:o,filter:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const u=ce(null==c?void 0:c.previous),p=ce(null==c?void 0:c.next),{communities:d}=l;return{data:A(d),prevPage:u,nextPage:p}};_m.locally=e=>{m().log("community/queryCommunities.locally",e)};const wm=async e=>{const t=m();t.log("community/getCommunities",e);const{data:n}=await t.http.get("/api/v3/communities/list",{params:{communityIds:e}});$h(n),B(n);const{communities:r}=n;return A(r)};wm.locally=e=>{var t;m().log("community/getCommunities.locally",e);const n=null!==(t=y("community",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const Cm=async e=>{const t=m();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`);$h(n),B(n);const{communities:r}=n;return r.find((t=>t.communityId===e))};Cm.locally=e=>{var t;m().log("community/getCommunity.locally",e);const[n]=null!==(t=y("community",e))&&void 0!==t?t:[];return n};const Sm=async e=>{const t=m();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r,communityId:o}=n,i=em(n,["page","communityId"]),{data:s}=await t.http.get(`/api/v3/communities/${o}/users`,{params:Object.assign(Object.assign({},i),{options:{token:ae(r,"skiplimit")}})}),{paging:a}=s,c=em(s,["paging"]);$h(c),B(c);const{communityUsers:l}=c,u=ce(a.next),p=ce(a.previous);return{data:A(l),nextPage:u,prevPage:p}};Sm.locally=e=>{m().log("community/queryCommunityMembers",e)};const km=async e=>{const t=m();t.log("comment/queryComments",e);const{page:n}=e,r=em(e,["page"]);e.parentId;const{data:o}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},r),{options:{token:ae(n,"afterbefore")}})}),{paging:i}=o,s=em(o,["paging"]);$h(s),B(s);const a=ce(i.previous),c=ce(i.next),{comments:l}=s;return{data:A(l),prevPage:a,nextPage:c}};km.locally=e=>{var t;m().log("post/queryComments.locally",e);const{referenceId:n,referenceType:r,parentId:o,isDeleted:i,page:s={before:0,limit:5}}=e;isNaN(s.limit)&&(s.limit=5);let a=null!==(t=y("comment"))&&void 0!==t?t:[];if(!a.length)return;if(a=Vh(a,"referenceId",n),a=Vh(a,"referenceType",r),a=Vh(a,"parentId",o),a=Vh(a,"isDeleted",i),!a.length)return;a=a.sort(zh);const c=isNaN(s.after)?0:a.findIndex((({segmentNumber:e})=>e===s.after+1)),l=isNaN(s.before)||0===s.before?a.length:a.findIndex((({segmentNumber:e})=>e===s.before-1))+1;if(c<0||l<0)return;let u=a.slice(-1!==c?c:0,-1!==l?l:void 0);if(u.length<s.limit)return;(isNaN(s.after)||isNaN(s.before))&&(u=isNaN(s.after)?(isNaN(s.before),u.slice(-s.limit)):u.slice(0,s.limit));for(let e=0;e<u.length-1;e++)if(u[e].segmentNumber!==u[e+1].segmentNumber-1)return;const p=u[0].segmentNumber>1?{before:u[0].segmentNumber,limit:s.limit}:void 0,d=u[u.length-1].segmentNumber<a[a.length-1].segmentNumber?{after:u[u.length-1].segmentNumber,limit:s.limit}:void 0;return{data:A(u),nextPage:d,prevPage:p}};const Em=async e=>{const t=m();t.log("comment/getComments",e);const{data:n}=await t.http.get("/api/v3/comments/list",{params:{commentIds:e}});$h(n),B(n);const{comments:r}=n;return A(r)};Em.locally=e=>{var t;m().log("comment/getComments.locally",e);const n=null!==(t=y("comment",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const Rm=async e=>{var t;const n=m();let r;n.log("comment/getComment",e);try{r=(await n.http.get(`/api/v3/comments/${e}`)).data}catch(n){throw 400400===(null===(t=n)||void 0===t?void 0:t.code)&&C("comment",{commentId:e}),n}$h(r),B(r);const{comments:o}=r;return o.find((t=>t.commentId===e))};Rm.locally=e=>{var t;m().log("comment/getComment.locally",e);const[n]=null!==(t=y("comment",e))&&void 0!==t?t:[];return n};const Im=async(e,t)=>{if("message"===e)return pm(t);if("post"===e)return vm(t);if("comment"===e)return Rm(t);throw new Error(`Incorrect referenceType: ${e}`)},Am=(e,t)=>{var n,r;if(m().userId!==t.reactor.userId)return;let o,i;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];i=(null!==(n=y("post",e.postId))&&void 0!==n?n:[])[0],o=e}else{const e=t.comments[0];i=(null!==(r=y("comment",e.commentId))&&void 0!==r?r:[])[0],o=e}if(i&&i.myReactions)if("post.addReaction"===e||"comment.addReaction"===e){if(i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:[...i.myReactions,t.reactor.reactionName]})}else{if(!i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:i.myReactions.filter((e=>e!==t.reactor.reactionName))})}},Om=async(e,t,n)=>{var r,o;const i=m();i.log("reaction/createReaction",{referenceId:t,referenceType:e,reactionName:n}),await i.http.post("/api/v2/reactions",{referenceId:t,referenceType:e,reactionName:n});const s=await Im(e,t);return um(e,s),null!==(o=null===(r=s.myReactions)||void 0===r?void 0:r.includes(n))&&void 0!==o&&o};Om.optimistically=(e,t,n)=>{var r,o;const i=R(e,t,(e=>{var t,r,o;if(!(null===(t=e.myReactions)||void 0===t?void 0:t.includes(n)))return Object.assign(Object.assign({},e),{syncedAt:-1,reactionsCount:e.reactionsCount+1,myReactions:[...null!==(r=e.myReactions)&&void 0!==r?r:[],n],reactions:Object.assign(Object.assign({},e.reactions),{[n]:(null!==(o=e.reactions[n])&&void 0!==o?o:0)+1})})}));return i&&um(e,i),null!==(o=null===(r=null==i?void 0:i.myReactions)||void 0===r?void 0:r.includes(n))&&void 0!==o&&o};const Tm=async(e,t,n)=>{var r,o;const i=m();i.log("reaction/removeReaction",{referenceId:t,referenceType:e,reactionName:n}),await i.http.delete("/api/v2/reactions",{data:{referenceId:t,referenceType:e,reactionName:n}});const s=await Im(e,t);return um(e,s),null!==(o=!(null===(r=s.myReactions)||void 0===r?void 0:r.includes(n)))&&void 0!==o&&o};Tm.optimistically=(e,t,n)=>{var r,o;const i=R(e,t,(e=>{var t,r,o;if(null===(t=e.myReactions)||void 0===t?void 0:t.includes(n))return Object.assign(Object.assign({},e),{syncedAt:-1,reactionsCount:Math.max(0,e.reactionsCount-1),myReactions:(null!==(r=e.myReactions)&&void 0!==r?r:[]).filter((e=>e!==n)),reactions:Object.assign(Object.assign({},e.reactions),{[n]:Math.max(0,(null!==(o=e.reactions[n])&&void 0!==o?o:0)-1)})})}));return i&&um(e,i),null!==(o=!(null===(r=null==i?void 0:i.myReactions)||void 0===r?void 0:r.includes(n)))&&void 0!==o&&o};const xm=(e,t)=>{const n=m();return vh(n,e,e,(e=>{var n,r;const[o]=null!==(n=y("post",e.posts[0].postId))&&void 0!==n?n:[],{communities:i}=e,s=em(e,["communities"]);$h(s),B(s),(null==i?void 0:i[0])&&_h("community.updated",{communities:i});const[a]=null!==(r=y("post",s.posts[0].postId))&&void 0!==r?r:[];o&&M(o,a)||t(a)}))},Pm=e=>xm("post.created",e),Mm=e=>xm("post.updated",e),Bm=e=>xm("post.deleted",e),jm=e=>xm("post.approved",e),Nm=e=>xm("post.declined",e),Fm=e=>xm("post.flagged",e),Um=e=>xm("post.unflagged",e),Lm=e=>{const t=m();return vh(t,"post.addReaction","post.addReaction",(t=>{var n,r;const[o]=null!==(n=y("post",t.posts[0].postId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("post.addReaction",t),B(i);const[s]=null!==(r=y("post",t.posts[0].postId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))},Dm=e=>{const t=m();return vh(t,"post.removeReaction","post.removeReaction",(t=>{var n,r;const[o]=null!==(n=y("post",t.posts[0].postId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("post.removeReaction",t),B(i);const[s]=null!==(r=y("post",t.posts[0].postId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))},qm=(e,t)=>{const n=m();return vh(n,e,e,(e=>{var n,r;const[o]=null!==(n=y("comment",e.comments[0].commentId))&&void 0!==n?n:[];$h(e),B(e);const[i]=null!==(r=y("comment",e.comments[0].commentId))&&void 0!==r?r:[];o&&M(o,i)||t(i)}))},$m=e=>qm("comment.created",e),Hm=e=>qm("comment.updated",e),Wm=e=>qm("comment.deleted",e),Vm=e=>qm("comment.flagged",e),Km=e=>qm("comment.unflagged",e),zm=e=>{const t=m();return vh(t,"comment.addReaction","comment.addReaction",(t=>{var n,r;const[o]=null!==(n=y("comment",t.comments[0].commentId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("comment.addReaction",t),B(i);const[s]=null!==(r=y("comment",t.comments[0].commentId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))},Jm=e=>{const t=m();return vh(t,"comment.removeReaction","comment.removeReaction",(t=>{var n,r;const[o]=null!==(n=y("comment",t.comments[0].commentId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("comment.removeReaction",t),B(i);const[s]=null!==(r=y("comment",t.comments[0].commentId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))};var Ym={post:{domainName:"posts",eventName:"v3/post.isflagbyme",primaryKey:"postId"},comment:{domainName:"comments",eventName:"v3/comment.isflagbyme",primaryKey:"commentId"},message:{domainName:"messages",eventName:"v3/message.isFlaggedByMe",primaryKey:"messageId"},user:{domainName:"users",eventName:"user.isFlagByMe",primaryKey:"userId"}};const Qm=async e=>{const t=m();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r,displayName:o,membership:i}=n,s=em(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/channels",{params:Object.assign(Object.assign({},s),{keyword:o,filter:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const u=ce(null==c?void 0:c.previous),p=ce(null==c?void 0:c.next),{channels:d}=l;return{data:A(d),prevPage:u,nextPage:p}};Qm.locally=e=>{m().log("channel/queryChannels.locally",e)};const Xm=async e=>{const t=m();t.log("channel/getChannels",e);const{data:n}=await t.http.get("/api/v3/channels/list",{params:{channelIds:e}});$h(n),B(n);const{channels:r}=n;return A(r)};Xm.locally=e=>{var t;m().log("channel/getChannels.locally",e);const n=null!==(t=y("channel",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const Gm=async e=>{const t=m();t.log("channel/getChannel",e);const{data:n}=await t.http.get(`/api/v3/channels/${e}`);$h(n),B(n);const{channels:r}=n;return r.find((t=>t.channelId===e))};Gm.locally=e=>{var t;m().log("channel/getChannel.locally",e);const[n]=null!==(t=y("channel",e))&&void 0!==t?t:[];return n};const Zm=async e=>{const t=m();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r,channelId:o,membership:i}=n,s=em(n,["page","channelId","membership"]),{data:a}=await t.http.get(`/api/v3/channels/${o}/users`,{params:Object.assign(Object.assign({},s),{filter:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const{channelUsers:u}=l,p=ce(c.next),d=ce(c.previous);return{data:A(u),nextPage:p,prevPage:d}};Zm.locally=e=>{m().log("channel/queryChannelMembers",e)};const eg=e=>{const t=m();return vh(t,"onChannelUpdated","v3.channel.didUpdate",(t=>{$h(t),B(t),e(t.channels[0])}))},tg=e=>{const t=m();return vh(t,"onChannelDeleted","v3.channel.didDelete",(t=>{$h(t),B(t),e(t.channels[0])}))},ng=e=>{const t=m();return vh(t,"onChannelJoined","v3.channel.didJoin",(t=>{$h(t),B(t),e(t.channels[0])}))},rg=e=>{const t=m();return vh(t,"onChannelLeft","v3.channel.didLeave",(t=>{$h(t),B(t),e(t.channels[0])}))},og=e=>{const t=m();return vh(t,"onMemberAdded","v3.channel.didAddUsers",(t=>{$h(t),B(t),e(t.channels[0])}))},ig=e=>{const t=m();return vh(t,"onMemberRemoved","v3.channel.didRemoveUsers",(t=>{$h(t),B(t),e(t.channels[0])}))},sg=e=>{const t=m();return vh(t,"message/onMessageCreated","v3.message.didCreate",(t=>{$h(t),B(t),e(t.messages[0])}))},ag=e=>{const t=m();return vh(t,"message/onMessageUpdated","v3.message.didUpdate",(t=>{$h(t),B(t),e(t.messages[0])}))},cg=e=>{const t=m();return vh(t,"message/onMessageDeleted","v3.message.didDelete",(t=>{$h(t),B(t),e(t.messages[0])}))},lg=(e,t)=>{const n=m();return vh(n,e,e,(e=>{var n,r;const[o]=null!==(n=y("community",e.communities[0].communityId))&&void 0!==n?n:[];$h(e),B(e);const[i]=null!==(r=y("community",e.communities[0].communityId))&&void 0!==r?r:[];o&&M(o,i)||t(i)}))};function ug(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function pg(e,t){return"community.joined"===e||"community.left"===e?t.communityUsers[0]:"community.userRemoved"===e?t.communityUsers.filter((e=>"none"===e.communityMembership))[0]:"community.userBanned"===e?t.communityUsers.filter((e=>"banned"===e.communityMembership))[0]:"community.userUnbanned"===e?t.communityUsers.filter((e=>!ug(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!ug(e,t,"ADD_COMMUNITY_USER")))[0]}const dg=(e,t)=>{const n=m();return vh(n,e,e,(n=>{var r,o,i,s;const[a]=null!==(r=y("community",n.communities[0].communityId))&&void 0!==r?r:[],[c]=null!==(o=y("communityUsers",v("communityUsers")(pg(e,n))))&&void 0!==o?o:[];$h(n),B(n);const[l]=null!==(i=y("community",n.communities[0].communityId))&&void 0!==i?i:[],[u]=null!==(s=y("communityUsers",v("communityUsers")(pg(e,n))))&&void 0!==s?s:[];a&&M(a,l)&&c&&M(c,u)||t(l,u)}))},fg=e=>lg("community.updated",e),hg=e=>lg("community.deleted",e),mg=e=>dg("community.joined",e),gg=e=>dg("community.left",e),yg=e=>dg("community.userAdded",e),bg=e=>dg("community.userRemoved",e),vg=e=>dg("community.userBanned",e),_g=e=>dg("community.userUnbanned",e),wg=async e=>{const t=m();t.log("stream/getStream",e);const{data:n}=await t.http.get(`/api/v3/video-streaming/${e}`);$h(n),B(n);const{videoStreamings:r}=n;return r.find((t=>t.streamId===e))};wg.locally=e=>{var t;m().log("stream/getStream",e);const[n]=null!==(t=y("stream",e))&&void 0!==t?t:[];return n};const Cg=async e=>{const t=m();t.log("stream/queryStreams",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"skiplimit")}})}),{paging:s,results:a}=i;$h(a),B(a);const c=ce(null==s?void 0:s.previous),l=ce(null==s?void 0:s.next),{videoStreamings:u}=a;return{data:A(u),prevPage:c,nextPage:l}};Cg.locally=e=>{m().log("stream/queryStreams.locally",e)};return e.VERSION=l,e.addChannelMembers=async(e,t)=>{const n=m();n.log("channel/addChannelMembers",e,t);const{data:r}=await n.http.post(`/api/v3/channels/${e}/users`,{channelId:e,userIds:t});$h(r),B(r),_h("v3.channel.didAddUsers",{channels:r.channels});const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"===t.membership))},e.addChannelMembersRole=async(e,t,n)=>{const r=m();r.log("channel/addChannelMembersRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/channels/${e}/users/roles`,{channelId:e,role:t,userIds:n});$h(o),B(o);const{channelUsers:i}=o;return!!i.find((n=>n.channelId===e&&n.roles.includes(t)))},e.addCommunityMembers=async(e,t)=>{const n=m();n.log("community/addCommunityMembers",e,t);const{data:r}=await n.http.post(`/api/v3/communities/${e}/users`,{communityId:e,userIds:t});$h(r),B(r),_h("community.userAdded",{communities:r.communities});const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.addCommunityMembersRole=async(e,t,n)=>{const r=m();r.log("community/addCommunityMembersRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/communities/${e}/users/roles`,{communityId:e,role:t,userIds:n});$h(o),B(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&n.roles.includes(t)))},e.addReaction=Om,e.clearCache=(e=["user","file","channel","message","community","post","comment"])=>{const t=m();t.log("client/api/enableCache"),e.forEach((e=>{var n,r;return null===(r=null===(n=t.cache)||void 0===n?void 0:n[e])||void 0===r?void 0:r.erase()}))},e.connectClient=async e=>{var t,n;const r=m();r.log("client/api/connectClient",Object.assign({apiKey:r.apiKey},e)),null!==(t=e.displayName)&&void 0!==t||(e.displayName=e.userId),null!==(n=e.deviceId)&&void 0!==n||(e.deviceId=`ascWebSdk#${Math.random().toString(16)}`);const{accessToken:o,users:i}=await(async e=>{const t=m();t.log("client/api/getToken",e);const n=await Ch(),{data:r}=await t.http.post("/v1/device",Object.assign(Object.assign({},e),{deviceInfo:n}),{headers:{"X-API-Key":t.apiKey}});return r})(e);r.http.defaults.headers.common.Authorization=`Bearer ${o}`,r.ws.io.opts.query={token:o},((e,t)=>{gh.forEach((n=>{e.on(n,(e=>t.emit(n,e)))}))})(r.ws,r.emitter),await new Promise((e=>{r.ws.once("connect",e),r.ws.open()}));const s=Eh((()=>{wh(),s()}));return r.userId=e.userId,r.user=i[0],r.accessToken=o,r.ws.connected},e.createCache=j,e.createChannel=async e=>{const t=m();t.log("user/createChannel",e);const{data:n}=await t.http.post("/api/v3/channels",e);$h(n),B(n);const{channels:r}=n;return r[0]},e.createClient=(e,t=It,n="amity")=>{const r=(e=>{const t=`${null==e?void 0:e.trim()}`.length>0&&"production"!==process.env.NODE_ENV,n=Rt(e),r=(e,...r)=>{t&&n(e,r)};return r.__instance__=n,r})(n);r("client/api/createClient",{apiKey:e.replace(/.{5}$/g,"xxxxx"),apiEndpoint:t});const o=(e=>{const t={maxSockets:100,maxFreeSockets:10,timeout:6e4,freeSocketTimeout:3e4},n=Yn.create({baseURL:e,httpAgent:new Zn(t),httpsAgent:new Xn(t),paramsSerializer:tr});return n.interceptors.response.use((e=>e),(e=>{var t;const{response:n}=e;console.error(null!==(t=null==n?void 0:n.data)&&void 0!==t?t:e),n&&er(n.data)})),n})(Ot(At.HTTP,t)),i=(e=>{const t=ts(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(Ot(At.HTTP,t)),s=mh(Ot(At.MQTT,t)),a=bh(),c={version:`${l}`,apiKey:e,log:r,http:o,ws:i,mqtt:s,emitter:a,use:()=>g(c)};try{m()}catch(e){g(c)}return c},e.createComment=async e=>{const t=m();t.log("comment/createComment",e);const{data:n}=await t.http.post("/api/v3/comments",e);$h(n),B(n);const r=await vm(e.referenceId);_h("post.updated",{posts:[r]}),_h("comment.created",n);const{comments:o}=n;return o[0]},e.createCommunity=async e=>{const t=m();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",e);$h(n),B(n),_h("community.created",n);const{communities:r}=n;return r[0]},e.createFile=async(e,t)=>{const n=m();if(n.log("file/createFile",e),!e.getAll("file").length)throw new Error("The formData object must have a `file` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v3/files",e,{headers:r,onUploadProgress({loaded:e,total:n}){t&&t(Math.round(100*e/n))}});return Hh(o),B({files:o}),o[0]},e.createMessage=hm,e.createPost=async e=>{const t=m();t.log("post/createPost",e),e.dataType&&!["text","image","file"].includes(e.dataType)||delete e.dataType;const{data:n}=await t.http.post("/api/v3/posts",e);$h(n),B(n),_h("community.updated",{communities:n.communities}),_h("post.created",n);const{posts:r}=n;return r[0]},e.createQuery=ge,e.createReport=async(e,t)=>{const n=m();n.log("report/createReport",{referenceType:e,referenceId:t});const{domainName:r}=Ym[e],{data:o}=await n.http.post(`/api/v3/${r}/${t}/flag`),i="message"===e?"v3.message.didUpdate":`${e}.updated`;return $h(o),B(o),_h(i,o),!!o},e.createStream=async e=>{const t=m();t.log("stream/createStream",e);const{data:n}=await t.http.post("/api/v3/video-streaming",e);$h(n),B(n);const{videoStreamings:r}=n;return r[0]},e.decorateModel=Wh,e.decorateModels=Hh,e.decoratePayload=$h,e.deleteChannel=async e=>{const t=m();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${e}`);return await Gm(e)},e.deleteComment=async(e,t=!1)=>{const n=m();n.log("comment/deleteComment",e);const r=await Rm(e);await n.http.delete(`/api/v4/comments/${e}`,{params:{commentId:e,permanent:t}});const o=Object.assign(Object.assign({},r),{isDeleted:!0}),i=await vm(r.referenceId);return _h("post.updated",{posts:[i]}),_h("comment.deleted",{comments:[o]}),t?setTimeout((()=>{C("comment",{commentId:e})}),0):I("comment",{commentId:e,isDeleted:!0}),o},e.deleteCommunity=async e=>{const t=m();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await Cm(e);return _h("community.deleted",{communities:[n]}),n},e.deleteFile=async e=>{const t=m();t.log("file/deleteFile",e);const{data:n}=await t.http.delete(`/api/v3/files/${e}`);return C("file",{fileId:n.fileId}),{success:!0}},e.deleteMessage=gm,e.deletePost=async(e,t=!1)=>{const n=m();n.log("post/deletePost",e);let r=await vm(e);if(await n.http.delete(`/api/v4/posts/${e}`,{params:{postId:e,permanent:t}}),"community"===r.targetType){const e=await Cm(r.targetId);_h("community.updated",{communities:[e]})}const o=Object.assign(Object.assign({},r),{isDeleted:!0});return _h("post.deleted",{posts:[o]}),t?setTimeout((()=>{C("post",{postId:e})}),0):I("post",{postId:e,isDeleted:!0}),o},e.deleteReport=async(e,t)=>{const n=m();n.log("report/deleteReport",{referenceType:e,referenceId:t});const{domainName:r}=Ym[e],{data:o}=await n.http.delete(`/api/v3/${r}/${t}/unflag`),i="message"===e?"v3.message.didUpdate":`${e}.updated`;return $h(o),B(o),_h(i,o),!!o},e.deleteStream=async e=>{const t=m();t.log("stream/deleteStream",e);const{data:n}=await t.http.delete(`/api/v3/video-streaming/${e}`),{success:r}=n;return r},e.disconnectClient=wh,e.disposeStream=async e=>{const t=m();t.log("stream/disposeStream",e);const{data:n}=await t.http.delete(`/api/v3/video-streaming/${e}/streaming-url`);$h(n),B(n);const{videoStreamings:r}=n;return r.find((t=>t.streamId===e))},e.dropFromCache=C,e.enableCache=(e=Ih("user","file","channel","message","community","post","comment","communityUsers","channelUsers","stream"))=>{const t=m();t.log("client/api/enableCache"),t.cache=j(e)},e.fileUrlWithSize=(e,t)=>`${e}?size=${t}`,e.filterByPropEquality=Vh,e.getActiveClient=m,e.getChannel=Gm,e.getChannels=Xm,e.getComment=Rm,e.getCommentTopic=({path:e})=>e,e.getComments=Em,e.getCommunities=wm,e.getCommunity=Cm,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>Yh({path:t},n),e.getFile=am,e.getMessage=pm,e.getMessages=dm,e.getPost=vm,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getPosts=bm,e.getRole=lm,e.getStream=wg,e.getUser=Gh,e.getUserTopic=({path:t},n=e.SubscriptionLevels.USER)=>Yh({path:t},n),e.getUsers=Zh,e.ingestInCache=B,e.isAfterBefore=ie,e.isConnected=()=>{var e,t;const n=m();return n.log("client/api/isConnected",n),!!(n.userId&&(null===(t=null===(e=n.http.defaults.headers.common)||void 0===e?void 0:e.Authorization)||void 0===t?void 0:t.length)&&n.ws.connected)},e.isFetcher=le,e.isFresh=he,e.isLocal=fe,e.isMutator=ue,e.isOffline=pe,e.isPaged=se,e.isReportedByMe=async(e,t)=>{var n,r;const o=m();o.log("report/isReportedByMe",{referenceType:e,referenceId:t});const{eventName:i,primaryKey:s}=Ym[e],{result:a,isFlagByMe:c}=null!==(n=await(async(e,t,n)=>{const{ws:r}=e;return await new Promise(((e,o)=>{r.emit(t,n,(t=>{try{e(er(t))}catch(e){o(e)}}))}))})(o,i,{[s]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkipLimit=oe,e.isSyncable=de,e.isSynced=me,e.joinChannel=async e=>{const t=m();t.log("channel/joinChannel",e);const{data:n}=await t.http.post(`/api/v3/channels/${e}/join`);$h(n),B(n);const{channelUsers:r}=n;return!!r.find((t=>t.channelId===e&&"member"===t.membership))},e.joinCommunity=async e=>{const t=m();t.log("community/joinCommunity",e);const{data:n}=await t.http.post(`/api/v3/communities/${e}/join`);$h(n),B(n),_h("community.joined",{communities:n.communities});const{communityUsers:r}=n;return!!r.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.leaveChannel=async e=>{const t=m();t.log("channel/leaveChannel",e);const{data:n}=await t.http.delete(`/api/v3/channels/${e}/leave`);$h(n),B(n);const{channelUsers:r}=n;return!!r.find((t=>t.channelId===e&&"member"!==t.membership))},e.leaveCommunity=async e=>{const t=m();t.log("community/leaveCommunity",e);const{data:n}=await t.http.delete(`/api/v3/communities/${e}/leave`);$h(n),B(n),_h("community.left",{communities:n.communities});const{communityUsers:r}=n;return!!r.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.memoryStore=Rh,e.memoryStores=Ih,e.mergeInCache=I,e.mutateCache=R,e.observeChannel=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeChannel(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.channelId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(eg((e=>o({data:e},"onUpdate"))),tg((e=>o({data:e},"onDelete"))),ng((e=>o({data:e},"onJoin"))),rg((e=>o({data:e},"onLeft"))),og((e=>o({data:e},"onMemberAdded"))),ig((e=>o({data:e},"onMemberRemoved")))),_e(ge(Gm,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.observeComment=(e,t,n="cache_then_server")=>{const{log:r}=m(),o=Date.now();r(`observeComment(tmpid: ${o}) > listen`);const i=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},s=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.commentId)===e&&i(t,n)},a=[];return a.push(Hm((e=>s({data:e},"onUpdate"))),Wm((e=>s({data:e},"onDelete"))),Vm((e=>s({data:e},"onFlagged"))),Km((e=>s({data:e},"onUnflagged"))),zm((e=>s({data:e},"onReactionAdded"))),Jm((e=>s({data:e},"onReactionRemoved")))),_e(ge(Rm,e),(e=>i(e,"onFetch")),ye(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observeComments=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeComments(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.referenceId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push($m((e=>i(e,"onCreate"))),Hm((e=>i(e,"onUpdate"))),Wm((e=>i(e,"onDelete"))),Vm((e=>i(e,"onFlagged"))),Km((e=>i(e,"onUnflagged"))),zm((e=>i(e,"onReactionAdded"))),Jm((e=>i(e,"onReactionRemoved")))),()=>{n(`observeComments(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeCommunity=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeCommunity(tmpid: ${r}) > listen`);const o=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.communityId)===e&&o(t,n)},s=[];return s.push(fg((e=>i({data:e},"onUpdate"))),hg((e=>i({data:e},"onDelete"))),mg((e=>i({data:e},"onJoin"))),gg((e=>i({data:e},"onLeft"))),yg((e=>i({data:e},"onUserAdded"))),bg((e=>i({data:e},"onUserRemoved"))),vg((e=>i({data:e},"onUserBanned"))),_g((e=>i({data:e},"onUserUnbanned")))),_e(ge(Cm,e),(e=>o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},e.observeFile=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return _e(ge(am,e),(n=>n.data&&((n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.fileId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}})(n,"onFetch"))),()=>{n(`observeFile(tmpid: ${r}) > dispose`)}},e.observeMessage=(e,t,n="cache_then_server")=>{const{log:r}=m(),o=Date.now();r(`observeMessage(tmpid: ${o}) > listen`);const i=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.messageId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},s=[];return s.push(ag((e=>i(e,"onUpdate"))),cg((e=>i(e,"onDelete")))),"no_fetch"!==n&&_e(ge(pm,e),(e=>e.data&&i(e,"onFetch")),ye(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},e.observeMessages=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeMessages(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.channelId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(sg((e=>i(e,"onCreate"))),ag((e=>i(e,"onUpdate"))),cg((e=>i(e,"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observePost=(e,t,n="cache_then_server")=>{const{log:r}=m(),o=Date.now();r(`observePost(tmpid: ${o}) > listen`);const i=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},s=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.postId)===e&&i(t,n)},a=[];return a.push(Mm((e=>s({data:e},"onUpdate"))),Bm((e=>s({data:e},"onDelete"))),jm((e=>s({data:e},"onApproved"))),Nm((e=>s({data:e},"onDeclined"))),Fm((e=>s({data:e},"onFlagged"))),Um((e=>s({data:e},"onUnflagged"))),Lm((e=>s({data:e},"onReactionAdded"))),Dm((e=>s({data:e},"onReactionRemoved")))),_e(ge(vm,e),(e=>i(e,"onFetch")),ye(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observePosts=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observePosts(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(e.targetId===n.targetId&&e.targetType===n.targetType){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(Pm((e=>i(e,"onCreate"))),Mm((e=>i(e,"onUpdate"))),Bm((e=>i(e,"onDelete"))),jm((e=>i(e,"onApproved"))),Nm((e=>i(e,"onDeclined"))),Fm((e=>i(e,"onFlagged"))),Um((e=>i(e,"onUnflagged"))),Lm((e=>i(e,"onReactionAdded"))),Dm((e=>i(e,"onReactionRemoved")))),()=>{n(`observePosts(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeUser=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeUser(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.userId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(rm((e=>o({data:e},"onUpdate"))),om((e=>o({data:e},"onFlagged"))),im((e=>o({data:e},"onUnflagged"))),sm((e=>o({data:e},"onFlagCleared")))),_e(ge(Gh,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.onChannelDeleted=tg,e.onChannelJoined=ng,e.onChannelLeft=rg,e.onChannelUpdated=eg,e.onClientBanned=Eh,e.onClientDisconnected=e=>kh((({code:t})=>{800211===t&&e()})),e.onCommentCreated=$m,e.onCommentDeleted=Wm,e.onCommentFlagged=Vm,e.onCommentReactionAdded=zm,e.onCommentReactionRemoved=Jm,e.onCommentUnflagged=Km,e.onCommentUpdated=Hm,e.onCommunityCreated=e=>lg("community.created",e),e.onCommunityDeleted=hg,e.onCommunityJoined=mg,e.onCommunityLeft=gg,e.onCommunityUpdated=fg,e.onCommunityUserAdded=yg,e.onCommunityUserBanned=vg,e.onCommunityUserRemoved=bg,e.onCommunityUserUnbanned=_g,e.onConnectionError=kh,e.onMemberAdded=og,e.onMemberRemoved=ig,e.onMessageCreated=sg,e.onMessageDeleted=cg,e.onMessageUpdated=ag,e.onPostApproved=jm,e.onPostCreated=Pm,e.onPostDeclined=Nm,e.onPostDeleted=Bm,e.onPostFlagged=Fm,e.onPostReactionAdded=Lm,e.onPostReactionRemoved=Dm,e.onPostUnflagged=Um,e.onPostUpdated=Mm,e.onReactionRemoved=(e,t,n)=>{const r=r=>{v(e)(r)===t&&n(r)};if("message"===e){const e=m(),t=e=>{var t,n;const o=(null===(n=(null!==(t=y("message",e.messages[0].messageId))&&void 0!==t?t:[])[0])||void 0===n?void 0:n.reactionsCount)!==e.messages[0].reactionsCount;$h(e),B(e),o&&r(e.messages[0])};return vh(e,"reaction/onReactionRemoved","v3.message.didUpdate",t)}return"post"===e?Dm(r):Jm(r)},e.onUserFlagCleared=sm,e.onUserFlagged=om,e.onUserUnflagged=im,e.onUserUpdated=rm,e.persistentStore=async(e,t={},n=250)=>{let r=t;const o=await qh.getItem(e);if(o)try{r=JSON.parse(o)}catch(e){}const i=Rh(r);let s=null;const a=()=>{s?s.then((()=>a())):(clearTimeout(undefined),setTimeout((async()=>{s=Promise.resolve().then((()=>qh.setItem(e,JSON.stringify(i.read())))).then((()=>s=null))}),n))};return{read:i.read,write:e=>{i.write(e),a()},erase:(...e)=>{i.erase(...e),a()}}},e.pullFromCache=y,e.pushToCache=w,e.queryChannelMembers=Zm,e.queryChannels=Qm,e.queryComments=km,e.queryCommunities=_m,e.queryCommunityMembers=Sm,e.queryGlobalFeed=async e=>{const t=m();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v4/me/global-feeds",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"skiplimit")}})}),{paging:s}=i,a=em(i,["paging"]);$h(a),B(a);const{posts:c}=a,l=ce(s.next),u=ce(s.previous);return{data:A(c),nextPage:l,prevPage:u}},e.queryMessages=fm,e.queryOptions=ye,e.queryPosts=ym,e.queryRoles=cm,e.queryStreams=Cg,e.queryUsers=tm,e.removeChannelMembers=async(e,t)=>{const n=m();n.log("channel/removeChannelMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/channels/${e}/users`,{data:{channelId:e,userIds:t}});$h(r),B(r),_h("v3.channel.didRemoveUsers",{channels:r.channels});const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},e.removeChannelMembersRole=async(e,t,n)=>{const r=m();r.log("channel/removeChannelMembersRole",e,t,n);const{data:o}=await r.http.delete(`/api/v3/channels/${e}/users/roles`,{data:{channelId:e,role:t,userIds:n}});$h(o),B(o);const{channelUsers:i}=o;return!!i.find((n=>n.channelId===e&&!n.roles.includes(t)))},e.removeCommunityMembers=async(e,t)=>{const n=m();n.log("community/removeCommunityMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/communities/${e}/users`,{data:{communityId:e,userIds:t}});$h(r),B(r),_h("community.userRemoved",{communities:r.communities});const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.removeCommunityMembersRole=async(e,t,n)=>{const r=m();r.log("community/removeCommunityMembersRole",e,t,n);const{data:o}=await r.http.delete(`/api/v3/communities/${e}/users/roles`,{data:{communityId:e,role:t,userIds:n}});$h(o),B(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&!n.roles.includes(t)))},e.removeReaction=Tm,e.runQuery=_e,e.sliceByPaging=(e,t,n)=>{if(console.log("slice by paging",n),!n)return t.slice();let r,o=0;n.after?(o=n.after,r=o+n.limit):n.before&&(r=n.before+1,o=r>n.limit?r-n.limit:0);const i=t.slice(o,r);return i.length===n.limit?i:void 0},e.sortByChannelSegment=Kh,e.sortByDisplayName=({displayName:e},{displayName:t})=>e===t?0:e<t?-1:1,e.sortByFirstCreated=({createdAt:e},{createdAt:t})=>new Date(e).valueOf()-new Date(t).valueOf(),e.sortByLastActivity=({lastActivity:e},{lastActivity:t})=>new Date(t).valueOf()-new Date(e).valueOf(),e.sortByLastCreated=({createdAt:e},{createdAt:t})=>new Date(t).valueOf()-new Date(e).valueOf(),e.sortBySegmentNumber=zh,e.subscribeTopic=function(e,t){const{mqtt:n,emitter:r,accessToken:o,user:i}=m();return Qh===o&&Xh===i._id||(Qh=o,Xh=i._id,n.connect({accessToken:o,userId:i._id}),((e,t)=>{yh.forEach((n=>{e.on(n,((...e)=>t.emit(n,1===e.length?e[0]:e)))})),e.on("message",((e,n)=>{const r=JSON.parse(n.toString());t.emit(r.eventType,r.data)}))})(n,r)),n.subscribe(e,t)},e.syncInCache=E,e.toPage=ce,e.toToken=ae,e.updateChannel=async(e,t)=>{const n=m();n.log("channel/updateChannel",e,t);const{data:r}=await n.http.put(`/api/v3/channels/${e}`,t);$h(r),B(r);const{channels:o}=r;return o.find((t=>t.channelId===e))},e.updateComment=async(e,t)=>{const n=m();n.log("user/updateComment",t);const{data:r}=await n.http.put(`/api/v3/comments/${e}`,t);$h(r),B(r),_h("comment.updated",r);const{comments:o}=r;return o.find((t=>t.commentId===e))},e.updateCommunity=async(e,t)=>{const n=m();n.log("community/updateCommunity",e,t);const{data:r}=await n.http.put(`/api/v3/communities/${e}`,t);$h(r),B(r),_h("community.updated",r);const{communities:o}=r;return o.find((t=>t.communityId===e))},e.updateMessage=mm,e.updatePost=async(e,t)=>{const n=m();n.log("user/updatePost",t);const{data:r}=await n.http.put(`/api/v3/posts/${e}`,t);$h(r),B(r),_h("post.updated",r);const{posts:o}=r;return o.find((t=>t.postId===e))},e.updateStream=async(e,t)=>{const n=m();n.log("stream/updateStream",e,t);const{data:r}=await n.http.put(`/api/v3/video-streaming/${e}`,t);$h(r),B(r);const{videoStreamings:o}=r;return o.find((t=>t.streamId===e))},e.updateUser=async(e,t)=>{const n=m();n.log("user/updateUser",e,t);const{data:r}=await n.http.put("/api/v3/users/",Object.assign(Object.assign({userId:e},t),{createNewUserWhenNotFound:!1}));return $h(r),B(r),r.users.find((t=>t.userId===e))},Object.defineProperty(e,"__esModule",{value:!0}),e}({},require$$0$1,require$$2,require$$2$1);
|
|
19
|
+
function em(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}Zh.locally=e=>{var t;const n=null!==(t=y("user",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const tm=async e=>{const t=m();t.log("user/queryUsers",e);const n=null!=e?e:{},{page:r,displayName:o,filter:i="all",sortBy:s="displayName"}=n,a=em(n,["page","displayName","filter","sortBy"]),{data:c}=await t.http.get("/api/v3/users",{params:Object.assign(Object.assign({},a),{keyword:o,filter:i,sortBy:s,options:{token:ae(r,"skiplimit")}})}),{paging:l}=c,u=em(c,["paging"]);$h(u),B(u);const p=ce(l.previous),d=ce(l.next),{users:f}=u;return{data:A(f),prevPage:p,nextPage:d}};tm.locally=e=>{m().log("user/queryUsers.locally",e)};const nm=(e,t)=>{const n=m();return vh(n,e,e,(e=>{$h(e),B(e),t(e.users[0])}))},rm=e=>nm("user.updated",e),om=e=>nm("user.flagged",e),im=e=>nm("user.unflagged",e),sm=e=>nm("user.flagCleared",e),am=async e=>{const t=m();t.log("file/getFile",e);const{data:n}=await t.http.get(`/api/v3/files/${e}`);return Wh(n),B({files:[n]}),n};am.locally=e=>{var t;m().log("file/getFile.locally",e);const[n]=null!==(t=y("file",e))&&void 0!==t?t:[];return n};const cm=async e=>{const t=m();t.log("role/queryRoles",e);const n=null!=e?e:{},{page:r,displayName:o,sortBy:i}=n,s=em(n,["page","displayName","sortBy"]),{data:a}=await t.http.get("/api/v3/roles",{params:Object.assign(Object.assign({},s),{keyword:o,sortBy:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const u=ce(c.previous),p=ce(c.next),{roles:d}=l;return{data:A(d),prevPage:u,nextPage:p}};cm.locally=e=>{m().log("role/queryRoles.locally",e)};const lm=async e=>{const t=m();t.log("role/getRole",e);const{data:n}=await t.http.get(`/api/v3/roles/${e}`);return Hh(n),B({roles:n}),n.find((t=>t.roleId===e))};lm.locally=e=>{var t;m().log("role/getRole.locally",e);const[n]=null!==(t=y("role",e))&&void 0!==t?t:[];return n};const um=(e,t)=>{"message"===e?_h("v3.message.didUpdate",{messages:[t]}):"post"===e?_h("post.updated",{posts:[t]}):"comment"===e&&_h("comment.updated",{comments:[t]})},pm=async e=>{const t=m();t.log("message/getMessage",e);const{data:n}=await t.http.get(`/api/v3/messages/${e}`);$h(n),B(n);const{messages:r}=n;return r.find((t=>t.messageId===e))};pm.locally=e=>{var t;m().log("message/getMessage.locally",e);const[n]=null!==(t=y("message",e))&&void 0!==t?t:[];return n};const dm=async e=>{const t=m();t.log("message/getMessages",e);const{data:n}=await t.http.get("/api/v3/messages/list",{params:{messageIds:e}});$h(n),B(n);const{messages:r}=n;return A(r)};dm.locally=e=>{var t;m().log("message/getMessages.locally",e);const n=null!==(t=y("message",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const fm=async e=>{const t=m();t.log("message/queryMessages",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v3/messages",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"afterbefore")}})}),{paging:s}=i,a=em(i,["paging"]);$h(a),B(a);const{messages:c}=a,l=ce(s.next),u=ce(s.previous);return{data:A(c),nextPage:l,prevPage:u}};fm.locally=e=>{var t,n,r,o,i;m().log("message/queryMessages.locally",e);const{channelId:s,page:a}=e,[c]=null!==(t=y("channel",s))&&void 0!==t?t:[];let l=null!==(n=y("message"))&&void 0!==n?n:[];if(l=Vh(l,"channelId",s),l=l.sort(Kh),a){let e,t=0;"after"in a?(t=0!==a.after?l.findIndex((e=>e.channelSegment===(null==a?void 0:a.after)))+1:0,e=t+a.limit):"before"in a&&(e=0!==a.before?l.findIndex((e=>e.channelSegment===(null==a?void 0:a.before)))+1:l.length-1,t=e>a.limit?e-a.limit:0);const n=l.slice(t,e);l=n.length===a.limit?n:[]}const u=(null===(r=l[0])||void 0===r?void 0:r.channelSegment)>0?{before:l[0].channelSegment,limit:null==a?void 0:a.limit}:void 0,p=(null===(o=l[l.length-1])||void 0===o?void 0:o.channelSegment)<(null!==(i=null==c?void 0:c.messageCount)&&void 0!==i?i:0)?{after:l[l.length-1].channelSegment,limit:null==a?void 0:a.limit}:void 0;return{data:A(l),nextPage:p,prevPage:u}};const hm=async e=>{const t=m();t.log("user/createMessage",e);const{data:n}=await t.http.post("/api/v3/messages",e);$h(n),B(n);const{messages:r}=n;return r[0]};hm.optimistically=e=>{var t,n,r;const o=m();if(o.log("user/createMessage.locally",e),!o.cache)return;const[i]=null!==(t=y("channel",e.channelId))&&void 0!==t?t:[];w("channel",Object.assign(Object.assign({},i),{messageCount:(null!==(n=i.messageCount)&&void 0!==n?n:0)+1}));const s=Object.assign(Object.assign({localId:mt(),messageId:Math.random().toString(16),userId:o.userId,channelSegment:(null!==(r=null==i?void 0:i.messageCount)&&void 0!==r?r:0)+1,createdAt:(new Date).toISOString()},e),{syncedAt:-1});return w("message",s),_h("v3.message.didCreate",{messages:[s]}),s};const mm=async(e,t)=>{const n=m();n.log("user/updateMessage",t);const{data:r}=await n.http.put(`/api/v3/messages/${e}`,t);return $h(r),B(r),r.messages.find((t=>t.messageId===e))};mm.optimistically=(e,t)=>{var n;m().log("user/updateMessage",t);const[r]=null!==(n=y("message",e))&&void 0!==n?n:[];if(!r)return;const o=Object.assign(Object.assign(Object.assign({},r),t),{updatedAt:(new Date).toISOString()});return w("message",o),_h("v3.message.didUpdate",{messages:[o]}),o};const gm=async e=>{const t=m();t.log("message/deleteMessage",e),await t.http.delete(`/api/v3/messages/${e}`);return await pm(e)};gm.optimistically=e=>{var t;m().log("message/deleteMessage",e);const[n]=null!==(t=y("message",e))&&void 0!==t?t:[];if(!n)return;const r=Object.assign(Object.assign({},n),{isDeleted:!0,updatedAt:(new Date).toISOString()});return w("message",r),_h("v3.message.didDelete",{messages:[r]}),r};const ym=async e=>{const t=m();t.log("post/queryPosts",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v3/posts",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"skiplimit")}})}),{paging:s}=i,a=em(i,["paging"]);$h(a),B(a);const{posts:c}=a,l=ce(s.next),u=ce(s.previous);return{data:A(c),nextPage:l,prevPage:u}};ym.locally=e=>{m().log("post/queryPosts.locally",e)};const bm=async e=>{const t=m();t.log("post/getPosts",e);const{data:n}=await t.http.get("/api/v3/posts/list",{params:{postIds:e}});$h(n),B(n);const{posts:r}=n;return r};bm.locally=e=>{var t;m().log("post/getPosts.locally",e);const n=null!==(t=y("post",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const vm=async e=>{var t;const n=m();let r;n.log("post/getPost",e);try{r=(await n.http.get(`/api/v3/posts/${e}`)).data}catch(n){throw 400400===(null===(t=n)||void 0===t?void 0:t.code)&&C("post",{postId:e}),n}$h(r),B(r);const{posts:o}=r;return o.find((t=>t.postId===e))};vm.locally=e=>{var t;m().log("post/getPost.locally",e);const[n]=null!==(t=y("post",e))&&void 0!==t?t:[];return n};const _m=async e=>{const t=m();t.log("channel/queryCommunities",e);const n=null!=e?e:{},{page:r,displayName:o,membership:i}=n,s=em(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/communities",{params:Object.assign(Object.assign({},s),{keyword:o,filter:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const u=ce(null==c?void 0:c.previous),p=ce(null==c?void 0:c.next),{communities:d}=l;return{data:A(d),prevPage:u,nextPage:p}};_m.locally=e=>{m().log("community/queryCommunities.locally",e)};const wm=async e=>{const t=m();t.log("community/getCommunities",e);const{data:n}=await t.http.get("/api/v3/communities/list",{params:{communityIds:e}});$h(n),B(n);const{communities:r}=n;return A(r)};wm.locally=e=>{var t;m().log("community/getCommunities.locally",e);const n=null!==(t=y("community",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const Cm=async e=>{const t=m();t.log("community/getCommunity",e);const{data:n}=await t.http.get(`/api/v3/communities/${e}`);$h(n),B(n);const{communities:r}=n;return r.find((t=>t.communityId===e))};Cm.locally=e=>{var t;m().log("community/getCommunity.locally",e);const[n]=null!==(t=y("community",e))&&void 0!==t?t:[];return n};const Sm=async e=>{const t=m();t.log("community/queryCommunityMembers",e);const n=null!=e?e:{},{page:r,communityId:o}=n,i=em(n,["page","communityId"]),{data:s}=await t.http.get(`/api/v3/communities/${o}/users`,{params:Object.assign(Object.assign({},i),{options:{token:ae(r,"skiplimit")}})}),{paging:a}=s,c=em(s,["paging"]);$h(c),B(c);const{communityUsers:l}=c,u=ce(a.next),p=ce(a.previous);return{data:A(l),nextPage:u,prevPage:p}};Sm.locally=e=>{m().log("community/queryCommunityMembers",e)};const km=async e=>{const t=m();t.log("comment/queryComments",e);const{page:n}=e,r=em(e,["page"]);e.parentId;const{data:o}=await t.http.get("/api/v3/comments",{params:Object.assign(Object.assign({},r),{options:{token:ae(n,"afterbefore")}})}),{paging:i}=o,s=em(o,["paging"]);$h(s),B(s);const a=ce(i.previous),c=ce(i.next),{comments:l}=s;return{data:A(l),prevPage:a,nextPage:c}};km.locally=e=>{var t;m().log("post/queryComments.locally",e);const{referenceId:n,referenceType:r,parentId:o,isDeleted:i,page:s={before:0,limit:5}}=e;isNaN(s.limit)&&(s.limit=5);let a=null!==(t=y("comment"))&&void 0!==t?t:[];if(!a.length)return;if(a=Vh(a,"referenceId",n),a=Vh(a,"referenceType",r),a=Vh(a,"parentId",o),a=Vh(a,"isDeleted",i),!a.length)return;a=a.sort(zh);const c=isNaN(s.after)?0:a.findIndex((({segmentNumber:e})=>e===s.after+1)),l=isNaN(s.before)||0===s.before?a.length:a.findIndex((({segmentNumber:e})=>e===s.before-1))+1;if(c<0||l<0)return;let u=a.slice(-1!==c?c:0,-1!==l?l:void 0);if(u.length<s.limit)return;(isNaN(s.after)||isNaN(s.before))&&(u=isNaN(s.after)?(isNaN(s.before),u.slice(-s.limit)):u.slice(0,s.limit));for(let e=0;e<u.length-1;e++)if(u[e].segmentNumber!==u[e+1].segmentNumber-1)return;const p=u[0].segmentNumber>1?{before:u[0].segmentNumber,limit:s.limit}:void 0,d=u[u.length-1].segmentNumber<a[a.length-1].segmentNumber?{after:u[u.length-1].segmentNumber,limit:s.limit}:void 0;return{data:A(u),nextPage:d,prevPage:p}};const Em=async e=>{const t=m();t.log("comment/getComments",e);const{data:n}=await t.http.get("/api/v3/comments/list",{params:{commentIds:e}});$h(n),B(n);const{comments:r}=n;return A(r)};Em.locally=e=>{var t;m().log("comment/getComments.locally",e);const n=null!==(t=y("comment",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const Rm=async e=>{var t;const n=m();let r;n.log("comment/getComment",e);try{r=(await n.http.get(`/api/v3/comments/${e}`)).data}catch(n){throw 400400===(null===(t=n)||void 0===t?void 0:t.code)&&C("comment",{commentId:e}),n}$h(r),B(r);const{comments:o}=r;return o.find((t=>t.commentId===e))};Rm.locally=e=>{var t;m().log("comment/getComment.locally",e);const[n]=null!==(t=y("comment",e))&&void 0!==t?t:[];return n};const Im=async(e,t)=>{if("message"===e)return pm(t);if("post"===e)return vm(t);if("comment"===e)return Rm(t);throw new Error(`Incorrect referenceType: ${e}`)},Am=(e,t)=>{var n,r;if(m().userId!==t.reactor.userId)return;let o,i;if("post.addReaction"===e||"post.removeReaction"===e){const e=t.posts[0];i=(null!==(n=y("post",e.postId))&&void 0!==n?n:[])[0],o=e}else{const e=t.comments[0];i=(null!==(r=y("comment",e.commentId))&&void 0!==r?r:[])[0],o=e}if(i&&i.myReactions)if("post.addReaction"===e||"comment.addReaction"===e){if(i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:[...i.myReactions,t.reactor.reactionName]})}else{if(!i.myReactions.includes(t.reactor.reactionName))return;Object.assign(o,{myReactions:i.myReactions.filter((e=>e!==t.reactor.reactionName))})}},Om=async(e,t,n)=>{var r,o;const i=m();i.log("reaction/createReaction",{referenceId:t,referenceType:e,reactionName:n}),await i.http.post("/api/v2/reactions",{referenceId:t,referenceType:e,reactionName:n});const s=await Im(e,t);return um(e,s),null!==(o=null===(r=s.myReactions)||void 0===r?void 0:r.includes(n))&&void 0!==o&&o};Om.optimistically=(e,t,n)=>{var r,o;const i=R(e,t,(e=>{var t,r,o;if(!(null===(t=e.myReactions)||void 0===t?void 0:t.includes(n)))return Object.assign(Object.assign({},e),{syncedAt:-1,reactionsCount:e.reactionsCount+1,myReactions:[...null!==(r=e.myReactions)&&void 0!==r?r:[],n],reactions:Object.assign(Object.assign({},e.reactions),{[n]:(null!==(o=e.reactions[n])&&void 0!==o?o:0)+1})})}));return i&&um(e,i),null!==(o=null===(r=null==i?void 0:i.myReactions)||void 0===r?void 0:r.includes(n))&&void 0!==o&&o};const Tm=async(e,t,n)=>{var r,o;const i=m();i.log("reaction/removeReaction",{referenceId:t,referenceType:e,reactionName:n}),await i.http.delete("/api/v2/reactions",{data:{referenceId:t,referenceType:e,reactionName:n}});const s=await Im(e,t);return um(e,s),null!==(o=!(null===(r=s.myReactions)||void 0===r?void 0:r.includes(n)))&&void 0!==o&&o};Tm.optimistically=(e,t,n)=>{var r,o;const i=R(e,t,(e=>{var t,r,o;if(null===(t=e.myReactions)||void 0===t?void 0:t.includes(n))return Object.assign(Object.assign({},e),{syncedAt:-1,reactionsCount:Math.max(0,e.reactionsCount-1),myReactions:(null!==(r=e.myReactions)&&void 0!==r?r:[]).filter((e=>e!==n)),reactions:Object.assign(Object.assign({},e.reactions),{[n]:Math.max(0,(null!==(o=e.reactions[n])&&void 0!==o?o:0)-1)})})}));return i&&um(e,i),null!==(o=!(null===(r=null==i?void 0:i.myReactions)||void 0===r?void 0:r.includes(n)))&&void 0!==o&&o};const xm=(e,t)=>{const n=m();return vh(n,e,e,(e=>{var n,r;const[o]=null!==(n=y("post",e.posts[0].postId))&&void 0!==n?n:[],{communities:i}=e,s=em(e,["communities"]);$h(s),B(s),(null==i?void 0:i[0])&&_h("community.updated",{communities:i});const[a]=null!==(r=y("post",s.posts[0].postId))&&void 0!==r?r:[];o&&M(o,a)||t(a)}))},Pm=e=>xm("post.created",e),Mm=e=>xm("post.updated",e),Bm=e=>xm("post.deleted",e),jm=e=>xm("post.approved",e),Nm=e=>xm("post.declined",e),Fm=e=>xm("post.flagged",e),Um=e=>xm("post.unflagged",e),Lm=e=>{const t=m();return vh(t,"post.addReaction","post.addReaction",(t=>{var n,r;const[o]=null!==(n=y("post",t.posts[0].postId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("post.addReaction",t),B(i);const[s]=null!==(r=y("post",t.posts[0].postId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))},Dm=e=>{const t=m();return vh(t,"post.removeReaction","post.removeReaction",(t=>{var n,r;const[o]=null!==(n=y("post",t.posts[0].postId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("post.removeReaction",t),B(i);const[s]=null!==(r=y("post",t.posts[0].postId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))},qm=(e,t)=>{const n=m();return vh(n,e,e,(e=>{var n,r;const[o]=null!==(n=y("comment",e.comments[0].commentId))&&void 0!==n?n:[];$h(e),B(e);const[i]=null!==(r=y("comment",e.comments[0].commentId))&&void 0!==r?r:[];o&&M(o,i)||t(i)}))},$m=e=>qm("comment.created",e),Hm=e=>qm("comment.updated",e),Wm=e=>qm("comment.deleted",e),Vm=e=>qm("comment.flagged",e),Km=e=>qm("comment.unflagged",e),zm=e=>{const t=m();return vh(t,"comment.addReaction","comment.addReaction",(t=>{var n,r;const[o]=null!==(n=y("comment",t.comments[0].commentId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("comment.addReaction",t),B(i);const[s]=null!==(r=y("comment",t.comments[0].commentId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))},Jm=e=>{const t=m();return vh(t,"comment.removeReaction","comment.removeReaction",(t=>{var n,r;const[o]=null!==(n=y("comment",t.comments[0].commentId))&&void 0!==n?n:[],i=em(t,["reactor"]);$h(i),Am("comment.removeReaction",t),B(i);const[s]=null!==(r=y("comment",t.comments[0].commentId))&&void 0!==r?r:[];o&&M(o,s)||e(s)}))};var Ym={post:{domainName:"posts",eventName:"v3/post.isflagbyme",primaryKey:"postId"},comment:{domainName:"comments",eventName:"v3/comment.isflagbyme",primaryKey:"commentId"},message:{domainName:"messages",eventName:"v3/message.isFlaggedByMe",primaryKey:"messageId"},user:{domainName:"users",eventName:"user.isFlagByMe",primaryKey:"userId"}};const Qm=async e=>{const t=m();t.log("channel/queryChannels",e);const n=null!=e?e:{},{page:r,displayName:o,membership:i}=n,s=em(n,["page","displayName","membership"]),{data:a}=await t.http.get("/api/v3/channels",{params:Object.assign(Object.assign({},s),{keyword:o,filter:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const u=ce(null==c?void 0:c.previous),p=ce(null==c?void 0:c.next),{channels:d}=l;return{data:A(d),prevPage:u,nextPage:p}};Qm.locally=e=>{m().log("channel/queryChannels.locally",e)};const Xm=async e=>{const t=m();t.log("channel/getChannels",e);const{data:n}=await t.http.get("/api/v3/channels/list",{params:{channelIds:e}});$h(n),B(n);const{channels:r}=n;return A(r)};Xm.locally=e=>{var t;m().log("channel/getChannels.locally",e);const n=null!==(t=y("channel",...e))&&void 0!==t?t:[];if((null==n?void 0:n.length)===e.length)return A(n)};const Gm=async e=>{const t=m();t.log("channel/getChannel",e);const{data:n}=await t.http.get(`/api/v3/channels/${e}`);$h(n),B(n);const{channels:r}=n;return r.find((t=>t.channelId===e))};Gm.locally=e=>{var t;m().log("channel/getChannel.locally",e);const[n]=null!==(t=y("channel",e))&&void 0!==t?t:[];return n};const Zm=async e=>{const t=m();t.log("channel/queryChannelMembers",e);const n=null!=e?e:{},{page:r,channelId:o,membership:i}=n,s=em(n,["page","channelId","membership"]),{data:a}=await t.http.get(`/api/v3/channels/${o}/users`,{params:Object.assign(Object.assign({},s),{filter:i,options:{token:ae(r,"skiplimit")}})}),{paging:c}=a,l=em(a,["paging"]);$h(l),B(l);const{channelUsers:u}=l,p=ce(c.next),d=ce(c.previous);return{data:A(u),nextPage:p,prevPage:d}};Zm.locally=e=>{m().log("channel/queryChannelMembers",e)};const eg=e=>{const t=m();return vh(t,"onChannelUpdated","v3.channel.didUpdate",(t=>{$h(t),B(t),e(t.channels[0])}))},tg=e=>{const t=m();return vh(t,"onChannelDeleted","v3.channel.didDelete",(t=>{$h(t),B(t),e(t.channels[0])}))},ng=e=>{const t=m();return vh(t,"onChannelJoined","v3.channel.didJoin",(t=>{$h(t),B(t),e(t.channels[0])}))},rg=e=>{const t=m();return vh(t,"onChannelLeft","v3.channel.didLeave",(t=>{$h(t),B(t),e(t.channels[0])}))},og=e=>{const t=m();return vh(t,"onMemberAdded","v3.channel.didAddUsers",(t=>{$h(t),B(t),e(t.channels[0])}))},ig=e=>{const t=m();return vh(t,"onMemberRemoved","v3.channel.didRemoveUsers",(t=>{$h(t),B(t),e(t.channels[0])}))},sg=e=>{const t=m();return vh(t,"message/onMessageCreated","v3.message.didCreate",(t=>{$h(t),B(t),e(t.messages[0])}))},ag=e=>{const t=m();return vh(t,"message/onMessageUpdated","v3.message.didUpdate",(t=>{$h(t),B(t),e(t.messages[0])}))},cg=e=>{const t=m();return vh(t,"message/onMessageDeleted","v3.message.didDelete",(t=>{$h(t),B(t),e(t.messages[0])}))},lg=(e,t)=>{const n=m();return vh(n,e,e,(e=>{var n,r;const[o]=null!==(n=y("community",e.communities[0].communityId))&&void 0!==n?n:[];$h(e),B(e);const[i]=null!==(r=y("community",e.communities[0].communityId))&&void 0!==r?r:[];o&&M(o,i)||t(i)}))};function ug(e,t,n){return!!e.permissions.some((e=>e===n))||t.users.find((t=>t.userId===e.userId)).permissions.some((e=>e===n))}function pg(e,t){return"community.joined"===e||"community.left"===e?t.communityUsers[0]:"community.userRemoved"===e?t.communityUsers.filter((e=>"none"===e.communityMembership))[0]:"community.userBanned"===e?t.communityUsers.filter((e=>"banned"===e.communityMembership))[0]:"community.userUnbanned"===e?t.communityUsers.filter((e=>!ug(e,t,"BAN_COMMUNITY_USER")))[0]:t.communityUsers.filter((e=>!ug(e,t,"ADD_COMMUNITY_USER")))[0]}const dg=(e,t)=>{const n=m();return vh(n,e,e,(n=>{var r,o,i,s;const[a]=null!==(r=y("community",n.communities[0].communityId))&&void 0!==r?r:[],[c]=null!==(o=y("communityUsers",v("communityUsers")(pg(e,n))))&&void 0!==o?o:[];$h(n),B(n);const[l]=null!==(i=y("community",n.communities[0].communityId))&&void 0!==i?i:[],[u]=null!==(s=y("communityUsers",v("communityUsers")(pg(e,n))))&&void 0!==s?s:[];a&&M(a,l)&&c&&M(c,u)||t(l,u)}))},fg=e=>lg("community.updated",e),hg=e=>lg("community.deleted",e),mg=e=>dg("community.joined",e),gg=e=>dg("community.left",e),yg=e=>dg("community.userAdded",e),bg=e=>dg("community.userRemoved",e),vg=e=>dg("community.userBanned",e),_g=e=>dg("community.userUnbanned",e),wg=async e=>{const t=m();t.log("stream/getStream",e);const{data:n}=await t.http.get(`/api/v3/video-streaming/${e}`);$h(n),B(n);const{videoStreamings:r}=n;return r.find((t=>t.streamId===e))};wg.locally=e=>{var t;m().log("stream/getStream",e);const[n]=null!==(t=y("stream",e))&&void 0!==t?t:[];return n};const Cg=async e=>{const t=m();t.log("stream/queryStreams",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v3/video-streaming",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"skiplimit")}})}),{paging:s,results:a}=i;$h(a),B(a);const c=ce(null==s?void 0:s.previous),l=ce(null==s?void 0:s.next),{videoStreamings:u}=a;return{data:A(u),prevPage:c,nextPage:l}};Cg.locally=e=>{m().log("stream/queryStreams.locally",e)};return e.VERSION=l,e.addChannelMembers=async(e,t)=>{const n=m();n.log("channel/addChannelMembers",e,t);const{data:r}=await n.http.post(`/api/v3/channels/${e}/users`,{channelId:e,userIds:t});$h(r),B(r),_h("v3.channel.didAddUsers",{channels:r.channels});const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"===t.membership))},e.addChannelMembersRole=async(e,t,n)=>{const r=m();r.log("channel/addChannelMembersRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/channels/${e}/users/roles`,{channelId:e,role:t,userIds:n});$h(o),B(o);const{channelUsers:i}=o;return!!i.find((n=>n.channelId===e&&n.roles.includes(t)))},e.addCommunityMembers=async(e,t)=>{const n=m();n.log("community/addCommunityMembers",e,t);const{data:r}=await n.http.post(`/api/v3/communities/${e}/users`,{communityId:e,userIds:t});$h(r),B(r),_h("community.userAdded",{communities:r.communities});const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.addCommunityMembersRole=async(e,t,n)=>{const r=m();r.log("community/addCommunityMembersRole",e,t,n);const{data:o}=await r.http.post(`/api/v3/communities/${e}/users/roles`,{communityId:e,role:t,userIds:n});$h(o),B(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&n.roles.includes(t)))},e.addReaction=Om,e.clearCache=(e=["user","file","channel","message","community","post","comment"])=>{const t=m();t.log("client/api/enableCache"),e.forEach((e=>{var n,r;return null===(r=null===(n=t.cache)||void 0===n?void 0:n[e])||void 0===r?void 0:r.erase()}))},e.connectClient=async e=>{var t,n;const r=m();r.log("client/api/connectClient",Object.assign({apiKey:r.apiKey},e)),null!==(t=e.displayName)&&void 0!==t||(e.displayName=e.userId),null!==(n=e.deviceId)&&void 0!==n||(e.deviceId=`ascWebSdk#${Math.random().toString(16)}`);const{accessToken:o,users:i}=await(async e=>{const t=m();t.log("client/api/getToken",e);const n=await Ch(),{data:r}=await t.http.post("/v1/device",Object.assign(Object.assign({},e),{deviceInfo:n}),{headers:{"X-API-Key":t.apiKey}});return r})(e);r.http.defaults.headers.common.Authorization=`Bearer ${o}`,r.ws.io.opts.query={token:o},((e,t)=>{gh.forEach((n=>{e.on(n,(e=>t.emit(n,e)))}))})(r.ws,r.emitter),await new Promise((e=>{r.ws.once("connect",e),r.ws.open()}));const s=Eh((()=>{wh(),s()}));return r.userId=e.userId,r.user=i[0],r.accessToken=o,r.ws.connected},e.createCache=j,e.createChannel=async e=>{const t=m();let n;return t.log("user/createChannel",e),n="conversation"===(null==e?void 0:e.type)?await t.http.post("/api/v3/channels/conversation",Object.assign(Object.assign({},e),{isDistinct:!0})):await t.http.post("/api/v3/channels",e),$h(n.data),B(n.data),n.data.channels[0]},e.createClient=(e,t=It,n="amity")=>{const r=(e=>{const t=`${null==e?void 0:e.trim()}`.length>0&&"production"!==process.env.NODE_ENV,n=Rt(e),r=(e,...r)=>{t&&n(e,r)};return r.__instance__=n,r})(n);r("client/api/createClient",{apiKey:e.replace(/.{5}$/g,"xxxxx"),apiEndpoint:t});const o=(e=>{const t={maxSockets:100,maxFreeSockets:10,timeout:6e4,freeSocketTimeout:3e4},n=Yn.create({baseURL:e,httpAgent:new Zn(t),httpsAgent:new Xn(t),paramsSerializer:tr});return n.interceptors.response.use((e=>e),(e=>{var t;const{response:n}=e;console.error(null!==(t=null==n?void 0:n.data)&&void 0!==t?t:e),n&&er(n.data)})),n})(Ot(At.HTTP,t)),i=(e=>{const t=ts(e,{autoConnect:!1,reconnectionDelay:2e3,transports:["websocket"]});return t.on("disconnect",(e=>{"io server disconnect"===e&&t.connect()})),t})(Ot(At.HTTP,t)),s=mh(Ot(At.MQTT,t)),a=bh(),c={version:`${l}`,apiKey:e,log:r,http:o,ws:i,mqtt:s,emitter:a,use:()=>g(c)};try{m()}catch(e){g(c)}return c},e.createComment=async e=>{const t=m();t.log("comment/createComment",e);const{data:n}=await t.http.post("/api/v3/comments",e);$h(n),B(n);const r=await vm(e.referenceId);_h("post.updated",{posts:[r]}),_h("comment.created",n);const{comments:o}=n;return o[0]},e.createCommunity=async e=>{const t=m();t.log("user/createCommunity",e);const{data:n}=await t.http.post("/api/v3/communities/",e);$h(n),B(n),_h("community.created",n);const{communities:r}=n;return r[0]},e.createFile=async(e,t)=>{const n=m();if(n.log("file/createFile",e),!e.getAll("file").length)throw new Error("The formData object must have a `file` key.");const r="getHeaders"in e?e.getHeaders():{"content-type":"multipart/form-data"},{data:o}=await n.http.post("/api/v3/files",e,{headers:r,onUploadProgress({loaded:e,total:n}){t&&t(Math.round(100*e/n))}});return Hh(o),B({files:o}),o[0]},e.createMessage=hm,e.createPost=async e=>{const t=m();t.log("post/createPost",e),e.dataType&&!["text","image","file"].includes(e.dataType)||delete e.dataType;const{data:n}=await t.http.post("/api/v3/posts",e);$h(n),B(n),_h("community.updated",{communities:n.communities}),_h("post.created",n);const{posts:r}=n;return r[0]},e.createQuery=ge,e.createReport=async(e,t)=>{const n=m();n.log("report/createReport",{referenceType:e,referenceId:t});const{domainName:r}=Ym[e],{data:o}=await n.http.post(`/api/v3/${r}/${t}/flag`),i="message"===e?"v3.message.didUpdate":`${e}.updated`;return $h(o),B(o),_h(i,o),!!o},e.createStream=async e=>{const t=m();t.log("stream/createStream",e);const{data:n}=await t.http.post("/api/v3/video-streaming",e);$h(n),B(n);const{videoStreamings:r}=n;return r[0]},e.decorateModel=Wh,e.decorateModels=Hh,e.decoratePayload=$h,e.deleteChannel=async e=>{const t=m();t.log("channel/deleteChannel",e),await t.http.delete(`/api/v3/channels/${e}`);return await Gm(e)},e.deleteComment=async(e,t=!1)=>{const n=m();n.log("comment/deleteComment",e);const r=await Rm(e);await n.http.delete(`/api/v4/comments/${e}`,{params:{commentId:e,permanent:t}});const o=Object.assign(Object.assign({},r),{isDeleted:!0}),i=await vm(r.referenceId);return _h("post.updated",{posts:[i]}),_h("comment.deleted",{comments:[o]}),t?setTimeout((()=>{C("comment",{commentId:e})}),0):I("comment",{commentId:e,isDeleted:!0}),o},e.deleteCommunity=async e=>{const t=m();t.log("community/deleteCommunity",e),await t.http.delete(`/api/v3/communities/${e}`);const n=await Cm(e);return _h("community.deleted",{communities:[n]}),n},e.deleteFile=async e=>{const t=m();t.log("file/deleteFile",e);const{data:n}=await t.http.delete(`/api/v3/files/${e}`);return C("file",{fileId:n.fileId}),{success:!0}},e.deleteMessage=gm,e.deletePost=async(e,t=!1)=>{const n=m();n.log("post/deletePost",e);let r=await vm(e);if(await n.http.delete(`/api/v4/posts/${e}`,{params:{postId:e,permanent:t}}),"community"===r.targetType){const e=await Cm(r.targetId);_h("community.updated",{communities:[e]})}const o=Object.assign(Object.assign({},r),{isDeleted:!0});return _h("post.deleted",{posts:[o]}),t?setTimeout((()=>{C("post",{postId:e})}),0):I("post",{postId:e,isDeleted:!0}),o},e.deleteReport=async(e,t)=>{const n=m();n.log("report/deleteReport",{referenceType:e,referenceId:t});const{domainName:r}=Ym[e],{data:o}=await n.http.delete(`/api/v3/${r}/${t}/unflag`),i="message"===e?"v3.message.didUpdate":`${e}.updated`;return $h(o),B(o),_h(i,o),!!o},e.deleteStream=async e=>{const t=m();t.log("stream/deleteStream",e);const{data:n}=await t.http.delete(`/api/v3/video-streaming/${e}`),{success:r}=n;return r},e.disconnectClient=wh,e.disposeStream=async e=>{const t=m();t.log("stream/disposeStream",e);const{data:n}=await t.http.delete(`/api/v3/video-streaming/${e}/streaming-url`);$h(n),B(n);const{videoStreamings:r}=n;return r.find((t=>t.streamId===e))},e.dropFromCache=C,e.enableCache=(e=Ih("user","file","channel","message","community","post","comment","communityUsers","channelUsers","stream"))=>{const t=m();t.log("client/api/enableCache"),t.cache=j(e)},e.fileUrlWithSize=(e,t)=>`${e}?size=${t}`,e.filterByPropEquality=Vh,e.getActiveClient=m,e.getChannel=Gm,e.getChannels=Xm,e.getComment=Rm,e.getCommentTopic=({path:e})=>e,e.getComments=Em,e.getCommunities=wm,e.getCommunity=Cm,e.getCommunityTopic=({path:t},n=e.SubscriptionLevels.COMMUNITY)=>Yh({path:t},n),e.getFile=am,e.getMessage=pm,e.getMessages=dm,e.getPost=vm,e.getPostTopic=({path:t},n=e.SubscriptionLevels.POST)=>"comment"===n?`${t}/comment/+`:t,e.getPosts=bm,e.getRole=lm,e.getStream=wg,e.getUser=Gh,e.getUserTopic=({path:t},n=e.SubscriptionLevels.USER)=>Yh({path:t},n),e.getUsers=Zh,e.ingestInCache=B,e.isAfterBefore=ie,e.isConnected=()=>{var e,t;const n=m();return n.log("client/api/isConnected",n),!!(n.userId&&(null===(t=null===(e=n.http.defaults.headers.common)||void 0===e?void 0:e.Authorization)||void 0===t?void 0:t.length)&&n.ws.connected)},e.isFetcher=le,e.isFresh=he,e.isLocal=fe,e.isMutator=ue,e.isOffline=pe,e.isPaged=se,e.isReportedByMe=async(e,t)=>{var n,r;const o=m();o.log("report/isReportedByMe",{referenceType:e,referenceId:t});const{eventName:i,primaryKey:s}=Ym[e],{result:a,isFlagByMe:c}=null!==(n=await(async(e,t,n)=>{const{ws:r}=e;return await new Promise(((e,o)=>{r.emit(t,n,(t=>{try{e(er(t))}catch(e){o(e)}}))}))})(o,i,{[s]:t}))&&void 0!==n?n:{};return null!==(r=null!=a?a:c)&&void 0!==r&&r},e.isSkipLimit=oe,e.isSyncable=de,e.isSynced=me,e.joinChannel=async e=>{const t=m();t.log("channel/joinChannel",e);const{data:n}=await t.http.post(`/api/v3/channels/${e}/join`);$h(n),B(n);const{channelUsers:r}=n;return!!r.find((t=>t.channelId===e&&"member"===t.membership))},e.joinCommunity=async e=>{const t=m();t.log("community/joinCommunity",e);const{data:n}=await t.http.post(`/api/v3/communities/${e}/join`);$h(n),B(n),_h("community.joined",{communities:n.communities});const{communityUsers:r}=n;return!!r.find((t=>t.communityId===e&&"member"===t.communityMembership))},e.leaveChannel=async e=>{const t=m();t.log("channel/leaveChannel",e);const{data:n}=await t.http.delete(`/api/v3/channels/${e}/leave`);$h(n),B(n);const{channelUsers:r}=n;return!!r.find((t=>t.channelId===e&&"member"!==t.membership))},e.leaveCommunity=async e=>{const t=m();t.log("community/leaveCommunity",e);const{data:n}=await t.http.delete(`/api/v3/communities/${e}/leave`);$h(n),B(n),_h("community.left",{communities:n.communities});const{communityUsers:r}=n;return!!r.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.memoryStore=Rh,e.memoryStores=Ih,e.mergeInCache=I,e.mutateCache=R,e.observeChannel=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeChannel(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.channelId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(eg((e=>o({data:e},"onUpdate"))),tg((e=>o({data:e},"onDelete"))),ng((e=>o({data:e},"onJoin"))),rg((e=>o({data:e},"onLeft"))),og((e=>o({data:e},"onMemberAdded"))),ig((e=>o({data:e},"onMemberRemoved")))),_e(ge(Gm,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeChannel(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.observeComment=(e,t,n="cache_then_server")=>{const{log:r}=m(),o=Date.now();r(`observeComment(tmpid: ${o}) > listen`);const i=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},s=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.commentId)===e&&i(t,n)},a=[];return a.push(Hm((e=>s({data:e},"onUpdate"))),Wm((e=>s({data:e},"onDelete"))),Vm((e=>s({data:e},"onFlagged"))),Km((e=>s({data:e},"onUnflagged"))),zm((e=>s({data:e},"onReactionAdded"))),Jm((e=>s({data:e},"onReactionRemoved")))),_e(ge(Rm,e),(e=>i(e,"onFetch")),ye(n)),()=>{r(`observeComment(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observeComments=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeComments(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.referenceId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push($m((e=>i(e,"onCreate"))),Hm((e=>i(e,"onUpdate"))),Wm((e=>i(e,"onDelete"))),Vm((e=>i(e,"onFlagged"))),Km((e=>i(e,"onUnflagged"))),zm((e=>i(e,"onReactionAdded"))),Jm((e=>i(e,"onReactionRemoved")))),()=>{n(`observeComments(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeCommunity=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeCommunity(tmpid: ${r}) > listen`);const o=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},i=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.communityId)===e&&o(t,n)},s=[];return s.push(fg((e=>i({data:e},"onUpdate"))),hg((e=>i({data:e},"onDelete"))),mg((e=>i({data:e},"onJoin"))),gg((e=>i({data:e},"onLeft"))),yg((e=>i({data:e},"onUserAdded"))),bg((e=>i({data:e},"onUserRemoved"))),vg((e=>i({data:e},"onUserBanned"))),_g((e=>i({data:e},"onUserUnbanned")))),_e(ge(Cm,e),(e=>o(e,"onFetch"))),()=>{n(`observeCommunity(tmpid: ${r}) > dispose`),s.forEach((e=>e()))}},e.observeFile=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeFile(tmpid: ${r}) > listen`);return _e(ge(am,e),(n=>n.data&&((n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.fileId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}})(n,"onFetch"))),()=>{n(`observeFile(tmpid: ${r}) > dispose`)}},e.observeMessage=(e,t,n="cache_then_server")=>{const{log:r}=m(),o=Date.now();r(`observeMessage(tmpid: ${o}) > listen`);const i=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.messageId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},s=[];return s.push(ag((e=>i(e,"onUpdate"))),cg((e=>i(e,"onDelete")))),"no_fetch"!==n&&_e(ge(pm,e),(e=>e.data&&i(e,"onFetch")),ye(n)),()=>{r(`observeMessages(tmpid: ${o}) > dispose`),s.forEach((e=>e()))}},e.observeMessages=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeMessages(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(n.channelId===e){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(sg((e=>i(e,"onCreate"))),ag((e=>i(e,"onUpdate"))),cg((e=>i(e,"onDelete")))),()=>{n(`observeMessages(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observePost=(e,t,n="cache_then_server")=>{const{log:r}=m(),o=Date.now();r(`observePost(tmpid: ${o}) > listen`);const i=(e,n)=>{var r,o;if(t instanceof Function)return t(e);"onFetch"!==n&&(null===(r=t.onEvent)||void 0===r||r.call(t,n,e)),null===(o=t[n])||void 0===o||o.call(t,e)},s=(t,n)=>{var r;(null===(r=t.data)||void 0===r?void 0:r.postId)===e&&i(t,n)},a=[];return a.push(Mm((e=>s({data:e},"onUpdate"))),Bm((e=>s({data:e},"onDelete"))),jm((e=>s({data:e},"onApproved"))),Nm((e=>s({data:e},"onDeclined"))),Fm((e=>s({data:e},"onFlagged"))),Um((e=>s({data:e},"onUnflagged"))),Lm((e=>s({data:e},"onReactionAdded"))),Dm((e=>s({data:e},"onReactionRemoved")))),_e(ge(vm,e),(e=>i(e,"onFetch")),ye(n)),()=>{r(`observePosts(tmpid: ${o}) > dispose`),a.forEach((e=>e()))}},e.observePosts=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observePosts(tmpid: ${r}) > listen`);const o=[],i=(n,r)=>{var o,i;if(e.targetId===n.targetId&&e.targetType===n.targetType){if(t instanceof Function)return t(n);null===(o=t.onEvent)||void 0===o||o.call(t,r,n),null===(i=t[r])||void 0===i||i.call(t,n)}};return o.push(Pm((e=>i(e,"onCreate"))),Mm((e=>i(e,"onUpdate"))),Bm((e=>i(e,"onDelete"))),jm((e=>i(e,"onApproved"))),Nm((e=>i(e,"onDeclined"))),Fm((e=>i(e,"onFlagged"))),Um((e=>i(e,"onUnflagged"))),Lm((e=>i(e,"onReactionAdded"))),Dm((e=>i(e,"onReactionRemoved")))),()=>{n(`observePosts(tmpid: ${r}) > dispose`),o.forEach((e=>e()))}},e.observeUser=(e,t)=>{const{log:n}=m(),r=Date.now();n(`observeUser(tmpid: ${r}) > listen`);const o=(n,r)=>{var o,i,s;if((null===(o=n.data)||void 0===o?void 0:o.userId)===e){if(t instanceof Function)return t(n);"onFetch"!==r&&(null===(i=t.onEvent)||void 0===i||i.call(t,r,n)),null===(s=t[r])||void 0===s||s.call(t,n)}},i=[];return i.push(rm((e=>o({data:e},"onUpdate"))),om((e=>o({data:e},"onFlagged"))),im((e=>o({data:e},"onUnflagged"))),sm((e=>o({data:e},"onFlagCleared")))),_e(ge(Gh,e),(e=>e.data&&o(e,"onFetch"))),()=>{n(`observeUser(tmpid: ${r}) > dispose`),i.forEach((e=>e()))}},e.onChannelDeleted=tg,e.onChannelJoined=ng,e.onChannelLeft=rg,e.onChannelUpdated=eg,e.onClientBanned=Eh,e.onClientDisconnected=e=>kh((({code:t})=>{800211===t&&e()})),e.onCommentCreated=$m,e.onCommentDeleted=Wm,e.onCommentFlagged=Vm,e.onCommentReactionAdded=zm,e.onCommentReactionRemoved=Jm,e.onCommentUnflagged=Km,e.onCommentUpdated=Hm,e.onCommunityCreated=e=>lg("community.created",e),e.onCommunityDeleted=hg,e.onCommunityJoined=mg,e.onCommunityLeft=gg,e.onCommunityUpdated=fg,e.onCommunityUserAdded=yg,e.onCommunityUserBanned=vg,e.onCommunityUserRemoved=bg,e.onCommunityUserUnbanned=_g,e.onConnectionError=kh,e.onMemberAdded=og,e.onMemberRemoved=ig,e.onMessageCreated=sg,e.onMessageDeleted=cg,e.onMessageUpdated=ag,e.onPostApproved=jm,e.onPostCreated=Pm,e.onPostDeclined=Nm,e.onPostDeleted=Bm,e.onPostFlagged=Fm,e.onPostReactionAdded=Lm,e.onPostReactionRemoved=Dm,e.onPostUnflagged=Um,e.onPostUpdated=Mm,e.onReactionRemoved=(e,t,n)=>{const r=r=>{v(e)(r)===t&&n(r)};if("message"===e){const e=m(),t=e=>{var t,n;const o=(null===(n=(null!==(t=y("message",e.messages[0].messageId))&&void 0!==t?t:[])[0])||void 0===n?void 0:n.reactionsCount)!==e.messages[0].reactionsCount;$h(e),B(e),o&&r(e.messages[0])};return vh(e,"reaction/onReactionRemoved","v3.message.didUpdate",t)}return"post"===e?Dm(r):Jm(r)},e.onUserFlagCleared=sm,e.onUserFlagged=om,e.onUserUnflagged=im,e.onUserUpdated=rm,e.persistentStore=async(e,t={},n=250)=>{let r=t;const o=await qh.getItem(e);if(o)try{r=JSON.parse(o)}catch(e){}const i=Rh(r);let s=null;const a=()=>{s?s.then((()=>a())):(clearTimeout(undefined),setTimeout((async()=>{s=Promise.resolve().then((()=>qh.setItem(e,JSON.stringify(i.read())))).then((()=>s=null))}),n))};return{read:i.read,write:e=>{i.write(e),a()},erase:(...e)=>{i.erase(...e),a()}}},e.pullFromCache=y,e.pushToCache=w,e.queryChannelMembers=Zm,e.queryChannels=Qm,e.queryComments=km,e.queryCommunities=_m,e.queryCommunityMembers=Sm,e.queryGlobalFeed=async e=>{const t=m();t.log("feed/queryGlobalFeed",e);const n=null!=e?e:{},{page:r}=n,o=em(n,["page"]),{data:i}=await t.http.get("/api/v4/me/global-feeds",{params:Object.assign(Object.assign({},o),{options:{token:ae(r,"skiplimit")}})}),{paging:s}=i,a=em(i,["paging"]);$h(a),B(a);const{posts:c}=a,l=ce(s.next),u=ce(s.previous);return{data:A(c),nextPage:l,prevPage:u}},e.queryMessages=fm,e.queryOptions=ye,e.queryPosts=ym,e.queryRoles=cm,e.queryStreams=Cg,e.queryUsers=tm,e.removeChannelMembers=async(e,t)=>{const n=m();n.log("channel/removeChannelMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/channels/${e}/users`,{data:{channelId:e,userIds:t}});$h(r),B(r),_h("v3.channel.didRemoveUsers",{channels:r.channels});const{channelUsers:o}=r;return!!o.find((t=>t.channelId===e&&"member"!==t.membership))},e.removeChannelMembersRole=async(e,t,n)=>{const r=m();r.log("channel/removeChannelMembersRole",e,t,n);const{data:o}=await r.http.delete(`/api/v3/channels/${e}/users/roles`,{data:{channelId:e,role:t,userIds:n}});$h(o),B(o);const{channelUsers:i}=o;return!!i.find((n=>n.channelId===e&&!n.roles.includes(t)))},e.removeCommunityMembers=async(e,t)=>{const n=m();n.log("community/removeCommunityMembers",e,t);const{data:r}=await n.http.delete(`/api/v3/communities/${e}/users`,{data:{communityId:e,userIds:t}});$h(r),B(r),_h("community.userRemoved",{communities:r.communities});const{communityUsers:o}=r;return!!o.find((t=>t.communityId===e&&"member"!==t.communityMembership))},e.removeCommunityMembersRole=async(e,t,n)=>{const r=m();r.log("community/removeCommunityMembersRole",e,t,n);const{data:o}=await r.http.delete(`/api/v3/communities/${e}/users/roles`,{data:{communityId:e,role:t,userIds:n}});$h(o),B(o);const{communityUsers:i}=o;return!!i.find((n=>n.communityId===e&&!n.roles.includes(t)))},e.removeReaction=Tm,e.runQuery=_e,e.sliceByPaging=(e,t,n)=>{if(console.log("slice by paging",n),!n)return t.slice();let r,o=0;n.after?(o=n.after,r=o+n.limit):n.before&&(r=n.before+1,o=r>n.limit?r-n.limit:0);const i=t.slice(o,r);return i.length===n.limit?i:void 0},e.sortByChannelSegment=Kh,e.sortByDisplayName=({displayName:e},{displayName:t})=>e===t?0:e<t?-1:1,e.sortByFirstCreated=({createdAt:e},{createdAt:t})=>new Date(e).valueOf()-new Date(t).valueOf(),e.sortByLastActivity=({lastActivity:e},{lastActivity:t})=>new Date(t).valueOf()-new Date(e).valueOf(),e.sortByLastCreated=({createdAt:e},{createdAt:t})=>new Date(t).valueOf()-new Date(e).valueOf(),e.sortBySegmentNumber=zh,e.subscribeTopic=function(e,t){const{mqtt:n,emitter:r,accessToken:o,user:i}=m();return Qh===o&&Xh===i._id||(Qh=o,Xh=i._id,n.connect({accessToken:o,userId:i._id}),((e,t)=>{yh.forEach((n=>{e.on(n,((...e)=>t.emit(n,1===e.length?e[0]:e)))})),e.on("message",((e,n)=>{const r=JSON.parse(n.toString());t.emit(r.eventType,r.data)}))})(n,r)),n.subscribe(e,t)},e.syncInCache=E,e.toPage=ce,e.toToken=ae,e.updateChannel=async(e,t)=>{const n=m();n.log("channel/updateChannel",e,t);const{data:r}=await n.http.put(`/api/v3/channels/${e}`,t);$h(r),B(r);const{channels:o}=r;return o.find((t=>t.channelId===e))},e.updateComment=async(e,t)=>{const n=m();n.log("user/updateComment",t);const{data:r}=await n.http.put(`/api/v3/comments/${e}`,t);$h(r),B(r),_h("comment.updated",r);const{comments:o}=r;return o.find((t=>t.commentId===e))},e.updateCommunity=async(e,t)=>{const n=m();n.log("community/updateCommunity",e,t);const{data:r}=await n.http.put(`/api/v3/communities/${e}`,t);$h(r),B(r),_h("community.updated",r);const{communities:o}=r;return o.find((t=>t.communityId===e))},e.updateMessage=mm,e.updatePost=async(e,t)=>{const n=m();n.log("user/updatePost",t);const{data:r}=await n.http.put(`/api/v3/posts/${e}`,t);$h(r),B(r),_h("post.updated",r);const{posts:o}=r;return o.find((t=>t.postId===e))},e.updateStream=async(e,t)=>{const n=m();n.log("stream/updateStream",e,t);const{data:r}=await n.http.put(`/api/v3/video-streaming/${e}`,t);$h(r),B(r);const{videoStreamings:o}=r;return o.find((t=>t.streamId===e))},e.updateUser=async(e,t)=>{const n=m();n.log("user/updateUser",e,t);const{data:r}=await n.http.put("/api/v3/users/",Object.assign(Object.assign({userId:e},t),{createNewUserWhenNotFound:!1}));return $h(r),B(r),r.users.find((t=>t.userId===e))},Object.defineProperty(e,"__esModule",{value:!0}),e}({},require$$0$1,require$$2,require$$2$1);
|
package/package.json
CHANGED
|
@@ -24,14 +24,17 @@ export const createChannel = async <T extends Amity.ChannelType>(
|
|
|
24
24
|
const client = getActiveClient()
|
|
25
25
|
client.log('user/createChannel', bundle)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
'/api/v3/channels', bundle,
|
|
29
|
-
)
|
|
27
|
+
let payload;
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (bundle?.type === 'conversation') {
|
|
30
|
+
payload = await client.http.post<Amity.ChannelPayload>('/api/v3/channels/conversation', {...bundle, isDistinct: true })
|
|
31
|
+
} else {
|
|
32
|
+
payload = await client.http.post<Amity.ChannelPayload>('/api/v3/channels', bundle)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
decoratePayload(payload.data)
|
|
36
|
+
ingestInCache(payload.data)
|
|
33
37
|
// no need for event, fired by server
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
return channels[0]
|
|
39
|
+
return payload.data.channels[0]
|
|
37
40
|
}
|