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.98 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self)["liteChatMessage-enhancer"]=n()}(this,(function(){"use strict";function e(e,n,t,s){return new(t||(t=Promise))((function(i,o){function r(e){try{c(s.next(e))}catch(e){o(e)}}function a(e){try{c(s.throw(e))}catch(e){o(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(r,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,o="openim.getmsg",r=t.helper.generateProtocolData({servcmd:o,data:{Cookie:e,SyncFlag:s,IsOnlineSync:i,NeedAbstract:1,NeedSignaling:1,NeedCachedMsg:1}}),a=`${r.head.seq}${o}`;try{const e=yield t.channel.sendPacket(r,{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,o;const r=function(e,n){const{From_Account:t,From_AccountHeadurl:s,From_AccountNick:i,IsNeedReadReceipt:o,MsgBody:r,MsgClientTime:a,MsgRandom:c,MsgSeq:u,MsgTimeStamp:d,SendMsgControl:l,SupportMessageExtension:g,To_Account:h,TinyId:_,MsgCheckResult:v,CloudCustomData:S,IsPeerRead:f,MsgFlagBits:E,MsgVersion:M,EventArray:p}=e;return{from:t,avatar:s,nick:i,needReadReceipt:1===o,readReceiptSentByPeer:f,clientTime:a,messageFlagBits:E,random:c,sequence:u,time:d,messageControlInfo:l,isSupportExtension:g,to:h,tinyID:_,checkResult:v,cloudCustomData:S,messageVersion:M,eventArray:p,elements:n.message.messageHelper.parseServerPushMessageElement(r)}}(e,n);if(10===(null===(o=null===(i=null==r?void 0:r.eventArray)||void 0===i?void 0:i[0])||void 0===o?void 0:o.Event))s.push(r);else{const e=n.message.messageFactory.createMessage(Object.assign(Object.assign({},r),{conversationType:"C2C"})),{elements:s}=r;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:o=[]}=n;s=(null==n?void 0:n.cookie)||"",e=null==n?void 0:n.syncFlag,this._parseAndSaveUnreadMessageList(i),this._saveUnreadNoticeList(o)}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:o,unreadNoticeList:r,cookie:a}=t;return this._parseAndSaveUnreadMessageList(o),{syncFlag:i,cookie:a,unreadMessageList:o,unreadNoticeList:r}}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()}};return console.log("message-enhancer"),function(e){i.install(e)}})); //# sourceMappingURL=message-enhancer.js.map