UNPKG

@sendbird/chat

Version:
2 lines (1 loc) 7.69 kB
import{c as e,bh as t,_ as n,b as s,ax as r,aS as i,K as a,M as o,w as u,D as c,aw as d,aa as h,aG as l,U as _,W as f,E as g}from"./__bundle-d4c97ab8.js";import{w as p,T as A}from"./__bundle-4450f15b.js";var E,C,b;!function(e){e.LATEST_LAST_MESSAGE="latest_last_message",e.CHRONOLOGICAL="chronological",e.CHANNEL_NAME_ALPHABETICAL="channel_name_alphabetical",e.METADATA_VALUE_ALPHABETICAL="metadata_value_alphabetical"}(E||(E={})),function(e){e.CHRONOLOGICAL="chronological",e.CHANNEL_NAME_ALPHABETICAL="channel_name_alphabetical",e.METADATA_VALUE_ALPHABETICAL="metadata_value_alphabetical"}(C||(C={})),function(e){e.CREATED_AT="created_at",e.SCHEDULED_AT="scheduled_at"}(b||(b={}));var R,L=function(e){switch(e){case E.LATEST_LAST_MESSAGE:return["-lastMessageUpdatedAt","-createdAt","syncIndex"];case E.CHRONOLOGICAL:return["-createdAt","syncIndex"];case E.CHANNEL_NAME_ALPHABETICAL:return["name"];default:return["-lastMessageUpdatedAt","-createdAt","syncIndex"]}},y=function(t){function n(e){var n=e.message,s=t.call(this)||this;return s.message=n,s}return e(n,t),n}(t),I={},N=function(){function e(e,t){var n=t.localCacheEnabled,s=t.enableAutoResend,r=t.dispatcher,i=t.sdkState,u=t.logger,c=this;this._iid=e,I[e]=this,this._localCacheEnabled=n,this._enableAutoResend=s,this._isProcessingAutoResend=!1,this._autoResendQueue=[],this._dispatcher=r,this._logger=u,this._sdkState=i,this._localCacheEnabled&&r.on((function(e){if(e instanceof a)switch(e.stateType){case o.CONNECTED:c._isProcessingAutoResend||c.processAutoResendRegisteredPendingMessages().then((function(){return c._processNextAutoResend()}));break;case o.INTERNAL_DISCONNECTED:case o.EXTERNAL_DISCONNECTED:c._isProcessingAutoResend=!1}}))}return e.of=function(e){return I[e]},e.prototype.processNonAutoResendRegisteredPendingMessages=function(){return n(this,void 0,void 0,(function(){var e,t,n,i,a,o;return s(this,(function(s){switch(s.label){case 0:return this._enableAutoResend?[4,this._fetchAllCachedPendingMessages()]:[2];case 1:e=s.sent();try{for(t=u(e),n=t.next();!n.done;n=t.next())0===(i=n.value).errorCode&&(this._logger.debug("cached pending message is not auto-resend registered. changing its sending status to failed: ",i.reqId),i.sendingStatus=r.FAILED,i.errorCode=c.ACK_TIMEOUT,this._dispatcher.dispatch(new d({messages:[i],source:h.LOCAL_MESSAGE_FAILED})))}catch(e){a={error:e}}finally{try{n&&!n.done&&(o=t.return)&&o.call(t)}finally{if(a)throw a.error}}return[2]}}))}))},e.prototype.processAutoResendRegisteredPendingMessages=function(){return n(this,void 0,void 0,(function(){var e,t,n,a,o,c,l,_;return s(this,(function(s){switch(s.label){case 0:return[4,this._fetchAllCachedPendingMessages()];case 1:e=s.sent();try{for(t=u(e),n=t.next();!n.done;n=t.next())a=n.value,this._enableAutoResend&&a.errorCode&&i(a.errorCode)&&(o=(new Date).getTime(),c=a.createdAt+2592e5,this._enableAutoResend&&o<=c?this._autoResendQueue.map((function(e){return e.reqId})).indexOf(a.reqId)<0&&this._autoResendQueue.push(a):(this._logger.debug("auto-resend registered pending messaged expired. expiration date: ",new Date(c).toLocaleString()),a.sendingStatus=r.FAILED,this._dispatcher.dispatch(new d({messages:[a],source:h.LOCAL_MESSAGE_FAILED}))))}catch(e){l={error:e}}finally{try{n&&!n.done&&(_=t.return)&&_.call(t)}finally{if(l)throw l.error}}return[2]}}))}))},e.prototype.completeCurrentAndProcessNextAutoResend=function(e){if(this._localCacheEnabled&&this._enableAutoResend&&(e.sendingStatus===r.SUCCEEDED||e.sendingStatus===r.FAILED&&!i(e.errorCode))){var t=this.indexOf(e);t>=0&&this._autoResendQueue.splice(t,1),0===t&&this._processNextAutoResend()}},e.prototype._fetchAllCachedPendingMessages=function(){return n(this,void 0,void 0,(function(){var e,t;return s(this,(function(n){switch(n.label){case 0:return e=p.of(this._iid),(t=new A).replyType=l.ALL,[4,e.fetch({sendingStatus:r.PENDING,backward:!0,filter:t})];case 1:return[2,n.sent()]}}))}))},e.prototype.indexOf=function(e){return this._autoResendQueue.length>0?this._autoResendQueue.map((function(e){return e.reqId})).indexOf(e.reqId):-1},e.prototype._isNotInQueue=function(e){return-1===this._autoResendQueue.map((function(e){return e.reqId})).indexOf(e.reqId)},e.prototype._processNextAutoResend=function(){return n(this,void 0,void 0,(function(){var e;return s(this,(function(t){if(this._localCacheEnabled&&this._enableAutoResend&&"foreground"===this._sdkState.appState)try{this._autoResendQueue.length>0?(this._isProcessingAutoResend||(this._logger.debug("auto-resend queue started."),this._isProcessingAutoResend=!0),e=this._autoResendQueue[0],this._dispatcher.dispatch(new y({message:e})),this._logger.debug("processing auto-resend for message request id: ",e.reqId)):(this._logger.debug("auto-resend queue finished."),this._isProcessingAutoResend=!1)}catch(e){this._logger.warn("process auto-resend error: ",e),this._isProcessingAutoResend=!1}return[2]}))}))},e}();!function(e){e[e.USER_BLOCK=20001]="USER_BLOCK",e[e.USER_UNBLOCK=2e4]="USER_UNBLOCK",e[e.FRIEND_DISCOVERED=20900]="FRIEND_DISCOVERED"}(R||(R={}));var D,v=function(){function e(e){this.category=e.cat,this.data=e.data}return e.getDataAsUserBlockEvent=function(e,t){var n=t.data,s=n.blocker,r=n.blockee;return{blocker:new _(e,s),blockee:new _(e,r)}},e.getDataAsFriendDiscoveredEvent=function(e,t){var n=t.data.friend_discoveries;return{friendDiscoveries:Array.isArray(n)?n.map((function(t){return new _(e,t)})):[]}},e}(),S=function(t){function n(e,n){var s=n.userId,r=t.call(this)||this;return r._iid=e,r.userId=s,r}return e(n,t),n}(t),T=function(t){function n(){return t.call(this)||this}return e(n,t),n}(t),m=function(t){function n(e){var n=e.configTs,s=t.call(this)||this;return s.configTs=n,s}return e(n,t),n}(t),O=function(t){function n(e,n,s){var r=t.call(this,e,"USEV",s)||this;return r.event=new v(s),r}return e(n,t),n}(f),P=function(t){function n(e){var n=e.appConfigsInfo,s=e.configTs,r=t.call(this)||this;return r.appConfigsInfo={},r.configTs=0,r.appConfigsInfo=n,r.configTs=s,r}return e(n,t),n}(t);!function(e){e[e.IDLE=0]="IDLE",e[e.RUNNING=1]="RUNNING",e[e.END=2]="END"}(D||(D={}));var w=function(t){function r(e,n,s,r){var i=t.call(this)||this;return i._state=D.IDLE,i._retryCount=0,i._retryLimit=3,i.priority=0,i._worker=n,i}return e(r,t),Object.defineProperty(r.prototype,"isIdle",{get:function(){return this._state===D.IDLE},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this._state===D.RUNNING},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"isDone",{get:function(){return this._state===D.END},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"retryCount",{get:function(){return this._retryCount},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"retryLimit",{get:function(){return this._retryLimit},enumerable:!1,configurable:!0}),r.prototype._run=function(e){return n(this,void 0,void 0,(function(){var t,n;return s(this,(function(s){switch(s.label){case 0:if(!this.isRunning)return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this._worker(e)];case 2:return t=s.sent(),this._retryCount=0,this.dispatch("progress",t),t.hasNext?this._run(t.nextToken):this.end(),[3,4];case 3:return n=s.sent(),this.dispatch("error",n),this._retryCount<this._retryLimit?(this._retryCount++,this._run(e)):this.stop(),[3,4];case 4:return[2]}}))}))},r.prototype.start=function(e){this.isIdle&&(this._state=D.RUNNING,this._run(e))},r.prototype.stop=function(){this._state=D.IDLE,this.dispatch("stop")},r.prototype.end=function(){this._state=D.END,this.dispatch("end")},r}(g);export{N as A,S as D,E as G,C as P,T as R,m as S,O as U,R as a,v as b,w as c,P as d,b as e,y as f,L as g};