@tencentcloud/lite-chat 1.1.1-beta.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencentcloud/lite-chat",
3
- "version": "1.1.1-beta.0",
3
+ "version": "1.1.1",
4
4
  "description": "Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut",
5
5
  "main": "index.js",
6
6
  "module": "index.es.js",
@@ -5,4 +5,4 @@ declare const conversationPlugin: {
5
5
  export default conversationPlugin;
6
6
  declare module '@tencentcloud/lite-chat/plugins/conversation' {
7
7
  export default conversationPlugin;
8
- }
8
+ }
@@ -1 +1 @@
1
- function e(e,t,n,s){return new(n||(n=Promise))((function(o,i){function a(e){try{l(s.next(e))}catch(e){i(e)}}function r(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="C2C",n="GROUP",s="TOPIC",o="@TIM#SYSTEM",i="AVChatRoom",a="Room",r="Live",l="TIMTextElem",c="TIMImageElem",u="TIMSoundElem",d="TIMFileElem",v="TIMFaceElem",p="TIMVideoFileElem",g="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",_="TIMCustomElem",C="TIMRelayElem",M="AcceptAndNotify",f="AcceptNotNotify",L="Discard",y="AcceptNotNotifyExceptAt";var I,D,T,E,S,O;!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"}(D||(D={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(T||(T={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(E||(E={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(S||(S={})),function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(O||(O={}));const P=e=>void 0===e,R=e=>"string"==typeof e,N=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),A=e=>null!==e&&"object"==typeof e,$=e=>N(e)||A(e),G=(e,t,n,s)=>{if(!$(e)||!$(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],!(P(t[a])||n&&n.includes(a)))if($(e[a])&&$(t[a]))o+=G(e[a],t[a],n,s);else{if(s&&s.includes(t[a]))continue;e[a]!==t[a]&&(e[a]=t[a],o+=1)}return o},U=e=>R(e)&&e.slice(0,3)===t,k=e=>R(e)&&e.slice(0,5)===n,b=e=>R(e)&&e===o,F=(e,t)=>{if(P(t))return"";switch(e){case l:return t.text||"";case c:return"[Image]";case g:return"[Location]";case u:return"[Voice]";case p:return"[Video]";case d:return"[File]";case _:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case v:return"[Animated Sticker]";case C:return"[Chat Record]";default:return""}},w=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:F(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 q(e){const t=[];if(!R(e))return t;const n=e.length;if(0===n)return t;for(let s=n-1;s>=0;s--)"1"===e[s]&&t.push(2**(n-s-1));return t}class x{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=w(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(){P(this.userProfile)&&this.type===t?this.userProfile={}:P(this.groupProfile)&&this.type===n&&(this.groupProfile={}),this.subType&&this.type===n&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){const{nextUnreadCount:o,isFromGetConversations:a,isUnreadC2CMessage:r}=e;P(o)||(this.subType!==i?a&&this.type===n||a&&this.type===s||r&&this.type===t?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=w(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(e){const{sequence:s,time:o}=e;return this.type===t&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}clearGroupAtInfoList(){this.groupAtInfoList.length=0}}var V=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}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s}=e;s.registerApi("getConversationList",this),s.registerApi("getConversationProfile",this),s.registerApi("getTotalUnreadMessageCount",this),t.subscribeInnerEvent(n.RE_LOGIN,this._recoverConversations,this),t.subscribeInnerEvent(n.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(n.NEW_MESSAGE,this._handleNewMessage,this),t.subscribeInnerEvent(n.MESSAGE_DELETED,this._handleMessageDeleted,this),t.subscribeInnerEvent(n.MESSAGE_REVOKED,this._handleMessageRevoked,this),t.subscribeInnerEvent(n.MESSAGE_MODIFIED,this._handleMessageModified,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}handleLoginSuccess(){this.syncConvList()}_handleNewMessage(e){const{conversationOptionsList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e;if(console.log(`${this._name}._handleNewMessage, conversationOptionsList length:`,t.length),0===t.length)return;this._updateLocalConvList({conversationOptionsList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConvNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleMessageDeleted(e){var n,s,o,i;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const a=(null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageStore)||void 0===s?void 0:s.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 c=!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),c=!0),e.startsWith(t)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),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:n=!0}=e;if(0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this._convMap.get(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){var t,n;console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:s,message:o}=e,i=this._convMap.get(s);if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.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=F(o.type,o.payload),a.cloudCustomData=o.cloudCustomData,a.version=o.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${s} lastMessage updated`))}syncConvList(){return e(this,arguments,void 0,(function*(e=!0){yield this._pagingGetConvList(e),this._pagingStatus=I.RESOLVED,this.emitConversationListUpdate()}))}_pagingGetConvList(t){return e(this,void 0,void 0,(function*(){var n;try{this._pagingStatus=I.PENDING;const s=yield function(t,n){return e(this,void 0,void 0,(function*(){const{fromAccount:e,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:a}=t,r="recentcontact.page_get",l=null==n?void 0:n.helper.generateProtocolData({servcmd:r,data:{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:e,StartIndex:o,TimeStamp:s,TopStartIndex:a,TopTimeStamp:i}}),c=`${l.head.seq}${r}`;return yield n.channel.sendPacket(l,{requestId:c})}))}({fromAccount:null===(n=this._core)||void 0===n?void 0:n.store.get("login").userId,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.emitConversationListUpdate()}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 s=this._convertConvKey(e).filter((({type:e,userID:t})=>1===e&&!this._isNonExistentAccount(t)||2===e)),o=this._core.store.get("login").userId;return s.map((e=>{var s,i,a,r,l,c,u,d,v,p,g,h;if(P(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===D.C2C){const n={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},p=null===(a=null===(i=null===(s=this._core)||void 0===s?void 0:s.user)||void 0===i?void 0:i.userProfile)||void 0===a?void 0:a.createProfile(e.userID,[n]);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===(c=e.lastMsg)||void 0===c?void 0:c.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(u=e.lastMsg)||void 0===u?void 0:u.cloudCustomData)||"",isRevoked:e.lastMessageFlag===T.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:e.lastC2CMsgFromAccount===o&&e.time<=e.c2cPeerReadTime,revoker:(null===(v=null===(d=e.lastMsg)||void 0===d?void 0:d.revokerInfo)||void 0===v?void 0:v.revoker)||null},unreadCount:0,userProfile:p,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:q(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}return{conversationID:`${n}${e.groupID}`,type:n,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===T.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(h=null===(g=e.lastMsg)||void 0===g?void 0:g.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:q(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,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",a=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.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 n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){let t="";return 0===e?t=M:1===e?t=L:2===e?t=f:3===e&&(t=y),t}_patchTypeAndPayload(e){const{event:t,elements:n=[]}=e.lastMsg||{};return P(t)?{type:n[0]?n[0].type:null,payload:n[0]?this._amendLayersOverLimitProp(n[0].content):null}:{type:h,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s: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:s,isFromGetConversations:o,isInstantMessage:i,isUnreadC2CMessage:a=!1,updateUnreadCount:r}=e,l=[],c=null==s?void 0:s.length;for(let e=0;e<c;e++){const c=new x(s[e]),{conversationID:u,type:d}=c;if(!this._isNonExistentAccount(u))if(this._convMap.has(u)){const l=this._convMap.get(u);if(o){this._convMap.set(u,c),d===t?c.unreadCount=l.unreadCount:d===n&&(c.groupProfile=JSON.parse(JSON.stringify(l.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:c,lastMessage:s[e].lastMessage,isFromGetConversations:o,isInstantMessage:i}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:i}),!0===r&&(null==l||l.updateUnreadCount({nextUnreadCount:c.unreadCount,isFromGetConversations:o,isUnreadC2CMessage:a}))}else l.push(c),this._convMap.set(u,c)}return{newConvList:l}}_isNonExistentAccount(e){let n;return e.startsWith(t)&&(n=e.replace(t,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}_mergeConversationInfo(e){var t,n;const{conversationID:s,tmpConversation:o,lastMessage:i,isFromGetConversations:a,isInstantMessage:r}=e,l=this._convMap.get(s),c=["unreadCount","allowType","adminForbidType","payload"];!1===r&&c.push("lastMessage"),a&&c.push("isPinned"),P(r)&&i&&null===(null==l?void 0:l.lastMessage.payload)&&(l.lastMessage.payload=i.payload),(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(null==l?void 0:l.lastMessage.revoker))||(l.lastMessage.revoker=null);G(l,o,c,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{conversationID:t,lastMessage:s,isInstantMessage:o}=e,i=this._convMap.get(t);if(i&&s){const{payload:e,nameCard:t,nick:a,cloudCustomData:r=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===n&&(i.lastMessage.nameCard=t,i.lastMessage.nick=a)),i.lastMessage.cloudCustomData!==r&&(i.lastMessage.cloudCustomData=r)}}_sortConvList(e){const t=[],n=[],s=[],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))?n.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):s.push(e)})),t.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(n).concat(s.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(o)}_isConvNeedShow(e){const t=this.getLocalConversation(e);if(P(t))return!0;const o=t.type===s,i=t.type===n&&t.subType===a,l=t.type===n&&t.subType===r;return!(o||i||l)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),a=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageStore)||void 0===s?void 0:s.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 from ${r} to ${l}, conversationID:${e}`),!0===t&&this.emitConversationListUpdate()),o}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._convTotalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate 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}))}emitConversationListUpdate(e=!1){var t;e&&(this._convMap=new Map(this._sortConvList([...this._convMap])));const n=this.getLocalConversationList();this._emitEvent({name:null===(t=this._core)||void 0===t?void 0:t.OuterEvent.CONVERSATION_LIST_UPDATED,data:n}),this._emitTotalUnreadCountUpdate()}getConversationList(t){return e(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(t),isSyncCompleted:this._isSyncCompleted()}}}))}_getConversationList(e){if(P(e))return this.getLocalConversationList();if(N(e)){if(0===e.length)return[];return this.getLocalConversationList().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 n=t;for(;null!==Object.getPrototypeOf(n);)n=Object.getPrototypeOf(n);return t===n})(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return this.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_isSyncCompleted(){return this._pagingStatus===I.RESOLVED}_filterType(e,s){return s!==t&&s!==n||e.type===s}_filterGroupName(e,t){return!R(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){return null===(n=t)||!("number"==typeof n&&!Number.isNaN(n-0)||"object"==typeof n&&n.constructor===Number)||(0===t?0===e.markList.length:e.markList.includes(t));var n}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_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 n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}getConversationProfile(s){return e(this,void 0,void 0,(function*(){let e;return this._convMap.has(s)?e=this._convMap.get(s):(e=new x({conversationID:s}),U(s)?(e.type=t,e.userProfile={userID:s.replace(t,"")}):(e.type=n,e.groupProfile={groupID:s.replace(n,"")}),this._convMap.set(s,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)}`)}))}getTotalUnreadMessageCount(){const e=this.getLocalConversationList();let t=0;return e.forEach((e=>{e.type!==o&&(""!==e.messageRemindType&&e.messageRemindType!==M||(t+=e.unreadCount))})),t}getLocalConversationList(){return[...this._convMap.values()].filter((e=>this._isConvNeedShow(e.conversationID)))}hasLocalConversation(e){return this._convMap.has(e)}getLocalConversation(e){return this._convMap.get(e)}setLocalConversation(e,t){return this._convMap.set(e,t)}deleteLocalConversation(e){this._convMap.delete(e)}_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)}};var j=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi("setMessageRead",this)}setMessageRead(s){return e(this,void 0,void 0,(function*(){var e,i;const{conversationID:a}=s,r={code:0,data:{}},l=V.getLocalConversation(a);if(console.log(`${this._name}.setMessageRead conversationID:${a} unreadCount:${(null==l?void 0:l.unreadCount)||0}`),!l)return r;const c=!(null===(i=null===(e=this._core)||void 0===e?void 0:e.helper)||void 0===i?void 0:i.isEmpty(l.groupAtInfoList));if(l.type===n&&c&&this._deleteGroupAtTips(a),0===l.unreadCount)return r;if(l.type===t){const e=this._getLocalMessageMaxTime(l);yield this._setC2CMessageRead(a,e)}if(l.type===n){const e=this._getLocalMessageMaxSequence(l);yield this._setGroupMessageRead(a,e)}return l.type===o&&(l.unreadCount=0),V.emitConversationListUpdate(),r}))}_deleteGroupAtTips(t){return e(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${t}`);const n=V.getLocalConversation(t);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const n=s.map((e=>({From_Account:e.from,To_Account:this._core.store.get("login").userId,MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(t,n){return e(this,void 0,void 0,(function*(){const{messageListToDelete:e}=t,s="openim.deletemsg",o=null==n?void 0:n.helper.generateProtocolData({servcmd:s,data:{DelMsgList:e}}),i=`${o.head.seq}${s}`;return yield n.channel.sendPacket(o,{requestId:i})}))}({messageListToDelete:n},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(t)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=V.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&V.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageStore.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageStore.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(t,n){return e(this,void 0,void 0,(function*(){try{yield function(t,n){return e(this,void 0,void 0,(function*(){const e="openim.msgreaded",s=null==n?void 0:n.helper.generateProtocolData({servcmd:e,data:t}),o=`${s.head.seq}${e}`;return yield n.channel.sendPacket(s,{requestId:o})}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:t.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok.`),V.updateUnreadCount(t)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(t,n){return e(this,void 0,void 0,(function*(){try{yield function(t,n){return e(this,void 0,void 0,(function*(){const{groupID:e,lastMessageSequence:s}=t,o="group_open_http_svc.msg_read_report",i=null==n?void 0:n.helper.generateProtocolData({servcmd:o,data:{GroupId:e,MsgReadedSeq:s}}),a=`${i.head.seq}${o}`;return yield n.channel.sendPacket(i,{requestId:a})}))}({groupID:t.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok.`),V.updateUnreadCount(t)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var Y=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi("pinConversation",this)}handleConversationPinned(e,s){if(!N(e))return;let o=!1;e.forEach((e=>{const{Type:i,To_Account:a,GroupId:r}=e;let l;1===i?l=V.getLocalConversation(`${t}${a}`):2===i&&(l=V.getLocalConversation(`${n}${r}`)),l&&(console.log(`${this._name}.handleConversationPinned conversationID:${l.conversationID} localPinned:${l.isPinned} remotePinned:${s}`),s&&!l.isPinned&&(l.isPinned=!0,o=!0),!s&&l.isPinned&&(l.isPinned=!1,o=!0))})),o&&V.emitConversationListUpdate(!0)}pinConversation(s){return e(this,void 0,void 0,(function*(){const{conversationID:o,isPinned:i}=s,a={code:0,data:{conversationID:o}},r=V.getLocalConversation(o);if(r&&r.isPinned===i)return a;if(b(o))return r&&(r.isPinned=i),V.emitConversationListUpdate(!0),a;try{let s=null;U(o)?s={Type:1,To_Account:o.replace(t,"")}:k(o)&&(s={Type:2,GroupId:o.replace(n,"")});const l=yield function(t,n){return e(this,void 0,void 0,(function*(){const{fromAccount:e,operationType:s,itemList:o}=t,i="recentcontact.top",a=null==n?void 0:n.helper.generateProtocolData({servcmd:i,data:{From_Account:e,OperationType:s,RecentContactItem:o}}),r=`${a.head.seq}${i}`;return yield n.channel.sendPacket(a,{requestId:r})}))}({fromAccount:this._core.store.get("login").userId,operationType:!0===i?1:2,itemList:[s]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${o} isPinned:${i}.`),l){if(r)r.isPinned!==i&&(r.isPinned=i);else{const e=new x({conversationID:o,type:U(o)?t:n,isPinned:i});V.setLocalConversation(o,e)}V.emitConversationListUpdate(!0)}return a}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var H=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi("deleteConversation",this)}handleConversationDeleted(e){if(!N(e))return;const s=[];e.forEach((e=>{const{Type:o,Peer_Account:i,GroupId:a}=e;1===o&&s.push(`${t}${i}`),2===o&&s.push(`${n}${a}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(t){return e(this,void 0,void 0,(function*(){R(t)&&(console.log(`${this._name}.deleteConversation conversationID:${t}`),yield this._deleteConversation({conversationIDList:[t],flag:E.ONLY_CONVERSATIONID}));const e=Object.assign({},t);e.conversationIDList.length>100&&(e.conversationIDList=e.conversationIDList.slice(0,100)),yield this._deleteConversation(e)}))}_deleteConversation(t){return e(this,void 0,void 0,(function*(){const{conversationIDList:e,clearHistoryMessage:n=!0,flag:s=0}=t;console.log(`${this._name}._deleteConversation conversationIDList:${e} clearHistoryMessage:${n}`);try{const t=yield Promise.all([this._deleteConversationFromLocal(e),this._deleteConversationFromServer(e,n)]),o=[...t[0],...t[1]];if(0===o.length)throw new this._core.helper.ChatError({code:O.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===E.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){return e.filter((e=>{var t;if(!V.hasLocalConversation(e))return!1;const s=null===(t=V.getLocalConversation(e))||void 0===t?void 0:t.type;return s!==n||this._hasLocalGroup(e)?s===o&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(s,o){return e(this,void 0,void 0,(function*(){const i={fromAccount:this._core.store.get("login").userId,conversationList:[],clearHistoryMessage:o?1:0};if(s.forEach((e=>{var s;if(V.hasLocalConversation(e)){const o=(null===(s=V.getLocalConversation(e))||void 0===s?void 0:s.type)||"",a=e.replace(o,"");o===t?i.conversationList.push({To_Account:a,Type:1}):o===n&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:a,Type:2})}})),0===i.conversationList.length)return[];const a=yield function(t,n){return e(this,void 0,void 0,(function*(){const{fromAccount:e,conversationList:s,clearHistoryMessage:o}=t,i="recentcontact.batch_delete",a=null==n?void 0:n.helper.generateProtocolData({servcmd:i,data:{From_Account:e,ContactItem:s,ClearRamble:o}}),r=`${a.head.seq}${i}`;return yield n.channel.sendPacket(a,{requestId:r})}))}(i,this._core);if(a){const{ResultItem:e=[]}=a,s=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const o=1===e.type?`${t}${e.To_Account}`:`${n}${e.ToGroupid}`;s.push(o)}})),this._deleteLocalConversationList(s),s}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{V.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&V.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=V.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(V.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&V.emitConversationListUpdate())}_hasLocalGroup(e){return!!e.replace(n,"")}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageStore.deleteConversationMessageList(e)}};var K=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi("setConversationDraft",this)}setConversationDraft(t){return e(this,void 0,void 0,(function*(){const{conversationID:e,draftText:n}=t;if(console.log(`${this._name} conversationID:${e} draftText:${n}`),!V.hasLocalConversation(e))throw new this._core.helper.ChatError({code:O.CONV_NOT_FOUND});const s=V.getLocalConversation(e);return null==s||s.setDraftText(n),V.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var J=new class{init(e){console.log("ConversationAction.init"),this._core=e,j.init(e),Y.init(e),H.init(e),K.init(e);const{notificationCenter:t,InnerEvent:n}=e,{InnerEventSubType:s}=t;t.subscribeInnerEvent(n.MESSAGE_PUSH,s.CONV_MODIFIED,this._handleConversationModified,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this)}_handleConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===S.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;H.handleConversationDeleted(t)}if(t===S.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;Y.handleConversationPinned(t,!0)}if(t===S.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;Y.handleConversationPinned(t,!1)}}))}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.CONV_MODIFIED,this._handleConversationModified,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const B=e=>!U(e)&&!k(e)&&!b(e),W={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0},z={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!B(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!B(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!B(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:e=>{if(!R(e)&&!A(e))return"options is String or Object.";if(R(e)&&B(e))return"conversationID is invalid.";if(A(e)){if(!N(e.conversationIDList))return"conversationIDList is not Array.";if(0===e.conversationIDList.length)return"conversationIDList is empty.";if(e.conversationIDList.some((e=>{if(B(e))return!0})))return"conversationIDList includes invalid conversationID.";if(e.clearHistoryMessage&&"boolean"!=typeof e.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!U(e)&&!k(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}};var Q=new class{install(e){V.init(e),J.init(e),e.helper.registerValidateConfig({auth:W,params:z})}handleLoginSuccess(){V.handleLoginSuccess()}};export{Q as default};
1
+ 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};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).liteChatConversation=t()}(this,(function(){"use strict";function e(e,t,n,s){return new(n||(n=Promise))((function(o,i){function a(e){try{l(s.next(e))}catch(e){i(e)}}function r(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,r)}l((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="C2C",n="GROUP",s="TOPIC",o="@TIM#SYSTEM",i="AVChatRoom",a="Room",r="Live",l="TIMTextElem",c="TIMImageElem",u="TIMSoundElem",d="TIMFileElem",v="TIMFaceElem",p="TIMVideoFileElem",g="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",_="TIMCustomElem",C="TIMRelayElem",f="AcceptAndNotify",M="AcceptNotNotify",y="Discard",L="AcceptNotNotifyExceptAt";var I,D,T,E,S,O;!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"}(D||(D={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(T||(T={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(E||(E={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(S||(S={})),function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(O||(O={}));const P=e=>void 0===e,R=e=>"string"==typeof e,N=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),A=e=>null!==e&&"object"==typeof e,$=e=>N(e)||A(e),G=(e,t,n,s)=>{if(!$(e)||!$(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],!(P(t[a])||n&&n.includes(a)))if($(e[a])&&$(t[a]))o+=G(e[a],t[a],n,s);else{if(s&&s.includes(t[a]))continue;e[a]!==t[a]&&(e[a]=t[a],o+=1)}return o},U=e=>R(e)&&e.slice(0,3)===t,k=e=>R(e)&&e.slice(0,5)===n,b=e=>R(e)&&e===o,F=(e,t)=>{if(P(t))return"";switch(e){case l:return t.text||"";case c:return"[Image]";case g:return"[Location]";case u:return"[Voice]";case p:return"[Video]";case d:return"[File]";case _:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case v:return"[Animated Sticker]";case C:return"[Chat Record]";default:return""}},w=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:F(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 q(e){const t=[];if(!R(e))return t;const n=e.length;if(0===n)return t;for(let s=n-1;s>=0;s--)"1"===e[s]&&t.push(2**(n-s-1));return t}class x{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=w(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(){P(this.userProfile)&&this.type===t?this.userProfile={}:P(this.groupProfile)&&this.type===n&&(this.groupProfile={}),this.subType&&this.type===n&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){const{nextUnreadCount:o,isFromGetConversations:a,isUnreadC2CMessage:r}=e;P(o)||(this.subType!==i?a&&this.type===n||a&&this.type===s||r&&this.type===t?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=w(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(e){const{sequence:s,time:o}=e;return this.type===t&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}clearGroupAtInfoList(){this.groupAtInfoList.length=0}}var V=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}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s}=e;s.registerApi("getConversationList",this),s.registerApi("getConversationProfile",this),s.registerApi("getTotalUnreadMessageCount",this),t.subscribeInnerEvent(n.RE_LOGIN,this._recoverConversations,this),t.subscribeInnerEvent(n.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(n.NEW_MESSAGE,this._handleNewMessage,this),t.subscribeInnerEvent(n.MESSAGE_DELETED,this._handleMessageDeleted,this),t.subscribeInnerEvent(n.MESSAGE_REVOKED,this._handleMessageRevoked,this),t.subscribeInnerEvent(n.MESSAGE_MODIFIED,this._handleMessageModified,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}handleLoginSuccess(){this.syncConvList()}_handleNewMessage(e){const{conversationOptionsList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e;if(console.log(`${this._name}._handleNewMessage, conversationOptionsList length:`,t.length),0===t.length)return;this._updateLocalConvList({conversationOptionsList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConvNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleMessageDeleted(e){var n,s,o,i;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const a=(null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageStore)||void 0===s?void 0:s.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 c=!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),c=!0),e.startsWith(t)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),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:n=!0}=e;if(0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this._convMap.get(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){var t,n;console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:s,message:o}=e,i=this._convMap.get(s);if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.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=F(o.type,o.payload),a.cloudCustomData=o.cloudCustomData,a.version=o.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${s} lastMessage updated`))}syncConvList(){return e(this,arguments,void 0,(function*(e=!0){yield this._pagingGetConvList(e),this._pagingStatus=I.RESOLVED,this.emitConversationListUpdate()}))}_pagingGetConvList(t){return e(this,void 0,void 0,(function*(){var n;try{this._pagingStatus=I.PENDING;const s=yield function(t,n){return e(this,void 0,void 0,(function*(){const{fromAccount:e,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:a}=t,r="recentcontact.page_get",l=null==n?void 0:n.helper.generateProtocolData({servcmd:r,data:{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:e,StartIndex:o,TimeStamp:s,TopStartIndex:a,TopTimeStamp:i}}),c=`${l.head.seq}${r}`;return yield n.channel.sendPacket(l,{requestId:c})}))}({fromAccount:null===(n=this._core)||void 0===n?void 0:n.store.get("login").userId,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.emitConversationListUpdate()}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 s=this._convertConvKey(e).filter((({type:e,userID:t})=>1===e&&!this._isNonExistentAccount(t)||2===e)),o=this._core.store.get("login").userId;return s.map((e=>{var s,i,a,r,l,c,u,d,v,p,g,h;if(P(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===D.C2C){const n={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},p=null===(a=null===(i=null===(s=this._core)||void 0===s?void 0:s.user)||void 0===i?void 0:i.userProfile)||void 0===a?void 0:a.createProfile(e.userID,[n]);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===(c=e.lastMsg)||void 0===c?void 0:c.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(u=e.lastMsg)||void 0===u?void 0:u.cloudCustomData)||"",isRevoked:e.lastMessageFlag===T.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:e.lastC2CMsgFromAccount===o&&e.time<=e.c2cPeerReadTime,revoker:(null===(v=null===(d=e.lastMsg)||void 0===d?void 0:d.revokerInfo)||void 0===v?void 0:v.revoker)||null},unreadCount:0,userProfile:p,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:q(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}return{conversationID:`${n}${e.groupID}`,type:n,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===T.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(h=null===(g=e.lastMsg)||void 0===g?void 0:g.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:q(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,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",a=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.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 n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){let t="";return 0===e?t=f:1===e?t=y:2===e?t=M:3===e&&(t=L),t}_patchTypeAndPayload(e){const{event:t,elements:n=[]}=e.lastMsg||{};return P(t)?{type:n[0]?n[0].type:null,payload:n[0]?this._amendLayersOverLimitProp(n[0].content):null}:{type:h,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s: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:s,isFromGetConversations:o,isInstantMessage:i,isUnreadC2CMessage:a=!1,updateUnreadCount:r}=e,l=[],c=null==s?void 0:s.length;for(let e=0;e<c;e++){const c=new x(s[e]),{conversationID:u,type:d}=c;if(!this._isNonExistentAccount(u))if(this._convMap.has(u)){const l=this._convMap.get(u);if(o){this._convMap.set(u,c),d===t?c.unreadCount=l.unreadCount:d===n&&(c.groupProfile=JSON.parse(JSON.stringify(l.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:c,lastMessage:s[e].lastMessage,isFromGetConversations:o,isInstantMessage:i}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:i}),!0===r&&(null==l||l.updateUnreadCount({nextUnreadCount:c.unreadCount,isFromGetConversations:o,isUnreadC2CMessage:a}))}else l.push(c),this._convMap.set(u,c)}return{newConvList:l}}_isNonExistentAccount(e){let n;return e.startsWith(t)&&(n=e.replace(t,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}_mergeConversationInfo(e){var t,n;const{conversationID:s,tmpConversation:o,lastMessage:i,isFromGetConversations:a,isInstantMessage:r}=e,l=this._convMap.get(s),c=["unreadCount","allowType","adminForbidType","payload"];!1===r&&c.push("lastMessage"),a&&c.push("isPinned"),P(r)&&i&&null===(null==l?void 0:l.lastMessage.payload)&&(l.lastMessage.payload=i.payload),(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(null==l?void 0:l.lastMessage.revoker))||(l.lastMessage.revoker=null);G(l,o,c,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{conversationID:t,lastMessage:s,isInstantMessage:o}=e,i=this._convMap.get(t);if(i&&s){const{payload:e,nameCard:t,nick:a,cloudCustomData:r=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===n&&(i.lastMessage.nameCard=t,i.lastMessage.nick=a)),i.lastMessage.cloudCustomData!==r&&(i.lastMessage.cloudCustomData=r)}}_sortConvList(e){const t=[],n=[],s=[],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))?n.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):s.push(e)})),t.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(n).concat(s.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(o)}_isConvNeedShow(e){const t=this.getLocalConversation(e);if(P(t))return!0;const o=t.type===s,i=t.type===n&&t.subType===a,l=t.type===n&&t.subType===r;return!(o||i||l)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),a=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageStore)||void 0===s?void 0:s.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 from ${r} to ${l}, conversationID:${e}`),!0===t&&this.emitConversationListUpdate()),o}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._convTotalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate 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}))}emitConversationListUpdate(e=!1){var t;e&&(this._convMap=new Map(this._sortConvList([...this._convMap])));const n=this.getLocalConversationList();this._emitEvent({name:null===(t=this._core)||void 0===t?void 0:t.OuterEvent.CONVERSATION_LIST_UPDATED,data:n}),this._emitTotalUnreadCountUpdate()}getConversationList(t){return e(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(t),isSyncCompleted:this._isSyncCompleted()}}}))}_getConversationList(e){if(P(e))return this.getLocalConversationList();if(N(e)){if(0===e.length)return[];return this.getLocalConversationList().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 n=t;for(;null!==Object.getPrototypeOf(n);)n=Object.getPrototypeOf(n);return t===n})(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return this.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_isSyncCompleted(){return this._pagingStatus===I.RESOLVED}_filterType(e,s){return s!==t&&s!==n||e.type===s}_filterGroupName(e,t){return!R(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){return null===(n=t)||!("number"==typeof n&&!Number.isNaN(n-0)||"object"==typeof n&&n.constructor===Number)||(0===t?0===e.markList.length:e.markList.includes(t));var n}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_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 n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}getConversationProfile(s){return e(this,void 0,void 0,(function*(){let e;return this._convMap.has(s)?e=this._convMap.get(s):(e=new x({conversationID:s}),U(s)?(e.type=t,e.userProfile={userID:s.replace(t,"")}):(e.type=n,e.groupProfile={groupID:s.replace(n,"")}),this._convMap.set(s,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)}`)}))}getTotalUnreadMessageCount(){const e=this.getLocalConversationList();let t=0;return e.forEach((e=>{e.type!==o&&(""!==e.messageRemindType&&e.messageRemindType!==f||(t+=e.unreadCount))})),t}getLocalConversationList(){return[...this._convMap.values()].filter((e=>this._isConvNeedShow(e.conversationID)))}hasLocalConversation(e){return this._convMap.has(e)}getLocalConversation(e){return this._convMap.get(e)}setLocalConversation(e,t){return this._convMap.set(e,t)}deleteLocalConversation(e){this._convMap.delete(e)}_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)}};var j=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi("setMessageRead",this)}setMessageRead(s){return e(this,void 0,void 0,(function*(){var e,i;const{conversationID:a}=s,r={code:0,data:{}},l=V.getLocalConversation(a);if(console.log(`${this._name}.setMessageRead conversationID:${a} unreadCount:${(null==l?void 0:l.unreadCount)||0}`),!l)return r;const c=!(null===(i=null===(e=this._core)||void 0===e?void 0:e.helper)||void 0===i?void 0:i.isEmpty(l.groupAtInfoList));if(l.type===n&&c&&this._deleteGroupAtTips(a),0===l.unreadCount)return r;if(l.type===t){const e=this._getLocalMessageMaxTime(l);yield this._setC2CMessageRead(a,e)}if(l.type===n){const e=this._getLocalMessageMaxSequence(l);yield this._setGroupMessageRead(a,e)}return l.type===o&&(l.unreadCount=0),V.emitConversationListUpdate(),r}))}_deleteGroupAtTips(t){return e(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${t}`);const n=V.getLocalConversation(t);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const n=s.map((e=>({From_Account:e.from,To_Account:this._core.store.get("login").userId,MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(t,n){return e(this,void 0,void 0,(function*(){const{messageListToDelete:e}=t,s="openim.deletemsg",o=null==n?void 0:n.helper.generateProtocolData({servcmd:s,data:{DelMsgList:e}}),i=`${o.head.seq}${s}`;return yield n.channel.sendPacket(o,{requestId:i})}))}({messageListToDelete:n},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(t)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=V.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&V.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageStore.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageStore.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(t,n){return e(this,void 0,void 0,(function*(){try{yield function(t,n){return e(this,void 0,void 0,(function*(){const e="openim.msgreaded",s=null==n?void 0:n.helper.generateProtocolData({servcmd:e,data:t}),o=`${s.head.seq}${e}`;return yield n.channel.sendPacket(s,{requestId:o})}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:t.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok.`),V.updateUnreadCount(t)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(t,n){return e(this,void 0,void 0,(function*(){try{yield function(t,n){return e(this,void 0,void 0,(function*(){const{groupID:e,lastMessageSequence:s}=t,o="group_open_http_svc.msg_read_report",i=null==n?void 0:n.helper.generateProtocolData({servcmd:o,data:{GroupId:e,MsgReadedSeq:s}}),a=`${i.head.seq}${o}`;return yield n.channel.sendPacket(i,{requestId:a})}))}({groupID:t.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok.`),V.updateUnreadCount(t)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var Y=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi("pinConversation",this)}handleConversationPinned(e,s){if(!N(e))return;let o=!1;e.forEach((e=>{const{Type:i,To_Account:a,GroupId:r}=e;let l;1===i?l=V.getLocalConversation(`${t}${a}`):2===i&&(l=V.getLocalConversation(`${n}${r}`)),l&&(console.log(`${this._name}.handleConversationPinned conversationID:${l.conversationID} localPinned:${l.isPinned} remotePinned:${s}`),s&&!l.isPinned&&(l.isPinned=!0,o=!0),!s&&l.isPinned&&(l.isPinned=!1,o=!0))})),o&&V.emitConversationListUpdate(!0)}pinConversation(s){return e(this,void 0,void 0,(function*(){const{conversationID:o,isPinned:i}=s,a={code:0,data:{conversationID:o}},r=V.getLocalConversation(o);if(r&&r.isPinned===i)return a;if(b(o))return r&&(r.isPinned=i),V.emitConversationListUpdate(!0),a;try{let s=null;U(o)?s={Type:1,To_Account:o.replace(t,"")}:k(o)&&(s={Type:2,GroupId:o.replace(n,"")});const l=yield function(t,n){return e(this,void 0,void 0,(function*(){const{fromAccount:e,operationType:s,itemList:o}=t,i="recentcontact.top",a=null==n?void 0:n.helper.generateProtocolData({servcmd:i,data:{From_Account:e,OperationType:s,RecentContactItem:o}}),r=`${a.head.seq}${i}`;return yield n.channel.sendPacket(a,{requestId:r})}))}({fromAccount:this._core.store.get("login").userId,operationType:!0===i?1:2,itemList:[s]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${o} isPinned:${i}.`),l){if(r)r.isPinned!==i&&(r.isPinned=i);else{const e=new x({conversationID:o,type:U(o)?t:n,isPinned:i});V.setLocalConversation(o,e)}V.emitConversationListUpdate(!0)}return a}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var H=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi("deleteConversation",this)}handleConversationDeleted(e){if(!N(e))return;const s=[];e.forEach((e=>{const{Type:o,Peer_Account:i,GroupId:a}=e;1===o&&s.push(`${t}${i}`),2===o&&s.push(`${n}${a}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(t){return e(this,void 0,void 0,(function*(){R(t)&&(console.log(`${this._name}.deleteConversation conversationID:${t}`),yield this._deleteConversation({conversationIDList:[t],flag:E.ONLY_CONVERSATIONID}));const e=Object.assign({},t);e.conversationIDList.length>100&&(e.conversationIDList=e.conversationIDList.slice(0,100)),yield this._deleteConversation(e)}))}_deleteConversation(t){return e(this,void 0,void 0,(function*(){const{conversationIDList:e,clearHistoryMessage:n=!0,flag:s=0}=t;console.log(`${this._name}._deleteConversation conversationIDList:${e} clearHistoryMessage:${n}`);try{const t=yield Promise.all([this._deleteConversationFromLocal(e),this._deleteConversationFromServer(e,n)]),o=[...t[0],...t[1]];if(0===o.length)throw new this._core.helper.ChatError({code:O.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===E.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){return e.filter((e=>{var t;if(!V.hasLocalConversation(e))return!1;const s=null===(t=V.getLocalConversation(e))||void 0===t?void 0:t.type;return s!==n||this._hasLocalGroup(e)?s===o&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(s,o){return e(this,void 0,void 0,(function*(){const i={fromAccount:this._core.store.get("login").userId,conversationList:[],clearHistoryMessage:o?1:0};if(s.forEach((e=>{var s;if(V.hasLocalConversation(e)){const o=(null===(s=V.getLocalConversation(e))||void 0===s?void 0:s.type)||"",a=e.replace(o,"");o===t?i.conversationList.push({To_Account:a,Type:1}):o===n&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:a,Type:2})}})),0===i.conversationList.length)return[];const a=yield function(t,n){return e(this,void 0,void 0,(function*(){const{fromAccount:e,conversationList:s,clearHistoryMessage:o}=t,i="recentcontact.batch_delete",a=null==n?void 0:n.helper.generateProtocolData({servcmd:i,data:{From_Account:e,ContactItem:s,ClearRamble:o}}),r=`${a.head.seq}${i}`;return yield n.channel.sendPacket(a,{requestId:r})}))}(i,this._core);if(a){const{ResultItem:e=[]}=a,s=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const o=1===e.type?`${t}${e.To_Account}`:`${n}${e.ToGroupid}`;s.push(o)}})),this._deleteLocalConversationList(s),s}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{V.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&V.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=V.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(V.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&V.emitConversationListUpdate())}_hasLocalGroup(e){return!!e.replace(n,"")}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageStore.deleteConversationMessageList(e)}};var K=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi("setConversationDraft",this)}setConversationDraft(t){return e(this,void 0,void 0,(function*(){const{conversationID:e,draftText:n}=t;if(console.log(`${this._name} conversationID:${e} draftText:${n}`),!V.hasLocalConversation(e))throw new this._core.helper.ChatError({code:O.CONV_NOT_FOUND});const s=V.getLocalConversation(e);return null==s||s.setDraftText(n),V.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var J=new class{init(e){console.log("ConversationAction.init"),this._core=e,j.init(e),Y.init(e),H.init(e),K.init(e);const{notificationCenter:t,InnerEvent:n}=e,{InnerEventSubType:s}=t;t.subscribeInnerEvent(n.MESSAGE_PUSH,s.CONV_MODIFIED,this._handleConversationModified,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this)}_handleConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===S.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;H.handleConversationDeleted(t)}if(t===S.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;Y.handleConversationPinned(t,!0)}if(t===S.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;Y.handleConversationPinned(t,!1)}}))}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.CONV_MODIFIED,this._handleConversationModified,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const B=e=>!U(e)&&!k(e)&&!b(e),W={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0},z={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!B(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!B(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!B(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:e=>{if(!R(e)&&!A(e))return"options is String or Object.";if(R(e)&&B(e))return"conversationID is invalid.";if(A(e)){if(!N(e.conversationIDList))return"conversationIDList is not Array.";if(0===e.conversationIDList.length)return"conversationIDList is empty.";if(e.conversationIDList.some((e=>{if(B(e))return!0})))return"conversationIDList includes invalid conversationID.";if(e.clearHistoryMessage&&"boolean"!=typeof e.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!U(e)&&!k(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}};return new class{install(e){V.init(e),J.init(e),e.helper.registerValidateConfig({auth:W,params:z})}handleLoginSuccess(){V.handleLoginSuccess()}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatConversation=t()}(this,(function(){"use strict";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",p="TIMFaceElem",g="TIMVideoFileElem",v="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",C="TIMCustomElem",_="TIMRelayElem",M="AcceptAndNotify",f="AcceptNotNotify",y="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 g:return"[Video]";case c:return"[File]";case C:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case p: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 b{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 U=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,p,g,v,h;if(E(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===L.C2C){const s={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},g=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===(p=null===(c=e.lastMsg)||void 0===c?void 0:c.revokerInfo)||void 0===p?void 0:p.revoker)||null},unreadCount:0,userProfile:g,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===(g=e.lastMsg)||void 0===g?void 0:g.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=y:2===e?t=f: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 b(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 b({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 A={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."}]};return{install:function(e){U.install(e),e.helper.registerValidateConfig({auth:A,params:F})},handleLoginSuccess:function(){U.handleLoginSuccess()}}}));
@@ -5,4 +5,4 @@ declare const friendPlugin: {
5
5
  export default friendPlugin;
6
6
  declare module '@tencentcloud/lite-chat/plugins/friend' {
7
7
  export default friendPlugin;
8
- }
8
+ }
@@ -1 +1 @@
1
- function e(e,t,s,i){return new(s||(s=Promise))((function(r,n){function o(e){try{a(i.next(e))}catch(e){n(e)}}function c(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,c)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="friend",s=2700,i=2742;var r=new class{constructor(){this._friendUserIdMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi("getFriendList",this),t.registerApi("getFriendProfile",this)}getFriendList(){return e(this,void 0,void 0,(function*(){return console.log(`${t} getFriendList`),{code:0,data:[]}}))}getFriendProfile(i){return e(this,void 0,void 0,(function*(){try{console.log(`${t} getFriendProfile params: `,i);let{userIDList:r}=i;const n=[];r.length>100&&(r=r.slice(0,100));const{friendUserIdList:o,unFriendUserIdList:c}=this._partitionByIsFriend(r);if(c.forEach((e=>{n.push({userID:e,code:s,message:"The specified userID is not my friend"})})),0===o.length)return{code:0,data:{friendList:o,failureUserIDList:n}};const a=(yield function(t,s){return e(this,void 0,void 0,(function*(){var e;const{channel:i,helper:r,store:n}=s,o="sns.friend_get_specified",c=null===(e=n.get("login"))||void 0===e?void 0:e.userId,a=r.generateProtocolData({servcmd:o,data:{From_Account:c,To_Account:t}}),l=`${a.head.seq}${o}`;return yield i.sendPacket(a,{requestId:l})}))}(o,this._core))||{},{successDueToResponseList:l,failureDueToResponseList:d}=this._handleFriendProfileResponse(a);return{code:0,data:{friendList:l,failureUserIDList:[...d,...n]}}}catch(e){throw console.error(`${t} getFriendProfile error:`,e),e}}))}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this)}reset(){this._friendUserIdMap.clear()}_handleFriendProfileResponse(e){const{InfoItem:t=[]}=e,s=[],i=[];return t.forEach((e=>{const{To_Account:t,ResultCode:r,ResultInfo:n,SnsProfileItem:o}=e;0===r?s.push(o):i.push({userID:t,code:r,message:n})})),{successDueToResponseList:s,failureDueToResponseList:i}}_partitionByIsFriend(e){const s=[],i=[];return e.forEach((e=>{this._friendUserIdMap.has(e)?s.push(e):i.push(e)})),console.log(`${t} _partitionByIsFriend, friendUserIdList: ${s}, unFriendUserIdList:${i}`),{friendUserIdList:s,unFriendUserIdList:i}}};var n=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi("getFriendApplicationList",this)}getFriendApplicationList(){return e(this,void 0,void 0,(function*(){return console.log(`${t} getFriendApplicationList`),{code:0,data:{friendApplicationList:[],unreadCount:0}}}))}};var o=new class{init(e){this._core=e}};function c(e){return e&&0!==e.length?e.map((e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp}))):[]}var a=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:i}=e;t.registerApi("getBlacklist",this,"getLocalBlacklist"),t.registerApi("addToBlacklist",this),t.registerApi("removeFromBlacklist",this),s.subscribeInnerEvent(i.MESSAGE_PUSH,s.InnerEventSubType.FRIEND_LIST_MODIFIED,this._onBlacklistChange,this),s.subscribeInnerEvent(i.RE_LOGIN,this._syncRemoteBlacklist,this)}getLocalBlacklist(){return e(this,void 0,void 0,(function*(){return console.log(`${t} getLocalBlacklist`),{code:0,data:Array.from(this._blacklistMap.keys())}}))}_syncRemoteBlacklist(){return e(this,void 0,void 0,(function*(){try{console.log(`${t} _syncRemoteBlacklist`);const s={From_Account:this._getCurrentUserId(),MaxLimited:100,StartIndex:this._startIndex},i=yield function(t,s){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=s,r="sns.black_list_get",n=e.generateProtocolData({servcmd:r,data:t}),o=`${n.head.seq}${r}`,a=yield i.sendPacket(n,{requestId:o}),{BlackListItem:l=[],StartIndex:d=0}=a;return{blackList:c(l),startIndex:d}}))}(s,this._core),{blackList:r=[],startIndex:n=0}=i;return this._startIndex=n,this._addBlacklistMap(r),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this._syncRemoteBlacklist()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(`${t} _syncRemoteBlacklist error:`,e),e}}))}addToBlacklist(s){return e(this,void 0,void 0,(function*(){try{console.log(`${t} addToBlacklist options:`,s);const i=this._preprocessBlacklist(s),r={From_Account:this._getCurrentUserId(),To_Account:i},n=yield function(t,s){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=s,r="sns.black_list_add",n=e.generateProtocolData({servcmd:r,data:t}),o=`${n.head.seq}${r}`,a=yield i.sendPacket(n,{requestId:o}),{ResultItem:l=[]}=a;return{blackList:c(l)}}))}(r,this._core),{blackList:o=[]}=n;return this._addBlacklistMap(o),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(`${t} addToBlacklist error:`,e),e}}))}removeFromBlacklist(s){return e(this,void 0,void 0,(function*(){try{console.log(`${t} removeFromBlacklist options:`,s);const i={From_Account:this._getCurrentUserId(),To_Account:s.userIDList},r=yield function(t,s){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=s,r="sns.black_list_delete",n=e.generateProtocolData({servcmd:r,data:t}),o=`${n.head.seq}${r}`,a=yield i.sendPacket(n,{requestId:o}),{ResultItem:l=[]}=a;return{blackList:c(l)}}))}(i,this._core),{blackList:n=[]}=r;return this._deleteBlacklistMap(n),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(`${t} removeFromBlacklist error:`,e),e}}))}handleLoginSuccess(){return e(this,void 0,void 0,(function*(){yield this._syncRemoteBlacklist()}))}dispose(){const{notificationCenter:e,InnerEvent:t,InnerEventSubType:s}=this._core;this.reset(),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,s.FRIEND_LIST_MODIFIED,this._onBlacklistChange,this),e.unSubscribeInnerEvent(t.RE_LOGIN,this._syncRemoteBlacklist,this)}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}_onBlacklistChange(e){console.log(`${t} _onBlackListChange event:`,e);const{BlackListAdd_Account:s=[],BlackListDel_Account:i=[]}=null==e?void 0:e.FriendListMod[0];let r=!1;if(s.length>0){s.some((e=>!this._blacklistMap.has(e)))&&(r=!0,this._addBlacklistMap(s.map((e=>({userID:e})))))}if(i.length>0){i.some((e=>this._blacklistMap.has(e)))&&(r=!0,this._deleteBlacklistMap(i.map((e=>({userID:e})))))}r&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(`${t} _addBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t,addBlackTimeStamp:s=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:s})}))}_deleteBlacklistMap(e){console.log(`${t} _deleteBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)}))}_preprocessBlacklist(e){let{userIDList:t}=e;const s=this._getCurrentUserId();if(1===t.length&&t[0]===s)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:i});return t.includes(s)&&(t=e.userIDList.filter((e=>e!==s))),t}_getCurrentUserId(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===t?void 0:t.userId}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:s}=this._core,i=Array.from(this._blacklistMap.keys());console.log(`${t} _emitBlackListUpdated blackList:`,i),e.emitOuterEvent(s.BLACKLIST_UPDATED,{name:s.BLACKLIST_UPDATED,data:i})}};const l={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendProfile:!0,getFriendList:!0,getFriendApplicationList:!0};var d=new class{install(e){console.log(`${t} install`),r.init(e),n.init(e),o.init(e),a.init(e),e.helper.registerValidateConfig({auth:l})}handleLoginSuccess(){console.log(`${t} handleLoginSuccess`),a.handleLoginSuccess()}reset(){console.log(`${t} reset`),a.reset(),r.reset()}dispose(){console.log(`${t} dispose`),a.dispose(),r.dispose()}};export{d as default};
1
+ function t(t,i,e,n){return new(e||(e=Promise))((function(r,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function c(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,c)}a((n=n.apply(t,i||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const i="friend";var e=new class{init(t){this._core=t;const{helper:i}=t;i.registerApi("getBlacklist",this)}getBlacklist(){return t(this,void 0,void 0,(function*(){return console.log(`${i} getBlacklist`),{code:0,data:[]}}))}};var n=new class{init(t){this._core=t;const{helper:i}=t;i.registerApi("getFriendList",this)}getFriendList(){return t(this,void 0,void 0,(function*(){return console.log(`${i} getFriendList`),{code:0,data:[]}}))}};var r=new class{init(t){this._core=t;const{helper:i}=t;i.registerApi("getFriendApplicationList",this)}getFriendApplicationList(){return t(this,void 0,void 0,(function*(){return console.log(`${i} getFriendApplicationList`),{code:0,data:{friendApplicationList:[],unreadCount:0}}}))}};var s=new class{init(t){this._core=t}};const o={getBlacklist:!0,getFriendList:!0,getFriendApplicationList:!0};var c=new class{install(t){e.init(t),n.init(t),r.init(t),s.init(t),t.helper.registerValidateConfig({auth:o})}};export{c as default};
package/plugins/friend.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).liteChatFriend=t()}(this,(function(){"use strict";function e(e,t,s,i){return new(s||(s=Promise))((function(n,r){function o(e){try{a(i.next(e))}catch(e){r(e)}}function c(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,c)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="friend",s=2700,i=2742;var n=new class{constructor(){this._friendUserIdMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi("getFriendList",this),t.registerApi("getFriendProfile",this)}getFriendList(){return e(this,void 0,void 0,(function*(){return console.log(`${t} getFriendList`),{code:0,data:[]}}))}getFriendProfile(i){return e(this,void 0,void 0,(function*(){try{console.log(`${t} getFriendProfile params: `,i);let{userIDList:n}=i;const r=[];n.length>100&&(n=n.slice(0,100));const{friendUserIdList:o,unFriendUserIdList:c}=this._partitionByIsFriend(n);if(c.forEach((e=>{r.push({userID:e,code:s,message:"The specified userID is not my friend"})})),0===o.length)return{code:0,data:{friendList:o,failureUserIDList:r}};const a=(yield function(t,s){return e(this,void 0,void 0,(function*(){var e;const{channel:i,helper:n,store:r}=s,o="sns.friend_get_specified",c=null===(e=r.get("login"))||void 0===e?void 0:e.userId,a=n.generateProtocolData({servcmd:o,data:{From_Account:c,To_Account:t}}),l=`${a.head.seq}${o}`;return yield i.sendPacket(a,{requestId:l})}))}(o,this._core))||{},{successDueToResponseList:l,failureDueToResponseList:d}=this._handleFriendProfileResponse(a);return{code:0,data:{friendList:l,failureUserIDList:[...d,...r]}}}catch(e){throw console.error(`${t} getFriendProfile error:`,e),e}}))}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this)}reset(){this._friendUserIdMap.clear()}_handleFriendProfileResponse(e){const{InfoItem:t=[]}=e,s=[],i=[];return t.forEach((e=>{const{To_Account:t,ResultCode:n,ResultInfo:r,SnsProfileItem:o}=e;0===n?s.push(o):i.push({userID:t,code:n,message:r})})),{successDueToResponseList:s,failureDueToResponseList:i}}_partitionByIsFriend(e){const s=[],i=[];return e.forEach((e=>{this._friendUserIdMap.has(e)?s.push(e):i.push(e)})),console.log(`${t} _partitionByIsFriend, friendUserIdList: ${s}, unFriendUserIdList:${i}`),{friendUserIdList:s,unFriendUserIdList:i}}};var r=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi("getFriendApplicationList",this)}getFriendApplicationList(){return e(this,void 0,void 0,(function*(){return console.log(`${t} getFriendApplicationList`),{code:0,data:{friendApplicationList:[],unreadCount:0}}}))}};var o=new class{init(e){this._core=e}};function c(e){return e&&0!==e.length?e.map((e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp}))):[]}var a=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:i}=e;t.registerApi("getBlacklist",this,"getLocalBlacklist"),t.registerApi("addToBlacklist",this),t.registerApi("removeFromBlacklist",this),s.subscribeInnerEvent(i.MESSAGE_PUSH,s.InnerEventSubType.FRIEND_LIST_MODIFIED,this._onBlacklistChange,this),s.subscribeInnerEvent(i.RE_LOGIN,this._syncRemoteBlacklist,this)}getLocalBlacklist(){return e(this,void 0,void 0,(function*(){return console.log(`${t} getLocalBlacklist`),{code:0,data:Array.from(this._blacklistMap.keys())}}))}_syncRemoteBlacklist(){return e(this,void 0,void 0,(function*(){try{console.log(`${t} _syncRemoteBlacklist`);const s={From_Account:this._getCurrentUserId(),MaxLimited:100,StartIndex:this._startIndex},i=yield function(t,s){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=s,n="sns.black_list_get",r=e.generateProtocolData({servcmd:n,data:t}),o=`${r.head.seq}${n}`,a=yield i.sendPacket(r,{requestId:o}),{BlackListItem:l=[],StartIndex:d=0}=a;return{blackList:c(l),startIndex:d}}))}(s,this._core),{blackList:n=[],startIndex:r=0}=i;return this._startIndex=r,this._addBlacklistMap(n),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this._syncRemoteBlacklist()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(`${t} _syncRemoteBlacklist error:`,e),e}}))}addToBlacklist(s){return e(this,void 0,void 0,(function*(){try{console.log(`${t} addToBlacklist options:`,s);const i=this._preprocessBlacklist(s),n={From_Account:this._getCurrentUserId(),To_Account:i},r=yield function(t,s){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=s,n="sns.black_list_add",r=e.generateProtocolData({servcmd:n,data:t}),o=`${r.head.seq}${n}`,a=yield i.sendPacket(r,{requestId:o}),{ResultItem:l=[]}=a;return{blackList:c(l)}}))}(n,this._core),{blackList:o=[]}=r;return this._addBlacklistMap(o),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(`${t} addToBlacklist error:`,e),e}}))}removeFromBlacklist(s){return e(this,void 0,void 0,(function*(){try{console.log(`${t} removeFromBlacklist options:`,s);const i={From_Account:this._getCurrentUserId(),To_Account:s.userIDList},n=yield function(t,s){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=s,n="sns.black_list_delete",r=e.generateProtocolData({servcmd:n,data:t}),o=`${r.head.seq}${n}`,a=yield i.sendPacket(r,{requestId:o}),{ResultItem:l=[]}=a;return{blackList:c(l)}}))}(i,this._core),{blackList:r=[]}=n;return this._deleteBlacklistMap(r),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(`${t} removeFromBlacklist error:`,e),e}}))}handleLoginSuccess(){return e(this,void 0,void 0,(function*(){yield this._syncRemoteBlacklist()}))}dispose(){const{notificationCenter:e,InnerEvent:t,InnerEventSubType:s}=this._core;this.reset(),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,s.FRIEND_LIST_MODIFIED,this._onBlacklistChange,this),e.unSubscribeInnerEvent(t.RE_LOGIN,this._syncRemoteBlacklist,this)}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}_onBlacklistChange(e){console.log(`${t} _onBlackListChange event:`,e);const{BlackListAdd_Account:s=[],BlackListDel_Account:i=[]}=null==e?void 0:e.FriendListMod[0];let n=!1;if(s.length>0){s.some((e=>!this._blacklistMap.has(e)))&&(n=!0,this._addBlacklistMap(s.map((e=>({userID:e})))))}if(i.length>0){i.some((e=>this._blacklistMap.has(e)))&&(n=!0,this._deleteBlacklistMap(i.map((e=>({userID:e})))))}n&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(`${t} _addBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t,addBlackTimeStamp:s=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:s})}))}_deleteBlacklistMap(e){console.log(`${t} _deleteBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)}))}_preprocessBlacklist(e){let{userIDList:t}=e;const s=this._getCurrentUserId();if(1===t.length&&t[0]===s)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:i});return t.includes(s)&&(t=e.userIDList.filter((e=>e!==s))),t}_getCurrentUserId(){var e,t;return null===(t=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===t?void 0:t.userId}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:s}=this._core,i=Array.from(this._blacklistMap.keys());console.log(`${t} _emitBlackListUpdated blackList:`,i),e.emitOuterEvent(s.BLACKLIST_UPDATED,{name:s.BLACKLIST_UPDATED,data:i})}};const l={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendProfile:!0,getFriendList:!0,getFriendApplicationList:!0};return new class{install(e){console.log(`${t} install`),n.init(e),r.init(e),o.init(e),a.init(e),e.helper.registerValidateConfig({auth:l})}handleLoginSuccess(){console.log(`${t} handleLoginSuccess`),a.handleLoginSuccess()}reset(){console.log(`${t} reset`),a.reset(),n.reset()}dispose(){console.log(`${t} dispose`),a.dispose(),n.dispose()}}}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).TencentCloudChatFriend=e()}(this,(function(){"use strict";function t(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{l(n.next(t))}catch(t){r(t)}}function c(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,c)}l((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const e="friend";var i=new class{init(t){this._core=t;const{helper:e}=t;e.registerApi("getBlacklist",this)}getBlacklist(){return t(this,void 0,void 0,(function*(){return console.log(`${e} getBlacklist`),{code:0,data:[]}}))}};var n=new class{init(t){this._core=t;const{helper:e}=t;e.registerApi("getFriendList",this)}getFriendList(){return t(this,void 0,void 0,(function*(){return console.log(`${e} getFriendList`),{code:0,data:[]}}))}};var o=new class{init(t){this._core=t;const{helper:e}=t;e.registerApi("getFriendApplicationList",this)}getFriendApplicationList(){return t(this,void 0,void 0,(function*(){return console.log(`${e} getFriendApplicationList`),{code:0,data:{friendApplicationList:[],unreadCount:0}}}))}};var r=new class{init(t){this._core=t}};const s={getBlacklist:!0,getFriendList:!0,getFriendApplicationList:!0};return new class{install(t){i.init(t),n.init(t),o.init(t),r.init(t),t.helper.registerValidateConfig({auth:s})}}}));
@@ -1,8 +1,8 @@
1
1
  declare const groupPlugin: {
2
- [key: string]: any;
3
- };
2
+ [key: string]: any;
3
+ };
4
4
 
5
+ export default groupPlugin;
6
+ declare module '@tencentcloud/lite-chat/plugins/group' {
5
7
  export default groupPlugin;
6
- declare module '@tencentcloud/lite-chat/plugins/group' {
7
- export default groupPlugin;
8
- }
8
+ }
@@ -1 +1 @@
1
- const e={GRP_WORK:"Private",GRP_PUBLIC:"Public",GRP_MEETING:"ChatRoom",GRP_AVCHATROOM:"AVChatRoom",GRP_COMMUNITY:"Community",GRP_ROOM:"Room",GRP_LIVE:"Live"},t={JOIN_OPTIONS_FREE_ACCESS:"FreeAccess",JOIN_OPTIONS_NEED_PERMISSION:"NeedPermission",JOIN_OPTIONS_DISABLE_APPLY:"DisableApply",JOIN_STATUS_SUCCESS:"JoinedSuccess",JOIN_STATUS_ALREADY_IN_GROUP:"AlreadyInGroup",JOIN_STATUS_WAIT_APPROVAL:"WaitAdminApproval"};Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e),{GRP_MBR_ROLE_OWNER:"Owner",GRP_MBR_ROLE_ADMIN:"Admin",GRP_MBR_ROLE_MEMBER:"Member",GRP_MBR_ROLE_CUSTOM:"Custom"}),{GRP_TIP_MBR_JOIN:1,GRP_TIP_MBR_QUIT:2,GRP_TIP_MBR_KICKED_OUT:3,GRP_TIP_MBR_SET_ADMIN:4,GRP_TIP_MBR_CANCELED_ADMIN:5,GRP_TIP_GRP_PROFILE_UPDATED:6,GRP_TIP_MBR_PROFILE_UPDATED:7,GRP_TIP_BAN_AVCHATROOM_MEMBER:10,GRP_TIP_UNBAN_AVCHATROOM_MEMBER:11}),t),{INVITE_OPTIONS_DISABLE_INVITE:"DisableInvite",INVITE_OPTIONS_NEED_PERMISSION:"NeedPermission",INVITE_OPTIONS_FREE_ACCESS:"FreeAccess"}),{GRP_PROFILE_OWNER_ID:"ownerID",GRP_PROFILE_CREATE_TIME:"createTime",GRP_PROFILE_LAST_INFO_TIME:"lastInfoTime",GRP_PROFILE_MEMBER_NUM:"memberNum",GRP_PROFILE_MAX_MEMBER_NUM:"maxMemberNum",GRP_PROFILE_JOIN_OPTION:"joinOption",GRP_PROFILE_INVITE_OPTION:"inviteOption",GRP_PROFILE_INTRODUCTION:"introduction",GRP_PROFILE_NOTIFICATION:"notification",GRP_PROFILE_MUTE_ALL_MBRS:"muteAllMembers"});const o=[e.GRP_PUBLIC,e.GRP_WORK,e.GRP_MEETING,e.GRP_AVCHATROOM,e.GRP_COMMUNITY],i=["Type","Name","Introduction","Notification","FaceUrl","Owner_Account","CreateTime","InfoSeq","LastInfoTime","LastMsgTime","MemberNum","MaxMemberNum","ApplyJoinOption","NextMsgSeq","ShutUpAllMember","InviteJoinOption"],r=["Type","Name","Introduction","Notification","FaceUrl","CreateTime","Owner_Account","LastInfoTime","LastMsgTime","NextMsgSeq","MemberNum","MaxMemberNum","ApplyJoinOption","InviteJoinOption"],s=["Role","JoinTime","MsgFlag","MsgSeq"],n=["Role","JoinTime","MsgSeq","MsgFlag","NameCard"],u=0,p=1,a="@TGS#_",c="@TOPIC#_",l="notStart",m="resolved",g="rejected",_=10018,h=11e3,d=2600,f=2602,I=2623,G=2660,v=t=>t===e.GRP_PUBLIC,y=t=>t===e.GRP_AVCHATROOM,M=({type:t,groupID:o})=>t===e.GRP_COMMUNITY||`${o}`.startsWith(a)&&!`${o}`.includes(c),O=e=>void 0===e,L=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),S=e=>L(e)||(e=>null!==e&&"object"==typeof e)(e),T=(e,t,o,i)=>{if(!S(e)||!S(t))return 0;let r=0;const s=Object.keys(t);let n;for(let u=0,p=s.length;u<p;u++)if(n=s[u],!(O(t[n])||o&&o.includes(n)))if(S(e[n])&&S(t[n]))r+=T(e[n],t[n],o,i);else{if(i&&i.includes(t[n]))continue;e[n]!==t[n]&&(e[n]=t[n],r+=1)}return r};function P(e){const t=[];if(!e)return t;for(let o=0,i=e.length;o<i;o++){const{Key:i,Value:r}=e[o];t.push({key:i,value:r})}return t}const R=["groupID","name","avatar","type","introduction","notification","ownerID","selfInfo","createTime","infoSequence","lastInfoTime","lastMessage","nextMessageSeq","memberNum","maxMemberNum","memberList","joinOption","groupCustomField","muteAllMembers","isSupportTopic","inviteOption","_lastRevokedTime"];class b{constructor(e){this.groupID="",this.name="",this.avatar="",this.type="",this.introduction="",this.notification="",this.ownerID="",this.createTime=0,this.selfInfo={messageRemindType:"",joinTime:"",nameCard:"",role:"",userID:"",memberCustomField:void 0,readedSequence:0,excludedUnreadSequenceList:void 0},this.lastMessage={lastTime:0,lastSequence:0,fromAccount:"",messageForShow:""},this.nextMessageSeq=0,this.memberNum=0,this.memberCount=0,this.maxMemberNum=0,this.maxMemberCount=0,this.joinOption="",this.inviteOption="",this.groupCustomField=[],this.muteAllMembers=!1,this.isSupportTopic=!1,this._lastRevokedTime=0,this._initGroup(e)}_initGroup(e){for(const t in e)R.indexOf(t)<0||("selfInfo"!==t?"isSupportTopic"!==t?("memberNum"===t&&(this.memberCount=e[t]),"maxMemberNum"===t&&(this.maxMemberCount=e[t]),this[t]=e[t]):this.isSupportTopic=1===e[t]:this.updateSelfInfo(e[t]))}updateGroup(e){e.appid=void 0,e.grossTopicNextMsgSeq=void 0,e.selfInfo&&(e.selfInfo.grossTopicReadSeq=void 0);const t=JSON.parse(JSON.stringify(e));var o;t.lastMsgTime&&(this.lastMessage.lastTime=t.lastMsgTime),O(t.muteAllMembers)||(t.muteAllMembers="On"===t.muteAllMembers),t.groupCustomField&&function(e,t){if(!L(e)||!L(t))return!1;let o=!1;t.forEach((({key:t,value:i})=>{const r=e.find((e=>e.key===t));r?r.value!==i&&(r.value=i,o=!0):(e.push({key:t,value:i}),o=!0)}))}(this.groupCustomField,t.groupCustomField),O(t.memberNum)||(this.memberCount=t.memberNum),O(t.maxMemberNum)||(this.maxMemberCount=t.maxMemberNum),O(t.isSupportTopic)||(this.isSupportTopic=null!==(o=t.isSupportTopic)&&("number"==typeof o&&!Number.isNaN(o-0)||"object"==typeof o&&o.constructor===Number)?1===t.isSupportTopic:t.isSupportTopic),T(this,t,["members","errorCode","lastMsgTime","groupCustomField","memberNum","maxMemberNum","isSupportTopic"]),L(t.members)&&t.members.length>0&&t.members.forEach((e=>{e.userID===this.selfInfo.userID&&T(this.selfInfo,e,["sequence"])}))}updateSelfInfo(e){const{nameCard:t,joinTime:o,role:i,messageRemindType:r,readedSequence:s,excludedUnreadSequenceList:n}=e;T(this.selfInfo,{nameCard:t,joinTime:o,role:i,messageRemindType:r,readedSequence:s,excludedUnreadSequenceList:n},[],["",null,void 0,0,NaN])}setSelfNameCard(e){this.selfInfo.nameCard=e}}var A=new class{constructor(){this._name="GroupStore",this._groupMap=new Map}init(e){console.log(`${this._name}.init`),this._core=e}hasLocalGroup(e){return this._groupMap.has(e)}getLocalGroup(e){return this._groupMap.get(e)}updateLocalGroup(e){let t;e.forEach((e=>{t=e.groupID,this.hasLocalGroup(t)?this.getLocalGroup(t).updateGroup(e):this._groupMap.set(t,new b(e))}));const o=this._core.store.get("login").userId;for(const[,e]of this._groupMap)e.selfInfo.userID=o,"Owner"===e.selfInfo.role&&(e.ownerID=o)}deleteLocalGroup(e){this._groupMap.delete(e)}clearLocalGroup(){this._groupMap.clear()}getLocalGroupList(){return[...this._groupMap.values()]}emitGroupListUpdate(){var e;const t=this.getLocalGroupList();this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.GROUP_LIST_UPDATED,data:t})}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}};function C(e,t,o,i){return new(o||(o=Promise))((function(r,s){function n(e){try{p(i.next(e))}catch(e){s(e)}}function u(e){try{p(i.throw(e))}catch(e){s(e)}}function p(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(n,u)}p((i=i.apply(e,t||[])).next())}))}function N(e,t,o){return C(this,void 0,void 0,(function*(){const{helper:i,channel:r}=o,s=i.generateProtocolData({servcmd:e,data:t}),n=`${s.head.seq}${e}`;return yield r.sendPacket(s,{requestId:n})}))}"function"==typeof SuppressedError&&SuppressedError;const E=function(e){return{code:0,data:e||{}}};var D=new class{constructor(){this._name="GetGroupList",this._pagingStatus=l,this.PAGING_GRP_COUNT_LIMIT=200}init(e){this._core=e;const{helper:t}=e;t.registerApi("getGroupList",this)}handleLoginSuccess(){this._syncGroupList()}getGroupList(){return C(this,void 0,void 0,(function*(){if(console.log(`${this._name}.getGroupList pagingStatus:${this._pagingStatus}`),this._pagingStatus===g||this._pagingStatus===l)return this._syncGroupList().then((()=>{const e=A.getLocalGroupList();return E({groupList:e,isSyncCompleted:this._isSyncCompleted()})})).catch((e=>{throw console.error(`${this._name}.getGroupList fail:`,e),e}));const e=A.getLocalGroupList();return console.log(`${this._name}.getGroupList return group count:${e.length}`),E({groupList:e,isSyncCompleted:this._isSyncCompleted()})}))}_syncGroupList(){return C(this,void 0,void 0,(function*(){this._pagingStatus===l&&A.clearLocalGroup();const e=this.PAGING_GRP_COUNT_LIMIT,t=[];try{yield this._pagingGetGroupList({limit:e,offset:0,groupList:t}),this._pagingStatus=m,this._groupListTreeShaking(t),A.updateLocalGroup(t);const o=A.getLocalGroupList().length;return console.log(`${this._name}._syncGroupList ok, count:${o}`),A.emitGroupListUpdate(),t}catch(e){throw this._pagingStatus=g,console.error(`${this._name}._syncGroupList fail:`,e),e}}))}_pagingGetGroupList(t){return C(this,void 0,void 0,(function*(){const{isCommunityRelay:o=!1,groupList:r}=t;let n,{limit:u,offset:p}=t;const a=[...i];o&&(n=e.GRP_COMMUNITY,a.push("AtInfoList"));try{const e=yield function(e,t){return C(this,void 0,void 0,(function*(){const{type:o,limit:i,offset:r,memberAccount:s,responseFilter:n}=e;return N(o?"million_group_open_http_svc.get_joined_group_list":"group_open_http_svc.get_joined_group_list",{Limit:i,Offset:r,Member_Account:s,ResponseFilter:n,SupportTopic:0,NeedAppDefineData:1},t)}))}({type:n,limit:u,offset:p,memberAccount:this._core.store.get("login").userId,responseFilter:{GroupBaseInfoFilter:a,SelfInfoFilter:[...s]}},this._core),{GroupIdList:t=[],TotalCount:i=0}=e||{},c=this._convertGroupKey(t);r.push(...c);const l=p+u,m=!(i>l),g=`offset:${p} limit:${u} total:${i} isCompleted:${m} current:${r.length} isCommunityRelay:${o}`;return console.log(`${this._name}._pagingGetGroupList ok. ${g}`),o?m?r:(p=l,this._pagingGetGroupList({isCommunityRelay:!0,limit:u,offset:p,groupList:r})):m?(console.log(`${this._name}._pagingGetGroupList start to get community list`),p=0,this._pagingGetGroupList({isCommunityRelay:!0,limit:u,offset:p,groupList:r})):(p=l,this._pagingGetGroupList({limit:u,offset:p,groupList:r}))}catch(e){if(e.ErrorCode===_)return console.warn(`${this._name}._pagingGetGroupList response size exceeds the limit, request count:${u}`),u=50,this._pagingGetGroupList({isCommunityRelay:o,limit:u,offset:p,groupList:r});if(o)return e.code===h&&console.log(`${this._name}._pagingGetGroupList ok. community unavailable`),r;throw e}}))}_groupListTreeShaking(e){const t=new Map([...A.getLocalGroupList()]);for(let o=0,i=e.length;o<i;o++)t.delete(e[o].groupID);const o=[...t.keys()];for(let e=0,t=o.length;e<t;e++)A.deleteLocalGroup(o[e])}_isSyncCompleted(){return this._pagingStatus===m}_convertGroupKey(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{AppDefinedData:i,ApplyJoinOption:r,CreateTime:s,FaceUrl:n,GroupId:u,Introduction:p,InviteJoinOption:a,LastInfoTime:c,LastMsgTime:l,MaxMemberNum:m,MuteAllMember:g,Name:_,NextMsgSeq:h,Notification:d,Owner_Account:f,ShutUpAllMember:I,Type:G,SelfInfo:v}=e[o],y=P(i),M=this._convertSelfInfo(v);t.push({groupCustomField:y,joinOption:r,createTime:s,avatar:n,groupID:u,introduction:p,inviteOption:a,lastInfoTime:c,lastMsgTime:l,maxMemberNum:m,muteAllMember:g,name:_,nextMessageSeq:h,notification:d,ownerID:f,shutUpAllMember:I,type:G,selfInfo:M})}return t}_convertSelfInfo(e){const{JoinTime:t,MsgFlag:o,MsgSeq:i,NoUnreadSeqList:r,Role:s}=e;return{joinTime:t,messageRemindType:o,readedSequence:i,excludedUnreadSequenceList:r,role:s}}};var w=new class{constructor(){this._name="CreateGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("createGroup",this)}createGroup(e){return C(this,void 0,void 0,(function*(){var t;this._preCheckParams(e),console.log(`${this._name}.createGroup options:`,e);try{const{store:o,helper:i}=this._core,r=yield function(e,t){return C(this,void 0,void 0,(function*(){const{name:o,type:i,groupID:r,introduction:s,notification:n,avatar:u,maxMemberNum:p,joinOption:a,inviteOption:c,memberList:l,groupCustomField:m,isSupportTopic:g}=e;return N("group_open_http_svc.create_group",{Name:o,Type:i,GroupId:r,Introduction:s,Notification:n,FaceUrl:u,MaxMemberCount:p,ApplyJoinOption:a,InviteJoinOption:c,MemberList:l,AppDefinedData:m,SupportTopic:g,webPushFlag:1},t)}))}(Object.assign(Object.assign({},e),{ownerID:o.get("login").userId}),this._core),{GroupId:s,OverJoinedGroupLimit_Account:n=[]}=r||{};console.log(`${this._name}.createGroup ok, groupType:${e.type} groupID:${s} overLimitUserIDList:${n}`),i.isEmpty(e.memberList)||i.isEmpty(n)||(e.memberList=null===(t=e.memberList)||void 0===t?void 0:t.filter((e=>n.includes(e.userID)))),A.updateLocalGroup([Object.assign(Object.assign({},e),{groupID:s})]),this._needSendCustomMessage(e)&&this._sendCustomMessage(s,e.type);const u=A.getLocalGroup(s);return A.emitGroupListUpdate(),E({group:u})}catch(e){throw console.error(`${this._name}.createGroup fail:`,e),e}}))}_preCheckParams(e){const{type:t,groupID:i}=e,r=!this._core.helper.isEmpty(i);if(!o.includes(t))throw new this._core.helper.ChatError({code:d});if(!M({type:t})){if(r&&M({groupID:i}))throw new this._core.helper.ChatError({code:f});O(e.isSupportTopic)||(e.isSupportTopic=void 0)}if(this._canIUseMemberList(t)||O(e.memberList)||(e.memberList=void 0),this._canIUseJoinOption(t)||O(e.joinOption)||(e.joinOption=void 0),this._canIUseSupportTopic(t)&&!O(e.isSupportTopic)&&(e.isSupportTopic=!0===e.isSupportTopic?1:0),M({type:t})&&r&&!M({groupID:i}))throw new this._core.helper.ChatError({code:f})}_canIUseMemberList(e){return!y(e)}_canIUseJoinOption(e){return v(e)||M({type:e})}_canIUseSupportTopic(e){return M({type:e})}_needSendCustomMessage(t){return t.type!==e.GRP_AVCHATROOM&&(t.type!==e.GRP_COMMUNITY||1!==t.isSupportTopic)}_sendCustomMessage(t,o){var i,r,s,n,a,c;let l="Create Group",m=u;o===e.GRP_COMMUNITY&&(l="Create Community",m=p);const g={to:t,conversationType:"GROUP",payload:{data:JSON.stringify({businessID:"group_create",content:l,cmd:m,opUser:this._core.store.get("login").userId,version:4})}},_=null===(s=null===(r=null===(i=this._core)||void 0===i?void 0:i.message)||void 0===r?void 0:r.messageFactory)||void 0===s?void 0:s.createCustomMessage(g);null===(c=null===(a=null===(n=this._core)||void 0===n?void 0:n.message)||void 0===a?void 0:a.messageSender)||void 0===c||c.sendMessage(_,{})}};var U=new class{constructor(){this._name="DismissGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("dismissGroup",this)}dismissGroup(e){return C(this,void 0,void 0,(function*(){console.log(`${this._name}.dismissGroup groupID:${e}`);try{return yield function(e,t){return C(this,void 0,void 0,(function*(){return N("group_open_http_svc.destroy_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.dismissGroup ok.`),A.deleteLocalGroup(e),A.emitGroupListUpdate(),E({groupID:e})}catch(e){throw console.error(`${this._name}.dismissGroup fail:`,e),e}}))}};var F=new class{constructor(){this._name="GetGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi("getGroupProfile",this)}getGroupProfile(e){return C(this,void 0,void 0,(function*(){const{groupID:t,groupCustomFieldFilter:o}=e,r={groupIDList:[t],responseFilter:{GroupBaseInfoFilter:[...i],AppDefinedDataFilter_Group:o,MemberInfoFilter:[...n]}};try{const e=yield this.getGroupProfileAdvance(r),{successGroupList:o,failureGroupList:i}=e;if(i.length>0)throw i[0];let s;return!A.hasLocalGroup(t)&&y(o[0].type)?s=new b(o[0]):(A.updateLocalGroup(o),s=A.getLocalGroup(t)),console.log(`${this._name}.getGroupProfile ok.`),E({group:s})}catch(e){throw console.error(`${this._name}.getGroupProfile fail:`,e),e}}))}getGroupProfileAdvance(e){return C(this,void 0,void 0,(function*(){const{groupIDList:t}=e,o=t.filter((e=>!M({groupID:e}))),i=t.filter((e=>M({groupID:e})));o.length>50&&(o.length=50),i.length>50&&(i.length=50);const r=yield Promise.all([this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:o})),this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:i,isCommunityProfile:!0}))]),s=[],n=[];return r.forEach((e=>{s.push(...e.successGroupList),n.push(...e.failureGroupList)})),{successGroupList:s,failureGroupList:n}}))}_getGroupProfileAdvance(e){return C(this,void 0,void 0,(function*(){const{isCommunityProfile:t=!1}=e,o=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(o[i[r]]=e[i[r]])}return o}(e,["isCommunityProfile"]);if(0===o.groupIDList.length)return{successGroupList:[],failureGroupList:[]};try{const e=yield function(e,t){return C(this,void 0,void 0,(function*(){const{groupIDList:o,responseFilter:i}=e;return N("group_open_http_svc.get_group_self_member_info",{GroupIdList:o,ResponseFilter:i},t)}))}(o,this._core),{GroupInfo:t=[]}=e||{},i=this._convertGroupProfileKey(t),r=i.filter((e=>O(e.errorCode)||0===e.errorCode)),s=i.filter((e=>e.errorCode&&0!==e.errorCode)).map((e=>({code:e.errorCode,message:e.errorInfo,data:{groupID:e.groupID}})));return console.log(`${this._name}._getGroupProfileAdvance ok, groupID:${o.groupIDList.join(",")}`),{successGroupList:r,failureGroupList:s}}catch(e){if(t)return{successGroupList:[],failureGroupList:[]};throw e}}))}_convertGroupProfileKey(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{AppDefinedData:i,ApplyJoinOption:r,CreateTime:s,FaceUrl:n,GroupId:u,InfoSeq:p,Introduction:a,InviteJoinOption:c,LastInfoTime:l,LastMsgTime:m,MaxMemberNum:g,MemberNum:_,MuteAllMember:h,Name:d,NextMsgSeq:f,Notification:I,Owner_Account:G,ShutUpAllMember:v,ShutUpUntil:y,Type:M,MemberList:O,ErrorCode:L,ErrorInfo:S}=e[o],T=P(i),R=this._convertMembers(O);t.push({groupCustomField:T,joinOption:r,createTime:s,avatar:n,groupID:u,infoSequence:p,introduction:a,inviteOption:c,lastInfoTime:l,lastMsgTime:m,maxMemberNum:g,memberNum:_,muteAllMember:h,name:d,nextMessageSeq:f,notification:I,ownerID:G,shutUpAllMember:v,muteUntil:y,type:M,members:R,errorCode:L,errorInfo:S})}return t}_convertMembers(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{AppMemberDefinedData:i,JoinTime:r,Member_Account:s,MsgFlag:n,MsgSeq:u,NameCard:p,Role:a}=e[o],c=P(i);t.push({memberCustomField:c,joinTime:r,userID:s,messageRemindType:n,sequence:u,nameCard:p,role:a})}return t}};var $=new class{constructor(){this._name="JoinGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("joinGroup",this)}joinGroup(e){return C(this,void 0,void 0,(function*(){const{groupID:o}=e;try{if(A.hasLocalGroup(o))try{return yield F.getGroupProfile({groupID:o}),E({status:t.JOIN_STATUS_SUCCESS})}catch(t){console.warn(`${this._name}.joinGroup ${o} was unjoined, start to join!`),A.deleteLocalGroup(o);return yield this._applyJoinGroup(e)}return yield this._applyJoinGroup(e)}catch(e){throw console.error(`${this._name}.joinGroup fail:`,e),e}}))}_applyJoinGroup(e){return C(this,void 0,void 0,(function*(){const o=Object.assign({},e),i=yield function(e,t){return C(this,void 0,void 0,(function*(){const{groupID:o,applyMessage:i,historyMessageFlag:r}=e;return N("group_open_http_svc.apply_join_group",{GroupId:o,ApplyMsg:i,HugeGroupHistoryMsgFlag:r},t)}))}(o,this._core),{JoinedStatus:r,LongPollingKey:s,StartSeq:n,HugeGroupFlag:u,AVChatRoomKey:p,RspMsgList:a}=i||{},c=`groupID:${e.groupID} joinedStatus:${r} longPollingKey:${s} startSeq:${n} avChatRoomFlag:${u} canGetAVChatRoomHistoryMsg:false, historyMsgCount:${(null==a?void 0:a.length)||0}`;if(console.log(`${this._name}._applyJoinGroup ok, ${c}`),r===t.JOIN_STATUS_WAIT_APPROVAL)return{code:0,data:{status:t.JOIN_STATUS_WAIT_APPROVAL}};if(r===t.JOIN_STATUS_SUCCESS)return this._handleJoinResult({group:new b({groupID:e.groupID}),avChatRoomFlag:u,longPollingKey:s,startSeq:n,avChatRoomKey:p,messageList:a});throw new this._core.helper.ChatError({code:G})}))}_handleJoinResult(e){const{group:o,avChatRoomFlag:i}=e;return 1===i?{}:(A.updateLocalGroup([o]),A.emitGroupListUpdate(),E({status:t.JOIN_STATUS_SUCCESS,group:o}))}};var j=new class{constructor(){this._name="QuitGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("quitGroup",this)}quitGroup(e){return C(this,void 0,void 0,(function*(){if(console.log(`${this._name}.quitGroup groupID:${e}`),!A.hasLocalGroup(e))throw new this._core.helper.ChatError({code:I});try{return yield function(e,t){return C(this,void 0,void 0,(function*(){return N("group_open_http_svc.quit_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.quitGroup ok.`),A.deleteLocalGroup(e),A.emitGroupListUpdate(),E({groupID:e})}catch(e){throw console.error(`${this._name}.quitGroup fail:`,e),e}}))}};var q=new class{constructor(){this._name="SearchGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("searchGroupByID",this)}searchGroupByID(e){return C(this,void 0,void 0,(function*(){console.log(`${this._name}.searchGroupByID groupID:${e}`);try{const t=yield function(e,t){return C(this,void 0,void 0,(function*(){return N("group_open_http_svc.get_group_public_info",{GroupIdList:[e],GroupBasePublicInfoFilter:[...r]},t)}))}(e,this._core),{GroupInfo:o=[]}=t||{},{AppDefinedData:i=[],ApplyJoinOption:s,CreateTime:n,FaceUrl:u,Introduction:p,InviteJoinOption:a,MaxMemberNum:c,MemberNum:l,Name:m,Owner_Account:g,Type:_,ErrorCode:h,ErrorInfo:d}=o[0];if(0!==h)throw new this._core.helper.ChatError({code:h,message:d});console.log(`${this._name}.searchGroupByID ok.`);const f=P(i),I=new b({groupID:e,name:m,avatar:u,introduction:p,joinOption:s,inviteOption:a,maxMemberNum:c,memberNum:l,type:_,ownerID:g,createTime:n,groupCustomField:f});return E({group:I})}catch(e){throw console.error(`${this._name}.searchGroupByID fail:`,e),e}}))}};var J=new class{constructor(){this._name="UpdateGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi("updateGroupProfile",this)}updateGroupProfile(e){return C(this,void 0,void 0,(function*(){const{groupID:t}=e;let o=A.getLocalGroup(t);if(o){const{type:t}=o;this._canIUseJoinOption(t)||O(e.joinOption)||(console.warn(`${this._name}.updateGroupProfile joinOption is unavailable for Work/Meeting/AVChatRoom`),e.joinOption=void 0)}O(e.muteAllMembers)||(e.muteAllMembers=!0===e.muteAllMembers?"On":"Off");try{return yield function(e,t){return C(this,void 0,void 0,(function*(){const{groupID:o,name:i,avatar:r,introduction:s,notification:n,muteAllMembers:u,joinOption:p,inviteOption:a,groupCustomField:c}=e;return N("group_open_http_svc.modify_group_base_info",{GroupId:o,Name:i,FaceUrl:r,Introduction:s,Notification:n,ShutUpAllMember:u,ApplyJoinOption:p,InviteJoinOption:a,AppDefinedData:c?function(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{key:i,value:r}=e[o];t.push({Key:i,Value:r})}return t}(c):void 0},t)}))}(e,this._core),console.log(`${this._name}.updateGroupProfile groupID:${t} ok.`),o?(o.updateGroup(e),A.emitGroupListUpdate()):o=new b(e),E({group:o})}catch(e){throw console.error(`${this._name}.updateGroupProfile groupID:${t} fail:`,e),e}}))}_canIUseJoinOption(e){return v(e)||M({type:e})}};var x=new class{init(e){console.log("GroupAction.init"),D.init(e),w.init(e),U.init(e),$.init(e),j.init(e),q.init(e),F.init(e),J.init(e)}handleLoginSuccess(){D.handleLoginSuccess()}};var B=new class{init(e){this._core=e}};var k=new class{init(e){this._core=e}};var V=new class{init(e){this._core=e}};const K={createGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1}},dismissGroup:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}],joinGroup:{groupID:{required:!0,rules:["string"],allowEmpty:!1},applyMessage:{required:!1,rules:["string"],allowEmpty:!0}},quitGroup:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}],searchGroupByID:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}],getGroupProfile:{groupID:{required:!0,rules:["string"],allowEmpty:!1},groupCustomFieldFilter:{required:!1,rules:["Array<string>"],allowEmpty:!0}},updateGroupProfile:{groupID:{required:!0,rules:["string"],allowEmpty:!1},muteAllMembers:{required:!1,rules:["boolean"],allowEmpty:!1}}},H={getGroupList:!0,createGroup:!0,dismissGroup:!0,joinGroup:!0,quitGroup:!0,searchGroupByID:!0,getGroupProfile:!0,updateGroupProfile:!0,getGroupApplicationList:!0};var W=new class{install(e){this._core=e,A.init(e),x.init(e),B.init(e),k.init(e),V.init(e),e.helper.registerValidateConfig({auth:H,params:K});const{notificationCenter:t,InnerEvent:o}=e;t.subscribeInnerEvent(o.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(o.DESTROY,this._dispose,this)}handleLoginSuccess(){x.handleLoginSuccess()}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGIN,this.handleLoginSuccess,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{W as default};
1
+ function r(r,o,t,e){return new(t||(t=Promise))((function(i,n){function s(r){try{a(e.next(r))}catch(r){n(r)}}function c(r){try{a(e.throw(r))}catch(r){n(r)}}function a(r){var o;r.done?i(r.value):(o=r.value,o instanceof t?o:new t((function(r){r(o)}))).then(s,c)}a((e=e.apply(r,o||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o="group";var t=new class{init(r){this._core=r;const{helper:o}=r;o.registerApi("searchGroupByID",this),o.registerApi("getGroupList",this),o.registerApi("getGroupApplicationList",this)}searchGroupByID(t){return r(this,void 0,void 0,(function*(){try{console.log(`${o} searchGroupByID: groupID: ${t}`);const e=yield function(o,t){return r(this,void 0,void 0,(function*(){try{const{helper:r,channel:e}=t,i="group_open_http_svc.get_group_public_info",n={GroupIdList:[o]},s=r.generateProtocolData({servcmd:i,data:n}),c=`${s.head.seq}${i}`;return yield e.sendPacket(s,{requestId:c})}catch(r){throw console.warn("searchGroupByID error:",r),r}}))}(t,this._core);return this._parseSearchGroupByIDResponse(e),{code:0,data:{group:{groupID:t}}}}catch(r){throw console.warn(`${o} searchGroupByID error:`,r),r}}))}getGroupList(){return r(this,void 0,void 0,(function*(){return console.log(`${o} getGroupList`),{code:0,data:{groupList:[]}}}))}getGroupApplicationList(){return r(this,void 0,void 0,(function*(){return console.log(`${o} getGroupApplicationList`),{code:0,data:{applicationList:[]}}}))}_parseSearchGroupByIDResponse(r){var o;const t=null===(o=r.GroupInfo)||void 0===o?void 0:o[0];if(0!==(null==t?void 0:t.ErrorCode))throw new this._core.helper.ChatError({functionName:"searchGroupByID",code:null==t?void 0:t.ErrorCode,message:null==t?void 0:t.ErrorCode});return r}};var e=new class{init(r){this._core=r}};var i=new class{init(r){this._core=r}};var n=new class{init(r){this._core=r}};var s=new class{init(r){this._core=r}};const c={searchGroupByID:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}]},a={getGroupList:!0,searchGroupByID:!0,getGroupApplicationList:!0};var u=new class{install(r){t.init(r),e.init(r),i.init(r),n.init(r),s.init(r),r.helper.registerValidateConfig({auth:a,params:c})}};export{u as default};
package/plugins/group.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).liteChatGroup=t()}(this,(function(){"use strict";const e={GRP_WORK:"Private",GRP_PUBLIC:"Public",GRP_MEETING:"ChatRoom",GRP_AVCHATROOM:"AVChatRoom",GRP_COMMUNITY:"Community",GRP_ROOM:"Room",GRP_LIVE:"Live"},t={JOIN_OPTIONS_FREE_ACCESS:"FreeAccess",JOIN_OPTIONS_NEED_PERMISSION:"NeedPermission",JOIN_OPTIONS_DISABLE_APPLY:"DisableApply",JOIN_STATUS_SUCCESS:"JoinedSuccess",JOIN_STATUS_ALREADY_IN_GROUP:"AlreadyInGroup",JOIN_STATUS_WAIT_APPROVAL:"WaitAdminApproval"};Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e),{GRP_MBR_ROLE_OWNER:"Owner",GRP_MBR_ROLE_ADMIN:"Admin",GRP_MBR_ROLE_MEMBER:"Member",GRP_MBR_ROLE_CUSTOM:"Custom"}),{GRP_TIP_MBR_JOIN:1,GRP_TIP_MBR_QUIT:2,GRP_TIP_MBR_KICKED_OUT:3,GRP_TIP_MBR_SET_ADMIN:4,GRP_TIP_MBR_CANCELED_ADMIN:5,GRP_TIP_GRP_PROFILE_UPDATED:6,GRP_TIP_MBR_PROFILE_UPDATED:7,GRP_TIP_BAN_AVCHATROOM_MEMBER:10,GRP_TIP_UNBAN_AVCHATROOM_MEMBER:11}),t),{INVITE_OPTIONS_DISABLE_INVITE:"DisableInvite",INVITE_OPTIONS_NEED_PERMISSION:"NeedPermission",INVITE_OPTIONS_FREE_ACCESS:"FreeAccess"}),{GRP_PROFILE_OWNER_ID:"ownerID",GRP_PROFILE_CREATE_TIME:"createTime",GRP_PROFILE_LAST_INFO_TIME:"lastInfoTime",GRP_PROFILE_MEMBER_NUM:"memberNum",GRP_PROFILE_MAX_MEMBER_NUM:"maxMemberNum",GRP_PROFILE_JOIN_OPTION:"joinOption",GRP_PROFILE_INVITE_OPTION:"inviteOption",GRP_PROFILE_INTRODUCTION:"introduction",GRP_PROFILE_NOTIFICATION:"notification",GRP_PROFILE_MUTE_ALL_MBRS:"muteAllMembers"});const o=[e.GRP_PUBLIC,e.GRP_WORK,e.GRP_MEETING,e.GRP_AVCHATROOM,e.GRP_COMMUNITY],i=["Type","Name","Introduction","Notification","FaceUrl","Owner_Account","CreateTime","InfoSeq","LastInfoTime","LastMsgTime","MemberNum","MaxMemberNum","ApplyJoinOption","NextMsgSeq","ShutUpAllMember","InviteJoinOption"],r=["Type","Name","Introduction","Notification","FaceUrl","CreateTime","Owner_Account","LastInfoTime","LastMsgTime","NextMsgSeq","MemberNum","MaxMemberNum","ApplyJoinOption","InviteJoinOption"],n=["Role","JoinTime","MsgFlag","MsgSeq"],s=["Role","JoinTime","MsgSeq","MsgFlag","NameCard"],u=0,p=1,a="@TGS#_",c="@TOPIC#_",l="notStart",m="resolved",g="rejected",h=10018,_=11e3,d=2600,f=2602,I=2623,G=2660,y=t=>t===e.GRP_PUBLIC,v=t=>t===e.GRP_AVCHATROOM,M=({type:t,groupID:o})=>t===e.GRP_COMMUNITY||`${o}`.startsWith(a)&&!`${o}`.includes(c),O=e=>void 0===e,L=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),T=e=>L(e)||(e=>null!==e&&"object"==typeof e)(e),S=(e,t,o,i)=>{if(!T(e)||!T(t))return 0;let r=0;const n=Object.keys(t);let s;for(let u=0,p=n.length;u<p;u++)if(s=n[u],!(O(t[s])||o&&o.includes(s)))if(T(e[s])&&T(t[s]))r+=S(e[s],t[s],o,i);else{if(i&&i.includes(t[s]))continue;e[s]!==t[s]&&(e[s]=t[s],r+=1)}return r};function P(e){const t=[];if(!e)return t;for(let o=0,i=e.length;o<i;o++){const{Key:i,Value:r}=e[o];t.push({key:i,value:r})}return t}const b=["groupID","name","avatar","type","introduction","notification","ownerID","selfInfo","createTime","infoSequence","lastInfoTime","lastMessage","nextMessageSeq","memberNum","maxMemberNum","memberList","joinOption","groupCustomField","muteAllMembers","isSupportTopic","inviteOption","_lastRevokedTime"];class R{constructor(e){this.groupID="",this.name="",this.avatar="",this.type="",this.introduction="",this.notification="",this.ownerID="",this.createTime=0,this.selfInfo={messageRemindType:"",joinTime:"",nameCard:"",role:"",userID:"",memberCustomField:void 0,readedSequence:0,excludedUnreadSequenceList:void 0},this.lastMessage={lastTime:0,lastSequence:0,fromAccount:"",messageForShow:""},this.nextMessageSeq=0,this.memberNum=0,this.memberCount=0,this.maxMemberNum=0,this.maxMemberCount=0,this.joinOption="",this.inviteOption="",this.groupCustomField=[],this.muteAllMembers=!1,this.isSupportTopic=!1,this._lastRevokedTime=0,this._initGroup(e)}_initGroup(e){for(const t in e)b.indexOf(t)<0||("selfInfo"!==t?"isSupportTopic"!==t?("memberNum"===t&&(this.memberCount=e[t]),"maxMemberNum"===t&&(this.maxMemberCount=e[t]),this[t]=e[t]):this.isSupportTopic=1===e[t]:this.updateSelfInfo(e[t]))}updateGroup(e){e.appid=void 0,e.grossTopicNextMsgSeq=void 0,e.selfInfo&&(e.selfInfo.grossTopicReadSeq=void 0);const t=JSON.parse(JSON.stringify(e));var o;t.lastMsgTime&&(this.lastMessage.lastTime=t.lastMsgTime),O(t.muteAllMembers)||(t.muteAllMembers="On"===t.muteAllMembers),t.groupCustomField&&function(e,t){if(!L(e)||!L(t))return!1;let o=!1;t.forEach((({key:t,value:i})=>{const r=e.find((e=>e.key===t));r?r.value!==i&&(r.value=i,o=!0):(e.push({key:t,value:i}),o=!0)}))}(this.groupCustomField,t.groupCustomField),O(t.memberNum)||(this.memberCount=t.memberNum),O(t.maxMemberNum)||(this.maxMemberCount=t.maxMemberNum),O(t.isSupportTopic)||(this.isSupportTopic=null!==(o=t.isSupportTopic)&&("number"==typeof o&&!Number.isNaN(o-0)||"object"==typeof o&&o.constructor===Number)?1===t.isSupportTopic:t.isSupportTopic),S(this,t,["members","errorCode","lastMsgTime","groupCustomField","memberNum","maxMemberNum","isSupportTopic"]),L(t.members)&&t.members.length>0&&t.members.forEach((e=>{e.userID===this.selfInfo.userID&&S(this.selfInfo,e,["sequence"])}))}updateSelfInfo(e){const{nameCard:t,joinTime:o,role:i,messageRemindType:r,readedSequence:n,excludedUnreadSequenceList:s}=e;S(this.selfInfo,{nameCard:t,joinTime:o,role:i,messageRemindType:r,readedSequence:n,excludedUnreadSequenceList:s},[],["",null,void 0,0,NaN])}setSelfNameCard(e){this.selfInfo.nameCard=e}}var A=new class{constructor(){this._name="GroupStore",this._groupMap=new Map}init(e){console.log(`${this._name}.init`),this._core=e}hasLocalGroup(e){return this._groupMap.has(e)}getLocalGroup(e){return this._groupMap.get(e)}updateLocalGroup(e){let t;e.forEach((e=>{t=e.groupID,this.hasLocalGroup(t)?this.getLocalGroup(t).updateGroup(e):this._groupMap.set(t,new R(e))}));const o=this._core.store.get("login").userId;for(const[,e]of this._groupMap)e.selfInfo.userID=o,"Owner"===e.selfInfo.role&&(e.ownerID=o)}deleteLocalGroup(e){this._groupMap.delete(e)}clearLocalGroup(){this._groupMap.clear()}getLocalGroupList(){return[...this._groupMap.values()]}emitGroupListUpdate(){var e;const t=this.getLocalGroupList();this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.GROUP_LIST_UPDATED,data:t})}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}};function C(e,t,o,i){return new(o||(o=Promise))((function(r,n){function s(e){try{p(i.next(e))}catch(e){n(e)}}function u(e){try{p(i.throw(e))}catch(e){n(e)}}function p(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,u)}p((i=i.apply(e,t||[])).next())}))}function N(e,t,o){return C(this,void 0,void 0,(function*(){const{helper:i,channel:r}=o,n=i.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield r.sendPacket(n,{requestId:s})}))}"function"==typeof SuppressedError&&SuppressedError;const E=function(e){return{code:0,data:e||{}}};var D=new class{constructor(){this._name="GetGroupList",this._pagingStatus=l,this.PAGING_GRP_COUNT_LIMIT=200}init(e){this._core=e;const{helper:t}=e;t.registerApi("getGroupList",this)}handleLoginSuccess(){this._syncGroupList()}getGroupList(){return C(this,void 0,void 0,(function*(){if(console.log(`${this._name}.getGroupList pagingStatus:${this._pagingStatus}`),this._pagingStatus===g||this._pagingStatus===l)return this._syncGroupList().then((()=>{const e=A.getLocalGroupList();return E({groupList:e,isSyncCompleted:this._isSyncCompleted()})})).catch((e=>{throw console.error(`${this._name}.getGroupList fail:`,e),e}));const e=A.getLocalGroupList();return console.log(`${this._name}.getGroupList return group count:${e.length}`),E({groupList:e,isSyncCompleted:this._isSyncCompleted()})}))}_syncGroupList(){return C(this,void 0,void 0,(function*(){this._pagingStatus===l&&A.clearLocalGroup();const e=this.PAGING_GRP_COUNT_LIMIT,t=[];try{yield this._pagingGetGroupList({limit:e,offset:0,groupList:t}),this._pagingStatus=m,this._groupListTreeShaking(t),A.updateLocalGroup(t);const o=A.getLocalGroupList().length;return console.log(`${this._name}._syncGroupList ok, count:${o}`),A.emitGroupListUpdate(),t}catch(e){throw this._pagingStatus=g,console.error(`${this._name}._syncGroupList fail:`,e),e}}))}_pagingGetGroupList(t){return C(this,void 0,void 0,(function*(){const{isCommunityRelay:o=!1,groupList:r}=t;let s,{limit:u,offset:p}=t;const a=[...i];o&&(s=e.GRP_COMMUNITY,a.push("AtInfoList"));try{const e=yield function(e,t){return C(this,void 0,void 0,(function*(){const{type:o,limit:i,offset:r,memberAccount:n,responseFilter:s}=e;return N(o?"million_group_open_http_svc.get_joined_group_list":"group_open_http_svc.get_joined_group_list",{Limit:i,Offset:r,Member_Account:n,ResponseFilter:s,SupportTopic:0,NeedAppDefineData:1},t)}))}({type:s,limit:u,offset:p,memberAccount:this._core.store.get("login").userId,responseFilter:{GroupBaseInfoFilter:a,SelfInfoFilter:[...n]}},this._core),{GroupIdList:t=[],TotalCount:i=0}=e||{},c=this._convertGroupKey(t);r.push(...c);const l=p+u,m=!(i>l),g=`offset:${p} limit:${u} total:${i} isCompleted:${m} current:${r.length} isCommunityRelay:${o}`;return console.log(`${this._name}._pagingGetGroupList ok. ${g}`),o?m?r:(p=l,this._pagingGetGroupList({isCommunityRelay:!0,limit:u,offset:p,groupList:r})):m?(console.log(`${this._name}._pagingGetGroupList start to get community list`),p=0,this._pagingGetGroupList({isCommunityRelay:!0,limit:u,offset:p,groupList:r})):(p=l,this._pagingGetGroupList({limit:u,offset:p,groupList:r}))}catch(e){if(e.ErrorCode===h)return console.warn(`${this._name}._pagingGetGroupList response size exceeds the limit, request count:${u}`),u=50,this._pagingGetGroupList({isCommunityRelay:o,limit:u,offset:p,groupList:r});if(o)return e.code===_&&console.log(`${this._name}._pagingGetGroupList ok. community unavailable`),r;throw e}}))}_groupListTreeShaking(e){const t=new Map([...A.getLocalGroupList()]);for(let o=0,i=e.length;o<i;o++)t.delete(e[o].groupID);const o=[...t.keys()];for(let e=0,t=o.length;e<t;e++)A.deleteLocalGroup(o[e])}_isSyncCompleted(){return this._pagingStatus===m}_convertGroupKey(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{AppDefinedData:i,ApplyJoinOption:r,CreateTime:n,FaceUrl:s,GroupId:u,Introduction:p,InviteJoinOption:a,LastInfoTime:c,LastMsgTime:l,MaxMemberNum:m,MuteAllMember:g,Name:h,NextMsgSeq:_,Notification:d,Owner_Account:f,ShutUpAllMember:I,Type:G,SelfInfo:y}=e[o],v=P(i),M=this._convertSelfInfo(y);t.push({groupCustomField:v,joinOption:r,createTime:n,avatar:s,groupID:u,introduction:p,inviteOption:a,lastInfoTime:c,lastMsgTime:l,maxMemberNum:m,muteAllMember:g,name:h,nextMessageSeq:_,notification:d,ownerID:f,shutUpAllMember:I,type:G,selfInfo:M})}return t}_convertSelfInfo(e){const{JoinTime:t,MsgFlag:o,MsgSeq:i,NoUnreadSeqList:r,Role:n}=e;return{joinTime:t,messageRemindType:o,readedSequence:i,excludedUnreadSequenceList:r,role:n}}};var w=new class{constructor(){this._name="CreateGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("createGroup",this)}createGroup(e){return C(this,void 0,void 0,(function*(){var t;this._preCheckParams(e),console.log(`${this._name}.createGroup options:`,e);try{const{store:o,helper:i}=this._core,r=yield function(e,t){return C(this,void 0,void 0,(function*(){const{name:o,type:i,groupID:r,introduction:n,notification:s,avatar:u,maxMemberNum:p,joinOption:a,inviteOption:c,memberList:l,groupCustomField:m,isSupportTopic:g}=e;return N("group_open_http_svc.create_group",{Name:o,Type:i,GroupId:r,Introduction:n,Notification:s,FaceUrl:u,MaxMemberCount:p,ApplyJoinOption:a,InviteJoinOption:c,MemberList:l,AppDefinedData:m,SupportTopic:g,webPushFlag:1},t)}))}(Object.assign(Object.assign({},e),{ownerID:o.get("login").userId}),this._core),{GroupId:n,OverJoinedGroupLimit_Account:s=[]}=r||{};console.log(`${this._name}.createGroup ok, groupType:${e.type} groupID:${n} overLimitUserIDList:${s}`),i.isEmpty(e.memberList)||i.isEmpty(s)||(e.memberList=null===(t=e.memberList)||void 0===t?void 0:t.filter((e=>s.includes(e.userID)))),A.updateLocalGroup([Object.assign(Object.assign({},e),{groupID:n})]),this._needSendCustomMessage(e)&&this._sendCustomMessage(n,e.type);const u=A.getLocalGroup(n);return A.emitGroupListUpdate(),E({group:u})}catch(e){throw console.error(`${this._name}.createGroup fail:`,e),e}}))}_preCheckParams(e){const{type:t,groupID:i}=e,r=!this._core.helper.isEmpty(i);if(!o.includes(t))throw new this._core.helper.ChatError({code:d});if(!M({type:t})){if(r&&M({groupID:i}))throw new this._core.helper.ChatError({code:f});O(e.isSupportTopic)||(e.isSupportTopic=void 0)}if(this._canIUseMemberList(t)||O(e.memberList)||(e.memberList=void 0),this._canIUseJoinOption(t)||O(e.joinOption)||(e.joinOption=void 0),this._canIUseSupportTopic(t)&&!O(e.isSupportTopic)&&(e.isSupportTopic=!0===e.isSupportTopic?1:0),M({type:t})&&r&&!M({groupID:i}))throw new this._core.helper.ChatError({code:f})}_canIUseMemberList(e){return!v(e)}_canIUseJoinOption(e){return y(e)||M({type:e})}_canIUseSupportTopic(e){return M({type:e})}_needSendCustomMessage(t){return t.type!==e.GRP_AVCHATROOM&&(t.type!==e.GRP_COMMUNITY||1!==t.isSupportTopic)}_sendCustomMessage(t,o){var i,r,n,s,a,c;let l="Create Group",m=u;o===e.GRP_COMMUNITY&&(l="Create Community",m=p);const g={to:t,conversationType:"GROUP",payload:{data:JSON.stringify({businessID:"group_create",content:l,cmd:m,opUser:this._core.store.get("login").userId,version:4})}},h=null===(n=null===(r=null===(i=this._core)||void 0===i?void 0:i.message)||void 0===r?void 0:r.messageFactory)||void 0===n?void 0:n.createCustomMessage(g);null===(c=null===(a=null===(s=this._core)||void 0===s?void 0:s.message)||void 0===a?void 0:a.messageSender)||void 0===c||c.sendMessage(h,{})}};var U=new class{constructor(){this._name="DismissGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("dismissGroup",this)}dismissGroup(e){return C(this,void 0,void 0,(function*(){console.log(`${this._name}.dismissGroup groupID:${e}`);try{return yield function(e,t){return C(this,void 0,void 0,(function*(){return N("group_open_http_svc.destroy_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.dismissGroup ok.`),A.deleteLocalGroup(e),A.emitGroupListUpdate(),E({groupID:e})}catch(e){throw console.error(`${this._name}.dismissGroup fail:`,e),e}}))}};var F=new class{constructor(){this._name="GetGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi("getGroupProfile",this)}getGroupProfile(e){return C(this,void 0,void 0,(function*(){const{groupID:t,groupCustomFieldFilter:o}=e,r={groupIDList:[t],responseFilter:{GroupBaseInfoFilter:[...i],AppDefinedDataFilter_Group:o,MemberInfoFilter:[...s]}};try{const e=yield this.getGroupProfileAdvance(r),{successGroupList:o,failureGroupList:i}=e;if(i.length>0)throw i[0];let n;return!A.hasLocalGroup(t)&&v(o[0].type)?n=new R(o[0]):(A.updateLocalGroup(o),n=A.getLocalGroup(t)),console.log(`${this._name}.getGroupProfile ok.`),E({group:n})}catch(e){throw console.error(`${this._name}.getGroupProfile fail:`,e),e}}))}getGroupProfileAdvance(e){return C(this,void 0,void 0,(function*(){const{groupIDList:t}=e,o=t.filter((e=>!M({groupID:e}))),i=t.filter((e=>M({groupID:e})));o.length>50&&(o.length=50),i.length>50&&(i.length=50);const r=yield Promise.all([this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:o})),this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:i,isCommunityProfile:!0}))]),n=[],s=[];return r.forEach((e=>{n.push(...e.successGroupList),s.push(...e.failureGroupList)})),{successGroupList:n,failureGroupList:s}}))}_getGroupProfileAdvance(e){return C(this,void 0,void 0,(function*(){const{isCommunityProfile:t=!1}=e,o=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(o[i[r]]=e[i[r]])}return o}(e,["isCommunityProfile"]);if(0===o.groupIDList.length)return{successGroupList:[],failureGroupList:[]};try{const e=yield function(e,t){return C(this,void 0,void 0,(function*(){const{groupIDList:o,responseFilter:i}=e;return N("group_open_http_svc.get_group_self_member_info",{GroupIdList:o,ResponseFilter:i},t)}))}(o,this._core),{GroupInfo:t=[]}=e||{},i=this._convertGroupProfileKey(t),r=i.filter((e=>O(e.errorCode)||0===e.errorCode)),n=i.filter((e=>e.errorCode&&0!==e.errorCode)).map((e=>({code:e.errorCode,message:e.errorInfo,data:{groupID:e.groupID}})));return console.log(`${this._name}._getGroupProfileAdvance ok, groupID:${o.groupIDList.join(",")}`),{successGroupList:r,failureGroupList:n}}catch(e){if(t)return{successGroupList:[],failureGroupList:[]};throw e}}))}_convertGroupProfileKey(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{AppDefinedData:i,ApplyJoinOption:r,CreateTime:n,FaceUrl:s,GroupId:u,InfoSeq:p,Introduction:a,InviteJoinOption:c,LastInfoTime:l,LastMsgTime:m,MaxMemberNum:g,MemberNum:h,MuteAllMember:_,Name:d,NextMsgSeq:f,Notification:I,Owner_Account:G,ShutUpAllMember:y,ShutUpUntil:v,Type:M,MemberList:O,ErrorCode:L,ErrorInfo:T}=e[o],S=P(i),b=this._convertMembers(O);t.push({groupCustomField:S,joinOption:r,createTime:n,avatar:s,groupID:u,infoSequence:p,introduction:a,inviteOption:c,lastInfoTime:l,lastMsgTime:m,maxMemberNum:g,memberNum:h,muteAllMember:_,name:d,nextMessageSeq:f,notification:I,ownerID:G,shutUpAllMember:y,muteUntil:v,type:M,members:b,errorCode:L,errorInfo:T})}return t}_convertMembers(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{AppMemberDefinedData:i,JoinTime:r,Member_Account:n,MsgFlag:s,MsgSeq:u,NameCard:p,Role:a}=e[o],c=P(i);t.push({memberCustomField:c,joinTime:r,userID:n,messageRemindType:s,sequence:u,nameCard:p,role:a})}return t}};var $=new class{constructor(){this._name="JoinGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("joinGroup",this)}joinGroup(e){return C(this,void 0,void 0,(function*(){const{groupID:o}=e;try{if(A.hasLocalGroup(o))try{return yield F.getGroupProfile({groupID:o}),E({status:t.JOIN_STATUS_SUCCESS})}catch(t){console.warn(`${this._name}.joinGroup ${o} was unjoined, start to join!`),A.deleteLocalGroup(o);return yield this._applyJoinGroup(e)}return yield this._applyJoinGroup(e)}catch(e){throw console.error(`${this._name}.joinGroup fail:`,e),e}}))}_applyJoinGroup(e){return C(this,void 0,void 0,(function*(){const o=Object.assign({},e),i=yield function(e,t){return C(this,void 0,void 0,(function*(){const{groupID:o,applyMessage:i,historyMessageFlag:r}=e;return N("group_open_http_svc.apply_join_group",{GroupId:o,ApplyMsg:i,HugeGroupHistoryMsgFlag:r},t)}))}(o,this._core),{JoinedStatus:r,LongPollingKey:n,StartSeq:s,HugeGroupFlag:u,AVChatRoomKey:p,RspMsgList:a}=i||{},c=`groupID:${e.groupID} joinedStatus:${r} longPollingKey:${n} startSeq:${s} avChatRoomFlag:${u} canGetAVChatRoomHistoryMsg:false, historyMsgCount:${(null==a?void 0:a.length)||0}`;if(console.log(`${this._name}._applyJoinGroup ok, ${c}`),r===t.JOIN_STATUS_WAIT_APPROVAL)return{code:0,data:{status:t.JOIN_STATUS_WAIT_APPROVAL}};if(r===t.JOIN_STATUS_SUCCESS)return this._handleJoinResult({group:new R({groupID:e.groupID}),avChatRoomFlag:u,longPollingKey:n,startSeq:s,avChatRoomKey:p,messageList:a});throw new this._core.helper.ChatError({code:G})}))}_handleJoinResult(e){const{group:o,avChatRoomFlag:i}=e;return 1===i?{}:(A.updateLocalGroup([o]),A.emitGroupListUpdate(),E({status:t.JOIN_STATUS_SUCCESS,group:o}))}};var j=new class{constructor(){this._name="QuitGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("quitGroup",this)}quitGroup(e){return C(this,void 0,void 0,(function*(){if(console.log(`${this._name}.quitGroup groupID:${e}`),!A.hasLocalGroup(e))throw new this._core.helper.ChatError({code:I});try{return yield function(e,t){return C(this,void 0,void 0,(function*(){return N("group_open_http_svc.quit_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.quitGroup ok.`),A.deleteLocalGroup(e),A.emitGroupListUpdate(),E({groupID:e})}catch(e){throw console.error(`${this._name}.quitGroup fail:`,e),e}}))}};var q=new class{constructor(){this._name="SearchGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi("searchGroupByID",this)}searchGroupByID(e){return C(this,void 0,void 0,(function*(){console.log(`${this._name}.searchGroupByID groupID:${e}`);try{const t=yield function(e,t){return C(this,void 0,void 0,(function*(){return N("group_open_http_svc.get_group_public_info",{GroupIdList:[e],GroupBasePublicInfoFilter:[...r]},t)}))}(e,this._core),{GroupInfo:o=[]}=t||{},{AppDefinedData:i=[],ApplyJoinOption:n,CreateTime:s,FaceUrl:u,Introduction:p,InviteJoinOption:a,MaxMemberNum:c,MemberNum:l,Name:m,Owner_Account:g,Type:h,ErrorCode:_,ErrorInfo:d}=o[0];if(0!==_)throw new this._core.helper.ChatError({code:_,message:d});console.log(`${this._name}.searchGroupByID ok.`);const f=P(i),I=new R({groupID:e,name:m,avatar:u,introduction:p,joinOption:n,inviteOption:a,maxMemberNum:c,memberNum:l,type:h,ownerID:g,createTime:s,groupCustomField:f});return E({group:I})}catch(e){throw console.error(`${this._name}.searchGroupByID fail:`,e),e}}))}};var J=new class{constructor(){this._name="UpdateGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi("updateGroupProfile",this)}updateGroupProfile(e){return C(this,void 0,void 0,(function*(){const{groupID:t}=e;let o=A.getLocalGroup(t);if(o){const{type:t}=o;this._canIUseJoinOption(t)||O(e.joinOption)||(console.warn(`${this._name}.updateGroupProfile joinOption is unavailable for Work/Meeting/AVChatRoom`),e.joinOption=void 0)}O(e.muteAllMembers)||(e.muteAllMembers=!0===e.muteAllMembers?"On":"Off");try{return yield function(e,t){return C(this,void 0,void 0,(function*(){const{groupID:o,name:i,avatar:r,introduction:n,notification:s,muteAllMembers:u,joinOption:p,inviteOption:a,groupCustomField:c}=e;return N("group_open_http_svc.modify_group_base_info",{GroupId:o,Name:i,FaceUrl:r,Introduction:n,Notification:s,ShutUpAllMember:u,ApplyJoinOption:p,InviteJoinOption:a,AppDefinedData:c?function(e){const t=[];for(let o=0,i=e.length;o<i;o++){const{key:i,value:r}=e[o];t.push({Key:i,Value:r})}return t}(c):void 0},t)}))}(e,this._core),console.log(`${this._name}.updateGroupProfile groupID:${t} ok.`),o?(o.updateGroup(e),A.emitGroupListUpdate()):o=new R(e),E({group:o})}catch(e){throw console.error(`${this._name}.updateGroupProfile groupID:${t} fail:`,e),e}}))}_canIUseJoinOption(e){return y(e)||M({type:e})}};var x=new class{init(e){console.log("GroupAction.init"),D.init(e),w.init(e),U.init(e),$.init(e),j.init(e),q.init(e),F.init(e),J.init(e)}handleLoginSuccess(){D.handleLoginSuccess()}};var B=new class{init(e){this._core=e}};var k=new class{init(e){this._core=e}};var V=new class{init(e){this._core=e}};const K={createGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1}},dismissGroup:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}],joinGroup:{groupID:{required:!0,rules:["string"],allowEmpty:!1},applyMessage:{required:!1,rules:["string"],allowEmpty:!0}},quitGroup:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}],searchGroupByID:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}],getGroupProfile:{groupID:{required:!0,rules:["string"],allowEmpty:!1},groupCustomFieldFilter:{required:!1,rules:["Array<string>"],allowEmpty:!0}},updateGroupProfile:{groupID:{required:!0,rules:["string"],allowEmpty:!1},muteAllMembers:{required:!1,rules:["boolean"],allowEmpty:!1}}},H={getGroupList:!0,createGroup:!0,dismissGroup:!0,joinGroup:!0,quitGroup:!0,searchGroupByID:!0,getGroupProfile:!0,updateGroupProfile:!0,getGroupApplicationList:!0};return new class{install(e){this._core=e,A.init(e),x.init(e),B.init(e),k.init(e),V.init(e),e.helper.registerValidateConfig({auth:H,params:K});const{notificationCenter:t,InnerEvent:o}=e;t.subscribeInnerEvent(o.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(o.DESTROY,this._dispose,this)}handleLoginSuccess(){x.handleLoginSuccess()}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGIN,this.handleLoginSuccess,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}}}));
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatGroup=r()}(this,(function(){"use strict";function e(e,r,o,t){return new(o||(o=Promise))((function(i,n){function s(e){try{u(t.next(e))}catch(e){n(e)}}function c(e){try{u(t.throw(e))}catch(e){n(e)}}function u(e){var r;e.done?i(e.value):(r=e.value,r instanceof o?r:new o((function(e){e(r)}))).then(s,c)}u((t=t.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const r="group";var o=new class{init(e){this._core=e;const{helper:r}=e;r.registerApi("searchGroupByID",this),r.registerApi("getGroupList",this),r.registerApi("getGroupApplicationList",this)}searchGroupByID(o){return e(this,void 0,void 0,(function*(){try{console.log(`${r} searchGroupByID: groupID: ${o}`);const t=yield function(r,o){return e(this,void 0,void 0,(function*(){try{const{helper:e,channel:t}=o,i="group_open_http_svc.get_group_public_info",n={GroupIdList:[r]},s=e.generateProtocolData({servcmd:i,data:n}),c=`${s.head.seq}${i}`;return yield t.sendPacket(s,{requestId:c})}catch(e){throw console.warn("searchGroupByID error:",e),e}}))}(o,this._core);return this._parseSearchGroupByIDResponse(t),{code:0,data:{group:{groupID:o}}}}catch(e){throw console.warn(`${r} searchGroupByID error:`,e),e}}))}getGroupList(){return e(this,void 0,void 0,(function*(){return console.log(`${r} getGroupList`),{code:0,data:{groupList:[]}}}))}getGroupApplicationList(){return e(this,void 0,void 0,(function*(){return console.log(`${r} getGroupApplicationList`),{code:0,data:{applicationList:[]}}}))}_parseSearchGroupByIDResponse(e){var r;const o=null===(r=e.GroupInfo)||void 0===r?void 0:r[0];if(0!==(null==o?void 0:o.ErrorCode))throw new this._core.helper.ChatError({functionName:"searchGroupByID",code:null==o?void 0:o.ErrorCode,message:null==o?void 0:o.ErrorCode});return e}};var t=new class{init(e){this._core=e}};var i=new class{init(e){this._core=e}};var n=new class{init(e){this._core=e}};var s=new class{init(e){this._core=e}};const c={searchGroupByID:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}]},u={getGroupList:!0,searchGroupByID:!0,getGroupApplicationList:!0};return new class{install(e){o.init(e),t.init(e),i.init(e),n.init(e),s.init(e),e.helper.registerValidateConfig({auth:u,params:c})}}}));
@@ -1,8 +1,8 @@
1
1
  declare const messageEnhancerPlugin: {
2
- [key: string]: any;
3
- };
2
+ [key: string]: any;
3
+ };
4
4
 
5
+ export default messageEnhancerPlugin;
6
+ declare module '@tencentcloud/lite-chat/plugins/message-enhancer' {
5
7
  export default messageEnhancerPlugin;
6
- declare module '@tencentcloud/lite-chat/plugins/message-enhancer' {
7
- export default messageEnhancerPlugin;
8
- }
8
+ }