-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgroupChannel.js
More file actions
1 lines (1 loc) · 35 KB
/
Copy pathgroupChannel.js
File metadata and controls
1 lines (1 loc) · 35 KB
1
import{_ as s,V as h,b as d,K as f,M as _,z as v,B as g,t as y,q as E,r as L,ab as A,T,E as F,aU as x,w as N,N as R,bl as V,D as z,J as K,c as W,d as B,u as J,g as Y,A as X,aW as Z,f as $,h as ee,j as te,a as ne,a2 as ae,a5 as re,ap as ie,aX as se,bm as oe,au as le,F as ce,aq as ue}from"./lib/__bundle-afb78439.js";export{bn as MessageEventSource,bo as MutedState}from"./lib/__bundle-afb78439.js";import{T as he,G as de,H as pe,s as fe,a as _e,P as ve,b as ge,S as me,c as Ce,I as ye,d as be,v as Me,e as Ee,f as Se,g as Le,h as Ae}from"./lib/__bundle-afacc700.js";export{C as CountPreference,D as DeliveryStatus,b as GroupChannel,i as GroupChannelEventSource,a as GroupChannelFilter,c as GroupChannelListQuery,j as GroupChannelSearchField,H as HiddenChannelFilter,k as HiddenState,I as InactiveChannelListQuery,M as Member,l as MemberListOrder,m as MemberListQuery,n as MemberState,o as MemberStateFilter,q as MessageCollection,r as MessageCollectionInitHandler,t as MessageCollectionInitPolicy,u as MutedMemberFilter,p as MyMemberStateFilter,O as OperatorFilter,P as PublicChannelFilter,Q as QueryType,S as SuperChannelFilter,U as UnreadChannelFilter,w as UnreadItemKey}from"./lib/__bundle-afacc700.js";import{ah as we,Q as Te,ai as Fe}from"./lib/__bundle-477b193e.js";export{ag as MessageFilter,aj as PinnedMessage,ak as PinnedMessageListQuery,al as ReadStatus,ai as ScheduledStatus}from"./lib/__bundle-477b193e.js";import{c as ke,F as xe,G as Ie,P as Ne,e as Ue}from"./lib/__bundle-0d03635f.js";export{G as GroupChannelListOrder,I as InactiveChannelListOrder,P as PublicGroupChannelListOrder,e as ScheduledMessageListOrder}from"./lib/__bundle-0d03635f.js";import{B as Ge}from"./lib/__bundle-91551c85.js";import"./lib/__bundle-8e7eec68.js";import"./lib/__bundle-c25f81e4.js";import"./lib/__bundle-acd77193.js";var Oe,De={},Pe=function(){function e(e){var t=e._iid,n=e.limit,a=void 0===n?100:n,r=this;this.ref=0,this._iid=t,this._limit=a;var i,o=h.of(this._iid),l=o.sdkState,c=o.dispatcher,u=o.logger,p=o.cacheContext,m=o.statManager;this._metadataKey=(i=l.userId,"sendbird:".concat(i,"@groupchannel/sync.meta"));var C=function(e){return"sendbird:".concat(e,"@groupchannel/sync")}(l.userId);this._sync=new ke(C,(function(){return s(r,void 0,void 0,(function(){var e,t,n,a,r,i,s,o,c,h,f,_,C,b,M,S;return d(this,(function(d){switch(d.label){case 0:return e={hasNext:!0,nextToken:""},[4,this.loadMetadata()];case 1:if(d.sent(),u.debug("channel background sync from",null===(c=this._metadata)||void 0===c?void 0:c.token),null===(h=this._metadata)||void 0===h?void 0:h.completed)return[3,14];t={includeEmpty:!0,includeMetaData:!0,hiddenChannelFilter:pe.ALL,order:Ie.CHRONOLOGICAL},d.label=2;case 2:if(d.trys.push([2,9,12,13]),t.order!==Ie.LATEST_LAST_MESSAGE)return[3,6];d.label=3;case 3:return d.trys.push([3,5,,6]),[4,p.preference.get(T(l.appId))];case 4:return n=d.sent(),t.includeChatNotification=Boolean(n),[3,6];case 5:return d.sent(),t.includeChatNotification=!1,[3,6];case 6:return[4,de.of(this._iid).getMyGroupChannels(null!==(_=null===(f=this._metadata)||void 0===f?void 0:f.token)&&void 0!==_?_:"",t,this._limit,A.SYNC_CHANNEL_BACKGROUND)];case 7:return a=d.sent(),r=a.channels,i=a.token,e.hasNext=r.length>=this._limit&&!!i,e.nextToken=i,this._metadata&&(this._metadata.token=i,(o=this._metadata.range).extends.apply(o,E([],L(r.map((function(e){return e.createdAt}))),!1)),this._metadata.completed=!e.hasNext),u.debug("channel background sync progress",e),[4,this.saveMetadata()];case 8:return d.sent(),[3,13];case 9:return s=d.sent(),u.debug("channel background sync error",s),s instanceof y&&s.isInvalidTokenError?[4,this.clearMetaData()]:[3,11];case 10:d.sent(),d.label=11;case 11:throw s;case 12:return m.put(new v({type:g.FEATURE_LOCALCACHE_EVENT,ts:Date.now(),data:{channel_url:"",measured_on:"channel_back_sync",event:"cache_fetch",max_db_size:null!==(b=null===(C=p.localCacheConfig)||void 0===C?void 0:C.maxSize)&&void 0!==b?b:0,use_local_cache:p.localCacheEnabled,starting_point:0,message_init_policy:null!==(S=null===(M=t.order)||void 0===M?void 0:M.toString())&&void 0!==S?S:"",collection_id:l.userId}})),[7];case 13:return[3,15];case 14:e.hasNext=!1,e.nextToken="",d.label=15;case 15:return[2,e]}}))}))})),this._connectionEventContext=c.on((function(e){if(e instanceof f)if(e.stateType===_.CONNECTED)r.resume();else r.pause();else e instanceof xe&&r.resume()}))}return e.of=function(t){return De[t]||(De[t]=new e({_iid:t})),De[t].ref++,De[t]},e.clear=function(e){De[e]&&(De[e].close(),delete De[e])},Object.defineProperty(e.prototype,"range",{get:function(){var e,t;return null!==(t=null===(e=this._metadata)||void 0===e?void 0:e.range)&&void 0!==t?t:new he({})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"completed",{get:function(){var e;return!!(null===(e=this._metadata)||void 0===e?void 0:e.completed)},enumerable:!1,configurable:!0}),e.prototype.loadMetadata=function(){return s(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return this._metadata?[3,2]:[4,h.of(this._iid).cacheContext.preference.get(this._metadataKey)];case 1:e=t.sent(),this._metadata={token:e?e.token:"",range:new he(e?e.range:{top:Number.MAX_SAFE_INTEGER,bottom:0}),completed:!!e&&e.completed},t.label=2;case 2:return[2,this._metadata]}}))}))},e.prototype.saveMetadata=function(){return s(this,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return this._metadata?[4,h.of(this._iid).cacheContext.preference.set(this._metadataKey,this._metadata)]:[3,2];case 1:return e.sent(),[2,!0];case 2:return[2,!1]}}))}))},e.prototype.clearMetaData=function(){return s(this,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return[4,h.of(this._iid).cacheContext.preference.remove(this._metadataKey)];case 1:return e.sent(),this._metadata=void 0,[2]}}))}))},e.prototype.resume=function(){var e,t,n=h.of(this._iid),a=n.logger;n.sessionManager.session.hasSession&&(a.debug("channel background sync resume()"),this._sync.start(null!==(t=null===(e=this._metadata)||void 0===e?void 0:e.token)&&void 0!==t?t:""))},e.prototype.pause=function(){h.of(this._iid).logger.debug("channel background sync stop()"),this._sync.stop()},e.prototype.close=function(){this.ref--,this.ref<=0&&(this.ref=0,this.pause(),this._connectionEventContext.close(),delete De[this._iid])},e}(),Re={},He=function(){function e(e){var t=e._iid,n=e.prefix,a=e.fetcher,r=this;this.ref=0,this._iid=t,this._fetcher=a,this._prefix=n;var i=h.of(this._iid),o=i.logger,l=i.sdkState,c=i.dispatcher,u=i.cacheContext,p=i.statManager;this._metadataKey=function(e,t){return t?"sendbird:".concat(e,":").concat(t,"@groupchannel/changelogs.meta"):"sendbird:".concat(e,"@groupchannel/changelogs.meta")}(l.userId,this._prefix),this._subscribers=new F;var m=function(e,t){return t?"sendbird:".concat(e,":").concat(t,"@groupchannel/changelogs"):"sendbird:".concat(e,"@groupchannel/changelogs")}(l.userId,this._prefix);this._sync=new ke(m,(function(){return s(r,void 0,void 0,(function(){var e,t,n,a,r,i,s,c,h,f,_;return d(this,(function(d){switch(d.label){case 0:return e={hasNext:!0,nextToken:0},[4,this.loadMetadata()];case 1:d.sent(),o.debug("channel changelog sync from",null===(h=this._metadata)||void 0===h?void 0:h.token),t=de.of(this._iid),d.label=2;case 2:return d.trys.push([2,5,8,12]),[4,this._fetcher(null!==(_=null===(f=this._metadata)||void 0===f?void 0:f.token)&&void 0!==_?_:"")];case 3:return n=d.sent(),a=n.updatedChannels,r=n.deletedChannelUrls,i=n.hasMore,s=n.token,this._subscribers.dispatch("progress",{updatedChannels:a,deletedChannelUrls:r,hasMore:i,token:s}),e.hasNext=i,e.nextToken=s,this._metadata&&(this._metadata.token=s),o.debug("channel changelog sync progress",e),[4,this.saveMetadata()];case 4:return d.sent(),u.localCacheEnabled&&p.put(new v({type:g.FEATURE_LOCALCACHE_EVENT,ts:Date.now(),data:{channel_url:"",measured_on:"channel_change_log_sync",event:a.length>0||r.length>0?"cache_miss":"cache_hit",max_db_size:a.length,use_local_cache:u.localCacheEnabled,starting_point:0,message_init_policy:r.length.toString(),collection_id:l.userId}})),[3,12];case 5:return c=d.sent(),o.debug("channel changelog sync error",c),c instanceof y&&c.isInvalidTokenError?[4,this.clearMetadata()]:[3,7];case 6:d.sent(),d.label=7;case 7:throw c;case 8:return e.hasNext?[3,11]:[4,x(500)];case 9:return d.sent(),[4,t.removeChannelsByRotation()];case 10:d.sent(),d.label=11;case 11:return[7];case 12:return[2,e]}}))}))})),this._sync.on("stop",(function(){r._subscribers.dispatch("pause")})),this._connectionEventContext=c.on((function(e){if(e instanceof f)if(e.stateType===_.CONNECTED)r.resume();else r.pause();else e instanceof xe&&r.resume()}))}return e.of=function(t){var n=t._iid,a=t.prefix,r=t.fetcher,i=a?"".concat(n,":").concat(a):n;return Re[i]||(Re[i]=new e({_iid:n,prefix:a,fetcher:r})),Re[i].ref++,Re[i]},e.clear=function(e){var t=e._iid,n=e.prefix,a=n?"".concat(t,":").concat(n):t;Re[a]&&(Re[a].close(),delete Re[a])},Object.defineProperty(e.prototype,"isRunning",{get:function(){return this._sync.isRunning},enumerable:!1,configurable:!0}),e.prototype.loadMetadata=function(){return s(this,void 0,void 0,(function(){var e,t,n,a;return d(this,(function(r){switch(r.label){case 0:return this._metadata?[3,2]:(e=h.of(this._iid),t=e.cacheContext,n=e.firstConnectedAt,[4,t.preference.get(this._metadataKey)]);case 1:a=r.sent(),this._metadata={token:a?a.token:n},r.label=2;case 2:return[2,this._metadata]}}))}))},e.prototype.saveMetadata=function(){return s(this,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return this._metadata?[4,h.of(this._iid).cacheContext.preference.set(this._metadataKey,this._metadata)]:[3,2];case 1:return e.sent(),[2,!0];case 2:return[2,!1]}}))}))},e.prototype.clearMetadata=function(){return s(this,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return[4,h.of(this._iid).cacheContext.preference.remove(this._metadataKey)];case 1:return e.sent(),this._metadata=void 0,[2]}}))}))},e.prototype.on=function(e,t){return this._subscribers.on(e,t)},e.prototype.resume=function(){h.of(this._iid).sessionManager.session.hasSession&&this._sync.start(0)},e.prototype.pause=function(){this._sync.stop()},e.prototype.close=function(){if(this.ref--,this.ref<=0){var e=this._prefix?"".concat(this._iid,":").concat(this._prefix):this._iid;this.ref=0,this.pause(),this._connectionEventContext.close(),delete Re[e]}},e}(),Ve=function(e,t){var n,a,r,i;switch(t){case Ie.LATEST_LAST_MESSAGE:return null!==(a=null===(n=e.lastMessage)||void 0===n?void 0:n.createdAt)&&void 0!==a?a:e.createdAt;case Ie.CHRONOLOGICAL:return e.createdAt;case Ie.CHANNEL_NAME_ALPHABETICAL:return e.name;default:return null!==(i=null===(r=e.lastMessage)||void 0===r?void 0:r.createdAt)&&void 0!==i?i:e.createdAt}},je=function(e,t){return e.findIndex((function(e){return e.isIdentical(t)}))},ze=function(e,t,n){if(e.length>0){for(var a=je(e,t),r=0,i=e.length-1,s=Math.floor((r+i)/2);r<i;){var o=Qe(e[s],t,n);if(o>0)i=s,s=Math.floor((r+i)/2);else{if(!(o<0))return{place:s,oldPosition:a};r=s+1,s=Math.floor((r+i)/2)}}return{place:Qe(e[s],t,n)>=0?s:s+1,oldPosition:a}}return{place:e.length,oldPosition:-1}},Qe=function(e,t,n){switch(n){case Ie.LATEST_LAST_MESSAGE:return e.lastMessage&&t.lastMessage?0===(a=t.lastMessage.createdAt-e.lastMessage.createdAt)?t.createdAt-e.createdAt:a:e.lastMessage?-1:t.lastMessage?1:t.createdAt-e.createdAt;case Ie.CHRONOLOGICAL:return t.createdAt-e.createdAt;case Ie.CHANNEL_NAME_ALPHABETICAL:var a;return 0===(a=e.name.localeCompare(t.name))?e.createdAt-t.createdAt:a;default:return 0}},Ke=function(){function e(e,t){var n,a=this;this._channels=[],this._isInitialized=!1,this._isLoadMoreChannelFetchActive=!1,this._iid=e,this._fetcher=t.fetcher,this._isDisposed=!1,this._isGetRemoteChannelsSucceeded=!0,this._includeChangesOnInitialLoad=null!==(n=t.includeChangesOnInitialLoad)&&void 0!==n&&n,this.filter=t.filter,this._channelFilter=t.filter,this.order=t.order,this._hasMore=!0,this._token="",this._limit=t.limit,this._localCacheToken=null;var r=h.of(this._iid),i=r.cacheContext,o=r.dispatcher;i.localCacheEnabled&&(this._backgroundSync=Pe.of(e),this._backgroundSync.resume()),this._changelogSync=He.of({_iid:this._iid,prefix:t.syncKeyPrefix,fetcher:this._fetcher.changeLogSync}),this._changelogSync.resume(),o.on((function(e){e instanceof f&&(e.stateType===_.CONNECTED?a._isGetRemoteChannelsSucceeded||s(a,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return[4,this._revokeLoadMore()];case 1:return e.sent(),[2]}}))})):e.stateType===_.LOGOUT&&a.dispose())}))}return Object.defineProperty(e.prototype,"hasMore",{get:function(){return!this._isDisposed&&this._hasMore},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"handler",{get:function(){return this._handler},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channels",{get:function(){return this._channels},enumerable:!1,configurable:!0}),e.prototype._subscribeChannelEvent=function(e,t){de.of(this._iid).subscribeChannelEvent(e,t)},e.prototype._unsubscribeChannelEvent=function(e){de.of(this._iid).unsubscribeChannelEvent(e)},Object.defineProperty(e.prototype,"_isLoadMoreChannelFetchInProgress",{get:function(){return this._isLoadMoreChannelFetchActive},enumerable:!1,configurable:!0}),e.prototype._prepareLoadMoreChannels=function(e){return e},e.prototype.setGroupChannelCollectionHandler=function(e){this._handler=e},e.prototype._addChannelsToView=function(e,t,n){var a,r,i,o,l=this;void 0===n&&(n=!1);var c=[],u=[],h=[];try{for(var p=N(e),f=p.next();!f.done;f=p.next()){var _=f.value,v=je(this._channels,_);v>=0&&this._channels.splice(v,1);var g=ze(this._channels,_,this.order).place;if(v<0)g===this._channels.length?!n&&this.hasMore||(c.push(_),this._channels.push(_)):(c.push(_),this._channels.splice(g,0,_));else switch(t.source){case A.EVENT_CHANNEL_UPDATED:case A.EVENT_MESSAGE_RECEIVED:case A.SYNC_CHANNEL_CHANGELOGS:case A.EVENT_MESSAGE_SENT:this.order===Ie.CHANNEL_NAME_ALPHABETICAL&&this.hasMore&&g===this._channels.length?h.push(_):(this._channels.splice(g,0,_),u.push(_));break;default:this._channels.splice(g,0,_),u.push(_)}}}catch(e){a={error:e}}finally{try{f&&!f.done&&(r=p.return)&&r.call(p)}finally{if(a)throw a.error}}if(h.length>0)try{for(var m=N(h),C=m.next();!C.done;C=m.next()){_=C.value;var y=je(this._channels,_);-1!==y&&this._channels.splice(y,1)}}catch(e){i={error:e}}finally{try{C&&!C.done&&(o=m.return)&&o.call(m)}finally{if(i)throw i.error}}fe(t.source)&&R((function(){return s(l,void 0,void 0,(function(){var e,n,a;return d(this,(function(r){return c.length>0&&(null===(e=this.handler)||void 0===e?void 0:e.onChannelsAdded)&&this.handler.onChannelsAdded(t,c),u.length>0&&(null===(n=this.handler)||void 0===n?void 0:n.onChannelsUpdated)&&this.handler.onChannelsUpdated(t,u),h.length>0&&(null===(a=this.handler)||void 0===a?void 0:a.onChannelsDeleted)&&this.handler.onChannelsDeleted(t,h.map((function(e){return e.url}))),[2]}))}))}))},e.prototype._removeChannelsFromView=function(e,t){var n,a,r=this,i=[],o=function(e){var t=l._channels.findIndex((function(t){return t.url===e}));t>=0&&(i.push(l._channels[t].url),l._channels.splice(t,1))},l=this;try{for(var c=N(e),u=c.next();!u.done;u=c.next()){o(u.value)}}catch(e){n={error:e}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(n)throw n.error}}return fe(t.source)&&i.length>0&&R((function(){return s(r,void 0,void 0,(function(){var e;return d(this,(function(n){return(null===(e=this.handler)||void 0===e?void 0:e.onChannelsDeleted)&&this.handler.onChannelsDeleted(t,i),[2]}))}))})),i},e.prototype._getLocalChannels=function(){return s(this,void 0,void 0,(function(){var e,t,n;return d(this,(function(a){switch(a.label){case 0:return e=de.of(this._iid),t=this.channels.length>0?new Set(this.channels.map((function(e){return e.url}))):void 0,[4,e.getChannelsFromCache(this._localCacheToken,this._channelFilter,this.order,this._limit,t)];case 1:return(n=a.sent()).length>0&&(this._localCacheToken=Ve(n[n.length-1],this.order)),[2,n]}}))}))},e.prototype._getRemoteChannels=function(){return s(this,void 0,void 0,(function(){var e,t,n;return d(this,(function(a){switch(a.label){case 0:return[4,this._fetcher.getRemoteChannels(this._token,this.filter,this.order,this._limit)];case 1:return e=a.sent(),t=e.channels,n=e.token,this._token=n,this._hasMore=!!n,t.length>0&&(this._localCacheToken=Ve(t[t.length-1],this.order)),[2,t]}}))}))},e.prototype._beginLoadMoreChannelFetch=function(){this._isLoadMoreChannelFetchActive=!0},e.prototype._endLoadMoreChannelFetch=function(){this._isLoadMoreChannelFetchActive=!1},e.prototype._revokeLoadMore=function(){return s(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:if(this._isDisposed)return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this._getRemoteChannels()];case 2:return e=t.sent(),this._isGetRemoteChannelsSucceeded=!0,this._addChannelsToView(e,{source:A.REQUEST_CHANNEL},!0),[3,4];case 3:return t.sent(),this._isGetRemoteChannelsSucceeded=!1,[3,4];case 4:return[2]}}))}))},e.prototype.loadMore=function(){var e,t,n;return s(this,void 0,void 0,(function(){var a,r,i,o,l,c,u,p,f,_,v,m,C,b,M,E,S,L,w,T,F,k=this;return d(this,(function(x){switch(x.label){case 0:if(this._isDisposed)throw new y({code:z.COLLECTION_DISPOSED,message:"Collection has been disposed."});return a=null,this._includeChangesOnInitialLoad&&0===this._channels.length&&this._changelogSync.isRunning?[4,new Promise((function(e){k._changelogSyncSubscriberContext=k._changelogSync.on("progress",(function(t){return e(t)})).on("pause",(function(){return e(null)}))}))]:[3,2];case 1:a=x.sent(),null===(e=this._changelogSyncSubscriberContext)||void 0===e||e.close(),x.label=2;case 2:return r=h.of(this._iid),i=r.cacheContext,o=r.connectionManager,l=r.statManager,this._isInitialized?[3,5]:(this._isInitialized=!0,i.localCacheEnabled?[4,null===(t=this._backgroundSync)||void 0===t?void 0:t.loadMetadata()]:[3,4]);case 3:x.sent(),x.label=4;case 4:l.put(new V({type:g.FEATURE_LOCALCACHE,data:{use_local_cache:i.localCacheEnabled,collection_interface:{group_channel:!0}}})),x.label=5;case 5:if(c=[],!this._hasMore)return[3,14];this._beginLoadMoreChannelFetch(),x.label=6;case 6:return x.trys.push([6,,12,13]),!i.localCacheEnabled||o.isConnected&&!(null===(n=this._backgroundSync)||void 0===n?void 0:n.completed)?[3,8]:[4,K((function(){return s(k,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return[4,this._getLocalChannels()];case 1:return c=e.sent(),[2]}}))}))}))];case 7:return x.sent(),this._hasMore=c.length>=this._limit,[3,11];case 8:return x.trys.push([8,10,,11]),[4,this._getRemoteChannels()];case 9:return c=x.sent(),this._isGetRemoteChannelsSucceeded=!0,[3,11];case 10:return x.sent(),this._isGetRemoteChannelsSucceeded=!1,[3,11];case 11:return c=this._prepareLoadMoreChannels(c),[3,13];case 12:return this._endLoadMoreChannelFetch(),[7];case 13:this._addChannelsToView(c,{source:A.REQUEST_CHANNEL},!0),this._hasMore||(this._localCacheToken=null),x.label=14;case 14:if(a){u=h.of(this._iid).sdkState,p=a.updatedChannels.filter((function(e){return k._channelFilter.match(e,u.userId)}));try{for(f=N(p),_=f.next();!_.done;_=f.next())v=_.value,(S=je(c,v))>=0?c[S]=v:(m=ze(c,v,this.order).place,c.splice(m,0,v)),this._addChannelsToView([v],{source:A.REQUEST_CHANNEL},!0)}catch(e){L={error:e}}finally{try{_&&!_.done&&(w=f.return)&&w.call(f)}finally{if(L)throw L.error}}C=c.map((function(e){return e.url}));try{for(b=N(a.deletedChannelUrls),M=b.next();!M.done;M=b.next())E=M.value,(S=C.indexOf(E))>=0&&(c.splice(S,1),C.splice(S,1))}catch(e){T={error:e}}finally{try{M&&!M.done&&(F=b.return)&&F.call(b)}finally{if(T)throw T.error}}this._removeChannelsFromView(a.deletedChannelUrls,{source:A.REQUEST_CHANNEL})}return[2,c]}}))}))},e.prototype.dispose=function(){var e,t,n;this._isDisposed||(this._isDisposed=!0,this._channels.length>0&&this._channels.splice(0,this._channels.length),this._localCacheToken=null,null===(e=this._backgroundSync)||void 0===e||e.close(),null===(t=this._changelogSync)||void 0===t||t.close(),null===(n=this._changelogSyncSubscriberContext)||void 0===n||n.close())},e}(),We=function(e){return{getRemoteChannels:function(t,n,a,r){return de.of(e).getMyGroupChannels(t,Y(B(B({},n),{userIdsFilter:n.userIdsFilter,searchFilter:n.searchFilter,order:a})),r)},changeLogSync:function(t){return s(void 0,void 0,void 0,(function(){var n,a,r,i,s;return d(this,(function(o){switch(o.label){case 0:n={includeEmpty:!0,includeMetaData:!0},a=h.of(e),r=a.cacheContext,i=a.sdkState,o.label=1;case 1:return o.trys.push([1,3,,4]),[4,r.preference.get(T(i.appId))];case 2:return s=o.sent(),n.includeChatNotification=Boolean(s),[3,4];case 3:return o.sent(),n.includeChatNotification=!1,[3,4];case 4:return[2,de.of(e).getMyGroupChannelChangeLogs(t,n,A.SYNC_CHANNEL_CHANGELOGS)]}}))}))}}},Be=function(e){function t(t,n){void 0===n&&(n={});var a,r,i,s=this;(s=e.call(this,t,B(B({},n),{filter:null!==(a=n.filter)&&void 0!==a?a:new _e,order:null!==(r=n.order)&&void 0!==r?r:Ie.LATEST_LAST_MESSAGE,limit:null!==(i=n.limit)&&void 0!==i?i:we,fetcher:We(t)}))||this)._hasCompletedInitialLoadMore=!1,s._pendingInitialMessageEventChannels=new Map,s._key="gcc-".concat(J());var o=h.of(s._iid).sdkState;return s._subscribeChannelEvent(s._key,{onUpdate:function(e,t){var n,a,r=t.source;if(s._shouldBufferInitialMessageEvent(r)){var i=de.of(s._iid);try{for(var l=N(e),c=l.next();!c.done;c=l.next()){var u=c.value;s.filter.match(u,o.userId)?s._pendingInitialMessageEventChannels.set(u.url,{channel:i.buildGroupChannelFromSerializedData(u.serialize()),context:t}):s._pendingInitialMessageEventChannels.delete(u.url)}}catch(e){n={error:e}}finally{try{c&&!c.done&&(a=l.return)&&a.call(l)}finally{if(n)throw n.error}}}else if(fe(r)){var h=e.filter((function(e){return s.filter.match(e,o.userId)})),d=e.filter((function(e){return!s.filter.match(e,o.userId)})).map((function(e){return e.url}));h.length>0&&s._addChannelsToView(h,t,!1),d.length>0&&s._removeChannelsFromView(d,t)}},onRemove:function(e,t){var n,a;try{for(var r=N(e),i=r.next();!i.done;i=r.next()){var o=i.value;s._pendingInitialMessageEventChannels.delete(o)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(a=r.return)&&a.call(r)}finally{if(n)throw n.error}}s._removeChannelsFromView(e,t)}}),s}return W(t,e),t.prototype._shouldBufferInitialMessageEvent=function(e){return!this._hasCompletedInitialLoadMore&&this._isLoadMoreChannelFetchInProgress&&(e===A.EVENT_MESSAGE_RECEIVED||e===A.EVENT_MESSAGE_SENT)},t.prototype._prepareLoadMoreChannels=function(e){var t,n;if(this._hasCompletedInitialLoadMore)return e;if(this._hasCompletedInitialLoadMore=!0,0===this._pendingInitialMessageEventChannels.size)return e;var a=!1,r=[];try{for(var i=N(e),s=i.next();!s.done;s=i.next()){var o=s.value,l=this._pendingInitialMessageEventChannels.get(o.url);l?(a=!0,this._pendingInitialMessageEventChannels.delete(o.url),r.push(l.channel)):r.push(o)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return this._pendingInitialMessageEventChannels.clear(),a?r:e},t.prototype.dispose=function(){this._pendingInitialMessageEventChannels.clear(),e.prototype.dispose.call(this),this._unsubscribeChannelEvent(this._key)},t}(Ke),qe=function(e){function t(t){var n=this,a=t.token,r=t.limit,i=t.order,s=t.includeEmpty,o=t.membershipFilter,l=t.channelNameContainsFilter,c=t.channelUrlsFilter,u=t.customTypesFilter,h=t.customTypeStartsWithFilter,d=t.superChannelFilter,p=t.metadataOrderKeyFilter,f=t.metadataKey,_=t.metadataValues,v=t.metadataValueStartsWith,g=t.includeFrozen,m=t.includeMetaData;return(n=e.call(this)||this).method=X.GET,n.path=Z,n.params=$(Y({token:a,limit:r,order:i,show_member:!0,show_read_receipt:!0,show_delivery_receipt:!0,show_empty:s,public_mode:ve.PUBLIC,public_membership_mode:o,name_contains:l,channel_urls:c,custom_types:u,custom_type_startswith:h,super_mode:d,metadata_order_key:p,metadata_key:f,metadata_values:_,metadata_value_startswith:v,show_frozen:g,show_metadata:m})),n}return W(t,e),t}(ee),Je=function(e){function t(t,n){var a=e.call(this,t,n)||this;a.channels=[];var r=n.next,i=n.channels,s=n.ts;return a.token=r,i&&i.length>0&&(a.channels=i.map((function(e){return e.ts=s,new ge(t,e)}))),a.ts="number"==typeof s?s:0,a}return W(t,e),t}(te);!function(e){e.ALL="all",e.JOINED="joined"}(Oe||(Oe={}));var Ye=function(e){function t(t,n){var a,r,i,s,o,l,c,u,h,d,p,f,_,v,g=this;return(g=e.call(this,t,n)||this).includeEmpty=!1,g.includeFrozen=!0,g.includeMetaData=!0,g.channelUrlsFilter=null,g.customTypesFilter=null,g.customTypeStartsWithFilter=null,g.channelNameContainsFilter=null,g.membershipFilter=Oe.ALL,g.superChannelFilter=me.ALL,g.metadataKey=null,g.metadataValues=null,g.metadataOrderKeyFilter=null,g.metadataValueStartsWith=null,g.order=Ne.CHRONOLOGICAL,g.includeEmpty=null!==(a=n.includeEmpty)&&void 0!==a&&a,g.includeFrozen=null===(r=n.includeFrozen)||void 0===r||r,g.includeMetaData=null===(i=n.includeMetaData)||void 0===i||i,g.channelUrlsFilter=null!==(s=n.channelUrlsFilter)&&void 0!==s?s:null,g.customTypesFilter=null!==(o=n.customTypesFilter)&&void 0!==o?o:null,g.customTypeStartsWithFilter=null!==(l=n.customTypeStartsWithFilter)&&void 0!==l?l:null,g.channelNameContainsFilter=null!==(c=n.channelNameContainsFilter)&&void 0!==c?c:null,g.membershipFilter=null!==(u=n.membershipFilter)&&void 0!==u?u:Oe.ALL,g.superChannelFilter=null!==(h=n.superChannelFilter)&&void 0!==h?h:me.ALL,g.metadataKey=null!==(d=n.metadataKey)&&void 0!==d?d:null,g.metadataValues=null!==(p=n.metadataValues)&&void 0!==p?p:null,g.metadataOrderKeyFilter=null!==(f=n.metadataOrderKeyFilter)&&void 0!==f?f:null,g.metadataValueStartsWith=null!==(_=n.metadataValueStartsWith)&&void 0!==_?_:null,g.order=null!==(v=n.order)&&void 0!==v?v:Ne.CHRONOLOGICAL,g}return W(t,e),t.prototype._validate=function(){return e.prototype._validate.call(this)&&ne("boolean",this.includeEmpty)&&ne("boolean",this.includeFrozen)&&ne("boolean",this.includeMetaData)&&ne("string",this.channelNameContainsFilter,!0)&&ae("string",this.channelUrlsFilter,!0)&&ae("string",this.customTypesFilter,!0)&&ne("string",this.customTypeStartsWithFilter,!0)&&re(Oe,this.membershipFilter)&&re(me,this.superChannelFilter)&&re(Ne,this.order)&&ne("string",this.metadataOrderKeyFilter,!0)&&ne("string",this.metadataKey,!0)&&ae("string",this.metadataValues,!0)&&ne("string",this.metadataValueStartsWith,!0)},t.prototype.next=function(){return s(this,void 0,void 0,(function(){var e,t,n,a,r,i,s;return d(this,(function(o){switch(o.label){case 0:return this._validate()?this._isLoading?[3,3]:(e=[],this._hasNext?(this._isLoading=!0,t=h.of(this._iid).requestQueue,n=new qe(Y(B(B({},this),{token:this._token}))),[4,t.send(n)]):[3,2]):[3,5];case 1:return a=o.sent(),r=a.as(Je),i=r.channels,s=r.token,this._token=s,this._hasNext=!!s,this._isLoading=!1,[2,i];case 2:return[2,e];case 3:throw y.queryInProgress;case 4:return[3,6];case 5:throw y.invalidParameters;case 6:return[2]}}))}))},t}(ie),Xe=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return Object.keys(t).forEach((function(e){n.hasOwnProperty(e)&&(n[e]=t[e])})),n}return W(t,e),t}(function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.onUserJoined=se,t.onUserLeft=se,t.onUserReceivedInvitation=se,t.onUserDeclinedInvitation=se,t.onChannelHidden=se,t.onUnreadMemberStatusUpdated=se,t.onUserMarkedRead=se,t.onUserMarkedUnread=se,t.onUndeliveredMemberStatusUpdated=se,t.onTypingStatusUpdated=se,t.onPollUpdated=se,t.onPollVoted=se,t.onPollDeleted=se,t.onPinnedMessageUpdated=se,t}return W(t,e),t}(Ge)),Ze=function(e){function t(t){var n=this,a=t.token,r=t.limit,i=t.order,s=t.reverse,o=t.channelUrl,l=t.messageTypeFilter,c=t.scheduledStatus;return(n=e.call(this)||this).method=X.GET,n.path="".concat(oe),n.params=$(Y({token:a,limit:r,reverse:s,channel_url:o,order:i,message_type:l,status:c})),n}return W(t,e),t}(ee),$e=function(e){function t(t,n){var a=e.call(this,t,n)||this;a.scheduledMessages=[];var r=n.next,i=n.scheduled_messages;return a.token=r,a.scheduledMessages=i.map((function(e){return Te(t,e)})),a}return W(t,e),t}(te),et=function(e){function t(t,n){var a,r,i,s,o,l=this;return(l=e.call(this,t,n)||this).channelUrl=null,l.order=null,l.reverse=!1,l.scheduledStatus=null,l.messageTypeFilter=le.ALL,l.channelUrl=null!==(a=n.channelUrl)&&void 0!==a?a:null,l.order=null!==(r=n.order)&&void 0!==r?r:null,l.reverse=null!==(i=n.reverse)&&void 0!==i&&i,l.scheduledStatus=null!==(s=n.scheduledStatus)&&void 0!==s?s:null,l.messageTypeFilter=null!==(o=n.messageTypeFilter)&&void 0!==o?o:le.ALL,l}return W(t,e),t.prototype._validate=function(){return e.prototype._validate.call(this)&&ne("string",this.channelUrl,!0)&&(re(Ue,this.order)||null===this.order)&&ne("boolean",this.reverse)&&(ae(Fe,this.scheduledStatus)||null===this.scheduledStatus)&&re(le,this.messageTypeFilter)},t.prototype.next=function(){return s(this,void 0,void 0,(function(){var e,t,n,a,r,i;return d(this,(function(s){switch(s.label){case 0:return this._validate()?this._isLoading?[3,3]:this._hasNext?(this._isLoading=!0,e=h.of(this._iid).requestQueue,t=new Ze(Y(B(B({},this),{token:this._token}))),[4,e.send(t)]):[3,2]:[3,5];case 1:return n=s.sent(),a=n.as($e),r=a.scheduledMessages,i=a.token,this._token=i,this._hasNext=!!i,this._isLoading=!1,[2,r];case 2:return[2,[]];case 3:throw y.queryInProgress;case 4:return[3,6];case 5:throw y.invalidParameters;case 6:return[2]}}))}))},t}(ie),tt=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="groupChannel",t}return W(t,e),t.prototype.init=function(t,n){var a=n.sdkState,r=n.dispatcher,i=n.sessionManager,s=n.requestQueue,o=n.logger,l=n.onlineDetector,c=n.cacheContext;e.prototype.init.call(this,t,{sdkState:a,dispatcher:r,sessionManager:i,requestQueue:s,logger:o,onlineDetector:l,cacheContext:c}),this._manager=new de(t,{sdkState:a,cacheContext:c,dispatcher:r,sessionManager:i,requestQueue:s,logger:o})},t.prototype.createGroupChannelCollection=function(e){return void 0===e&&(e={}),new Be(this._iid,e)},t.prototype.createMyGroupChannelListQuery=function(e){return void 0===e&&(e={}),new Ce(this._iid,e)},t.prototype.createInactiveChannelListQuery=function(e){return void 0===e&&(e={}),new ye(this._iid,e)},t.prototype.createPublicGroupChannelListQuery=function(e){return void 0===e&&(e={}),new Ye(this._iid,e)},t.prototype.createScheduledMessageListQuery=function(e){return void 0===e&&(e={}),new et(this._iid,e)},t.prototype.addGroupChannelHandler=function(e,t){ce(ne("string",e)&&t instanceof Xe).throw(y.invalidParameters),this._manager.addHandler(e,t)},t.prototype.removeGroupChannelHandler=function(e){ce(ne("string",e)).throw(y.invalidParameters),this._manager.removeHandler(e)},t.prototype.removeAllGroupChannelHandlers=function(){this._manager.clearHandler()},t.prototype.buildGroupChannelFromSerializedData=function(e){return this._manager.buildGroupChannelFromSerializedData(e)},t.prototype.buildGroupChannelListQueryFromSerializedData=function(e){return this._manager.buildGroupChannelListQueryFromSerializedData(e)},t.prototype.buildInactiveChannelListQueryFromSerializedData=function(e){return this._manager.buildInactiveChannelListQueryFromSerializedData(e)},t.prototype.buildMemberFromSerializedData=function(e){return this._manager.buildMemberFromSerializedData(e)},t.prototype.getChannel=function(e){return s(this,void 0,void 0,(function(){return d(this,(function(t){return ce(ne("string",e)).throw(y.invalidParameters),[2,this._manager.getChannel(e)]}))}))},t.prototype.getChannelWithoutCache=function(e){return s(this,void 0,void 0,(function(){return d(this,(function(t){return ce(ne("string",e)).throw(y.invalidParameters),[2,this._manager.getChannelWithoutCache(e)]}))}))},t.prototype.getMyGroupChannelChangeLogsByToken=function(e,t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var n;return d(this,(function(a){switch(a.label){case 0:return n=B(B({},be),t),ce(ne("string",e)&&Me(n)).throw(y.invalidParameters),[4,this._manager.getMyGroupChannelChangeLogs(e,n)];case 1:return[2,a.sent()]}}))}))},t.prototype.getMyGroupChannelChangeLogsByTimestamp=function(e,t){return void 0===t&&(t={}),s(this,void 0,void 0,(function(){var n;return d(this,(function(a){switch(a.label){case 0:return n=B(B({},be),t),ce(ne("number",e)&&Me(n)).throw(y.invalidParameters),[4,this._manager.getMyGroupChannelChangeLogs(e,n)];case 1:return[2,a.sent()]}}))}))},t.prototype.getGroupChannelCount=function(e){return s(this,void 0,void 0,(function(){var t;return d(this,(function(n){return t=B(B({},Ee),e),ce(Se(t)).throw(y.invalidParameters),[2,this._manager.getGroupChannelCount(t)]}))}))},t.prototype.getUnreadItemCount=function(e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){return d(this,(function(t){switch(t.label){case 0:return[4,this._manager.getUnreadItemCount(e)];case 1:return[2,t.sent()]}}))}))},t.prototype.getTotalUnreadChannelCount=function(){return s(this,void 0,void 0,(function(){return d(this,(function(e){switch(e.label){case 0:return[4,this._manager.getTotalUnreadChannelCount()];case 1:return[2,e.sent()]}}))}))},t.prototype.getTotalUnreadMessageCount=function(e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){return d(this,(function(t){switch(t.label){case 0:return[4,this._manager.getTotalUnreadMessageCount(e)];case 1:return[2,t.sent()]}}))}))},t.prototype.getTotalScheduledMessageCount=function(e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){return d(this,(function(t){switch(t.label){case 0:return[4,this._manager.getTotalScheduledMessageCount(e)];case 1:return[2,t.sent()]}}))}))},t.prototype.getSubscribedTotalUnreadMessageCount=function(){return this._manager.getSubscribedTotalUnreadMessageCount()},t.prototype.getSubscribedCustomTypeTotalUnreadMessageCount=function(){return this._manager.getSubscribedCustomTypeTotalUnreadMessageCount()},t.prototype.getSubscribedCustomTypeUnreadMessageCount=function(e){return this._manager.getSubscribedCustomTypeUnreadMessageCount(e)},t.prototype.createChannel=function(e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){var t;return d(this,(function(n){return t=B(B({},Le),e),ce(Ae(t)).throw(y.invalidParameters),[2,this._manager.createChannel(t)]}))}))},t.prototype.createDistinctChannelIfNotExist=function(e){return void 0===e&&(e={}),s(this,void 0,void 0,(function(){var t;return d(this,(function(n){return t=B(B({},Le),e),ce(Ae(t)).throw(y.invalidParameters),t&&(t.isDistinct=!0),[2,this.createChannel(t)]}))}))},t.prototype.createChannelWithUserIds=function(e,t,n,a,r,i){return void 0===t&&(t=!1),void 0===r&&(r=""),void 0===i&&(i=""),s(this,void 0,void 0,(function(){var s;return d(this,(function(o){return s=B(B({},Le),{invitedUserIds:e,isDistinct:t,name:n,data:r,customType:i}),"string"==typeof a?s.coverUrl=a:s.coverImage=a,[2,this.createChannel(s)]}))}))},t.prototype.markAsReadAll=function(){return s(this,void 0,void 0,(function(){return d(this,(function(e){return this._manager.markAsReadAll(),[2]}))}))},t.prototype.markAsReadWithChannelUrls=function(e){return s(this,void 0,void 0,(function(){return d(this,(function(t){return ce(ae("string",e)).throw(y.invalidParameters),this._manager.markAsReadWithChannelUrls(e),[2]}))}))},t.prototype.markAsDelivered=function(e){return s(this,void 0,void 0,(function(){return d(this,(function(t){switch(t.label){case 0:return ce(ne("string",e)).throw(y.invalidParameters),[4,this.getChannel(e)];case 1:return[4,t.sent().markAsDelivered()];case 2:return t.sent(),[2]}}))}))},t}(ue);export{Ke as BaseChannelCollection,Be as GroupChannelCollection,Xe as GroupChannelHandler,tt as GroupChannelModule,Oe as MembershipFilter,Ye as PublicGroupChannelListQuery,et as ScheduledMessageListQuery};