@tencentcloud/lite-chat
Version:
Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut
2 lines (1 loc) • 21.5 kB
JavaScript
function e(e,t,s,n){return new(s||(s=Promise))((function(o,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function r(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,r)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="C2C",s="GROUP",n="TOPIC",o="@TIM#SYSTEM",i="AVChatRoom",a="Room",r="Live",l="TIMTextElem",u="TIMImageElem",d="TIMSoundElem",c="TIMFileElem",g="TIMFaceElem",p="TIMVideoFileElem",v="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",C="TIMCustomElem",_="TIMRelayElem",M="AcceptAndNotify",y="AcceptNotNotify",f="Discard",T="AcceptNotNotifyExceptAt";var I,L,S;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(I||(I={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(L||(L={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(S||(S={}));const E=e=>void 0===e,D=e=>"string"==typeof e,O=e=>"function"==typeof Array.isArray?Array.isArray(e):"array"===(e=>{var t;return null===(t=Object.prototype.toString.call(e).match(/^\[object (.*)\]$/))||void 0===t?void 0:t[1].toLowerCase()})(e),R=e=>O(e)||(e=>null!==e&&"object"==typeof e)(e),k=(e,t,s,n)=>{if(!R(e)||!R(t))return 0;let o=0;const i=Object.keys(t);let a;for(let r=0,l=i.length;r<l;r++)if(a=i[r],!(E(t[a])||s&&s.includes(a)))if(R(e[a])&&R(t[a]))o+=k(e[a],t[a],s,n);else{if(n&&n.includes(t[a]))continue;e[a]!==t[a]&&(e[a]=t[a],o+=1)}return o},P=(e,t)=>{if(E(t))return"";switch(e){case l:return t.text||"";case u:return"[Image]";case v:return"[Location]";case d:return"[Voice]";case p:return"[Video]";case c:return"[File]";case C:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case g:return"[Animated Sticker]";case _:return"[Chat Record]";default:return""}},G=e=>({lastTime:(null==e?void 0:e.time)||(null==e?void 0:e.lastTime)||0,lastSequence:(null==e?void 0:e.sequence)||(null==e?void 0:e.lastSequence)||0,fromAccount:(null==e?void 0:e.from)||(null==e?void 0:e.fromAccount)||"",messageForShow:P(null==e?void 0:e.type,null==e?void 0:e.payload),payload:(null==e?void 0:e.payload)||null,type:(null==e?void 0:e.type)||"",isRevoked:(null==e?void 0:e.isRevoked)||!1,cloudCustomData:(null==e?void 0:e.cloudCustomData)||"",onlineOnlyFlag:(null==e?void 0:e._onlineOnlyFlag)||!1,nick:(null==e?void 0:e.nick)||"",nameCard:(null==e?void 0:e.nameCard)||"",version:(null==e?void 0:e.version)||0,isPeerRead:(null==e?void 0:e.isPeerRead)||!1,revoker:(null==e?void 0:e.revoker)||null});function N(e){const t=[];if(!D(e))return t;const s=e.length;if(0===s)return t;for(let n=s-1;n>=0;n--)"1"===e[n]&&t.push(2**(s-n-1));return t}class U{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=G(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark="",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){E(this.userProfile)&&this.type===t?this.userProfile={}:E(this.groupProfile)&&this.type===s&&(this.groupProfile={}),this.subType&&this.type===s&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){const{nextUnreadCount:o,isFromGetConversations:a,isUnreadC2CMessage:r}=e;E(o)||(this.subType!==i?a&&this.type===s||a&&this.type===n||r&&this.type===t?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=G(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(e){const{sequence:n,time:o}=e;return this.type===t&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}}var A=new class{constructor(){this._name="ConversationFactory",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0,this._pagingConvIDMap=new Map,this._convMap=new Map,this._convTotalUnreadCount=0}install(e){this._core=e;const{notificationCenter:t,InnerEvent:s,helper:n}=e;n.registerApi("getConversationList",this),n.registerApi("getConversationProfile",this),n.registerApi("setMessageRead",this),n.registerApi("getTotalUnreadMessageCount",this),n.registerApi("setConversationDraft",this),t.subscribeInnerEvent(s.RE_LOGIN,this._recoverConversations,this),t.subscribeInnerEvent(s.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(s.NEW_MESSAGE,this._handleNewMessage,this),t.subscribeInnerEvent(s.MESSAGE_DELETED,this._handleMessageDeleted,this),t.subscribeInnerEvent(s.MESSAGE_REVOKED,this._handleMessageRevoked,this),t.subscribeInnerEvent(s.MESSAGE_MODIFIED,this._handleMessageModified,this),t.subscribeInnerEvent(s.DESTROY,this._dispose,this),console.log(`${this._name}.install`)}handleLoginSuccess(){this.syncConvList()}_handleNewMessage(e){const{conversationOptionsList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e;if(console.log(`${this._name}._handleNewMessage, conversationOptionsList length:`,t.length),0===t.length)return;this._updateLocalConvList({conversationOptionsList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConvNeedShow(e.conversationID))).length>0&&this._onConversationListUpdate()}_handleMessageDeleted(e){var s,n,o,i;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const a=(null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(a.length||0)-1;e>=0;e--)if(!a[e].isDeleted){r=a[e];break}const l=this._convMap.get(e);if(!l)return;let u=!1;l.lastMessage.lastSequence===r.sequence&&l.lastMessage.lastTime===r.time||((null===(i=null===(o=this._core)||void 0===o?void 0:o.helper)||void 0===i?void 0:i.isEmpty(r))&&(r=void 0),l.updateLastMessage(r),u=!0),e.startsWith(t)&&this._updateUnreadCount(e),u&&(this._onConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. \n update conversationID:${e} with lastMessage:`,l.lastMessage))}_handleMessageRevoked(e){console.log(`${this._name}._handleMessageRevoked`,JSON.stringify(e));const{messageList:t=[],updateUnreadCount:s=!0}=e;if(0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this._convMap.get(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))})),o&&this._onConversationListUpdate()}_handleMessageModified(e){var t,s;console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:n,message:o}=e,i=this._convMap.get(n);if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(i))return;const{lastMessage:a}=i;a&&a.lastTime===o.time&&a.lastSequence===o.sequence&&a.version!==o.version&&(a.type=o.type,a.payload=o.payload,a.messageForShow=P(o.type,o.payload),a.cloudCustomData=o.cloudCustomData,a.version=o.version,this._onConversationListUpdate(),console.log(`${this._name} conversationID:${n} lastMessage updated`))}syncConvList(){return e(this,arguments,void 0,(function*(e=!0){yield this._pagingGetConvList(e),this._pagingStatus=I.RESOLVED,this._onConversationListUpdate()}))}_pagingGetConvList(t){return e(this,void 0,void 0,(function*(){try{this._pagingStatus=I.PENDING;const s=yield function(t,s){return e(this,void 0,void 0,(function*(){const{pagingTimeStamp:e,pagingStartIndex:n,pagingPinnedTimeStamp:o,pagingPinnedStartIndex:i}=t;try{const t="recentcontact.page_get",a=null==s?void 0:s.helper.generateProtocolData({servcmd:t,data:{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:null==s?void 0:s.store.get("login").userId,StartIndex:n,TimeStamp:e,TopStartIndex:i,TopTimeStamp:o}}),r=`${a.head.seq}${t}`;return yield s.channel.sendPacket(a,{requestId:r})}catch(e){throw console.warn(`ConversationService.pagingGetConvList error: ${e}`),e}}))}({pagingTimeStamp:t?this._pagingTimeStamp:0,pagingStartIndex:t?this._pagingStartIndex:0,pagingPinnedTimeStamp:t?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:t?this._pagingPinnedStartIndex:0},this._core);if(s){const{CompleteFlag:e,SessionItem:n=[],TimeStamp:o,StartIndex:i,TopTimeStamp:a,TopStartIndex:r}=s;if(n.length>0){const e=this._getConvOptions(n);this._pagingConvIDMap=new Map([...this._pagingConvIDMap,...e.map((e=>[e.conversationID,1]))]),this._updateLocalConvList({conversationOptionsList:e,isFromGetConversations:!0,updateUnreadCount:!0}),this._onConversationListUpdate()}this._pagingTimeStamp=o,this._pagingStartIndex=i,this._pagingPinnedTimeStamp=a,this._pagingPinnedStartIndex=r,1!==e&&this._pagingGetConvList(t)}}catch(e){throw console.error(`${this._name}._pagingGetConvList fail:`,e),e}}))}_getConvOptions(e){const n=this._convertConvKey(e).filter((({type:e,userID:t})=>1===e&&!this._isNonExistentAccount(t)||2===e)),o=this._core.store.get("login").userId;return n.map((e=>{var n,i,a,r,l,u,d,c,g,p,v,h;if(E(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===L.C2C){const s={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},p=null===(a=null===(i=null===(n=this._core)||void 0===n?void 0:n.user)||void 0===i?void 0:i.userProfile)||void 0===a?void 0:a.createProfile(e.userID,[s]);return{conversationID:`${t}${e.userID}`,type:t,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(r=e.lastMsg)||void 0===r?void 0:r.elements[0])?null===(l=e.lastMsg)||void 0===l?void 0:l.elements[0].type:null,payload:(null===(u=e.lastMsg)||void 0===u?void 0:u.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(d=e.lastMsg)||void 0===d?void 0:d.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:e.lastC2CMsgFromAccount===o&&e.time<=e.c2cPeerReadTime,revoker:(null===(g=null===(c=e.lastMsg)||void 0===c?void 0:c.revokerInfo)||void 0===g?void 0:g.revoker)||null},unreadCount:0,userProfile:p,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}return{conversationID:`${s}${e.groupID}`,type:s,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(p=e.lastMsg)||void 0===p?void 0:p.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(h=null===(v=e.lastMsg)||void 0===v?void 0:v.revokerInfo)||void 0===h?void 0:h.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}))}_convertConvKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,s,n,o;if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(e))return null;let i="",a=null;return e.MsgBody&&(i=null===(n=e.MsgBody[0])||void 0===n?void 0:n.MsgType,a=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:a,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var s;if(!t)return t;const n=this._core.message.messageFactory.getElementClass(e);return n?null===(s=n.parseServerPushElement(t))||void 0===s?void 0:s.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(s[n[o]]=e[n[o]])}return s}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){let t="";return 0===e?t=M:1===e?t=f:2===e?t=y:3===e&&(t=T),t}_patchTypeAndPayload(e){const{event:t,elements:s=[]}=e.lastMsg||{};return E(t)?{type:s[0]?s[0].type:null,payload:s[0]?this._amendLayersOverLimitProp(s[0].content):null}:{type:h,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:s=0}=e,n=t-s;return n>0?n:0}_updateLocalConvList(e){const{newConvList:t}=this._getTmpConvListMapping(e);this._convMap=new Map(this._sortConvList([...this._convMap])),this._core.store.set("conversation",{conversationMap:this._convMap}),console.log(`${this._name}._updateLocalConvList newConvList: ${t.length}`)}_getTmpConvListMapping(e){const{conversationOptionsList:n,isFromGetConversations:o,isInstantMessage:i,isUnreadC2CMessage:a=!1,updateUnreadCount:r}=e,l=[],u=null==n?void 0:n.length;for(let e=0;e<u;e++){const u=new U(n[e]),{conversationID:d,type:c}=u;if(!this._isNonExistentAccount(d))if(this._convMap.has(d)){const l=this._convMap.get(d);if(o){this._convMap.set(d,u),c===t?u.unreadCount=l.unreadCount:c===s&&(u.groupProfile=JSON.parse(JSON.stringify(l.groupProfile)));continue}this._mergeConversationInfo({conversationID:d,tmpConversation:u,lastMessage:n[e].lastMessage,isFromGetConversations:o,isInstantMessage:i}),this._patchLastMessage({conversationID:d,lastMessage:n[e].lastMessage,isInstantMessage:i}),!0===r&&(null==l||l.updateUnreadCount({nextUnreadCount:u.unreadCount,isFromGetConversations:o,isUnreadC2CMessage:a}))}else l.push(u),this._convMap.set(d,u)}return{newConvList:l}}_isNonExistentAccount(e){let s;return e.startsWith(t)&&(s=e.replace(t,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}_mergeConversationInfo(e){var t,s;const{conversationID:n,tmpConversation:o,lastMessage:i,isFromGetConversations:a,isInstantMessage:r}=e,l=this._convMap.get(n),u=["unreadCount","allowType","adminForbidType","payload"];!1===r&&u.push("lastMessage"),a&&u.push("isPinned"),E(r)&&i&&null===(null==l?void 0:l.lastMessage.payload)&&(l.lastMessage.payload=i.payload),(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(null==l?void 0:l.lastMessage.revoker))||(l.lastMessage.revoker=null);k(l,o,u,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{conversationID:t,lastMessage:n,isInstantMessage:o}=e,i=this._convMap.get(t);if(i&&n){const{payload:e,nameCard:t,nick:a,cloudCustomData:r=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===s&&(i.lastMessage.nameCard=t,i.lastMessage.nick=a)),i.lastMessage.cloudCustomData!==r&&(i.lastMessage.cloudCustomData=r)}}_sortConvList(e){const t=[],s=[],n=[],o=[];return e.forEach((e=>{var i,a,r,l;!0===e[1].isPinned?(null===(a=null===(i=this._core)||void 0===i?void 0:i.helper)||void 0===a?void 0:a.isEmpty(e[1].lastMessage.lastTime))?s.push(e):t.push(e):(null===(l=null===(r=this._core)||void 0===r?void 0:r.helper)||void 0===l?void 0:l.isEmpty(e[1].lastMessage.lastTime))?o.push(e):n.push(e)})),t.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(o)}_getLocalConvList(){return[...this._convMap.values()].filter((e=>this._isConvNeedShow(e.conversationID)))}_isConvNeedShow(e){const t=this._getLocalConversation(e);if(E(t))return!0;const o=t.type===n,i=t.type===s&&t.subType===a,l=t.type===s&&t.subType===r;return!(o||i||l)}_getLocalConversation(e){return this._convMap.get(e)}_updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this._getLocalConversation(e),a=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const r=i.unreadCount,l=null==a?void 0:a.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return r!==l&&(i.unreadCount=l,o=!0,console.log(`${this._name}._updateUnreadCount\n from ${r} to ${l}, conversationID:${e}`),!0===t&&this._onConversationListUpdate()),o}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}_onConversationListUpdate(){var e;const t=this._getLocalConvList();this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.CONVERSATION_LIST_UPDATED,data:t}),this._onTotalUnreadCountUpdate()}_onTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._convTotalUnreadCount!==t&&(console.log(`${this._name}._onTotalUnreadCountUpdate from ${this._convTotalUnreadCount} to ${t}`),this._convTotalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}getConversationList(t){return e(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(t),isSyncCompleted:this._isSyncCompleted()}}}))}_getConversationList(e){if(E(e))return this._getLocalConvList();if(O(e)){if(0===e.length)return[];return this._getLocalConvList().filter((t=>e.includes(t.conversationID)))}if((e=>{if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let s=t;for(;null!==Object.getPrototypeOf(s);)s=Object.getPrototypeOf(s);return t===s})(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return this._getLocalConvList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_isSyncCompleted(){return this._pagingStatus===I.RESOLVED}_filterType(e,n){return n!==t&&n!==s||e.type===n}_filterGroupName(e,t){return!D(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){return null===(s=t)||!("number"==typeof s&&!Number.isNaN(s-0)||"object"==typeof s&&s.constructor===Number)||(0===t?0===e.markList.length:e.markList.includes(t));var s}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_recoverConversations(){return e(this,void 0,void 0,(function*(){try{yield this.syncConvList(),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.RECOVER_CONVERSATIONS_COMPLETED)}catch(e){console.debug(e)}}))}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}getConversationProfile(n){return e(this,void 0,void 0,(function*(){let e;return this._convMap.has(n)?e=this._convMap.get(n):(e=new U({conversationID:n}),(e=>D(e)&&e.slice(0,3)===t)(n)?(e.type=t,e.userProfile={userID:n.replace(t,"")}):(e.type=s,e.groupProfile={groupID:n.replace(s,"")}),this._convMap.set(n,e)),{code:0,data:{conversation:e}}}))}setMessageRead(t){return e(this,void 0,void 0,(function*(){console.log(`${this._name}.setMessageRead ok, ${JSON.stringify(t)}`)}))}setConversationDraft(t){return e(this,void 0,void 0,(function*(){return console.log(`${this._name}.setConversationDraft , ${JSON.stringify(t)}`),{code:0,data:{conversation:{}}}}))}getTotalUnreadMessageCount(){const e=this._getLocalConvList();let t=0;return e.forEach((e=>{e.type!==o&&(""!==e.messageRemindType&&e.messageRemindType!==M||(t+=e.unreadCount))})),t}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.RE_LOGIN,this._recoverConversations,this),e.unSubscribeInnerEvent(t.LOGIN,this.handleLoginSuccess,this),e.unSubscribeInnerEvent(t.NEW_MESSAGE,this._handleNewMessage,this),e.unSubscribeInnerEvent(t.MESSAGE_DELETED,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(t.MESSAGE_REVOKED,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(t.MESSAGE_MODIFIED,this._handleMessageModified,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const b={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0},F={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!e.startsWith("C2C")&&!e.startsWith("GROUP"))||"conversationID is invalid."}]};var x={install:function(e){A.install(e),e.helper.registerValidateConfig({auth:b,params:F})},handleLoginSuccess:function(){A.handleLoginSuccess()}};export{x as default};