-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathopenChannel.js
1 lines (1 loc) · 30.8 KB
/
openChannel.js
1
import{c as e,_ as n,b as t,an as r,a1 as a,a as s,i,A as o,bu as u,bv as l,f as c,g as h,e as d,u as p,as as f,U as C,I as v,q as _,r as g,j as y,C as m,aI as U,W as E,a0 as M,K as w,M as P,w as b,N as D,V as T,aU as N,aa as I,b0 as H,bp as O,F as x,t as A,bq as R,aJ as L,aq as q,aW as F,b7 as k}from"./lib/__bundle-d4c97ab8.js";import{a6 as S,a7 as z,a8 as Q,aa as G,a9 as K,ab as W,ac as j,ad as V,ah as B,ai as X,ak as Y,al as Z,P as J,E as $,ax as ee,W as ne,ao as te}from"./lib/__bundle-4450f15b.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-6e9248cc.js";import{B as fe}from"./lib/__bundle-eb6fd75a.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,x,A,L,q,F,k,J,$,ee,ne,te,ae,fe,Ce,ve,_e,ge,ye,me,Ee,we,Pe,be,De,Te,Ne,Ie,He,Oe,xe,Ae,Re,Le,qe,Fe,ke,Se,ze,Qe,Ge,Ke,We,je,Ve,Be,Xe,Ye,Ze,Je,$e,en,nn,tn=this;return t(this,(function(rn){switch(rn.label){case 0:switch(rn.trys.push([0,62,,63]),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,61];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(),D((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,61];case 4:return i=null,"MEDI"===e.code?i=e.as(B):"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.of(this._iid).requestDeduplicator.updatePendingResponse(l,Date.now())),D((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,61];case 7:return h=e.as(O),te=h.channelUrl,ae=h.channelType,d=h.messageId,ae!==m.OPEN?[3,9]:[4,this.getChannel(te,!0)];case 8:p=rn.sent(),D((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,61];case 10:return f=e.as(he),te=f.channelUrl,ae=f.channelType,C=f.event,ae!==m.OPEN?[3,12]:[4,this.getChannel(te,!0)];case 11:v=rn.sent(),D((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,61];case 13:return(_=e.as(ce).event).channelType!==m.OPEN?[3,15]:[4,this.getChannel(_.channelUrl,!0)];case 14:g=rn.sent(),D((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,61];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,te=P.channelUrl,we=P.participantCount,x=P.updatedAt,[4,this.getChannelFromCache(te)]);case 19:(A=rn.sent())&&A._updateParticipantCount(we,x)&&U.push(A),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:q=rn.sent(),D((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(q)}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,61];case 27:return F=e.as(ue),k=F.event,J=F.status,te=F.channelUrl,ae=F.channelType,te&&ae===m.OPEN?[4,this.getChannel(te,!0)]:[3,29];case 28:$=rn.sent(),this._dispatcher.dispatch(new H({event:k,source:I.EVENT_POLL_UPDATED})),D(J===R?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,61];case 30:return ee=e.as(V),ne=ee.event,te=ee.channelUrl,ae=ee.channelType,te&&ae===m.OPEN?[4,this.getChannel(te,!0)]:[3,32];case 31:fe=rn.sent(),this._dispatcher.dispatch(new N({event:ne,source:I.EVENT_POLL_VOTED})),D((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(fe,ne)}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,61];case 33:if(!(Ce=e.as(re).event).isOpenChannelEvent)return[3,60];switch(Ce.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,41];case ie.USER_CHANNEL_BAN:case ie.USER_CHANNEL_UNBAN:return[3,43];case ie.CHANNEL_FREEZE:case ie.CHANNEL_UNFREEZE:return[3,45];case ie.CHANNEL_DELETED:return[3,48];case ie.CHANNEL_PROP_CHANGED:return[3,50];case ie.CHANNEL_META_DATA_CHANGED:return[3,52];case ie.CHANNEL_META_COUNTERS_CHANGED:return[3,54];case ie.PINNED_MESSAGE_CHANGED:return[3,56]}return[3,60];case 34:return[4,this.getChannel(Ce.channelUrl,!0)];case 35:return ve=rn.sent(),_e=e.as(Ue),we=_e.participantCount,ge=_e.user,ye=ve._updateParticipantCount(we,Ce.ts),T.of(this._iid).requestDeduplicator.updatePendingResponse(ve,Date.now()),D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onUserEntered&&e.onUserEntered(ve,ge),ye&&e.onChannelParticipantCountChanged&&e.onChannelParticipantCountChanged(ve)})),[2]}))}))})),[3,60];case 36:return[4,this.getChannel(Ce.channelUrl,!0)];case 37:return me=rn.sent(),Ee=e.as(Me),we=Ee.participantCount,Pe=Ee.user,be=me._updateParticipantCount(we,Ce.ts),T.of(this._iid).requestDeduplicator.updatePendingResponse(me,Date.now()),D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onUserExited&&e.onUserExited(me,Pe),be&&e.onChannelParticipantCountChanged&&e.onChannelParticipantCountChanged(me)})),[2]}))}))})),[3,60];case 38:return[4,this.getChannel(Ce.channelUrl,!0)];case 39:return De=rn.sent(),Te=e.as(oe).operators,De.operators=Te,T.of(this._iid).requestDeduplicator.updatePendingResponse(De,Date.now()),[4,this.upsertChannelsToCache([De])];case 40:return rn.sent(),D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onOperatorUpdated&&e.onOperatorUpdated(De,Te)})),[2]}))}))})),[3,60];case 41:return[4,this.getChannel(Ce.channelUrl,!0)];case 42:return Ne=rn.sent(),Ie=Ce.category===ie.USER_CHANNEL_MUTE,He=e.as(Ie?W:j).user,D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){Ie?e.onUserMuted&&e.onUserMuted(Ne,He):e.onUserUnmuted&&e.onUserUnmuted(Ne,He)})),[2]}))}))})),[3,60];case 43:return[4,this.getChannel(Ce.channelUrl,!0)];case 44:return Oe=rn.sent(),xe=Ce.category===ie.USER_CHANNEL_BAN,Ae=e.as(xe?G:K).user,D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){xe?e.onUserBanned&&e.onUserBanned(Oe,Ae):e.onUserUnbanned&&e.onUserUnbanned(Oe,Ae)})),[2]}))}))})),[3,60];case 45:return[4,this.getChannel(Ce.channelUrl,!0)];case 46:return Re=rn.sent(),Le=e.as(Q).freeze,Re.isFrozen=Le,T.of(this._iid).requestDeduplicator.updatePendingResponse(Re,Date.now()),[4,this.upsertChannelsToCache([Re])];case 47:return rn.sent(),D((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(Re):e.onChannelUnfrozen&&e.onChannelUnfrozen(Re)})),[2]}))}))})),[3,60];case 48:return[4,this.removeChannelsFromCache([Ce.channelUrl])];case 49:return rn.sent(),D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onChannelDeleted&&e.onChannelDeleted(Ce.channelUrl,m.OPEN)})),[2]}))}))})),[3,60];case 50:return[4,this.getChannelWithoutCache(Ce.channelUrl,!0,!1)];case 51:return qe=rn.sent(),D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onChannelChanged&&e.onChannelChanged(qe)})),[2]}))}))})),[3,60];case 52:return[4,this.getChannel(Ce.channelUrl,!0)];case 53:return Fe=rn.sent(),ke=e.as(z),Se=ke.created,ze=ke.updated,Qe=ke.deleted,Se&&Fe._upsertCachedMetaData(Se,Ce.ts),ze&&Fe._upsertCachedMetaData(ze,Ce.ts),Qe&&Fe._removeFromCachedMetaData(Qe,Ce.ts),(Se||ze||Qe)&&T.of(this._iid).requestDeduplicator.updatePendingResponse(Fe,Date.now()),D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){Se&&e.onMetaDataCreated&&e.onMetaDataCreated(Fe,Se),ze&&e.onMetaDataUpdated&&e.onMetaDataUpdated(Fe,ze),Qe&&e.onMetaDataDeleted&&e.onMetaDataDeleted(Fe,Qe)})),[2]}))}))})),[3,60];case 54:return[4,this.getChannel(Ce.channelUrl,!0)];case 55:return Ge=rn.sent(),Ke=e.as(S),We=Ke.created,je=Ke.updated,Ve=Ke.deleted,D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){We&&e.onMetaCounterCreated&&e.onMetaCounterCreated(Ge,We),je&&e.onMetaCounterUpdated&&e.onMetaCounterUpdated(Ge,je),Ve&&e.onMetaCounterDeleted&&e.onMetaCounterDeleted(Ge,Ve)})),[2]}))}))})),[3,60];case 56:return[4,this.getChannel(Ce.channelUrl,!0)];case 57:return Be=rn.sent(),Xe=e.as(se),Ye=Xe.pinnedMessageIds,Ze=Xe.latestPinnedMessage,(Je=Xe.ts)>Be._pinnedMessagesUpdatedAt?(Be.pinnedMessageIds=Ye,Be.lastPinnedMessage=Ze,Be._pinnedMessagesUpdatedAt=Je,T.of(this._iid).requestDeduplicator.updatePendingResponse(Be,Date.now()),[4,this.upsertChannelsToCache([Be])]):[3,59];case 58:rn.sent(),D((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(Be)}catch(e){a={error:e}}finally{try{n&&!n.done&&(s=e.return)&&s.call(e)}finally{if(a)throw a.error}}return[2]}))}))})),D((function(){return n(tn,void 0,void 0,(function(){return t(this,(function(e){return this._openChannelHandlers.forEach((function(e){e.onPinnedMessageUpdated&&e.onPinnedMessageUpdated(Be)})),[2]}))}))})),rn.label=59;case 59:return[3,60];case 60:return[3,61];case 61:return[3,63];case 62:if($e=rn.sent(),M($e))throw $e;return[3,63];case 63: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:x(s("string",e)).throw(A.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,a){return void 0===r&&(r=!1),void 0===a&&(a=!0),n(this,void 0,void 0,(function(){var n,i,o,u,l=this;return t(this,(function(t){switch(t.label){case 0:return x(s("string",e)).throw(A.invalidParameters),n=T.of(this._iid).requestDeduplicator,i=new _e({channelUrl:e,isInternalCall:r}),[4,n.requestGetChannel(i.path,(function(){return l._requestQueue.send(i)}),i.params,a)];case 1:return o=t.sent(),u=o.as(ge).channel,[4,this.upsertChannelsToCache([u])];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),x(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(A.invalidParameters),r=new ye(n),[4,this._requestQueue.send(r)];case 1:return o=t.sent(),u=o.as(ge).channel,[4,this.upsertChannelsToCache([u])];case 2:return t.sent(),[2,u]}}))}))},o}(ae),be={name:void 0,coverUrlOrImage:void 0,data:void 0,customType:void 0,operatorUserIds:void 0},De=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),Te=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 J(e,n)})),r}return e(t,n),t}(h),Ne=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=T.of(this._iid).requestQueue,n=new De(y(y({},this),{token:this._token})),[4,e.send(n)]):[3,2]:[3,5];case 1:return r=t.sent(),a=r.as(Te),s=a.participants,i=a.token,this._token=i,this._hasNext=!!i,this._isLoading=!1,[2,s];case 2:return[2,[]];case 3:throw A.queryInProgress;case 4:return[3,6];case 5:throw A.invalidParameters;case 6:return[2]}}))}))},a}(L),Ie=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),He=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,n){void 0===n&&(n=!1);var t=y(y({},$.payloadify(e,n)),{participant_count:e.participantCount,operators:e.operators.map((function(e){return C.payloadify(e)})),latest_pinned_message:e.lastPinnedMessage?ee(e.lastPinnedMessage):null});return n?t:d(p(t))},o.prototype.serialize=function(){return q(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 Ne(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=T.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=T.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),x(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(A.invalidParameters),r=T.of(this._iid).requestQueue,o=new Ie(y({channelUrl:this.url},n)),[4,r.send(o)];case 1:return u=t.sent(),l=u.as(He).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=T.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}($),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)),Re=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),Le=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),qe=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=T.of(this._iid).requestQueue,n=new Re(p(y(y({},this),{token:this._token}))),[4,e.send(n)]):[3,3]:[3,6];case 1:return r=t.sent(),a=r.as(Le),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 A.queryInProgress;case 5:return[3,7];case 6:throw A.invalidParameters;case 7:return[2]}}))}))},i}(F),Fe=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 qe(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}(k);export{xe as OpenChannel,Ae as OpenChannelHandler,qe as OpenChannelListQuery,Fe as OpenChannelModule,Ne as ParticipantListQuery};