-
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) · 32.5 KB
/
groupChannel.js
File metadata and controls
1 lines (1 loc) · 32.5 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 T,T as A,E as F,aU as x,w as N,N as I,bl as R,D as V,J as K,c as z,d as W,u as B,g as J,A as Y,aW as X,f as Z,h as $,j as ee,a as te,a2 as ne,a5 as ae,ap as re,aX as ie,bm as se,au as oe,F as le,aq as ce}from"./lib/__bundle-e9d3f9f9.js";export{bn as MessageEventSource,bo as MutedState}from"./lib/__bundle-e9d3f9f9.js";import{T as ue,G as he,H as de,s as pe,a as fe,P as _e,b as ve,S as me,c as ge,d as ye,v as Ce,e as be,f as Se,g as Me,h as Ee}from"./lib/__bundle-cd0f09d3.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,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-cd0f09d3.js";import{ah as Le,Q as Te,ai as we}from"./lib/__bundle-b83d0535.js";export{ag as MessageFilter,aj as PinnedMessage,ak as PinnedMessageListQuery,al as ReadStatus,ai as ScheduledStatus}from"./lib/__bundle-b83d0535.js";import{c as Ae,F as ke,G as Fe,P as xe,e as Ne}from"./lib/__bundle-3845896a.js";export{G as GroupChannelListOrder,P as PublicGroupChannelListOrder,e as ScheduledMessageListOrder}from"./lib/__bundle-3845896a.js";import{B as Ue}from"./lib/__bundle-6295d67d.js";import"./lib/__bundle-6c219ecb.js";import"./lib/__bundle-d136e60a.js";import"./lib/__bundle-acd77193.js";var Ge,Oe={},Ie=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 Ae(C,(function(){return s(r,void 0,void 0,(function(){var e,t,n,a,r,i,s,o,c,h,f,_,C,b,S,M;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:de.ALL,order:Fe.CHRONOLOGICAL},d.label=2;case 2:if(d.trys.push([2,9,12,13]),t.order!==Fe.LATEST_LAST_MESSAGE)return[3,6];d.label=3;case 3:return d.trys.push([3,5,,6]),[4,p.preference.get(A(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,he.of(this._iid).getMyGroupChannels(null!==(_=null===(f=this._metadata)||void 0===f?void 0:f.token)&&void 0!==_?_:"",t,this._limit,T.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!==(M=null===(S=t.order)||void 0===S?void 0:S.toString())&&void 0!==M?M:"",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 ke&&r.resume()}))}return e.of=function(t){return Oe[t]||(Oe[t]=new e({_iid:t})),Oe[t].ref++,Oe[t]},e.clear=function(e){Oe[e]&&(Oe[e].close(),delete Oe[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 ue({})},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 ue(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 Oe[this._iid])},e}(),De={},Pe=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 Ae(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=he.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 ke&&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 De[i]||(De[i]=new e({_iid:n,prefix:a,fetcher:r})),De[i].ref++,De[i]},e.clear=function(e){var t=e._iid,n=e.prefix,a=n?"".concat(t,":").concat(n):t;De[a]&&(De[a].close(),delete De[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 De[e]}},e}(),Re=function(e,t){var n,a,r,i;switch(t){case Fe.LATEST_LAST_MESSAGE:return null!==(a=null===(n=e.lastMessage)||void 0===n?void 0:n.createdAt)&&void 0!==a?a:e.createdAt;case Fe.CHRONOLOGICAL:return e.createdAt;case Fe.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}},He=function(e,t){return e.findIndex((function(e){return e.isIdentical(t)}))},Ve=function(e,t,n){if(e.length>0){for(var a=He(e,t),r=0,i=e.length-1,s=Math.floor((r+i)/2);r<i;){var o=je(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:je(e[s],t,n)>=0?s:s+1,oldPosition:a}}return{place:e.length,oldPosition:-1}},je=function(e,t,n){switch(n){case Fe.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 Fe.CHRONOLOGICAL:return t.createdAt-e.createdAt;case Fe.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._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=Ie.of(e),this._backgroundSync.resume()),this._changelogSync=Pe.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){he.of(this._iid).subscribeChannelEvent(e,t)},e.prototype._unsubscribeChannelEvent=function(e){he.of(this._iid).unsubscribeChannelEvent(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=He(this._channels,_);v>=0&&this._channels.splice(v,1);var m=Ve(this._channels,_,this.order).place;if(v<0)m===this._channels.length?!n&&this.hasMore||(c.push(_),this._channels.push(_)):(c.push(_),this._channels.splice(m,0,_));else switch(t.source){case T.EVENT_CHANNEL_UPDATED:case T.EVENT_MESSAGE_RECEIVED:case T.SYNC_CHANNEL_CHANGELOGS:case T.EVENT_MESSAGE_SENT:this.order===Fe.CHANNEL_NAME_ALPHABETICAL&&this.hasMore&&m===this._channels.length?h.push(_):(this._channels.splice(m,0,_),u.push(_));break;default:this._channels.splice(m,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 g=N(h),y=g.next();!y.done;y=g.next()){_=y.value;var C=He(this._channels,_);-1!==C&&this._channels.splice(C,1)}}catch(e){i={error:e}}finally{try{y&&!y.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}pe(t.source)&&I((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 pe(t.source)&&i.length>0&&I((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=he.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=Re(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=Re(t[t.length-1],this.order)),[2,t]}}))}))},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:T.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,S,M,E,L,w,A,k,F=this;return d(this,(function(x){switch(x.label){case 0:if(this._isDisposed)throw new y({code:V.COLLECTION_DISPOSED,message:"Collection has been disposed."});return a=null,this._includeChangesOnInitialLoad&&0===this._channels.length&&this._changelogSync.isRunning?[4,new Promise((function(e){F._changelogSyncSubscriberContext=F._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 R({type:g.FEATURE_LOCALCACHE,data:{use_local_cache:i.localCacheEnabled,collection_interface:{group_channel:!0}}})),x.label=5;case 5:return c=[],this._hasMore?!i.localCacheEnabled||o.isConnected&&!(null===(n=this._backgroundSync)||void 0===n?void 0:n.completed)?[3,7]:[4,K((function(){return s(F,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]}}))}))}))]:[3,11];case 6:return x.sent(),this._hasMore=c.length>=this._limit,[3,10];case 7:return x.trys.push([7,9,,10]),[4,this._getRemoteChannels()];case 8:return c=x.sent(),this._isGetRemoteChannelsSucceeded=!0,[3,10];case 9:return x.sent(),this._isGetRemoteChannelsSucceeded=!1,[3,10];case 10:this._addChannelsToView(c,{source:T.REQUEST_CHANNEL},!0),this._hasMore||(this._localCacheToken=null),x.label=11;case 11:if(a){u=h.of(this._iid).sdkState,p=a.updatedChannels.filter((function(e){return F._channelFilter.match(e,u.userId)}));try{for(f=N(p),_=f.next();!_.done;_=f.next())v=_.value,(E=He(c,v))>=0?c[E]=v:(m=Ve(c,v,this.order).place,c.splice(m,0,v)),this._addChannelsToView([v],{source:T.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),S=b.next();!S.done;S=b.next())M=S.value,(E=C.indexOf(M))>=0&&(c.splice(E,1),C.splice(E,1))}catch(e){A={error:e}}finally{try{S&&!S.done&&(k=b.return)&&k.call(b)}finally{if(A)throw A.error}}this._removeChannelsFromView(a.deletedChannelUrls,{source:T.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}(),Qe=function(e){return{getRemoteChannels:function(t,n,a,r){return he.of(e).getMyGroupChannels(t,J(W(W({},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(A(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,he.of(e).getMyGroupChannelChangeLogs(t,n,T.SYNC_CHANNEL_CHANGELOGS)]}}))}))}}},ze=function(e){function t(t,n){void 0===n&&(n={});var a,r,i,s=this;(s=e.call(this,t,W(W({},n),{filter:null!==(a=n.filter)&&void 0!==a?a:new fe,order:null!==(r=n.order)&&void 0!==r?r:Fe.LATEST_LAST_MESSAGE,limit:null!==(i=n.limit)&&void 0!==i?i:Le,fetcher:Qe(t)}))||this)._key="gcc-".concat(B());var o=h.of(s._iid).sdkState;return s._subscribeChannelEvent(s._key,{onUpdate:function(e,t){var n=t.source;if(pe(n)){var a=e.filter((function(e){return s.filter.match(e,o.userId)})),r=e.filter((function(e){return!s.filter.match(e,o.userId)})).map((function(e){return e.url}));a.length>0&&s._addChannelsToView(a,t,!1),r.length>0&&s._removeChannelsFromView(r,t)}},onRemove:function(e,t){s._removeChannelsFromView(e,t)}}),s}return z(t,e),t.prototype.dispose=function(){e.prototype.dispose.call(this),this._unsubscribeChannelEvent(this._key)},t}(Ke),We=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,m=t.includeFrozen,g=t.includeMetaData;return(n=e.call(this)||this).method=Y.GET,n.path=X,n.params=Z(J({token:a,limit:r,order:i,show_member:!0,show_read_receipt:!0,show_delivery_receipt:!0,show_empty:s,public_mode:_e.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:m,show_metadata:g})),n}return z(t,e),t}($),Be=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 ve(t,e)}))),a.ts="number"==typeof s?s:0,a}return z(t,e),t}(ee);!function(e){e.ALL="all",e.JOINED="joined"}(Ge||(Ge={}));var qe=function(e){function t(t,n){var a,r,i,s,o,l,c,u,h,d,p,f,_,v,m=this;return(m=e.call(this,t,n)||this).includeEmpty=!1,m.includeFrozen=!0,m.includeMetaData=!0,m.channelUrlsFilter=null,m.customTypesFilter=null,m.customTypeStartsWithFilter=null,m.channelNameContainsFilter=null,m.membershipFilter=Ge.ALL,m.superChannelFilter=me.ALL,m.metadataKey=null,m.metadataValues=null,m.metadataOrderKeyFilter=null,m.metadataValueStartsWith=null,m.order=xe.CHRONOLOGICAL,m.includeEmpty=null!==(a=n.includeEmpty)&&void 0!==a&&a,m.includeFrozen=null===(r=n.includeFrozen)||void 0===r||r,m.includeMetaData=null===(i=n.includeMetaData)||void 0===i||i,m.channelUrlsFilter=null!==(s=n.channelUrlsFilter)&&void 0!==s?s:null,m.customTypesFilter=null!==(o=n.customTypesFilter)&&void 0!==o?o:null,m.customTypeStartsWithFilter=null!==(l=n.customTypeStartsWithFilter)&&void 0!==l?l:null,m.channelNameContainsFilter=null!==(c=n.channelNameContainsFilter)&&void 0!==c?c:null,m.membershipFilter=null!==(u=n.membershipFilter)&&void 0!==u?u:Ge.ALL,m.superChannelFilter=null!==(h=n.superChannelFilter)&&void 0!==h?h:me.ALL,m.metadataKey=null!==(d=n.metadataKey)&&void 0!==d?d:null,m.metadataValues=null!==(p=n.metadataValues)&&void 0!==p?p:null,m.metadataOrderKeyFilter=null!==(f=n.metadataOrderKeyFilter)&&void 0!==f?f:null,m.metadataValueStartsWith=null!==(_=n.metadataValueStartsWith)&&void 0!==_?_:null,m.order=null!==(v=n.order)&&void 0!==v?v:xe.CHRONOLOGICAL,m}return z(t,e),t.prototype._validate=function(){return e.prototype._validate.call(this)&&te("boolean",this.includeEmpty)&&te("boolean",this.includeFrozen)&&te("boolean",this.includeMetaData)&&te("string",this.channelNameContainsFilter,!0)&&ne("string",this.channelUrlsFilter,!0)&&ne("string",this.customTypesFilter,!0)&&te("string",this.customTypeStartsWithFilter,!0)&&ae(Ge,this.membershipFilter)&&ae(me,this.superChannelFilter)&&ae(xe,this.order)&&te("string",this.metadataOrderKeyFilter,!0)&&te("string",this.metadataKey,!0)&&ne("string",this.metadataValues,!0)&&te("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 We(J(W(W({},this),{token:this._token}))),[4,t.send(n)]):[3,2]):[3,5];case 1:return a=o.sent(),r=a.as(Be),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}(re),Je=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 z(t,e),t}(function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.onUserJoined=ie,t.onUserLeft=ie,t.onUserReceivedInvitation=ie,t.onUserDeclinedInvitation=ie,t.onChannelHidden=ie,t.onUnreadMemberStatusUpdated=ie,t.onUserMarkedRead=ie,t.onUserMarkedUnread=ie,t.onUndeliveredMemberStatusUpdated=ie,t.onTypingStatusUpdated=ie,t.onPollUpdated=ie,t.onPollVoted=ie,t.onPollDeleted=ie,t.onPinnedMessageUpdated=ie,t}return z(t,e),t}(Ue)),Ye=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=Y.GET,n.path="".concat(se),n.params=Z(J({token:a,limit:r,reverse:s,channel_url:o,order:i,message_type:l,status:c})),n}return z(t,e),t}($),Xe=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 z(t,e),t}(ee),Ze=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=oe.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:oe.ALL,l}return z(t,e),t.prototype._validate=function(){return e.prototype._validate.call(this)&&te("string",this.channelUrl,!0)&&(ae(Ne,this.order)||null===this.order)&&te("boolean",this.reverse)&&(ne(we,this.scheduledStatus)||null===this.scheduledStatus)&&ae(oe,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 Ye(J(W(W({},this),{token:this._token}))),[4,e.send(t)]):[3,2]:[3,5];case 1:return n=s.sent(),a=n.as(Xe),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}(re),$e=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="groupChannel",t}return z(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 he(t,{sdkState:a,cacheContext:c,dispatcher:r,sessionManager:i,requestQueue:s,logger:o})},t.prototype.createGroupChannelCollection=function(e){return void 0===e&&(e={}),new ze(this._iid,e)},t.prototype.createMyGroupChannelListQuery=function(e){return void 0===e&&(e={}),new ge(this._iid,e)},t.prototype.createPublicGroupChannelListQuery=function(e){return void 0===e&&(e={}),new qe(this._iid,e)},t.prototype.createScheduledMessageListQuery=function(e){return void 0===e&&(e={}),new Ze(this._iid,e)},t.prototype.addGroupChannelHandler=function(e,t){le(te("string",e)&&t instanceof Je).throw(y.invalidParameters),this._manager.addHandler(e,t)},t.prototype.removeGroupChannelHandler=function(e){le(te("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.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 le(te("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 le(te("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=W(W({},ye),t),le(te("string",e)&&Ce(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=W(W({},ye),t),le(te("number",e)&&Ce(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=W(W({},be),e),le(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=W(W({},Me),e),le(Ee(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=W(W({},Me),e),le(Ee(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=W(W({},Me),{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 le(ne("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 le(te("string",e)).throw(y.invalidParameters),[4,this.getChannel(e)];case 1:return[4,t.sent().markAsDelivered()];case 2:return t.sent(),[2]}}))}))},t}(ce);export{Ke as BaseChannelCollection,ze as GroupChannelCollection,Je as GroupChannelHandler,$e as GroupChannelModule,Ge as MembershipFilter,qe as PublicGroupChannelListQuery,Ze as ScheduledMessageListQuery};