-
Notifications
You must be signed in to change notification settings - Fork 16
/
openChannel.js
1 lines (1 loc) · 30 KB
/
openChannel.js
1
import{c as e,_ as n,b as t,af as r,Q as a,a as s,i,A as o,bn as u,bo as l,f as c,h,e as d,u as p,ak as f,U as C,z as v,p as _,q as g,g as y,C as m,aA as U,W as E,O as M,D as w,F as P,t as b,G as T,aM as N,a2 as D,aT as H,bi as I,w as O,s as x,bj as A,aB as L,V as R,ai as F,aO as k,a_ as S}from"./lib/__bundle-4b8c4ff5.js";import{a3 as z,a4 as q,a5 as Q,a7 as G,a6 as j,a8 as B,a9 as K,aa as V,ae as W,af as X,ag as Y,ah as Z,P as $,z as J,as as ee,T as ne,ak as te}from"./lib/__bundle-c4a9b19b.js";import{C as re,B as ae,U as se,a as ie,O as oe,P as ue,M as le,T as ce,R as he,b as de,A as pe}from"./lib/__bundle-5ddf8230.js";import{B as fe}from"./lib/__bundle-8b543c7e.js";import"./lib/__bundle-acd77193.js";var Ce=function(r){function a(){var e=null!==r&&r.apply(this,arguments)||this;return e._channels=new Map,e._enteredChannelUrls=[],e}return e(a,r),Object.defineProperty(a.prototype,"enteredChannels",{get:function(){var e=this;return this._enteredChannelUrls.map((function(n){return e._channels.get(n)})).filter((function(e){return!!e}))},enumerable:!1,configurable:!0}),a.prototype.isEnteredChannel=function(e){return this._enteredChannelUrls.includes(e)},a.prototype.enter=function(e){this._enteredChannelUrls.indexOf(e)<0&&this._enteredChannelUrls.push(e)},a.prototype.exit=function(e){var n=this._enteredChannelUrls.indexOf(e);n>=0&&this._enteredChannelUrls.splice(n,1)},a.prototype.exitAll=function(){this._enteredChannelUrls=[]},a.prototype.get=function(e){return n(this,void 0,void 0,(function(){return t(this,(function(n){return[2,this._channels.get(e)]}))}))},a.prototype.upsert=function(e){return n(this,void 0,void 0,(function(){var n,r=this;return t(this,(function(t){return n=[],e.forEach((function(e){if(r._channels.has(e.url)){var t=r._channels.get(e.url);Object.assign(t,e),n.push(t)}else r._channels.set(e.url,e),n.push(e)})),[2,n]}))}))},a.prototype.remove=function(e){return n(this,void 0,void 0,(function(){return t(this,(function(n){return this._channels.delete(e),this.exit(e),[2]}))}))},a.prototype.clear=function(){return n(this,void 0,void 0,(function(){return t(this,(function(e){return this._channels.clear(),this._enteredChannelUrls=[],[2]}))}))},a}(r),ve={channelUrl:void 0,name:void 0,coverUrlOrImage:void 0,data:void 0,customType:void 0,operatorUserIds:void 0,isEphemeral:void 0},_e=function(n){function t(e){var t=e.channelUrl,r=e.isInternalCall,a=n.call(this)||this;return a.method=o.GET,a.path="".concat(r?u:l,"/").concat(encodeURIComponent(t)),a.params={show_pinned_messages:!0},a}return e(t,n),t}(c),ge=function(n){function t(e,t){var r=n.call(this,e,t)||this;return r.channel=new xe(e,t),r}return e(t,n),t}(h),ye=function(n){function t(e){var t=this,r=e.channelUrl,a=e.coverUrlOrImage,u=e.name,c=e.data,h=e.customType,f=e.operatorUserIds,C=e.isEphemeral;return(t=n.call(this)||this).method=o.POST,t.path=l,t.params=d(p({channel_url:r,cover_url:s("string",a)?a:null,cover_file:i(a)?a:null,name:u,data:c,custom_type:h,operators:f,is_ephemeral:C})),t}return e(t,n),t}(c);!function(n){function t(e,t){var r=n.call(this,e,t)||this;return r.channel=new xe(e,t),r}e(t,n)}(h);var me=function(n){function t(e){var t=e.channelUrl;return n.call(this,{code:"ENTR",payload:{channel_url:t},ackRequired:!0})||this}return e(t,n),t}(f),Ue=function(n){function t(e,t,r){var a,s,i=this;return i=n.call(this,e,"SYEV",r)||this,r.data&&(i.participantCount=null!==(a=r.data.participant_count)&&void 0!==a?a:0,i.user=new C(e,r.data),i.ts=null!==(s=r.data.edge_ts)&&void 0!==s?s:0),i}return e(t,n),t}(re),Ee=function(n){function t(e){var t=e.channelUrl;return n.call(this,{code:"EXIT",payload:{channel_url:t},ackRequired:!0})||this}return e(t,n),t}(f),Me=function(n){function t(e,t,r){var a,s,i=this;return i=n.call(this,e,"EXIT",r)||this,r.data&&(i.participantCount=null!==(a=r.data.participant_count)&&void 0!==a?a:0,i.user=new C(e,r.data),i.ts=null!==(s=r.data.edge_ts)&&void 0!==s?s:0),i}return e(t,n),t}(re),we={},Pe=function(r){function o(e,a){var s=r.call(this,e,y(y({},a),{channelType:m.OPEN}))||this;return s.subscribeChannelEvent=U,s.unsubscribeChannelEvent=U,s.refreshChannel=function(){return n(s,void 0,void 0,(function(){return t(this,(function(e){return[2,U()]}))}))},s._openChannelCache=new Ce(e),s._openChannelHandlers=new Map,s._dispatcher.on((function(e){var n,t;if(e instanceof E)s._handleEvent(e).catch((function(e){if(M(e)&&"foreground"===s._sdkState.appState)throw e}));else if(e instanceof w&&e.stateType===P.CONNECTED){var r=s._openChannelCache.enteredChannels;try{for(var a=b(r),i=a.next();!i.done;i=a.next()){i.value.enter()}}catch(e){n={error:e}}finally{try{i&&!i.done&&(t=a.return)&&t.call(a)}finally{if(n)throw n.error}}}})),we[e]||(we[e]=s),s}return e(o,r),o.of=function(e){return we[e]},o.prototype.buildOpenChannelFromSerializedData=function(e){var n=v(e);return new xe(this._iid,xe.payloadify(n))},o.prototype.getChannelFromCache=function(e){var r;return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,this._openChannelCache.get(e)];case 1:return[2,null!==(r=n.sent())&&void 0!==r?r:null]}}))}))},o.prototype.upsertChannelsToCache=function(e){return n(this,void 0,void 0,(function(){return t(this,(function(n){switch(n.label){case 0:return[4,this._openChannelCache.upsert(e)];case 1:return[2,n.sent()]}}))}))},o.prototype.removeChannelsFromCache=function(e){return n(this,void 0,void 0,(function(){var n,r,a,s,i,o;return t(this,(function(t){switch(t.label){case 0:t.trys.push([0,5,6,7]),n=b(e),r=n.next(),t.label=1;case 1:return r.done?[3,4]:(a=r.value,[4,this._openChannelCache.remove(a)]);case 2:t.sent(),t.label=3;case 3:return r=n.next(),[3,1];case 4:return[3,7];case 5:return s=t.sent(),i={error:s},[3,7];case 6:try{r&&!r.done&&(o=n.return)&&o.call(n)}finally{if(i)throw i.error}return[7];case 7:return[2]}}))}))},o.prototype.setEnteredToCache=function(e){this._openChannelCache.enter(e.url)},o.prototype.setExitedToCache=function(e){this._openChannelCache.exit(e.url)},Object.defineProperty(o.prototype,"handlers",{get:function(){return _([],g(this._openChannelHandlers.values()),!1)},enumerable:!1,configurable:!0}),o.prototype._handleEvent=function(e){return n(this,void 0,void 0,(function(){var r,a,s,i,o,u,l,c,h,d,p,f,C,v,_,g,y,U,E,w,P,O,x,L,R,F,k,S,$,J,ee,ne,te,ae,fe,Ce,ve,_e,ge,ye,me,Ee,we,Pe,be,Te,Ne,De,He,Ie,Oe,xe,Ae,Le,Re,Fe,ke,Se,ze,qe,Qe,Ge,je,Be,Ke,Ve,We,Xe,Ye,Ze,$e,Je,en,nn,tn=this;return t(this,(function(rn){switch(rn.label){case 0:switch(rn.trys.push([0,59,,60]),e.code){case"MESG":case"FILE":case"ADMM":case"BRDM":return[3,1];case"MEDI":case"FEDI":case"AEDI":return[3,4];case"DELM":return[3,7];case"MRCT":return[3,10];case"MTHD":return[3,13];case"MCNT":return[3,16];case"PEDI":return[3,27];case"VOTE":return[3,30];case"SYEV":return[3,33]}return[3,58];case 1:return i=null,"MESG"===e.code?i=e.as(Y):"FILE"===e.code?i=e.as(Z):"ADMM"!==e.code&&"BRDM"!=e.code||(i=e.as(pe)),i?(r=i.message,a=i.isMentioned,r.channelType!==m.OPEN?[3,3]:[4,this.getChannel(r.channelUrl,!0)]):[3,3];case 2:s=rn.sent(),T((function(){return n(tn,void 0,void 0,(function(){var e,n,i,o,u;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())i=n.value,this._openChannelCache.isEnteredChannel(s.url)&&(i.onMessageReceived&&i.onMessageReceived(s,r),a&&i.onMentionReceived&&i.onMentionReceived(s,r))}catch(e){o={error:e}}finally{try{n&&!n.done&&(u=e.return)&&u.call(e)}finally{if(o)throw o.error}}return[2]}))}))})),rn.label=3;case 3:return[3,58];case 4:return i=null,"MEDI"===e.code?i=e.as(W):"FEDI"===e.code?i=e.as(X):"AEDI"===e.code&&(i=e.as(de)),i?(o=i.message,u=i.mentionCountChange,o.channelType!==m.OPEN?[3,6]:[4,this.getChannel(o.channelUrl,!0)]):[3,6];case 5:l=rn.sent(),c=!1,l.lastPinnedMessage&&l.lastPinnedMessage.messageId===o.messageId&&l.lastPinnedMessage.updatedAt<o.updatedAt&&(l.lastPinnedMessage=o,c=!0),T((function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s,i,h;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())r=n.value,this._openChannelCache.isEnteredChannel(l.url)&&(c&&(null===(i=r.onPinnedMessageUpdated)||void 0===i||i.call(r,l),null===(h=r.onChannelChanged)||void 0===h||h.call(r,l)),r.onMessageUpdated&&r.onMessageUpdated(l,o),u>0&&r.onMentionReceived&&r.onMentionReceived(l,o))}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),rn.label=6;case 6:return[3,58];case 7:return h=e.as(I),ne=h.channelUrl,te=h.channelType,d=h.messageId,te!==m.OPEN?[3,9]:[4,this.getChannel(ne,!0)];case 8:p=rn.sent(),T((function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())r=n.value,this._openChannelCache.isEnteredChannel(p.url)&&r.onMessageDeleted&&r.onMessageDeleted(p,d)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),rn.label=9;case 9:return[3,58];case 10:return f=e.as(he),ne=f.channelUrl,te=f.channelType,C=f.event,te!==m.OPEN?[3,12]:[4,this.getChannel(ne,!0)];case 11:v=rn.sent(),T((function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())r=n.value,this._openChannelCache.isEnteredChannel(v.url)&&r.onReactionUpdated&&r.onReactionUpdated(v,C)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),rn.label=12;case 12:return[3,58];case 13:return(_=e.as(ce).event).channelType!==m.OPEN?[3,15]:[4,this.getChannel(_.channelUrl,!0)];case 14:g=rn.sent(),T((function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())r=n.value,this._openChannelCache.isEnteredChannel(g.url)&&r.onThreadInfoUpdated&&r.onThreadInfoUpdated(g,_)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),rn.label=15;case 15:return[3,58];case 16:y=e.as(le).openChannelMemberCounts,U=[],rn.label=17;case 17:rn.trys.push([17,22,23,24]),E=b(y),w=E.next(),rn.label=18;case 18:return w.done?[3,21]:(P=w.value,ne=P.channelUrl,Ee=P.participantCount,O=P.updatedAt,[4,this.getChannelFromCache(ne)]);case 19:(x=rn.sent())&&x._updateParticipantCount(Ee,O)&&U.push(x),rn.label=20;case 20:return w=E.next(),[3,18];case 21:return[3,24];case 22:return L=rn.sent(),en={error:L},[3,24];case 23:try{w&&!w.done&&(nn=E.return)&&nn.call(E)}finally{if(en)throw en.error}return[7];case 24:return U.length>0?[4,this.upsertChannelsToCache(U)]:[3,26];case 25:R=rn.sent(),T((function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())(r=n.value).onChannelMemberCountChanged&&r.onChannelMemberCountChanged(R)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),rn.label=26;case 26:return[3,58];case 27:return F=e.as(ue),k=F.event,S=F.status,ne=F.channelUrl,te=F.channelType,ne&&te===m.OPEN?[4,this.getChannel(ne,!0)]:[3,29];case 28:$=rn.sent(),this._dispatcher.dispatch(new H({event:k,source:D.EVENT_POLL_UPDATED})),T(S===A?function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())(r=n.value).onPollDeleted&&r.onPollDeleted($,k.pollId)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))}:function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())(r=n.value).onPollUpdated&&r.onPollUpdated($,k)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))}),rn.label=29;case 29:return[3,58];case 30:return J=e.as(V),ee=J.event,ne=J.channelUrl,te=J.channelType,ne&&te===m.OPEN?[4,this.getChannel(ne,!0)]:[3,32];case 31:ae=rn.sent(),this._dispatcher.dispatch(new N({event:ee,source:D.EVENT_POLL_VOTED})),T((function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())(r=n.value).onPollVoted&&r.onPollVoted(ae,ee)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),rn.label=32;case 32:return[3,58];case 33:if(!(fe=e.as(re).event).isOpenChannelEvent)return[3,57];switch(fe.category){case ie.CHANNEL_ENTER:return[3,34];case ie.CHANNEL_EXIT:return[3,36];case ie.CHANNEL_OPERATOR_UPDATE:return[3,38];case ie.USER_CHANNEL_MUTE:case ie.USER_CHANNEL_UNMUTE:return[3,40];case ie.USER_CHANNEL_BAN:case ie.USER_CHANNEL_UNBAN:return[3,42];case ie.CHANNEL_FREEZE:case ie.CHANNEL_UNFREEZE:return[3,44];case ie.CHANNEL_DELETED:return[3,46];case ie.CHANNEL_PROP_CHANGED:return[3,49];case ie.CHANNEL_META_DATA_CHANGED:return[3,51];case ie.CHANNEL_META_COUNTERS_CHANGED:return[3,53];case ie.PINNED_MESSAGE_CHANGED:return[3,55]}return[3,57];case 34:return[4,this.getChannel(fe.channelUrl,!0)];case 35:return Ce=rn.sent(),ve=e.as(Ue),Ee=ve.participantCount,_e=ve.user,ge=Ce._updateParticipantCount(Ee,fe.ts),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onUserEntered&&e.onUserEntered(Ce,_e),ge&&e.onChannelParticipantCountChanged&&e.onChannelParticipantCountChanged(Ce)})),[2]}))}))})),[3,57];case 36:return[4,this.getChannel(fe.channelUrl,!0)];case 37:return ye=rn.sent(),me=e.as(Me),Ee=me.participantCount,we=me.user,Pe=ye._updateParticipantCount(Ee,fe.ts),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onUserExited&&e.onUserExited(ye,we),Pe&&e.onChannelParticipantCountChanged&&e.onChannelParticipantCountChanged(ye)})),[2]}))}))})),[3,57];case 38:return[4,this.getChannel(fe.channelUrl,!0)];case 39:return be=rn.sent(),Te=e.as(oe).operators,be.operators=Te,this.upsertChannelsToCache([be]),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onOperatorUpdated&&e.onOperatorUpdated(be,Te)})),[2]}))}))})),[3,57];case 40:return[4,this.getChannel(fe.channelUrl,!0)];case 41:return Ne=rn.sent(),De=fe.category===ie.USER_CHANNEL_MUTE,He=e.as(De?B:K).user,T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){De?e.onUserMuted&&e.onUserMuted(Ne,He):e.onUserUnmuted&&e.onUserUnmuted(Ne,He)})),[2]}))}))})),[3,57];case 42:return[4,this.getChannel(fe.channelUrl,!0)];case 43:return Ie=rn.sent(),Oe=fe.category===ie.USER_CHANNEL_BAN,xe=e.as(Oe?G:j).user,T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){Oe?e.onUserBanned&&e.onUserBanned(Ie,xe):e.onUserUnbanned&&e.onUserUnbanned(Ie,xe)})),[2]}))}))})),[3,57];case 44:return[4,this.getChannel(fe.channelUrl,!0)];case 45:return Ae=rn.sent(),Le=e.as(Q).freeze,Ae.isFrozen=Le,this.upsertChannelsToCache([Ae]),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){Le?e.onChannelFrozen&&e.onChannelFrozen(Ae):e.onChannelUnfrozen&&e.onChannelUnfrozen(Ae)})),[2]}))}))})),[3,57];case 46:return[4,this.getChannel(fe.channelUrl,!0)];case 47:return Re=rn.sent(),[4,this.removeChannelsFromCache([Re.url])];case 48:return rn.sent(),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onChannelDeleted&&e.onChannelDeleted(Re.url,Re.channelType)})),[2]}))}))})),[3,57];case 49:return[4,this.getChannelWithoutCache(fe.channelUrl,!0)];case 50:return Fe=rn.sent(),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onChannelChanged&&e.onChannelChanged(Fe)})),[2]}))}))})),[3,57];case 51:return[4,this.getChannel(fe.channelUrl,!0)];case 52:return ke=rn.sent(),Se=e.as(q),ze=Se.created,qe=Se.updated,Qe=Se.deleted,ze&&ke._upsertCachedMetaData(ze,fe.ts),qe&&ke._upsertCachedMetaData(qe,fe.ts),Qe&&ke._removeFromCachedMetaData(Qe,fe.ts),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){ze&&e.onMetaDataCreated&&e.onMetaDataCreated(ke,ze),qe&&e.onMetaDataUpdated&&e.onMetaDataUpdated(ke,qe),Qe&&e.onMetaDataDeleted&&e.onMetaDataDeleted(ke,Qe)})),[2]}))}))})),[3,57];case 53:return[4,this.getChannel(fe.channelUrl,!0)];case 54:return Ge=rn.sent(),je=e.as(z),Be=je.created,Ke=je.updated,Ve=je.deleted,T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){Be&&e.onMetaCounterCreated&&e.onMetaCounterCreated(Ge,Be),Ke&&e.onMetaCounterUpdated&&e.onMetaCounterUpdated(Ge,Ke),Ve&&e.onMetaCounterDeleted&&e.onMetaCounterDeleted(Ge,Ve)})),[2]}))}))})),[3,57];case 55:return[4,this.getChannel(fe.channelUrl,!0)];case 56:return We=rn.sent(),Xe=e.as(se),Ye=Xe.pinnedMessageIds,Ze=Xe.latestPinnedMessage,($e=Xe.ts)>We._pinnedMessagesUpdatedAt&&(We.pinnedMessageIds=Ye,We.lastPinnedMessage=Ze,We._pinnedMessagesUpdatedAt=$e,this.upsertChannelsToCache([We]),T((function(){return n(tn,void 0,void 0,(function(){var e,n,r,a,s;return t(this,(function(t){try{for(e=b(this._openChannelHandlers.values()),n=e.next();!n.done;n=e.next())(r=n.value).onChannelChanged&&r.onChannelChanged(We)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),T((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onPinnedMessageUpdated&&e.onPinnedMessageUpdated(We)})),[2]}))}))}))),[3,57];case 57:return[3,58];case 58:return[3,60];case 59:if(Je=rn.sent(),M(Je))throw Je;return[3,60];case 60:return[2]}}))}))},o.prototype.addHandler=function(e,n){this._openChannelHandlers.set(e,n)},o.prototype.removeHandler=function(e){this._openChannelHandlers.delete(e)},o.prototype.clearHandler=function(){this._openChannelHandlers.clear()},o.prototype.getChannel=function(e,r){return void 0===r&&(r=!1),n(this,void 0,void 0,(function(){var n;return t(this,(function(t){switch(t.label){case 0:O(s("string",e)).throw(x.invalidParameters),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.getChannelFromCache(e)];case 2:return(n=t.sent())?[2,n]:[3,4];case 3:return t.sent(),[3,4];case 4:return[4,this.getChannelWithoutCache(e,r)];case 5:return[2,t.sent()]}}))}))},o.prototype.getChannelWithoutCache=function(e,r){return void 0===r&&(r=!1),n(this,void 0,void 0,(function(){var n,a,i;return t(this,(function(t){switch(t.label){case 0:return O(s("string",e)).throw(x.invalidParameters),n=new _e({channelUrl:e,isInternalCall:r}),[4,this._requestQueue.send(n)];case 1:return a=t.sent(),i=a.as(ge).channel,[4,this.upsertChannelsToCache([i])];case 2:return[2,t.sent()[0]]}}))}))},o.prototype.createChannel=function(e){return n(this,void 0,void 0,(function(){var n,r,o,u;return t(this,(function(t){switch(t.label){case 0:return n=y(y({},ve),e),O(function(e){return a("string",e.operatorUserIds,!0)&&(s("string",e.coverUrlOrImage,!0)||i(e.coverUrlOrImage,!0))&&s("string",e.name,!0)&&s("string",e.data,!0)&&s("string",e.customType,!0)&&(s("string",e.channelUrl)&&/^\w+$/.test(e.channelUrl)||null===e.channelUrl||void 0===e.channelUrl)&&s("boolean",e.isEphemeral,!0)}(n)).throw(x.invalidParameters),r=new ye(n),[4,this._requestQueue.send(r)];case 1:return o=t.sent(),u=o.as(ge).channel,this.upsertChannelsToCache([u]),[2,u]}}))}))},o}(ae),be={name:void 0,coverUrlOrImage:void 0,data:void 0,customType:void 0,operatorUserIds:void 0},Te=function(n){function t(e){var t=this,r=e.channelUrl,a=e.token,s=e.limit;return(t=n.call(this)||this).method=o.GET,t.path="".concat(l,"/").concat(encodeURIComponent(r),"/participants"),t.params={token:a,limit:s},t}return e(t,n),t}(c),Ne=function(n){function t(e,t){var r=n.call(this,e,t)||this;r.participants=[];var a=t.next,s=t.participants;return r.token=a,r.participants=s.map((function(n){return new $(e,n)})),r}return e(t,n),t}(h),De=function(r){function a(e,n,t){return r.call(this,e,n,m.OPEN,t)||this}return e(a,r),a.prototype._validate=function(){return r.prototype._validate.call(this)},a.prototype.next=function(){return n(this,void 0,void 0,(function(){var e,n,r,a,s,i;return t(this,(function(t){switch(t.label){case 0:return this._validate()?this._isLoading?[3,3]:this._hasNext?(this._isLoading=!0,e=R.of(this._iid).requestQueue,n=new Te(y(y({},this),{token:this._token})),[4,e.send(n)]):[3,2]:[3,5];case 1:return r=t.sent(),a=r.as(Ne),s=a.participants,i=a.token,this._token=i,this._hasNext=!!i,this._isLoading=!1,[2,s];case 2:return[2,[]];case 3:throw x.queryInProgress;case 4:return[3,6];case 5:throw x.invalidParameters;case 6:return[2]}}))}))},a}(L),He=function(n){function t(e){var t=this,r=e.channelUrl,a=e.coverUrlOrImage,u=e.name,c=e.data,h=e.customType,f=e.operatorUserIds;return(t=n.call(this)||this).method=o.PUT,t.path="".concat(l,"/").concat(encodeURIComponent(r)),t.params=d(p({cover_url:s("string",a)?a:null,cover_file:i(a)?a:null,name:u,data:c,custom_type:h,operators:f})),t}return e(t,n),t}(c),Ie=function(n){function t(e,t){var r=n.call(this,e,t)||this;return r.channel=new xe(e,t),r}return e(t,n),t}(h),Oe=function(n){function t(e){var t=this,r=e.channelUrl;return(t=n.call(this)||this).method=o.DELETE,t.path="".concat(l,"/").concat(encodeURIComponent(r)),t}return e(t,n),t}(c);!function(n){function t(e,t){return n.call(this,e,t)||this}e(t,n)}(h);var xe=function(r){function o(e,n){var t,a=this;return(a=r.call(this,e,n)||this)._lastParticipantCountUpdated=0,a.participantCount=0,a.operators=[],a.lastPinnedMessage=null,a._pinnedMessagesUpdatedAt=0,a.channelType=m.OPEN,a.participantCount=null!==(t=n.participant_count)&&void 0!==t?t:0,a.operators=Array.isArray(n.operators)?n.operators.map((function(n){return new C(e,n)})):[],a.lastPinnedMessage=n.latest_pinned_message?ne(a._iid,y({channel_type:a.channelType},n.latest_pinned_message)):null,a}return e(o,r),o.payloadify=function(e){return d(p(y(y({},J.payloadify(e)),{participant_count:e.participantCount,operators:e.operators.map((function(e){return C.payloadify(e)})),latest_pinned_message:e.lastPinnedMessage?ee(e.lastPinnedMessage):null})))},o.prototype.serialize=function(){return F(this)},o.prototype.isOperator=function(e){return e instanceof C?this.isOperator(e.userId):this.operators.some((function(n){return n.userId===e}))},o.prototype._updateParticipantCount=function(e,n){return n>this._lastParticipantCountUpdated&&(this.participantCount=e,this._lastParticipantCountUpdated=n,!0)},o.prototype.createParticipantListQuery=function(e){return new De(this._iid,this.url,e)},o.prototype.refresh=function(){return n(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,Pe.of(this._iid).getChannelWithoutCache(this.url)];case 1:return[2,e.sent()]}}))}))},o.prototype.enter=function(){return n(this,void 0,void 0,(function(){var e,n,r,a,s,i;return t(this,(function(t){switch(t.label){case 0:return e=R.of(this._iid).requestQueue,n=new me({channelUrl:this.url}),[4,e.send(n)];case 1:return r=t.sent(),a=r.as(Ue),s=a.participantCount,i=a.ts,this._updateParticipantCount(s,i),Pe.of(this._iid).setEnteredToCache(this),[2]}}))}))},o.prototype.exit=function(){return n(this,void 0,void 0,(function(){var e,n,r,a,s,i;return t(this,(function(t){switch(t.label){case 0:return e=R.of(this._iid).requestQueue,n=new Ee({channelUrl:this.url}),[4,e.send(n)];case 1:return r=t.sent(),a=r.as(Me),s=a.participantCount,i=a.ts,this._updateParticipantCount(s,i),Pe.of(this._iid).setExitedToCache(this),te.of(this._iid).fileMessageQueue.cancel(this),[2]}}))}))},o.prototype.updateChannel=function(e){return n(this,void 0,void 0,(function(){var n,r,o,u,l;return t(this,(function(t){switch(t.label){case 0:return n=y(y({},be),e),O(function(e){return a("string",e.operatorUserIds,!0)&&(s("string",e.coverUrlOrImage,!0)||i(e.coverUrlOrImage,!0))&&s("string",e.name,!0)&&s("string",e.data,!0)&&s("string",e.customType,!0)}(n)).throw(x.invalidParameters),r=R.of(this._iid).requestQueue,o=new He(y({channelUrl:this.url},n)),[4,r.send(o)];case 1:return u=t.sent(),l=u.as(Ie).channel,this._update(l),[4,Pe.of(this._iid).upsertChannelsToCache([l])];case 2:return t.sent(),[2,this]}}))}))},o.prototype.updateChannelWithOperatorUserIds=function(e,r,a,s,i){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){return n=y(y({},be),{name:e,coverUrlOrImage:r,data:a,operatorUserIds:s,customType:i}),[2,this.updateChannel(n)]}))}))},o.prototype.delete=function(){return n(this,void 0,void 0,(function(){var e,n;return t(this,(function(t){switch(t.label){case 0:return e=R.of(this._iid).requestQueue,n=new Oe({channelUrl:this.url}),[4,e.send(n)];case 1:return t.sent(),[4,Pe.of(this._iid).removeChannelsFromCache([this.url])];case 2:return t.sent(),[2]}}))}))},o.prototype.updateUserMessage=function(e,a){return n(this,void 0,void 0,(function(){var n,s,i,o=this;return t(this,(function(t){switch(t.label){case 0:return[4,r.prototype.updateUserMessage.call(this,e,a)];case 1:return n=t.sent(),s=!1,i=!1,this.lastPinnedMessage&&this.lastPinnedMessage.messageId===n.messageId&&(this.lastPinnedMessage=n,s=!0,i=!0),s&&Pe.of(this._iid).handlers.map((function(e){e.onChannelChanged&&e.onChannelChanged(o)})),i&&Pe.of(this._iid).handlers.map((function(e){e.onPinnedMessageUpdated&&e.onPinnedMessageUpdated(o)})),[2,n]}}))}))},o.prototype.updateFileMessage=function(e,a){return n(this,void 0,void 0,(function(){var n,s,i,o=this;return t(this,(function(t){switch(t.label){case 0:return[4,r.prototype.updateFileMessage.call(this,e,a)];case 1:return n=t.sent(),s=!1,i=!1,this.lastPinnedMessage&&this.lastPinnedMessage.messageId===n.messageId&&(this.lastPinnedMessage=n,s=!0,i=!0),s&&Pe.of(this._iid).handlers.map((function(e){e.onChannelChanged&&e.onChannelChanged(o)})),i&&Pe.of(this._iid).handlers.map((function(e){e.onPinnedMessageUpdated&&e.onPinnedMessageUpdated(o)})),[2,n]}}))}))},o}(J),Ae=function(n){function t(e){void 0===e&&(e={});var t=n.call(this)||this;return Object.keys(e).forEach((function(n){t.hasOwnProperty(n)&&(t[n]=e[n])})),t}return e(t,n),t}(function(n){function t(){var e=null!==n&&n.apply(this,arguments)||this;return e.onUserEntered=U,e.onUserExited=U,e.onChannelParticipantCountChanged=U,e.onPollUpdated=U,e.onPollVoted=U,e.onPollDeleted=U,e.onPinnedMessageUpdated=U,e}return e(t,n),t}(fe)),Le=function(n){function t(e){var t=this,r=e.token,a=e.limit,s=e.nameKeyword,i=e.urlKeyword,u=e.customTypes,c=e.includeFrozen,h=e.includeMetaData;return(t=n.call(this)||this).method=o.GET,t.path=l,t.params=d({token:r,limit:a,name_contains:s,url_contains:i,custom_types:u,show_frozen:c,show_metadata:h,show_pinned_messages:!0}),t}return e(t,n),t}(c),Re=function(n){function t(e,t){var r=n.call(this,e,t)||this;r.channels=[];var a=t.next,s=t.channels,i=t.ts;return r.token=a,s&&s.length>0&&(r.channels=s.map((function(n){return new xe(e,n)}))),r.ts="number"==typeof i?i:null,r}return e(t,n),t}(h),Fe=function(r){function i(e,n){var t,a,s,i,o,u=this;return(u=r.call(this,e,n)||this).includeFrozen=!0,u.includeMetaData=!0,u.nameKeyword=null,u.urlKeyword=null,u.customTypes=null,u.includeFrozen=null===(t=n.includeFrozen)||void 0===t||t,u.includeMetaData=null===(a=n.includeMetaData)||void 0===a||a,u.nameKeyword=null!==(s=n.nameKeyword)&&void 0!==s?s:null,u.urlKeyword=null!==(i=n.urlKeyword)&&void 0!==i?i:null,u.customTypes=null!==(o=n.customTypes)&&void 0!==o?o:null,u}return e(i,r),i.prototype._validate=function(){return r.prototype._validate.call(this)&&s("boolean",this.includeFrozen)&&s("boolean",this.includeMetaData)&&s("string",this.nameKeyword,!0)&&s("string",this.urlKeyword,!0)&&a("string",this.customTypes,!0)},i.prototype.next=function(){return n(this,void 0,void 0,(function(){var e,n,r,a,s,i;return t(this,(function(t){switch(t.label){case 0:return this._validate()?this._isLoading?[3,4]:this._hasNext?(this._isLoading=!0,e=R.of(this._iid).requestQueue,n=new Le(p(y(y({},this),{token:this._token}))),[4,e.send(n)]):[3,3]:[3,6];case 1:return r=t.sent(),a=r.as(Re),s=a.channels,i=a.token,this._token=i,this._hasNext=!!i,[4,Pe.of(this._iid).upsertChannelsToCache(s)];case 2:return t.sent(),this._isLoading=!1,[2,s];case 3:return[2,[]];case 4:throw x.queryInProgress;case 5:return[3,7];case 6:throw x.invalidParameters;case 7:return[2]}}))}))},i}(k),ke=function(r){function a(){var e=null!==r&&r.apply(this,arguments)||this;return e.name="openChannel",e}return e(a,r),a.prototype.init=function(e,n){var t=n.sdkState,a=n.dispatcher,s=n.sessionManager,i=n.requestQueue,o=n.logger,u=n.onlineDetector,l=n.cacheContext;r.prototype.init.call(this,e,{sdkState:t,dispatcher:a,sessionManager:s,requestQueue:i,logger:o,onlineDetector:u,cacheContext:l}),this._manager=new Pe(e,{sdkState:t,dispatcher:a,requestQueue:i,logger:o,cacheContext:l,sessionManager:s})},a.prototype.createOpenChannelListQuery=function(e){return void 0===e&&(e={}),new Fe(this._iid,e)},a.prototype.addOpenChannelHandler=function(e,n){this._manager.addHandler(e,n)},a.prototype.removeOpenChannelHandler=function(e){this._manager.removeHandler(e)},a.prototype.removeAllOpenChannelHandlers=function(){this._manager.clearHandler()},a.prototype.buildOpenChannelFromSerializedData=function(e){return this._manager.buildOpenChannelFromSerializedData(e)},a.prototype.getChannel=function(e){return n(this,void 0,void 0,(function(){return t(this,(function(n){return[2,this._manager.getChannel(e)]}))}))},a.prototype.getChannelWithoutCache=function(e){return n(this,void 0,void 0,(function(){return t(this,(function(n){return[2,this._manager.getChannelWithoutCache(e)]}))}))},a.prototype.createChannel=function(e){return void 0===e&&(e={}),n(this,void 0,void 0,(function(){return t(this,(function(n){return[2,this._manager.createChannel(e)]}))}))},a.prototype.createChannelWithOperatorUserIds=function(e,r,a,s,i){return n(this,void 0,void 0,(function(){var n;return t(this,(function(t){return(n=y({},ve)).name=e,n.coverUrlOrImage=r,n.data=a,n.operatorUserIds=s,n.customType=i,[2,this._manager.createChannel(n)]}))}))},a}(S);export{xe as OpenChannel,Ae as OpenChannelHandler,Fe as OpenChannelListQuery,ke as OpenChannelModule,De as ParticipantListQuery};