@tencentcloud/lite-chat 1.6.5 → 1.6.6
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/basic.es.js +1 -1
- package/basic.js +1 -1
- package/package.json +1 -1
- package/plugins/avchatroom.es.js +1 -1
- package/plugins/avchatroom.js +1 -1
- package/plugins/cloud-search.es.js +1 -1
- package/plugins/cloud-search.js +1 -1
- package/plugins/conversation-group.es.js +1 -1
- package/plugins/conversation-group.js +1 -1
- package/plugins/conversation.es.js +1 -1
- package/plugins/conversation.js +1 -1
- package/plugins/follow.es.js +1 -1
- package/plugins/follow.js +1 -1
- package/plugins/friend.es.js +1 -1
- package/plugins/friend.js +1 -1
- package/plugins/group.es.js +1 -1
- package/plugins/group.js +1 -1
- package/plugins/message-enhancer.es.js +1 -1
- package/plugins/message-enhancer.js +1 -1
- package/plugins/offline-message-synchronizer.es.js +1 -1
- package/plugins/offline-message-synchronizer.js +1 -1
- package/plugins/push-token-register.es.js +1 -0
- package/plugins/push-token-register.js +1 -0
- package/plugins/rich-media-message.es.js +1 -1
- package/plugins/rich-media-message.js +1 -1
- package/plugins/signaling.es.js +1 -1
- package/plugins/signaling.js +1 -1
- package/plugins/topic.es.js +1 -1
- package/plugins/topic.js +1 -1
- package/professional.es.js +1 -1
- package/professional.js +1 -1
- package/standard.es.js +1 -1
- package/standard.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(t="undefined"!=typeof globalThis?globalThis:t||self)["TencentCloudChatConversation-group"]=o()}(this,function(){"use strict";var t=new class{constructor(){this._conversationGroupMap=new Map}init(t){this._core=t}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(t){return this._conversationGroupMap.get(t)}setConversationGroup(t,o){this._conversationGroupMap.set(t,o)}};function o(t,o,e,n){return new(e||(e=Promise))(function(r,s){function a(t){try{c(n.next(t))}catch(t){s(t)}}function i(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var o;t.done?r(t.value):(o=t.value,o instanceof e?o:new e(function(t){t(o)})).then(a,i)}c((n=n.apply(t,o||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const e=new class{init(t){this.core=t}},n="CONV_GROUP",r=2500,s=2503,a=1,i=2,c="NOT_STARTED",u="FETCHING",p="FINISHED",d="FAILED",v=0,l=1,C=1,h=2,m=3,f=1,I=2;function G(t){const{helper:o,constants:r}=e.core;if(!o.checkBusinessCapabilityBits(n))throw new o.ChatError({functionName:t,code:r.ERROR_CODE.NO_USE,replacement1:t})}function _(){const{notificationCenter:o,OuterEvent:n}=e.core;o.emitOuterEvent(n.CONVERSATION_GROUP_LIST_UPDATED,{name:n.CONVERSATION_GROUP_LIST_UPDATED,data:[...t.getConversationGroupMap().values()]})}function g(t){const{utils:{isUndefined:o},constants:{OuterConstant:n}}=e.core,{Type:r,To_Account:s,Peer_Account:c}=t;let u="";const p=t.ToGroupId||t.GroupId;return r===a?o(c)?o(s)||(u=`${n.CONV_C2C}${s}`):u=`${n.CONV_C2C}${c}`:r===i&&(u=`${n.CONV_GROUP}${p}`),u}function D(t){const o=[],{OuterConstant:n,common:{isC2CConv:r,isGroupConv:s}}=e.core,{conversationIDList:c,failureConversationIDList:u,additionalData:p={}}=t;return c.forEach(t=>{N(t,u),r(t)?o.push(Object.assign({ContactItem:{Type:a,To_Account:t.replace(n.CONV_C2C,"")}},p)):s(t)&&o.push(Object.assign({ContactItem:{Type:i,ToGroupId:t.replace(n.CONV_GROUP,"")}},p))}),o}function N(t,o){const{appStore:{conversationStore:n},common:{isC2CConv:a,isGroupConv:i}}=e.core;n.getConversation(t)?a(t)||i(t)||o.push({conversationID:t,code:s}):o.push({conversationID:t,code:r})}function L(t){const{utils:{isString:o}}=e.core,n=[];if(!o(t))return n;const r=t.length;if(0===r)return n;for(let o=r-1;o>=0;o--)"1"===t[o]&&n.push(Math.pow(2,r-o-1));return n}function E(t){null==t||t.forEach((o,n)=>{const{appStore:r}=e.core,{conversationID:s,data:a}=o,i=n===t.length-1;r.conversationStore.updateConversation(s,a,{emit:i})})}function O(t){const{conversationInfoList:o,fromAccount:n}=t,r={From_Account:n,MarkItem:o};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:r})}function S(t){const{fromAccount:o,groupName:n,conversationInfoList:r}=t,s={From_Account:o,UpdateType:1,UpdateGroup:{UpdateGroupType:I,OldGroupName:n,ContactUpdateItem:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:s})}var R=new class{init(t){const{helper:{registerApi:o}}=t;this._core=t,o({apiName:"createConversationGroup",context:this})}createConversationGroup(n){return o(this,void 0,void 0,function*(){const{utils:{isPlainObject:o,isArray:r},appStore:s}=this._core;G("createConversationGroup");const{groupName:a,conversationIDList:i}=n,c=[],u=this._generateConversationInfo(i,c);if(c.length===i.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{const n=yield function(t){const{common:{buildAndSendPacket:o,getCurrentUserID:n}}=e.core,{item:r,groupName:s}=t;return o({servcmd:"recentcontact.create_contact_group",data:{From_Account:n(),GroupContactItem:[{GroupName:s,ContactItem:r}]}})}({groupName:a,item:u});if(n){const{GroupResultItem:e=[]}=n,{GroupItem:i,ResultItem:u}=(null==e?void 0:e[0])||{},p=[];if(o(i)){const{GroupName:o,GroupId:e}=i;t.setConversationGroup(e,o),_()}if(r(u)){const t=[];u.forEach(o=>{const{ContactItem:e,ResultCode:n,ResultInfo:r}=o,i=g(e);if(0===n){const o=s.conversationStore.getConversation(i);if(o&&!o.conversationGroupList.includes(a)){const e=o.conversationGroupList.slice();e.push(a),t.push({conversationID:i,data:{conversationGroupList:e}})}}else c.push({conversationID:i,code:n,message:r})}),t.length>0&&(E(t),_())}return{code:0,data:{successConversationIDList:p,failureConversationIDList:c}}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"createConversationGroup",code:o,message:e})}})}_generateConversationInfo(t,o,e={}){const n=[],{OuterConstant:r,common:{isC2CConv:s,isGroupConv:c}}=this._core;return t.forEach(t=>{N(t,o),s(t)?n.push(Object.assign({Type:a,To_Account:t.replace(r.CONV_C2C,"")},e)):c(t)&&n.push(Object.assign({Type:i,ToGroupId:t.replace(r.CONV_GROUP,"")},e))}),n}};var A=new class{constructor(){this._fetchConversationGroupStatus=c}init(t){const{helper:{registerApi:o,registerWorkflowStep:e},constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:r}}=t;this._core=t,o({apiName:"getConversationGroupList",context:this}),e(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),e(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,function*(){return G("getConversationGroupList"),this._fetchConversationGroupStatus===d&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...t.getConversationGroupMap().values()]}})}_syncConversationGroupList(){return o(this,void 0,void 0,function*(){return yield this._fetchConversationGroupList(0)})}_fetchConversationGroupList(n){return o(this,arguments,void 0,function*(o,n=[]){const{common:{getCurrentUserID:r},utils:{isArray:s}}=this._core;this._fetchConversationGroupStatus=u;try{const a=r(),i=yield function(t){const{fromAccount:o,startIndex:n}=t,r={From_Account:o,StartIndex:n};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:r})}({fromAccount:a,startIndex:o});if(i){const{CompleteFlag:o,ContactItem:e=[],NextStartIndex:r=0,GroupItem:a=[]}=i;if(s(a)&&a.forEach(o=>{const{GroupName:e,GroupId:n}=o;t.setConversationGroup(n,e)}),n.push(...e),o===v)return this._fetchConversationGroupList(r);if(o===l)return this._fetchConversationGroupStatus=p,n}}catch(t){this._fetchConversationGroupStatus=d,console.error(t)}})}_updateConversation(t){var o;const{constants:{WORKFLOW_STEP:e}}=this._core,n=(null===(o=null==t?void 0:t.result)||void 0===o?void 0:o[e.CONVERSATION_GROUP_LIST_SYNC])||[];E(this._generateConversationUpdateFields(n)),_()}_generateConversationUpdateFields(o){const{utils:{isArray:e},appStore:n}=this._core,r=[];if(e(o)){let s;o.forEach(o=>{const a=[],{StandardMark:i,CustomMark:c="",ContactGroupId:u}=o;e(u)&&u.forEach(o=>{t.getConversationGroupMap().has(o)&&a.push(t.getConversationGroup(o))});const p=g(o);s=n.conversationStore.getConversation(p),s&&r.push({conversationID:p,data:{markList:L(i),customData:c,conversationGroupList:[...a]}})})}return r}reset(){this._fetchConversationGroupStatus=c}dispose(){this.reset()}};var T=new class{init(t){const{notificationCenter:o,helper:{registerApi:e},InnerEvent:{MESSAGE_PUSH:n},InnerEventSubType:{CONVERSATION_MARK_UPDATED:r,CONVERSATION_GROUP_ADD:s,CONVERSATION_GROUP_DELETED:a,CONVERSATION_GROUP_UPDATED:i}}=t;this._core=t,e({apiName:"renameConversationGroup",context:this}),e({apiName:"deleteConversationGroup",context:this}),e({apiName:"markConversation",context:this}),e({apiName:"setConversationCustomData",context:this}),e({apiName:"deleteConversationsFromGroup",context:this}),e({apiName:"addConversationsToGroup",context:this}),o.subscribeInnerEvent(n,s,this._handleConversationGroupAdd,this),o.subscribeInnerEvent(n,a,this._handleConversationGroupDeleted,this),o.subscribeInnerEvent(n,i,this._handleConversationGroupUpdated,this),o.subscribeInnerEvent(n,r,this._handleConversationMarkUpdated,this)}renameConversationGroup(n){return o(this,void 0,void 0,function*(){G("renameConversationGroup");const{common:{getCurrentUserID:o}}=this._core,{oldName:r,newName:s}=n,a=`oldName:${r} newName:${s}`;try{const n=yield function(t){const{fromAccount:o,oldName:n,newName:r}=t,s={From_Account:o,UpdateType:1,UpdateGroup:{UpdateGroupType:f,OldGroupName:n,NewGroupName:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:s})}({fromAccount:o(),oldName:r,newName:s});if(n){const{UpdateGroupResult:o}=n,{GroupId:e}=o;t.setConversationGroup(e,s),_(),this._updateLocalConversationGroupName({oldName:r,newName:s})}return{successLog:{message:a}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"renameConversationGroup",code:o,message:e,moreMessage:a})}})}deleteConversationGroup(n){return o(this,void 0,void 0,function*(){G("deleteConversationGroup");const{common:{getCurrentUserID:o}}=this._core;try{const r=yield function(t){const{fromAccount:o,groupName:n}=t,r={From_Account:o,GroupName:[n]};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:r})}({fromAccount:o(),groupName:n});if(r){const{GroupItem:o}=r;let e=!1;return null==o||o.forEach(o=>{const{GroupId:n}=o,r=t.getConversationGroupMap();r.has(n)&&(r.delete(n),e=!0)}),e&&_(),this._deleteLocalConversationGroupName([n]),{successLog:{message:`groupName:${n}`}}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:o,message:e,moreMessage:`groupName:${n}`})}})}markConversation(t){return o(this,void 0,void 0,function*(){G("markConversation");const{utils:{isNumber:o},common:{getCurrentUserID:e},appStore:n}=this._core,{conversationIDList:r,markType:s,enableMark:a}=t,i=this._getFlagBit(s),c=[],u=[];let p,d;!0===a&&o(i)?p=[i]:d=[i];const v=D({conversationIDList:r,failureConversationIDList:c,additionalData:{SetMark:p,ClearMark:d,OptType:C}});if(c.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{const t=yield O({conversationInfoList:v,fromAccount:e()});if(t){const{ResultItem:o}=t,e=[];o.forEach(t=>{const{ContactItem:o,ResultCode:r,ResultInfo:i}=t,p=g(o);if(0===r){u.push(p);const t=n.conversationStore.getConversation(p);if(t){const o=t.markList.indexOf(s),n=!1===a&&-1!==o;if(!0===a&&-1===o)e.push({conversationID:p,data:{markList:[...t.markList,s]}});else if(n){const n=t.markList.slice();n.splice(o,1),e.push({conversationID:p,data:{markList:n}})}}}else c.push({conversationID:p,code:r,message:i})}),E(e)}return{code:0,data:{successConversationIDList:u,failureConversationIDList:c}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"markConversation",code:o,message:e})}})}setConversationCustomData(t){return o(this,void 0,void 0,function*(){G("setConversationCustomData");const{common:{getCurrentUserID:o},appStore:e}=this._core,{conversationIDList:n,customData:r}=t,s=[],a=[],i=D({conversationIDList:n,failureConversationIDList:s,additionalData:{CustomMark:r,OptType:h}});if(s.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:s}};try{const t=yield O({fromAccount:o(),conversationInfoList:i});if(t){const{ResultItem:o}=t,n=[];null==o||o.forEach(t=>{const{ContactItem:o,ResultCode:i,ResultInfo:c}=t;if(0===i){const t=g(o);a.push(t);const s=e.conversationStore.getConversation(t);s&&s.customData!==r&&n.push({conversationID:t,data:{customData:r}})}else s.push({conversationID:conversationID,code:i,message:c})}),E(n)}return{code:0,data:{successConversationIDList:a,failureConversationIDList:s}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"setConversationCustomData",code:o,message:e})}})}deleteConversationsFromGroup(t){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");const{common:{getCurrentUserID:o},appStore:e}=this._core,{conversationIDList:n,groupName:r}=t,s=[],a=[],i=D({conversationIDList:n,failureConversationIDList:s,additionalData:{ContactOptType:2}});if(s.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:s}};try{const t=yield S({fromAccount:o(),groupName:r,conversationInfoList:i});if(t){const o=[],{UpdateGroupResult:{ContactResultItem:n}}=t;null==n||n.forEach(t=>{const n=g(t.ContactItem);if(0===t.ResultCode){const t=e.conversationStore.getConversation(n);if(t){const e=t.conversationGroupList.indexOf(r);if(-1!==e){const r=t.conversationGroupList.slice();r.splice(e,1),a.push(n),o.push({conversationID:n,data:{conversationGroupList:r}})}}}else s.push({conversationID:n,code:t.ResultCode,message:t.ResultInfo})}),o.length>0&&(_(),E(o))}return{code:0,data:{successConversationIDList:a,failureConversationIDList:s}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:o,message:e})}})}addConversationsToGroup(t){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");const{common:{getCurrentUserID:o},appStore:e}=this._core,{conversationIDList:n,groupName:r}=t,s=[],a=[],i=D({conversationIDList:n,failureConversationIDList:s,additionalData:{ContactOptType:1}});if(s.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:s}};try{const t=yield S({fromAccount:o(),groupName:r,conversationInfoList:i});if(t){const o=[],{UpdateGroupResult:{ContactResultItem:n}}=t;null==n||n.forEach(t=>{const n=g(t.ContactItem);if(0===t.ResultCode){const t=e.conversationStore.getConversation(n);if(t){if(-1===t.conversationGroupList.indexOf(r)){const e=t.conversationGroupList.slice();e.push(r),a.push(n),o.push({conversationID:n,data:{conversationGroupList:e}})}}}else s.push({conversationID:n,code:t.ResultCode,message:t.ResultInfo})}),o.length>0&&(_(),E(o))}return{code:0,data:{successConversationIDList:a,failureConversationIDList:s}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:o,message:e})}})}_updateLocalConversationGroupName(t){const{appStore:o}=this._core,{oldName:e,newName:n}=t;let r=[];const s=[];let a=-1;Array.from(o.conversationStore.getConversationMap().values()).forEach(t=>{if(r=t.conversationGroupList,a=r.indexOf(e),-1!==a){const o=r.slice();o.splice(a,1,n),s.push({conversationID:t.conversationID,data:{conversationGroupList:o}})}}),E(s)}_deleteLocalConversationGroupName(t){const{utils:{isEmpty:o},appStore:e}=this._core;if(o(t))return;const n=[];Array.from(e.conversationStore.getConversationMap().values()).forEach(o=>{const{conversationID:e,conversationGroupList:r}=o,s=r.filter(o=>!t.includes(o));s.length<r.length&&n.push({conversationID:e,data:{conversationGroupList:s}})}),E(n)}_getFlagBit(t){const o=t.toString(2),e=o.length;for(let t=e-1;t>=0;t--)if("1"===o[t])return e-t-1}_handleConversationGroupAdd(o){var e;const{utils:{isArray:n},appStore:r}=this._core;null===(e=null==o?void 0:o.RecentContactMod)||void 0===e||e.forEach(o=>{const{RecentContactCreateContactGroup:{MsgContactGroupContactItem:e}}=o;let s=!1;null==e||e.forEach(o=>{const{MsgGroupItem:e,MsgRecentContactItem:a}=o,{GroupId:i,GroupName:c}=e,u=[];t.getConversationGroup(i)!==c&&(t.setConversationGroup(i,c),s=!0),n(a)&&a.forEach(t=>{var o;const e=g(t),n=r.conversationStore.getConversation(e);if(n&&!(null===(o=n.conversationGroupList)||void 0===o?void 0:o.includes(c))){const t=n.conversationGroupList.slice();t.push(c),u.push({conversationID:e,data:{conversationGroupList:t}})}}),s&&_(),E(u)})})}_handleConversationGroupDeleted(o){var e;const{utils:{isArray:n}}=this._core;null===(e=null==o?void 0:o.RecentContactMod)||void 0===e||e.forEach(o=>{const{MsgGroupItem:e}=(null==o?void 0:o.RecentContactDelContactGroup)||{};if(n(e)){let o=!1;const n=[];e.forEach(e=>{const{GroupId:r,GroupName:s}=e,a=t.getConversationGroupMap();a.has(r)&&(a.delete(r),o=!0,n.push(s))}),o&&_(),n.length>0&&this._deleteLocalConversationGroupName(n)}})}_handleConversationGroupUpdated(t){var o;null===(o=t.RecentContactMod)||void 0===o||o.forEach(t=>{const{RecentContactUpdateContactGroup:{MsgUpdateGroup:{GroupId:o,GroupName:e,OldGroupName:n,RecentContactUpdateGroupItem:r,UpdateGroupType:s}}}=t;1===s?this._handleGroupNameUpdated({groupID:o,newName:e,oldName:n}):2===s&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:r,groupName:n})})}_handleConversationMarkUpdated(t){var o;const{appStore:e}=this._core;null===(o=null==t?void 0:t.RecentContactMod)||void 0===o||o.forEach(t=>{const{RecentContactMarkContact:{RecentContactMarkContactItem:o}}=t,n=[];null==o||o.forEach(t=>{const{RecentContactItem:o,CustomMark:r,StandardMark:s,OptType:a}=t,i=g(o),c=e.conversationStore.getConversation(i);c&&(a===C?this._updateStandMark({conversation:c,standardMark:s,updateConversationList:n}):a===h?this._updateCustomMark({conversation:c,customMark:r,updateConversationList:n}):a===m&&(this._updateStandMark({conversation:c,standardMark:s,updateConversationList:n}),this._updateCustomMark({conversation:c,customMark:r,updateConversationList:n})))}),E(n)})}_updateStandMark(t){const{conversation:o,standardMark:e,updateConversationList:n}=t,r=L(e);(function(t,o){if(t===o)return!0;if(!t||!o)return!1;if(t.length!==o.length)return!1;t.sort(),o.sort();for(let e=0,n=t.length;e<n;e++)if(t[e]!==o[e])return!1;return!0})(o.markList,r)||n.push({conversationID:o.conversationID,data:{markList:r}})}_updateCustomMark(t){const{conversation:o,customMark:e,updateConversationList:n}=t;o.customData!==e&&void 0!==e&&(o.customData=e,n.push({conversationID:o.conversationID,data:{customData:e}}))}_handleGroupNameUpdated(o){const{groupID:e,oldName:n,newName:r}=o;t.getConversationGroup(e)!==r&&(t.setConversationGroup(e,r),_(),this._updateLocalConversationGroupName({oldName:n,newName:r}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:t,groupName:o}){const{appStore:e}=this._core,n=[];t.forEach(t=>{const{RecentContactItem:r,ContactOptType:s}=t,a=g(r),i=e.conversationStore.getConversation(a),c=i.conversationGroupList.indexOf(o);if(i){const t=i.conversationGroupList.slice();1===s&&-1===c?(t.push(o),n.push({conversationID:a,data:{conversationGroupList:t}})):2===s&&-1!==c&&(t.splice(c,1),n.push({conversationID:a,data:{conversationGroupList:t}}))}}),E(n)}dispose(){const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{CONVERSATION_MARK_UPDATED:e,CONVERSATION_GROUP_ADD:n,CONVERSATION_GROUP_DELETED:r,CONVERSATION_GROUP_UPDATED:s}}=this._core;t.unSubscribeInnerEvent(o,n,this._handleConversationGroupAdd,this),t.unSubscribeInnerEvent(o,r,this._handleConversationGroupDeleted,this),t.unSubscribeInnerEvent(o,s,this._handleConversationGroupUpdated,this),t.unSubscribeInnerEvent(o,e,this._handleConversationMarkUpdated,this)}};const y={required:!0,rules:["string"],allowEmpty:!1},U={required:!0,rules:["array"],allowEmpty:!1},M={createConversationGroup:{groupName:y,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:y,newName:Object.assign(Object.assign({},y),{customValidator:t=>!(t.length>32)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:U,groupName:y},deleteConversationsFromGroup:{conversationIDList:U,groupName:y},markConversation:{conversationIDList:U,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:t=>t<=0?"markType must be greater than 0":!(t>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:U,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:t=>"string"!=typeof t?"customData must be string":!(t.length>256)||"customData length cannot longer than 256"}}},k={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};return new class{constructor(){this.name="ConversationGroup"}install(o){this._core=o,e.init(o),t.init(o),R.init(o),A.init(o),T.init(o),o.helper.registerValidateConfig({auth:k,params:M}),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.LOGOUT,this.reset,this),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.DESTROY,this.dispose,this)}dispose(){const{notificationCenter:t,InnerEvent:o}=this._core;t.unSubscribeInnerEvent(o.LOGOUT,this.reset,this),t.unSubscribeInnerEvent(o.DESTROY,this.dispose,this),T.dispose(),A.dispose()}reset(){A.reset()}}});
|
|
1
|
+
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(t="undefined"!=typeof globalThis?globalThis:t||self)["TencentCloudChatConversation-group"]=o()}(this,(function(){"use strict";var t=new class{constructor(){this._conversationGroupMap=new Map}init(t){this._core=t}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(t){return this._conversationGroupMap.get(t)}setConversationGroup(t,o){this._conversationGroupMap.set(t,o)}};function o(t,o,e,n){return new(e||(e=Promise))((function(r,s){function a(t){try{c(n.next(t))}catch(t){s(t)}}function i(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var o;t.done?r(t.value):(o=t.value,o instanceof e?o:new e((function(t){t(o)}))).then(a,i)}c((n=n.apply(t,o||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const e=new class{init(t){this.core=t}},n="CONV_GROUP",r=2500,s=2503,a=1,i=2,c="NOT_STARTED",u="FETCHING",p="FINISHED",d="FAILED",v=0,l=1,C=1,h=2,m=3,f=1,I=2;function G(t){const{helper:o,constants:r}=e.core;if(!o.checkBusinessCapabilityBits(n))throw new o.ChatError({functionName:t,code:r.ERROR_CODE.NO_USE,replacement1:t})}function _(){const{notificationCenter:o,OuterEvent:n}=e.core;o.emitOuterEvent(n.CONVERSATION_GROUP_LIST_UPDATED,{name:n.CONVERSATION_GROUP_LIST_UPDATED,data:[...t.getConversationGroupMap().values()]})}function g(t){const{utils:{isUndefined:o},constants:{OuterConstant:n}}=e.core,{Type:r,To_Account:s,Peer_Account:c}=t;let u="";const p=t.ToGroupId||t.GroupId;return r===a?o(c)?o(s)||(u=`${n.CONV_C2C}${s}`):u=`${n.CONV_C2C}${c}`:r===i&&(u=`${n.CONV_GROUP}${p}`),u}function D(t){const o=[],{OuterConstant:n,common:{isC2CConv:r,isGroupConv:s}}=e.core,{conversationIDList:c,failureConversationIDList:u,additionalData:p={}}=t;return c.forEach((t=>{N(t,u),r(t)?o.push(Object.assign({ContactItem:{Type:a,To_Account:t.replace(n.CONV_C2C,"")}},p)):s(t)&&o.push(Object.assign({ContactItem:{Type:i,ToGroupId:t.replace(n.CONV_GROUP,"")}},p))})),o}function N(t,o){const{appStore:{conversationStore:n},common:{isC2CConv:a,isGroupConv:i}}=e.core;n.getConversation(t)?a(t)||i(t)||o.push({conversationID:t,code:s}):o.push({conversationID:t,code:r})}function L(t){const{utils:{isString:o}}=e.core,n=[];if(!o(t))return n;const r=t.length;if(0===r)return n;for(let o=r-1;o>=0;o--)"1"===t[o]&&n.push(Math.pow(2,r-o-1));return n}function E(t){null==t||t.forEach(((o,n)=>{const{appStore:r}=e.core,{conversationID:s,data:a}=o,i=n===t.length-1;r.conversationStore.updateConversation(s,a,{emit:i})}))}function O(t){const{conversationInfoList:o,fromAccount:n}=t,r={From_Account:n,MarkItem:o};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:r})}function S(t){const{fromAccount:o,groupName:n,conversationInfoList:r}=t,s={From_Account:o,UpdateType:1,UpdateGroup:{UpdateGroupType:I,OldGroupName:n,ContactUpdateItem:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:s})}var R=new class{init(t){const{helper:{registerApi:o}}=t;this._core=t,o({apiName:"createConversationGroup",context:this})}createConversationGroup(n){return o(this,void 0,void 0,(function*(){const{utils:{isPlainObject:o,isArray:r},appStore:s}=this._core;G("createConversationGroup");const{groupName:a,conversationIDList:i}=n,c=[],u=this._generateConversationInfo(i,c);if(c.length===i.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{const n=yield function(t){const{common:{buildAndSendPacket:o,getCurrentUserID:n}}=e.core,{item:r,groupName:s}=t;return o({servcmd:"recentcontact.create_contact_group",data:{From_Account:n(),GroupContactItem:[{GroupName:s,ContactItem:r}]}})}({groupName:a,item:u});if(n){const{GroupResultItem:e=[]}=n,{GroupItem:i,ResultItem:u}=(null==e?void 0:e[0])||{},p=[];if(o(i)){const{GroupName:o,GroupId:e}=i;t.setConversationGroup(e,o),_()}if(r(u)){const t=[];u.forEach((o=>{const{ContactItem:e,ResultCode:n,ResultInfo:r}=o,i=g(e);if(0===n){const o=s.conversationStore.getConversation(i);if(o&&!o.conversationGroupList.includes(a)){const e=o.conversationGroupList.slice();e.push(a),t.push({conversationID:i,data:{conversationGroupList:e}})}}else c.push({conversationID:i,code:n,message:r})})),t.length>0&&(E(t),_())}return{code:0,data:{successConversationIDList:p,failureConversationIDList:c}}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"createConversationGroup",code:o,message:e})}}))}_generateConversationInfo(t,o,e={}){const n=[],{OuterConstant:r,common:{isC2CConv:s,isGroupConv:c}}=this._core;return t.forEach((t=>{N(t,o),s(t)?n.push(Object.assign({Type:a,To_Account:t.replace(r.CONV_C2C,"")},e)):c(t)&&n.push(Object.assign({Type:i,ToGroupId:t.replace(r.CONV_GROUP,"")},e))})),n}};var A=new class{constructor(){this._fetchConversationGroupStatus=c}init(t){const{helper:{registerApi:o,registerWorkflowStep:e},constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:r}}=t;this._core=t,o({apiName:"getConversationGroupList",context:this}),e(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),e(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,(function*(){return G("getConversationGroupList"),this._fetchConversationGroupStatus===d&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...t.getConversationGroupMap().values()]}}))}_syncConversationGroupList(){return o(this,void 0,void 0,(function*(){return yield this._fetchConversationGroupList(0)}))}_fetchConversationGroupList(n){return o(this,arguments,void 0,(function*(o,n=[]){const{common:{getCurrentUserID:r},utils:{isArray:s}}=this._core;this._fetchConversationGroupStatus=u;try{const a=r(),i=yield function(t){const{fromAccount:o,startIndex:n}=t,r={From_Account:o,StartIndex:n};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:r})}({fromAccount:a,startIndex:o});if(i){const{CompleteFlag:o,ContactItem:e=[],NextStartIndex:r=0,GroupItem:a=[]}=i;if(s(a)&&a.forEach((o=>{const{GroupName:e,GroupId:n}=o;t.setConversationGroup(n,e)})),n.push(...e),o===v)return this._fetchConversationGroupList(r);if(o===l)return this._fetchConversationGroupStatus=p,n}}catch(t){this._fetchConversationGroupStatus=d,console.error(t)}}))}_updateConversation(t){var o;const{constants:{WORKFLOW_STEP:e}}=this._core,n=(null===(o=null==t?void 0:t.result)||void 0===o?void 0:o[e.CONVERSATION_GROUP_LIST_SYNC])||[];E(this._generateConversationUpdateFields(n)),_()}_generateConversationUpdateFields(o){const{utils:{isArray:e},appStore:n}=this._core,r=[];if(e(o)){let s;o.forEach((o=>{const a=[],{StandardMark:i,CustomMark:c="",ContactGroupId:u}=o;e(u)&&u.forEach((o=>{t.getConversationGroupMap().has(o)&&a.push(t.getConversationGroup(o))}));const p=g(o);s=n.conversationStore.getConversation(p),s&&r.push({conversationID:p,data:{markList:L(i),customData:c,conversationGroupList:[...a]}})}))}return r}reset(){this._fetchConversationGroupStatus=c}dispose(){this.reset()}};var T=new class{init(t){const{notificationCenter:o,helper:{registerApi:e},InnerEvent:{MESSAGE_PUSH:n},InnerEventSubType:{CONVERSATION_MARK_UPDATED:r,CONVERSATION_GROUP_ADD:s,CONVERSATION_GROUP_DELETED:a,CONVERSATION_GROUP_UPDATED:i}}=t;this._core=t,e({apiName:"renameConversationGroup",context:this}),e({apiName:"deleteConversationGroup",context:this}),e({apiName:"markConversation",context:this}),e({apiName:"setConversationCustomData",context:this}),e({apiName:"deleteConversationsFromGroup",context:this}),e({apiName:"addConversationsToGroup",context:this}),o.subscribeInnerEvent(n,s,this._handleConversationGroupAdd,this),o.subscribeInnerEvent(n,a,this._handleConversationGroupDeleted,this),o.subscribeInnerEvent(n,i,this._handleConversationGroupUpdated,this),o.subscribeInnerEvent(n,r,this._handleConversationMarkUpdated,this)}renameConversationGroup(n){return o(this,void 0,void 0,(function*(){G("renameConversationGroup");const{common:{getCurrentUserID:o}}=this._core,{oldName:r,newName:s}=n,a=`oldName:${r} newName:${s}`;try{const n=yield function(t){const{fromAccount:o,oldName:n,newName:r}=t,s={From_Account:o,UpdateType:1,UpdateGroup:{UpdateGroupType:f,OldGroupName:n,NewGroupName:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:s})}({fromAccount:o(),oldName:r,newName:s});if(n){const{UpdateGroupResult:o}=n,{GroupId:e}=o;t.setConversationGroup(e,s),_(),this._updateLocalConversationGroupName({oldName:r,newName:s})}return{successLog:{message:a}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"renameConversationGroup",code:o,message:e,moreMessage:a})}}))}deleteConversationGroup(n){return o(this,void 0,void 0,(function*(){G("deleteConversationGroup");const{common:{getCurrentUserID:o}}=this._core;try{const r=yield function(t){const{fromAccount:o,groupName:n}=t,r={From_Account:o,GroupName:[n]};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:r})}({fromAccount:o(),groupName:n});if(r){const{GroupItem:o}=r;let e=!1;return null==o||o.forEach((o=>{const{GroupId:n}=o,r=t.getConversationGroupMap();r.has(n)&&(r.delete(n),e=!0)})),e&&_(),this._deleteLocalConversationGroupName([n]),{successLog:{message:`groupName:${n}`}}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:o,message:e,moreMessage:`groupName:${n}`})}}))}markConversation(t){return o(this,void 0,void 0,(function*(){G("markConversation");const{utils:{isNumber:o},common:{getCurrentUserID:e},appStore:n}=this._core,{conversationIDList:r,markType:s,enableMark:a}=t,i=this._getFlagBit(s),c=[],u=[];let p,d;!0===a&&o(i)?p=[i]:d=[i];const v=D({conversationIDList:r,failureConversationIDList:c,additionalData:{SetMark:p,ClearMark:d,OptType:C}});if(c.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{const t=yield O({conversationInfoList:v,fromAccount:e()});if(t){const{ResultItem:o}=t,e=[];o.forEach((t=>{const{ContactItem:o,ResultCode:r,ResultInfo:i}=t,p=g(o);if(0===r){u.push(p);const t=n.conversationStore.getConversation(p);if(t){const o=t.markList.indexOf(s),n=!1===a&&-1!==o;if(!0===a&&-1===o)e.push({conversationID:p,data:{markList:[...t.markList,s]}});else if(n){const n=t.markList.slice();n.splice(o,1),e.push({conversationID:p,data:{markList:n}})}}}else c.push({conversationID:p,code:r,message:i})})),E(e)}return{code:0,data:{successConversationIDList:u,failureConversationIDList:c}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"markConversation",code:o,message:e})}}))}setConversationCustomData(t){return o(this,void 0,void 0,(function*(){G("setConversationCustomData");const{common:{getCurrentUserID:o},appStore:e}=this._core,{conversationIDList:n,customData:r}=t,s=[],a=[],i=D({conversationIDList:n,failureConversationIDList:s,additionalData:{CustomMark:r,OptType:h}});if(s.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:s}};try{const t=yield O({fromAccount:o(),conversationInfoList:i});if(t){const{ResultItem:o}=t,n=[];null==o||o.forEach((t=>{const{ContactItem:o,ResultCode:i,ResultInfo:c}=t;if(0===i){const t=g(o);a.push(t);const s=e.conversationStore.getConversation(t);s&&s.customData!==r&&n.push({conversationID:t,data:{customData:r}})}else s.push({conversationID:conversationID,code:i,message:c})})),E(n)}return{code:0,data:{successConversationIDList:a,failureConversationIDList:s}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"setConversationCustomData",code:o,message:e})}}))}deleteConversationsFromGroup(t){return o(this,void 0,void 0,(function*(){G("deleteConversationsFromGroup");const{common:{getCurrentUserID:o},appStore:e}=this._core,{conversationIDList:n,groupName:r}=t,s=[],a=[],i=D({conversationIDList:n,failureConversationIDList:s,additionalData:{ContactOptType:2}});if(s.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:s}};try{const t=yield S({fromAccount:o(),groupName:r,conversationInfoList:i});if(t){const o=[],{UpdateGroupResult:{ContactResultItem:n}}=t;null==n||n.forEach((t=>{const n=g(t.ContactItem);if(0===t.ResultCode){const t=e.conversationStore.getConversation(n);if(t){const e=t.conversationGroupList.indexOf(r);if(-1!==e){const r=t.conversationGroupList.slice();r.splice(e,1),a.push(n),o.push({conversationID:n,data:{conversationGroupList:r}})}}}else s.push({conversationID:n,code:t.ResultCode,message:t.ResultInfo})})),o.length>0&&(_(),E(o))}return{code:0,data:{successConversationIDList:a,failureConversationIDList:s}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:o,message:e})}}))}addConversationsToGroup(t){return o(this,void 0,void 0,(function*(){G("deleteConversationsFromGroup");const{common:{getCurrentUserID:o},appStore:e}=this._core,{conversationIDList:n,groupName:r}=t,s=[],a=[],i=D({conversationIDList:n,failureConversationIDList:s,additionalData:{ContactOptType:1}});if(s.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:s}};try{const t=yield S({fromAccount:o(),groupName:r,conversationInfoList:i});if(t){const o=[],{UpdateGroupResult:{ContactResultItem:n}}=t;null==n||n.forEach((t=>{const n=g(t.ContactItem);if(0===t.ResultCode){const t=e.conversationStore.getConversation(n);if(t){if(-1===t.conversationGroupList.indexOf(r)){const e=t.conversationGroupList.slice();e.push(r),a.push(n),o.push({conversationID:n,data:{conversationGroupList:e}})}}}else s.push({conversationID:n,code:t.ResultCode,message:t.ResultInfo})})),o.length>0&&(_(),E(o))}return{code:0,data:{successConversationIDList:a,failureConversationIDList:s}}}catch(t){const{errorCode:o,errorInfo:e}=t;throw new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:o,message:e})}}))}_updateLocalConversationGroupName(t){const{appStore:o}=this._core,{oldName:e,newName:n}=t;let r=[];const s=[];let a=-1;Array.from(o.conversationStore.getConversationMap().values()).forEach((t=>{if(r=t.conversationGroupList,a=r.indexOf(e),-1!==a){const o=r.slice();o.splice(a,1,n),s.push({conversationID:t.conversationID,data:{conversationGroupList:o}})}})),E(s)}_deleteLocalConversationGroupName(t){const{utils:{isEmpty:o},appStore:e}=this._core;if(o(t))return;const n=[];Array.from(e.conversationStore.getConversationMap().values()).forEach((o=>{const{conversationID:e,conversationGroupList:r}=o,s=r.filter((o=>!t.includes(o)));s.length<r.length&&n.push({conversationID:e,data:{conversationGroupList:s}})})),E(n)}_getFlagBit(t){const o=t.toString(2),e=o.length;for(let t=e-1;t>=0;t--)if("1"===o[t])return e-t-1}_handleConversationGroupAdd(o){var e;const{utils:{isArray:n},appStore:r}=this._core;null===(e=null==o?void 0:o.RecentContactMod)||void 0===e||e.forEach((o=>{const{RecentContactCreateContactGroup:{MsgContactGroupContactItem:e}}=o;let s=!1;null==e||e.forEach((o=>{const{MsgGroupItem:e,MsgRecentContactItem:a}=o,{GroupId:i,GroupName:c}=e,u=[];t.getConversationGroup(i)!==c&&(t.setConversationGroup(i,c),s=!0),n(a)&&a.forEach((t=>{var o;const e=g(t),n=r.conversationStore.getConversation(e);if(n&&!(null===(o=n.conversationGroupList)||void 0===o?void 0:o.includes(c))){const t=n.conversationGroupList.slice();t.push(c),u.push({conversationID:e,data:{conversationGroupList:t}})}})),s&&_(),E(u)}))}))}_handleConversationGroupDeleted(o){var e;const{utils:{isArray:n}}=this._core;null===(e=null==o?void 0:o.RecentContactMod)||void 0===e||e.forEach((o=>{const{MsgGroupItem:e}=(null==o?void 0:o.RecentContactDelContactGroup)||{};if(n(e)){let o=!1;const n=[];e.forEach((e=>{const{GroupId:r,GroupName:s}=e,a=t.getConversationGroupMap();a.has(r)&&(a.delete(r),o=!0,n.push(s))})),o&&_(),n.length>0&&this._deleteLocalConversationGroupName(n)}}))}_handleConversationGroupUpdated(t){var o;null===(o=t.RecentContactMod)||void 0===o||o.forEach((t=>{const{RecentContactUpdateContactGroup:{MsgUpdateGroup:{GroupId:o,GroupName:e,OldGroupName:n,RecentContactUpdateGroupItem:r,UpdateGroupType:s}}}=t;1===s?this._handleGroupNameUpdated({groupID:o,newName:e,oldName:n}):2===s&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:r,groupName:n})}))}_handleConversationMarkUpdated(t){var o;const{appStore:e}=this._core;null===(o=null==t?void 0:t.RecentContactMod)||void 0===o||o.forEach((t=>{const{RecentContactMarkContact:{RecentContactMarkContactItem:o}}=t,n=[];null==o||o.forEach((t=>{const{RecentContactItem:o,CustomMark:r,StandardMark:s,OptType:a}=t,i=g(o),c=e.conversationStore.getConversation(i);c&&(a===C?this._updateStandMark({conversation:c,standardMark:s,updateConversationList:n}):a===h?this._updateCustomMark({conversation:c,customMark:r,updateConversationList:n}):a===m&&(this._updateStandMark({conversation:c,standardMark:s,updateConversationList:n}),this._updateCustomMark({conversation:c,customMark:r,updateConversationList:n})))})),E(n)}))}_updateStandMark(t){const{conversation:o,standardMark:e,updateConversationList:n}=t,r=L(e);(function(t,o){if(t===o)return!0;if(!t||!o)return!1;if(t.length!==o.length)return!1;t.sort(),o.sort();for(let e=0,n=t.length;e<n;e++)if(t[e]!==o[e])return!1;return!0})(o.markList,r)||n.push({conversationID:o.conversationID,data:{markList:r}})}_updateCustomMark(t){const{conversation:o,customMark:e,updateConversationList:n}=t;o.customData!==e&&void 0!==e&&(o.customData=e,n.push({conversationID:o.conversationID,data:{customData:e}}))}_handleGroupNameUpdated(o){const{groupID:e,oldName:n,newName:r}=o;t.getConversationGroup(e)!==r&&(t.setConversationGroup(e,r),_(),this._updateLocalConversationGroupName({oldName:n,newName:r}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:t,groupName:o}){const{appStore:e}=this._core,n=[];t.forEach((t=>{const{RecentContactItem:r,ContactOptType:s}=t,a=g(r),i=e.conversationStore.getConversation(a),c=i.conversationGroupList.indexOf(o);if(i){const t=i.conversationGroupList.slice();1===s&&-1===c?(t.push(o),n.push({conversationID:a,data:{conversationGroupList:t}})):2===s&&-1!==c&&(t.splice(c,1),n.push({conversationID:a,data:{conversationGroupList:t}}))}})),E(n)}dispose(){const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{CONVERSATION_MARK_UPDATED:e,CONVERSATION_GROUP_ADD:n,CONVERSATION_GROUP_DELETED:r,CONVERSATION_GROUP_UPDATED:s}}=this._core;t.unSubscribeInnerEvent(o,n,this._handleConversationGroupAdd,this),t.unSubscribeInnerEvent(o,r,this._handleConversationGroupDeleted,this),t.unSubscribeInnerEvent(o,s,this._handleConversationGroupUpdated,this),t.unSubscribeInnerEvent(o,e,this._handleConversationMarkUpdated,this)}};const y={required:!0,rules:["string"],allowEmpty:!1},U={required:!0,rules:["array"],allowEmpty:!1},M={createConversationGroup:{groupName:y,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:y,newName:Object.assign(Object.assign({},y),{customValidator:t=>!(t.length>32)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:U,groupName:y},deleteConversationsFromGroup:{conversationIDList:U,groupName:y},markConversation:{conversationIDList:U,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:t=>t<=0?"markType must be greater than 0":!(t>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:U,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:t=>"string"!=typeof t?"customData must be string":!(t.length>256)||"customData length cannot longer than 256"}}},k={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};return new class{constructor(){this.name="ConversationGroup"}install(o){this._core=o,e.init(o),t.init(o),R.init(o),A.init(o),T.init(o),o.helper.registerValidateConfig({auth:k,params:M}),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.LOGOUT,this.reset,this),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.DESTROY,this.dispose,this)}dispose(){const{notificationCenter:t,InnerEvent:o}=this._core;t.unSubscribeInnerEvent(o.LOGOUT,this.reset,this),t.unSubscribeInnerEvent(o.DESTROY,this.dispose,this),T.dispose(),A.dispose()}reset(){A.reset()}}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new class{init(e){this.core=e}};function t(e,t,s,n){return new(s||(s=Promise))(function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(r,a)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t===s.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{OuterConstant:s}=e.core;let n="";return 0===t?n=s.MSG_REMIND_ACPT_AND_NOTE:1===t?n=s.MSG_REMIND_DISCARD:2===t?n=s.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(n=s.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}function a(t){const{OuterConstant:s}=e.core;let n;return t.startsWith(s.CONV_C2C)&&(n=t.replace(s.CONV_C2C,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}function c(t,s){const{helper:n}=e.core,o=new n.ChatError({functionName:t,code:(null==s?void 0:s.errorCode)||(null==s?void 0:s.code),message:(null==s?void 0:s.errorInfo)||(null==s?void 0:s.message)});throw console.error(`${t} fail:`,o),o}class l{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.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(){const{core:{OuterConstant:t,utils:{isUndefined:s}}}=e;s(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:s(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;n(o)||(this.subType!==s.GRP_AVCHATROOM?i&&this.type===s.CONV_GROUP||r&&this.type===s.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u||(u={}));var _;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(_||(_={}));const h=0,p=1;var C=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:r,MESSAGE_PUSH:a,NEW_MESSAGE:c,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ:C}}=e;this._conversationStore=n,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(l,this._handleMessageDeleted,this),s.subscribeInnerEvent(d,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${this._name}.init`)}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;s.forEach(e=>{const{conversationID:t,unreadCount:s}=e,n=this.getLocalConversation(t);n&&n.unreadCount!==s&&(n.updateUnreadCount({nextUnreadCount:s,isUnreadC2CMessage:o}),i=!0)}),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(e){var t;for(let s=0;s<e.length;s++)if(12===e[s].Event){if(null===(t=e[s].GroupTips[0].MsgBody)||void 0===t?void 0:t.TopicId)continue;this._handleNewGroupAtTips(e[s])}}_handleGroupListSyncFinished(e){var t;const{constants:{WORKFLOW_STEP:s}}=this._core,n=e.result[s.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:o}}=this._core;let i=!1;for(let e=0;e<n.length;e++){const s=n[e],r=`${o}${s.groupID}`;if(!this.hasLocalConversation(r))continue;const a=this.getLocalConversation(r);a.groupProfile=JSON.parse(JSON.stringify(s)),a.lastMessage.lastSequence<s.nextMessageSeq&&(a.lastMessage.lastSequence=s.nextMessageSeq-1),a.subType||(a.subType=s.type),(null===(t=s._groupAtInfoList)||void 0===t?void 0:t.length)>0&&this._handleNewGroupAtTips({GroupTips:s._groupAtInfoList}),i=!0}i&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};if(0===t.length)return;const{common:{isTopic:i}}=this._core;if(i(t[0].conversationID))return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter(e=>this._isConversationNeedShow(e.conversationID)).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach(e=>{const{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)}),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:s,MsgSeq:n,GroupAtType:o}=e;return{from:t,groupID:s,sequence:n,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,s=e.getCurrentUserID();let n=!1;this._groupAtTipsList.forEach(e=>{const{groupID:o,from:i}=e;if(i!==s){const s=this.getLocalConversation(`${t.CONV_GROUP}${o}`);s&&(s.updateGroupAtInfoList(e),n=!0)}}),n&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,s;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:s=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let n=null,o=!1;t.forEach(e=>{n=this.getLocalConversation(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.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:s}=e,n=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(n))return;const{lastMessage:r}=n;if(r){const e=(null==s?void 0:s[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:s}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(s),this._core.ssoLog.debug("updateLocalConversationList",` newConversationList: ${s.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:s,isFromGetConversations:n,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,c=[],d=null==s?void 0:s.length;for(let e=0;e<d;e++){const d=new l(s[e]),{conversationID:u,type:_}=d;if(!a(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(n){this.setLocalConversation(u,d),_===t.CONV_C2C?d.unreadCount=(null==a?void 0:a.unreadCount)||0:_===t.CONV_GROUP&&(d.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:d,lastMessage:s[e].lastMessage,isFromGetConversations:n,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:d.unreadCount,isFromGetConversations:n,isUnreadC2CMessage:i}))}else c.push(d),this.setLocalConversation(u,d)}return{newConversationList:c}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:s,lastMessage:n,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:d}}=this._core;c(i)&&n&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=n.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);d(r,s,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:s,lastMessage:n,isInstantMessage:o}=e,i=this.getLocalConversation(s);if(i&&n){const{payload:e,nameCard:s,nick:r,cloudCustomData:a=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=s,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];t.forEach(t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?n.push(t):s.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)});const r=s.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime).concat(n).concat(o.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],s=[],{OuterConstant:{CONV_GROUP:n,CONV_C2C:o}}=this._core;e.forEach(e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===n){const e=i.replace(n,"");s.push(e)}}),t.length>0&&this._updateC2CConversation(t),s.length>0&&this._updateGroupConversation(s)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:s},appStore:{userStore:n},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then(e=>{((null==e?void 0:e.data)||[]).forEach(e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${s}${o}`);if(r){const s=(null===(t=n.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=s,r.userProfile=e,i=!0}}),i&&this.emitConversationListUpdate()}).catch(e=>{})}_updateGroupConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{isEmpty:o,safeStringify:i},ssoLog:r,apiMap:{getGroupProfile:a}}=this._core;let c=!1;try{yield Promise.all(e.map(e=>t(this,void 0,void 0,function*(){const t=n.getGroup(e),i=this.getLocalConversation(`${s}${e}`);t&&i&&(i.groupProfile=t,c=!0),o(t)&&i&&"function"==typeof a&&(yield a({groupID:e}))}))),c&&this.emitConversationListUpdate()}catch(e){r.debug("_updateGroupConversation",i(e))}})}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach(e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach(e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})})})}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),a.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this.getLocalConversation(e),r=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageDataHandler)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter(e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,s=this.getLocalConversationList();this._emitEvent({name:t,data:s}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_emitTotalUnreadCountUpdate",` from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach(s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.unreadCount)}),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter(e=>this._isConversationNeedShow(e.conversationID))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach(e=>{const n=this.getLocalConversation(e);(null==n?void 0:n.messageRemindType)!==t&&(n.messageRemindType=t,s=!0)}),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${s}`),s&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:s,lastReadTime:n=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(s);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],s=n&&t.time>n,r=o&&t.sequence>o;if(!s&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex(e=>!1===e[1].isPinned);t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a,SYNC_CONVERSATION_LIST:c}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:l}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,l,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(c,this._handleConversationSynced,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};var v=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}})}_getConversationList(e){const{utils:{isUndefined:t,isArray:s,isPlainObject:n}}=this._core;if(t(e))return C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter(t=>e.includes(t.conversationID))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.getLocalConversationList().filter(e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i))}return[]}_filterType(e,t){const{OuterConstant:s}=this._core;return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:s}}=this._core;return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:s}}=this._core;return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}};var g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){try{const{common:s}=this._core,n=yield function(e,s){return t(this,void 0,void 0,function*(){const{toAccount:t,userIDList:n}=e,o={To_Account:t,Peer_Account:n};return s.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:o})})}({toAccount:s.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=n||{};o.forEach(e=>{const{Peer_Account:t,MuteNotifications:s}=e,n=`${this._core.OuterConstant.CONV_C2C}${t}`,o=r(s);C.patchMessageRemindType([n],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var m=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){if(0!==e.length)try{const s=yield function(e,s){return t(this,void 0,void 0,function*(){const{groupIDList:t,responseFilter:n}=e,o={GroupIdList:t,ResponseFilter:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:o})})}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:n=[]}=s||{};n.forEach(e=>{var t;const{GroupId:s,MemberList:n}=e,o=(null===(t=n[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${s}`;C.patchMessageRemindType([i],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var f=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:n,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let d=C.getLocalConversation(e);if(o(e))return c.data.conversation=d,c;let u=!1;const _=s(e)?t:n;if(a(d)&&(u=!0,d=new l({conversationID:e,type:_})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=d,null==d?void 0:d.getProfileCompleted())return c;if(_===t){const s=e.replace(t,"");yield this._handleC2CConversation(d,s),u&&(yield g.get([s]))}if(_===n){const t=e.replace(n,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(d,t),u&&d.groupProfile.type!==i&&(yield m.get([t]))}return c})}_handleC2CConversation(e,s){return t(this,void 0,void 0,function*(){var t,n;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,d=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[s]});if(0===(null==d?void 0:d.data.length))throw new i.ChatError({code:_.USER_OR_GRP_NOT_FOUND});e.userProfile=null==d?void 0:d.data[0];const u=null===(n=c.getFriend(s))||void 0===n?void 0:n.remark;r(u)||e.remark===u||(e.remark=u),e.setProfileCompleted();const h=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.appendToPinnedConversation(e)})}_handleGroupConversation(e,s){return t(this,void 0,void 0,function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:n}}=this._core,{conversationID:o}=e,i=yield t({groupID:s});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)})}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.getTotalUnreadMessageCount()}};var E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){this._core=e;const{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:s}=this._core;e.forEach(e=>{const{ReadC2cMsgNotify:n}=e;if(!t(n)){const{UinPairReadArray:e=[]}=n;e.forEach(e=>{const{From_Account:t,LastReadTime:n}=e,o=`${s.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${n}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.updateUnreadCount(o)})}})}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:s}}=this._core;e.forEach(e=>{const{GroupReadInfoArray:n}=e.MsgBody;s(n)||n.forEach(e=>{const{GroupId:s,LastReadMsgSeq:n}=e,o=`${t.CONV_GROUP}${s}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${n}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.updateUnreadCount(o),this._clearGroupAtInfoList(o)})})}setMessageRead(e){return t(this,void 0,void 0,function*(){var t,s;const{OuterConstant:n}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r.groupAtInfoList));if(r.type===n.CONV_GROUP&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})})}setAllMessageRead(){return t(this,arguments,void 0,function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;s.scope||(s.scope=n);const{scope:r}=s,a=this._generateSetAllMessageReadRequestData(r);if(a.allC2CMessageReadStatus===h&&0===a.groupMessageReadInfoList.length)return{code:0};try{const s=yield function(s){return t(this,void 0,void 0,function*(){const{allC2CMessageReadStatus:t,groupMessageReadInfoList:n}=s,o={C2CReadAllMsg:t,GroupReadInfo:n};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:o})})}(a);if(s){const{GroupReadInfoArray:e,C2CReadAllMsg:t}=s,n=this._parseGroupReadInfo(e);this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})>0&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}})}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.emitConversationListUpdate()}_updateAllConversationReadStatus(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:n}=this._core,o=n.conversationStore.getConversationMap(),{allC2CMessageReadStatus:i}=e;let r=0;for(const[e,n]of o)if(n.unreadCount>=1){if(i===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.markMessageAsRead({conversationID:e,lastReadTime:t})}else if(n.type===s){const t=e.replace(s,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){const s=this._serverGroupConversationLastReadSeqMap.get(t);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.updateUnreadCount(e,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_C2C_MSG:n},appStore:o}=this._core,i={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},r=o.conversationStore.getConversationMap();for(const[,o]of r){const{type:r,unreadCount:a}=o;if(this._shouldSetAllMessageRead({scope:e,type:r,unreadCount:a}))if(r===t&&i.allC2CMessageReadStatus===h){if(i.allC2CMessageReadStatus=p,e===n)break}else if(r===s){const e=this._getLocalMessageMaxSequence(o),{groupID:t}=o.groupProfile;i.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return i}_parseGroupReadInfo(e){const{utils:{isUndefined:t}}=this._core,s=[];return null==e||e.forEach(e=>{const{GroupId:n,MsgSeq:o,RetCode:i,LastReadMsgSeq:r}=e;t(i)?this._serverGroupConversationLastReadSeqMap.set(n,r):(this._serverGroupConversationLastReadSeqMap.set(n,o),0!==i&&s.push(`${n}-${o}-${i}`))}),s}_deleteGroupAtTips(e){return t(this,void 0,void 0,function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const s=C.getLocalConversation(e);if(!s)return;const n=(null==s?void 0:s.groupAtInfoList)||[];if(0!==n.length)try{const{common:{getCurrentUserID:s,isCommunity:o},OuterConstant:{CONV_GROUP:i,CONV_AT_ALL:r}}=this._core;let a=[...n];if(o({groupID:e.replace(i,"")})&&(a=n.filter(e=>!e.atTypeArray.includes(r)),0===a.length))return void this._clearGroupAtInfoList(e,!1);const c=a.map(e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID}));yield function(e,s){return t(this,void 0,void 0,function*(){const{messageListToDelete:t}=e,n={DelMsgList:t};return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:n})})}({messageListToDelete:c},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${n.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}})}_clearGroupAtInfoList(e,t=!0){const s=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.emitConversationListUpdate())}_getLocalMessageMaxTime(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){return s.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})})}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:s,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${s}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}})}_setGroupMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,lastMessageSequence:n}=e,o={GroupId:t,MsgReadedSeq:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:o})})}({groupID:e.replace("GROUP",""),lastMessageSequence:s},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${s}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}})}_shouldSetAllMessageRead(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}}=this._core,{type:r,scope:a,unreadCount:c}=e;return!(c<=0)&&(!(r!==t||![n,o].includes(a))||!(r!==s||![n,i].includes(a)))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:s}}=this._core;if(!s(e))return;const{OuterConstant:n}=this._core;let o=!1;e.forEach(e=>{const{Type:s,To_Account:i,GroupId:r}=e;let a;1===s?a=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.getLocalConversation(`${n.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))}),o&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.replace(i.CONV_GROUP,"")});const o=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,operationType:n,itemList:o}=e,i={From_Account:t,OperationType:n,RecentContactItem:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.top",data:i})})}({fromAccount:r.getCurrentUserID(),operationType:!0===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}})}};var S=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:s}=this._core,n=[];e.forEach(e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&n.push(`${s.CONV_C2C}${o}`),2===t&&n.push(`${s.CONV_GROUP}${i}`)}),console.log(`${this._name}.handleConversationDeleted conversationIDList:${n}`),this._deleteLocalConversationList(n)}deleteConversation(e){return t(this,void 0,void 0,function*(){const{utils:{isString:t}}=this._core;if(t(e))return void(yield this._deleteConversation({conversationIDList:[e],flag:u.ONLY_CONVERSATIONID}));const s=Object.assign({},e);s.conversationIDList.length>100&&(s.conversationIDList=s.conversationIDList.slice(0,100)),yield this._deleteConversation(s)})}_deleteConversation(e){return t(this,void 0,void 0,function*(){const{conversationIDList:t,clearHistoryMessage:s=!0,flag:n=0}=e,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,s)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}})}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter(e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.getLocalConversation(e))||void 0===s?void 0:s.type;return n!==t.CONV_GROUP||this._hasLocalGroup(e)?n===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)})}_deleteConversationFromServer(e,s){return t(this,void 0,void 0,function*(){const{OuterConstant:n,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:s?1:0};if(e.forEach(e=>{var t;if(C.hasLocalConversation(e)){const s=(null===(t=C.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(s,"");s===n.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):s===n.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}}),0===i.conversationList.length)return[];const r=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,conversationList:n,clearHistoryMessage:o}=e,i={From_Account:t,ContactItem:n,ClearRamble:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:i})})}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach(e=>{if(0===e.ResultCode){const s=1===e.Type?`${n.CONV_C2C}${e.To_Account}`:`${n.CONV_GROUP}${e.ToGroupid}`;t.push(s)}}),this._deleteLocalConversationList(t),t}return[]})}_deleteLocalConversationList(e){let t=!1;e.forEach(e=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,n=e.replace(t,"");return!!s.getGroup(n)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var I=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,function*(){const{conversationID:t,draftText:s}=e;if(console.log(`${this._name} conversationID:${t} draftText:${s}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.emitConversationListUpdate(),{code:0,data:{conversation:n}}})}};var L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(s,n){return t(this,void 0,void 0,function*(){s.length>30&&(console.warn(`${this._name}.set userIDList length:${s.length} exceeds limit 30`),s.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=e.core.OuterConstant;return{[t]:0,[s]:1,[n]:2}}()[n],i=yield function(e,s){return t(this,void 0,void 0,function*(){const{userIDList:t,receiveMessageOption:n}=e,o={Peer_Account:t,Mute_Notifications:n};return s.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:o})})}({userIDList:s,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach(e=>{const{Peer_Account:t,ErrorCode:n}=e;a.push({userID:t,code:n});const o=s.indexOf(t);o>-1&&s.splice(o,1)});const c=[],l=[],{OuterConstant:d}=this._core;return s.forEach(e=>{l.push(`${d.CONV_C2C}${e}`),c.push({userID:e})}),C.patchMessageRemindType(l,n),{code:0,data:{successUserIDList:c,failureUserIDList:a}}})}};var O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,s){return t(this,void 0,void 0,function*(){const{common:{getCurrentUserID:n,isTopic:o},OuterConstant:i}=this._core;if(yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,userID:n,receiveMessageOption:o}=e,i={GroupId:t,Member_Account:n,MsgFlag:o};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:i})})}({groupID:e,userID:n(),receiveMessageOption:s},this._core),!o(e)){const t=`${i.CONV_GROUP}${e}`;C.patchMessageRemindType([t],s)}return{code:0,data:{groupID:e,messageRemindType:s}}})}};var T=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:s,ssoLog:n}=this._core;e.forEach(e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map(e=>`${s.CONV_C2C}${e}`),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}})}setMessageRemindType(e){return t(this,void 0,void 0,function*(){const t="setMessageRemindType",{groupID:s,userIDList:n,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${this._name}.${t} userIDList:${n} messageRemindType:${o}`);return yield L.set(n,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const s=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,s),s}})}};var y=new class{init(e){e.ssoLog.debug("ConversationAction.init"),this._core=e,v.init(e),f.init(e),M.init(e),E.init(e),R.init(e),S.init(e),I.init(e),T.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(s,o,this._onConversationModified,this),t.subscribeInnerEvent(s,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(s,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(s,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(n,this._dispose,this)}_onConversationModified(e){const{constants:{ConvModifyPushType:t}}=this._core,{RecentContactMod:s=[]}=e;s.forEach(e=>{const{PushType:s}=e;if(s===t.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;S.handleConversationDeleted(t)}if(s===t.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(s===t.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}})}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;E.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;T.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;E.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}};var A=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(s){return t(this,void 0,void 0,function*(){try{const{OuterConstant:{MSG_REMIND_ACPT_NOT_NOTE:n}}=this._core,{messageRemindType:o=n,isRepeated:i=!0}=s,{startTime:r=0,endTime:a=0}=this._calcStartAndEndTime(s),c=yield function(s){return t(this,void 0,void 0,function*(){const{common:t}=e.core,{startTime:n,endTime:o,isRepeated:i,messageRemindType:r}=s,a={StartTime:n,EndTime:o,IsRepeated:i,Level:r};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:a})})}({messageRemindType:this._getType(o),startTime:r,endTime:a,isRepeated:i?d.ON:d.OFF});return{code:0,data:{errorCode:c.ErrorCode,errorInfo:c.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}})}_calcStartAndEndTime(e){const{startHour:t=0,startMinute:s=0,startSecond:n=0,duration:o=0,isRepeated:i=!0}=e,r=new Date,a=new Date(r.getFullYear(),r.getMonth(),r.getDate(),t,s,n),c=Math.round(a.getTime()/1e3);let l=c+o;return i&&o>=86400&&(l=c+86400),{startTime:c,endTime:l}}_getType(e){const{OuterConstant:t}=this._core;return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}};var D=new class{init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:n}=e;t.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),s.subscribeInnerEvent(n.MESSAGE_PUSH,s.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){const t=this._handleResult(e),{notificationCenter:s,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:n}}=this._core;s.emitOuterEvent(n,{name:n,data:t})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,function*(){try{const s=yield function(){return t(this,void 0,void 0,function*(){const{common:t}=e.core,s={To_Account:t.getCurrentUserID()};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:s})})}();return{code:0,data:this._handleResult(s)}}catch(e){c("getAllReceiveMessageOpt",e)}})}_handleResult(e){const{OuterConstant:t}=this._core,{MSG_REMIND_ACPT_AND_NOTE:s,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:o}=t,i={0:s,1:n,2:o},{Level:r,StartTime:a,EndTime:c,IsRepeated:l}=e;return{messageRemindType:i[r]||s,startTime:a,endTime:c,isRepeated:l===d.ON}}};var N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:s,isObject:n,isString:o}}}=e;if(!o(t)&&!n(t))return"options is String or Object.";if(o(t)&&G(t))return"conversationID is invalid.";if(n(t)){if(!s(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some(e=>{if(G(e))return!0}))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!s(e)&&!n(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};var $=new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}};export{$ as default};
|
|
1
|
+
const e=new class{init(e){this.core=e}};function t(e,t,s,n){return new(s||(s=Promise))((function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t===s.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{OuterConstant:s}=e.core;let n="";return 0===t?n=s.MSG_REMIND_ACPT_AND_NOTE:1===t?n=s.MSG_REMIND_DISCARD:2===t?n=s.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(n=s.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}function a(t){const{OuterConstant:s}=e.core;let n;return t.startsWith(s.CONV_C2C)&&(n=t.replace(s.CONV_C2C,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}function c(t,s){const{helper:n}=e.core,o=new n.ChatError({functionName:t,code:(null==s?void 0:s.errorCode)||(null==s?void 0:s.code),message:(null==s?void 0:s.errorInfo)||(null==s?void 0:s.message)});throw console.error(`${t} fail:`,o),o}class l{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.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(){const{core:{OuterConstant:t,utils:{isUndefined:s}}}=e;s(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={userID:this.conversationID.replace(t.CONV_C2C,"")}:s(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={groupID:this.conversationID.replace(t.CONV_GROUP,""),selfInfo:{},lastMessage:{}}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;n(o)||(this.subType!==s.GRP_AVCHATROOM?i&&this.type===s.CONV_GROUP||r&&this.type===s.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u||(u={}));var _;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(_||(_={}));const h=0,p=1;var C=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:r,MESSAGE_PUSH:a,NEW_MESSAGE:c,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ:C}}=e;this._conversationStore=n,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(l,this._handleMessageDeleted,this),s.subscribeInnerEvent(d,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${this._name}.init`)}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;s.forEach((e=>{const{conversationID:t,unreadCount:s}=e,n=this.getLocalConversation(t);n&&n.unreadCount!==s&&(n.updateUnreadCount({nextUnreadCount:s,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(e){var t;for(let s=0;s<e.length;s++)if(12===e[s].Event){if(null===(t=e[s].GroupTips[0].MsgBody)||void 0===t?void 0:t.TopicId)continue;this._handleNewGroupAtTips(e[s])}}_handleGroupListSyncFinished(e){var t;const{constants:{WORKFLOW_STEP:s}}=this._core,n=e.result[s.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:o}}=this._core;let i=!1;for(let e=0;e<n.length;e++){const s=n[e],r=`${o}${s.groupID}`;if(!this.hasLocalConversation(r))continue;const a=this.getLocalConversation(r);a.groupProfile=JSON.parse(JSON.stringify(s)),a.lastMessage.lastSequence<s.nextMessageSeq&&(a.lastMessage.lastSequence=s.nextMessageSeq-1),a.subType||(a.subType=s.type),(null===(t=s._groupAtInfoList)||void 0===t?void 0:t.length)>0&&this._handleNewGroupAtTips({GroupTips:s._groupAtInfoList}),i=!0}i&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};if(0===t.length)return;const{common:{isTopic:i}}=this._core;if(i(t[0].conversationID))return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:s,MsgSeq:n,GroupAtType:o}=e;return{from:t,groupID:s,sequence:n,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,s=e.getCurrentUserID();let n=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==s){const s=this.getLocalConversation(`${t.CONV_GROUP}${o}`);s&&(s.updateGroupAtInfoList(e),n=!0)}})),n&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,s;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:s=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this.getLocalConversation(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.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:s}=e,n=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(n))return;const{lastMessage:r}=n;if(r){const e=(null==s?void 0:s[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:s}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(s),this._core.ssoLog.debug("updateLocalConversationList",` newConversationList: ${s.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:s,isFromGetConversations:n,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,c=[],d=null==s?void 0:s.length;for(let e=0;e<d;e++){const d=new l(s[e]),{conversationID:u,type:_}=d;if(!a(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(n){this.setLocalConversation(u,d),_===t.CONV_C2C?d.unreadCount=(null==a?void 0:a.unreadCount)||0:_===t.CONV_GROUP&&(d.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:d,lastMessage:s[e].lastMessage,isFromGetConversations:n,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:d.unreadCount,isFromGetConversations:n,isUnreadC2CMessage:i}))}else c.push(d),this.setLocalConversation(u,d)}return{newConversationList:c}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:s,lastMessage:n,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:d}}=this._core;c(i)&&n&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=n.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);d(r,s,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:s,lastMessage:n,isInstantMessage:o}=e,i=this.getLocalConversation(s);if(i&&n){const{payload:e,nameCard:s,nick:r,cloudCustomData:a=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=s,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?n.push(t):s.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=s.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(n).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],s=[],{OuterConstant:{CONV_GROUP:n,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===n){const e=i.replace(n,"");s.push(e)}})),t.length>0&&this._updateC2CConversation(t),s.length>0&&this._updateGroupConversation(s)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:s},appStore:{userStore:n},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${s}${o}`);if(r){const s=(null===(t=n.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=s,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{isEmpty:o,safeStringify:i},ssoLog:r,apiMap:{getGroupProfile:a}}=this._core;let c=!1;try{yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){const t=n.getGroup(e),i=this.getLocalConversation(`${s}${e}`);t&&i&&(i.groupProfile=t,c=!0),o(t)&&i&&"function"==typeof a&&(yield a({groupID:e}))}))))),c&&this.emitConversationListUpdate()}catch(e){r.debug("_updateGroupConversation",i(e))}}))}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach((e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach((e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})}))}))}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach((e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))})),a.forEach((e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))})),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this.getLocalConversation(e),r=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageDataHandler)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){var t,s;e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:n},conversation:o}=this._core,i=this.getLocalConversationList();this._emitEvent({name:n,data:i,isSyncCompleted:null===(s=null===(t=null==o?void 0:o.syncConversationHandler)||void 0===t?void 0:t.isSyncCompleted)||void 0===s?void 0:s.call(t)}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_emitTotalUnreadCountUpdate",` from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach((s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.unreadCount)})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach((e=>{const n=this.getLocalConversation(e);(null==n?void 0:n.messageRemindType)!==t&&(n.messageRemindType=t,s=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${s}`),s&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:s,lastReadTime:n=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(s);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],s=n&&t.time>n,r=o&&t.sequence>o;if(!s&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex((e=>!1===e[1].isPinned));t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a,SYNC_CONVERSATION_LIST:c}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:l}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,l,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(c,this._handleConversationSynced,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};var v=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:s,isPlainObject:n}}=this._core;if(t(e))return C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:s}=this._core;return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:s}}=this._core;return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:s}}=this._core;return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}};var g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:s}=this._core,n=yield function(e,s){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:n}=e,o={To_Account:t,Peer_Account:n};return s.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:o})}))}({toAccount:s.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=n||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:s}=e,n=`${this._core.OuterConstant.CONV_C2C}${t}`,o=r(s);C.patchMessageRemindType([n],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var m=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const s=yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:n}=e,o={GroupIdList:t,ResponseFilter:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:o})}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:n=[]}=s||{};n.forEach((e=>{var t;const{GroupId:s,MemberList:n}=e,o=(null===(t=n[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${s}`;C.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var f=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:n,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let d=C.getLocalConversation(e);if(o(e))return c.data.conversation=d,c;let u=!1;const _=s(e)?t:n;if(a(d)&&(u=!0,d=new l({conversationID:e,type:_})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=d,null==d?void 0:d.getProfileCompleted())return c;if(_===t){const s=e.replace(t,"");yield this._handleC2CConversation(d,s),u&&(yield g.get([s]))}if(_===n){const t=e.replace(n,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(d,t),u&&d.groupProfile.type!==i&&(yield m.get([t]))}return c}))}_handleC2CConversation(e,s){return t(this,void 0,void 0,(function*(){var t,n;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,d=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[s]});if(0===(null==d?void 0:d.data.length))throw new i.ChatError({code:_.USER_OR_GRP_NOT_FOUND});e.userProfile=null==d?void 0:d.data[0];const u=null===(n=c.getFriend(s))||void 0===n?void 0:n.remark;r(u)||e.remark===u||(e.remark=u),e.setProfileCompleted();const h=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.appendToPinnedConversation(e)}))}_handleGroupConversation(e,s){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:n}}=this._core,{conversationID:o}=e,i=yield t({groupID:s});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)}))}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.getTotalUnreadMessageCount()}};var E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){this._core=e;const{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:s}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:n}=e;if(!t(n)){const{UinPairReadArray:e=[]}=n;e.forEach((e=>{const{From_Account:t,LastReadTime:n}=e,o=`${s.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${n}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:s}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:n}=e.MsgBody;s(n)||n.forEach((e=>{const{GroupId:s,LastReadMsgSeq:n}=e,o=`${t.CONV_GROUP}${s}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${n}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,s;const{OuterConstant:n}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r.groupAtInfoList));if(r.type===n.CONV_GROUP&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})}))}setAllMessageRead(){return t(this,arguments,void 0,(function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;s.scope||(s.scope=n);const{scope:r}=s,a=this._generateSetAllMessageReadRequestData(r);if(a.allC2CMessageReadStatus===h&&0===a.groupMessageReadInfoList.length)return{code:0};try{const s=yield function(s){return t(this,void 0,void 0,(function*(){const{allC2CMessageReadStatus:t,groupMessageReadInfoList:n}=s,o={C2CReadAllMsg:t,GroupReadInfo:n};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:o})}))}(a);if(s){const{GroupReadInfoArray:e,C2CReadAllMsg:t}=s,n=this._parseGroupReadInfo(e);this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})>0&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}}))}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.emitConversationListUpdate()}_updateAllConversationReadStatus(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:n}=this._core,o=n.conversationStore.getConversationMap(),{allC2CMessageReadStatus:i}=e;let r=0;for(const[e,n]of o)if(n.unreadCount>=1){if(i===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.markMessageAsRead({conversationID:e,lastReadTime:t})}else if(n.type===s){const t=e.replace(s,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){const s=this._serverGroupConversationLastReadSeqMap.get(t);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.updateUnreadCount(e,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_C2C_MSG:n},appStore:o}=this._core,i={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},r=o.conversationStore.getConversationMap();for(const[,o]of r){const{type:r,unreadCount:a}=o;if(this._shouldSetAllMessageRead({scope:e,type:r,unreadCount:a}))if(r===t&&i.allC2CMessageReadStatus===h){if(i.allC2CMessageReadStatus=p,e===n)break}else if(r===s){const e=this._getLocalMessageMaxSequence(o),{groupID:t}=o.groupProfile;i.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return i}_parseGroupReadInfo(e){const{utils:{isUndefined:t}}=this._core,s=[];return null==e||e.forEach((e=>{const{GroupId:n,MsgSeq:o,RetCode:i,LastReadMsgSeq:r}=e;t(i)?this._serverGroupConversationLastReadSeqMap.set(n,r):(this._serverGroupConversationLastReadSeqMap.set(n,o),0!==i&&s.push(`${n}-${o}-${i}`))})),s}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const s=C.getLocalConversation(e);if(!s)return;const n=(null==s?void 0:s.groupAtInfoList)||[];if(0!==n.length)try{const{common:{getCurrentUserID:s,isCommunity:o},OuterConstant:{CONV_GROUP:i,CONV_AT_ALL:r}}=this._core;let a=[...n];if(o({groupID:e.replace(i,"")})&&(a=n.filter((e=>!e.atTypeArray.includes(r))),0===a.length))return void this._clearGroupAtInfoList(e,!1);const c=a.map((e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,s){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e,n={DelMsgList:t};return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:n})}))}({messageListToDelete:c},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${n.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e,t=!0){const s=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.emitConversationListUpdate())}_getLocalMessageMaxTime(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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(e,s){return t(this,void 0,void 0,(function*(){try{yield function(e,s){return t(this,void 0,void 0,(function*(){return s.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:s,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${s}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,s){return t(this,void 0,void 0,(function*(){try{yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:n}=e,o={GroupId:t,MsgReadedSeq:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:o})}))}({groupID:e.replace("GROUP",""),lastMessageSequence:s},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${s}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}_shouldSetAllMessageRead(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}}=this._core,{type:r,scope:a,unreadCount:c}=e;return!(c<=0)&&(!(r!==t||![n,o].includes(a))||!(r!==s||![n,i].includes(a)))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:s}}=this._core;if(!s(e))return;const{OuterConstant:n}=this._core;let o=!1;e.forEach((e=>{const{Type:s,To_Account:i,GroupId:r}=e;let a;1===s?a=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.getLocalConversation(`${n.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.replace(i.CONV_GROUP,"")});const o=yield function(e,s){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:n,itemList:o}=e,i={From_Account:t,OperationType:n,RecentContactItem:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.top",data:i})}))}({fromAccount:r.getCurrentUserID(),operationType:!0===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}}))}};var S=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:s}=this._core,n=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&n.push(`${s.CONV_C2C}${o}`),2===t&&n.push(`${s.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${n}`),this._deleteLocalConversationList(n)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return void(yield this._deleteConversation({conversationIDList:[e],flag:u.ONLY_CONVERSATIONID}));const s=Object.assign({},e);s.conversationIDList.length>100&&(s.conversationIDList=s.conversationIDList.slice(0,100)),yield this._deleteConversation(s)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:s=!0,flag:n=0}=e,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,s)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.getLocalConversation(e))||void 0===s?void 0:s.type;return n!==t.CONV_GROUP||this._hasLocalGroup(e)?n===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,s){return t(this,void 0,void 0,(function*(){const{OuterConstant:n,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:s?1:0};if(e.forEach((e=>{var t;if(C.hasLocalConversation(e)){const s=(null===(t=C.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(s,"");s===n.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):s===n.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,s){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:n,clearHistoryMessage:o}=e,i={From_Account:t,ContactItem:n,ClearRamble:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:i})}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const s=1===e.Type?`${n.CONV_C2C}${e.To_Account}`:`${n.CONV_GROUP}${e.ToGroupid}`;t.push(s)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,n=e.replace(t,"");return!!s.getGroup(n)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var I=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:s}=e;if(console.log(`${this._name} conversationID:${t} draftText:${s}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.emitConversationListUpdate(),{code:0,data:{conversation:n}}}))}};var L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(s,n){return t(this,void 0,void 0,(function*(){s.length>30&&(console.warn(`${this._name}.set userIDList length:${s.length} exceeds limit 30`),s.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=e.core.OuterConstant;return{[t]:0,[s]:1,[n]:2}}()[n],i=yield function(e,s){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:n}=e,o={Peer_Account:t,Mute_Notifications:n};return s.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:o})}))}({userIDList:s,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:n}=e;a.push({userID:t,code:n});const o=s.indexOf(t);o>-1&&s.splice(o,1)}));const c=[],l=[],{OuterConstant:d}=this._core;return s.forEach((e=>{l.push(`${d.CONV_C2C}${e}`),c.push({userID:e})})),C.patchMessageRemindType(l,n),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,s){return t(this,void 0,void 0,(function*(){const{common:{getCurrentUserID:n,isTopic:o},OuterConstant:i}=this._core;if(yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:n,receiveMessageOption:o}=e,i={GroupId:t,Member_Account:n,MsgFlag:o};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:i})}))}({groupID:e,userID:n(),receiveMessageOption:s},this._core),!o(e)){const t=`${i.CONV_GROUP}${e}`;C.patchMessageRemindType([t],s)}return{code:0,data:{groupID:e,messageRemindType:s}}}))}};var T=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:s,ssoLog:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map((e=>`${s.CONV_C2C}${e}`)),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:s,userIDList:n,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${this._name}.${t} userIDList:${n} messageRemindType:${o}`);return yield L.set(n,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const s=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,s),s}}))}};var y=new class{init(e){e.ssoLog.debug("ConversationAction.init"),this._core=e,v.init(e),f.init(e),M.init(e),E.init(e),R.init(e),S.init(e),I.init(e),T.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(s,o,this._onConversationModified,this),t.subscribeInnerEvent(s,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(s,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(s,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(n,this._dispose,this)}_onConversationModified(e){const{constants:{ConvModifyPushType:t}}=this._core,{RecentContactMod:s=[]}=e;s.forEach((e=>{const{PushType:s}=e;if(s===t.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;S.handleConversationDeleted(t)}if(s===t.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(s===t.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;E.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;T.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;E.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}};var A=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(s){return t(this,void 0,void 0,(function*(){try{const{OuterConstant:{MSG_REMIND_ACPT_NOT_NOTE:n}}=this._core,{messageRemindType:o=n,isRepeated:i=!0}=s,{startTime:r=0,endTime:a=0}=this._calcStartAndEndTime(s),c=yield function(s){return t(this,void 0,void 0,(function*(){const{common:t}=e.core,{startTime:n,endTime:o,isRepeated:i,messageRemindType:r}=s,a={StartTime:n,EndTime:o,IsRepeated:i,Level:r};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:a})}))}({messageRemindType:this._getType(o),startTime:r,endTime:a,isRepeated:i?d.ON:d.OFF});return{code:0,data:{errorCode:c.ErrorCode,errorInfo:c.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}}))}_calcStartAndEndTime(e){const{startHour:t=0,startMinute:s=0,startSecond:n=0,duration:o=0,isRepeated:i=!0}=e,r=new Date,a=new Date(r.getFullYear(),r.getMonth(),r.getDate(),t,s,n),c=Math.round(a.getTime()/1e3);let l=c+o;return i&&o>=86400&&(l=c+86400),{startTime:c,endTime:l}}_getType(e){const{OuterConstant:t}=this._core;return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}};var D=new class{init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:n}=e;t.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),s.subscribeInnerEvent(n.MESSAGE_PUSH,s.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){const t=this._handleResult(e),{notificationCenter:s,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:n}}=this._core;s.emitOuterEvent(n,{name:n,data:t})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,(function*(){try{const s=yield function(){return t(this,void 0,void 0,(function*(){const{common:t}=e.core,s={To_Account:t.getCurrentUserID()};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:s})}))}();return{code:0,data:this._handleResult(s)}}catch(e){c("getAllReceiveMessageOpt",e)}}))}_handleResult(e){const{OuterConstant:t}=this._core,{MSG_REMIND_ACPT_AND_NOTE:s,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:o}=t,i={0:s,1:n,2:o},{Level:r,StartTime:a,EndTime:c,IsRepeated:l}=e;return{messageRemindType:i[r]||s,startTime:a,endTime:c,isRepeated:l===d.ON}}};var N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:s,isObject:n,isString:o}}}=e;if(!o(t)&&!n(t))return"options is String or Object.";if(o(t)&&G(t))return"conversationID is invalid.";if(n(t)){if(!s(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if(G(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!s(e)&&!n(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};var $=new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}};export{$ as default};
|
package/plugins/conversation.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).TencentCloudChatConversation=t()}(this,function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t,s,n){return new(s||(s=Promise))(function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(r,a)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t===s.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{OuterConstant:s}=e.core;let n="";return 0===t?n=s.MSG_REMIND_ACPT_AND_NOTE:1===t?n=s.MSG_REMIND_DISCARD:2===t?n=s.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(n=s.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}function a(t){const{OuterConstant:s}=e.core;let n;return t.startsWith(s.CONV_C2C)&&(n=t.replace(s.CONV_C2C,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}function c(t,s){const{helper:n}=e.core,o=new n.ChatError({functionName:t,code:(null==s?void 0:s.errorCode)||(null==s?void 0:s.code),message:(null==s?void 0:s.errorInfo)||(null==s?void 0:s.message)});throw console.error(`${t} fail:`,o),o}class l{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.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(){const{core:{OuterConstant:t,utils:{isUndefined:s}}}=e;s(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:s(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;n(o)||(this.subType!==s.GRP_AVCHATROOM?i&&this.type===s.CONV_GROUP||r&&this.type===s.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u||(u={}));var _;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(_||(_={}));const h=0,p=1;var C=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:r,MESSAGE_PUSH:a,NEW_MESSAGE:c,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ:C}}=e;this._conversationStore=n,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(l,this._handleMessageDeleted,this),s.subscribeInnerEvent(d,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${this._name}.init`)}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;s.forEach(e=>{const{conversationID:t,unreadCount:s}=e,n=this.getLocalConversation(t);n&&n.unreadCount!==s&&(n.updateUnreadCount({nextUnreadCount:s,isUnreadC2CMessage:o}),i=!0)}),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(e){var t;for(let s=0;s<e.length;s++)if(12===e[s].Event){if(null===(t=e[s].GroupTips[0].MsgBody)||void 0===t?void 0:t.TopicId)continue;this._handleNewGroupAtTips(e[s])}}_handleGroupListSyncFinished(e){var t;const{constants:{WORKFLOW_STEP:s}}=this._core,n=e.result[s.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:o}}=this._core;let i=!1;for(let e=0;e<n.length;e++){const s=n[e],r=`${o}${s.groupID}`;if(!this.hasLocalConversation(r))continue;const a=this.getLocalConversation(r);a.groupProfile=JSON.parse(JSON.stringify(s)),a.lastMessage.lastSequence<s.nextMessageSeq&&(a.lastMessage.lastSequence=s.nextMessageSeq-1),a.subType||(a.subType=s.type),(null===(t=s._groupAtInfoList)||void 0===t?void 0:t.length)>0&&this._handleNewGroupAtTips({GroupTips:s._groupAtInfoList}),i=!0}i&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};if(0===t.length)return;const{common:{isTopic:i}}=this._core;if(i(t[0].conversationID))return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter(e=>this._isConversationNeedShow(e.conversationID)).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach(e=>{const{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)}),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:s,MsgSeq:n,GroupAtType:o}=e;return{from:t,groupID:s,sequence:n,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,s=e.getCurrentUserID();let n=!1;this._groupAtTipsList.forEach(e=>{const{groupID:o,from:i}=e;if(i!==s){const s=this.getLocalConversation(`${t.CONV_GROUP}${o}`);s&&(s.updateGroupAtInfoList(e),n=!0)}}),n&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,s;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:s=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let n=null,o=!1;t.forEach(e=>{n=this.getLocalConversation(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.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:s}=e,n=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(n))return;const{lastMessage:r}=n;if(r){const e=(null==s?void 0:s[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:s}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(s),this._core.ssoLog.debug("updateLocalConversationList",` newConversationList: ${s.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:s,isFromGetConversations:n,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,c=[],d=null==s?void 0:s.length;for(let e=0;e<d;e++){const d=new l(s[e]),{conversationID:u,type:_}=d;if(!a(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(n){this.setLocalConversation(u,d),_===t.CONV_C2C?d.unreadCount=(null==a?void 0:a.unreadCount)||0:_===t.CONV_GROUP&&(d.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:d,lastMessage:s[e].lastMessage,isFromGetConversations:n,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:d.unreadCount,isFromGetConversations:n,isUnreadC2CMessage:i}))}else c.push(d),this.setLocalConversation(u,d)}return{newConversationList:c}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:s,lastMessage:n,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:d}}=this._core;c(i)&&n&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=n.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);d(r,s,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:s,lastMessage:n,isInstantMessage:o}=e,i=this.getLocalConversation(s);if(i&&n){const{payload:e,nameCard:s,nick:r,cloudCustomData:a=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=s,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];t.forEach(t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?n.push(t):s.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)});const r=s.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime).concat(n).concat(o.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],s=[],{OuterConstant:{CONV_GROUP:n,CONV_C2C:o}}=this._core;e.forEach(e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===n){const e=i.replace(n,"");s.push(e)}}),t.length>0&&this._updateC2CConversation(t),s.length>0&&this._updateGroupConversation(s)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:s},appStore:{userStore:n},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then(e=>{((null==e?void 0:e.data)||[]).forEach(e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${s}${o}`);if(r){const s=(null===(t=n.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=s,r.userProfile=e,i=!0}}),i&&this.emitConversationListUpdate()}).catch(e=>{})}_updateGroupConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{isEmpty:o,safeStringify:i},ssoLog:r,apiMap:{getGroupProfile:a}}=this._core;let c=!1;try{yield Promise.all(e.map(e=>t(this,void 0,void 0,function*(){const t=n.getGroup(e),i=this.getLocalConversation(`${s}${e}`);t&&i&&(i.groupProfile=t,c=!0),o(t)&&i&&"function"==typeof a&&(yield a({groupID:e}))}))),c&&this.emitConversationListUpdate()}catch(e){r.debug("_updateGroupConversation",i(e))}})}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach(e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach(e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})})})}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),a.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this.getLocalConversation(e),r=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageDataHandler)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter(e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,s=this.getLocalConversationList();this._emitEvent({name:t,data:s}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_emitTotalUnreadCountUpdate",` from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach(s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.unreadCount)}),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter(e=>this._isConversationNeedShow(e.conversationID))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach(e=>{const n=this.getLocalConversation(e);(null==n?void 0:n.messageRemindType)!==t&&(n.messageRemindType=t,s=!0)}),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${s}`),s&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:s,lastReadTime:n=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(s);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],s=n&&t.time>n,r=o&&t.sequence>o;if(!s&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex(e=>!1===e[1].isPinned);t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a,SYNC_CONVERSATION_LIST:c}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:l}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,l,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(c,this._handleConversationSynced,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};var v=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}})}_getConversationList(e){const{utils:{isUndefined:t,isArray:s,isPlainObject:n}}=this._core;if(t(e))return C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter(t=>e.includes(t.conversationID))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.getLocalConversationList().filter(e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i))}return[]}_filterType(e,t){const{OuterConstant:s}=this._core;return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:s}}=this._core;return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:s}}=this._core;return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}};var g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){try{const{common:s}=this._core,n=yield function(e,s){return t(this,void 0,void 0,function*(){const{toAccount:t,userIDList:n}=e,o={To_Account:t,Peer_Account:n};return s.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:o})})}({toAccount:s.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=n||{};o.forEach(e=>{const{Peer_Account:t,MuteNotifications:s}=e,n=`${this._core.OuterConstant.CONV_C2C}${t}`,o=r(s);C.patchMessageRemindType([n],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var m=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){if(0!==e.length)try{const s=yield function(e,s){return t(this,void 0,void 0,function*(){const{groupIDList:t,responseFilter:n}=e,o={GroupIdList:t,ResponseFilter:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:o})})}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:n=[]}=s||{};n.forEach(e=>{var t;const{GroupId:s,MemberList:n}=e,o=(null===(t=n[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${s}`;C.patchMessageRemindType([i],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var f=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:n,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let d=C.getLocalConversation(e);if(o(e))return c.data.conversation=d,c;let u=!1;const _=s(e)?t:n;if(a(d)&&(u=!0,d=new l({conversationID:e,type:_})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=d,null==d?void 0:d.getProfileCompleted())return c;if(_===t){const s=e.replace(t,"");yield this._handleC2CConversation(d,s),u&&(yield g.get([s]))}if(_===n){const t=e.replace(n,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(d,t),u&&d.groupProfile.type!==i&&(yield m.get([t]))}return c})}_handleC2CConversation(e,s){return t(this,void 0,void 0,function*(){var t,n;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,d=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[s]});if(0===(null==d?void 0:d.data.length))throw new i.ChatError({code:_.USER_OR_GRP_NOT_FOUND});e.userProfile=null==d?void 0:d.data[0];const u=null===(n=c.getFriend(s))||void 0===n?void 0:n.remark;r(u)||e.remark===u||(e.remark=u),e.setProfileCompleted();const h=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.appendToPinnedConversation(e)})}_handleGroupConversation(e,s){return t(this,void 0,void 0,function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:n}}=this._core,{conversationID:o}=e,i=yield t({groupID:s});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)})}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.getTotalUnreadMessageCount()}};var E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){this._core=e;const{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:s}=this._core;e.forEach(e=>{const{ReadC2cMsgNotify:n}=e;if(!t(n)){const{UinPairReadArray:e=[]}=n;e.forEach(e=>{const{From_Account:t,LastReadTime:n}=e,o=`${s.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${n}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.updateUnreadCount(o)})}})}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:s}}=this._core;e.forEach(e=>{const{GroupReadInfoArray:n}=e.MsgBody;s(n)||n.forEach(e=>{const{GroupId:s,LastReadMsgSeq:n}=e,o=`${t.CONV_GROUP}${s}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${n}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.updateUnreadCount(o),this._clearGroupAtInfoList(o)})})}setMessageRead(e){return t(this,void 0,void 0,function*(){var t,s;const{OuterConstant:n}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r.groupAtInfoList));if(r.type===n.CONV_GROUP&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})})}setAllMessageRead(){return t(this,arguments,void 0,function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;s.scope||(s.scope=n);const{scope:r}=s,a=this._generateSetAllMessageReadRequestData(r);if(a.allC2CMessageReadStatus===h&&0===a.groupMessageReadInfoList.length)return{code:0};try{const s=yield function(s){return t(this,void 0,void 0,function*(){const{allC2CMessageReadStatus:t,groupMessageReadInfoList:n}=s,o={C2CReadAllMsg:t,GroupReadInfo:n};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:o})})}(a);if(s){const{GroupReadInfoArray:e,C2CReadAllMsg:t}=s,n=this._parseGroupReadInfo(e);this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})>0&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}})}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.emitConversationListUpdate()}_updateAllConversationReadStatus(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:n}=this._core,o=n.conversationStore.getConversationMap(),{allC2CMessageReadStatus:i}=e;let r=0;for(const[e,n]of o)if(n.unreadCount>=1){if(i===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.markMessageAsRead({conversationID:e,lastReadTime:t})}else if(n.type===s){const t=e.replace(s,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){const s=this._serverGroupConversationLastReadSeqMap.get(t);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.updateUnreadCount(e,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_C2C_MSG:n},appStore:o}=this._core,i={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},r=o.conversationStore.getConversationMap();for(const[,o]of r){const{type:r,unreadCount:a}=o;if(this._shouldSetAllMessageRead({scope:e,type:r,unreadCount:a}))if(r===t&&i.allC2CMessageReadStatus===h){if(i.allC2CMessageReadStatus=p,e===n)break}else if(r===s){const e=this._getLocalMessageMaxSequence(o),{groupID:t}=o.groupProfile;i.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return i}_parseGroupReadInfo(e){const{utils:{isUndefined:t}}=this._core,s=[];return null==e||e.forEach(e=>{const{GroupId:n,MsgSeq:o,RetCode:i,LastReadMsgSeq:r}=e;t(i)?this._serverGroupConversationLastReadSeqMap.set(n,r):(this._serverGroupConversationLastReadSeqMap.set(n,o),0!==i&&s.push(`${n}-${o}-${i}`))}),s}_deleteGroupAtTips(e){return t(this,void 0,void 0,function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const s=C.getLocalConversation(e);if(!s)return;const n=(null==s?void 0:s.groupAtInfoList)||[];if(0!==n.length)try{const{common:{getCurrentUserID:s,isCommunity:o},OuterConstant:{CONV_GROUP:i,CONV_AT_ALL:r}}=this._core;let a=[...n];if(o({groupID:e.replace(i,"")})&&(a=n.filter(e=>!e.atTypeArray.includes(r)),0===a.length))return void this._clearGroupAtInfoList(e,!1);const c=a.map(e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID}));yield function(e,s){return t(this,void 0,void 0,function*(){const{messageListToDelete:t}=e,n={DelMsgList:t};return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:n})})}({messageListToDelete:c},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${n.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}})}_clearGroupAtInfoList(e,t=!0){const s=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.emitConversationListUpdate())}_getLocalMessageMaxTime(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){return s.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})})}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:s,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${s}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}})}_setGroupMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,lastMessageSequence:n}=e,o={GroupId:t,MsgReadedSeq:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:o})})}({groupID:e.replace("GROUP",""),lastMessageSequence:s},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${s}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}})}_shouldSetAllMessageRead(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}}=this._core,{type:r,scope:a,unreadCount:c}=e;return!(c<=0)&&(!(r!==t||![n,o].includes(a))||!(r!==s||![n,i].includes(a)))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:s}}=this._core;if(!s(e))return;const{OuterConstant:n}=this._core;let o=!1;e.forEach(e=>{const{Type:s,To_Account:i,GroupId:r}=e;let a;1===s?a=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.getLocalConversation(`${n.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))}),o&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.replace(i.CONV_GROUP,"")});const o=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,operationType:n,itemList:o}=e,i={From_Account:t,OperationType:n,RecentContactItem:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.top",data:i})})}({fromAccount:r.getCurrentUserID(),operationType:!0===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}})}};var S=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:s}=this._core,n=[];e.forEach(e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&n.push(`${s.CONV_C2C}${o}`),2===t&&n.push(`${s.CONV_GROUP}${i}`)}),console.log(`${this._name}.handleConversationDeleted conversationIDList:${n}`),this._deleteLocalConversationList(n)}deleteConversation(e){return t(this,void 0,void 0,function*(){const{utils:{isString:t}}=this._core;if(t(e))return void(yield this._deleteConversation({conversationIDList:[e],flag:u.ONLY_CONVERSATIONID}));const s=Object.assign({},e);s.conversationIDList.length>100&&(s.conversationIDList=s.conversationIDList.slice(0,100)),yield this._deleteConversation(s)})}_deleteConversation(e){return t(this,void 0,void 0,function*(){const{conversationIDList:t,clearHistoryMessage:s=!0,flag:n=0}=e,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,s)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}})}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter(e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.getLocalConversation(e))||void 0===s?void 0:s.type;return n!==t.CONV_GROUP||this._hasLocalGroup(e)?n===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)})}_deleteConversationFromServer(e,s){return t(this,void 0,void 0,function*(){const{OuterConstant:n,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:s?1:0};if(e.forEach(e=>{var t;if(C.hasLocalConversation(e)){const s=(null===(t=C.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(s,"");s===n.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):s===n.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}}),0===i.conversationList.length)return[];const r=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,conversationList:n,clearHistoryMessage:o}=e,i={From_Account:t,ContactItem:n,ClearRamble:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:i})})}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach(e=>{if(0===e.ResultCode){const s=1===e.Type?`${n.CONV_C2C}${e.To_Account}`:`${n.CONV_GROUP}${e.ToGroupid}`;t.push(s)}}),this._deleteLocalConversationList(t),t}return[]})}_deleteLocalConversationList(e){let t=!1;e.forEach(e=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,n=e.replace(t,"");return!!s.getGroup(n)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var I=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,function*(){const{conversationID:t,draftText:s}=e;if(console.log(`${this._name} conversationID:${t} draftText:${s}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.emitConversationListUpdate(),{code:0,data:{conversation:n}}})}};var L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(s,n){return t(this,void 0,void 0,function*(){s.length>30&&(console.warn(`${this._name}.set userIDList length:${s.length} exceeds limit 30`),s.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=e.core.OuterConstant;return{[t]:0,[s]:1,[n]:2}}()[n],i=yield function(e,s){return t(this,void 0,void 0,function*(){const{userIDList:t,receiveMessageOption:n}=e,o={Peer_Account:t,Mute_Notifications:n};return s.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:o})})}({userIDList:s,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach(e=>{const{Peer_Account:t,ErrorCode:n}=e;a.push({userID:t,code:n});const o=s.indexOf(t);o>-1&&s.splice(o,1)});const c=[],l=[],{OuterConstant:d}=this._core;return s.forEach(e=>{l.push(`${d.CONV_C2C}${e}`),c.push({userID:e})}),C.patchMessageRemindType(l,n),{code:0,data:{successUserIDList:c,failureUserIDList:a}}})}};var O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,s){return t(this,void 0,void 0,function*(){const{common:{getCurrentUserID:n,isTopic:o},OuterConstant:i}=this._core;if(yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,userID:n,receiveMessageOption:o}=e,i={GroupId:t,Member_Account:n,MsgFlag:o};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:i})})}({groupID:e,userID:n(),receiveMessageOption:s},this._core),!o(e)){const t=`${i.CONV_GROUP}${e}`;C.patchMessageRemindType([t],s)}return{code:0,data:{groupID:e,messageRemindType:s}}})}};var T=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:s,ssoLog:n}=this._core;e.forEach(e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map(e=>`${s.CONV_C2C}${e}`),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}})}setMessageRemindType(e){return t(this,void 0,void 0,function*(){const t="setMessageRemindType",{groupID:s,userIDList:n,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${this._name}.${t} userIDList:${n} messageRemindType:${o}`);return yield L.set(n,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const s=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,s),s}})}};var y=new class{init(e){e.ssoLog.debug("ConversationAction.init"),this._core=e,v.init(e),f.init(e),M.init(e),E.init(e),R.init(e),S.init(e),I.init(e),T.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(s,o,this._onConversationModified,this),t.subscribeInnerEvent(s,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(s,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(s,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(n,this._dispose,this)}_onConversationModified(e){const{constants:{ConvModifyPushType:t}}=this._core,{RecentContactMod:s=[]}=e;s.forEach(e=>{const{PushType:s}=e;if(s===t.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;S.handleConversationDeleted(t)}if(s===t.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(s===t.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}})}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;E.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;T.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;E.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}};var A=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(s){return t(this,void 0,void 0,function*(){try{const{OuterConstant:{MSG_REMIND_ACPT_NOT_NOTE:n}}=this._core,{messageRemindType:o=n,isRepeated:i=!0}=s,{startTime:r=0,endTime:a=0}=this._calcStartAndEndTime(s),c=yield function(s){return t(this,void 0,void 0,function*(){const{common:t}=e.core,{startTime:n,endTime:o,isRepeated:i,messageRemindType:r}=s,a={StartTime:n,EndTime:o,IsRepeated:i,Level:r};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:a})})}({messageRemindType:this._getType(o),startTime:r,endTime:a,isRepeated:i?d.ON:d.OFF});return{code:0,data:{errorCode:c.ErrorCode,errorInfo:c.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}})}_calcStartAndEndTime(e){const{startHour:t=0,startMinute:s=0,startSecond:n=0,duration:o=0,isRepeated:i=!0}=e,r=new Date,a=new Date(r.getFullYear(),r.getMonth(),r.getDate(),t,s,n),c=Math.round(a.getTime()/1e3);let l=c+o;return i&&o>=86400&&(l=c+86400),{startTime:c,endTime:l}}_getType(e){const{OuterConstant:t}=this._core;return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}};var D=new class{init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:n}=e;t.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),s.subscribeInnerEvent(n.MESSAGE_PUSH,s.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){const t=this._handleResult(e),{notificationCenter:s,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:n}}=this._core;s.emitOuterEvent(n,{name:n,data:t})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,function*(){try{const s=yield function(){return t(this,void 0,void 0,function*(){const{common:t}=e.core,s={To_Account:t.getCurrentUserID()};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:s})})}();return{code:0,data:this._handleResult(s)}}catch(e){c("getAllReceiveMessageOpt",e)}})}_handleResult(e){const{OuterConstant:t}=this._core,{MSG_REMIND_ACPT_AND_NOTE:s,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:o}=t,i={0:s,1:n,2:o},{Level:r,StartTime:a,EndTime:c,IsRepeated:l}=e;return{messageRemindType:i[r]||s,startTime:a,endTime:c,isRepeated:l===d.ON}}};var N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:s,isObject:n,isString:o}}}=e;if(!o(t)&&!n(t))return"options is String or Object.";if(o(t)&&G(t))return"conversationID is invalid.";if(n(t)){if(!s(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some(e=>{if(G(e))return!0}))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!s(e)&&!n(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};return new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}}});
|
|
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";const e=new class{init(e){this.core=e}};function t(e,t,s,n){return new(s||(s=Promise))((function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t===s.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{OuterConstant:s}=e.core;let n="";return 0===t?n=s.MSG_REMIND_ACPT_AND_NOTE:1===t?n=s.MSG_REMIND_DISCARD:2===t?n=s.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(n=s.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}function a(t){const{OuterConstant:s}=e.core;let n;return t.startsWith(s.CONV_C2C)&&(n=t.replace(s.CONV_C2C,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}function c(t,s){const{helper:n}=e.core,o=new n.ChatError({functionName:t,code:(null==s?void 0:s.errorCode)||(null==s?void 0:s.code),message:(null==s?void 0:s.errorInfo)||(null==s?void 0:s.message)});throw console.error(`${t} fail:`,o),o}class l{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.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(){const{core:{OuterConstant:t,utils:{isUndefined:s}}}=e;s(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={userID:this.conversationID.replace(t.CONV_C2C,"")}:s(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={groupID:this.conversationID.replace(t.CONV_GROUP,""),selfInfo:{},lastMessage:{}}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;n(o)||(this.subType!==s.GRP_AVCHATROOM?i&&this.type===s.CONV_GROUP||r&&this.type===s.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u||(u={}));var _;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(_||(_={}));const h=0,p=1;var C=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:r,MESSAGE_PUSH:a,NEW_MESSAGE:c,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ:C}}=e;this._conversationStore=n,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(l,this._handleMessageDeleted,this),s.subscribeInnerEvent(d,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${this._name}.init`)}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;s.forEach((e=>{const{conversationID:t,unreadCount:s}=e,n=this.getLocalConversation(t);n&&n.unreadCount!==s&&(n.updateUnreadCount({nextUnreadCount:s,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(e){var t;for(let s=0;s<e.length;s++)if(12===e[s].Event){if(null===(t=e[s].GroupTips[0].MsgBody)||void 0===t?void 0:t.TopicId)continue;this._handleNewGroupAtTips(e[s])}}_handleGroupListSyncFinished(e){var t;const{constants:{WORKFLOW_STEP:s}}=this._core,n=e.result[s.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:o}}=this._core;let i=!1;for(let e=0;e<n.length;e++){const s=n[e],r=`${o}${s.groupID}`;if(!this.hasLocalConversation(r))continue;const a=this.getLocalConversation(r);a.groupProfile=JSON.parse(JSON.stringify(s)),a.lastMessage.lastSequence<s.nextMessageSeq&&(a.lastMessage.lastSequence=s.nextMessageSeq-1),a.subType||(a.subType=s.type),(null===(t=s._groupAtInfoList)||void 0===t?void 0:t.length)>0&&this._handleNewGroupAtTips({GroupTips:s._groupAtInfoList}),i=!0}i&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};if(0===t.length)return;const{common:{isTopic:i}}=this._core;if(i(t[0].conversationID))return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:s,MsgSeq:n,GroupAtType:o}=e;return{from:t,groupID:s,sequence:n,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,s=e.getCurrentUserID();let n=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==s){const s=this.getLocalConversation(`${t.CONV_GROUP}${o}`);s&&(s.updateGroupAtInfoList(e),n=!0)}})),n&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,s;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:s=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this.getLocalConversation(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.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:s}=e,n=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(n))return;const{lastMessage:r}=n;if(r){const e=(null==s?void 0:s[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:s}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(s),this._core.ssoLog.debug("updateLocalConversationList",` newConversationList: ${s.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:s,isFromGetConversations:n,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,c=[],d=null==s?void 0:s.length;for(let e=0;e<d;e++){const d=new l(s[e]),{conversationID:u,type:_}=d;if(!a(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(n){this.setLocalConversation(u,d),_===t.CONV_C2C?d.unreadCount=(null==a?void 0:a.unreadCount)||0:_===t.CONV_GROUP&&(d.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:d,lastMessage:s[e].lastMessage,isFromGetConversations:n,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:d.unreadCount,isFromGetConversations:n,isUnreadC2CMessage:i}))}else c.push(d),this.setLocalConversation(u,d)}return{newConversationList:c}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:s,lastMessage:n,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:d}}=this._core;c(i)&&n&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=n.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);d(r,s,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:s,lastMessage:n,isInstantMessage:o}=e,i=this.getLocalConversation(s);if(i&&n){const{payload:e,nameCard:s,nick:r,cloudCustomData:a=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=s,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?n.push(t):s.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=s.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(n).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],s=[],{OuterConstant:{CONV_GROUP:n,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===n){const e=i.replace(n,"");s.push(e)}})),t.length>0&&this._updateC2CConversation(t),s.length>0&&this._updateGroupConversation(s)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:s},appStore:{userStore:n},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${s}${o}`);if(r){const s=(null===(t=n.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=s,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{isEmpty:o,safeStringify:i},ssoLog:r,apiMap:{getGroupProfile:a}}=this._core;let c=!1;try{yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){const t=n.getGroup(e),i=this.getLocalConversation(`${s}${e}`);t&&i&&(i.groupProfile=t,c=!0),o(t)&&i&&"function"==typeof a&&(yield a({groupID:e}))}))))),c&&this.emitConversationListUpdate()}catch(e){r.debug("_updateGroupConversation",i(e))}}))}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach((e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach((e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})}))}))}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach((e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))})),a.forEach((e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))})),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this.getLocalConversation(e),r=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageDataHandler)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){var t,s;e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:n},conversation:o}=this._core,i=this.getLocalConversationList();this._emitEvent({name:n,data:i,isSyncCompleted:null===(s=null===(t=null==o?void 0:o.syncConversationHandler)||void 0===t?void 0:t.isSyncCompleted)||void 0===s?void 0:s.call(t)}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_emitTotalUnreadCountUpdate",` from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach((s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.unreadCount)})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach((e=>{const n=this.getLocalConversation(e);(null==n?void 0:n.messageRemindType)!==t&&(n.messageRemindType=t,s=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${s}`),s&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:s,lastReadTime:n=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(s);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],s=n&&t.time>n,r=o&&t.sequence>o;if(!s&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex((e=>!1===e[1].isPinned));t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a,SYNC_CONVERSATION_LIST:c}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:l}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,l,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(c,this._handleConversationSynced,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};var v=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:s,isPlainObject:n}}=this._core;if(t(e))return C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:s}=this._core;return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:s}}=this._core;return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:s}}=this._core;return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}};var g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:s}=this._core,n=yield function(e,s){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:n}=e,o={To_Account:t,Peer_Account:n};return s.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:o})}))}({toAccount:s.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=n||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:s}=e,n=`${this._core.OuterConstant.CONV_C2C}${t}`,o=r(s);C.patchMessageRemindType([n],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var m=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const s=yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:n}=e,o={GroupIdList:t,ResponseFilter:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:o})}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:n=[]}=s||{};n.forEach((e=>{var t;const{GroupId:s,MemberList:n}=e,o=(null===(t=n[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${s}`;C.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var f=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:n,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let d=C.getLocalConversation(e);if(o(e))return c.data.conversation=d,c;let u=!1;const _=s(e)?t:n;if(a(d)&&(u=!0,d=new l({conversationID:e,type:_})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=d,null==d?void 0:d.getProfileCompleted())return c;if(_===t){const s=e.replace(t,"");yield this._handleC2CConversation(d,s),u&&(yield g.get([s]))}if(_===n){const t=e.replace(n,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(d,t),u&&d.groupProfile.type!==i&&(yield m.get([t]))}return c}))}_handleC2CConversation(e,s){return t(this,void 0,void 0,(function*(){var t,n;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,d=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[s]});if(0===(null==d?void 0:d.data.length))throw new i.ChatError({code:_.USER_OR_GRP_NOT_FOUND});e.userProfile=null==d?void 0:d.data[0];const u=null===(n=c.getFriend(s))||void 0===n?void 0:n.remark;r(u)||e.remark===u||(e.remark=u),e.setProfileCompleted();const h=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.appendToPinnedConversation(e)}))}_handleGroupConversation(e,s){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:n}}=this._core,{conversationID:o}=e,i=yield t({groupID:s});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)}))}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.getTotalUnreadMessageCount()}};var E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){this._core=e;const{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:s}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:n}=e;if(!t(n)){const{UinPairReadArray:e=[]}=n;e.forEach((e=>{const{From_Account:t,LastReadTime:n}=e,o=`${s.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${n}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:s}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:n}=e.MsgBody;s(n)||n.forEach((e=>{const{GroupId:s,LastReadMsgSeq:n}=e,o=`${t.CONV_GROUP}${s}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${n}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,s;const{OuterConstant:n}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r.groupAtInfoList));if(r.type===n.CONV_GROUP&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})}))}setAllMessageRead(){return t(this,arguments,void 0,(function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;s.scope||(s.scope=n);const{scope:r}=s,a=this._generateSetAllMessageReadRequestData(r);if(a.allC2CMessageReadStatus===h&&0===a.groupMessageReadInfoList.length)return{code:0};try{const s=yield function(s){return t(this,void 0,void 0,(function*(){const{allC2CMessageReadStatus:t,groupMessageReadInfoList:n}=s,o={C2CReadAllMsg:t,GroupReadInfo:n};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:o})}))}(a);if(s){const{GroupReadInfoArray:e,C2CReadAllMsg:t}=s,n=this._parseGroupReadInfo(e);this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})>0&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}}))}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.emitConversationListUpdate()}_updateAllConversationReadStatus(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:n}=this._core,o=n.conversationStore.getConversationMap(),{allC2CMessageReadStatus:i}=e;let r=0;for(const[e,n]of o)if(n.unreadCount>=1){if(i===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.markMessageAsRead({conversationID:e,lastReadTime:t})}else if(n.type===s){const t=e.replace(s,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){const s=this._serverGroupConversationLastReadSeqMap.get(t);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.updateUnreadCount(e,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_C2C_MSG:n},appStore:o}=this._core,i={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},r=o.conversationStore.getConversationMap();for(const[,o]of r){const{type:r,unreadCount:a}=o;if(this._shouldSetAllMessageRead({scope:e,type:r,unreadCount:a}))if(r===t&&i.allC2CMessageReadStatus===h){if(i.allC2CMessageReadStatus=p,e===n)break}else if(r===s){const e=this._getLocalMessageMaxSequence(o),{groupID:t}=o.groupProfile;i.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return i}_parseGroupReadInfo(e){const{utils:{isUndefined:t}}=this._core,s=[];return null==e||e.forEach((e=>{const{GroupId:n,MsgSeq:o,RetCode:i,LastReadMsgSeq:r}=e;t(i)?this._serverGroupConversationLastReadSeqMap.set(n,r):(this._serverGroupConversationLastReadSeqMap.set(n,o),0!==i&&s.push(`${n}-${o}-${i}`))})),s}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const s=C.getLocalConversation(e);if(!s)return;const n=(null==s?void 0:s.groupAtInfoList)||[];if(0!==n.length)try{const{common:{getCurrentUserID:s,isCommunity:o},OuterConstant:{CONV_GROUP:i,CONV_AT_ALL:r}}=this._core;let a=[...n];if(o({groupID:e.replace(i,"")})&&(a=n.filter((e=>!e.atTypeArray.includes(r))),0===a.length))return void this._clearGroupAtInfoList(e,!1);const c=a.map((e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,s){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e,n={DelMsgList:t};return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:n})}))}({messageListToDelete:c},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${n.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e,t=!0){const s=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.emitConversationListUpdate())}_getLocalMessageMaxTime(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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(e,s){return t(this,void 0,void 0,(function*(){try{yield function(e,s){return t(this,void 0,void 0,(function*(){return s.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:s,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${s}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,s){return t(this,void 0,void 0,(function*(){try{yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:n}=e,o={GroupId:t,MsgReadedSeq:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:o})}))}({groupID:e.replace("GROUP",""),lastMessageSequence:s},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${s}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}_shouldSetAllMessageRead(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}}=this._core,{type:r,scope:a,unreadCount:c}=e;return!(c<=0)&&(!(r!==t||![n,o].includes(a))||!(r!==s||![n,i].includes(a)))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:s}}=this._core;if(!s(e))return;const{OuterConstant:n}=this._core;let o=!1;e.forEach((e=>{const{Type:s,To_Account:i,GroupId:r}=e;let a;1===s?a=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.getLocalConversation(`${n.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.replace(i.CONV_GROUP,"")});const o=yield function(e,s){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:n,itemList:o}=e,i={From_Account:t,OperationType:n,RecentContactItem:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.top",data:i})}))}({fromAccount:r.getCurrentUserID(),operationType:!0===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}}))}};var S=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:s}=this._core,n=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&n.push(`${s.CONV_C2C}${o}`),2===t&&n.push(`${s.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${n}`),this._deleteLocalConversationList(n)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return void(yield this._deleteConversation({conversationIDList:[e],flag:u.ONLY_CONVERSATIONID}));const s=Object.assign({},e);s.conversationIDList.length>100&&(s.conversationIDList=s.conversationIDList.slice(0,100)),yield this._deleteConversation(s)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:s=!0,flag:n=0}=e,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,s)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.getLocalConversation(e))||void 0===s?void 0:s.type;return n!==t.CONV_GROUP||this._hasLocalGroup(e)?n===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,s){return t(this,void 0,void 0,(function*(){const{OuterConstant:n,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:s?1:0};if(e.forEach((e=>{var t;if(C.hasLocalConversation(e)){const s=(null===(t=C.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(s,"");s===n.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):s===n.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,s){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:n,clearHistoryMessage:o}=e,i={From_Account:t,ContactItem:n,ClearRamble:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:i})}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const s=1===e.Type?`${n.CONV_C2C}${e.To_Account}`:`${n.CONV_GROUP}${e.ToGroupid}`;t.push(s)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,n=e.replace(t,"");return!!s.getGroup(n)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var I=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:s}=e;if(console.log(`${this._name} conversationID:${t} draftText:${s}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.emitConversationListUpdate(),{code:0,data:{conversation:n}}}))}};var L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(s,n){return t(this,void 0,void 0,(function*(){s.length>30&&(console.warn(`${this._name}.set userIDList length:${s.length} exceeds limit 30`),s.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=e.core.OuterConstant;return{[t]:0,[s]:1,[n]:2}}()[n],i=yield function(e,s){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:n}=e,o={Peer_Account:t,Mute_Notifications:n};return s.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:o})}))}({userIDList:s,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:n}=e;a.push({userID:t,code:n});const o=s.indexOf(t);o>-1&&s.splice(o,1)}));const c=[],l=[],{OuterConstant:d}=this._core;return s.forEach((e=>{l.push(`${d.CONV_C2C}${e}`),c.push({userID:e})})),C.patchMessageRemindType(l,n),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,s){return t(this,void 0,void 0,(function*(){const{common:{getCurrentUserID:n,isTopic:o},OuterConstant:i}=this._core;if(yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:n,receiveMessageOption:o}=e,i={GroupId:t,Member_Account:n,MsgFlag:o};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:i})}))}({groupID:e,userID:n(),receiveMessageOption:s},this._core),!o(e)){const t=`${i.CONV_GROUP}${e}`;C.patchMessageRemindType([t],s)}return{code:0,data:{groupID:e,messageRemindType:s}}}))}};var T=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:s,ssoLog:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map((e=>`${s.CONV_C2C}${e}`)),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:s,userIDList:n,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${this._name}.${t} userIDList:${n} messageRemindType:${o}`);return yield L.set(n,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const s=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,s),s}}))}};var y=new class{init(e){e.ssoLog.debug("ConversationAction.init"),this._core=e,v.init(e),f.init(e),M.init(e),E.init(e),R.init(e),S.init(e),I.init(e),T.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(s,o,this._onConversationModified,this),t.subscribeInnerEvent(s,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(s,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(s,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(n,this._dispose,this)}_onConversationModified(e){const{constants:{ConvModifyPushType:t}}=this._core,{RecentContactMod:s=[]}=e;s.forEach((e=>{const{PushType:s}=e;if(s===t.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;S.handleConversationDeleted(t)}if(s===t.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(s===t.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;E.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;T.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;E.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}};var A=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(s){return t(this,void 0,void 0,(function*(){try{const{OuterConstant:{MSG_REMIND_ACPT_NOT_NOTE:n}}=this._core,{messageRemindType:o=n,isRepeated:i=!0}=s,{startTime:r=0,endTime:a=0}=this._calcStartAndEndTime(s),c=yield function(s){return t(this,void 0,void 0,(function*(){const{common:t}=e.core,{startTime:n,endTime:o,isRepeated:i,messageRemindType:r}=s,a={StartTime:n,EndTime:o,IsRepeated:i,Level:r};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:a})}))}({messageRemindType:this._getType(o),startTime:r,endTime:a,isRepeated:i?d.ON:d.OFF});return{code:0,data:{errorCode:c.ErrorCode,errorInfo:c.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}}))}_calcStartAndEndTime(e){const{startHour:t=0,startMinute:s=0,startSecond:n=0,duration:o=0,isRepeated:i=!0}=e,r=new Date,a=new Date(r.getFullYear(),r.getMonth(),r.getDate(),t,s,n),c=Math.round(a.getTime()/1e3);let l=c+o;return i&&o>=86400&&(l=c+86400),{startTime:c,endTime:l}}_getType(e){const{OuterConstant:t}=this._core;return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}};var D=new class{init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:n}=e;t.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),s.subscribeInnerEvent(n.MESSAGE_PUSH,s.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){const t=this._handleResult(e),{notificationCenter:s,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:n}}=this._core;s.emitOuterEvent(n,{name:n,data:t})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,(function*(){try{const s=yield function(){return t(this,void 0,void 0,(function*(){const{common:t}=e.core,s={To_Account:t.getCurrentUserID()};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:s})}))}();return{code:0,data:this._handleResult(s)}}catch(e){c("getAllReceiveMessageOpt",e)}}))}_handleResult(e){const{OuterConstant:t}=this._core,{MSG_REMIND_ACPT_AND_NOTE:s,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:o}=t,i={0:s,1:n,2:o},{Level:r,StartTime:a,EndTime:c,IsRepeated:l}=e;return{messageRemindType:i[r]||s,startTime:a,endTime:c,isRepeated:l===d.ON}}};var N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:s,isObject:n,isString:o}}}=e;if(!o(t)&&!n(t))return"options is String or Object.";if(o(t)&&G(t))return"conversationID is invalid.";if(n(t)){if(!s(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if(G(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!s(e)&&!n(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};return new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}}}));
|