UNPKG

pope-test-lite-chat-api

Version:

Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut

3 lines (2 loc) 4.74 kB
function e(e,n,t,s){return new(t||(t=Promise))((function(i,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(o,a)}c((s=s.apply(e,n||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;var n,t;!function(e){e[e.START_SYNC=0]="START_SYNC",e[e.SYNCING=1]="SYNCING",e[e.SYNC_COMPLETE=2]="SYNC_COMPLETE"}(n||(n={})),function(e){e[e.LOGIN_SUCCESS=0]="LOGIN_SUCCESS",e[e.SEND_MESSAGE=1]="SEND_MESSAGE"}(t||(t={}));function s(n,t){return e(this,void 0,void 0,(function*(){const{cookie:e,syncFlag:s,syncTriggerEvent:i}=n,r="openim.getmsg",o=t.helper.generateProtocolData({servcmd:r,data:{Cookie:e,SyncFlag:s,IsOnlineSync:i,NeedAbstract:1,NeedSignaling:1,NeedCachedMsg:1}}),a=`${o.head.seq}${r}`;try{const e=yield t.channel.sendPacket(o,{requestId:a});if(!e)return null;const{unreadMessageList:n,unreadNoticeList:s}=function(e,n){const t=[],s=[];return null==e||e.forEach((e=>{var i,r;const o=function(e,n){const{From_Account:t,From_AccountHeadurl:s,From_AccountNick:i,IsNeedReadReceipt:r,MsgBody:o,MsgClientTime:a,MsgRandom:c,MsgSeq:u,MsgTimeStamp:d,SendMsgControl:l,SupportMessageExtension:g,To_Account:h,TinyId:_,MsgCheckResult:v,CloudCustomData:S,IsPeerRead:E,MsgFlagBits:M,MsgVersion:f,EventArray:C}=e;return{from:t,avatar:s,nick:i,needReadReceipt:1===r,readReceiptSentByPeer:E,clientTime:a,messageFlagBits:M,random:c,sequence:u,time:d,messageControlInfo:l,isSupportExtension:g,to:h,tinyID:_,checkResult:v,cloudCustomData:S,messageVersion:f,eventArray:C,elements:n.message.messageHelper.parseServerPushMessageElement(o)}}(e,n);if(10===(null===(r=null===(i=null==o?void 0:o.eventArray)||void 0===i?void 0:i[0])||void 0===r?void 0:r.Event))s.push(o);else{const e=n.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:"C2C"})),{elements:s}=o;e.setElement(s),t.push(e)}})),{unreadMessageList:t,unreadNoticeList:s}}(e.MsgList,t);return{syncFlag:null==e?void 0:e.SyncFlag,unreadMessageList:n,unreadNoticeList:s,cookie:null==e?void 0:e.Cookie}}catch(e){console.warn(e)}}))}var i=new class{constructor(){this._unreadDBMessageMap=new Map,this._unreadDBNoticeList=[]}install(e){this._core=e,e.notificationCenter.subscribeInnerEvent(e.InnerEvent.LOGIN,this._syncUnreadDBMessageAfterLogin,this),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.RE_LOGIN,this._syncUnreadDBMessageAfterLogin,this),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.LOGOUT,this._reset,this),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.DESTROY,this._dispose,this)}_syncUnreadDBMessageAfterLogin(){return e(this,void 0,void 0,(function*(){let e=n.START_SYNC,s="";for(;this._canContinueSync({cookie:s,syncFlag:e});){const n=yield this._fetchUnreadDBMessage({cookie:s,syncFlag:e,syncTriggerEvent:t.LOGIN_SUCCESS});if(!n)break;const{unreadMessageList:i=[],unreadNoticeList:r=[]}=n;s=(null==n?void 0:n.cookie)||"",e=null==n?void 0:n.syncFlag,this._parseAndSaveUnreadMessageList(i),this._saveUnreadNoticeList(r)}this._emitUnreadMessageSyncComplete()}))}_emitUnreadMessageSyncComplete(){var e;null===(e=this._core)||void 0===e||e.notificationCenter.emitInnerEvent(this._core.InnerEvent.UNREAD_MESSAGES_SYNC_COMPLETED,{unreadNoticeList:this._unreadDBNoticeList,unreadMessageMap:this._unreadDBMessageMap})}_saveUnreadNoticeList(e){this._unreadDBNoticeList=[...this._unreadDBNoticeList,...e]}_fetchUnreadDBMessage(n){return e(this,void 0,void 0,(function*(){try{const e="unread-message._fetchUnreadDBMessage";console.log(`${e} options:`,n);const t=yield s(n,this._core);if(!t)return null;const{syncFlag:i,unreadMessageList:r,unreadNoticeList:o,cookie:a}=t;return this._parseAndSaveUnreadMessageList(r),{syncFlag:i,cookie:a,unreadMessageList:r,unreadNoticeList:o}}catch(e){console.log(e)}}))}_canContinueSync({cookie:e,syncFlag:t}){var s;return t===n.START_SYNC||t===n.SYNCING&&!(null===(s=this._core)||void 0===s?void 0:s.helper.isEmpty(e))}_parseAndSaveUnreadMessageList(e){e.forEach((e=>{const{ID:n}=e;this._unreadDBMessageMap.set(n,e)}))}_reset(){this._unreadDBMessageMap.clear(),this._unreadDBNoticeList=[]}_dispose(){var e,n,t;null===(e=this._core)||void 0===e||e.notificationCenter.unSubscribeInnerEvent(this._core.InnerEvent.LOGIN,this._syncUnreadDBMessageAfterLogin,this),null===(n=this._core)||void 0===n||n.notificationCenter.unSubscribeInnerEvent(this._core.InnerEvent.LOGOUT,this._reset,this),null===(t=this._core)||void 0===t||t.notificationCenter.unSubscribeInnerEvent(this._core.InnerEvent.DESTROY,this._dispose,this),this._reset()}};function r(e){i.install(e)}console.log("message-enhancer");export{r as default}; //# sourceMappingURL=message-enhancer.js.map