@tencentcloud/lite-chat 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function r(r,o,t,e){return new(t||(t=Promise))((function(i,n){function s(r){try{a(e.next(r))}catch(r){n(r)}}function c(r){try{a(e.throw(r))}catch(r){n(r)}}function a(r){var o;r.done?i(r.value):(o=r.value,o instanceof t?o:new t((function(r){r(o)}))).then(s,c)}a((e=e.apply(r,o||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o="group";var t=new class{init(r){this._core=r;const{helper:o}=r;o.registerApi("searchGroupByID",this),o.registerApi("getGroupList",this),o.registerApi("getGroupApplicationList",this)}searchGroupByID(t){return r(this,void 0,void 0,(function*(){try{console.log(`${o} searchGroupByID: groupID: ${t}`);const e=yield function(o,t){return r(this,void 0,void 0,(function*(){try{const{helper:r,channel:e}=t,i="group_open_http_svc.get_group_public_info",n={GroupIdList:[o]},s=r.generateProtocolData({servcmd:i,data:n}),c=`${s.head.seq}${i}`;return yield e.sendPacket(s,{requestId:c})}catch(r){throw console.warn("searchGroupByID error:",r),r}}))}(t,this._core);return this._parseSearchGroupByIDResponse(e),{code:0,data:{group:{groupID:t}}}}catch(r){throw console.warn(`${o} searchGroupByID error:`,r),r}}))}getGroupList(){return r(this,void 0,void 0,(function*(){return console.log(`${o} getGroupList`),{code:0,data:{groupList:[]}}}))}getGroupApplicationList(){return r(this,void 0,void 0,(function*(){return console.log(`${o} getGroupApplicationList`),{code:0,data:{applicationList:[]}}}))}_parseSearchGroupByIDResponse(r){var o;const t=null===(o=r.GroupInfo)||void 0===o?void 0:o[0];if(0!==(null==t?void 0:t.ErrorCode))throw new this._core.helper.ChatError({functionName:"searchGroupByID",code:null==t?void 0:t.ErrorCode,message:null==t?void 0:t.ErrorCode});return r}};var e=new class{init(r){this._core=r}};var i=new class{init(r){this._core=r}};var n=new class{init(r){this._core=r}};var s=new class{init(r){this._core=r}};const c={searchGroupByID:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}]},a={getGroupList:!0,searchGroupByID:!0,getGroupApplicationList:!0};var u=new class{install(r){t.init(r),e.init(r),i.init(r),n.init(r),s.init(r),r.helper.registerValidateConfig({auth:a,params:c})}};export{u as default};
1
+ const e=new class{init(e){this.core=e}},t="AVChatRoom",o="AV_HISTORY_MSG",r=["Type","Name","Introduction","Notification","FaceUrl","Owner_Account","CreateTime","InfoSeq","LastInfoTime","LastMsgTime","MemberNum","MaxMemberNum","ApplyJoinOption","NextMsgSeq","ShutUpAllMember","InviteJoinOption","LastRecallTime"],i=["Type","Name","Introduction","Notification","FaceUrl","CreateTime","Owner_Account","LastInfoTime","LastMsgTime","NextMsgSeq","MemberNum","MaxMemberNum","ApplyJoinOption","InviteJoinOption"],n=["Role","JoinTime","MsgFlag","MsgSeq"],s=["Role","JoinTime","MsgSeq","MsgFlag","NameCard"],u=0,a=1,c="notStart",p="resolved",l="rejected",h=10018,m=11e3,d=2,g=["Owner","Admin","Member"],_=["Role","JoinTime","NameCard","ShutUpUntil","OnlineStatus"],f=0,G=1,b=2,v=4,I=1,y=2,C=3,M=4,A=5,D=1,L=0,S=4,O=6,w=1,T=2,$=3,N=4,E=5,P=6,R=400,U=300,k={from:!0,groupID:!0,groupName:!0,to:!0},q={from:!0,groupID:!0,groupName:!0,to:!0,type:!0},F=2,j=4,x=5,K=7,V=8,J=15,B=20,H=21,Y=2600,W=2602,Q=2603,z=2620,X=2621,Z=2623,ee=2660,te=2661,oe=2681,re=2683,ie=2684,ne=2685,se=2687,ue=t=>t===e.core.OuterConstant.GRP_PUBLIC,ae=t=>t===e.core.OuterConstant.GRP_AVCHATROOM,ce=(t,o)=>{const{isArray:r}=e.core.utils;if(!r(t)||!r(o))return!1;let i=!1;return o.forEach((({key:e,value:o})=>{const r=t.find((t=>t.key===e));r?r.value!==o&&(r.value=o,i=!0):(t.push({key:e,value:o}),i=!0)})),i},pe=e=>{const t=[];if(!e)return t;for(let o=0,r=e.length;o<r;o++){const{Key:r,Value:i}=e[o];t.push({key:r,value:i})}return t},le=e=>{const t=[];for(let o=0,r=e.length;o<r;o++){const{key:r,value:i}=e[o];t.push({Key:r,Value:i})}return t},he=["groupID","name","avatar","type","introduction","notification","ownerID","selfInfo","createTime","infoSequence","lastInfoTime","lastMessage","nextMessageSeq","memberCount","maxMemberCount","memberList","joinOption","groupCustomField","muteAllMembers","isSupportTopic","inviteOption","_lastRevokedTime"];class me{constructor(e){this.groupID="",this.name="",this.avatar="",this.type="",this.introduction="",this.notification="",this.ownerID="",this.createTime=0,this.selfInfo={messageRemindType:"",joinTime:"",nameCard:"",role:"",userID:"",memberCustomField:void 0,readedSequence:0,excludedUnreadSequenceList:void 0},this.lastMessage={lastTime:0,lastSequence:0,fromAccount:"",messageForShow:""},this.nextMessageSeq=0,this.memberCount=0,this.maxMemberCount=0,this.joinOption="",this.inviteOption="",this.groupCustomField=[],this.muteAllMembers=!1,this.isSupportTopic=!1,this._lastRevokedTime=0,this._initGroup(e)}_initGroup(t){const{utils:{isString:o}}=e.core;for(const e in t)he.indexOf(e)<0||("selfInfo"!==e?"isSupportTopic"!==e?"muteAllMembers"===e&&o(t[e])?this.muteAllMembers="On"===t[e]:this[e]=t[e]:this.isSupportTopic=1===t[e]:this.updateSelfInfo(t[e]))}updateGroup(t){const{utils:{isArray:o,isUndefined:r,isNumber:i,isString:n},common:{deepMerge:s}}=e.core;t.appid=void 0,t.grossTopicNextMsgSeq=void 0,t.selfInfo&&(t.selfInfo.grossTopicReadSeq=void 0);const u=JSON.parse(JSON.stringify(t));u.lastMsgTime&&(this.lastMessage.lastTime=u.lastMsgTime),n(u.muteAllMembers)&&(u.muteAllMembers="On"===u.muteAllMembers),u.groupCustomField&&ce(this.groupCustomField,u.groupCustomField),r(u.isSupportTopic)||(this.isSupportTopic=i(u.isSupportTopic)?1===u.isSupportTopic:u.isSupportTopic),s(this,u,["members","errorCode","lastMsgTime","groupCustomField","isSupportTopic"]),o(u.members)&&u.members.length>0&&u.members.forEach((e=>{e.userID===this.selfInfo.userID&&s(this.selfInfo,e,["sequence"])}))}updateSelfInfo(t){const{nameCard:o,joinTime:r,role:i,messageRemindType:n,readedSequence:s,excludedUnreadSequenceList:u}=t,{common:{deepMerge:a}}=e.core;a(this.selfInfo,{nameCard:o,joinTime:r,role:i,messageRemindType:n,readedSequence:s,excludedUnreadSequenceList:u},[],["",null,void 0,0,NaN])}setSelfNameCard(e){this.selfInfo.nameCard=e}}var de=new class{constructor(){this._name="GroupDataHandler"}init(e){this._core=e;const{appStore:{groupStore:t}}=e;this._groupMap=t.getGroupMap(),console.log(`${this._name}.init`)}hasLocalGroup(e){return this._groupMap.has(e)}getLocalGroup(e){return this._groupMap.get(e)}updateLocalGroup(e){const{common:{getCurrentUserID:t}}=this._core;let o;e.forEach((e=>{var t;o=e.groupID,this.hasLocalGroup(o)?null===(t=this.getLocalGroup(o))||void 0===t||t.updateGroup(e):this._groupMap.set(o,new me(e))}));const r=t();for(const[,e]of this._groupMap)e.selfInfo.userID=r,"Owner"===e.selfInfo.role&&(e.ownerID=r)}deleteLocalGroup(e){this._groupMap.delete(e)}getLocalGroupList(){return[...this._groupMap.values()]}clearLocalGroup(){this._groupMap.clear()}emitGroupListUpdate(){const e=this.getLocalGroupList(),{OuterEvent:{GROUP_LIST_UPDATED:t},notificationCenter:o}=this._core;o.emitOuterEvent(t,{name:t,data:e})}updateConversationGroupProfile(e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:o}}=this._core,r=`${o}${e}`;if(t.getConversation(r)){const o=this.getLocalGroup(e);t.updateConversation(r,{groupProfile:o})}}reset(){this.clearLocalGroup()}};function ge(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(o[r[i]]=e[r[i]])}return o}function _e(e,t,o,r){return new(o||(o=Promise))((function(i,n){function s(e){try{a(r.next(e))}catch(e){n(e)}}function u(e){try{a(r.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))}function fe(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}"function"==typeof SuppressedError&&SuppressedError;const Ge=function(e){return{code:0,data:e||{}}};var be=new class{constructor(){this._name="GetGroupList",this._pagingStatus=c,this.PAGING_GRP_COUNT_LIMIT=200}init(e){this._core=e;const{helper:t,constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:r}}=e;t.registerApi({apiName:"getGroupList",context:this}),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,r.GROUP_LIST_SYNC,this._syncGroupList,this)}getGroupList(){return _e(this,void 0,void 0,(function*(){if(console.log(`${this._name}.getGroupList pagingStatus:${this._pagingStatus}`),this._pagingStatus===l||this._pagingStatus===c)return this._syncGroupList().then((()=>{const e=de.getLocalGroupList();return Ge({groupList:e,isSyncCompleted:this._isSyncCompleted()})})).catch((e=>{throw console.error(`${this._name}.getGroupList fail:`,e),e}));const e=de.getLocalGroupList();return console.log(`${this._name}.getGroupList return group count:${e.length}`),Ge({groupList:e,isSyncCompleted:this._isSyncCompleted()})}))}_syncGroupList(){return _e(this,void 0,void 0,(function*(){this._pagingStatus===c&&de.clearLocalGroup();const e=this.PAGING_GRP_COUNT_LIMIT,t=[];try{yield this._pagingGetGroupList({limit:e,offset:0,groupList:t}),this._pagingStatus=p,this._groupListTreeShaking(t),de.updateLocalGroup(t);const o=de.getLocalGroupList();return console.log(`${this._name}._syncGroupList ok, count:${o.length}`),de.emitGroupListUpdate(),o}catch(e){throw this._pagingStatus=l,console.error(`${this._name}._syncGroupList fail:`,e),e}}))}_pagingGetGroupList(e){return _e(this,void 0,void 0,(function*(){const{isCommunityRelay:t=!1,groupList:o}=e;let i,{limit:s,offset:u}=e;const a=[...r];t&&(i=this._core.OuterConstant.GRP_COMMUNITY,a.push("AtInfoList"));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{type:o,limit:r,offset:i,memberAccount:n,responseFilter:s}=e;return fe(o?"million_group_open_http_svc.get_joined_group_list":"group_open_http_svc.get_joined_group_list",{Limit:r,Offset:i,Member_Account:n,ResponseFilter:s,SupportTopic:0,NeedAppDefineData:1},t)}))}({type:i,limit:s,offset:u,memberAccount:this._core.store.get("login").userId,responseFilter:{GroupBaseInfoFilter:a,SelfInfoFilter:[...n]}},this._core),{GroupIdList:r=[],TotalCount:c=0}=e||{},p=this._convertGroupKey(r);o.push(...p);const l=u+s,h=!(c>l),m=`offset:${u} limit:${s} total:${c} isCompleted:${h} current:${o.length} isCommunityRelay:${t}`;return console.log(`${this._name}._pagingGetGroupList ok. ${m}`),t?h?o:(u=l,this._pagingGetGroupList({isCommunityRelay:!0,limit:s,offset:u,groupList:o})):h?(console.log(`${this._name}._pagingGetGroupList start to get community list`),u=0,this._pagingGetGroupList({isCommunityRelay:!0,limit:s,offset:u,groupList:o})):(u=l,this._pagingGetGroupList({limit:s,offset:u,groupList:o}))}catch(e){if(e.ErrorCode===h)return console.warn(`${this._name}._pagingGetGroupList response size exceeds the limit, request count:${s}`),s=50,this._pagingGetGroupList({isCommunityRelay:t,limit:s,offset:u,groupList:o});if(t)return e.code===m&&console.log(`${this._name}._pagingGetGroupList ok. community unavailable`),o;throw e}}))}_groupListTreeShaking(e){const t=new Map([...de.getLocalGroupList()]);for(let o=0,r=e.length;o<r;o++)t.delete(e[o].groupID);const o=[...t.keys()];for(let e=0,t=o.length;e<t;e++)de.deleteLocalGroup(o[e])}_isSyncCompleted(){return this._pagingStatus===p}_convertGroupKey(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppDefinedData:r,ApplyJoinOption:i,CreateTime:n,FaceUrl:s,GroupId:u,Introduction:a,InviteJoinOption:c,LastInfoTime:p,LastMsgTime:l,MemberNum:h,MaxMemberNum:m,MuteAllMember:d,Name:g,NextMsgSeq:_,Notification:f,Owner_Account:G,Type:b,LastRecallTime:v,SelfInfo:I}=e[o],y=pe(r),C=this._convertSelfInfo(I);t.push({groupCustomField:y,joinOption:i,createTime:n,avatar:s,groupID:u,introduction:a,inviteOption:c,lastInfoTime:p,lastMsgTime:l,memberCount:h,maxMemberCount:m,muteAllMembers:d,name:g,nextMessageSeq:_,notification:f,ownerID:G,type:b,_lastRevokedTime:v,selfInfo:C})}return t}_convertSelfInfo(e){const{JoinTime:t,MsgFlag:o,MsgSeq:r,NoUnreadSeqList:i,Role:n}=e;return{joinTime:t,messageRemindType:o,readedSequence:r,excludedUnreadSequenceList:i,role:n}}};var ve=new class{constructor(){this._name="CreateGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"createGroup",context:this})}createGroup(e){return _e(this,void 0,void 0,(function*(){var t;this._preCheckParams(e),console.log(`${this._name}.createGroup options:`,e);try{const{utils:{isEmpty:o},common:{getCurrentUserID:r}}=this._core,i=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{name:o,type:r,groupID:i,introduction:n,notification:s,avatar:u,maxMemberNum:a,joinOption:c,inviteOption:p,memberList:l,groupCustomField:h,isSupportTopic:m}=e;let d;return l&&(d=l.map((e=>{const{userID:t,memberCustomField:o}=e;return{Member_Account:t,AppMemberDefinedData:o?le(o):void 0}}))),fe("group_open_http_svc.create_group",{Name:o,Type:r,GroupId:i,Introduction:n,Notification:s,FaceUrl:u,MaxMemberCount:a,ApplyJoinOption:c,InviteJoinOption:p,MemberList:d,AppDefinedData:h,SupportTopic:m,webPushFlag:1},t)}))}(Object.assign(Object.assign({},e),{ownerID:r()}),this._core),{GroupId:n,OverJoinedGroupLimit_Account:s=[]}=i||{};if(console.log(`${this._name}.createGroup ok, groupType:${e.type} groupID:${n} overLimitUserIDList:${s}`),o(e.memberList)||o(s)||(e.memberList=null===(t=e.memberList)||void 0===t?void 0:t.filter((e=>s.includes(e.userID)))),this._notNeedUpdateLocalGroup(e))return Ge({group:new me(e)});de.updateLocalGroup([Object.assign(Object.assign({},e),{groupID:n})]),this._sendCustomMessage(n,e.type);const u=de.getLocalGroup(n);return de.emitGroupListUpdate(),Ge({group:u})}catch(e){throw console.error(`${this._name}.createGroup fail:`,e),e}}))}_preCheckParams(t){const{type:o,groupID:r}=t,{utils:{isEmpty:i,isUndefined:n},common:{isCommunity:s}}=this._core,u=!i(r);if(!(()=>{const{GRP_PUBLIC:t,GRP_WORK:o,GRP_MEETING:r,GRP_AVCHATROOM:i,GRP_COMMUNITY:n}=e.core.OuterConstant;return[t,o,r,i,n]})().includes(o))throw new this._core.helper.ChatError({code:Y});if(!s({type:o})){if(u&&s({groupID:r}))throw new this._core.helper.ChatError({code:W});n(t.isSupportTopic)||(t.isSupportTopic=void 0)}if(this._canIUseMemberList(o)||n(t.memberList)||(t.memberList=void 0),this._canIUseJoinOption(o)||n(t.joinOption)||(t.joinOption=void 0),this._canIUseTopic(t)&&(t.isSupportTopic=!0===t.isSupportTopic?1:0),s({type:o})&&u&&!s({groupID:r}))throw new this._core.helper.ChatError({code:W})}_canIUseMemberList(e){return!ae(e)}_canIUseJoinOption(e){return ue(e)||this._core.common.isCommunity({type:e})}_canIUseTopic(e){const{type:t,isSupportTopic:o}=e,{utils:{isUndefined:r},common:{isCommunity:i}}=this._core;return i({type:t})&&r(o)}_notNeedUpdateLocalGroup(e){const{type:t,isSupportTopic:o}=e,{OuterConstant:r}=this._core;return t===r.GRP_AVCHATROOM||t===r.GRP_COMMUNITY&&1===o}_sendCustomMessage(e,t){var o,r,i,n,s,c;const{OuterConstant:p}=this._core;let l="Create Group",h=u;t===p.GRP_COMMUNITY&&(l="Create Community",h=a);const m={to:e,conversationType:"GROUP",payload:{data:JSON.stringify({businessID:"group_create",content:l,cmd:h,opUser:this._core.store.get("login").userId,version:4})}},d=null===(i=null===(r=null===(o=this._core)||void 0===o?void 0:o.message)||void 0===r?void 0:r.messageFactory)||void 0===i?void 0:i.createCustomMessage(m);null===(c=null===(s=null===(n=this._core)||void 0===n?void 0:n.message)||void 0===s?void 0:s.messageSender)||void 0===c||c.sendMessage(d,{})}};var Ie=new class{constructor(){this._name="AttributesDataHandler",this._groupAttributesCache=new Map,this._groupAttributesCacheValuesCopy={}}init(e){this._core=e;const{helper:t,constants:o}=e;t.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.GROUP_ATTRIBUTE_CACHE_CLEAR,this.clearLocalMainSequence,this)}clearLocalMainSequence(){this._groupAttributesCache.forEach((e=>{e.localMainSequence=0}))}isGroupAttributesUpdated(e){const{elements:{newGroupProfile:t}}=e,{utils:{isEmpty:o,isUndefined:r}}=this._core;return!r(t)&&!o(t.groupAttributeOption)}handleGroupAttributesUpdated(e){const{groupID:t,groupAttributeOption:o}=e,{serverMainSequence:r,groupAttributeList:i=[],operation:n}=o;console.log(`${this._name}.handleGroupAttributesUpdated groupID:${t} operation:${n}`);const{utils:{isUndefined:s}}=this._core;s(n)||(this.refreshGroupAttributesCache({groupID:t,serverMainSequence:r,groupAttributeList:i,operation:n}),this.emitGroupAttributesUpdated(t))}initGroupAttributesCache(e){const{groupID:t,avChatRoomKey:o}=e;this._groupAttributesCache.set(t,{lastUpdateTime:0,localMainSequence:0,serverMainSequence:0,avChatRoomKey:o,values:new Map}),console.log(`${this._name}.initGroupAttributesCache. groupID:${t} avChatRoomKey:${o}`)}hasGroupAttributesCache(e){return this._groupAttributesCache.has(e)}getGroupAttributesCache(e){return this.hasGroupAttributesCache(e)||this.initGroupAttributesCache({groupID:e}),this._groupAttributesCache.get(e)}deleteGroupAttributesCache(e){this.hasGroupAttributesCache(e)&&this._groupAttributesCache.delete(e)}refreshGroupAttributesCache(e){const{groupID:t,serverMainSequence:o,groupAttributeList:r,operation:i}=e;if(this.hasGroupAttributesCache(t)){const e=this.getGroupAttributesCache(t),{localMainSequence:n}=e;i!==A&&o-n!=1||(e.serverMainSequence=o,e.localMainSequence=o,e.lastUpdateTime=Date.now(),this._updateGroupAttributesCacheValues({groupAttributes:e,groupAttributeList:r,operation:i})),o-n>1&&(e.serverMainSequence=o),this._groupAttributesCache.set(t,e),console.log(`${this._name}.refreshGroupAttributesCache. operation:${i} localMainSequence:${n} serverMainSequence:${o}`)}}_updateGroupAttributesCacheValues(e){const{groupAttributes:t,groupAttributeList:o=[],operation:r}=e;r!==C?r!==M?(r===I&&t.values.clear(),o.forEach((e=>{const{key:o,value:r,sequence:i}=e;t.values.set(o,{value:r,sequence:i})}))):o.forEach((e=>{t.values.delete(e.key)})):t.values.clear()}getGroupAttributesCacheValues(e){var t;const{groupID:o,keyList:r=[]}=e,i={};if(this.hasGroupAttributesCache(o)){const{values:e}=this.getGroupAttributesCache(o);if(0===r.length){for(const o of e.keys())i[o]=(null===(t=e.get(o))||void 0===t?void 0:t.value)||"";return i}return r.forEach((t=>{var o;e.has(t)&&(i[t]=(null===(o=e.get(t))||void 0===o?void 0:o.value)||"")})),i}return i}saveGroupAttributesCacheValuesCopy(e){this._groupAttributesCacheValuesCopy=this.getGroupAttributesCacheValues({groupID:e})}emitGroupAttributesUpdated(e){var t;const o=this.getGroupAttributesCacheValues({groupID:e}),{updatedKeyList:r,deletedKeyList:i}=this._computeValuesChangedData(o);console.log(`${this._name}.emitGroupAttributesUpdated update count:${r.length}, delete count:${i.length}`),0===r.length&&0===i.length||this._emitEvent({name:null===(t=this._core)||void 0===t?void 0:t.OuterEvent.GROUP_ATTRIBUTES_UPDATED,data:{groupID:e,groupAttributes:o,updatedKeyList:r,deletedKeyList:i}})}_computeValuesChangedData(e){const{utils:{isUndefined:t}}=this._core,o=[],r=[];return Object.keys(e).forEach((t=>{e[t]!==this._groupAttributesCacheValuesCopy[t]&&o.push(t)})),Object.keys(this._groupAttributesCacheValuesCopy).forEach((o=>{t(e[o])&&r.push(o)})),this._groupAttributesCacheValuesCopy={},{updatedKeyList:o,deletedKeyList:r}}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}convertKeyValueMapToList(e){const t=[];return Object.keys(e).forEach((o=>{t.push({key:o,value:e[o]})})),t}};var ye=new class{constructor(){this._name="DismissGroup"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"dismissGroup",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}dismissGroup(e){return _e(this,void 0,void 0,(function*(){console.log(`${this._name}.dismissGroup groupID:${e}`);try{yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.destroy_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.dismissGroup ok.`);const{type:t}=de.getLocalGroup(e);return de.deleteLocalGroup(e),de.emitGroupListUpdate(),Ie.deleteGroupAttributesCache(e),Ge({groupID:e,type:t})}catch(e){throw console.error(`${this._name}.dismissGroup fail:`,e),e}}))}};var Ce=new class{constructor(){this._name="GetGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupProfile",context:this})}getGroupProfile(e){return _e(this,void 0,void 0,(function*(){const{groupID:t,groupCustomFieldFilter:o}=e,i={groupIDList:[t],responseFilter:{GroupBaseInfoFilter:[...r],AppDefinedDataFilter_Group:o,MemberInfoFilter:[...s]}};try{const e=yield this.getGroupProfileAdvance(i),{successGroupList:o,failureGroupList:r}=e;if(r.length>0)throw r[0];let n;return!de.hasLocalGroup(t)&&ae(o[0].type)?n=new me(o[0]):(de.updateLocalGroup(o),n=de.getLocalGroup(t)),n.isSupportTopic||de.updateConversationGroupProfile(t),console.log(`${this._name}.getGroupProfile ok.`),Ge({group:n})}catch(e){throw console.error(`${this._name}.getGroupProfile fail:`,e),e}}))}getGroupProfileAdvance(e){return _e(this,void 0,void 0,(function*(){const{groupIDList:t}=e,{common:{isCommunity:o}}=this._core,r=t.filter((e=>!o({groupID:e}))),i=t.filter((e=>o({groupID:e})));r.length>50&&(r.length=50),i.length>50&&(i.length=50);const n=yield Promise.all([this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:r})),this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:i,isCommunityProfile:!0}))]),s=[],u=[];return n.forEach((e=>{s.push(...e.successGroupList),u.push(...e.failureGroupList)})),{successGroupList:s,failureGroupList:u}}))}_getGroupProfileAdvance(e){return _e(this,void 0,void 0,(function*(){const{isCommunityProfile:t=!1}=e,o=ge(e,["isCommunityProfile"]);if(0===o.groupIDList.length)return{successGroupList:[],failureGroupList:[]};try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupIDList:o,responseFilter:r}=e;return fe("group_open_http_svc.get_group_self_member_info",{GroupIdList:o,ResponseFilter:r},t)}))}(o,this._core),{GroupInfo:t=[]}=e||{},r=this._convertGroupProfileKey(t),{utils:{isUndefined:i}}=this._core,n=r.filter((e=>i(e.errorCode)||0===e.errorCode)),s=r.filter((e=>e.errorCode&&0!==e.errorCode)).map((e=>({code:e.errorCode,message:e.errorInfo,data:{groupID:e.groupID}})));return console.log(`${this._name}._getGroupProfileAdvance ok, groupID:${o.groupIDList.join(",")}`),{successGroupList:n,failureGroupList:s}}catch(e){if(t)return{successGroupList:[],failureGroupList:[]};throw e}}))}_convertGroupProfileKey(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppDefinedData:r,ApplyJoinOption:i,CreateTime:n,FaceUrl:s,GroupId:u,InfoSeq:a,Introduction:c,InviteJoinOption:p,LastInfoTime:l,LastMsgTime:h,MaxMemberNum:m,MemberNum:d,MuteAllMember:g,Name:_,NextMsgSeq:f,Notification:G,Owner_Account:b,ShutUpAllMember:v,ShutUpUntil:I,Type:y,MemberList:C,ErrorCode:M,ErrorInfo:A}=e[o],D=pe(r),L=this._convertMembers(C);t.push({groupCustomField:D,joinOption:i,createTime:n,avatar:s,groupID:u,infoSequence:a,introduction:c,inviteOption:p,lastInfoTime:l,lastMsgTime:h,maxMemberCount:m,memberCount:d,muteAllMembers:g,name:_,nextMessageSeq:f,notification:G,ownerID:b,shutUpAllMember:v,muteUntil:I,type:y,members:L,errorCode:M,errorInfo:A})}return t}_convertMembers(e){if(!e)return[];const t=[];for(let o=0,r=e.length;o<r;o++){const{AppMemberDefinedData:r,JoinTime:i,Member_Account:n,MsgFlag:s,MsgSeq:u,NameCard:a,Role:c}=e[o],p=pe(r);t.push({memberCustomField:p,joinTime:i,userID:n,messageRemindType:s,sequence:u,nameCard:a,role:c})}return t}};var Me=new class{constructor(){this._name="JoinGroup"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"joinGroup",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}joinGroup(e){return _e(this,void 0,void 0,(function*(){const{groupID:t}=e;try{if(de.hasLocalGroup(t))try{return yield Ce.getGroupProfile({groupID:t}),Ge({status:this._core.OuterConstant.JOIN_STATUS_SUCCESS})}catch(o){console.warn(`${this._name}.joinGroup ${t} was unjoined, start to join!`),de.deleteLocalGroup(t);return yield this._applyJoinGroup(e)}return yield this._applyJoinGroup(e)}catch(e){throw console.error(`${this._name}.joinGroup fail:`,e),e}}))}_applyJoinGroup(e){return _e(this,void 0,void 0,(function*(){const{OuterConstant:t,helper:r}=this._core,{groupID:i}=e,n=Object.assign({},e),s=r.checkBusinessCapabilityBits(o);s&&(n.historyMessageFlag=1);const u=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,applyMessage:r,historyMessageFlag:i}=e;return fe("group_open_http_svc.apply_join_group",{GroupId:o,ApplyMsg:r,HugeGroupHistoryMsgFlag:i},t)}))}(n,this._core),{JoinedStatus:a,LongPollingKey:c,StartSeq:p,HugeGroupFlag:l,AVChatRoomKey:h,RspMsgList:m=[]}=u||{},d=`groupID:${i} joinedStatus:${a} longPollingKey:${c} startSeq:${p} avChatRoomFlag:${l} canGetAVChatRoomHistoryMsg:${s}, historyMessageCount:${m.length}`;if(console.log(`${this._name}._applyJoinGroup ok, ${d}`),a===t.JOIN_STATUS_WAIT_APPROVAL)return{code:0,data:{status:t.JOIN_STATUS_WAIT_APPROVAL}};if(a===t.JOIN_STATUS_SUCCESS){let e=null;try{e=(yield Ce.getGroupProfile({groupID:i})).data.group}catch(t){e=new me({groupID:i}),console.warn(`${this._name}._applyJoinGroup getGroupProfile failed, groupID: ${i}, errorCode:`,null==t?void 0:t.code)}return this._handleJoinResult({group:e,avChatRoomFlag:l,longPollingKey:c,startSequence:p,avChatRoomKey:h,historyMessageList:m})}throw new this._core.helper.ChatError({code:ee})}))}_handleJoinResult(e){const{group:t,avChatRoomFlag:o,avChatRoomKey:r}=e;return 1===o?(Ie.initGroupAttributesCache({groupID:t.groupID,avChatRoomKey:r}),Ge(e)):(de.updateLocalGroup([t]),de.emitGroupListUpdate(),Ge({status:this._core.OuterConstant.JOIN_STATUS_SUCCESS,group:t}))}};var Ae=new class{constructor(){this._name="QuitGroup"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"quitGroup",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}quitGroup(e){return _e(this,void 0,void 0,(function*(){if(!de.hasLocalGroup(e))throw new this._core.helper.ChatError({code:Z});try{yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.quit_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.quitGroup ok, groupID:${e}`);const{type:t}=de.getLocalGroup(e);return de.deleteLocalGroup(e),de.emitGroupListUpdate(),Ie.deleteGroupAttributesCache(e),Ge({groupID:e,type:t})}catch(e){throw console.error(`${this._name}.quitGroup fail:`,e),e}}))}};var De=new class{constructor(){this._name="SearchGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"searchGroupByID",context:this})}searchGroupByID(e){return _e(this,void 0,void 0,(function*(){console.log(`${this._name}.searchGroupByID groupID:${e}`);try{const t=yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.get_group_public_info",{GroupIdList:[e],GroupBasePublicInfoFilter:[...i]},t)}))}(e,this._core),{GroupInfo:o=[]}=t||{},{AppDefinedData:r=[],ApplyJoinOption:n,CreateTime:s,FaceUrl:u,Introduction:a,InviteJoinOption:c,MaxMemberNum:p,MemberNum:l,Name:h,Owner_Account:m,Type:d,ErrorCode:g,ErrorInfo:_}=o[0];if(0!==g)throw new this._core.helper.ChatError({code:g,message:_});console.log(`${this._name}.searchGroupByID ok.`);const f=pe(r),G=new me({groupID:e,name:h,avatar:u,introduction:a,joinOption:n,inviteOption:c,maxMemberCount:p,memberCount:l,type:d,ownerID:m,createTime:s,groupCustomField:f});return Ge({group:G})}catch(e){throw console.error(`${this._name}.searchGroupByID fail:`,e),e}}))}};var Le=new class{constructor(){this._name="UpdateGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"updateGroupProfile",context:this})}updateGroupProfile(e){return _e(this,void 0,void 0,(function*(){const{groupID:t}=e,{utils:{isUndefined:o}}=this._core;let r=de.getLocalGroup(t);if(r){const{type:t}=r;this._canIUseJoinOption(t)||o(e.joinOption)||(console.warn(`${this._name}.updateGroupProfile joinOption is unavailable for Work/Meeting/AVChatRoom`),e.joinOption=void 0)}o(e.muteAllMembers)||(e.muteAllMembers=!0===e.muteAllMembers?"On":"Off");try{return yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,name:r,avatar:i,introduction:n,notification:s,muteAllMembers:u,joinOption:a,inviteOption:c,groupCustomField:p}=e;return fe("group_open_http_svc.modify_group_base_info",{GroupId:o,Name:r,FaceUrl:i,Introduction:n,Notification:s,ShutUpAllMember:u,ApplyJoinOption:a,InviteJoinOption:c,AppDefinedData:p?le(p):void 0},t)}))}(e,this._core),console.log(`${this._name}.updateGroupProfile groupID:${t} ok.`),r?(r.updateGroup(e),de.emitGroupListUpdate()):r=new me(e),Ge({group:r})}catch(e){throw console.error(`${this._name}.updateGroupProfile groupID:${t} fail:`,e),e}}))}_canIUseJoinOption(e){return ue(e)||this._core.common.isCommunity({type:e})}};var Se=new class{constructor(){this._name="ChangeGroupOwner"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"changeGroupOwner",context:this})}changeGroupOwner(e){return _e(this,void 0,void 0,(function*(){const t="changeGroupOwner",{groupID:o,newOwnerID:r}=e,i=de.getLocalGroup(o),{helper:n,OuterConstant:s,common:{getCurrentUserID:u}}=this._core;if((null==i?void 0:i.type)===s.GRP_AVCHATROOM)throw new n.ChatError({functionName:t,code:z});if(r===u())throw new n.ChatError({functionName:t,code:X});console.log(`${this._name}.${t} groupID:${o} newOwnerID:${r}`);try{return yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,newOwnerID:r}=e;return fe("group_open_http_svc.change_group_owner",{GroupId:o,NewOwner_Account:r},t)}))}(e,this._core),console.log(`${this._name}.${t} ok.`),i.ownerID=r,de.emitGroupListUpdate(),Ge({group:i})}catch(e){const o=new n.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var Oe=new class{constructor(){this._name="GetGroupOnlineMemberCount",this._onlineMemberCountMap=new Map}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}getGroupOnlineMemberCount(e){return _e(this,void 0,void 0,(function*(){const t="getGroupOnlineMemberCount",o=de.hasLocalGroup(e);if(console.log(`${this._name}.${t} groupID:${e} hasLocalGroup:${o}`),!o)return Ge({memberCount:0});const r=Date.now();if(this._onlineMemberCountMap.has(e)){const t=this._onlineMemberCountMap.get(e),{lastReqTime:o=0,memberCount:i=0}=t||{};if(r-o<=6e4)return Ge({memberCount:i})}try{const o=yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.get_online_member_num",{GroupId:e},t)}))}(e,this._core),{OnlineMemberNum:r=0}=o||{};return this._onlineMemberCountMap.set(e,{lastReqTime:Date.now(),memberCount:r}),console.log(`${this._name}.${t} ok. groupID:${e} memberCount:${r}`),Ge({memberCount:r})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var we=new class{init(e,t){console.log("GroupAction.init"),be.init(e),ve.init(e),ye.init(e,t),Me.init(e,t),Ae.init(e,t),De.init(e),Ce.init(e),Le.init(e),Se.init(e),Oe.init(e,t)}dismissGroup(e){return ye.dismissGroup(e)}joinGroup(e){return Me.joinGroup(e)}quitGroup(e){return Ae.quitGroup(e)}getGroupOnlineMemberCount(e){return Oe.getGroupOnlineMemberCount(e)}};function Te(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}var $e=new class{constructor(){this._name="GetGroupApplicationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupApplicationList",context:this})}getGroupApplicationList(){return _e(this,void 0,void 0,(function*(){const e="getGroupApplicationList";try{const t=yield Promise.all([this._getGroupApplicationList(),this._getGroupApplicationList({type:this._core.OuterConstant.GRP_COMMUNITY})]);console.log(`${this._name}.${e} ok.`);const o=this._handleGroupApplicationResult([...t[0],...t[1]]);return Ge({applicationList:o})}catch(t){const o=new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo});throw console.error(`${this._name}.${e} fail:`,o),o}}))}_getGroupApplicationList(t){return _e(this,void 0,void 0,(function*(){const{type:o,startTime:r=0,limit:i=20}=t||{},{common:n}=this._core;let s;try{s=yield function(t,o){return _e(this,void 0,void 0,(function*(){const{type:r,startTime:i,limit:n,handleAccount:s}=t;return Te(e.core.common.isCommunity({type:r})?"million_group_open_http_svc.get_pendency":"group_open_http_svc.get_pendency",{StartTime:i,Limit:n,Handle_Account:s},o)}))}({type:o,startTime:r,limit:i,handleAccount:n.getCurrentUserID()},this._core)}catch(e){if(11e3!==(null==e?void 0:e.errorCode))throw e;s={}}const{NextStartTime:u=0,PendencyList:a=[]}=s||{};if(0===u)return a;const c=yield this._getGroupApplicationList(Object.assign(Object.assign({},t),{startTime:u}));return[...a,...c]}))}_handleGroupApplicationResult(e){const t=[];return e.forEach((e=>{const o=this._convertApplicationData(e),{handled:r}=o,i=ge(o,["handled"]);0===r&&t.push(i)})),t}_convertApplicationData(e){const{Handled:t,AddTime:o,ApplyInviteMsg:r,Authentication:i,FromUserNickName:n,From_Account:s,GroupId:u,GroupName:a,PendencyType:c,To_Account:p}=e;return{handled:t,messageKey:o,applicant:s,applicantNick:n,groupID:u,groupName:a,authentication:i,applicationType:c,userID:p,note:r}}};var Ne=new class{constructor(){this._name="HandleGroupApplication"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"handleGroupApplication",context:this})}handleGroupApplication(t){return _e(this,void 0,void 0,(function*(){const o="handleGroupApplication",{application:r}=t,i=this._handleParams(t);try{(null==r?void 0:r.applicationType)===d?yield function(t,o){return _e(this,void 0,void 0,(function*(){const{groupID:r,handleAction:i,handleMessage:n,applicant:s,authentication:u,invitee:a}=t;return Te(e.core.common.isCommunity({groupID:r})?"million_group_open_http_svc.handle_invite_join_permission_group":"group_open_http_svc.handle_invite_join_permission_group",{GroupId:r,HandleMsg:i,ApprovalMsg:n,Applicant_Account:s,Authentication:u,Invited_Account:a},o)}))}(i,this._core):yield function(t,o){return _e(this,void 0,void 0,(function*(){const{groupID:r,handleAction:i,handleMessage:n,applicant:s,authentication:u,messageKey:a}=t;return Te(e.core.common.isCommunity({groupID:r})?"million_group_open_http_svc.handle_apply_join_group":"group_open_http_svc.handle_apply_join_group",{GroupId:r,HandleMsg:i,ApprovalMsg:n,Applicant_Account:s,Authentication:u,MsgKey:a},o)}))}(i,this._core),console.log(`${this._name}.${o} ok.`);const t=de.getLocalGroup(i.groupID);return Ge({group:t})}catch(e){const t=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${o} fail:`,t),t}}))}_handleParams(e){var t;const{handleAction:o,handleMessage:r,message:i,application:n}=e;let s,u,a,c,p;if(i){const{payload:e}=i||{};s=e.operatorID,u=null===(t=e.groupProfile)||void 0===t?void 0:t.groupID,a=e.authentication,c=e.messageKey}else s=(null==n?void 0:n.applicant)||"",u=(null==n?void 0:n.groupID)||"",a=(null==n?void 0:n.authentication)||"",c=(null==n?void 0:n.messageKey)||0;return(null==n?void 0:n.applicationType)===d&&(p=n.userID),{handleAction:o,handleMessage:r,applicant:s,invitee:p,groupID:u,authentication:a,messageKey:c}}};var Ee=new class{init(e){console.log("GroupApplication.init"),$e.init(e),Ne.init(e)}};let Pe=class{constructor(e){this.userID="",this.avatar="",this.nick="",this.role="",this.joinTime="",this.nameCard="",this.muteUntil=0,this.memberCustomField=[],this.isOnline=!1,this.updateMember(e)}updateMember(t){const{core:{utils:{isUndefined:o},common:{deepMerge:r}}}=e;o(t.muteTime)||(this.muteUntil=Math.floor((Date.now()+1e3*t.muteTime)/1e3)),o(t.onlineStatus)||(this.isOnline="Online"===t.onlineStatus);const i=[null,void 0,"",0,NaN];t.memberCustomField&&ce(this.memberCustomField,t.memberCustomField),r(this,t,["memberCustomField","marks","onlineStatus","muteTime"],i)}};function Re(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}function Ue(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userID:r,muteTime:i,role:n,nameCard:s,memberCustomField:u}=e;let a;u&&(a=le(u));return Re("group_open_http_svc.modify_group_member_info",{GroupId:o,Member_Account:r,ShutUpTime:i,Role:n,NameCard:s,AppMemberDefinedData:a},t)}))}var ke=new class{constructor(){this._name="GetGroupMemberList"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}getGroupMemberList(e){return _e(this,void 0,void 0,(function*(){const t="getGroupMemberList",{groupID:o,offset:r=0,count:i=100,role:n="",filter:s=""}=e;console.log(`${this._name}.${t} groupID:${o} offset:${r} count:${i} role:${n} filter:${s}`);const u=de.getLocalGroup(o),a=i>100?100:i,c={groupID:o,offset:r,limit:a,memberRoleFilter:g.includes(n)?[n]:void 0,memberInfoFilter:_};try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,offset:r,limit:i,memberRoleFilter:n,memberInfoFilter:s}=e;return Re("group_open_http_svc.get_group_member_info",{GroupId:o,Offset:r,Limit:i,MemberRoleFilter:n,MemberInfoFilter:s},t)}))}(c,this._core),{MemberList:i,MemberNum:n,Next:s}=e||{};console.log(`${this._name}.${t} ok, totalMemberCount:${n} next:${s}`);const{utils:{isArray:p,isEmpty:l},common:{isCommunity:h}}=this._core;if(u&&(u.memberCount=n),!p(i)||0===i.length)return Ge({memberList:[],offset:0});let m=r+a;h({groupID:o})&&(m=l(s)?0:s),i.length<a&&(m=0);let d=this._convertMemberInfo(i);d=yield this._patchAvatarAndNick(d);const g=this._generateGroupMember(d);return Ge({memberList:g,offset:m})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_convertMemberInfo(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppMemberDefinedData:r,JoinTime:i,Member_Account:n,OnlineStatus:s,Role:u,ShutUpUntil:a}=e[o],c=pe(r);t.push({userID:n,joinTime:i,onlineStatus:s,role:u,muteUntil:a,memberCustomField:c})}return t}_patchAvatarAndNick(e){return _e(this,void 0,void 0,(function*(){var t;const o=e.map((e=>e.userID)),r=yield null===(t=this._core.user.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:o}),i=(null==r?void 0:r.data)||[],n=new Map(i.map((e=>[e.userID,e])));return e.forEach((e=>{if(n.has(e.userID)){const{nick:t="",avatar:o=""}=n.get(e.userID);e.nick=t,e.avatar=o}})),e}))}_generateGroupMember(e){const t=[];for(let o=0,r=e.length;o<r;o++){const r=new Pe(e[o]);t.push(r)}return t}};var qe=new class{constructor(){this._name="GetGroupMemberProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupMemberProfile",context:this})}getGroupMemberProfile(e){return _e(this,void 0,void 0,(function*(){const t="getGroupMemberProfile",{groupID:o,userIDList:r,memberCustomFieldFilter:i}=e,n=de.getLocalGroup(o),{helper:s,utils:{isArray:u}}=this._core;if(n&&ae(n.type))throw new s.ChatError({functionName:t,replacement1:t,code:se});r.length>50&&(console.warn(`${this._name}.${t} userIDList length:${r.length} exceeds limit 50`),r.splice(50));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userIDList:r,memberInfoFilter:i,memberCustomFieldFilter:n}=e;return Re("group_open_http_svc.get_specified_group_member_info",{GroupId:o,Member_List_Account:r,MemberInfoFilter:i,AppDefinedDataFilter_GroupMember:n},t)}))}({groupID:o,userIDList:r,memberCustomFieldFilter:i,memberInfoFilter:[..._]},this._core);console.log(`${this._name}.${t} ok.`);const{MemberList:n}=e||{};if(!u(n)||0===n.length)return Ge({memberList:[]});let s=this._convertMemberInfo(n);s=yield this._getMemberAvatarAndNick(s);const a=this._generateGroupMember(s);return Ge({memberList:a})}catch(e){const o=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_convertMemberInfo(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppMemberDefinedData:r,JoinTime:i,Member_Account:n,OnlineStatus:s,Role:u,ShutUpUntil:a}=e[o],c=pe(r);t.push({userID:n,joinTime:i,onlineStatus:s,role:u,muteUntil:a,memberCustomField:c})}return t}_getMemberAvatarAndNick(e){return _e(this,void 0,void 0,(function*(){var t;const o=e.map((e=>e.userID)),r=yield null===(t=this._core.user.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:o}),i=(null==r?void 0:r.data)||[],n=new Map(i.map((e=>[e.userID,e])));return e.forEach((e=>{if(n.has(e.userID)){const{nick:t="",avatar:o=""}=n.get(e.userID);e.nick=t,e.avatar=o}})),e}))}_generateGroupMember(e){const t=[];for(let o=0,r=e.length;o<r;o++){const r=new Pe(e[o]);t.push(r)}return t}};var Fe=new class{constructor(){this._name="AddGroupMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"addGroupMember",context:this})}addGroupMember(e){return _e(this,void 0,void 0,(function*(){const t="addGroupMember",{groupID:o,userIDList:r}=e,i=de.getLocalGroup(o),{helper:n}=this._core;if(i&&ae(i.type))throw new n.ChatError({functionName:t,code:te});const s=r.map((e=>({Member_Account:e})));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userIDList:r}=e;return Re("group_open_http_svc.add_group_member",{GroupId:o,MemberList:r},t)}))}({groupID:o,userIDList:s},this._core),{MemberList:r=[]}=e||{},{failureUserIDList:n,successUserIDList:u,existedUserIDList:a,overLimitUserIDList:c}=this._handleResult(r);return console.log(`${this._name}.${t} groupID:${o} ok, successUserIDList:${u} failureUserIDList:${n} existedUserIDList:${a} overLimitUserIDList:${c}`),Ge({failureUserIDList:n,successUserIDList:u,existedUserIDList:a,overLimitUserIDList:c,group:i})}catch(e){const o=new n.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_handleResult(e){const t=[],o=[],r=[],i=[];return e.forEach((e=>{const{Result:n,Member_Account:s}=e;n===f?t.push(s):n===G?o.push(s):n===b?r.push(s):n===v&&i.push(s)})),{failureUserIDList:t,successUserIDList:o,existedUserIDList:r,overLimitUserIDList:i}}};var je=new class{constructor(){this._name="DeleteGroupMember"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}deleteGroupMember(e){return _e(this,void 0,void 0,(function*(){const t="deleteGroupMember",{groupID:o,userIDList:r}=e,i=de.getLocalGroup(o),{helper:n,utils:{isUndefined:s}}=this._core;if(s(i))throw new n.ChatError({functionName:t,code:Q});r.length>20&&(console.warn(`${this._name}.${t} userIDList length:${r.length} exceeds limit 20`),r.splice(20));try{return yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userIDList:r,reason:i}=e;return Re("group_open_http_svc.delete_group_member",{GroupId:o,MemberToDel_Account:r,Reason:i},t)}))}({groupID:o,userIDList:r},this._core),console.log(`${this._name}.${t} ok, groupID:${o} userIDList length:${r.length}`),Ge({group:i,userIDList:r})}catch(e){const o=new n.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var xe=new class{constructor(){this._name="SetGroupMemberMuteTime"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberMuteTime",context:this})}setGroupMemberMuteTime(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberMuteTime",{helper:o}=this._core;this._preCheckSettingMuteParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,muteTime:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} muteTime:${i}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,muteTime:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingMuteParams(e){const{userID:t}=e,{store:o,helper:r}=this._core;if(t===o.get("login").userId)throw new r.ChatError({functionName:"setGroupMemberMuteTime",code:ne})}};var Ke=new class{constructor(){this._name="SetGroupMemberRole"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberRole",context:this})}setGroupMemberRole(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberRole",{helper:o}=this._core;this._preCheckSettingRoleParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,role:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} role:${i}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,role:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingRoleParams(e){var t;const{groupID:o,userID:r,role:i}=e,{store:n,helper:s,OuterConstant:u,common:{isCommunity:a}}=this._core,c=de.getLocalGroup(o);if((null===(t=null==c?void 0:c.selfInfo)||void 0===t?void 0:t.role)!==u.GRP_MBR_ROLE_OWNER)throw new s.ChatError({functionName:"setGroupMemberRole",code:oe});if(r===n.get("login").userId)throw new s.ChatError({functionName:"setGroupMemberRole",code:ie});const p=[...g];if(a({groupID:o})&&p.push(u.GRP_MBR_ROLE_CUSTOM),!p.includes(i))throw new s.ChatError({functionName:"setGroupMemberRole",code:re})}};var Ve=new class{constructor(){this._name="SetGroupMemberNameCard"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberNameCard",context:this})}setGroupMemberNameCard(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberNameCard",{helper:o}=this._core;this._preCheckSettingNameCardParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,nameCard:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} nameCard:${i}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,nameCard:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingNameCardParams(e){const{groupID:t}=e,{helper:o}=this._core,r=de.getLocalGroup(t);if(ae(null==r?void 0:r.type))throw new o.ChatError({functionName:"setGroupMemberNameCard",code:se})}};var Je=new class{constructor(){this._name="SetGroupMemberCustomField"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberCustomField",context:this})}setGroupMemberCustomField(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberCustomField",{helper:o}=this._core;this._preCheckSettingCustomFiledParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,memberCustomField:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} memberCustomField:${JSON.stringify(i)}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,memberCustomField:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingCustomFiledParams(e){const{groupID:t}=e,{helper:o}=this._core,r=de.getLocalGroup(t);if(ae(null==r?void 0:r.type))throw new o.ChatError({functionName:"setGroupMemberCustomField",code:se})}};var Be=new class{init(e,t){console.log("GroupMember.init"),ke.init(e,t),qe.init(e),Fe.init(e),je.init(e,t),xe.init(e),Ke.init(e),Ve.init(e),Je.init(e)}getGroupMemberList(e){return ke.getGroupMemberList(e)}deleteGroupMember(e){return je.deleteGroupMember(e)}};var He=new class{init(e){this._core=e}};function Ye(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}var We=new class{constructor(){this._name="InitGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"initGroupAttributes",context:this})}initGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="initGroupAttributes",{groupID:o,groupAttributes:r}=e,{serverMainSequence:i,avChatRoomKey:n}=Ie.getGroupAttributesCache(o),s=Ie.convertKeyValueMapToList(r);try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,groupAttributeList:i,avChatRoomKey:n}=e;return Ye("group_open_http_svc.set_group_attr",{GroupId:o,AttrMainSeq:r,GroupAttr:i,BytesKey:n,AttrControl:["RaceConflict"]},t)}))}({groupID:o,avChatRoomKey:n,groupAttributeList:s,mainSequence:i},this._core),{AttrMainSeq:u,GroupAttr:a}=e||{};console.log(`${this._name}.${t} ok. groupID:${o} serverMainSequence:${u}`);const c=a.map((e=>{const{Key:t,seq:o}=e;return{key:t,value:r[t],sequence:o}}));return Ie.saveGroupAttributesCacheValuesCopy(o),Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:u,groupAttributeList:c,operation:I}),Ie.emitGroupAttributesUpdated(o),Ge({groupAttributes:r})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var Qe=new class{constructor(){this._name="SetGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupAttributes",context:this})}setGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="setGroupAttributes",{groupID:o,groupAttributes:r}=e,{serverMainSequence:i,avChatRoomKey:n,values:s}=Ie.getGroupAttributesCache(o),u=Ie.convertKeyValueMapToList(r).map((e=>{var t;const{key:o,value:r}=e;return{key:o,value:r,seq:(null===(t=s.get(e.key))||void 0===t?void 0:t.sequence)||0}}));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,groupAttributeList:i,avChatRoomKey:n}=e;return Ye("group_open_http_svc.modify_group_attr",{GroupId:o,AttrMainSeq:r,GroupAttr:i,BytesKey:n,AttrControl:["RaceConflict"]},t)}))}({groupID:o,avChatRoomKey:n,groupAttributeList:u,mainSequence:i},this._core),{AttrMainSeq:s,GroupAttr:a}=e||{};console.log(`${this._name}.${t} ok. groupID:${o} serverMainSequence:${s}`);const c=a.map((e=>{const{Key:t,seq:o}=e;return{key:t,value:r[t],sequence:o}}));return Ie.saveGroupAttributesCacheValuesCopy(o),Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:s,groupAttributeList:c,operation:y}),Ie.emitGroupAttributesUpdated(o),Ge({groupAttributes:r})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var ze=new class{constructor(){this._name="DeleteGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteGroupAttributes",context:this})}deleteGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="deleteGroupAttributes",{groupID:o,keyList:r=[]}=e;try{let e;e=0===r.length?yield this._clearGroupAttributes(o):yield this._deleteGroupAttributes(o,r);const{resultList:i,serverMainSequence:n,operation:s,groupAttributeList:u}=e||{};return console.log(`${this._name}.${t} ok. groupID:${o} operation: ${s}`),Ie.saveGroupAttributesCacheValuesCopy(o),Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:n,groupAttributeList:u,operation:s}),Ie.emitGroupAttributesUpdated(o),Ge({keyList:i})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_deleteGroupAttributes(e,t){return _e(this,void 0,void 0,(function*(){const{serverMainSequence:o,avChatRoomKey:r,values:i}=Ie.getGroupAttributesCache(e),n=[],s=[];t.forEach((e=>{if(i.has(e)){const{sequence:t=0}=i.get(e)||{};s.push({key:e,seq:t}),n.push(e)}}));const u=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,groupAttributeList:i,avChatRoomKey:n}=e;return Ye("group_open_http_svc.delete_group_attr",{GroupId:o,AttrMainSeq:r,GroupAttr:i,BytesKey:n,AttrControl:["RaceConflict"]},t)}))}({groupID:e,avChatRoomKey:r,groupAttributeList:s,mainSequence:o},this._core),{AttrMainSeq:a}=u||{};return{resultList:n,serverMainSequence:a,groupAttributeList:s,operation:M}}))}_clearGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const{serverMainSequence:t,avChatRoomKey:o,values:r}=Ie.getGroupAttributesCache(e),i=[...r.keys()],n=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,avChatRoomKey:i}=e;return Ye("group_open_http_svc.clear_group_attr",{GroupId:o,AttrMainSeq:r,BytesKey:i,AttrControl:["RaceConflict"]},t)}))}({groupID:e,avChatRoomKey:o,mainSequence:t},this._core),{AttrMainSeq:s}=n||{};return{resultList:i,serverMainSequence:s,operation:C}}))}};var Xe=new class{constructor(){this._name="GetGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupAttributes",context:this})}getGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="getGroupAttributes",{groupID:o}=e,{avChatRoomKey:r,lastUpdateTime:i,localMainSequence:n,serverMainSequence:s}=Ie.getGroupAttributesCache(o);if(Date.now()-i>=3e4||n<s)try{yield this.getGroupAttributesFromServer({groupID:o,avChatRoomKey:r});const i=Ie.getGroupAttributesCacheValues(e);return console.log(`${this._name}.${t} from server. groupID:${o}`),Ge({groupAttributes:i})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}const u=Ie.getGroupAttributesCacheValues(e);return console.log(`${this._name}.${t} from cache. groupID:${o}`),Ge({groupAttributes:u})}))}getGroupAttributesFromServer(e){return _e(this,void 0,void 0,(function*(){const{utils:{isUndefined:t}}=this._core,{groupID:o,avChatRoomKey:r}=e,i=t(r)?L:D,n=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,groupType:r,avChatRoomKey:i}=e;return Ye("group_open_attr_http_svc.get_group_attr",{GroupId:o,GroupType:r,Key:i},t)}))}({groupID:o,avChatRoomKey:r,groupType:i},this._core),{AttrMainSeq:s,GroupAttrAry:u}=n||{};if(console.log(`${this._name}._getGroupAttributesFromServer ok. groupID:${o} serverMainSequence:${s}`),!t(s)){const e=u.map((e=>{const{key:t,value:o,seq:r}=e;return{key:t,value:o,sequence:r}}));Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:s,groupAttributeList:e,operation:A})}}))}};var Ze=new class{init(e){console.log("GroupAttribute.init"),We.init(e),Qe.init(e),ze.init(e),Xe.init(e),Ie.init(e)}isGroupAttributesUpdated(e){return Ie.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){const{to:t,elements:{newGroupProfile:o}}=e,{groupAttributeOption:r}=o,{serverMainSequence:i,withChangedAttributeInfo:n}=r,{localMainSequence:s}=Ie.getGroupAttributesCache(t),u=i-s;if(console.log(`GroupAttribute.handleGroupAttributesUpdated groupID:${t} withChangedAttributeInfo:${n} diffSequence:${u}`),0!==u)if(Ie.saveGroupAttributesCacheValuesCopy(t),1!==n||1!==u){if(Ie.hasGroupAttributesCache(t)){const{avChatRoomKey:e}=Ie.getGroupAttributesCache(t);Xe.getGroupAttributesFromServer({groupID:t,avChatRoomKey:e}).then((()=>{Ie.emitGroupAttributesUpdated(t)})).catch((()=>{}))}}else Ie.handleGroupAttributesUpdated({groupID:t,groupAttributeOption:r})}};function et(e,t="tips"){const{ClientSeq:o,From_Account:r,MsgClientTime:i,MsgPriority:n,MsgRandom:s,MsgSeq:u,MsgTimeStamp:a,TinyId:c,ToGroupId:p,GroupInfo:l,MsgBody:h}=e,m=function(e){const{GroupCode:t,GroupId:o,GroupName:r,GroupType:i,MsgFrom_AccountExtraInfo:n,From_Account:s,To_Account:u}=e;return{groupCode:t,groupID:o,groupName:r,type:i,messageFromAccountExtraInformation:n,from:s,to:u}}(l);return{clientSequence:o,from:r,clientTime:i,priority:n,random:s,sequence:u,time:a,tinyID:c,to:p,groupProfile:m,elements:"tips"===t?tt(h):function(e){const t={};return Object.keys(e).forEach((o=>{switch(o){case"MsgKey":t.messageKey=e[o];break;case"Operator_Account":t.operatorID=e[o];break;case"ReportType":t.operationType=e[o];break;case"Authentication":t.authentication=e[o];break;case"MsgFlag":t.messageRemindType=e[o];break;case"UserDefinedField":t.userDefinedField=e[o];break;case"RemarkInfo":t.remarkInfo=e[o];break;case"BanDuration":t.duration=e[o]}})),t}(h)}}function tt(e){const t={};return Object.keys(e).forEach((o=>{switch(o){case"MemberNum":t.memberCount=e[o];break;case"OpType":t.operationType=e[o];break;case"Operator_Account":t.operatorID=e[o];break;case"List_Account":t.userIDList=e[o];break;case"MsgMemberExtraInfo":t.memberInfoList=e[o].map((e=>ot(e)));break;case"MsgOperatorMemberExtraInfo":t.operatorInfo=ot(e[o]);break;case"MsgGroupNewInfo":t.newGroupProfile=function(e){const t={};return Object.keys(e).forEach((o=>{switch(o){case"GroupIntroduction":t.introduction=e[o];break;case"GroupName":t.groupName=e[o];break;case"GroupFaceUrl":t.avatar=e[o];break;case"GroupNotification":t.notification=e[o];break;case"ApplyJoinOption":t.joinOption=e[o];break;case"InviteJoinOption":t.inviteOption=e[o];break;case"ShutupAll":t.muteAllMembers=e[o];break;case"Owner_Account":t.ownerID=e[o];break;case"GroupAttrOption":t.groupAttributeOption=function(e){const{BytesChangedKeys:t,GroupAttrSeq:o,OpType:r,PushChangedAttrValFlag:i,GroupAttrInfo:n}=e,s=n.map((e=>{const{Key:t,Val:o,SubKeySeq:r}=e;return{key:t,value:o,sequence:r}}));return{changedKeyList:t,groupAttributeList:s,serverMainSequence:o,operation:r,withChangedAttributeInfo:i}}(e[o])}})),t}(e[o]);break;case"MsgMemberInfo":t.msgMemberInfo=e[o].map((e=>function(e){const{ShutupTime:t,User_Account:o}=e;return{muteTime:t,userID:o}}(e)));break;case"OnlineMemberInfo":t.onlineMemberInfo=function(e){const{ExpireTime:t,OnlineMemberNum:o}=e;return{expireTime:t,onlineMemberNum:o}}(e[o])}})),t}function ot(e){const{ImageUrl:t,NickName:o,Role:r,UserId:i}=e;return{avatar:t,nick:o,role:r,userID:i}}class rt{constructor(t){this.type=e.core.OuterConstant.MSG_GRP_TIP,this.content={},this._initContent(t)}static parseServerPushElement(e){const t=tt(e);return new rt(t)}_initContent(e){Object.keys(e).forEach((t=>{switch(t){case"groupProfile":this._initGroupProfile(e[t]);break;case"operatorInfo":this._initOperatorInfo(e[t]);break;case"memberInfoList":case"msgMemberInfo":this._updateMemberList(e[t]);break;case"newGroupProfile":this._initNewGroupProfile(e[t]);break;case"memberExtraInfo":case"remarkInfo":case"onlineMemberInfo":break;default:this.content[t]=e[t]}})),this.content.userIDList||(this.content.userIDList=[this.content.operatorID])}_initGroupProfile(e){this.content.groupProfile={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];k[r]&&(this.content.groupProfile[r]=e[r])}}_initOperatorInfo(e){this.content.operatorInfo={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];this.content.operatorInfo[r]=e[r]}}_updateMemberList(e){this.content.memberList?this.content.memberList.forEach((t=>{e.forEach((e=>{t.userID===e.userID&&Object.assign(t,e)}))})):this.content.memberList=e}_initNewGroupProfile(e){this.content.newGroupProfile={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];"muteAllMembers"!==r?this.content.newGroupProfile[r]=e[r]:this.content.newGroupProfile.muteAllMembers=1===e.muteAllMembers}}}var it=new class{constructor(){this._name="GroupTipsNotification"}init(e){this._core=e;const{message:{messageFactory:t},OuterConstant:o}=e;null==t||t.registerElementClass(o.MSG_GRP_TIP,rt)}onNewGroupTips(e){console.log(`${this._name}.onNewGroupTips options:${JSON.stringify(e)}`);const{messageList:t}=this._handleGroupTips(e),{notificationCenter:o,OuterEvent:r}=this._core;t.length>0&&(o.emitOuterEvent(r.MESSAGE_RECEIVED,{name:r.MESSAGE_RECEIVED,data:t}),this._handleGroupTipMessage(t))}_handleGroupTips(e){const{Event:t,GroupTips:o}=e,r=new Map,i=[],n=[];for(let e=0,i=o.length;e<i;e++){const i=et(o[e],"tips");if(t===O&&Ze.isGroupAttributesUpdated(i)){Ze.handleGroupAttributesUpdated(i);continue}const{groupProfile:{groupID:s}}=i;if(!de.hasLocalGroup(s))continue;const u=this._assembleMessage(i);if(t===O&&(u._onlineOnlyFlag=!0,n.push(u)),t===S){if(!this._core.message.messageDataHandler.storeConversationMessage(u))continue;n.push(u)}this._handleConversationOptions(r,u)}return i.push(...r.values()),{conversationUpdateFieldList:i,messageList:n}}_assembleMessage(e){const{OuterConstant:t,message:{messageFactory:o}}=this._core;e.flow="in",e.conversationType=t.CONV_GROUP;const r=o.createMessage(e);this._patchNickAndAvatar(e.elements,r);const i=new rt(Object.assign(Object.assign({},e.elements),{groupProfile:Object.assign({},e.groupProfile)}));return r.setElement(i),r.isSystemMessage=!1,r}_patchNickAndAvatar(e,t){const{utils:{isEmpty:o}}=this._core,{operationType:r,memberInfoList:i,operatorInfo:n}=e;let s={};if(o(i)?o(n)||(s=n):r!==w&&r!==$&&r!==N&&r!==E||(s=Object.assign({},i[0])),!o(s)){const{nick:e="",avatar:o=""}=s;t.nick=e,t.avatar=o}}_handleConversationOptions(e,t){const{conversationID:o,conversationType:r}=t;let i;if(e.has(o))i=e.get(o),"in"===t.flow&&(t._isExcludedFromUnreadCount||t._onlineOnlyFlag||i.unreadCount++),i.type=r,i.lastMessage=t._isExcludedFromLastMessage?"":t;else{let e=0;"in"===t.flow&&(t._isExcludedFromUnreadCount||t._onlineOnlyFlag||(e=1)),i={conversationID:o,unreadCount:e,type:r,lastMessage:t._isExcludedFromLastMessage?"":t}}e.set(o,i)}_handleGroupTipMessage(e){e.forEach((e=>{const{operationType:t}=e.payload;switch(t){case w:this._handleNewMemberJoined(e);break;case T:this._handleMemberQuitted(e);break;case $:this._handleMemberKicked(e);break;case P:this._handleGroupProfileUpdated(e)}}))}_handleNewMemberJoined(e){this._handleGroupMemberCountUpdated(e)}_handleMemberQuitted(e){this._handleGroupMemberCountUpdated(e)}_handleMemberKicked(e){this._handleGroupMemberCountUpdated(e)}_handleGroupProfileUpdated(e){var t;const{newGroupProfile:o,groupProfile:r,operatorInfo:i}=e.payload,{groupID:n}=r,s=de.getLocalGroup(n);Object.keys(o).forEach((e=>{switch(e){case"ownerID":this._handleGroupOwnerChanged(n,o);break;case"groupName":s.name=o[e];break;default:s[e]=o[e]}}));const{utils:{isUndefined:u}}=this._core;u(i)||(null===(t=null==s?void 0:s.selfInfo)||void 0===t?void 0:t.userID)!==i.userID||Object.keys(i).forEach((e=>{"nameCard"===e&&s.updateSelfInfo({nameCard:i[e]}),"role"===e&&this._updateSelfRole(s,i[e])})),de.emitGroupListUpdate(),de.updateConversationGroupProfile(n)}_handleGroupOwnerChanged(e,t){const{common:o,OuterConstant:r}=this._core,i=de.getLocalGroup(e),n=o.getCurrentUserID(),{ownerID:s}=t;n===s&&i.updateGroup({ownerID:s,selfInfo:{role:r.GRP_MBR_ROLE_OWNER}})}_updateSelfRole(e,t){const{OuterConstant:o}=this._core;let r=o.GRP_MBR_ROLE_MEMBER;t===R?r=o.GRP_MBR_ROLE_OWNER:t===U&&(r=o.GRP_MBR_ROLE_ADMIN),e.updateSelfInfo({role:r})}_handleGroupMemberCountUpdated(e){const{memberCount:t,groupProfile:{groupID:o}}=e.payload,r=de.getLocalGroup(o),{utils:{isNumber:i}}=this._core;r&&i(t)&&r.memberCount!==t&&(r.memberCount=t,de.emitGroupListUpdate(),de.updateConversationGroupProfile(o))}};class nt{constructor(t){this.type=e.core.OuterConstant.MSG_GRP_SYS_NOTICE,this.content={},this._initContent(t)}_initContent(e){Object.keys(e).forEach((t=>{switch(t){case"remarkInfo":this.content.handleMessage=e[t];break;case"groupProfile":this._initGroupProfile(e[t]);break;case"memberInfoList":break;default:this.content[t]=e[t]}}))}_initGroupProfile(e){this.content.groupProfile={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];q[r]&&(this.content.groupProfile[r]=e[r])}}}var st=new class{constructor(){this._name="GroupSystemNotification"}init(e){this._core=e;const{message:{messageFactory:t},OuterConstant:{MSG_GRP_SYS_NOTICE:o}}=e;null==t||t.registerElementClass(o,nt)}onNewGroupSystemNotification(e){const{GroupTips:t=[],isInstantMessage:o=!0}=e;console.log(`${this._name}.onNewGroupSystemNotification count:${t.length} isInstantMessage:${o}`);const{conversationUpdateFieldList:r,messageList:i}=this._handleGroupSystemNotification(t,o),{notificationCenter:n,OuterEvent:s}=this._core;r.length>0&&this._handleGroupSysTemMessage(o,i),!0===o&&i.length>0&&n.emitOuterEvent(s.MESSAGE_RECEIVED,{name:s.MESSAGE_RECEIVED,data:i})}_handleGroupSystemNotification(e,t){const o=[];let r={};for(let i=0;i<e.length;i++){const n=et(e[i],"system"),{elements:{operationType:s}}=n;if(s===J)continue;const u=this._assembleMessage(n);this._core.message.messageDataHandler.storeConversationMessage(u)&&(o.push(u),r=this._handleConversationOptions(u,t))}return r.lastMessage=o[o.length-1],{conversationUpdateFieldList:o.length>0?[r]:[],messageList:o}}_assembleMessage(e){const{message:{messageFactory:t},OuterConstant:o,utils:{randomInt:r}}=this._core;e.flow="in",e.conversationType=o.CONV_SYSTEM,e.conversationSubType=e.groupProfile.type,e.conversationID=o.CONV_SYSTEM;const i=t.createMessage(e),n=new nt(Object.assign(Object.assign({},e.elements),{groupProfile:Object.assign({},e.groupProfile)}));i.setElement(n),i.isSystemMessage=!0;const s=1===i.sequence&&1===i.random,u=2===i.sequence&&2===i.random;return(s||u)&&(i.sequence=r(),i.random=r(),i.generateMessageID()),i}_handleConversationOptions(e,t){const{OuterConstant:o}=this._core,r={conversationID:o.CONV_SYSTEM,unreadCount:0,type:o.CONV_SYSTEM,subType:e.conversationSubType,lastMessage:null};return t&&r.unreadCount++,r}_handleGroupSysTemMessage(e,t){e&&t.forEach((e=>{const{operationType:t}=e.payload;switch(t){case F:this._handleGroupJoinResult(e);break;case j:this._handleMemberKicked(e);break;case x:this._handleGroupDismissed(e);break;case K:this._handleGroupInvitedResult(e);break;case V:this._handleGroupQuitResult(e);break;case B:this._handleMessageRemindTypeSynced(e);break;case H:this._handleAVChatRoomMemberBanned(e)}}))}_handleGroupJoinResult(e){const{groupProfile:t}=e.payload,{groupID:o,type:r}=t,i=de.hasLocalGroup(o);console.log(`${this._name}._handleGroupJoinResult groupID:${o} type:${r} hasLocalGroup:${i}`),i||ae(r)||(de.updateLocalGroup([Object.assign({},t)]),de.emitGroupListUpdate())}_handleMemberKicked(e){const{groupProfile:{groupID:t,type:o}}=e.payload;de.hasLocalGroup(t)&&this._deleteLocalGroup(t,o),this._updateConversationProfile(t,{unreadCount:0})}_handleGroupDismissed(e){const{groupProfile:{groupID:t,type:o}}=e.payload;de.hasLocalGroup(t)&&this._deleteLocalGroup(t,o),this._updateConversationProfile(t,{unreadCount:0})}_handleGroupInvitedResult(e){const{groupProfile:t}=e.payload,{groupID:o}=t,r=de.hasLocalGroup(o);console.log(`${this._name}._handleGroupInvitedResult groupID:${o} hasLocalGroup:${r}`),r||(de.updateLocalGroup([Object.assign({},t)]),de.emitGroupListUpdate())}_handleGroupQuitResult(e){const{groupProfile:{groupID:t,type:o}}=e.payload,r=de.hasLocalGroup(t);console.log(`${this._name}._handleGroupQuitResult groupID:${t} type:${o} hasLocalGroup:${r}`),r&&this._deleteLocalGroup(t,o),this._updateConversationProfile(t,{unreadCount:0})}_handleMessageRemindTypeSynced(e){const{groupProfile:{groupID:t},messageRemindType:o}=e.payload;this._updateConversationProfile(t,{messageRemindType:o})}_handleAVChatRoomMemberBanned(e){const{groupProfile:{groupID:t,type:o}}=e.payload;this._deleteLocalGroup(t,o)}_deleteLocalGroup(e,t){if(ae(t)){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:o}}=this._core;t.deleteConversation(`${o}${e}`)}de.deleteLocalGroup(e),de.emitGroupListUpdate()}_updateConversationProfile(e,t){const{appStore:{conversationStore:o},OuterConstant:{CONV_GROUP:r}}=this._core,i=`${r}${e}`;o.getConversation(i)&&o.updateConversation(i,t)}};var ut=new class{init(e){this._core=e,console.log("GroupNotificationHandler.init"),it.init(e),st.init(e);const{notificationCenter:t,InnerEvent:o}=e,{InnerEventSubType:r}=t;t.subscribeInnerEvent(o.MESSAGE_PUSH,r.GROUP_TIPS_NOTIFICATION,this._onNewGroupTipsNotification,this),t.subscribeInnerEvent(o.MESSAGE_PUSH,r.GROUP_SYSTEM_NOTIFICATION,this._onNewGroupSystemNotification,this),t.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onNewGroupTipsNotification(e){it.onNewGroupTips(e)}_onNewGroupSystemNotification(e){st.onNewGroupSystemNotification(e)}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:o}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,o.GROUP_TIPS_NOTIFICATION,this._onNewGroupTipsNotification,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,o.GROUP_SYSTEM_NOTIFICATION,this._onNewGroupSystemNotification,this)}};const at={required:!0,rules:["string"],allowEmpty:!1},ct={required:!0,rules:["number"],allowEmpty:!1},pt={required:!0,rules:["array"],allowEmpty:!1},lt={required:!0,rules:["object"],allowEmpty:!1},ht={createGroup:{name:at,type:at},dismissGroup:[Object.assign({key:"groupID"},at)],joinGroup:{groupID:at,applyMessage:{required:!1,rules:["string"],allowEmpty:!0}},quitGroup:[Object.assign({key:"groupID"},at)],searchGroupByID:[Object.assign({key:"groupID"},at)],getGroupProfile:{groupID:at,groupCustomFieldFilter:{required:!1,rules:["array"],allowEmpty:!0}},updateGroupProfile:{groupID:at,muteAllMembers:{required:!1,rules:["boolean"],allowEmpty:!1}},changeGroupOwner:{groupID:at,newOwnerID:at},getGroupOnlineMemberCount:[Object.assign({key:"groupID"},at)],handleGroupApplication:{handleAction:at},getGroupMemberList:{groupID:at},getGroupMemberProfile:{groupID:at,userIDList:pt,memberCustomFieldFilter:{required:!1,rules:["array"],allowEmpty:!0}},addGroupMember:{groupID:at,userIDList:pt},deleteGroupMember:{groupID:at,userIDList:pt},setGroupMemberMuteTime:{groupID:at,userID:at,muteTime:Object.assign(Object.assign({},ct),{customValidator:e=>!(e<0)||"muteTime must be a non-negative number."})},setGroupMemberRole:{groupID:at,userID:at,role:at},setGroupMemberNameCard:{groupID:at,userID:{required:!1,rules:["string"],allowEmpty:!1},nameCard:at},setGroupMemberCustomField:{groupID:at,userID:{required:!1,rules:["string"],allowEmpty:!1},memberCustomField:pt},markGroupMemberList:{groupID:at,markType:Object.assign(Object.assign({},ct),{customValidator:e=>!(e<1e3)||"markType must be greater than or equal to 1000."}),enableMark:{required:!0,rules:["boolean"],allowEmpty:!1},userIDList:pt},initGroupAttributes:{groupID:at,groupAttributes:lt},setGroupAttributes:{groupID:at,groupAttributes:lt},deleteGroupAttributes:{groupID:at,keyList:Object.assign(Object.assign({},pt),{allowEmpty:!0})},getGroupAttributes:{groupID:at,keyList:Object.assign(Object.assign({},pt),{allowEmpty:!0})}},mt={getGroupList:!0,createGroup:!0,dismissGroup:!0,joinGroup:!0,quitGroup:!0,searchGroupByID:!0,getGroupProfile:!0,updateGroupProfile:!0,changeGroupOwner:!0,getGroupOnlineMemberCount:!0,getGroupApplicationList:!0,handleGroupApplication:!0,getGroupMemberList:!0,getGroupMemberProfile:!0,addGroupMember:!0,deleteGroupMember:!0,setGroupMemberMuteTime:!0,setGroupMemberRole:!0,setGroupMemberNameCard:!0,setGroupMemberCustomField:!0,markGroupMemberList:!0,initGroupAttributes:!0,setGroupAttributes:!0,getGroupAttributes:!0,deleteGroupAttributes:!0};var dt=new class{constructor(){this._installedSubPlugins=[],this.groupDataHandler=de,this.groupAction=we,this.groupAttribute=Ze,this.groupMember=Be}install(t,o=[]){this._core=t,e.init(t),de.init(t),we.init(t,this),Be.init(t,this),Ee.init(t),He.init(t),Ze.init(t),ut.init(t),t.helper.registerValidateConfig({auth:mt,params:ht}),this._installSubPlugins(o);const{notificationCenter:r,InnerEvent:i}=t;r.subscribeInnerEvent(i.LOGOUT,this._reset,this),r.subscribeInnerEvent(i.DESTROY,this._dispose,this)}getInstalledSubPlugins(){return this._installedSubPlugins}_installSubPlugins(e){const{utils:{isArray:t}}=this._core;e&&t(e)&&e.forEach((e=>{var t;null===(t=e.install)||void 0===t||t.call(e,this._core,this),this._installedSubPlugins.push(e.name)}))}_reset(){de.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{dt as default};
package/plugins/group.js CHANGED
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatGroup=r()}(this,(function(){"use strict";function e(e,r,o,t){return new(o||(o=Promise))((function(i,n){function s(e){try{u(t.next(e))}catch(e){n(e)}}function c(e){try{u(t.throw(e))}catch(e){n(e)}}function u(e){var r;e.done?i(e.value):(r=e.value,r instanceof o?r:new o((function(e){e(r)}))).then(s,c)}u((t=t.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const r="group";var o=new class{init(e){this._core=e;const{helper:r}=e;r.registerApi("searchGroupByID",this),r.registerApi("getGroupList",this),r.registerApi("getGroupApplicationList",this)}searchGroupByID(o){return e(this,void 0,void 0,(function*(){try{console.log(`${r} searchGroupByID: groupID: ${o}`);const t=yield function(r,o){return e(this,void 0,void 0,(function*(){try{const{helper:e,channel:t}=o,i="group_open_http_svc.get_group_public_info",n={GroupIdList:[r]},s=e.generateProtocolData({servcmd:i,data:n}),c=`${s.head.seq}${i}`;return yield t.sendPacket(s,{requestId:c})}catch(e){throw console.warn("searchGroupByID error:",e),e}}))}(o,this._core);return this._parseSearchGroupByIDResponse(t),{code:0,data:{group:{groupID:o}}}}catch(e){throw console.warn(`${r} searchGroupByID error:`,e),e}}))}getGroupList(){return e(this,void 0,void 0,(function*(){return console.log(`${r} getGroupList`),{code:0,data:{groupList:[]}}}))}getGroupApplicationList(){return e(this,void 0,void 0,(function*(){return console.log(`${r} getGroupApplicationList`),{code:0,data:{applicationList:[]}}}))}_parseSearchGroupByIDResponse(e){var r;const o=null===(r=e.GroupInfo)||void 0===r?void 0:r[0];if(0!==(null==o?void 0:o.ErrorCode))throw new this._core.helper.ChatError({functionName:"searchGroupByID",code:null==o?void 0:o.ErrorCode,message:null==o?void 0:o.ErrorCode});return e}};var t=new class{init(e){this._core=e}};var i=new class{init(e){this._core=e}};var n=new class{init(e){this._core=e}};var s=new class{init(e){this._core=e}};const c={searchGroupByID:[{key:"groupID",required:!0,rules:["string"],allowEmpty:!1}]},u={getGroupList:!0,searchGroupByID:!0,getGroupApplicationList:!0};return new class{install(e){o.init(e),t.init(e),i.init(e),n.init(e),s.init(e),e.helper.registerValidateConfig({auth:u,params:c})}}}));
1
+ !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).TencentCloudChatGroup=t()}(this,(function(){"use strict";const e=new class{init(e){this.core=e}},t="AVChatRoom",o="AV_HISTORY_MSG",r=["Type","Name","Introduction","Notification","FaceUrl","Owner_Account","CreateTime","InfoSeq","LastInfoTime","LastMsgTime","MemberNum","MaxMemberNum","ApplyJoinOption","NextMsgSeq","ShutUpAllMember","InviteJoinOption","LastRecallTime"],i=["Type","Name","Introduction","Notification","FaceUrl","CreateTime","Owner_Account","LastInfoTime","LastMsgTime","NextMsgSeq","MemberNum","MaxMemberNum","ApplyJoinOption","InviteJoinOption"],n=["Role","JoinTime","MsgFlag","MsgSeq"],s=["Role","JoinTime","MsgSeq","MsgFlag","NameCard"],u=0,a=1,c="notStart",p="resolved",l="rejected",h=10018,m=11e3,d=2,g=["Owner","Admin","Member"],_=["Role","JoinTime","NameCard","ShutUpUntil","OnlineStatus"],f=0,G=1,b=2,v=4,I=1,y=2,C=3,M=4,A=5,D=1,L=0,S=4,O=6,w=1,T=2,$=3,N=4,E=5,P=6,R=400,U=300,k={from:!0,groupID:!0,groupName:!0,to:!0},q={from:!0,groupID:!0,groupName:!0,to:!0,type:!0},F=2,j=4,x=5,K=7,V=8,J=15,B=20,H=21,Y=2600,W=2602,Q=2603,z=2620,X=2621,Z=2623,ee=2660,te=2661,oe=2681,re=2683,ie=2684,ne=2685,se=2687,ue=t=>t===e.core.OuterConstant.GRP_PUBLIC,ae=t=>t===e.core.OuterConstant.GRP_AVCHATROOM,ce=(t,o)=>{const{isArray:r}=e.core.utils;if(!r(t)||!r(o))return!1;let i=!1;return o.forEach((({key:e,value:o})=>{const r=t.find((t=>t.key===e));r?r.value!==o&&(r.value=o,i=!0):(t.push({key:e,value:o}),i=!0)})),i},pe=e=>{const t=[];if(!e)return t;for(let o=0,r=e.length;o<r;o++){const{Key:r,Value:i}=e[o];t.push({key:r,value:i})}return t},le=e=>{const t=[];for(let o=0,r=e.length;o<r;o++){const{key:r,value:i}=e[o];t.push({Key:r,Value:i})}return t},he=["groupID","name","avatar","type","introduction","notification","ownerID","selfInfo","createTime","infoSequence","lastInfoTime","lastMessage","nextMessageSeq","memberCount","maxMemberCount","memberList","joinOption","groupCustomField","muteAllMembers","isSupportTopic","inviteOption","_lastRevokedTime"];class me{constructor(e){this.groupID="",this.name="",this.avatar="",this.type="",this.introduction="",this.notification="",this.ownerID="",this.createTime=0,this.selfInfo={messageRemindType:"",joinTime:"",nameCard:"",role:"",userID:"",memberCustomField:void 0,readedSequence:0,excludedUnreadSequenceList:void 0},this.lastMessage={lastTime:0,lastSequence:0,fromAccount:"",messageForShow:""},this.nextMessageSeq=0,this.memberCount=0,this.maxMemberCount=0,this.joinOption="",this.inviteOption="",this.groupCustomField=[],this.muteAllMembers=!1,this.isSupportTopic=!1,this._lastRevokedTime=0,this._initGroup(e)}_initGroup(t){const{utils:{isString:o}}=e.core;for(const e in t)he.indexOf(e)<0||("selfInfo"!==e?"isSupportTopic"!==e?"muteAllMembers"===e&&o(t[e])?this.muteAllMembers="On"===t[e]:this[e]=t[e]:this.isSupportTopic=1===t[e]:this.updateSelfInfo(t[e]))}updateGroup(t){const{utils:{isArray:o,isUndefined:r,isNumber:i,isString:n},common:{deepMerge:s}}=e.core;t.appid=void 0,t.grossTopicNextMsgSeq=void 0,t.selfInfo&&(t.selfInfo.grossTopicReadSeq=void 0);const u=JSON.parse(JSON.stringify(t));u.lastMsgTime&&(this.lastMessage.lastTime=u.lastMsgTime),n(u.muteAllMembers)&&(u.muteAllMembers="On"===u.muteAllMembers),u.groupCustomField&&ce(this.groupCustomField,u.groupCustomField),r(u.isSupportTopic)||(this.isSupportTopic=i(u.isSupportTopic)?1===u.isSupportTopic:u.isSupportTopic),s(this,u,["members","errorCode","lastMsgTime","groupCustomField","isSupportTopic"]),o(u.members)&&u.members.length>0&&u.members.forEach((e=>{e.userID===this.selfInfo.userID&&s(this.selfInfo,e,["sequence"])}))}updateSelfInfo(t){const{nameCard:o,joinTime:r,role:i,messageRemindType:n,readedSequence:s,excludedUnreadSequenceList:u}=t,{common:{deepMerge:a}}=e.core;a(this.selfInfo,{nameCard:o,joinTime:r,role:i,messageRemindType:n,readedSequence:s,excludedUnreadSequenceList:u},[],["",null,void 0,0,NaN])}setSelfNameCard(e){this.selfInfo.nameCard=e}}var de=new class{constructor(){this._name="GroupDataHandler"}init(e){this._core=e;const{appStore:{groupStore:t}}=e;this._groupMap=t.getGroupMap(),console.log(`${this._name}.init`)}hasLocalGroup(e){return this._groupMap.has(e)}getLocalGroup(e){return this._groupMap.get(e)}updateLocalGroup(e){const{common:{getCurrentUserID:t}}=this._core;let o;e.forEach((e=>{var t;o=e.groupID,this.hasLocalGroup(o)?null===(t=this.getLocalGroup(o))||void 0===t||t.updateGroup(e):this._groupMap.set(o,new me(e))}));const r=t();for(const[,e]of this._groupMap)e.selfInfo.userID=r,"Owner"===e.selfInfo.role&&(e.ownerID=r)}deleteLocalGroup(e){this._groupMap.delete(e)}getLocalGroupList(){return[...this._groupMap.values()]}clearLocalGroup(){this._groupMap.clear()}emitGroupListUpdate(){const e=this.getLocalGroupList(),{OuterEvent:{GROUP_LIST_UPDATED:t},notificationCenter:o}=this._core;o.emitOuterEvent(t,{name:t,data:e})}updateConversationGroupProfile(e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:o}}=this._core,r=`${o}${e}`;if(t.getConversation(r)){const o=this.getLocalGroup(e);t.updateConversation(r,{groupProfile:o})}}reset(){this.clearLocalGroup()}};function ge(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(o[r[i]]=e[r[i]])}return o}function _e(e,t,o,r){return new(o||(o=Promise))((function(i,n){function s(e){try{a(r.next(e))}catch(e){n(e)}}function u(e){try{a(r.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))}function fe(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}"function"==typeof SuppressedError&&SuppressedError;const Ge=function(e){return{code:0,data:e||{}}};var be=new class{constructor(){this._name="GetGroupList",this._pagingStatus=c,this.PAGING_GRP_COUNT_LIMIT=200}init(e){this._core=e;const{helper:t,constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:r}}=e;t.registerApi({apiName:"getGroupList",context:this}),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,r.GROUP_LIST_SYNC,this._syncGroupList,this)}getGroupList(){return _e(this,void 0,void 0,(function*(){if(console.log(`${this._name}.getGroupList pagingStatus:${this._pagingStatus}`),this._pagingStatus===l||this._pagingStatus===c)return this._syncGroupList().then((()=>{const e=de.getLocalGroupList();return Ge({groupList:e,isSyncCompleted:this._isSyncCompleted()})})).catch((e=>{throw console.error(`${this._name}.getGroupList fail:`,e),e}));const e=de.getLocalGroupList();return console.log(`${this._name}.getGroupList return group count:${e.length}`),Ge({groupList:e,isSyncCompleted:this._isSyncCompleted()})}))}_syncGroupList(){return _e(this,void 0,void 0,(function*(){this._pagingStatus===c&&de.clearLocalGroup();const e=this.PAGING_GRP_COUNT_LIMIT,t=[];try{yield this._pagingGetGroupList({limit:e,offset:0,groupList:t}),this._pagingStatus=p,this._groupListTreeShaking(t),de.updateLocalGroup(t);const o=de.getLocalGroupList();return console.log(`${this._name}._syncGroupList ok, count:${o.length}`),de.emitGroupListUpdate(),o}catch(e){throw this._pagingStatus=l,console.error(`${this._name}._syncGroupList fail:`,e),e}}))}_pagingGetGroupList(e){return _e(this,void 0,void 0,(function*(){const{isCommunityRelay:t=!1,groupList:o}=e;let i,{limit:s,offset:u}=e;const a=[...r];t&&(i=this._core.OuterConstant.GRP_COMMUNITY,a.push("AtInfoList"));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{type:o,limit:r,offset:i,memberAccount:n,responseFilter:s}=e;return fe(o?"million_group_open_http_svc.get_joined_group_list":"group_open_http_svc.get_joined_group_list",{Limit:r,Offset:i,Member_Account:n,ResponseFilter:s,SupportTopic:0,NeedAppDefineData:1},t)}))}({type:i,limit:s,offset:u,memberAccount:this._core.store.get("login").userId,responseFilter:{GroupBaseInfoFilter:a,SelfInfoFilter:[...n]}},this._core),{GroupIdList:r=[],TotalCount:c=0}=e||{},p=this._convertGroupKey(r);o.push(...p);const l=u+s,h=!(c>l),m=`offset:${u} limit:${s} total:${c} isCompleted:${h} current:${o.length} isCommunityRelay:${t}`;return console.log(`${this._name}._pagingGetGroupList ok. ${m}`),t?h?o:(u=l,this._pagingGetGroupList({isCommunityRelay:!0,limit:s,offset:u,groupList:o})):h?(console.log(`${this._name}._pagingGetGroupList start to get community list`),u=0,this._pagingGetGroupList({isCommunityRelay:!0,limit:s,offset:u,groupList:o})):(u=l,this._pagingGetGroupList({limit:s,offset:u,groupList:o}))}catch(e){if(e.ErrorCode===h)return console.warn(`${this._name}._pagingGetGroupList response size exceeds the limit, request count:${s}`),s=50,this._pagingGetGroupList({isCommunityRelay:t,limit:s,offset:u,groupList:o});if(t)return e.code===m&&console.log(`${this._name}._pagingGetGroupList ok. community unavailable`),o;throw e}}))}_groupListTreeShaking(e){const t=new Map([...de.getLocalGroupList()]);for(let o=0,r=e.length;o<r;o++)t.delete(e[o].groupID);const o=[...t.keys()];for(let e=0,t=o.length;e<t;e++)de.deleteLocalGroup(o[e])}_isSyncCompleted(){return this._pagingStatus===p}_convertGroupKey(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppDefinedData:r,ApplyJoinOption:i,CreateTime:n,FaceUrl:s,GroupId:u,Introduction:a,InviteJoinOption:c,LastInfoTime:p,LastMsgTime:l,MemberNum:h,MaxMemberNum:m,MuteAllMember:d,Name:g,NextMsgSeq:_,Notification:f,Owner_Account:G,Type:b,LastRecallTime:v,SelfInfo:I}=e[o],y=pe(r),C=this._convertSelfInfo(I);t.push({groupCustomField:y,joinOption:i,createTime:n,avatar:s,groupID:u,introduction:a,inviteOption:c,lastInfoTime:p,lastMsgTime:l,memberCount:h,maxMemberCount:m,muteAllMembers:d,name:g,nextMessageSeq:_,notification:f,ownerID:G,type:b,_lastRevokedTime:v,selfInfo:C})}return t}_convertSelfInfo(e){const{JoinTime:t,MsgFlag:o,MsgSeq:r,NoUnreadSeqList:i,Role:n}=e;return{joinTime:t,messageRemindType:o,readedSequence:r,excludedUnreadSequenceList:i,role:n}}};var ve=new class{constructor(){this._name="CreateGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"createGroup",context:this})}createGroup(e){return _e(this,void 0,void 0,(function*(){var t;this._preCheckParams(e),console.log(`${this._name}.createGroup options:`,e);try{const{utils:{isEmpty:o},common:{getCurrentUserID:r}}=this._core,i=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{name:o,type:r,groupID:i,introduction:n,notification:s,avatar:u,maxMemberNum:a,joinOption:c,inviteOption:p,memberList:l,groupCustomField:h,isSupportTopic:m}=e;let d;return l&&(d=l.map((e=>{const{userID:t,memberCustomField:o}=e;return{Member_Account:t,AppMemberDefinedData:o?le(o):void 0}}))),fe("group_open_http_svc.create_group",{Name:o,Type:r,GroupId:i,Introduction:n,Notification:s,FaceUrl:u,MaxMemberCount:a,ApplyJoinOption:c,InviteJoinOption:p,MemberList:d,AppDefinedData:h,SupportTopic:m,webPushFlag:1},t)}))}(Object.assign(Object.assign({},e),{ownerID:r()}),this._core),{GroupId:n,OverJoinedGroupLimit_Account:s=[]}=i||{};if(console.log(`${this._name}.createGroup ok, groupType:${e.type} groupID:${n} overLimitUserIDList:${s}`),o(e.memberList)||o(s)||(e.memberList=null===(t=e.memberList)||void 0===t?void 0:t.filter((e=>s.includes(e.userID)))),this._notNeedUpdateLocalGroup(e))return Ge({group:new me(e)});de.updateLocalGroup([Object.assign(Object.assign({},e),{groupID:n})]),this._sendCustomMessage(n,e.type);const u=de.getLocalGroup(n);return de.emitGroupListUpdate(),Ge({group:u})}catch(e){throw console.error(`${this._name}.createGroup fail:`,e),e}}))}_preCheckParams(t){const{type:o,groupID:r}=t,{utils:{isEmpty:i,isUndefined:n},common:{isCommunity:s}}=this._core,u=!i(r);if(!(()=>{const{GRP_PUBLIC:t,GRP_WORK:o,GRP_MEETING:r,GRP_AVCHATROOM:i,GRP_COMMUNITY:n}=e.core.OuterConstant;return[t,o,r,i,n]})().includes(o))throw new this._core.helper.ChatError({code:Y});if(!s({type:o})){if(u&&s({groupID:r}))throw new this._core.helper.ChatError({code:W});n(t.isSupportTopic)||(t.isSupportTopic=void 0)}if(this._canIUseMemberList(o)||n(t.memberList)||(t.memberList=void 0),this._canIUseJoinOption(o)||n(t.joinOption)||(t.joinOption=void 0),this._canIUseTopic(t)&&(t.isSupportTopic=!0===t.isSupportTopic?1:0),s({type:o})&&u&&!s({groupID:r}))throw new this._core.helper.ChatError({code:W})}_canIUseMemberList(e){return!ae(e)}_canIUseJoinOption(e){return ue(e)||this._core.common.isCommunity({type:e})}_canIUseTopic(e){const{type:t,isSupportTopic:o}=e,{utils:{isUndefined:r},common:{isCommunity:i}}=this._core;return i({type:t})&&r(o)}_notNeedUpdateLocalGroup(e){const{type:t,isSupportTopic:o}=e,{OuterConstant:r}=this._core;return t===r.GRP_AVCHATROOM||t===r.GRP_COMMUNITY&&1===o}_sendCustomMessage(e,t){var o,r,i,n,s,c;const{OuterConstant:p}=this._core;let l="Create Group",h=u;t===p.GRP_COMMUNITY&&(l="Create Community",h=a);const m={to:e,conversationType:"GROUP",payload:{data:JSON.stringify({businessID:"group_create",content:l,cmd:h,opUser:this._core.store.get("login").userId,version:4})}},d=null===(i=null===(r=null===(o=this._core)||void 0===o?void 0:o.message)||void 0===r?void 0:r.messageFactory)||void 0===i?void 0:i.createCustomMessage(m);null===(c=null===(s=null===(n=this._core)||void 0===n?void 0:n.message)||void 0===s?void 0:s.messageSender)||void 0===c||c.sendMessage(d,{})}};var Ie=new class{constructor(){this._name="AttributesDataHandler",this._groupAttributesCache=new Map,this._groupAttributesCacheValuesCopy={}}init(e){this._core=e;const{helper:t,constants:o}=e;t.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.GROUP_ATTRIBUTE_CACHE_CLEAR,this.clearLocalMainSequence,this)}clearLocalMainSequence(){this._groupAttributesCache.forEach((e=>{e.localMainSequence=0}))}isGroupAttributesUpdated(e){const{elements:{newGroupProfile:t}}=e,{utils:{isEmpty:o,isUndefined:r}}=this._core;return!r(t)&&!o(t.groupAttributeOption)}handleGroupAttributesUpdated(e){const{groupID:t,groupAttributeOption:o}=e,{serverMainSequence:r,groupAttributeList:i=[],operation:n}=o;console.log(`${this._name}.handleGroupAttributesUpdated groupID:${t} operation:${n}`);const{utils:{isUndefined:s}}=this._core;s(n)||(this.refreshGroupAttributesCache({groupID:t,serverMainSequence:r,groupAttributeList:i,operation:n}),this.emitGroupAttributesUpdated(t))}initGroupAttributesCache(e){const{groupID:t,avChatRoomKey:o}=e;this._groupAttributesCache.set(t,{lastUpdateTime:0,localMainSequence:0,serverMainSequence:0,avChatRoomKey:o,values:new Map}),console.log(`${this._name}.initGroupAttributesCache. groupID:${t} avChatRoomKey:${o}`)}hasGroupAttributesCache(e){return this._groupAttributesCache.has(e)}getGroupAttributesCache(e){return this.hasGroupAttributesCache(e)||this.initGroupAttributesCache({groupID:e}),this._groupAttributesCache.get(e)}deleteGroupAttributesCache(e){this.hasGroupAttributesCache(e)&&this._groupAttributesCache.delete(e)}refreshGroupAttributesCache(e){const{groupID:t,serverMainSequence:o,groupAttributeList:r,operation:i}=e;if(this.hasGroupAttributesCache(t)){const e=this.getGroupAttributesCache(t),{localMainSequence:n}=e;i!==A&&o-n!=1||(e.serverMainSequence=o,e.localMainSequence=o,e.lastUpdateTime=Date.now(),this._updateGroupAttributesCacheValues({groupAttributes:e,groupAttributeList:r,operation:i})),o-n>1&&(e.serverMainSequence=o),this._groupAttributesCache.set(t,e),console.log(`${this._name}.refreshGroupAttributesCache. operation:${i} localMainSequence:${n} serverMainSequence:${o}`)}}_updateGroupAttributesCacheValues(e){const{groupAttributes:t,groupAttributeList:o=[],operation:r}=e;r!==C?r!==M?(r===I&&t.values.clear(),o.forEach((e=>{const{key:o,value:r,sequence:i}=e;t.values.set(o,{value:r,sequence:i})}))):o.forEach((e=>{t.values.delete(e.key)})):t.values.clear()}getGroupAttributesCacheValues(e){var t;const{groupID:o,keyList:r=[]}=e,i={};if(this.hasGroupAttributesCache(o)){const{values:e}=this.getGroupAttributesCache(o);if(0===r.length){for(const o of e.keys())i[o]=(null===(t=e.get(o))||void 0===t?void 0:t.value)||"";return i}return r.forEach((t=>{var o;e.has(t)&&(i[t]=(null===(o=e.get(t))||void 0===o?void 0:o.value)||"")})),i}return i}saveGroupAttributesCacheValuesCopy(e){this._groupAttributesCacheValuesCopy=this.getGroupAttributesCacheValues({groupID:e})}emitGroupAttributesUpdated(e){var t;const o=this.getGroupAttributesCacheValues({groupID:e}),{updatedKeyList:r,deletedKeyList:i}=this._computeValuesChangedData(o);console.log(`${this._name}.emitGroupAttributesUpdated update count:${r.length}, delete count:${i.length}`),0===r.length&&0===i.length||this._emitEvent({name:null===(t=this._core)||void 0===t?void 0:t.OuterEvent.GROUP_ATTRIBUTES_UPDATED,data:{groupID:e,groupAttributes:o,updatedKeyList:r,deletedKeyList:i}})}_computeValuesChangedData(e){const{utils:{isUndefined:t}}=this._core,o=[],r=[];return Object.keys(e).forEach((t=>{e[t]!==this._groupAttributesCacheValuesCopy[t]&&o.push(t)})),Object.keys(this._groupAttributesCacheValuesCopy).forEach((o=>{t(e[o])&&r.push(o)})),this._groupAttributesCacheValuesCopy={},{updatedKeyList:o,deletedKeyList:r}}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}convertKeyValueMapToList(e){const t=[];return Object.keys(e).forEach((o=>{t.push({key:o,value:e[o]})})),t}};var ye=new class{constructor(){this._name="DismissGroup"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"dismissGroup",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}dismissGroup(e){return _e(this,void 0,void 0,(function*(){console.log(`${this._name}.dismissGroup groupID:${e}`);try{yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.destroy_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.dismissGroup ok.`);const{type:t}=de.getLocalGroup(e);return de.deleteLocalGroup(e),de.emitGroupListUpdate(),Ie.deleteGroupAttributesCache(e),Ge({groupID:e,type:t})}catch(e){throw console.error(`${this._name}.dismissGroup fail:`,e),e}}))}};var Ce=new class{constructor(){this._name="GetGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupProfile",context:this})}getGroupProfile(e){return _e(this,void 0,void 0,(function*(){const{groupID:t,groupCustomFieldFilter:o}=e,i={groupIDList:[t],responseFilter:{GroupBaseInfoFilter:[...r],AppDefinedDataFilter_Group:o,MemberInfoFilter:[...s]}};try{const e=yield this.getGroupProfileAdvance(i),{successGroupList:o,failureGroupList:r}=e;if(r.length>0)throw r[0];let n;return!de.hasLocalGroup(t)&&ae(o[0].type)?n=new me(o[0]):(de.updateLocalGroup(o),n=de.getLocalGroup(t)),n.isSupportTopic||de.updateConversationGroupProfile(t),console.log(`${this._name}.getGroupProfile ok.`),Ge({group:n})}catch(e){throw console.error(`${this._name}.getGroupProfile fail:`,e),e}}))}getGroupProfileAdvance(e){return _e(this,void 0,void 0,(function*(){const{groupIDList:t}=e,{common:{isCommunity:o}}=this._core,r=t.filter((e=>!o({groupID:e}))),i=t.filter((e=>o({groupID:e})));r.length>50&&(r.length=50),i.length>50&&(i.length=50);const n=yield Promise.all([this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:r})),this._getGroupProfileAdvance(Object.assign(Object.assign({},e),{groupIDList:i,isCommunityProfile:!0}))]),s=[],u=[];return n.forEach((e=>{s.push(...e.successGroupList),u.push(...e.failureGroupList)})),{successGroupList:s,failureGroupList:u}}))}_getGroupProfileAdvance(e){return _e(this,void 0,void 0,(function*(){const{isCommunityProfile:t=!1}=e,o=ge(e,["isCommunityProfile"]);if(0===o.groupIDList.length)return{successGroupList:[],failureGroupList:[]};try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupIDList:o,responseFilter:r}=e;return fe("group_open_http_svc.get_group_self_member_info",{GroupIdList:o,ResponseFilter:r},t)}))}(o,this._core),{GroupInfo:t=[]}=e||{},r=this._convertGroupProfileKey(t),{utils:{isUndefined:i}}=this._core,n=r.filter((e=>i(e.errorCode)||0===e.errorCode)),s=r.filter((e=>e.errorCode&&0!==e.errorCode)).map((e=>({code:e.errorCode,message:e.errorInfo,data:{groupID:e.groupID}})));return console.log(`${this._name}._getGroupProfileAdvance ok, groupID:${o.groupIDList.join(",")}`),{successGroupList:n,failureGroupList:s}}catch(e){if(t)return{successGroupList:[],failureGroupList:[]};throw e}}))}_convertGroupProfileKey(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppDefinedData:r,ApplyJoinOption:i,CreateTime:n,FaceUrl:s,GroupId:u,InfoSeq:a,Introduction:c,InviteJoinOption:p,LastInfoTime:l,LastMsgTime:h,MaxMemberNum:m,MemberNum:d,MuteAllMember:g,Name:_,NextMsgSeq:f,Notification:G,Owner_Account:b,ShutUpAllMember:v,ShutUpUntil:I,Type:y,MemberList:C,ErrorCode:M,ErrorInfo:A}=e[o],D=pe(r),L=this._convertMembers(C);t.push({groupCustomField:D,joinOption:i,createTime:n,avatar:s,groupID:u,infoSequence:a,introduction:c,inviteOption:p,lastInfoTime:l,lastMsgTime:h,maxMemberCount:m,memberCount:d,muteAllMembers:g,name:_,nextMessageSeq:f,notification:G,ownerID:b,shutUpAllMember:v,muteUntil:I,type:y,members:L,errorCode:M,errorInfo:A})}return t}_convertMembers(e){if(!e)return[];const t=[];for(let o=0,r=e.length;o<r;o++){const{AppMemberDefinedData:r,JoinTime:i,Member_Account:n,MsgFlag:s,MsgSeq:u,NameCard:a,Role:c}=e[o],p=pe(r);t.push({memberCustomField:p,joinTime:i,userID:n,messageRemindType:s,sequence:u,nameCard:a,role:c})}return t}};var Me=new class{constructor(){this._name="JoinGroup"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"joinGroup",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}joinGroup(e){return _e(this,void 0,void 0,(function*(){const{groupID:t}=e;try{if(de.hasLocalGroup(t))try{return yield Ce.getGroupProfile({groupID:t}),Ge({status:this._core.OuterConstant.JOIN_STATUS_SUCCESS})}catch(o){console.warn(`${this._name}.joinGroup ${t} was unjoined, start to join!`),de.deleteLocalGroup(t);return yield this._applyJoinGroup(e)}return yield this._applyJoinGroup(e)}catch(e){throw console.error(`${this._name}.joinGroup fail:`,e),e}}))}_applyJoinGroup(e){return _e(this,void 0,void 0,(function*(){const{OuterConstant:t,helper:r}=this._core,{groupID:i}=e,n=Object.assign({},e),s=r.checkBusinessCapabilityBits(o);s&&(n.historyMessageFlag=1);const u=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,applyMessage:r,historyMessageFlag:i}=e;return fe("group_open_http_svc.apply_join_group",{GroupId:o,ApplyMsg:r,HugeGroupHistoryMsgFlag:i},t)}))}(n,this._core),{JoinedStatus:a,LongPollingKey:c,StartSeq:p,HugeGroupFlag:l,AVChatRoomKey:h,RspMsgList:m=[]}=u||{},d=`groupID:${i} joinedStatus:${a} longPollingKey:${c} startSeq:${p} avChatRoomFlag:${l} canGetAVChatRoomHistoryMsg:${s}, historyMessageCount:${m.length}`;if(console.log(`${this._name}._applyJoinGroup ok, ${d}`),a===t.JOIN_STATUS_WAIT_APPROVAL)return{code:0,data:{status:t.JOIN_STATUS_WAIT_APPROVAL}};if(a===t.JOIN_STATUS_SUCCESS){let e=null;try{e=(yield Ce.getGroupProfile({groupID:i})).data.group}catch(t){e=new me({groupID:i}),console.warn(`${this._name}._applyJoinGroup getGroupProfile failed, groupID: ${i}, errorCode:`,null==t?void 0:t.code)}return this._handleJoinResult({group:e,avChatRoomFlag:l,longPollingKey:c,startSequence:p,avChatRoomKey:h,historyMessageList:m})}throw new this._core.helper.ChatError({code:ee})}))}_handleJoinResult(e){const{group:t,avChatRoomFlag:o,avChatRoomKey:r}=e;return 1===o?(Ie.initGroupAttributesCache({groupID:t.groupID,avChatRoomKey:r}),Ge(e)):(de.updateLocalGroup([t]),de.emitGroupListUpdate(),Ge({status:this._core.OuterConstant.JOIN_STATUS_SUCCESS,group:t}))}};var Ae=new class{constructor(){this._name="QuitGroup"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"quitGroup",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}quitGroup(e){return _e(this,void 0,void 0,(function*(){if(!de.hasLocalGroup(e))throw new this._core.helper.ChatError({code:Z});try{yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.quit_group",{GroupId:e},t)}))}(e,this._core),console.log(`${this._name}.quitGroup ok, groupID:${e}`);const{type:t}=de.getLocalGroup(e);return de.deleteLocalGroup(e),de.emitGroupListUpdate(),Ie.deleteGroupAttributesCache(e),Ge({groupID:e,type:t})}catch(e){throw console.error(`${this._name}.quitGroup fail:`,e),e}}))}};var De=new class{constructor(){this._name="SearchGroup"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"searchGroupByID",context:this})}searchGroupByID(e){return _e(this,void 0,void 0,(function*(){console.log(`${this._name}.searchGroupByID groupID:${e}`);try{const t=yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.get_group_public_info",{GroupIdList:[e],GroupBasePublicInfoFilter:[...i]},t)}))}(e,this._core),{GroupInfo:o=[]}=t||{},{AppDefinedData:r=[],ApplyJoinOption:n,CreateTime:s,FaceUrl:u,Introduction:a,InviteJoinOption:c,MaxMemberNum:p,MemberNum:l,Name:h,Owner_Account:m,Type:d,ErrorCode:g,ErrorInfo:_}=o[0];if(0!==g)throw new this._core.helper.ChatError({code:g,message:_});console.log(`${this._name}.searchGroupByID ok.`);const f=pe(r),G=new me({groupID:e,name:h,avatar:u,introduction:a,joinOption:n,inviteOption:c,maxMemberCount:p,memberCount:l,type:d,ownerID:m,createTime:s,groupCustomField:f});return Ge({group:G})}catch(e){throw console.error(`${this._name}.searchGroupByID fail:`,e),e}}))}};var Le=new class{constructor(){this._name="UpdateGroupProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"updateGroupProfile",context:this})}updateGroupProfile(e){return _e(this,void 0,void 0,(function*(){const{groupID:t}=e,{utils:{isUndefined:o}}=this._core;let r=de.getLocalGroup(t);if(r){const{type:t}=r;this._canIUseJoinOption(t)||o(e.joinOption)||(console.warn(`${this._name}.updateGroupProfile joinOption is unavailable for Work/Meeting/AVChatRoom`),e.joinOption=void 0)}o(e.muteAllMembers)||(e.muteAllMembers=!0===e.muteAllMembers?"On":"Off");try{return yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,name:r,avatar:i,introduction:n,notification:s,muteAllMembers:u,joinOption:a,inviteOption:c,groupCustomField:p}=e;return fe("group_open_http_svc.modify_group_base_info",{GroupId:o,Name:r,FaceUrl:i,Introduction:n,Notification:s,ShutUpAllMember:u,ApplyJoinOption:a,InviteJoinOption:c,AppDefinedData:p?le(p):void 0},t)}))}(e,this._core),console.log(`${this._name}.updateGroupProfile groupID:${t} ok.`),r?(r.updateGroup(e),de.emitGroupListUpdate()):r=new me(e),Ge({group:r})}catch(e){throw console.error(`${this._name}.updateGroupProfile groupID:${t} fail:`,e),e}}))}_canIUseJoinOption(e){return ue(e)||this._core.common.isCommunity({type:e})}};var Se=new class{constructor(){this._name="ChangeGroupOwner"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"changeGroupOwner",context:this})}changeGroupOwner(e){return _e(this,void 0,void 0,(function*(){const t="changeGroupOwner",{groupID:o,newOwnerID:r}=e,i=de.getLocalGroup(o),{helper:n,OuterConstant:s,common:{getCurrentUserID:u}}=this._core;if((null==i?void 0:i.type)===s.GRP_AVCHATROOM)throw new n.ChatError({functionName:t,code:z});if(r===u())throw new n.ChatError({functionName:t,code:X});console.log(`${this._name}.${t} groupID:${o} newOwnerID:${r}`);try{return yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,newOwnerID:r}=e;return fe("group_open_http_svc.change_group_owner",{GroupId:o,NewOwner_Account:r},t)}))}(e,this._core),console.log(`${this._name}.${t} ok.`),i.ownerID=r,de.emitGroupListUpdate(),Ge({group:i})}catch(e){const o=new n.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var Oe=new class{constructor(){this._name="GetGroupOnlineMemberCount",this._onlineMemberCountMap=new Map}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}getGroupOnlineMemberCount(e){return _e(this,void 0,void 0,(function*(){const t="getGroupOnlineMemberCount",o=de.hasLocalGroup(e);if(console.log(`${this._name}.${t} groupID:${e} hasLocalGroup:${o}`),!o)return Ge({memberCount:0});const r=Date.now();if(this._onlineMemberCountMap.has(e)){const t=this._onlineMemberCountMap.get(e),{lastReqTime:o=0,memberCount:i=0}=t||{};if(r-o<=6e4)return Ge({memberCount:i})}try{const o=yield function(e,t){return _e(this,void 0,void 0,(function*(){return fe("group_open_http_svc.get_online_member_num",{GroupId:e},t)}))}(e,this._core),{OnlineMemberNum:r=0}=o||{};return this._onlineMemberCountMap.set(e,{lastReqTime:Date.now(),memberCount:r}),console.log(`${this._name}.${t} ok. groupID:${e} memberCount:${r}`),Ge({memberCount:r})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var we=new class{init(e,t){console.log("GroupAction.init"),be.init(e),ve.init(e),ye.init(e,t),Me.init(e,t),Ae.init(e,t),De.init(e),Ce.init(e),Le.init(e),Se.init(e),Oe.init(e,t)}dismissGroup(e){return ye.dismissGroup(e)}joinGroup(e){return Me.joinGroup(e)}quitGroup(e){return Ae.quitGroup(e)}getGroupOnlineMemberCount(e){return Oe.getGroupOnlineMemberCount(e)}};function Te(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}var $e=new class{constructor(){this._name="GetGroupApplicationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupApplicationList",context:this})}getGroupApplicationList(){return _e(this,void 0,void 0,(function*(){const e="getGroupApplicationList";try{const t=yield Promise.all([this._getGroupApplicationList(),this._getGroupApplicationList({type:this._core.OuterConstant.GRP_COMMUNITY})]);console.log(`${this._name}.${e} ok.`);const o=this._handleGroupApplicationResult([...t[0],...t[1]]);return Ge({applicationList:o})}catch(t){const o=new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo});throw console.error(`${this._name}.${e} fail:`,o),o}}))}_getGroupApplicationList(t){return _e(this,void 0,void 0,(function*(){const{type:o,startTime:r=0,limit:i=20}=t||{},{common:n}=this._core;let s;try{s=yield function(t,o){return _e(this,void 0,void 0,(function*(){const{type:r,startTime:i,limit:n,handleAccount:s}=t;return Te(e.core.common.isCommunity({type:r})?"million_group_open_http_svc.get_pendency":"group_open_http_svc.get_pendency",{StartTime:i,Limit:n,Handle_Account:s},o)}))}({type:o,startTime:r,limit:i,handleAccount:n.getCurrentUserID()},this._core)}catch(e){if(11e3!==(null==e?void 0:e.errorCode))throw e;s={}}const{NextStartTime:u=0,PendencyList:a=[]}=s||{};if(0===u)return a;const c=yield this._getGroupApplicationList(Object.assign(Object.assign({},t),{startTime:u}));return[...a,...c]}))}_handleGroupApplicationResult(e){const t=[];return e.forEach((e=>{const o=this._convertApplicationData(e),{handled:r}=o,i=ge(o,["handled"]);0===r&&t.push(i)})),t}_convertApplicationData(e){const{Handled:t,AddTime:o,ApplyInviteMsg:r,Authentication:i,FromUserNickName:n,From_Account:s,GroupId:u,GroupName:a,PendencyType:c,To_Account:p}=e;return{handled:t,messageKey:o,applicant:s,applicantNick:n,groupID:u,groupName:a,authentication:i,applicationType:c,userID:p,note:r}}};var Ne=new class{constructor(){this._name="HandleGroupApplication"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"handleGroupApplication",context:this})}handleGroupApplication(t){return _e(this,void 0,void 0,(function*(){const o="handleGroupApplication",{application:r}=t,i=this._handleParams(t);try{(null==r?void 0:r.applicationType)===d?yield function(t,o){return _e(this,void 0,void 0,(function*(){const{groupID:r,handleAction:i,handleMessage:n,applicant:s,authentication:u,invitee:a}=t;return Te(e.core.common.isCommunity({groupID:r})?"million_group_open_http_svc.handle_invite_join_permission_group":"group_open_http_svc.handle_invite_join_permission_group",{GroupId:r,HandleMsg:i,ApprovalMsg:n,Applicant_Account:s,Authentication:u,Invited_Account:a},o)}))}(i,this._core):yield function(t,o){return _e(this,void 0,void 0,(function*(){const{groupID:r,handleAction:i,handleMessage:n,applicant:s,authentication:u,messageKey:a}=t;return Te(e.core.common.isCommunity({groupID:r})?"million_group_open_http_svc.handle_apply_join_group":"group_open_http_svc.handle_apply_join_group",{GroupId:r,HandleMsg:i,ApprovalMsg:n,Applicant_Account:s,Authentication:u,MsgKey:a},o)}))}(i,this._core),console.log(`${this._name}.${o} ok.`);const t=de.getLocalGroup(i.groupID);return Ge({group:t})}catch(e){const t=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${o} fail:`,t),t}}))}_handleParams(e){var t;const{handleAction:o,handleMessage:r,message:i,application:n}=e;let s,u,a,c,p;if(i){const{payload:e}=i||{};s=e.operatorID,u=null===(t=e.groupProfile)||void 0===t?void 0:t.groupID,a=e.authentication,c=e.messageKey}else s=(null==n?void 0:n.applicant)||"",u=(null==n?void 0:n.groupID)||"",a=(null==n?void 0:n.authentication)||"",c=(null==n?void 0:n.messageKey)||0;return(null==n?void 0:n.applicationType)===d&&(p=n.userID),{handleAction:o,handleMessage:r,applicant:s,invitee:p,groupID:u,authentication:a,messageKey:c}}};var Ee=new class{init(e){console.log("GroupApplication.init"),$e.init(e),Ne.init(e)}};let Pe=class{constructor(e){this.userID="",this.avatar="",this.nick="",this.role="",this.joinTime="",this.nameCard="",this.muteUntil=0,this.memberCustomField=[],this.isOnline=!1,this.updateMember(e)}updateMember(t){const{core:{utils:{isUndefined:o},common:{deepMerge:r}}}=e;o(t.muteTime)||(this.muteUntil=Math.floor((Date.now()+1e3*t.muteTime)/1e3)),o(t.onlineStatus)||(this.isOnline="Online"===t.onlineStatus);const i=[null,void 0,"",0,NaN];t.memberCustomField&&ce(this.memberCustomField,t.memberCustomField),r(this,t,["memberCustomField","marks","onlineStatus","muteTime"],i)}};function Re(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}function Ue(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userID:r,muteTime:i,role:n,nameCard:s,memberCustomField:u}=e;let a;u&&(a=le(u));return Re("group_open_http_svc.modify_group_member_info",{GroupId:o,Member_Account:r,ShutUpTime:i,Role:n,NameCard:s,AppMemberDefinedData:a},t)}))}var ke=new class{constructor(){this._name="GetGroupMemberList"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}getGroupMemberList(e){return _e(this,void 0,void 0,(function*(){const t="getGroupMemberList",{groupID:o,offset:r=0,count:i=100,role:n="",filter:s=""}=e;console.log(`${this._name}.${t} groupID:${o} offset:${r} count:${i} role:${n} filter:${s}`);const u=de.getLocalGroup(o),a=i>100?100:i,c={groupID:o,offset:r,limit:a,memberRoleFilter:g.includes(n)?[n]:void 0,memberInfoFilter:_};try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,offset:r,limit:i,memberRoleFilter:n,memberInfoFilter:s}=e;return Re("group_open_http_svc.get_group_member_info",{GroupId:o,Offset:r,Limit:i,MemberRoleFilter:n,MemberInfoFilter:s},t)}))}(c,this._core),{MemberList:i,MemberNum:n,Next:s}=e||{};console.log(`${this._name}.${t} ok, totalMemberCount:${n} next:${s}`);const{utils:{isArray:p,isEmpty:l},common:{isCommunity:h}}=this._core;if(u&&(u.memberCount=n),!p(i)||0===i.length)return Ge({memberList:[],offset:0});let m=r+a;h({groupID:o})&&(m=l(s)?0:s),i.length<a&&(m=0);let d=this._convertMemberInfo(i);d=yield this._patchAvatarAndNick(d);const g=this._generateGroupMember(d);return Ge({memberList:g,offset:m})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_convertMemberInfo(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppMemberDefinedData:r,JoinTime:i,Member_Account:n,OnlineStatus:s,Role:u,ShutUpUntil:a}=e[o],c=pe(r);t.push({userID:n,joinTime:i,onlineStatus:s,role:u,muteUntil:a,memberCustomField:c})}return t}_patchAvatarAndNick(e){return _e(this,void 0,void 0,(function*(){var t;const o=e.map((e=>e.userID)),r=yield null===(t=this._core.user.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:o}),i=(null==r?void 0:r.data)||[],n=new Map(i.map((e=>[e.userID,e])));return e.forEach((e=>{if(n.has(e.userID)){const{nick:t="",avatar:o=""}=n.get(e.userID);e.nick=t,e.avatar=o}})),e}))}_generateGroupMember(e){const t=[];for(let o=0,r=e.length;o<r;o++){const r=new Pe(e[o]);t.push(r)}return t}};var qe=new class{constructor(){this._name="GetGroupMemberProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupMemberProfile",context:this})}getGroupMemberProfile(e){return _e(this,void 0,void 0,(function*(){const t="getGroupMemberProfile",{groupID:o,userIDList:r,memberCustomFieldFilter:i}=e,n=de.getLocalGroup(o),{helper:s,utils:{isArray:u}}=this._core;if(n&&ae(n.type))throw new s.ChatError({functionName:t,replacement1:t,code:se});r.length>50&&(console.warn(`${this._name}.${t} userIDList length:${r.length} exceeds limit 50`),r.splice(50));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userIDList:r,memberInfoFilter:i,memberCustomFieldFilter:n}=e;return Re("group_open_http_svc.get_specified_group_member_info",{GroupId:o,Member_List_Account:r,MemberInfoFilter:i,AppDefinedDataFilter_GroupMember:n},t)}))}({groupID:o,userIDList:r,memberCustomFieldFilter:i,memberInfoFilter:[..._]},this._core);console.log(`${this._name}.${t} ok.`);const{MemberList:n}=e||{};if(!u(n)||0===n.length)return Ge({memberList:[]});let s=this._convertMemberInfo(n);s=yield this._getMemberAvatarAndNick(s);const a=this._generateGroupMember(s);return Ge({memberList:a})}catch(e){const o=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_convertMemberInfo(e){const t=[];for(let o=0,r=e.length;o<r;o++){const{AppMemberDefinedData:r,JoinTime:i,Member_Account:n,OnlineStatus:s,Role:u,ShutUpUntil:a}=e[o],c=pe(r);t.push({userID:n,joinTime:i,onlineStatus:s,role:u,muteUntil:a,memberCustomField:c})}return t}_getMemberAvatarAndNick(e){return _e(this,void 0,void 0,(function*(){var t;const o=e.map((e=>e.userID)),r=yield null===(t=this._core.user.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:o}),i=(null==r?void 0:r.data)||[],n=new Map(i.map((e=>[e.userID,e])));return e.forEach((e=>{if(n.has(e.userID)){const{nick:t="",avatar:o=""}=n.get(e.userID);e.nick=t,e.avatar=o}})),e}))}_generateGroupMember(e){const t=[];for(let o=0,r=e.length;o<r;o++){const r=new Pe(e[o]);t.push(r)}return t}};var Fe=new class{constructor(){this._name="AddGroupMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"addGroupMember",context:this})}addGroupMember(e){return _e(this,void 0,void 0,(function*(){const t="addGroupMember",{groupID:o,userIDList:r}=e,i=de.getLocalGroup(o),{helper:n}=this._core;if(i&&ae(i.type))throw new n.ChatError({functionName:t,code:te});const s=r.map((e=>({Member_Account:e})));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userIDList:r}=e;return Re("group_open_http_svc.add_group_member",{GroupId:o,MemberList:r},t)}))}({groupID:o,userIDList:s},this._core),{MemberList:r=[]}=e||{},{failureUserIDList:n,successUserIDList:u,existedUserIDList:a,overLimitUserIDList:c}=this._handleResult(r);return console.log(`${this._name}.${t} groupID:${o} ok, successUserIDList:${u} failureUserIDList:${n} existedUserIDList:${a} overLimitUserIDList:${c}`),Ge({failureUserIDList:n,successUserIDList:u,existedUserIDList:a,overLimitUserIDList:c,group:i})}catch(e){const o=new n.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_handleResult(e){const t=[],o=[],r=[],i=[];return e.forEach((e=>{const{Result:n,Member_Account:s}=e;n===f?t.push(s):n===G?o.push(s):n===b?r.push(s):n===v&&i.push(s)})),{failureUserIDList:t,successUserIDList:o,existedUserIDList:r,overLimitUserIDList:i}}};var je=new class{constructor(){this._name="DeleteGroupMember"}init(e,o){this._core=e;const{helper:r}=e;r.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>!o.getInstalledSubPlugins().includes(t)})}deleteGroupMember(e){return _e(this,void 0,void 0,(function*(){const t="deleteGroupMember",{groupID:o,userIDList:r}=e,i=de.getLocalGroup(o),{helper:n,utils:{isUndefined:s}}=this._core;if(s(i))throw new n.ChatError({functionName:t,code:Q});r.length>20&&(console.warn(`${this._name}.${t} userIDList length:${r.length} exceeds limit 20`),r.splice(20));try{return yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,userIDList:r,reason:i}=e;return Re("group_open_http_svc.delete_group_member",{GroupId:o,MemberToDel_Account:r,Reason:i},t)}))}({groupID:o,userIDList:r},this._core),console.log(`${this._name}.${t} ok, groupID:${o} userIDList length:${r.length}`),Ge({group:i,userIDList:r})}catch(e){const o=new n.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var xe=new class{constructor(){this._name="SetGroupMemberMuteTime"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberMuteTime",context:this})}setGroupMemberMuteTime(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberMuteTime",{helper:o}=this._core;this._preCheckSettingMuteParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,muteTime:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} muteTime:${i}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,muteTime:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingMuteParams(e){const{userID:t}=e,{store:o,helper:r}=this._core;if(t===o.get("login").userId)throw new r.ChatError({functionName:"setGroupMemberMuteTime",code:ne})}};var Ke=new class{constructor(){this._name="SetGroupMemberRole"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberRole",context:this})}setGroupMemberRole(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberRole",{helper:o}=this._core;this._preCheckSettingRoleParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,role:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} role:${i}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,role:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingRoleParams(e){var t;const{groupID:o,userID:r,role:i}=e,{store:n,helper:s,OuterConstant:u,common:{isCommunity:a}}=this._core,c=de.getLocalGroup(o);if((null===(t=null==c?void 0:c.selfInfo)||void 0===t?void 0:t.role)!==u.GRP_MBR_ROLE_OWNER)throw new s.ChatError({functionName:"setGroupMemberRole",code:oe});if(r===n.get("login").userId)throw new s.ChatError({functionName:"setGroupMemberRole",code:ie});const p=[...g];if(a({groupID:o})&&p.push(u.GRP_MBR_ROLE_CUSTOM),!p.includes(i))throw new s.ChatError({functionName:"setGroupMemberRole",code:re})}};var Ve=new class{constructor(){this._name="SetGroupMemberNameCard"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberNameCard",context:this})}setGroupMemberNameCard(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberNameCard",{helper:o}=this._core;this._preCheckSettingNameCardParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,nameCard:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} nameCard:${i}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,nameCard:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingNameCardParams(e){const{groupID:t}=e,{helper:o}=this._core,r=de.getLocalGroup(t);if(ae(null==r?void 0:r.type))throw new o.ChatError({functionName:"setGroupMemberNameCard",code:se})}};var Je=new class{constructor(){this._name="SetGroupMemberCustomField"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupMemberCustomField",context:this})}setGroupMemberCustomField(e){return _e(this,void 0,void 0,(function*(){const t="setGroupMemberCustomField",{helper:o}=this._core;this._preCheckSettingCustomFiledParams(e);try{yield Ue(e,this._core);const{groupID:o,userID:r,memberCustomField:i}=e;console.log(`${this._name}.${t} ok, groupID:${o} userID:${r} memberCustomField:${JSON.stringify(i)}`);const n=de.getLocalGroup(o),s=new Pe({userID:r,memberCustomField:i});return Ge({group:n,member:s})}catch(e){const r=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,r),r}}))}_preCheckSettingCustomFiledParams(e){const{groupID:t}=e,{helper:o}=this._core,r=de.getLocalGroup(t);if(ae(null==r?void 0:r.type))throw new o.ChatError({functionName:"setGroupMemberCustomField",code:se})}};var Be=new class{init(e,t){console.log("GroupMember.init"),ke.init(e,t),qe.init(e),Fe.init(e),je.init(e,t),xe.init(e),Ke.init(e),Ve.init(e),Je.init(e)}getGroupMemberList(e){return ke.getGroupMemberList(e)}deleteGroupMember(e){return je.deleteGroupMember(e)}};var He=new class{init(e){this._core=e}};function Ye(e,t,o){return _e(this,void 0,void 0,(function*(){const{helper:r,channel:i}=o,n=r.generateProtocolData({servcmd:e,data:t}),s=`${n.head.seq}${e}`;return yield i.sendPacket(n,{requestId:s})}))}var We=new class{constructor(){this._name="InitGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"initGroupAttributes",context:this})}initGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="initGroupAttributes",{groupID:o,groupAttributes:r}=e,{serverMainSequence:i,avChatRoomKey:n}=Ie.getGroupAttributesCache(o),s=Ie.convertKeyValueMapToList(r);try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,groupAttributeList:i,avChatRoomKey:n}=e;return Ye("group_open_http_svc.set_group_attr",{GroupId:o,AttrMainSeq:r,GroupAttr:i,BytesKey:n,AttrControl:["RaceConflict"]},t)}))}({groupID:o,avChatRoomKey:n,groupAttributeList:s,mainSequence:i},this._core),{AttrMainSeq:u,GroupAttr:a}=e||{};console.log(`${this._name}.${t} ok. groupID:${o} serverMainSequence:${u}`);const c=a.map((e=>{const{Key:t,seq:o}=e;return{key:t,value:r[t],sequence:o}}));return Ie.saveGroupAttributesCacheValuesCopy(o),Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:u,groupAttributeList:c,operation:I}),Ie.emitGroupAttributesUpdated(o),Ge({groupAttributes:r})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var Qe=new class{constructor(){this._name="SetGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setGroupAttributes",context:this})}setGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="setGroupAttributes",{groupID:o,groupAttributes:r}=e,{serverMainSequence:i,avChatRoomKey:n,values:s}=Ie.getGroupAttributesCache(o),u=Ie.convertKeyValueMapToList(r).map((e=>{var t;const{key:o,value:r}=e;return{key:o,value:r,seq:(null===(t=s.get(e.key))||void 0===t?void 0:t.sequence)||0}}));try{const e=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,groupAttributeList:i,avChatRoomKey:n}=e;return Ye("group_open_http_svc.modify_group_attr",{GroupId:o,AttrMainSeq:r,GroupAttr:i,BytesKey:n,AttrControl:["RaceConflict"]},t)}))}({groupID:o,avChatRoomKey:n,groupAttributeList:u,mainSequence:i},this._core),{AttrMainSeq:s,GroupAttr:a}=e||{};console.log(`${this._name}.${t} ok. groupID:${o} serverMainSequence:${s}`);const c=a.map((e=>{const{Key:t,seq:o}=e;return{key:t,value:r[t],sequence:o}}));return Ie.saveGroupAttributesCacheValuesCopy(o),Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:s,groupAttributeList:c,operation:y}),Ie.emitGroupAttributesUpdated(o),Ge({groupAttributes:r})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}};var ze=new class{constructor(){this._name="DeleteGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteGroupAttributes",context:this})}deleteGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="deleteGroupAttributes",{groupID:o,keyList:r=[]}=e;try{let e;e=0===r.length?yield this._clearGroupAttributes(o):yield this._deleteGroupAttributes(o,r);const{resultList:i,serverMainSequence:n,operation:s,groupAttributeList:u}=e||{};return console.log(`${this._name}.${t} ok. groupID:${o} operation: ${s}`),Ie.saveGroupAttributesCacheValuesCopy(o),Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:n,groupAttributeList:u,operation:s}),Ie.emitGroupAttributesUpdated(o),Ge({keyList:i})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}}))}_deleteGroupAttributes(e,t){return _e(this,void 0,void 0,(function*(){const{serverMainSequence:o,avChatRoomKey:r,values:i}=Ie.getGroupAttributesCache(e),n=[],s=[];t.forEach((e=>{if(i.has(e)){const{sequence:t=0}=i.get(e)||{};s.push({key:e,seq:t}),n.push(e)}}));const u=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,groupAttributeList:i,avChatRoomKey:n}=e;return Ye("group_open_http_svc.delete_group_attr",{GroupId:o,AttrMainSeq:r,GroupAttr:i,BytesKey:n,AttrControl:["RaceConflict"]},t)}))}({groupID:e,avChatRoomKey:r,groupAttributeList:s,mainSequence:o},this._core),{AttrMainSeq:a}=u||{};return{resultList:n,serverMainSequence:a,groupAttributeList:s,operation:M}}))}_clearGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const{serverMainSequence:t,avChatRoomKey:o,values:r}=Ie.getGroupAttributesCache(e),i=[...r.keys()],n=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,mainSequence:r,avChatRoomKey:i}=e;return Ye("group_open_http_svc.clear_group_attr",{GroupId:o,AttrMainSeq:r,BytesKey:i,AttrControl:["RaceConflict"]},t)}))}({groupID:e,avChatRoomKey:o,mainSequence:t},this._core),{AttrMainSeq:s}=n||{};return{resultList:i,serverMainSequence:s,operation:C}}))}};var Xe=new class{constructor(){this._name="GetGroupAttributes"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getGroupAttributes",context:this})}getGroupAttributes(e){return _e(this,void 0,void 0,(function*(){const t="getGroupAttributes",{groupID:o}=e,{avChatRoomKey:r,lastUpdateTime:i,localMainSequence:n,serverMainSequence:s}=Ie.getGroupAttributesCache(o);if(Date.now()-i>=3e4||n<s)try{yield this.getGroupAttributesFromServer({groupID:o,avChatRoomKey:r});const i=Ie.getGroupAttributesCacheValues(e);return console.log(`${this._name}.${t} from server. groupID:${o}`),Ge({groupAttributes:i})}catch(e){const o=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,o),o}const u=Ie.getGroupAttributesCacheValues(e);return console.log(`${this._name}.${t} from cache. groupID:${o}`),Ge({groupAttributes:u})}))}getGroupAttributesFromServer(e){return _e(this,void 0,void 0,(function*(){const{utils:{isUndefined:t}}=this._core,{groupID:o,avChatRoomKey:r}=e,i=t(r)?L:D,n=yield function(e,t){return _e(this,void 0,void 0,(function*(){const{groupID:o,groupType:r,avChatRoomKey:i}=e;return Ye("group_open_attr_http_svc.get_group_attr",{GroupId:o,GroupType:r,Key:i},t)}))}({groupID:o,avChatRoomKey:r,groupType:i},this._core),{AttrMainSeq:s,GroupAttrAry:u}=n||{};if(console.log(`${this._name}._getGroupAttributesFromServer ok. groupID:${o} serverMainSequence:${s}`),!t(s)){const e=u.map((e=>{const{key:t,value:o,seq:r}=e;return{key:t,value:o,sequence:r}}));Ie.refreshGroupAttributesCache({groupID:o,serverMainSequence:s,groupAttributeList:e,operation:A})}}))}};var Ze=new class{init(e){console.log("GroupAttribute.init"),We.init(e),Qe.init(e),ze.init(e),Xe.init(e),Ie.init(e)}isGroupAttributesUpdated(e){return Ie.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){const{to:t,elements:{newGroupProfile:o}}=e,{groupAttributeOption:r}=o,{serverMainSequence:i,withChangedAttributeInfo:n}=r,{localMainSequence:s}=Ie.getGroupAttributesCache(t),u=i-s;if(console.log(`GroupAttribute.handleGroupAttributesUpdated groupID:${t} withChangedAttributeInfo:${n} diffSequence:${u}`),0!==u)if(Ie.saveGroupAttributesCacheValuesCopy(t),1!==n||1!==u){if(Ie.hasGroupAttributesCache(t)){const{avChatRoomKey:e}=Ie.getGroupAttributesCache(t);Xe.getGroupAttributesFromServer({groupID:t,avChatRoomKey:e}).then((()=>{Ie.emitGroupAttributesUpdated(t)})).catch((()=>{}))}}else Ie.handleGroupAttributesUpdated({groupID:t,groupAttributeOption:r})}};function et(e,t="tips"){const{ClientSeq:o,From_Account:r,MsgClientTime:i,MsgPriority:n,MsgRandom:s,MsgSeq:u,MsgTimeStamp:a,TinyId:c,ToGroupId:p,GroupInfo:l,MsgBody:h}=e,m=function(e){const{GroupCode:t,GroupId:o,GroupName:r,GroupType:i,MsgFrom_AccountExtraInfo:n,From_Account:s,To_Account:u}=e;return{groupCode:t,groupID:o,groupName:r,type:i,messageFromAccountExtraInformation:n,from:s,to:u}}(l);return{clientSequence:o,from:r,clientTime:i,priority:n,random:s,sequence:u,time:a,tinyID:c,to:p,groupProfile:m,elements:"tips"===t?tt(h):function(e){const t={};return Object.keys(e).forEach((o=>{switch(o){case"MsgKey":t.messageKey=e[o];break;case"Operator_Account":t.operatorID=e[o];break;case"ReportType":t.operationType=e[o];break;case"Authentication":t.authentication=e[o];break;case"MsgFlag":t.messageRemindType=e[o];break;case"UserDefinedField":t.userDefinedField=e[o];break;case"RemarkInfo":t.remarkInfo=e[o];break;case"BanDuration":t.duration=e[o]}})),t}(h)}}function tt(e){const t={};return Object.keys(e).forEach((o=>{switch(o){case"MemberNum":t.memberCount=e[o];break;case"OpType":t.operationType=e[o];break;case"Operator_Account":t.operatorID=e[o];break;case"List_Account":t.userIDList=e[o];break;case"MsgMemberExtraInfo":t.memberInfoList=e[o].map((e=>ot(e)));break;case"MsgOperatorMemberExtraInfo":t.operatorInfo=ot(e[o]);break;case"MsgGroupNewInfo":t.newGroupProfile=function(e){const t={};return Object.keys(e).forEach((o=>{switch(o){case"GroupIntroduction":t.introduction=e[o];break;case"GroupName":t.groupName=e[o];break;case"GroupFaceUrl":t.avatar=e[o];break;case"GroupNotification":t.notification=e[o];break;case"ApplyJoinOption":t.joinOption=e[o];break;case"InviteJoinOption":t.inviteOption=e[o];break;case"ShutupAll":t.muteAllMembers=e[o];break;case"Owner_Account":t.ownerID=e[o];break;case"GroupAttrOption":t.groupAttributeOption=function(e){const{BytesChangedKeys:t,GroupAttrSeq:o,OpType:r,PushChangedAttrValFlag:i,GroupAttrInfo:n}=e,s=n.map((e=>{const{Key:t,Val:o,SubKeySeq:r}=e;return{key:t,value:o,sequence:r}}));return{changedKeyList:t,groupAttributeList:s,serverMainSequence:o,operation:r,withChangedAttributeInfo:i}}(e[o])}})),t}(e[o]);break;case"MsgMemberInfo":t.msgMemberInfo=e[o].map((e=>function(e){const{ShutupTime:t,User_Account:o}=e;return{muteTime:t,userID:o}}(e)));break;case"OnlineMemberInfo":t.onlineMemberInfo=function(e){const{ExpireTime:t,OnlineMemberNum:o}=e;return{expireTime:t,onlineMemberNum:o}}(e[o])}})),t}function ot(e){const{ImageUrl:t,NickName:o,Role:r,UserId:i}=e;return{avatar:t,nick:o,role:r,userID:i}}class rt{constructor(t){this.type=e.core.OuterConstant.MSG_GRP_TIP,this.content={},this._initContent(t)}static parseServerPushElement(e){const t=tt(e);return new rt(t)}_initContent(e){Object.keys(e).forEach((t=>{switch(t){case"groupProfile":this._initGroupProfile(e[t]);break;case"operatorInfo":this._initOperatorInfo(e[t]);break;case"memberInfoList":case"msgMemberInfo":this._updateMemberList(e[t]);break;case"newGroupProfile":this._initNewGroupProfile(e[t]);break;case"memberExtraInfo":case"remarkInfo":case"onlineMemberInfo":break;default:this.content[t]=e[t]}})),this.content.userIDList||(this.content.userIDList=[this.content.operatorID])}_initGroupProfile(e){this.content.groupProfile={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];k[r]&&(this.content.groupProfile[r]=e[r])}}_initOperatorInfo(e){this.content.operatorInfo={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];this.content.operatorInfo[r]=e[r]}}_updateMemberList(e){this.content.memberList?this.content.memberList.forEach((t=>{e.forEach((e=>{t.userID===e.userID&&Object.assign(t,e)}))})):this.content.memberList=e}_initNewGroupProfile(e){this.content.newGroupProfile={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];"muteAllMembers"!==r?this.content.newGroupProfile[r]=e[r]:this.content.newGroupProfile.muteAllMembers=1===e.muteAllMembers}}}var it=new class{constructor(){this._name="GroupTipsNotification"}init(e){this._core=e;const{message:{messageFactory:t},OuterConstant:o}=e;null==t||t.registerElementClass(o.MSG_GRP_TIP,rt)}onNewGroupTips(e){console.log(`${this._name}.onNewGroupTips options:${JSON.stringify(e)}`);const{messageList:t}=this._handleGroupTips(e),{notificationCenter:o,OuterEvent:r}=this._core;t.length>0&&(o.emitOuterEvent(r.MESSAGE_RECEIVED,{name:r.MESSAGE_RECEIVED,data:t}),this._handleGroupTipMessage(t))}_handleGroupTips(e){const{Event:t,GroupTips:o}=e,r=new Map,i=[],n=[];for(let e=0,i=o.length;e<i;e++){const i=et(o[e],"tips");if(t===O&&Ze.isGroupAttributesUpdated(i)){Ze.handleGroupAttributesUpdated(i);continue}const{groupProfile:{groupID:s}}=i;if(!de.hasLocalGroup(s))continue;const u=this._assembleMessage(i);if(t===O&&(u._onlineOnlyFlag=!0,n.push(u)),t===S){if(!this._core.message.messageDataHandler.storeConversationMessage(u))continue;n.push(u)}this._handleConversationOptions(r,u)}return i.push(...r.values()),{conversationUpdateFieldList:i,messageList:n}}_assembleMessage(e){const{OuterConstant:t,message:{messageFactory:o}}=this._core;e.flow="in",e.conversationType=t.CONV_GROUP;const r=o.createMessage(e);this._patchNickAndAvatar(e.elements,r);const i=new rt(Object.assign(Object.assign({},e.elements),{groupProfile:Object.assign({},e.groupProfile)}));return r.setElement(i),r.isSystemMessage=!1,r}_patchNickAndAvatar(e,t){const{utils:{isEmpty:o}}=this._core,{operationType:r,memberInfoList:i,operatorInfo:n}=e;let s={};if(o(i)?o(n)||(s=n):r!==w&&r!==$&&r!==N&&r!==E||(s=Object.assign({},i[0])),!o(s)){const{nick:e="",avatar:o=""}=s;t.nick=e,t.avatar=o}}_handleConversationOptions(e,t){const{conversationID:o,conversationType:r}=t;let i;if(e.has(o))i=e.get(o),"in"===t.flow&&(t._isExcludedFromUnreadCount||t._onlineOnlyFlag||i.unreadCount++),i.type=r,i.lastMessage=t._isExcludedFromLastMessage?"":t;else{let e=0;"in"===t.flow&&(t._isExcludedFromUnreadCount||t._onlineOnlyFlag||(e=1)),i={conversationID:o,unreadCount:e,type:r,lastMessage:t._isExcludedFromLastMessage?"":t}}e.set(o,i)}_handleGroupTipMessage(e){e.forEach((e=>{const{operationType:t}=e.payload;switch(t){case w:this._handleNewMemberJoined(e);break;case T:this._handleMemberQuitted(e);break;case $:this._handleMemberKicked(e);break;case P:this._handleGroupProfileUpdated(e)}}))}_handleNewMemberJoined(e){this._handleGroupMemberCountUpdated(e)}_handleMemberQuitted(e){this._handleGroupMemberCountUpdated(e)}_handleMemberKicked(e){this._handleGroupMemberCountUpdated(e)}_handleGroupProfileUpdated(e){var t;const{newGroupProfile:o,groupProfile:r,operatorInfo:i}=e.payload,{groupID:n}=r,s=de.getLocalGroup(n);Object.keys(o).forEach((e=>{switch(e){case"ownerID":this._handleGroupOwnerChanged(n,o);break;case"groupName":s.name=o[e];break;default:s[e]=o[e]}}));const{utils:{isUndefined:u}}=this._core;u(i)||(null===(t=null==s?void 0:s.selfInfo)||void 0===t?void 0:t.userID)!==i.userID||Object.keys(i).forEach((e=>{"nameCard"===e&&s.updateSelfInfo({nameCard:i[e]}),"role"===e&&this._updateSelfRole(s,i[e])})),de.emitGroupListUpdate(),de.updateConversationGroupProfile(n)}_handleGroupOwnerChanged(e,t){const{common:o,OuterConstant:r}=this._core,i=de.getLocalGroup(e),n=o.getCurrentUserID(),{ownerID:s}=t;n===s&&i.updateGroup({ownerID:s,selfInfo:{role:r.GRP_MBR_ROLE_OWNER}})}_updateSelfRole(e,t){const{OuterConstant:o}=this._core;let r=o.GRP_MBR_ROLE_MEMBER;t===R?r=o.GRP_MBR_ROLE_OWNER:t===U&&(r=o.GRP_MBR_ROLE_ADMIN),e.updateSelfInfo({role:r})}_handleGroupMemberCountUpdated(e){const{memberCount:t,groupProfile:{groupID:o}}=e.payload,r=de.getLocalGroup(o),{utils:{isNumber:i}}=this._core;r&&i(t)&&r.memberCount!==t&&(r.memberCount=t,de.emitGroupListUpdate(),de.updateConversationGroupProfile(o))}};class nt{constructor(t){this.type=e.core.OuterConstant.MSG_GRP_SYS_NOTICE,this.content={},this._initContent(t)}_initContent(e){Object.keys(e).forEach((t=>{switch(t){case"remarkInfo":this.content.handleMessage=e[t];break;case"groupProfile":this._initGroupProfile(e[t]);break;case"memberInfoList":break;default:this.content[t]=e[t]}}))}_initGroupProfile(e){this.content.groupProfile={};const t=Object.keys(e);for(let o=0;o<t.length;o++){const r=t[o];q[r]&&(this.content.groupProfile[r]=e[r])}}}var st=new class{constructor(){this._name="GroupSystemNotification"}init(e){this._core=e;const{message:{messageFactory:t},OuterConstant:{MSG_GRP_SYS_NOTICE:o}}=e;null==t||t.registerElementClass(o,nt)}onNewGroupSystemNotification(e){const{GroupTips:t=[],isInstantMessage:o=!0}=e;console.log(`${this._name}.onNewGroupSystemNotification count:${t.length} isInstantMessage:${o}`);const{conversationUpdateFieldList:r,messageList:i}=this._handleGroupSystemNotification(t,o),{notificationCenter:n,OuterEvent:s}=this._core;r.length>0&&this._handleGroupSysTemMessage(o,i),!0===o&&i.length>0&&n.emitOuterEvent(s.MESSAGE_RECEIVED,{name:s.MESSAGE_RECEIVED,data:i})}_handleGroupSystemNotification(e,t){const o=[];let r={};for(let i=0;i<e.length;i++){const n=et(e[i],"system"),{elements:{operationType:s}}=n;if(s===J)continue;const u=this._assembleMessage(n);this._core.message.messageDataHandler.storeConversationMessage(u)&&(o.push(u),r=this._handleConversationOptions(u,t))}return r.lastMessage=o[o.length-1],{conversationUpdateFieldList:o.length>0?[r]:[],messageList:o}}_assembleMessage(e){const{message:{messageFactory:t},OuterConstant:o,utils:{randomInt:r}}=this._core;e.flow="in",e.conversationType=o.CONV_SYSTEM,e.conversationSubType=e.groupProfile.type,e.conversationID=o.CONV_SYSTEM;const i=t.createMessage(e),n=new nt(Object.assign(Object.assign({},e.elements),{groupProfile:Object.assign({},e.groupProfile)}));i.setElement(n),i.isSystemMessage=!0;const s=1===i.sequence&&1===i.random,u=2===i.sequence&&2===i.random;return(s||u)&&(i.sequence=r(),i.random=r(),i.generateMessageID()),i}_handleConversationOptions(e,t){const{OuterConstant:o}=this._core,r={conversationID:o.CONV_SYSTEM,unreadCount:0,type:o.CONV_SYSTEM,subType:e.conversationSubType,lastMessage:null};return t&&r.unreadCount++,r}_handleGroupSysTemMessage(e,t){e&&t.forEach((e=>{const{operationType:t}=e.payload;switch(t){case F:this._handleGroupJoinResult(e);break;case j:this._handleMemberKicked(e);break;case x:this._handleGroupDismissed(e);break;case K:this._handleGroupInvitedResult(e);break;case V:this._handleGroupQuitResult(e);break;case B:this._handleMessageRemindTypeSynced(e);break;case H:this._handleAVChatRoomMemberBanned(e)}}))}_handleGroupJoinResult(e){const{groupProfile:t}=e.payload,{groupID:o,type:r}=t,i=de.hasLocalGroup(o);console.log(`${this._name}._handleGroupJoinResult groupID:${o} type:${r} hasLocalGroup:${i}`),i||ae(r)||(de.updateLocalGroup([Object.assign({},t)]),de.emitGroupListUpdate())}_handleMemberKicked(e){const{groupProfile:{groupID:t,type:o}}=e.payload;de.hasLocalGroup(t)&&this._deleteLocalGroup(t,o),this._updateConversationProfile(t,{unreadCount:0})}_handleGroupDismissed(e){const{groupProfile:{groupID:t,type:o}}=e.payload;de.hasLocalGroup(t)&&this._deleteLocalGroup(t,o),this._updateConversationProfile(t,{unreadCount:0})}_handleGroupInvitedResult(e){const{groupProfile:t}=e.payload,{groupID:o}=t,r=de.hasLocalGroup(o);console.log(`${this._name}._handleGroupInvitedResult groupID:${o} hasLocalGroup:${r}`),r||(de.updateLocalGroup([Object.assign({},t)]),de.emitGroupListUpdate())}_handleGroupQuitResult(e){const{groupProfile:{groupID:t,type:o}}=e.payload,r=de.hasLocalGroup(t);console.log(`${this._name}._handleGroupQuitResult groupID:${t} type:${o} hasLocalGroup:${r}`),r&&this._deleteLocalGroup(t,o),this._updateConversationProfile(t,{unreadCount:0})}_handleMessageRemindTypeSynced(e){const{groupProfile:{groupID:t},messageRemindType:o}=e.payload;this._updateConversationProfile(t,{messageRemindType:o})}_handleAVChatRoomMemberBanned(e){const{groupProfile:{groupID:t,type:o}}=e.payload;this._deleteLocalGroup(t,o)}_deleteLocalGroup(e,t){if(ae(t)){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:o}}=this._core;t.deleteConversation(`${o}${e}`)}de.deleteLocalGroup(e),de.emitGroupListUpdate()}_updateConversationProfile(e,t){const{appStore:{conversationStore:o},OuterConstant:{CONV_GROUP:r}}=this._core,i=`${r}${e}`;o.getConversation(i)&&o.updateConversation(i,t)}};var ut=new class{init(e){this._core=e,console.log("GroupNotificationHandler.init"),it.init(e),st.init(e);const{notificationCenter:t,InnerEvent:o}=e,{InnerEventSubType:r}=t;t.subscribeInnerEvent(o.MESSAGE_PUSH,r.GROUP_TIPS_NOTIFICATION,this._onNewGroupTipsNotification,this),t.subscribeInnerEvent(o.MESSAGE_PUSH,r.GROUP_SYSTEM_NOTIFICATION,this._onNewGroupSystemNotification,this),t.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onNewGroupTipsNotification(e){it.onNewGroupTips(e)}_onNewGroupSystemNotification(e){st.onNewGroupSystemNotification(e)}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:o}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,o.GROUP_TIPS_NOTIFICATION,this._onNewGroupTipsNotification,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,o.GROUP_SYSTEM_NOTIFICATION,this._onNewGroupSystemNotification,this)}};const at={required:!0,rules:["string"],allowEmpty:!1},ct={required:!0,rules:["number"],allowEmpty:!1},pt={required:!0,rules:["array"],allowEmpty:!1},lt={required:!0,rules:["object"],allowEmpty:!1},ht={createGroup:{name:at,type:at},dismissGroup:[Object.assign({key:"groupID"},at)],joinGroup:{groupID:at,applyMessage:{required:!1,rules:["string"],allowEmpty:!0}},quitGroup:[Object.assign({key:"groupID"},at)],searchGroupByID:[Object.assign({key:"groupID"},at)],getGroupProfile:{groupID:at,groupCustomFieldFilter:{required:!1,rules:["array"],allowEmpty:!0}},updateGroupProfile:{groupID:at,muteAllMembers:{required:!1,rules:["boolean"],allowEmpty:!1}},changeGroupOwner:{groupID:at,newOwnerID:at},getGroupOnlineMemberCount:[Object.assign({key:"groupID"},at)],handleGroupApplication:{handleAction:at},getGroupMemberList:{groupID:at},getGroupMemberProfile:{groupID:at,userIDList:pt,memberCustomFieldFilter:{required:!1,rules:["array"],allowEmpty:!0}},addGroupMember:{groupID:at,userIDList:pt},deleteGroupMember:{groupID:at,userIDList:pt},setGroupMemberMuteTime:{groupID:at,userID:at,muteTime:Object.assign(Object.assign({},ct),{customValidator:e=>!(e<0)||"muteTime must be a non-negative number."})},setGroupMemberRole:{groupID:at,userID:at,role:at},setGroupMemberNameCard:{groupID:at,userID:{required:!1,rules:["string"],allowEmpty:!1},nameCard:at},setGroupMemberCustomField:{groupID:at,userID:{required:!1,rules:["string"],allowEmpty:!1},memberCustomField:pt},markGroupMemberList:{groupID:at,markType:Object.assign(Object.assign({},ct),{customValidator:e=>!(e<1e3)||"markType must be greater than or equal to 1000."}),enableMark:{required:!0,rules:["boolean"],allowEmpty:!1},userIDList:pt},initGroupAttributes:{groupID:at,groupAttributes:lt},setGroupAttributes:{groupID:at,groupAttributes:lt},deleteGroupAttributes:{groupID:at,keyList:Object.assign(Object.assign({},pt),{allowEmpty:!0})},getGroupAttributes:{groupID:at,keyList:Object.assign(Object.assign({},pt),{allowEmpty:!0})}},mt={getGroupList:!0,createGroup:!0,dismissGroup:!0,joinGroup:!0,quitGroup:!0,searchGroupByID:!0,getGroupProfile:!0,updateGroupProfile:!0,changeGroupOwner:!0,getGroupOnlineMemberCount:!0,getGroupApplicationList:!0,handleGroupApplication:!0,getGroupMemberList:!0,getGroupMemberProfile:!0,addGroupMember:!0,deleteGroupMember:!0,setGroupMemberMuteTime:!0,setGroupMemberRole:!0,setGroupMemberNameCard:!0,setGroupMemberCustomField:!0,markGroupMemberList:!0,initGroupAttributes:!0,setGroupAttributes:!0,getGroupAttributes:!0,deleteGroupAttributes:!0};return new class{constructor(){this._installedSubPlugins=[],this.groupDataHandler=de,this.groupAction=we,this.groupAttribute=Ze,this.groupMember=Be}install(t,o=[]){this._core=t,e.init(t),de.init(t),we.init(t,this),Be.init(t,this),Ee.init(t),He.init(t),Ze.init(t),ut.init(t),t.helper.registerValidateConfig({auth:mt,params:ht}),this._installSubPlugins(o);const{notificationCenter:r,InnerEvent:i}=t;r.subscribeInnerEvent(i.LOGOUT,this._reset,this),r.subscribeInnerEvent(i.DESTROY,this._dispose,this)}getInstalledSubPlugins(){return this._installedSubPlugins}_installSubPlugins(e){const{utils:{isArray:t}}=this._core;e&&t(e)&&e.forEach((e=>{var t;null===(t=e.install)||void 0===t||t.call(e,this._core,this),this._installedSubPlugins.push(e.name)}))}_reset(){de.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}}}));
@@ -1 +1 @@
1
- const e={deleteMessage:[{required:!0,rules:["array"],allowEmpty:!1}],revokeMessage:[{required:!0,rules:["object"],allowEmpty:!1}],resendMessage:[{key:"message",required:!0,rules:["object"],allowEmpty:!1},{key:"options",required:!1,rules:["object"],allowEmpty:!1}],getMessageList:{conversationID:{required:!0,rules:["string"],allowEmpty:!1},nextReqMessageID:{required:!1,rules:["string"],allowEmpty:!0},count:{required:!1,rules:["number"],allowEmpty:!0}},getMessageListHopping:{conversationID:{required:!0,rules:["string"],allowEmpty:!1},sequence:{required:!1,rules:["number"],allowEmpty:!0},direction:{required:!1,rules:["number"],allowEmpty:!0},count:{required:!1,rules:["number"],allowEmpty:!0}}},s={deleteMessage:!0,revokeMessage:!0,resendMessage:!0,getMessageList:!0,getMessageListHopping:!0,createTextMessage:!0};function t(e,s,t,n){return new(t||(t=Promise))((function(o,r){function i(e){try{c(n.next(e))}catch(e){r(e)}}function a(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var s;e.done?o(e.value):(s=e.value,s instanceof t?s:new t((function(e){e(s)}))).then(i,a)}c((n=n.apply(e,s||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n{constructor(e){this._core=e}deleteMessage(e){return t(this,void 0,void 0,(function*(){const{to:s,messageIdentifiers:t}=e,n="openim.delete_c2c_msg_ramble",o={From_Account:this._getCurrentUserId(),To_Account:s,MsgKeyList:t},r=this._core.helper.generateProtocolData({servcmd:n,data:o}),i=`${r.head.seq}${n}`;return this._core.channel.sendPacket(r,{requestId:i})}))}revokeMessage(e){return t(this,void 0,void 0,(function*(){const{to:s,from:t,sequence:n,time:o,random:r}=e,i="openim.msgwithdraw",a={MsgInfo:{From_Account:t,To_Account:s,MsgSeq:n,MsgRandom:r,MsgTimeStamp:o}},c=this._core.helper.generateProtocolData({servcmd:i,data:a}),g=`${c.head.seq}${i}`;return this._core.channel.sendPacket(c,{requestId:g})}))}_getCurrentUserId(){var e,s;return null===(s=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===s?void 0:s.userId}}class o{constructor(e){this._core=e}deleteMessage(e){return t(this,void 0,void 0,(function*(){const{to:s,messageIdentifiers:t}=e,n="group_open_http_svc.delete_group_ramble_msg_by_seq",o={GroupId:s,Deleter_Account:this._getCurrentUserId(),Seqs:t},r=this._core.helper.generateProtocolData({servcmd:n,data:o}),i=`${r.head.seq}${n}`;return this._core.channel.sendPacket(r,{requestId:i})}))}revokeMessage(e){return t(this,void 0,void 0,(function*(){const{to:s,sequence:t}=e,n="group_open_http_svc.group_msg_recall",o={GroupId:s,MsgSeqList:[{MsgSeq:t}]},r=this._core.helper.generateProtocolData({servcmd:n,data:o}),i=`${r.head.seq}${n}`;return this._core.channel.sendPacket(r,{requestId:i})}))}_getCurrentUserId(){var e,s;return null===(s=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===s?void 0:s.userId}}const r=2116,i="C2C",a="GROUP",c=20,g=1,l=300;var u,d,h;!function(e){e.MSG_TEXT="TIMTextElem",e.MSG_CUSTOM="TIMCustomElem",e.MSG_LOCATION="TIMLocationElem",e.MSG_FACE="TIMFaceElem"}(u||(u={})),function(e){e[e.DATA_HAS_EXPIRED=0]="DATA_HAS_EXPIRED",e[e.HAS_MORE_DATA=1]="HAS_MORE_DATA",e[e.NO_MORE_DATA=2]="NO_MORE_DATA"}(d||(d={})),function(e){e[e.FORWARD=0]="FORWARD",e[e.BACKWARD=1]="BACKWARD"}(h||(h={}));class v{constructor(e){this._core=e}generateRevokeMessage(e){const{conversationID:s,sequence:t,random:n,tinyID:o,clientTime:r,revokeReason:i,revoker:a}=e;let c={};const{messageStore:g}=this._core.message;return c=g.revokeMessage({conversationID:s,sequence:t,random:n}),c||(c={conversationID:s,sequence:t},o&&r&&n&&(c.ID=`${o}-${r}-${n}`)),c=Object.assign(Object.assign({},c),{revoker:a,revokeReason:i,revokerInfo:{userID:a,nick:"",avatar:""}}),c}updateRevokerInfo(e){return t(this,void 0,void 0,(function*(){const s=e.map((e=>e.revoker));try{const t=yield this._fetchUserInfos(s);t&&e.forEach((e=>{const{revoker:s}=e;t[s]&&(e.revokerInfo.nick=t[s].nick||"",e.revokerInfo.avatar=t[s].avatar||"",e.revokerInfo.userID=s)}))}catch(e){console.debug(e)}}))}filterValidMessages(e){return e.filter((e=>{const s=!this._core.helper.isEmpty(null==e?void 0:e.getElements()),t=1===(null==e?void 0:e.isPlaceMessage);if(!s){this._core.ssoLog.createSSOLogData({method:"emptyMessageBody"}).setLogInfo({message:`from:${e.from} to:${e.to} sequence:${e.sequence}`}).end()}return s&&!t}))}_fetchUserInfos(e){return t(this,void 0,void 0,(function*(){var s,t;const n=yield null===(s=this._core.user.userProfile)||void 0===s?void 0:s.getUserProfile({userIDList:e});return(null==n?void 0:n.data)?null===(t=n.data)||void 0===t?void 0:t.reduce(((e,{userID:s,nick:t,avatar:n})=>(e[s]={nick:t||"",avatar:n||""},e)),{}):null}))}}var M=new class{constructor(){this._core=null,this._c2cMessageAction=null,this._groupMessageAction=null}install(e){this._core=e,this._groupMessageAction=new o(e),this._c2cMessageAction=new n(e),this._messageHelper=new v(e);const{notificationCenter:s,helper:t,InnerEvent:r}=e;s.subscribeInnerEvent(r.DESTROY,this._dispose,this),t.registerApi("deleteMessage",this),t.registerApi("revokeMessage",this),t.registerApi("resendMessage",this)}deleteMessage(e){return t(this,void 0,void 0,(function*(){let s=[],t=[];const{conversationID:n,conversationType:o}=e[0],i=n.replace(o,"");if("@TIM#SYSTEM"===o)throw new this._core.helper.ChatError({code:r});if(e.forEach((e=>{const{conversationID:r,conversationType:i,status:a,_onlineOnlyFlag:c,sequence:g,random:l,time:u}=e||{};if("success"===a&&r===n&&i===o){if(!c){const e="C2C"===i?`${g}_${l}_${u}`:String(g);s.push(e)}t.push(e)}})),0===s.length)return this._handleDeleteMessageSuccess(t),{code:0,data:{messageList:t}};s.length>30&&(s=s.slice(0,30),t=t.slice(0,30));try{return"C2C"===o?yield this._c2cMessageAction.deleteMessage({to:i,messageIdentifiers:s}):yield this._groupMessageAction.deleteMessage({to:i,messageIdentifiers:s}),this._handleDeleteMessageSuccess(t),{code:0,data:{messageList:t}}}catch(e){const{errorCode:s}=e;throw new this._core.helper.ChatError({functionName:"deleteMessage",code:s})}}))}revokeMessage(e){return t(this,void 0,void 0,(function*(){var s;const t=this._core.ssoLog.createSSOLogData({method:"revokeMessage"}),{conversationType:n,isRevoked:o}=e;let r=null;if("@TIM#SYSTEM"===n)throw new this._core.helper.ChatError({message:"system message cannot be revoked"});if(o)throw new this._core.helper.ChatError({message:"message has been revoked"});t.setLogInfo({message:`type:${e.type} from:${e.from} to:${e.to}`});try{if(r="C2C"===n?yield this._c2cMessageAction.revokeMessage(e):yield this._groupMessageAction.revokeMessage(e),r){const{RecallRetList:n}=r,o=(null===(s=null==n?void 0:n[0])||void 0===s?void 0:s.RetCode)||0;if(0!==o)throw new this._core.helper.ChatError({code:o});return t.end(),yield this._handleRevokeMessageSuccess(e),{code:0,data:{message:e}}}}catch(e){const{errorCode:s}=e,t=new this._core.helper.ChatError({functionName:"revokeMessage",code:s});throw this._core.ssoLog.getSSOLogData("revokeMessage").setError(t).end(),t}}))}resendMessage(e,s){return t(this,void 0,void 0,(function*(){var t,n;return e.isResend=!0,e.status="unSend",null===(n=null===(t=this._core)||void 0===t?void 0:t.apiMap)||void 0===n?void 0:n.sendMessage(e,s)}))}_handleDeleteMessageSuccess(e){0!==e.length&&(e.forEach((e=>{e.isDeleted=!0;const s=this._core.message.messageStore.getLocalMessageList(e.conversationID);null==s||s.forEach((s=>{s.ID===e.ID&&(s.isDeleted=!0)}))})),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.MESSAGE_DELETED,e[0].conversationID))}_handleRevokeMessageSuccess(e){return t(this,void 0,void 0,(function*(){var s;e.isRevoked=!0,e.revoker=null===(s=this._core.store.get("login"))||void 0===s?void 0:s.userId,yield this._messageHelper.updateRevokerInfo([e]),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.MESSAGE_REVOKED,[e])}))}_dispose(){const{notificationCenter:e,InnerEvent:s}=this._core;e.subscribeInnerEvent(s.DESTROY,this._dispose,this)}};class _{static parseServerPushElement(e){const{MsgContent:s={Text:""}}=e,{Text:t}=s;return new _({text:t})}constructor(e){this.type="TIMTextElem",this.content={text:e.text||""}}validateBeforeSend(){var e,s;return(null===(s=null===(e=this.content)||void 0===e?void 0:e.text)||void 0===s?void 0:s.length)>0?{isValid:!0}:{isValid:!1,error:{message:"content can not be empty"}}}convertToBackendFormat(){const{text:e}=this.content;return{MsgType:this.type,MsgContent:{Text:e}}}}var p=new class{install(e){this._core=e,e.message.messageFactory.registerElementClass(u.MSG_TEXT,_),e.helper.registerApi("createTextMessage",this)}createTextMessage(e){var s,t;if(!e)return null;const n="string"==typeof e.payload?e.payload:(null===(s=null==e?void 0:e.payload)||void 0===s?void 0:s.text)||"",o=new _({text:n}),r=null===(t=this._core.store.get("login"))||void 0===t?void 0:t.userId,i=this._core.message.messageFactory.createMessage(Object.assign(Object.assign({},e),{from:r}));return i.setElement(o),i}};class m{install(e){this._messageHelper=new v(e),this._core=e;const{notificationCenter:s,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n},InnerEventSubType:{C2C_NOTIFY_MESSAGE:o}}=e;s.subscribeInnerEvent(t,o,this._handleC2CNotifyMessage,this),s.subscribeInnerEvent(n,this._dispose,this)}_handleC2CNotifyMessage(e){const{C2cNotifyMsgArray:s}=e;null==s||s.forEach((e=>{Object.keys(e).includes("WithdrawC2cMsgNotify")&&this._handleC2CRevokeMessage(e)}))}_handleC2CRevokeMessage(e){return t(this,void 0,void 0,(function*(){try{const{WithdrawC2cMsgNotify:{C2cWithdrawInfoArray:s}}=e,t=[],{notificationCenter:n,OuterEvent:o,InnerEvent:r}=this._core;s.forEach((e=>{const{MsgRand:s,MsgSeq:n,To_Account:o,From_Account:r,RevokerInfo:{Revoker_Account:i,Reason:a}}=e,c=this._getCurrentUserId()===r?`C2C${o}`:`C2C${r}`,g=this._messageHelper.generateRevokeMessage({conversationID:c,sequence:n,random:s,revoker:i,revokeReason:a});t.push(g)})),0!==t.length&&n.emitInnerEvent(r.MESSAGE_REVOKED,{revokedMessages:t,updateUnreadCount:!0}),yield this._messageHelper.updateRevokerInfo(t),n.emitOuterEvent(o.MESSAGE_REVOKED,{name:o.MESSAGE_REVOKED,data:t})}catch(e){console.debug(e)}}))}_getCurrentUserId(){var e,s;return null===(s=null===(e=this._core)||void 0===e?void 0:e.store.get("login"))||void 0===s?void 0:s.userId}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:s,DESTROY:t},InnerEventSubType:{C2C_NOTIFY_MESSAGE:n}}=this._core;e.unSubscribeInnerEvent(s,n,this._handleC2CNotifyMessage,this),e.unSubscribeInnerEvent(t,this._dispose,this)}}class E{install(e){this._messageHelper=new v(e),this._core=e;const{notificationCenter:s,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n},InnerEventSubType:{GROUP_NOTIFY_MESSAGE:o}}=e;s.subscribeInnerEvent(t,o,this._handleGroupNotifyMessage,this),s.subscribeInnerEvent(n,this._dispose,this)}_handleGroupNotifyMessage(e){const{GroupTips:s}=e;null==s||s.forEach((e=>{var s;Array.isArray(null===(s=null==e?void 0:e.MsgBody)||void 0===s?void 0:s.GroupWithdrawInfoArray)&&this._handleGroupRevokeMessage(e)}))}_handleGroupRevokeMessage(e){return t(this,void 0,void 0,(function*(){try{const{RevokerInfo:s,MsgBody:{GroupWithdrawInfoArray:t}}=e,n=[],{notificationCenter:o,OuterEvent:r,InnerEvent:i}=this._core;t.forEach((e=>{const{Random:t,MsgSeq:o,GroupId:r,MsgClientTime:i,TinyId:a,TopicId:c,RevokerInfo:{Revoker_Account:g=(null==s?void 0:s.Revoker_Account)||"",Reason:l=(null==s?void 0:s.Reason)||""}}=e,u=c?`GROUP${c}`:`GROUP${r}`,d=this._messageHelper.generateRevokeMessage({conversationID:u,sequence:o,random:t,tinyID:a,clientTime:i,revoker:g,revokeReason:l});n.push(d)})),0!==n.length&&(o.emitInnerEvent(i.MESSAGE_REVOKED,{revokedMessages:n,updateUnreadCount:!0}),yield this._messageHelper.updateRevokerInfo(n),o.emitOuterEvent(r.MESSAGE_REVOKED,{name:r.MESSAGE_REVOKED,data:n}))}catch(e){console.debug(e)}}))}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:s,DESTROY:t},InnerEventSubType:{GROUP_NOTIFY_MESSAGE:n}}=this._core;e.unSubscribeInnerEvent(s,n,this._handleGroupNotifyMessage,this),e.unSubscribeInnerEvent(t,this._dispose,this)}}var I=new class{constructor(){this._c2cMessageReceiver=new m,this._groupMessageReceiver=new E}install(e){this._c2cMessageReceiver.install(e),this._groupMessageReceiver.install(e)}};class S{constructor(e){this._lastMessageSequenceMapOnDisconnect=new Map,this._core=e,this._messageHelper=new v(e)}getRoamingMessagesByAnchor(e){return t(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"getRoamingMessagesByAnchor"}),{conversationID:t,count:n,direction:o,sequence:r}=e,i=t.replace(a,"");let c=r;if(o===h.BACKWARD){if("number"!=typeof r)return{messageList:[],hasNoMoreHistoryMessage:!1,nextReqMessageIDFromServer:""};c=r+n-1}const g={GroupId:i,ReqMsgNumber:n,WithRecalledMsg:1,Version:1};c&&(g.ReqMsgSeq=c);const l="group_open_http_svc.group_msg_get",u=this._core.helper.generateProtocolData({servcmd:l,data:g}),v=`${u.head.seq}${l}`,M=yield this._core.channel.sendPacket(u,{requestId:v});if(M){const{RspMsgList:e,NextReqMsgSeq:t=0,IsFinished:n,InvisibleMsgSeq:a}=M;s.setLogInfo({message:`groupID:${i} sequence:${r} reqSeq:${c} direction:${o}\n complete:${n} nextSequence:${t} remoteMsgCount:${e.length} invisibleSequenceList:${a}`}).end();const g=[];for(let s=0;s<e.length;s++){const t=e[s],n=this._parseMessage(t);g.push(n)}g.reverse();return{messageList:g,invisibleSequenceList:a,nextReqMessageIDFromServer:t,hasNoMoreHistoryMessage:[d.NO_MORE_DATA,d.DATA_HAS_EXPIRED].includes(n)}}}catch(e){const s=new this._core.helper.ChatError({code:null==e?void 0:e.code});this._core.ssoLog.getSSOLogData("getRoamingMessagesByAnchor").setError(s).end()}}))}recoverHistoryMessage(e){return t(this,void 0,void 0,(function*(){const{message:{messageReceiver:s,messageStore:n},notificationCenter:o,OuterEvent:r}=this._core;null==e||e.forEach((e=>t(this,void 0,void 0,(function*(){const{conversationID:t,lastMessage:i}=e;let a=this._getLocalLastMessageSequence(t);const c=i.lastSequence;if(this._shouldRecoverHistory({localLastMessageSequence:a,serverLastMessageSequence:c})){const e=c-a;let i=!1;const g=Math.ceil(e/20);for(let e=0;e<g;e++)try{const e=c-a,g=Math.min(20,e),l=yield this.getRoamingMessagesByAnchor({conversationID:t,sequence:a+g,direction:h.FORWARD,count:g}),{nextReqMessageIDFromServer:u,hasNoMoreHistoryMessage:d,messageList:v}=l;i=d&&u<0,a=v[v.length-1].sequence;const M=[];if(Array.isArray(v)&&(v.forEach((e=>{s.groupMessageReceiver.updateMessageProfile(e);n.storeConversationMessage(e)&&M.push(e)})),M.length>0&&o.emitOuterEvent(r.MESSAGE_RECEIVED,{name:r.MESSAGE_RECEIVED,data:M})),i)break}catch(e){console.debug(e);break}}}))))}))}updateLastMessageSequenceMapOnDisconnect(){const e=this._core.message.messageStore.getContinuousMessagesByConversation();for(const[s,t]of e){if(s.startsWith("C2C"))continue;const e=Array.from(t.values());if((null==e?void 0:e.length)>0){const t=e[e.length-1].sequence;this._lastMessageSequenceMapOnDisconnect.set(s,t)}}}_shouldRecoverHistory(e){const{localLastMessageSequence:s,serverLastMessageSequence:t}=e;if("number"!=typeof s||"number"!=typeof t)return!1;const n=t-s;return 0!==t&&s&&(n>=g&&n<l)}_getLocalLastMessageSequence(e){if(this._lastMessageSequenceMapOnDisconnect.has(e))return this._lastMessageSequenceMapOnDisconnect.get(e);const s=this._core.message.messageStore.getLocalMessageList(e),t=s[s.length-1];return null==t?void 0:t.sequence}_parseMessage(e){const s=a,t=this._core.message.messageHelper.parseServerGroupMessage(e),n=this._core.message.messageFactory.createMessage(Object.assign(Object.assign({},t),{conversationType:s,flow:"in"}));return n.setElement(t.elements),n}}var f=new class{constructor(){this._clearedConversations=new Set,this._fetchedCompleteConversations=new Set}install(e){this._core=e,this._groupMessageHistory=new S(e),this._messageHelper=new v(e);const{InnerEvent:s,notificationCenter:t}=e;e.helper.registerApi("getMessageList",this),e.helper.registerApi("getMessageListHopping",this),t.subscribeInnerEvent(s.RECOVER_CONVERSATIONS_COMPLETED,this._recoverHistoryMessage,this),t.subscribeInnerEvent(s.SOCKET_DISCONNECTED,this._handleSocketDisconnected,this),t.subscribeInnerEvent(s.DESTROY,this._dispose,this)}getMessageList(e){return t(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"getMessageList"});let{conversationID:t,nextReqMessageID:n}=e;const o=c;if("@TIM#SYSTEM"===t)return{code:0,data:{messageList:[],isCompleted:!1,nextMessageSeq:""}};const r=this._getAvailableLocalMessagesCount({conversationID:t,nextReqMessageID:n});if(this._needFetchHistoryMessageList({conversationID:t,availableLocalMessagesCount:r,targetCount:o})){let e=null;if(t.startsWith(a)&&(e=yield this._groupMessageHistory.getRoamingMessagesByAnchor({conversationID:t,sequence:Number(n),count:o,direction:h.FORWARD})),e){const{nextReqMessageIDFromServer:o,hasNoMoreHistoryMessage:i,messageList:a}=e,c=this._messageHelper.filterValidMessages(a),g=this._core.message.messageStore.prependLocalMessageList({messageList:c,conversationID:t}),l=this._core.message.messageStore.getLocalMessageList(t).slice(0,g.length+r),u=l.filter((e=>e.isRevoked));yield this._messageHelper.updateRevokerInfo(u);const d={nextReqMessageID:i?"":String(o),messageList:l,isCompleted:i},h=l.map((e=>e.sequence));return s.setLogInfo({message:`conversationID: ${t} nextReqMessageID: ${n} \n availableLocalMessagesCount: ${r} sequenceList: ${JSON.stringify(h)} `}).end(),{code:0,data:d}}return{code:0,data:{messageList:[],isCompleted:!1,nextMessageSeq:""}}}s.setLogInfo({message:`conversationID: ${t} nextReqMessageID: ${n} availableLocalMessagesCount: ${r}}`}).end();return{code:0,data:this._getMessageListFromMemory({conversationID:t,nextReqMessageID:n,count:o})}}catch(e){const s=new this._core.helper.ChatError({code:null==e?void 0:e.code});this._core.ssoLog.getSSOLogData("getMessageList").setError(s).end(),console.debug(s)}}))}getMessageListHopping(e){return t(this,void 0,void 0,(function*(){var s,t;const{conversationID:n,sequence:o,direction:r=h.FORWARD}=e,{isEmpty:i}=this._core.helper;if(![h.BACKWARD,h.FORWARD].includes(r))throw new this._core.helper.ChatError({message:"direction must be 0 or 1"});let{count:g=c}=e;g=g>c?c:g;let l=null;if(n.startsWith(a)&&(l=yield this._groupMessageHistory.getRoamingMessagesByAnchor({conversationID:n,sequence:o,count:g,direction:r})),l){const{nextReqMessageIDFromServer:e,hasNoMoreHistoryMessage:n,messageList:a,invisibleSequenceList:c}=l,g=this._messageHelper.filterValidMessages(a);if(this._core.message.messageStore.storeSparseMessageList(g),r===h.FORWARD){const s=n&&e<1;return{code:0,data:{messageList:g,isCompleted:s,nextMessageSeq:s?"":e}}}if(r===h.BACKWARD){if(i(a)&&i(c))return{code:0,data:{messageList:[],isCompleted:!0,nextMessageSeq:""}};const e=(null===(s=null==a?void 0:a[a.length-1])||void 0===s?void 0:s.sequence)||0,n=(null===(t=null==c?void 0:c[c.length-1])||void 0===t?void 0:t.sequence)||0;return{code:0,data:{messageList:g.filter((e=>e.sequence>=o)),isCompleted:!1,nextMessageSeq:Math.max(e,n)+1}}}return{code:0,data:l}}return{code:0,data:{messageList:[],isCompleted:!1,nextMessageSeq:""}}}))}_getAvailableLocalMessagesCount({conversationID:e,nextReqMessageID:s}){const t=this._core.message.messageStore.getLocalMessageList(e),{length:n}=t;if(!s)return n;let o=-1;return(null==e?void 0:e.startsWith(i))?o=t.findIndex((e=>e.ID===s)):(null==e?void 0:e.startsWith(a))&&(o=t.findIndex((e=>s.includes("-")?e.ID===s:String(e.sequence)===s))),-1===o?0:o}_needFetchHistoryMessageList({conversationID:e,availableLocalMessagesCount:s,targetCount:t}){return!!this._clearedConversations.has(e)||s<=t&&!this._fetchedCompleteConversations.has(e)}_getMessageListFromMemory({conversationID:e,nextReqMessageID:s,count:t}){const n=this._core.message.messageStore.getLocalMessageList(e),o=n.length;let r=o,a={isCompleted:!1,nextReqMessageID:"",messageList:[]},c=0,g=o;return s?s&&(g=n.findIndex((t=>e.startsWith(i)?t.ID===s:String(t.sequence)===s)),c=g>t?g-t:0,r=g):c=o>t?o-t:0,a.nextReqMessageID=0===c?"":this._generateNextReqMessageID({conversationID:e,targetIndex:c}),a.messageList=n.slice(c,g),a.isCompleted=r<=t,a}_generateNextReqMessageID({conversationID:e,targetIndex:s}){const t=this._core.message.messageStore.getLocalMessageList(e);return e.startsWith("C2C")?t[s].ID:String(t[s].sequence)}_recoverHistoryMessage(){const{conversationMap:e}=this._core.store.get("conversation")||{};if(e instanceof Map){const s=[...e.values()].filter((e=>e.type===a));this._groupMessageHistory.recoverHistoryMessage(s)}}_handleSocketDisconnected(){this._groupMessageHistory.updateLastMessageSequenceMapOnDisconnect()}_dispose(){const{notificationCenter:e,InnerEvent:s}=this._core;e.unSubscribeInnerEvent(s.RECOVER_CONVERSATIONS_COMPLETED,this._recoverHistoryMessage,this),e.unSubscribeInnerEvent(s.SOCKET_DISCONNECTED,this._handleSocketDisconnected,this),e.unSubscribeInnerEvent(s.DESTROY,this._dispose,this)}};var R=new class{install(e){this._core=e;const{helper:s}=e;s.registerApi("getMessageReactions",this),s.registerApi("getMessageReadReceiptList",this)}getMessageReadReceiptList(e){return t(this,void 0,void 0,(function*(){return console.log("getMessageReadReceiptList: options: ",e),{code:0,data:{messageList:[]}}}))}getMessageReactions(e){return t(this,void 0,void 0,(function*(){return console.log("getMessageReactions: options: ",e),{code:0,data:[]}}))}};function D(t){M.install(t),p.install(t),I.install(t),f.install(t),R.install(t),t.helper.registerValidateConfig({auth:s,params:e})}export{D as default};
1
+ function e(e,t,s,o){return new(s||(s=Promise))((function(n,r){function i(e){try{c(o.next(e))}catch(e){r(e)}}function a(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(e){this.core=e}};var s,o,n;!function(e){e.MSG_TEXT="TIMTextElem",e.MSG_CUSTOM="TIMCustomElem",e.MSG_LOCATION="TIMLocationElem",e.MSG_FACE="TIMFaceElem"}(s||(s={})),function(e){e[e.DATA_HAS_EXPIRED=0]="DATA_HAS_EXPIRED",e[e.HAS_MORE_DATA=1]="HAS_MORE_DATA",e[e.NO_MORE_DATA=2]="NO_MORE_DATA"}(o||(o={})),function(e){e[e.FORWARD=0]="FORWARD",e[e.BACKWARD=1]="BACKWARD"}(n||(n={}));const r="MSG_REACTION",i=0,a=1,c={ZH_CN:"zh (cmn-Hans-CN)",EN_US:"en-US",YUE_HK:"yue-Hant-HK",JA_JP:"ja-JP",ZH_PY:"zh-PY"},d="16k_zh",u="16k_en",l="16k_yue",g="16k_ja",m="16k_zh-PY",h={[c.ZH_CN]:d,[c.EN_US]:u,[c.YUE_HK]:l,[c.JA_JP]:g,[c.ZH_PY]:m},p=/\.(wav|pcm|ogg-opus|speex|silk|mp3|m4a|aac|amr)/,_={READ:0,UNREAD:1};const v=2116,M="C2C",f="GROUP",y=20,R=1,E=300;function I(s){return e(this,void 0,void 0,(function*(){var o;const{appStore:n}=t.core,{messageList:r,conversationID:i}=s,a=n.conversationStore.getConversationMap();let c=null===(o=a.get(i))||void 0===o?void 0:o.peerReadTime;if(!c){const s=i.replace(M,""),o=yield function(s){return e(this,void 0,void 0,(function*(){const e={To_Account:s};return t.core.common.buildAndSendPacket({servcmd:"openim.get_peer_read_time",data:e})}))}([s]);if(o){const{ReadTime:e}=o;c=null==e?void 0:e[0],a.has(i)&&(a.get(i).peerReadTime=c)}}r.forEach((e=>{e.time<=c&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0)}))}))}function C(s){return e(this,void 0,void 0,(function*(){var e;const{message:o,user:n,appStore:r,constants:{OuterConstant:i}}=t.core,a=r.conversationStore.getConversationMap();if(a.has(s)){const r=null===(e=a.get(s))||void 0===e?void 0:e.userProfile;if(r&&s.startsWith(i.CONV_C2C)){const{avatar:e,nick:o}=r;t.core.message.messageDataHandler.updateNickAndAvatarOfSentMessage({conversationID:s,latestAvatar:e,latestNick:o,isSentByMe:!1})}const{data:c}=(yield n.userProfile.getMyProfile())||{};if(c){const{avatar:e,nick:t}=c;o.messageDataHandler.updateNickAndAvatarOfSentMessage({conversationID:s,latestAvatar:e,latestNick:t,isSentByMe:!0})}}}))}function S(e){let s;const{message:o}=t.core,{conversationID:n,messageID:r}=e;if(s=o.messageDataHandler.getLocalMessageList(n).find((e=>e.ID===r)),!s){s=o.messageDataHandler.getSparseMessageList(n).find((e=>e.ID===r))}return s}function D(e){return e.map((e=>{const{from:t,to:s,cloudCustomData:o,avatar:n,nick:r,ID:i,clientSequence:a,clientTime:c,messageRandom:d,messageSequence:u,time:l}=e;return{ClientSeq:a,CloudCustomData:o,From_Account:t,From_AccountHeadurl:n,From_AccountNick:r,Id:i,MsgBody:JSON.parse(JSON.stringify(e.transformElementsToServerFormat())),MsgClientTime:c,MsgRandom:d,Random:d,MsgSeq:u,MsgTimeStamp:l,ReceiverId:s,SenderId:t,To_Account:s}}))}function A(e){var s;const{From_Account:o,From_AccountHeadurl:n,From_AccountNick:r,GroupId:i,MsgClientTime:a,ClientSeq:c,To_Account:d,MsgTimeStamp:u,TinyId:l,MsgRandom:g,MsgSeq:m}=e;return{from:o,avatar:n,nick:r,clientTime:a,time:u,tinyID:l,random:g,sequence:m,to:d,groupID:i,clientSequence:c,_elements:null===(s=e.MsgBody)||void 0===s?void 0:s.map((e=>{const{MsgType:s}=e;return t.core.message.messageFactory.getElementClass(s).parseServerPushElement(e)}))}}var L=new class{constructor(){this._reactionsMap=new Map}init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{MESSAGE_REACTION_UPDATED:n,MESSAGE_REACTION_UPDATED_SYNC:r}}=e;t.registerApi({apiName:"addMessageReaction",context:this}),t.registerApi({apiName:"removeMessageReaction",context:this}),t.registerApi({apiName:"getMessageReactions",context:this}),t.registerApi({apiName:"getAllUserListOfMessageReaction",context:this}),s.subscribeInnerEvent(o,n,this._handleReactionUpdated,this),s.subscribeInnerEvent(o,r,this._handleReactionSync,this)}addMessageReaction(s,o){return e(this,void 0,void 0,(function*(){const{OuterConstant:n,ssoLog:r,helper:i}=this._core;this._validateMessageReactionBusinessCapability();const a=r.createSSOLogData({method:"addMessageReaction"}),{conversationID:c,ID:d,conversationType:u,from:l,to:g,clientSequence:m,random:h,time:p,sequence:_}=s;try{return this._recordMessageReactedByMe(d,o),u===n.CONV_C2C?yield function(s,o){return e(this,void 0,void 0,(function*(){var e;const{from:n,to:r,clientSequence:i,random:a,time:c,reactionID:d}=s,u={From_Account:n,To_Account:r,MsgKey:`${i}_${a}_${c}`,Reaction:d,Add_Account:[null===(e=o.store.get("login"))||void 0===e?void 0:e.userId]};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.reaction_add",data:u})}))}({from:l,to:g,clientSequence:m,random:h,time:p,reactionID:o},this._core):u===n.CONV_GROUP&&(yield function(s,o){return e(this,void 0,void 0,(function*(){var e;const{to:n,reactionID:r,sequence:i}=s,a={GroupId:n,MsgSeq:i,Reaction:r,Add_Account:[null===(e=o.store.get("login"))||void 0===e?void 0:e.userId]};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.group_reaction_add",data:a})}))}({to:g,reactionID:o,sequence:_},this._core)),a.setLogInfo({message:`conversationID:${c} messageID:${d} reactionID:${o}`}).end(),{code:0}}catch(e){this._removeMyReactionRecord(d,o);const{errorCode:t}=e||{},s=new i.ChatError({functionName:"addMessageReaction",code:t});a.setError(s).end(),console.error("addMessageReaction error: ",e)}}))}removeMessageReaction(s,o){return e(this,void 0,void 0,(function*(){const{OuterConstant:n,ssoLog:r,helper:i}=this._core;this._validateMessageReactionBusinessCapability();const a=r.createSSOLogData({method:"removeMessageReaction"});try{const{conversationID:r,ID:i,conversationType:c,from:d,to:u,clientSequence:l,random:g,time:m,sequence:h}=s;return this._removeMyReactionRecord(i,o),c===n.CONV_C2C?yield function(s,o){return e(this,void 0,void 0,(function*(){var e;const{from:n,to:r,clientSequence:i,random:a,time:c,reactionID:d}=s,u={From_Account:n,To_Account:r,MsgKey:`${i}_${a}_${c}`,Reaction:d,Del_Account:[null===(e=o.store.get("login"))||void 0===e?void 0:e.userId]};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.reaction_del",data:u})}))}({from:d,to:u,clientSequence:l,random:g,time:m,reactionID:o},this._core):c===n.CONV_GROUP&&(yield function(s,o){return e(this,void 0,void 0,(function*(){var e;const{common:{isTopic:n},constants:{OuterConstant:{GROUP_ID_PREFIX:r}}}=t.core,{to:i,reactionID:a,sequence:c}=s,d=null===(e=o.store.get("login"))||void 0===e?void 0:e.userId;let u,l=i;n(i)&&(u=i,l=u.split(r.TOPIC)[0]);const g={TopicId:u,GroupId:l,MsgSeq:c,Reaction:a,Del_Account:[d]};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.group_reaction_del",data:g},o)}))}({to:u,reactionID:o,sequence:h},this._core)),a.setLogInfo({message:`conversationID:${r} messageID:${i} reactionID:${o}`}).end(),{code:0}}catch(e){const{errorCode:t}=e||{},s=new i.ChatError({functionName:"removeMessageReaction",code:t});a.setError(s).end(),console.error("removeMessageReaction error: ",e)}}))}getAllUserListOfMessageReaction(s){return e(this,void 0,void 0,(function*(){this._validateMessageReactionBusinessCapability();const{message:o,reactionID:n,nextSeq:r=0}=s,i=s.count>100?100:s.count,{conversationID:a}=o,{ssoLog:c,helper:d,constants:u}=this._core;try{let s=null;if(s=a.startsWith(u.OuterConstant.CONV_C2C)?yield function(s){return e(this,void 0,void 0,(function*(){const{message:e,nextSeq:o,reactionID:n,count:r}=s,{from:i,to:a,clientSequence:c,random:d,time:u}=e,l={Reaction:n,NextSeq:o,Count:r,From_Account:i,To_Account:a,MsgKey:`${c}_${d}_${u}`};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.reaction_iterate",data:l})}))}({message:o,reactionID:n,nextSeq:r,count:i}):yield function(s){return e(this,void 0,void 0,(function*(){const{common:{isTopic:e},constants:{OuterConstant:{GROUP_ID_PREFIX:o}}}=t.core,{message:n,nextSeq:r,reactionID:i,count:a}=s,{sequence:c}=n;let d,u=n.to;e(n.to)&&(d=n.to,u=d.split(o.TOPIC)[0]);const l={Reaction:i,NextSeq:r,TopicId:d,GroupId:u,Count:a,MsgSeq:c};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.group_reaction_iterate",data:l})}))}({message:o,reactionID:n,nextSeq:r,count:i}),s){const{Reaction_Account:e,NextSeq:t}=s,o=yield this._getUserProfileList(e);return{code:0,data:{nextSeq:t,isCompleted:0===r,userList:o}}}}catch(e){const{errorCode:t}=e||{},s=new d.ChatError({functionName:"getAllUserListOfMessageReaction",code:t});c.createSSOLogData({method:"removeMessageReaction"}).setError(s).end(),console.error("getAllUserListOfMessageReaction error: ",e)}}))}getMessageReactions(s){return e(this,void 0,void 0,(function*(){const{constants:o}=this._core;this._validateMessageReactionBusinessCapability();const{messageList:n,maxUserCountPerReaction:r=10}=s,i=n[0];let a=null;const c=new Map,{from:d,to:u,conversationType:l}=i,g=this._generateMessageKeyList(n,c);l===o.OuterConstant.CONV_C2C?a=yield function(s){return e(this,void 0,void 0,(function*(){const{from:e,to:o,messageKeyList:n,maxUserCountPerReaction:r}=s,i={From_Account:e,To_Account:o,MsgKeyList:n,Count:r};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.reaction_multi_stat",data:i})}))}({from:d,to:u,messageKeyList:g,maxUserCountPerReaction:r}):l===o.OuterConstant.CONV_GROUP&&(a=yield function(s){return e(this,void 0,void 0,(function*(){const{common:{isTopic:e},constants:{OuterConstant:{GROUP_ID_PREFIX:o}}}=t.core;let n,{groupId:r,messageSequenceList:i,maxUserCountPerReaction:a}=s;e(r)&&(n=r,r=r.split(o.TOPIC)[0]);const c={GroupId:r,TopicId:n,MsgSeqList:i,Count:a};return t.core.common.buildAndSendPacket({servcmd:"openim_msg_ext_http_svc.group_reaction_multi_stat",data:c})}))}({groupId:u,messageSequenceList:g,maxUserCountPerReaction:r}));const{Results:m=[]}=a||{},h=this._extractUserIDsFromReactionResults(m),p=yield this._getUserProfileMap(h);return{code:0,data:{resultList:m.map((e=>{const{ReactionList:t,MsgSeq:s,MsgKey:o}=e;return{messageID:this._generateMessageID({messageSequence:s,messageKey:o,messageIDMap:c}),reactionList:t.map((e=>{const{Reaction:t,Count:s,Reaction_Account:o,ReactedByMe:n}=e;return{reactionID:t,totalUserCount:s,partialUserList:this._generatePartialUserInfo({userIDList:o,userProfileMap:p}),reactedByMyself:1===n}}))}}))}}}))}dispose(){this._reactionsMap.clear()}_extractUserIDsFromReactionResults(e){const t=[];return null==e||e.forEach((e=>{const{ReactionList:s=[]}=e;s.forEach((e=>{e.Reaction_Account&&t.push(...e.Reaction_Account)}))})),t}_getUserProfileList(t){return e(this,void 0,void 0,(function*(){var e;try{const s=yield null===(e=this._core.user.userProfile)||void 0===e?void 0:e.getUserProfile({userIDList:t});return s?s.data:[]}catch(e){return[]}}))}_getUserProfileMap(t){return e(this,void 0,void 0,(function*(){const e=new Map;return(yield this._getUserProfileList(t)).forEach((t=>{const{nick:s,avatar:o,userID:n}=t;e.set(n,{nick:s,avatar:o,userID:n})})),e}))}_recordMessageReactedByMe(e,t){const s=`${e}-${t}`;this._reactionsMap.has(s)?this._reactionsMap.get(s).reactedByMe=!0:this._reactionsMap.set(s,{reactedByMe:!0})}_removeMyReactionRecord(e,t){const s=`${e}-${t}`;this._reactionsMap.has(s)&&(this._reactionsMap.get(s).reactedByMe=!1)}_recordMessageReactionInfo(e){const{messageID:t,reactionID:s,reactionInfo:o}=e,n=`${t}-${s}`,r=this._reactionsMap.get(n)||{};this._reactionsMap.set(n,Object.assign(Object.assign({},r),o))}_validateMessageReactionBusinessCapability(){const{helper:e,constants:t}=this._core;if(!e.checkBusinessCapabilityBits(r))throw new e.ChatError({functionName:"addMessageReaction",code:t.ERROR_CODE.NO_USE,replacement1:"addMessageReaction"})}_handleReactionUpdated(t){const{MsgReactionNotifyList:s}=t,{notificationCenter:o,constants:n}=this._core;s.forEach((t=>e(this,void 0,void 0,(function*(){const{C2CMsgInfo:e,GroupMsgInfo:s,MsgReactionSummary:r}=t,{TinyId:i,MsgClientTime:a,MsgRandom:c}=Object.assign(Object.assign({},e),s),d=`${i}-${a}-${c}`,u=this._extractUserIDsFromReactionResults([{ReactionList:r}]),l=yield this._getUserProfileMap(u),g=r.map((e=>{var t;const{Reaction:s,Reaction_Account:o}=e,n=this._generatePartialUserInfo({userIDList:o,userProfileMap:l}),r=o?e.Count:0,i=(null===(t=this._reactionsMap.get(`${d}-${s}`))||void 0===t?void 0:t.reactedByMe)||!1;return this._recordMessageReactionInfo({messageID:d,reactionID:s,reactionInfo:{reactionID:s,totalUserCount:r,partialUserList:n}}),{reactionID:s,totalUserCount:r,partialUserList:n,reactedByMyself:i}}));o.emitOuterEvent(n.OuterEvent.MESSAGE_REACTIONS_UPDATED,{name:n.OuterEvent.MESSAGE_REACTIONS_UPDATED,data:{messageID:d,reactionList:g}})}))))}_handleReactionSync(e){var t;const{notificationCenter:s,constants:o}=this._core,{C2CMsgInfo:n={},GroupMsgInfo:r={},Reaction:i,OperateType:a}=e.MsgReactionNotify,{TinyId:c="",MsgClientTime:d=0,MsgRandom:u=0}=Object.assign(Object.assign({},n),r),l=`${c}-${d}-${u}`,g=`${l}-${i}`;if(1===a?this._recordMessageReactedByMe(l,i):this._removeMyReactionRecord(l,i),null===(t=this._reactionsMap.get(g))||void 0===t?void 0:t.reactionID){const e=this._reactionsMap.get(g);e.reactedByMyself=1===a,s.emitOuterEvent(o.OuterEvent.MESSAGE_REACTIONS_UPDATED,{name:o.OuterEvent.MESSAGE_REACTIONS_UPDATED,data:{messageID:l,reactionList:[e]}})}}_generatePartialUserInfo({userIDList:e,userProfileMap:t}){const s=[];return null==e||e.forEach((e=>{t.has(e)&&s.push(t.get(e))})),s}_generateMessageID(e){const{messageSequence:t,messageKey:s,messageIDMap:o}=e;return s?o.get(s):o.get(t)}_generateMessageKeyList(e,t){const{constants:s}=this._core,o=e[0],{conversationType:n}=o;let r=[];return n===s.OuterConstant.CONV_C2C?r=e.map((e=>{const{clientSequence:s,random:o,time:n,ID:r}=e,i=`${s}_${o}_${n}`;return t.set(i,r),i})):n===s.OuterConstant.CONV_GROUP&&(r=e.map((e=>{const{ID:s,sequence:o}=e;return t.set(o,s),o}))),r}};var O=new class{init(e){this._core=e;const{helper:t,InnerEvent:{MESSAGE_PUSH:s},InnerEventSubType:{C2C_MESSAGE_READ_RECEIPT:o,GROUP_MESSAGE_READ_RECEIPT:n},notificationCenter:r}=e;t.registerApi({apiName:"sendMessageReadReceipt",context:this}),t.registerApi({apiName:"getMessageReadReceiptList",context:this}),t.registerApi({apiName:"getGroupMessageReadMemberList",context:this}),r.subscribeInnerEvent(s,o,this._handleC2CMessageReadReceipt,this),r.subscribeInnerEvent(s,n,this._handleGroupMessageReadReceipt,this)}sendMessageReadReceipt(s){return e(this,void 0,void 0,(function*(){const{common:o,constants:n}=this._core,r=this._filterValidMessageSendByOther(s);if(0===r.length)throw new o.ChatError({code:n.ERROR_CODE.READ_RECEIPT_MSG_LIST_EMPTY});try{const{conversationType:s}=r[0];return s===n.OuterConstant.CONV_C2C?yield function(s){return e(this,void 0,void 0,(function*(){const{common:e,constants:o}=t.core,n={Peer_Account:s[0].conversationID.replace(o.OuterConstant.CONV_C2C,""),C2CMsgInfo:s.map((e=>{const{from:t,to:s,sequence:o,random:n,time:r,clientTime:i}=e;return{From_Account:t,To_Account:s,MsgSeq:o,MsgRandom:n,MsgTime:r,MsgClientTime:i}}))};return e.buildAndSendPacket({servcmd:"openim.c2c_msg_read_receipt",data:n})}))}(r):yield function(s){return e(this,void 0,void 0,(function*(){const{common:e,constants:o}=t.core,n={GroupId:s[0].conversationID.replace(o.OuterConstant.CONV_GROUP,""),MsgSeqList:s.map((e=>({MsgSeq:e.sequence})))};return e.buildAndSendPacket({servcmd:"group_open_http_svc.group_msg_receipt",data:n})}))}(r),{code:0,data:{}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o.ChatError({code:t,message:s})}}))}getMessageReadReceiptList(s){return e(this,void 0,void 0,(function*(){const{common:o,constants:n}=this._core;try{const{conversationType:o}=s[0];if(o===n.OuterConstant.CONV_GROUP){const o=this._filterValidMessageSendByMe(s);if((null==o?void 0:o.length)>0){const n=yield function(s){return e(this,void 0,void 0,(function*(){const{common:e,constants:o}=t.core,n={GroupId:s[0].conversationID.replace(o.OuterConstant.CONV_GROUP,""),MsgSeqList:s.map((e=>({MsgSeq:e.sequence})))};return e.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_msg_receipt",data:n})}))}(o),{GroupMsgReceiptList:r}=n||{};this._updateGroupMessagesReadReceiptInfo({messageList:s,readReceiptList:r})}}return{code:0,data:{messageList:s}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o.ChatError({code:t,message:s})}}))}getGroupMessageReadMemberList(s){return e(this,void 0,void 0,(function*(){const{constants:o,common:n}=this._core,{message:r,filter:i=_.READ,cursor:a=""}=s,{conversationID:c,sequence:d,ID:u}=r,l=c.replace(o.OuterConstant.CONV_GROUP,""),g=s.count>=100?100:s.count;try{const s=yield function(s){return e(this,void 0,void 0,(function*(){const{sequence:e,groupID:o,filter:n,cursor:r,count:i}=s,a={MsgSeq:e,GroupId:o,Filter:n,Cursor:r,Num:i};return t.core.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_msg_receipt_detail",data:a})}))}({groupID:l,sequence:d,filter:i,cursor:a,count:g});if(s){const{Cursor:e,IsFinish:t,UnreadList:o,ReadList:n}=s,r={cursor:e,isCompleted:1===t,messageID:u,unreadUserIDList:[],readUserIDList:[]};return i===_.READ?r.readUserIDList=n.map((e=>e.Read_Account)):i===_.UNREAD&&(r.unreadUserIDList=o.map((e=>e.Unread_Account))),{code:0,data:r}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new n.ChatError({code:t,message:s})}}))}_handleC2CMessageReadReceipt(e){const t=[],{constants:s,helper:o}=this._core,{C2cMsgInfo:n,PeerReadTime:r,Peer_Account:i}=e;if(o.isEmpty(n))return;const a=`${s.OuterConstant.CONV_C2C}${i}`;null==n||n.forEach((e=>{const{TinyId:s,MsgClientTime:o,MsgRandom:n}=e,c=`${s}-${o}-${n}`,d=S({conversationID:a,messageID:c});d&&!d.readReceiptInfo.isPeerRead&&(d.readReceiptInfo.isPeerRead=!0,d.readReceiptInfo.timestamp=r,t.push({userID:i,messageID:c,isPeerRead:!0,timestamp:r}))})),this._emitReadReceiptEventIfNeed(t)}_updateGroupMessagesReadReceiptInfo(e){const{messageList:t,readReceiptList:s}=e,o=new Map;t.forEach((e=>{o.set(e.sequence,e)})),null==s||s.forEach((e=>{if(0===e.Code){const{MsgSeq:t,ReadNum:s,UnreadNum:n}=e,r=o.get(t);r&&(r.readReceiptInfo.readCount=s,r.readReceiptInfo.unreadCount=n)}}))}_handleGroupMessageReadReceipt(e){const t=[],{constants:s}=this._core,{GroupTips:o}=e;o.forEach((e=>{const{MsgBody:{GroupMsgReceiptList:o},GroupInfo:{GroupId:n}}=e,r=`${s.OuterConstant.CONV_GROUP}${n}`;null==o||o.forEach((e=>{const{TinyId:s,MsgClientTime:o,MsgRandom:i,ReadNum:a,UnreadNum:c}=e,d=`${s}-${o}-${i}`,u=S({conversationID:r,messageID:d}),l={groupID:n,messageID:d,readCount:0,unreadCount:0};u&&("number"==typeof a&&(u.readReceiptInfo.readCount=a,l.readCount=a),"number"==typeof c&&(u.readReceiptInfo.unreadCount=c,l.unreadCount=c),t.push(l))}))})),this._emitReadReceiptEventIfNeed(t)}_emitReadReceiptEventIfNeed(e){const{notificationCenter:t,OuterEvent:s}=this._core;e.length>0&&t.emitOuterEvent(s.MESSAGE_READ_RECEIPT_RECEIVED,{name:s.MESSAGE_READ_RECEIPT_RECEIVED,data:e})}_filterValidMessageSendByOther(e){return this._filterNeedReadReceiptMessages(e).filter((e=>{const{from:t}=e;return t!==this._core.common.getCurrentUserID()}))}_filterValidMessageSendByMe(e){const{OuterConstant:t}=this._core.constants;return this._filterNeedReadReceiptMessages(e).filter((e=>{const{from:s,status:o}=e;return s===this._core.common.getCurrentUserID()&&o===t.MessageStatus.SUCCESS}))}_filterNeedReadReceiptMessages(e){return e.filter((e=>!0===e.needReadReceipt))}dispose(){const{InnerEvent:{MESSAGE_PUSH:e},InnerEventSubType:{C2C_MESSAGE_READ_RECEIPT:t,GROUP_MESSAGE_READ_RECEIPT:s},notificationCenter:o}=this._core;o.unSubscribeInnerEvent(e,t,this._handleC2CMessageReadReceipt,this),o.unSubscribeInnerEvent(e,s,this._handleGroupMessageReadReceipt,this)}};const T=Object.assign(Object.assign({deleteMessage:[{required:!0,rules:["array"],allowEmpty:!1}],revokeMessage:[{required:!0,rules:["object"],allowEmpty:!1}],resendMessage:[{key:"message",required:!0,rules:["object"],allowEmpty:!1},{key:"options",required:!1,rules:["object"],allowEmpty:!1}],getMessageList:{conversationID:{required:!0,rules:["string"],allowEmpty:!1},nextReqMessageID:{required:!1,rules:["string"],allowEmpty:!0},count:{required:!1,rules:["number"],allowEmpty:!0}},getMessageListHopping:{conversationID:{required:!0,rules:["string"],allowEmpty:!1},sequence:{required:!1,rules:["number"],allowEmpty:!0},direction:{required:!1,rules:["number"],allowEmpty:!0},count:{required:!1,rules:["number"],allowEmpty:!0}},createTextAtMessage:{to:{required:!0,rules:["string"],allowEmpty:!1},conversationType:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>"GROUP"===e||"conversationType should be GROUP."},payload:{required:!0,rules:["object"],allowEmpty:!1,customValidator:e=>{const t=function(e){var t;if("string"!=typeof(null==e?void 0:e.text)||"string"==typeof e.text&&0===(null===(t=null==e?void 0:e.text)||void 0===t?void 0:t.length))return"payload.text is invalid.";return!0}(e);return!0!==t?t:!((null==e?void 0:e.atUserList)&&!Array.isArray(e.atUserList))||"atUserList should be an array or undefind."}}},findMessage:[{required:!0,rules:["string"],allowEmpty:!1}],translateText:{sourceTextList:{required:!0,rules:["array"],allowEmpty:!1},sourceLanguage:{required:!0,rules:["string"],allowEmpty:!1},targetLanguage:{required:!0,rules:["string"],allowEmpty:!1}},createForwardMessage:{to:{required:!0,rules:["string"],allowEmpty:!1},conversationType:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!e.startsWith("C2C")&&!e.startsWith("GROUP"))||"conversationType is invalid."},payload:{required:!0,rules:["object"],allowEmpty:!1}},createLocationMessage:{to:{required:!0,rules:["string"],allowEmpty:!1},conversationType:{required:!0,rules:["string"],allowEmpty:!1},payload:{required:!0,rules:["object"],allowEmpty:!1,customValidator:e=>{const{utils:{isString:s,isNumber:o}}=t.core;return s(null==e?void 0:e.description)?o(null==e?void 0:e.longitude)?!!o(null==e?void 0:e.latitude)||"payload.latitude must be a number.":"payload.longitude must be a number.":"payload.description must be a string."}}}},{addMessageReaction:[{key:"message",required:!0,rules:["object"],allowEmpty:!1},{key:"reactionID",required:!0,rules:["string"],allowEmpty:!1}],removeMessageReaction:[{key:"message",required:!0,rules:["object"],allowEmpty:!1},{key:"reactionID",required:!0,rules:["string"],allowEmpty:!1}],getMessageReactions:{messageList:{required:!0,rules:["array"],allowEmpty:!1},maxUserCountPerReaction:{required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"!=typeof e?"maxUserCountPerReaction is invalid.":!(e<0||e>10)||"maxUserCountPerReaction should between [0, 10]."}},getAllUserListOfMessageReaction:{message:{required:!0,rules:["object"],allowEmpty:!1,customValidator:e=>"success"===e.status||"message is invalid."},reactionID:{required:!0,rules:["string"],allowEmpty:!1},nextSeq:{required:!1,rules:["number"],allowEmpty:!0},count:{required:!1,rules:["number"],allowEmpty:!0}}}),{sendMessageReadReceipt:[{required:!0,rules:["array"],allowEmpty:!1}],getMessageReadReceiptList:[{required:!0,rules:["array"],allowEmpty:!1}],getGroupMessageReadMemberList:{message:{required:!0,rules:["object"],allowEmpty:!1},filter:{required:!1,rules:["number"],allowEmpty:!0},count:{required:!1,rules:["number"],allowEmpty:!0},cursor:{required:!1,rules:["string"],allowEmpty:!0}}}),q=Object.assign(Object.assign({deleteMessage:!0,revokeMessage:!0,resendMessage:!0,getMessageList:!0,getMessageListHopping:!0,createTextAtMessage:!0,findMessage:!0,translateText:!0,createForwardMessage:!0,createLocationMessage:!0},{addMessageReaction:!0,removeMessageReaction:!0,getMessageReactions:!0,getAllUserListOfMessageReaction:!0}),{sendMessageReadReceipt:!0,getMessageReadReceiptList:!0,getGroupMessageReadMemberList:!0});class b{constructor(e){this._core=e}deleteMessage(t){return e(this,void 0,void 0,(function*(){const{to:e,messageIdentifiers:s}=t,o="openim.delete_c2c_msg_ramble",n={From_Account:this._core.common.getCurrentUserID(),To_Account:e,MsgKeyList:s},r=this._core.helper.generateProtocolData({servcmd:o,data:n}),i=`${r.head.seq}${o}`;return this._core.channel.sendPacket(r,{requestId:i})}))}revokeMessage(t){return e(this,void 0,void 0,(function*(){const{to:e,from:s,sequence:o,time:n,random:r}=t,i="openim.msgwithdraw",a={MsgInfo:{From_Account:s,To_Account:e,MsgSeq:o,MsgRandom:r,MsgTimeStamp:n}},c=this._core.helper.generateProtocolData({servcmd:i,data:a}),d=`${c.head.seq}${i}`;return this._core.channel.sendPacket(c,{requestId:d})}))}}class w{constructor(e){this._core=e}deleteMessage(t){return e(this,void 0,void 0,(function*(){const{to:e,messageIdentifiers:s}=t,o="group_open_http_svc.delete_group_ramble_msg_by_seq",n={GroupId:e,Deleter_Account:this._core.common.getCurrentUserID(),Seqs:s},r=this._core.helper.generateProtocolData({servcmd:o,data:n}),i=`${r.head.seq}${o}`;return this._core.channel.sendPacket(r,{requestId:i})}))}revokeMessage(t){return e(this,void 0,void 0,(function*(){const{to:e,sequence:s}=t,o="group_open_http_svc.group_msg_recall",n={GroupId:e,MsgSeqList:[{MsgSeq:s}]},r=this._core.helper.generateProtocolData({servcmd:o,data:n}),i=`${r.head.seq}${o}`;return this._core.channel.sendPacket(r,{requestId:i})}))}}class P{constructor(e){this._core=e}generateRevokeMessage(e){const{conversationID:t,sequence:s,random:o,tinyID:n,clientTime:r,revokeReason:i,revoker:a}=e;let c={};const{messageDataHandler:d}=this._core.message;return c=d.revokeMessage({conversationID:t,sequence:s,random:o,revoker:a}),c||(c={conversationID:t,sequence:s},n&&r&&o&&(c.ID=`${n}-${r}-${o}`)),c=Object.assign(Object.assign({},c),{revoker:a,revokeReason:i,revokerInfo:{userID:a,nick:"",avatar:""}}),c}updateRevokerInfo(t){return e(this,void 0,void 0,(function*(){const e=t.map((e=>e.revoker));try{const s=yield this._fetchUserInfos(e);s&&t.forEach((e=>{const{revoker:t}=e;s[t]&&(e.revokerInfo.nick=s[t].nick||"",e.revokerInfo.avatar=s[t].avatar||"",e.revokerInfo.userID=t)}))}catch(e){console.debug(e)}}))}filterValidMessages(e){return e.filter((e=>{const t=!this._core.helper.isEmpty(null==e?void 0:e.getElements()),s=1===(null==e?void 0:e.isPlaceMessage);if(!t){this._core.ssoLog.createSSOLogData({method:"emptyMessageBody"}).setLogInfo({message:`from:${e.from} to:${e.to} sequence:${e.sequence}`}).end()}return t&&!s}))}_fetchUserInfos(t){return e(this,void 0,void 0,(function*(){var e,s;const o=yield null===(e=this._core.user.userProfile)||void 0===e?void 0:e.getUserProfile({userIDList:t});return(null==o?void 0:o.data)?null===(s=o.data)||void 0===s?void 0:s.reduce(((e,{userID:t,nick:s,avatar:o})=>(e[t]={nick:s||"",avatar:o||""},e)),{}):null}))}}var N=new class{constructor(){this._core=null,this._c2cMessageAction=null,this._groupMessageAction=null}init(e){this._core=e,this._groupMessageAction=new w(e),this._c2cMessageAction=new b(e),this._messageHelper=new P(e);const{helper:t}=e;t.registerApi({apiName:"deleteMessage",context:this}),t.registerApi({apiName:"revokeMessage",context:this}),t.registerApi({apiName:"resendMessage",context:this}),t.registerApi({apiName:"findMessage",context:this})}deleteMessage(t){return e(this,void 0,void 0,(function*(){let e=[],s=[];const{conversationID:o,conversationType:n}=t[0],r=o.replace(n,"");if("@TIM#SYSTEM"===n)throw new this._core.helper.ChatError({code:v});if(t.forEach((t=>{const{conversationID:r,conversationType:i,status:a,_onlineOnlyFlag:c,sequence:d,random:u,time:l}=t||{};if("success"===a&&r===o&&i===n){if(!c){const t="C2C"===i?`${d}_${u}_${l}`:String(d);e.push(t)}s.push(t)}})),0===e.length)return this._handleDeleteMessageSuccess(s),{code:0,data:{messageList:s}};e.length>30&&(e=e.slice(0,30),s=s.slice(0,30));try{return"C2C"===n?yield this._c2cMessageAction.deleteMessage({to:r,messageIdentifiers:e}):yield this._groupMessageAction.deleteMessage({to:r,messageIdentifiers:e}),this._handleDeleteMessageSuccess(s),{code:0,data:{messageList:s}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"deleteMessage",code:t})}}))}revokeMessage(t){return e(this,void 0,void 0,(function*(){var e;const s=this._core.ssoLog.createSSOLogData({method:"revokeMessage"}),{conversationType:o,isRevoked:n}=t;let r=null;if("@TIM#SYSTEM"===o)throw new this._core.helper.ChatError({message:"system message cannot be revoked"});if(n)throw new this._core.helper.ChatError({message:"message has been revoked"});s.setLogInfo({message:`type:${t.type} from:${t.from} to:${t.to}`});try{if(r="C2C"===o?yield this._c2cMessageAction.revokeMessage(t):yield this._groupMessageAction.revokeMessage(t),r){const{RecallRetList:o}=r,n=(null===(e=null==o?void 0:o[0])||void 0===e?void 0:e.RetCode)||0;if(0!==n)throw new this._core.helper.ChatError({code:n});return s.end(),yield this._handleRevokeMessageSuccess(t),{code:0,data:{message:t}}}}catch(e){const{errorCode:t}=e,s=new this._core.helper.ChatError({functionName:"revokeMessage",code:t});throw this._core.ssoLog.getSSOLogData("revokeMessage").setError(s).end(),s}}))}resendMessage(t,s){return e(this,void 0,void 0,(function*(){var e,o;return t.isResend=!0,t.status="unSend",null===(o=null===(e=this._core)||void 0===e?void 0:e.apiMap)||void 0===o?void 0:o.sendMessage(t,s)}))}findMessage(e){return this._core.message.messageDataHandler.findMessage(e)}_handleDeleteMessageSuccess(e){0!==e.length&&(e.forEach((e=>{e.isDeleted=!0;const t=this._core.message.messageDataHandler.getLocalMessageList(e.conversationID);null==t||t.forEach((t=>{t.ID===e.ID&&(t.isDeleted=!0)}))})),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.MESSAGE_DELETED,e[0].conversationID))}_handleRevokeMessageSuccess(t){return e(this,void 0,void 0,(function*(){var e;const s=null===(e=this._core.store.get("login"))||void 0===e?void 0:e.userId,{conversationID:o,sequence:n,random:r}=t;this._core.message.messageDataHandler.revokeMessage({conversationID:o,sequence:n,random:r,revoker:s}),yield this._messageHelper.updateRevokerInfo([t])}))}};class k{static parseServerPushElement(e){const{MsgContent:t={}}=e,{Index:s,Data:o}=t;return new k({index:s,data:o})}constructor(e){this.type=s.MSG_FACE;const{index:t,data:o}=e;this.content={index:t,data:o}}validateBeforeSend(){var e,t;return"number"==typeof(null===(e=this.content)||void 0===e?void 0:e.index)&&"string"==typeof(null===(t=this.content)||void 0===t?void 0:t.data)?{isValid:!0}:{isValid:!1,error:{message:"content is invalid"}}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},s=t?this.payload:this.content,{index:o,data:n}=s;return{MsgType:this.type,MsgContent:{Index:o,Data:n}}}}class x{static parseServerPushElement(e){const{MsgContent:t={}}=e,{Desc:s,Longitude:o,Latitude:n}=t;return new x({description:s,longitude:o,latitude:n})}constructor(e){this.type=s.MSG_LOCATION;const{description:t,longitude:o,latitude:n}=e;this.content={description:t,longitude:o,latitude:n}}validateBeforeSend(){return{isValid:!0}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},s=t?this.payload:this.content,{description:o,longitude:n,latitude:r}=s;return{MsgType:this.type,MsgContent:{Desc:o,Longitude:n,Latitude:r}}}}var G=new class{init(e){this._core=e,e.message.messageFactory.registerElementClass(s.MSG_FACE,k),e.message.messageFactory.registerElementClass(s.MSG_LOCATION,x),e.helper.registerApi({apiName:"createFaceMessage",context:this}),e.helper.registerApi({apiName:"createTextAtMessage",context:this}),e.helper.registerApi({apiName:"createForwardMessage",context:this}),e.helper.registerApi({apiName:"createLocationMessage",context:this})}createFaceMessage(e){if(!e)return null;const{index:t,data:s}=(null==e?void 0:e.payload)||{},o=new k({index:t,data:s}),n=this._core.common.getCurrentUserID(),r=this._core.message.messageFactory.createMessage(Object.assign(Object.assign({},e),{from:n}));return r.setElement(o),r}createTextAtMessage(e){const{atUserList:t}=(null==e?void 0:e.payload)||{},s=this._core.apiMap.createTextMessage(e),{OuterConstant:o}=this._core;if(!s)return null;if(Array.isArray(t)){const e=[],n=[];t.forEach((t=>{t!==o.MSG_AT_ALL?(e.push({GroupAtAllFlag:i,GroupAt_Account:t}),n.push(t)):(e.push({GroupAtAllFlag:a}),n.push(o.MSG_AT_ALL))})),s._groupAtInfoList=e,s.atUserList=n}return s}createForwardMessage(e){const{helper:t,OuterConstant:s}=this._core,{to:o,conversationType:n,priority:r,payload:i,needReadReceipt:a,receiverList:c,cloudCustomData:d="",isSupportExtension:u=!1}=e;if(!Array.isArray(i._elements))throw new t.ChatError({functionName:"createForwardMessage",code:2454});if(i.type===s.MSG_GRP_TIP)throw new t.ChatError({functionName:"createForwardMessage",code:2453});const l=this._core.common.getCurrentUserID(),g=this._core.message.messageFactory.createMessage({to:o,from:l,conversationType:n,isPlaceMessage:0,priority:r,payload:i,needReadReceipt:a,isSupportExtension:u,cloudCustomData:d,receiverList:c});return g.setRelayFlag(!0),g.setElement(i._elements[0]),g}createLocationMessage(e){if(!e)return null;const{description:t,longitude:s,latitude:o}=(null==e?void 0:e.payload)||{},n=new x({description:t,longitude:s,latitude:o}),r=this._core.common.getCurrentUserID(),i=this._core.message.messageFactory.createMessage(Object.assign(Object.assign({},e),{from:r}));return i.setElement(n),i}};class U{init(e){this._messageHelper=new P(e),this._core=e;const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s},InnerEventSubType:{C2C_REVOKED_MESSAGE:o},helper:{registerWorkflowStep:n},constants:{WORKFLOW_NAME:r,WORKFLOW_STEP:i}}=e;t.subscribeInnerEvent(s,o,this._handleC2CNotifyMessage,this),n(r.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.HANDLE_C2C_REVOKED_MESSAGE_FROM_SYNC_UNREAD,this._handleC2CRevokeMessagesFromUnreadMessageSync,this)}_handleC2CNotifyMessage(e){const{C2cNotifyMsgArray:t}=e;null==t||t.forEach((e=>{Object.keys(e).includes("WithdrawC2cMsgNotify")&&this._handleC2CRevokeMessage(e)}))}_handleC2CRevokeMessage(t){return e(this,void 0,void 0,(function*(){try{const{WithdrawC2cMsgNotify:{C2cWithdrawInfoArray:e}}=t;yield this._parseAndEmitC2CRevokedMessages(e)}catch(e){console.debug(e)}}))}_parseAndEmitC2CRevokedMessages(t){return e(this,void 0,void 0,(function*(){const e=[],{notificationCenter:s,OuterEvent:o,common:{getCurrentUserID:n}}=this._core;t.forEach((t=>{const{MsgRand:s,MsgSeq:o,To_Account:r,From_Account:i,RevokerInfo:{Revoker_Account:a,Revoke_Reason:c,Reason:d=c}}=t,u=n()===i?`C2C${r}`:`C2C${i}`,l=this._messageHelper.generateRevokeMessage({conversationID:u,sequence:o,random:s,revoker:a,revokeReason:d});e.push(l)})),e.length>0&&(yield this._messageHelper.updateRevokerInfo(e),s.emitOuterEvent(o.MESSAGE_REVOKED,{name:o.MESSAGE_REVOKED,data:e}))}))}_handleC2CRevokeMessagesFromUnreadMessageSync(t){return e(this,void 0,void 0,(function*(){const{revokedMessageList:e}=t.result;yield this._parseAndEmitC2CRevokedMessages(e)}))}dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t},InnerEventSubType:{C2C_REVOKED_MESSAGE:s}}=this._core;e.unSubscribeInnerEvent(t,s,this._handleC2CNotifyMessage,this)}}class F{init(e){this._messageHelper=new P(e),this._core=e;const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s},InnerEventSubType:{GROUP_MESSAGE_REVOKED:o}}=e;t.subscribeInnerEvent(s,o,this._handleGroupNotifyMessage,this)}_handleGroupNotifyMessage(e){const{GroupTips:t}=e;null==t||t.forEach((e=>{var t;Array.isArray(null===(t=null==e?void 0:e.MsgBody)||void 0===t?void 0:t.GroupWithdrawInfoArray)&&this._handleGroupRevokeMessage(e)}))}_handleGroupRevokeMessage(t){return e(this,void 0,void 0,(function*(){try{const{RevokerInfo:e,MsgBody:{GroupWithdrawInfoArray:s}}=t,o=[],{notificationCenter:n,OuterEvent:r,InnerEvent:i}=this._core;s.forEach((t=>{const{Random:s,MsgSeq:n,GroupId:r,MsgClientTime:i,TinyId:a,TopicId:c,RevokerInfo:{Revoker_Account:d=(null==e?void 0:e.Revoker_Account)||"",Reason:u=(null==e?void 0:e.Reason)||""}}=t,l=c?`GROUP${c}`:`GROUP${r}`,g=this._messageHelper.generateRevokeMessage({conversationID:l,sequence:n,random:s,tinyID:a,clientTime:i,revoker:d,revokeReason:u});o.push(g)})),0!==o.length&&(yield this._messageHelper.updateRevokerInfo(o),n.emitOuterEvent(r.MESSAGE_REVOKED,{name:r.MESSAGE_REVOKED,data:o}))}catch(e){console.debug(e)}}))}dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t},InnerEventSubType:{GROUP_MESSAGE_REVOKED:s}}=this._core;e.unSubscribeInnerEvent(t,s,this._handleGroupNotifyMessage,this)}}var H=new class{constructor(){this._c2cMessageReceiver=new U,this._groupMessageReceiver=new F}init(e){this._c2cMessageReceiver.init(e),this._groupMessageReceiver.init(e)}dispose(){this._c2cMessageReceiver.dispose(),this._groupMessageReceiver.dispose()}};class ${constructor(e){this._lastMessageSequenceMapOnDisconnect=new Map,this._core=e,this._messageHelper=new P(e)}getRoamingMessagesByAnchor(t){return e(this,void 0,void 0,(function*(){try{const e=this._core.ssoLog.createSSOLogData({method:"getRoamingMessagesByAnchor"}),{conversationID:s,count:r,direction:i,sequence:a}=t,c=s.replace(f,"");let d=a;if(i===n.BACKWARD){if("number"!=typeof a)return{messageList:[],hasNoMoreHistoryMessage:!1,nextReqMessageIDFromServer:""};d=a+r-1}const u={GroupId:c,ReqMsgNumber:r,WithRecalledMsg:1,Version:1};d&&(u.ReqMsgSeq=d);const l="group_open_http_svc.group_msg_get",g=this._core.helper.generateProtocolData({servcmd:l,data:u}),m=`${g.head.seq}${l}`,h=yield this._core.channel.sendPacket(g,{requestId:m});if(h){const{RspMsgList:t=[],NextReqMsgSeq:s=0,IsFinished:n,InvisibleMsgSeq:r}=h;e.setLogInfo({message:`groupID:${c} sequence:${a} reqSeq:${d} direction:${i}\n complete:${n} nextSequence:${s} remoteMsgCount:${t.length} invisibleSequenceList:${r}`}).end();const u=[];for(let e=0;e<t.length;e++){const s=t[e],o=this._parseMessage(s);u.push(o)}u.reverse();const l=[o.NO_MORE_DATA,o.DATA_HAS_EXPIRED].includes(n);return{messageList:this._messageHelper.filterValidMessages(u),invisibleSequenceList:r,nextReqMessageIDFromServer:s,hasNoMoreHistoryMessage:l}}}catch(e){const t=new this._core.helper.ChatError({code:null==e?void 0:e.code});this._core.ssoLog.getSSOLogData("getRoamingMessagesByAnchor").setError(t).end()}}))}recoverHistoryMessage(t){return e(this,void 0,void 0,(function*(){const{message:{messageReceiver:s,messageDataHandler:o},notificationCenter:r,OuterEvent:i,constants:{OuterConstant:a}}=this._core,c=[];null==t||t.forEach((t=>e(this,void 0,void 0,(function*(){const{conversationID:e,lastMessage:d}=t;let u=this._getLocalLastMessageSequence(e);const l=d.lastSequence;if(this._shouldRecoverHistory({localLastMessageSequence:u,serverLastMessageSequence:l})){const t=l-u;let a=!1;const c=Math.ceil(t/20);for(let t=0;t<c;t++)try{const t=l-u,c=Math.min(20,t),d=yield this.getRoamingMessagesByAnchor({conversationID:e,sequence:u+c,direction:n.FORWARD,count:c}),{nextReqMessageIDFromServer:g,hasNoMoreHistoryMessage:m,messageList:h}=d;a=m&&g<0,u=h[h.length-1].sequence;const p=[];if(Array.isArray(h)&&(h.forEach((e=>{s.groupMessageReceiver.updateMessageProfile(e);o.storeConversationMessage(e)&&p.push(e)})),p.length>0&&r.emitOuterEvent(i.MESSAGE_RECEIVED,{name:i.MESSAGE_RECEIVED,data:p})),a)break}catch(e){console.debug(e);break}}else c.push(e.replace(a.CONV_GROUP,""))})))),this._recoverGroupRevokeNotice(c)}))}updateLastMessageSequenceMapOnDisconnect(){const e=this._core.message.messageDataHandler.getContinuousMessagesByConversation();for(const[t,s]of e){if(t.startsWith("C2C"))continue;const e=Array.from(s.values());if((null==e?void 0:e.length)>0){const s=e[e.length-1].sequence;this._lastMessageSequenceMapOnDisconnect.set(t,s)}}}_shouldRecoverHistory(e){const{localLastMessageSequence:t,serverLastMessageSequence:s}=e;if("number"!=typeof t||"number"!=typeof s)return!1;const o=s-t;return 0!==s&&t&&(o>=R&&o<E)}_getLocalLastMessageSequence(e){if(this._lastMessageSequenceMapOnDisconnect.has(e))return this._lastMessageSequenceMapOnDisconnect.get(e);const t=this._core.message.messageDataHandler.getLocalMessageList(e),s=t[t.length-1];return null==s?void 0:s.sequence}_parseMessage(e){const{constants:{OuterConstant:t}}=this._core,s=f;4===e.Event&&(e.MsgBody.MsgType=t.MSG_GRP_TIP);const o=this._core.message.messageHelper.parseServerGroupMessage(e),n=this._core.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:s,flow:"in"}));return n.setElement(o.elements),n}_recoverGroupRevokeNotice(e){const t=this._filterValidGroupIDList(e);if(0===t.length)return;const s=Math.min(Math.ceil(t.length/10),5);Promise.all(Array.from({length:s},((e,s)=>{const o=10*s,n=Math.min(o+10,t.length);return this._fetchGroupRevokeNotice(t.slice(o,n))}))).catch((e=>console.error(e)))}_fetchGroupRevokeNotice(s){return e(this,void 0,void 0,(function*(){var o;try{const n=yield function(s){return e(this,void 0,void 0,(function*(){const{appStore:e,constants:{OuterConstant:o},common:n}=t.core,r=e.groupStore.getGroupMap(),i={NotifyReqList:s.map((e=>{const s=r.get(e);return{NotifyType:1,Limit:20,Type:n.isCommunity({type:s.type,groupID:e})?o.GRP_COMMUNITY:void 0,GroupId:e,BeginTime:(null==s?void 0:s._lastRevokedTime)||0,EndTime:1e3*t.core.common.timeManager.getServerTimeMs()}}))||[]};return n.buildAndSendPacket({servcmd:"group_open_http_svc.batch_get_group_notify",data:i})}))}(s);if(n){const e=[];null===(o=null==n?void 0:n.NotifyRspList)||void 0===o||o.forEach((t=>{const{GroupId:s,NotifyMsgList:o}=t,n=this._parseServerRevokeMessageList({groupID:s,serverRevokeMessageList:o});e.push(...n)})),0!==e.length&&(yield this._emitMessageRevokedEvent(e))}}catch(e){console.error(e)}}))}_parseServerRevokeMessageList(e){const{serverRevokeMessageList:t,groupID:s}=e,o=[];return null==t||t.forEach((e=>{const{ClientTime:t,MsgSeq:n,Random:r,RevokerInfo:{Revoker_Account:i="",Reason:a=""}}=e,c=`GROUP${s}`,d=this._messageHelper.generateRevokeMessage({conversationID:c,sequence:n,random:r,clientTime:t,revoker:i,revokeReason:a});o.push(d)})),o}_filterValidGroupIDList(e){const{constants:{OuterConstant:t}}=this._core,s=this._core.appStore.groupStore.getGroupMap();return(null==e?void 0:e.filter((e=>{if(!s.has(e))return!1;const o=s.get(e);return(null==o?void 0:o.type)!==t.GRP_AVCHATROOM&&!(null==o?void 0:o.isSupportTopic)})))||[]}_emitMessageRevokedEvent(t){return e(this,void 0,void 0,(function*(){const{notificationCenter:e,OuterEvent:s}=this._core;yield this._messageHelper.updateRevokerInfo(t),e.emitOuterEvent(s.MESSAGE_REVOKED,{name:s.MESSAGE_REVOKED,data:t})}))}}class V{constructor(e){this._historyMessageListFetchAnchors=new Map,this._core=e,this._messageHelper=new P(e)}getRoamingMessagesByAnchor(s){return e(this,void 0,void 0,(function*(){var o;try{const{conversationID:n,count:r,messageID:i,time:a,direction:c}=s;let d=a,u="";if(!a){const e=i?this._core.message.messageDataHandler.findMessage(i):null;if(d=(null==e?void 0:e.time)||0,i&&this._historyMessageListFetchAnchors.has(n)){const e=this._historyMessageListFetchAnchors.get(n);d=e.lastMessageTime,u=e.messageKey}}const l=n.replace(M,""),g=yield function(s){return e(this,void 0,void 0,(function*(){const{peerAccount:e,count:o,lastMessageTime:n,messageKey:r,direction:i}=s,a={Peer_Account:e,MaxCnt:o,WithRecalledMsg:1,LastMsgTime:n,MsgKey:r,GetDirection:i};return t.core.common.buildAndSendPacket({servcmd:"openim.getroammsg",data:a})}))}({count:r,lastMessageTime:d,messageKey:u,peerAccount:l,direction:c});if(g){const{MsgList:e=[],Complete:t,MsgKey:s,LastMsgTime:r}=g;this._historyMessageListFetchAnchors.set(n,{messageKey:s,lastMessageTime:r});const i=[];for(let t=0;t<e.length;t++){const s=e[t],o=this._parseMessage(s);i.push(o)}const a=this._messageHelper.filterValidMessages(i);return{messageList:a,nextReqMessageIDFromServer:null===(o=a[0])||void 0===o?void 0:o.ID,lastMessageTime:r,hasNoMoreHistoryMessage:1===t}}}catch(e){throw new this._core.helper.ChatError({code:null==e?void 0:e.code})}}))}_parseMessage(e){const t=M,s=this._core.message.messageHelper.parseServerPushMessage(e),o=this._core.message.messageFactory.createMessage(Object.assign(Object.assign({},s),{conversationType:t,flow:"in"}));return o.setElement(s.elements),o}}var K=new class{constructor(){this._clearedConversations=new Set,this._fetchedCompleteConversations=new Set}init(e){this._core=e,this._groupMessageHistory=new $(e),this._c2cMessageHistory=new V(e),this._messageHelper=new P(e);const{InnerEvent:t,notificationCenter:s,constants:o}=e;e.helper.registerApi({apiName:"getMessageList",context:this}),e.helper.registerApi({apiName:"getMessageListHopping",context:this}),e.helper.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.HISTORY_MESSAGE_RECOVER,this._recoverHistoryMessage,this),s.subscribeInnerEvent(t.SOCKET_DISCONNECTED,this._handleSocketDisconnected,this)}getMessageList(s){return e(this,void 0,void 0,(function*(){try{const e=this._core.ssoLog.createSSOLogData({method:"getMessageList"});let{conversationID:o,nextReqMessageID:r}=s;const i=y;if("@TIM#SYSTEM"===o)return{code:0,data:{messageList:[],isCompleted:!1,nextMessageSeq:""}};const a=this._getAvailableLocalMessagesCount({conversationID:o,nextReqMessageID:r});if(this._needFetchHistoryMessageList({conversationID:o,availableLocalMessagesCount:a,targetCount:i})){let s=null;if(o.startsWith(f)?s=yield this._groupMessageHistory.getRoamingMessagesByAnchor({conversationID:o,sequence:Number(r),count:i,direction:n.FORWARD}):o.startsWith(M)&&(s=yield this._c2cMessageHistory.getRoamingMessagesByAnchor({conversationID:o,messageID:r,count:i,direction:n.FORWARD})),s){const{nextReqMessageIDFromServer:n,hasNoMoreHistoryMessage:i,messageList:c}=s,d=this._core.message.messageDataHandler.prependLocalMessageList({messageList:c,conversationID:o});!function(e){const{appStore:s,message:o,OuterConstant:n}=t.core,r=s.conversationStore.getConversation(e),i=o.messageDataHandler.getLocalMessageList(e);if(!r||0===i.length||e===n.CONV_SYSTEM)return;const a=[];for(let e=0;e<i.length;e++)"in"!==i[e].flow?"out"!==i[e].flow||i[e].isRead||i[e].setIsRead(!0):a.push(i[e]);let c=0;if(r.type===n.CONV_C2C){const e=a.slice(-r.unreadCount).filter((e=>e.isRevoked)).length;c=a.length-r.unreadCount-e}else c=a.length-r.unreadCount;for(let e=0;e<c&&!a[e].isRead;e++)a[e].setIsRead(!0)}(o),yield C(o),o.startsWith(M)&&(yield I({messageList:c,conversationID:o}));const u=this._core.message.messageDataHandler.getLocalMessageList(o).slice(0,d.length+a),l=u.filter((e=>e.isRevoked));yield this._messageHelper.updateRevokerInfo(l);const g={nextReqMessageID:i?"":String(n),messageList:u,isCompleted:i},m=u.map((e=>e.sequence));return e.setLogInfo({message:`conversationID: ${o} nextReqMessageID: ${r} \n availableLocalMessagesCount: ${a} sequenceList: ${JSON.stringify(m)} `}).end(),{code:0,data:g}}return{code:0,data:{messageList:[],isCompleted:!1,nextMessageSeq:""}}}e.setLogInfo({message:`conversationID: ${o} nextReqMessageID: ${r} availableLocalMessagesCount: ${a}}`}).end();return{code:0,data:yield this._getMessageListFromMemory({conversationID:o,nextReqMessageID:r,count:i})}}catch(e){const t=new this._core.helper.ChatError({code:null==e?void 0:e.code});this._core.ssoLog.getSSOLogData("getMessageList").setError(t).end(),console.debug(t)}}))}getMessageListHopping(t){return e(this,void 0,void 0,(function*(){var e,s;const{conversationID:o,sequence:r,time:i,direction:a=n.FORWARD}=t,{isEmpty:c}=this._core.helper;if(![n.BACKWARD,n.FORWARD].includes(a))throw new this._core.helper.ChatError({message:"direction must be 0 or 1"});let{count:d=y}=t;d=d>y?y:d;let u=null;if(o.startsWith(f)){if(u=yield this._groupMessageHistory.getRoamingMessagesByAnchor({conversationID:o,sequence:r,count:d,direction:a}),u){const{nextReqMessageIDFromServer:t,hasNoMoreHistoryMessage:o,messageList:i,invisibleSequenceList:d}=u;if(this._core.message.messageDataHandler.storeSparseMessageList(i),a===n.FORWARD){const e=o&&t<1;return{code:0,data:{messageList:i,isCompleted:e,nextMessageSeq:e?"":t}}}if(a===n.BACKWARD){if(c(i)&&c(d))return{code:0,data:{messageList:[],isCompleted:!0,nextMessageSeq:""}};const t=(null===(e=null==i?void 0:i[i.length-1])||void 0===e?void 0:e.sequence)||0,o=(null===(s=null==d?void 0:d[d.length-1])||void 0===s?void 0:s.sequence)||0;return{code:0,data:{messageList:i.filter((e=>e.sequence>=r)),isCompleted:!1,nextMessageSeq:Math.max(t,o)+1}}}return{code:0,data:u}}}else if(o.startsWith(M)&&(u=yield this._c2cMessageHistory.getRoamingMessagesByAnchor({conversationID:o,count:d+1,time:i,direction:a}),u)){const{messageList:e,lastMessageTime:t,hasNoMoreHistoryMessage:s}=u;return s||(a===n.FORWARD?e.shift():e.pop()),this._core.message.messageDataHandler.storeSparseMessageList(e),{code:0,data:{messageList:e,isCompleted:s,nextMessageTime:s?"":t}}}}))}_getAvailableLocalMessagesCount({conversationID:e,nextReqMessageID:t}){const s=this._core.message.messageDataHandler.getLocalMessageList(e),{length:o}=s;if(!t)return o;let n=-1;return(null==e?void 0:e.startsWith(M))?n=s.findIndex((e=>e.ID===t)):(null==e?void 0:e.startsWith(f))&&(n=s.findIndex((e=>t.includes("-")?e.ID===t:String(e.sequence)===t))),-1===n?0:n}_needFetchHistoryMessageList({conversationID:e,availableLocalMessagesCount:t,targetCount:s}){return!!this._clearedConversations.has(e)||t<=s&&!this._fetchedCompleteConversations.has(e)}_getMessageListFromMemory(t){return e(this,arguments,void 0,(function*({conversationID:e,nextReqMessageID:t,count:s}){const o=this._core.message.messageDataHandler.getLocalMessageList(e),n=o.length;let r=n,i={isCompleted:!1,nextReqMessageID:"",messageList:[]},a=0,c=n;return t?t&&(c=o.findIndex((s=>e.startsWith(M)?s.ID===t:String(s.sequence)===t)),a=c>s?c-s:0,r=c):a=n>s?n-s:0,i.nextReqMessageID=0===a?"":this._generateNextReqMessageID({conversationID:e,targetIndex:a}),i.messageList=o.slice(a,c),i.isCompleted=r<=s,e.startsWith(M)&&(yield C(e),yield I({messageList:i.messageList,conversationID:e})),i}))}_generateNextReqMessageID({conversationID:e,targetIndex:t}){const s=this._core.message.messageDataHandler.getLocalMessageList(e);return e.startsWith("C2C")?s[t].ID:String(s[t].sequence)}_recoverHistoryMessage(){const{appStore:e,constants:{OuterConstant:{GRP_AVCHATROOM:t}}}=this._core,s=e.conversationStore.getConversationMap()||{};if(s instanceof Map){const e=[...s.values()].filter((e=>e.type===f&&e.groupProfile.type!==t));this._groupMessageHistory.recoverHistoryMessage(e)}}_handleSocketDisconnected(){this._groupMessageHistory.updateLastMessageSequenceMapOnDisconnect()}dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.SOCKET_DISCONNECTED,this._handleSocketDisconnected,this)}};var B=new class{constructor(){this._core=null}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"translateText",context:this})}translateText(t){return e(this,void 0,void 0,(function*(){try{const{sourceLanguage:s,sourceTextList:o,targetLanguage:n}=t,r=yield function(t,s){return e(this,void 0,void 0,(function*(){var e,o;const{sourceTextList:n,sourceLanguage:r,targetLanguage:i}=t,{store:a,helper:c,channel:d}=s,u="im_open_translate.ws_batch_trans_text",l={SourceText:n,Source:r,Target:i,FromAccount:null===(e=a.get("login"))||void 0===e?void 0:e.tinyID,SDKAppID:null===(o=a.get("instance"))||void 0===o?void 0:o.sdkAppId},g=c.generateProtocolData({servcmd:u,data:l}),m=`${g.head.seq}${u}`,h=yield d.sendPacket(g,{requestId:m});if(h){const{CmdErrorCode:e,TargetText:t}=h;return{cmdErrorCode:e,translatedTextList:t}}}))}({sourceLanguage:s,sourceTextList:o,targetLanguage:n},this._core);if(r){const{cmdErrorCode:{ErrorCode:e,ErrorInfo:t},translatedTextList:s}=r;if(0===e)return{code:0,data:{translatedTextList:s}};throw{errorCode:e,errorInfo:t,message:t}}}catch(e){const{errorCode:t,errorInfo:s}=e||{};throw new this._core.helper.ChatError({functionName:"translateText",code:t,message:s})}}))}};var W=new class{init(e){this._core=e,e.common.registerApi({apiName:"convertVoiceToText",context:this})}convertVoiceToText(s){return e(this,void 0,void 0,(function*(){var e,o;const{message:n,language:r=c.ZH_PY}=s;let{url:i}=n.payload||{};const a=null===(e=this._core.store.get("login"))||void 0===e?void 0:e.userID;n.from===a&&"out"===n.flow&&(i=n.payload.remoteAudioUrl),this._validateVoiceFormat(i);const d=(null===(o=p.exec(i))||void 0===o?void 0:o[1])||"mp3",u=h[r]||m;try{const e=yield function(e){var s;const{store:o,common:n}=t.core,{url:r,format:i,serverLanguageType:a}=e,c={BytesUrl:r,BytesEngServiceType:a,BytesVoiceFormat:i,Uint32Sdkappid:null===(s=o.get("instance"))||void 0===s?void 0:s.sdkAppId,Uint64SourceType:0};return n.buildAndSendPacket({servcmd:"im_open_speech.ws_sentence_recognition",data:c})}({url:i,format:d,serverLanguageType:u});if(e){const{CmdErrorCode:t,BytesResult:s}=e;if(0===t.ErrorCode)return{code:0,data:{result:s}};throw{code:t.ErrorCode,message:t.ErrorInfo}}}catch(e){const{code:t,message:s}=e||{},o=new this._core.common.ChatError({functionName:"convertVoiceToText",code:t,message:s});console.error(o),this._core.ssoLog.createSSOLogData({method:"convertVoiceToText"}).setError(o).end()}}))}_validateVoiceFormat(e){if(!p.test(e))throw new this._core.common.ChatError({code:2119})}};class j{constructor(e){const{constants:s,common:o,utils:n}=t.core,{CONV_C2C:r,CONV_GROUP:i}=s.OuterConstant,{ID:a,tinyID:c,from:d,to:u,clientTime:l=o.timeManager.getServerTimeSeconds()||0,random:g,sequence:m,cloudCustomData:h="",nick:p="",avatar:_="",clientSequence:v,conversationType:M,groupID:f,_elements:y,time:R}=e;this.ID=a||`${c}-${l}-${g}`,this.messageRandom=g,this.from=d,this.messageSender=d,this.time=R,this.messageSequence=m,this.clientSequence=v||m,this.clientTime=l,this.cloudCustomData=h,this.messageReceiver=u,this.avatar=_,this.nick=p;const E=n.deepCopyWithMethods(y);E.forEach((e=>{e.payload=e.content,delete e.content})),this.messageBody=E,a?M.startsWith(r)?this.receiverUserID=u:M.startsWith(i)&&(this.receiverGroupID=u):f?(this.receiverGroupID=f,this.messageReceiver=f):u&&(this.receiverUserID=u,this.messageReceiver=u)}transformElementsToServerFormat(){return this.messageBody?Array.isArray(this.messageBody)?this.messageBody.map((e=>e.transformToServerFormat({isMergerMessage:!0}))):this.messageBody.transformToServerFormat({isMergerMessage:!0}):null}}class Y{static parseServerPushElement(e){const{MsgContent:t}=e,{MsgList:s=[],CompatibleText:o,AbstractList:n,Title:r,PbMsgKey:i,JsonMsgKey:a}=t||{},c=s.map((e=>A(e)));return new Y({messageList:c,title:r,abstractList:n,compatibleText:o,pbDownloadKey:i,downloadKey:a})}constructor(e){this.type=t.core.constants.OuterConstant.MSG_MERGER;const{messageList:s,title:o,abstractList:n,compatibleText:r,pbDownloadKey:i="",downloadKey:a="",version:c=0,layersOverLimit:d=!1}=e,u=[];s.forEach((e=>{if(e){const t=new j(e);u.push(t)}})),this.content={messageList:u,title:o,abstractList:n,compatibleText:r,version:c,downloadKey:a,pbDownloadKey:i,layersOverLimit:d}}validateBeforeSend(){const{isEmpty:e}=t.core.helper;return e(this.content.messageList)?{isValid:!1,error:{message:"content is invalid"}}:{isValid:!0}}transformToServerFormat(e){const{isMergerMessage:t=!1}=e||{},s=t?this.payload:this.content,{abstractList:o,compatibleText:n,downloadKey:r,layersOverLimit:i,pbDownloadKey:a,title:c,version:d,messageList:u}=s;return{MsgType:this.type,MsgContent:{AbstractList:o,CompatibleText:n,JsonMsgKey:r,LayersOverLimit:i,PbMsgKey:a,Title:c,Version:d,MsgList:D(u)}}}}var J=new class{init(e){this._core=e;const{message:t,helper:s,constants:{OuterConstant:o}}=e;t.messageFactory.registerElementClass(o.MSG_MERGER,Y),s.registerApi({apiName:"createMergerMessage",context:this}),s.registerApi({apiName:"sendMessage",context:this,matcher:e=>e[0].type===o.MSG_MERGER}),s.registerApi({apiName:"downloadMergerMessage",context:this})}createMergerMessage(e){const{common:t}=this._core;if(!e)return null;const s=new Y(e.payload),o=t.getCurrentUserID(),n=this._core.message.messageFactory.createMessage(Object.assign(Object.assign({},e),{from:o}));return n.setRelayFlag(!0),n.setElement(s),n}sendMessage(s,o){return e(this,void 0,void 0,(function*(){var n,r,i;try{const a=function(e){let s="utf-8";t.core.helper.IN_BROWSER&&document&&(s=document.charset.toLowerCase());let o,n=0,r=0;if(r=e.length,"utf-8"===s||"utf8"===s)for(let t=0;t<r;t++)o=e.codePointAt(t),o<=127?n+=1:o<=2047?n+=2:o<=65535?n+=3:(n+=4,t++);else if("utf-16"===s||"utf16"===s)for(let t=0;t<r;t++)o=e.codePointAt(t),o<=65535?n+=2:(n+=4,t++);else n=e.replace(/[^\x00-\xff]/g,"aa").length;return n}(JSON.stringify(s));let c=s,d=null;if(a>11264){c=this._core.utils.deepCopyWithMethods(s);try{const{JsonMsgKey:s,PbMsgKey:o}=yield function(s){return e(this,void 0,void 0,(function*(){const{payload:{messageList:e}}=s,o={MsgList:D(e)};return t.core.common.buildAndSendPacket({servcmd:"im_long_msg.save_relay_json_msg",data:o})}))}(c),{payload:n}=c;d=new Y(Object.assign(Object.assign({},n),{messageList:[],downloadKey:s,pbDownloadKey:o})),c.setElement(d)}catch(e){console.error(e)}}const{data:{message:u}}=yield null===(i=null===(r=null===(n=this._core)||void 0===n?void 0:n.message)||void 0===r?void 0:r.messageSender)||void 0===i?void 0:i.sendMessage(c,o);return d&&u.setElement(s._elements),{code:0,data:{message:u}}}catch(e){throw console.error(e),e}}))}downloadMergerMessage(s){return e(this,void 0,void 0,(function*(){try{const o=s.payload,{downloadKey:n,pbDownload:r,type:i,messageList:a}=o,c=function(e,t){var s={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(s[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(s[o[n]]=e[o[n]])}return s}(o,["downloadKey","pbDownload","type","messageList"]),d=yield function(s){return e(this,void 0,void 0,(function*(){return t.core.common.buildAndSendPacket({servcmd:"im_long_msg.get_relay_json_msg",data:{JsonMsgKey:s}})}))}(n),{MsgList:u}=d||{},l=null==u?void 0:u.map((e=>{const t=A(e);return new j(t)}));return"function"==typeof s.isOnlineMessage?s.setElement({type:s.type,content:Object.assign({messageList:l},c)}):(s.payload.messageList=l,s.payload.downloadKey="",s.payload.pbDownloadKey=""),s}catch(e){console.error(e)}}))}};var X=new class{install(e){this._core=e,t.init(e),N.init(e),G.init(e),H.init(e),K.init(e),L.init(e),B.init(e),W.init(e),O.init(e),J.init(e),e.helper.registerValidateConfig({auth:q,params:T}),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.DESTROY,this.dispose,this)}dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this.dispose,this),H.dispose(),K.dispose(),O.dispose()}};export{X as default};