@tencentcloud/lite-chat 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/basic.es.js +3 -2
- package/basic.js +3 -2
- package/package.json +1 -1
- package/plugins/cloud-search.es.js +1 -1
- package/plugins/cloud-search.js +1 -1
- package/plugins/conversation-group.d.ts +8 -0
- package/plugins/conversation-group.es.js +1 -1
- package/plugins/conversation-group.js +1 -1
- package/plugins/conversation.es.js +1 -1
- package/plugins/conversation.js +1 -1
- package/plugins/follow.es.js +1 -1
- package/plugins/follow.js +1 -1
- package/plugins/friend.es.js +1 -1
- package/plugins/friend.js +1 -1
- package/plugins/group.es.js +1 -1
- package/plugins/group.js +1 -1
- package/plugins/message-enhancer.es.js +3 -4
- package/plugins/message-enhancer.js +3 -4
- package/plugins/offline-message-synchronizer.d.ts +9 -0
- package/plugins/offline-message-synchronizer.es.js +1 -0
- package/plugins/offline-message-synchronizer.js +1 -0
- package/plugins/rich-media-message.es.js +1 -1
- package/plugins/rich-media-message.js +1 -1
- package/plugins/signaling.d.ts +8 -0
- package/plugins/signaling.es.js +1 -1
- package/plugins/signaling.js +1 -1
- package/plugins/topic.es.js +1 -1
- package/plugins/topic.js +1 -1
- package/professional.es.js +5 -5
- package/professional.js +5 -5
- package/standard.es.js +5 -5
- package/standard.js +5 -5
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,r){var t={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&r.indexOf(s)<0&&(t[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,s=Object.getOwnPropertySymbols(e);o<s.length;o++)r.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(t[s[o]]=e[s[o]]);return t}function r(e,i,n,u){return new(n=n||Promise)(function(t,r){function o(e){try{a(u.next(e))}catch(e){r(e)}}function s(e){try{a(u.throw(e))}catch(e){r(e)}}function a(e){var r;e.done?t(e.value):((r=e.value)instanceof n?r:new n(function(e){e(r)})).then(o,s)}a((u=u.apply(e,i||[])).next())})}let t=new class{init(e){this.core=e}},o="message",s="user",n={OR:"or",AND:"and"},a=20,i=20,u=20,c={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5"},d={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND"},p={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&1<=e&&e<=100||"count must be a number between 1 and 100"},l={required:!1,rules:["string"],allowEmpty:!0},h={required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=t.core["OuterConstant"];if(!Array.isArray(r))return"groupTypeList should be an array";var o=[e.GRP_PUBLIC,e.GRP_COMMUNITY,e.GRP_WORK,e.GRP_MEETING];let s=!1;for(let e=0;e<r.length;e++)if(-1===o.indexOf(r[e])){s=!0;break}return!s||"groupTypeList should be supported group type"}},y=r=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&0<=e||r+" should be a number >= 0';"}),m={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=t.core["OuterConstant"];return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},g={searchCloudMessages:{keywordList:c,keywordListMatchType:d,cursor:l,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=t.core["OuterConstant"],o=[e.MSG_TEXT,e.MSG_IMAGE,e.MSG_AUDIO,e.MSG_FILE,e.MSG_VIDEO,e.MSG_LOCATION,e.MSG_CUSTOM,e.MSG_MERGER];let s=!1;for(let e=0;e<r.length;e++)if(-1===o.indexOf(r[e])){s=!0;break}return!s||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=t.core["OuterConstant"];return!!(null!=e&&e.startsWith(r.CONV_C2C)||null!=e&&e.startsWith(r.CONV_GROUP)||e===r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:y("timePosition"),timePeriod:y("timePeriod")},searchCloudUsers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,miniBirthday:y("miniBirthday"),maxBirthday:y("maxBirthday"),gender:m},searchCloudGroupMembers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h}},C={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};var L=new class{install(e){this._core=e,t.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:C,params:g})}searchCloudMessages(v){return r(this,void 0,void 0,function*(){try{let{OuterConstant:i,helper:n,ssoLog:o}=this._core,s=o.createSSOLogData({method:"searchCloudMessages"}),{conversationID:a,timePeriod:u,timePosition:c}=v,d=e(v,["conversationID","timePeriod","timePosition"]),l=Object.assign({count:100},d);a&&(a.startsWith(i.CONV_C2C)?l.account=a.replace(i.CONV_C2C,""):a.startsWith(i.CONV_GROUP)&&(l.groupID=a.replace(i.CONV_GROUP,""))),this._setTimeRangeParams(l,{timePeriod:u,timePosition:c});var p=yield function(l){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,senderUserIDList:s,messageTypeList:a,endTime:i,startTime:n,cursor:u,account:c,groupID:d}=l,e={Count:e,KeywordList:r,MatchType:o,SendUserIDList:s,MsgTypeList:a,EndTime:i,StartTime:n,Cursor:u,PeerAccount:c,GroupID:d};return t.core.common.buildAndSendPacket({servcmd:"message_search.query",data:e})})}(l);if(!p)return{code:0,data:{}};var{ErrorCode:h,ErrorInfo:y,TotalCount:m,Cursor:g="",ConversationMsgs:C=[]}=p;if(0!==h)throw{errorCode:h,errorInfo:y};var L=`keywordList:${v.keywordList} keywordListMatchType:${v.keywordListMatchType} cursor:${v.cursor} res: totalCount:`+m,w=(s.setLogInfo({message:L}).end(),C.map(e=>{let{MsgList:r,Count:t,GroupID:s,UserID:o}=e,a=s?""+i.CONV_GROUP+s:""+i.CONV_C2C+o;return this._isSearchingAllConversations(v)&&1<t?{conversationID:a,messageCount:t,messageList:[]}:{conversationID:a,messageCount:t,messageList:r.map(e=>{return n.isEmpty(s)?(r=this._core,t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),(r=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}))).setElement(o.elements),r):(t=this._core,o=t.OuterConstant.CONV_GROUP,r=t.message.messageHelper.parseServerGroupMessage(e),(t=t.message.messageFactory.createMessage(Object.assign(Object.assign({},r),{conversationType:o,flow:"in"}))).setElement(r.elements),t);var r,t,o})}}));return{code:0,data:{searchResultList:w,cursor:g,totalCount:m}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudMessages"})}})}searchCloudUsers(w){return r(this,void 0,void 0,function*(){var d;try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:s,count:a=i}=w,u=e(w,["keywordListMatchType","count"]),c=Object.assign({count:a,keywordListMatchType:s===n.AND?1:0},u);this._setBirthdayRangeParams(c,w);var l=yield function(u){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,miniBirthday:s,maxBirthday:a,cursor:i,gender:n}=u,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:i,UserBirthStart:s,UserBirthEnd:a,Gender:n};return t.core.common.buildAndSendPacket({servcmd:"user_search.query",data:e})})}(c);if(!l)return{error:0,data:{}};var{ErrorCode:p,ErrorInfo:h,TotalCount:y,Cursor:m="",Users:g=[]}=l;if(0!==p)throw{errorCode:p,errorInfo:h};var C=`keywordList:${w.keywordList} keywordListMatchType:${w.keywordListMatchType} cursor:${w.cursor} count:${w.count} res: totalCount:`+y,L=(o.setLogInfo({message:C}).end(),[]);for(let e=0,r=g.length;e<r;e++){let{UserID:t,ProfileItems:o}=g[e];if(t!==this._core.OuterConstant.USER_NOT_FOUND&&""!==t){let e=o.map(e=>({tag:e.Tag,value:e.StrValue})),r=null==(d=this._core.user.userProfile)?void 0:d.createProfile(t,e);L.push(r)}}return{code:0,data:{searchResultList:L,cursor:m,totalCount:y}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudUsers"})}})}searchCloudGroupMembers(L){return r(this,void 0,void 0,function*(){try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:s=u,keywordListMatchType:a}=L,i=e(L,["count","keywordListMatchType"]),c=Object.assign({count:s,keywordListMatchType:a===n.AND?1:0},i),d=yield function(n){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,groupTypeList:s,cursor:a,groupIDList:i}=n,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:a,GroupType:s,GroupIdList:i};return t.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:e})})}(c);if(!d)return{code:0,data:{}};var{ErrorCode:p,ErrorInfo:h,GroupMembers:y=[],Cursor:m,TotalCount:g}=d;if(0!==p)throw{errorCode:p,errorInfo:h};var C=`keywordList:${L.keywordList} keywordListMatchType:${L.keywordListMatchType} cursor:${L.cursor} count:${L.count} res: totalCount:`+g;o.setLogInfo({message:C}).end();let l=new Map;return y.forEach(e=>{var{GroupID:r,GroupName:e,GroupType:t,GroupFaceUrl:o,GroupMemberUserName:s,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:n=""}=e,e={groupID:r,name:e,type:t,avatar:o},t={userID:a,nick:s,nameCard:i,avatar:n};if(l.has(r)){let e=l.get(r);e.memberList.push(t),l.set(r,e)}else l.set(r,{groupInfo:e,memberList:[t]})}),{code:0,data:{searchResultList:[...l.values()],cursor:m,totalCount:g}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroupMembers"})}})}searchCloudGroups(C){return r(this,void 0,void 0,function*(){try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:s=a,keywordListMatchType:i}=C,u=e(C,["count","keywordListMatchType"]),c=Object.assign({count:s,keywordListMatchType:i===n.AND?1:0},u),d=yield function(i){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,groupTypeList:s,cursor:a}=i,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:a,GroupType:s};return t.core.common.buildAndSendPacket({servcmd:"group_search.query",data:e})})}(c);if(!d)return{code:0,data:{}};var{ErrorCode:l,ErrorInfo:p,Groups:h,Cursor:y,TotalCount:m}=d;if(0!==l)throw{errorCode:l,errorInfo:p};var g=`keywordList:${C.keywordList} keywordListMatchType:${C.keywordListMatchType} cursor:${C.cursor} count:${C.count} res: totalCount:`+m;return o.setLogInfo({message:g}).end(),{code:0,data:{searchResultList:(null==h?void 0:h.map(e=>{var{GroupFaceUrl:e,GroupID:r,GroupIntroduction:t,GroupMemberNum:o,GroupName:s,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:n,GroupType:u,GroupAddOption:c,GroupInviteOption:d}=e;return{avatar:e,groupID:r,introduction:t,memberCount:o,name:s,ownerTinyID:a,ownerID:i,ownerNick:n,type:u,joinOption:c,inviteOption:d}}))||[],cursor:y,totalCount:m}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroups"})}})}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&0<r&&(e.startTime=t&&0<t?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&0<t&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:s}){var{ssoLog:a,helper:i}=this._core;let n=e;60020===e?n="SearchUnable":t!==o&&27003===e?n="SearchParamsError":t!==o&&60018===e&&(n="SearchOverLimit");t=new i.ChatError({code:n,message:r});throw a.getSSOLogData(s).setError(t).end(),t}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){var{miniBirthday:r,maxBirthday:t}=r;void 0!==r&&(e.miniBirthday=r,void 0===t)&&(e.maxBirthday=4294967295),void 0!==t&&(e.maxBirthday=t)}};export{L as default};
|
|
1
|
+
function e(e,r){var t={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&r.indexOf(s)<0&&(t[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,s=Object.getOwnPropertySymbols(e);o<s.length;o++)r.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(t[s[o]]=e[s[o]]);return t}function r(e,i,n,u){return new(n=n||Promise)(function(t,r){function o(e){try{a(u.next(e))}catch(e){r(e)}}function s(e){try{a(u.throw(e))}catch(e){r(e)}}function a(e){var r;e.done?t(e.value):((r=e.value)instanceof n?r:new n(function(e){e(r)})).then(o,s)}a((u=u.apply(e,i||[])).next())})}let t=new class{init(e){this.core=e}},o="message",s="user",n={OR:"or",AND:"and"},a=20,i=20,u=20,c={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5"},d={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND"},p={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&1<=e&&e<=100||"count must be a number between 1 and 100"},l={required:!1,rules:["string"],allowEmpty:!0},h={required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=t.core["OuterConstant"];if(!Array.isArray(r))return"groupTypeList should be an array";var o=[e.GRP_PUBLIC,e.GRP_COMMUNITY,e.GRP_WORK,e.GRP_MEETING];let s=!1;for(let e=0;e<r.length;e++)if(-1===o.indexOf(r[e])){s=!0;break}return!s||"groupTypeList should be supported group type"}},y=r=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&0<=e||r+" should be a number >= 0';"}),m={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=t.core["OuterConstant"];return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},g={searchCloudMessages:{keywordList:c,keywordListMatchType:d,cursor:l,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=t.core["OuterConstant"],o=[e.MSG_TEXT,e.MSG_IMAGE,e.MSG_AUDIO,e.MSG_FILE,e.MSG_VIDEO,e.MSG_LOCATION,e.MSG_CUSTOM,e.MSG_MERGER];let s=!1;for(let e=0;e<r.length;e++)if(-1===o.indexOf(r[e])){s=!0;break}return!s||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=t.core["OuterConstant"];return!!(null!=e&&e.startsWith(r.CONV_C2C)||null!=e&&e.startsWith(r.CONV_GROUP)||e===r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:y("timePosition"),timePeriod:y("timePeriod")},searchCloudUsers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,miniBirthday:y("miniBirthday"),maxBirthday:y("maxBirthday"),gender:m},searchCloudGroupMembers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h}},C={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};var L=new class{constructor(){this.name="CloudSearch"}install(e){this._core=e,t.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:C,params:g})}searchCloudMessages(v){return r(this,void 0,void 0,function*(){try{let{OuterConstant:i,helper:n,ssoLog:o}=this._core,s=o.createSSOLogData({method:"searchCloudMessages"}),{conversationID:a,timePeriod:u,timePosition:c}=v,d=e(v,["conversationID","timePeriod","timePosition"]),l=Object.assign({count:100},d);a&&(a.startsWith(i.CONV_C2C)?l.account=a.replace(i.CONV_C2C,""):a.startsWith(i.CONV_GROUP)&&(l.groupID=a.replace(i.CONV_GROUP,""))),this._setTimeRangeParams(l,{timePeriod:u,timePosition:c});var h=yield function(l){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,senderUserIDList:s,messageTypeList:a,endTime:i,startTime:n,cursor:u,account:c,groupID:d}=l,e={Count:e,KeywordList:r,MatchType:o,SendUserIDList:s,MsgTypeList:a,EndTime:i,StartTime:n,Cursor:u,PeerAccount:c,GroupID:d};return t.core.common.buildAndSendPacket({servcmd:"message_search.query",data:e})})}(l);if(!h)return{code:0,data:{}};var{ErrorCode:p,ErrorInfo:y,TotalCount:m,Cursor:g="",ConversationMsgs:C=[]}=h;if(0!==p)throw{errorCode:p,errorInfo:y};var L=`keywordList:${v.keywordList} keywordListMatchType:${v.keywordListMatchType} cursor:${v.cursor} res: totalCount:`+m,w=(s.setLogInfo({message:L}).end(),C.map(e=>{let{MsgList:r,Count:t,GroupID:s,UserID:o}=e,a=s?""+i.CONV_GROUP+s:""+i.CONV_C2C+o;return this._isSearchingAllConversations(v)&&1<t?{conversationID:a,messageCount:t,messageList:[]}:{conversationID:a,messageCount:t,messageList:r.map(e=>{return n.isEmpty(s)?(r=this._core,t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),(r=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}))).setElement(o.elements),r):(t=this._core,o=t.OuterConstant.CONV_GROUP,r=t.message.messageHelper.parseServerGroupMessage(e),(t=t.message.messageFactory.createMessage(Object.assign(Object.assign({},r),{conversationType:o,flow:"in"}))).setElement(r.elements),t);var r,t,o})}}));return{code:0,data:{searchResultList:w,cursor:g,totalCount:m}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudMessages"})}})}searchCloudUsers(w){return r(this,void 0,void 0,function*(){var d;try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:s,count:a=i}=w,u=e(w,["keywordListMatchType","count"]),c=Object.assign({count:a,keywordListMatchType:s===n.AND?1:0},u);this._setBirthdayRangeParams(c,w);var l=yield function(u){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,miniBirthday:s,maxBirthday:a,cursor:i,gender:n}=u,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:i,UserBirthStart:s,UserBirthEnd:a,Gender:n};return t.core.common.buildAndSendPacket({servcmd:"user_search.query",data:e})})}(c);if(!l)return{error:0,data:{}};var{ErrorCode:h,ErrorInfo:p,TotalCount:y,Cursor:m="",Users:g=[]}=l;if(0!==h)throw{errorCode:h,errorInfo:p};var C=`keywordList:${w.keywordList} keywordListMatchType:${w.keywordListMatchType} cursor:${w.cursor} count:${w.count} res: totalCount:`+y,L=(o.setLogInfo({message:C}).end(),[]);for(let e=0,r=g.length;e<r;e++){let{UserID:t,ProfileItems:o}=g[e];if(t!==this._core.OuterConstant.USER_NOT_FOUND&&""!==t){let e=o.map(e=>({tag:e.Tag,value:e.StrValue})),r=null==(d=this._core.user.userProfile)?void 0:d.createProfile(t,e);L.push(r)}}return{code:0,data:{searchResultList:L,cursor:m,totalCount:y}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudUsers"})}})}searchCloudGroupMembers(L){return r(this,void 0,void 0,function*(){try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:s=u,keywordListMatchType:a}=L,i=e(L,["count","keywordListMatchType"]),c=Object.assign({count:s,keywordListMatchType:a===n.AND?1:0},i),d=yield function(n){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,groupTypeList:s,cursor:a,groupIDList:i}=n,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:a,GroupType:s,GroupIdList:i};return t.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:e})})}(c);if(!d)return{code:0,data:{}};var{ErrorCode:h,ErrorInfo:p,GroupMembers:y=[],Cursor:m,TotalCount:g}=d;if(0!==h)throw{errorCode:h,errorInfo:p};var C=`keywordList:${L.keywordList} keywordListMatchType:${L.keywordListMatchType} cursor:${L.cursor} count:${L.count} res: totalCount:`+g;o.setLogInfo({message:C}).end();let l=new Map;return y.forEach(e=>{var{GroupID:r,GroupName:e,GroupType:t,GroupFaceUrl:o,GroupMemberUserName:s,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:n=""}=e,e={groupID:r,name:e,type:t,avatar:o},t={userID:a,nick:s,nameCard:i,avatar:n};if(l.has(r)){let e=l.get(r);e.memberList.push(t),l.set(r,e)}else l.set(r,{groupInfo:e,memberList:[t]})}),{code:0,data:{searchResultList:[...l.values()],cursor:m,totalCount:g}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroupMembers"})}})}searchCloudGroups(C){return r(this,void 0,void 0,function*(){try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:s=a,keywordListMatchType:i}=C,u=e(C,["count","keywordListMatchType"]),c=Object.assign({count:s,keywordListMatchType:i===n.AND?1:0},u),d=yield function(i){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,groupTypeList:s,cursor:a}=i,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:a,GroupType:s};return t.core.common.buildAndSendPacket({servcmd:"group_search.query",data:e})})}(c);if(!d)return{code:0,data:{}};var{ErrorCode:l,ErrorInfo:h,Groups:p,Cursor:y,TotalCount:m}=d;if(0!==l)throw{errorCode:l,errorInfo:h};var g=`keywordList:${C.keywordList} keywordListMatchType:${C.keywordListMatchType} cursor:${C.cursor} count:${C.count} res: totalCount:`+m;return o.setLogInfo({message:g}).end(),{code:0,data:{searchResultList:(null==p?void 0:p.map(e=>{var{GroupFaceUrl:e,GroupID:r,GroupIntroduction:t,GroupMemberNum:o,GroupName:s,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:n,GroupType:u,GroupAddOption:c,GroupInviteOption:d}=e;return{avatar:e,groupID:r,introduction:t,memberCount:o,name:s,ownerTinyID:a,ownerID:i,ownerNick:n,type:u,joinOption:c,inviteOption:d}}))||[],cursor:y,totalCount:m}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroups"})}})}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&0<r&&(e.startTime=t&&0<t?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&0<t&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:s}){var{ssoLog:a,helper:i}=this._core;let n=e;60020===e?n="SearchUnable":t!==o&&27003===e?n="SearchParamsError":t!==o&&60018===e&&(n="SearchOverLimit");t=new i.ChatError({code:n,message:r});throw a.getSSOLogData(s).setError(t).end(),t}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){var{miniBirthday:r,maxBirthday:t}=r;void 0!==r&&(e.miniBirthday=r,void 0===t)&&(e.maxBirthday=4294967295),void 0!==t&&(e.maxBirthday=t)}};export{L as default};
|
package/plugins/cloud-search.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)["TencentCloudChatCloud-search"]=r()}(this,function(){function f(e,r){var t={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&r.indexOf(s)<0&&(t[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,s=Object.getOwnPropertySymbols(e);o<s.length;o++)r.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(t[s[o]]=e[s[o]]);return t}function L(e,i,n,u){return new(n=n||Promise)(function(t,r){function o(e){try{a(u.next(e))}catch(e){r(e)}}function s(e){try{a(u.throw(e))}catch(e){r(e)}}function a(e){var r;e.done?t(e.value):((r=e.value)instanceof n?r:new n(function(e){e(r)})).then(o,s)}a((u=u.apply(e,i||[])).next())})}let w=new class{init(e){this.core=e}},n="message",o="user",m={OR:"or",AND:"and"},e={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5"},r={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||!![m.OR,m.AND].includes(e)||"keywordListMatchType should be OR or AND"},t={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&1<=e&&e<=100||"count must be a number between 1 and 100"},s={required:!1,rules:["string"],allowEmpty:!0},a={required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=w.core["OuterConstant"];if(!Array.isArray(r))return"groupTypeList should be an array";var t=[e.GRP_PUBLIC,e.GRP_COMMUNITY,e.GRP_WORK,e.GRP_MEETING];let o=!1;for(let e=0;e<r.length;e++)if(-1===t.indexOf(r[e])){o=!0;break}return!o||"groupTypeList should be supported group type"}},i=r=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&0<=e||r+" should be a number >= 0';"}),u={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=w.core["OuterConstant"];return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},c={searchCloudMessages:{keywordList:e,keywordListMatchType:r,cursor:s,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=w.core["OuterConstant"],t=[e.MSG_TEXT,e.MSG_IMAGE,e.MSG_AUDIO,e.MSG_FILE,e.MSG_VIDEO,e.MSG_LOCATION,e.MSG_CUSTOM,e.MSG_MERGER];let o=!1;for(let e=0;e<r.length;e++)if(-1===t.indexOf(r[e])){o=!0;break}return!o||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=w.core["OuterConstant"];return!!(null!=e&&e.startsWith(r.CONV_C2C)||null!=e&&e.startsWith(r.CONV_GROUP)||e===r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:i("timePosition"),timePeriod:i("timePeriod")},searchCloudUsers:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,miniBirthday:i("miniBirthday"),maxBirthday:i("maxBirthday"),gender:u},searchCloudGroupMembers:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,groupTypeList:a,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,groupTypeList:a}},d={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};return new class{install(e){this._core=e,w.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:d,params:c})}searchCloudMessages(C){return L(this,void 0,void 0,function*(){try{let{OuterConstant:i,helper:n,ssoLog:e}=this._core,r=e.createSSOLogData({method:"searchCloudMessages"}),{conversationID:t,timePeriod:o,timePosition:s}=C,a=f(C,["conversationID","timePeriod","timePosition"]),u=Object.assign({count:100},a);t&&(t.startsWith(i.CONV_C2C)?u.account=t.replace(i.CONV_C2C,""):t.startsWith(i.CONV_GROUP)&&(u.groupID=t.replace(i.CONV_GROUP,""))),this._setTimeRangeParams(u,{timePeriod:o,timePosition:s});var c=yield function(d){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,senderUserIDList:o,messageTypeList:s,endTime:a,startTime:i,cursor:n,account:u,groupID:c}=d,e={Count:e,KeywordList:r,MatchType:t,SendUserIDList:o,MsgTypeList:s,EndTime:a,StartTime:i,Cursor:n,PeerAccount:u,GroupID:c};return w.core.common.buildAndSendPacket({servcmd:"message_search.query",data:e})})}(u);if(!c)return{code:0,data:{}};var{ErrorCode:d,ErrorInfo:l,TotalCount:h,Cursor:p="",ConversationMsgs:y=[]}=c;if(0!==d)throw{errorCode:d,errorInfo:l};var m=`keywordList:${C.keywordList} keywordListMatchType:${C.keywordListMatchType} cursor:${C.cursor} res: totalCount:`+h,g=(r.setLogInfo({message:m}).end(),y.map(e=>{let{MsgList:r,Count:t,GroupID:s,UserID:o}=e,a=s?""+i.CONV_GROUP+s:""+i.CONV_C2C+o;return this._isSearchingAllConversations(C)&&1<t?{conversationID:a,messageCount:t,messageList:[]}:{conversationID:a,messageCount:t,messageList:r.map(e=>{return n.isEmpty(s)?(r=this._core,t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),(r=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}))).setElement(o.elements),r):(t=this._core,o=t.OuterConstant.CONV_GROUP,r=t.message.messageHelper.parseServerGroupMessage(e),(t=t.message.messageFactory.createMessage(Object.assign(Object.assign({},r),{conversationType:o,flow:"in"}))).setElement(r.elements),t);var r,t,o})}}));return{code:0,data:{searchResultList:g,cursor:p,totalCount:h}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:n,functionName:"searchCloudMessages"})}})}searchCloudUsers(y){return L(this,void 0,void 0,function*(){var a;try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:r,count:t=20}=y,o=f(y,["keywordListMatchType","count"]),s=Object.assign({count:t,keywordListMatchType:r===m.AND?1:0},o);this._setBirthdayRangeParams(s,y);var i=yield function(n){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,miniBirthday:o,maxBirthday:s,cursor:a,gender:i}=n,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:a,UserBirthStart:o,UserBirthEnd:s,Gender:i};return w.core.common.buildAndSendPacket({servcmd:"user_search.query",data:e})})}(s);if(!i)return{error:0,data:{}};var{ErrorCode:n,ErrorInfo:u,TotalCount:c,Cursor:d="",Users:l=[]}=i;if(0!==n)throw{errorCode:n,errorInfo:u};var h=`keywordList:${y.keywordList} keywordListMatchType:${y.keywordListMatchType} cursor:${y.cursor} count:${y.count} res: totalCount:`+c,p=(e.setLogInfo({message:h}).end(),[]);for(let e=0,r=l.length;e<r;e++){let{UserID:t,ProfileItems:o}=l[e];if(t!==this._core.OuterConstant.USER_NOT_FOUND&&""!==t){let e=o.map(e=>({tag:e.Tag,value:e.StrValue})),r=null==(a=this._core.user.userProfile)?void 0:a.createProfile(t,e);p.push(r)}}return{code:0,data:{searchResultList:p,cursor:d,totalCount:c}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudUsers"})}})}searchCloudGroupMembers(p){return L(this,void 0,void 0,function*(){try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:r=20,keywordListMatchType:t}=p,o=f(p,["count","keywordListMatchType"]),s=Object.assign({count:r,keywordListMatchType:t===m.AND?1:0},o),a=yield function(i){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,groupTypeList:o,cursor:s,groupIDList:a}=i,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:s,GroupType:o,GroupIdList:a};return w.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:e})})}(s);if(!a)return{code:0,data:{}};var{ErrorCode:i,ErrorInfo:n,GroupMembers:c=[],Cursor:d,TotalCount:l}=a;if(0!==i)throw{errorCode:i,errorInfo:n};var h=`keywordList:${p.keywordList} keywordListMatchType:${p.keywordListMatchType} cursor:${p.cursor} count:${p.count} res: totalCount:`+l;e.setLogInfo({message:h}).end();let u=new Map;return c.forEach(e=>{var{GroupID:r,GroupName:e,GroupType:t,GroupFaceUrl:o,GroupMemberUserName:s,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:n=""}=e,e={groupID:r,name:e,type:t,avatar:o},t={userID:a,nick:s,nameCard:i,avatar:n};if(u.has(r)){let e=u.get(r);e.memberList.push(t),u.set(r,e)}else u.set(r,{groupInfo:e,memberList:[t]})}),{code:0,data:{searchResultList:[...u.values()],cursor:d,totalCount:l}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudGroupMembers"})}})}searchCloudGroups(h){return L(this,void 0,void 0,function*(){try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:r=20,keywordListMatchType:t}=h,o=f(h,["count","keywordListMatchType"]),s=Object.assign({count:r,keywordListMatchType:t===m.AND?1:0},o),a=yield function(a){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,groupTypeList:o,cursor:s}=a,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:s,GroupType:o};return w.core.common.buildAndSendPacket({servcmd:"group_search.query",data:e})})}(s);if(!a)return{code:0,data:{}};var{ErrorCode:i,ErrorInfo:n,Groups:u,Cursor:c,TotalCount:d}=a;if(0!==i)throw{errorCode:i,errorInfo:n};var l=`keywordList:${h.keywordList} keywordListMatchType:${h.keywordListMatchType} cursor:${h.cursor} count:${h.count} res: totalCount:`+d;return e.setLogInfo({message:l}).end(),{code:0,data:{searchResultList:(null==u?void 0:u.map(e=>{var{GroupFaceUrl:e,GroupID:r,GroupIntroduction:t,GroupMemberNum:o,GroupName:s,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:n,GroupType:u,GroupAddOption:c,GroupInviteOption:d}=e;return{avatar:e,groupID:r,introduction:t,memberCount:o,name:s,ownerTinyID:a,ownerID:i,ownerNick:n,type:u,joinOption:c,inviteOption:d}}))||[],cursor:c,totalCount:d}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudGroups"})}})}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&0<r&&(e.startTime=t&&0<t?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&0<t&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:o}){var{ssoLog:s,helper:a}=this._core;let i=e;60020===e?i="SearchUnable":t!==n&&27003===e?i="SearchParamsError":t!==n&&60018===e&&(i="SearchOverLimit");t=new a.ChatError({code:i,message:r});throw s.getSSOLogData(o).setError(t).end(),t}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){var{miniBirthday:r,maxBirthday:t}=r;void 0!==r&&(e.miniBirthday=r,void 0===t)&&(e.maxBirthday=4294967295),void 0!==t&&(e.maxBirthday=t)}}});
|
|
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)["TencentCloudChatCloud-search"]=r()}(this,function(){function f(e,r){var t={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&r.indexOf(s)<0&&(t[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,s=Object.getOwnPropertySymbols(e);o<s.length;o++)r.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(t[s[o]]=e[s[o]]);return t}function L(e,i,n,u){return new(n=n||Promise)(function(t,r){function o(e){try{a(u.next(e))}catch(e){r(e)}}function s(e){try{a(u.throw(e))}catch(e){r(e)}}function a(e){var r;e.done?t(e.value):((r=e.value)instanceof n?r:new n(function(e){e(r)})).then(o,s)}a((u=u.apply(e,i||[])).next())})}let w=new class{init(e){this.core=e}},n="message",o="user",m={OR:"or",AND:"and"},e={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5"},r={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||!![m.OR,m.AND].includes(e)||"keywordListMatchType should be OR or AND"},t={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&1<=e&&e<=100||"count must be a number between 1 and 100"},s={required:!1,rules:["string"],allowEmpty:!0},a={required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=w.core["OuterConstant"];if(!Array.isArray(r))return"groupTypeList should be an array";var t=[e.GRP_PUBLIC,e.GRP_COMMUNITY,e.GRP_WORK,e.GRP_MEETING];let o=!1;for(let e=0;e<r.length;e++)if(-1===t.indexOf(r[e])){o=!0;break}return!o||"groupTypeList should be supported group type"}},i=r=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&0<=e||r+" should be a number >= 0';"}),u={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=w.core["OuterConstant"];return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},c={searchCloudMessages:{keywordList:e,keywordListMatchType:r,cursor:s,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=w.core["OuterConstant"],t=[e.MSG_TEXT,e.MSG_IMAGE,e.MSG_AUDIO,e.MSG_FILE,e.MSG_VIDEO,e.MSG_LOCATION,e.MSG_CUSTOM,e.MSG_MERGER];let o=!1;for(let e=0;e<r.length;e++)if(-1===t.indexOf(r[e])){o=!0;break}return!o||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=w.core["OuterConstant"];return!!(null!=e&&e.startsWith(r.CONV_C2C)||null!=e&&e.startsWith(r.CONV_GROUP)||e===r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:i("timePosition"),timePeriod:i("timePeriod")},searchCloudUsers:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,miniBirthday:i("miniBirthday"),maxBirthday:i("maxBirthday"),gender:u},searchCloudGroupMembers:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,groupTypeList:a,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,groupTypeList:a}},d={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};return new class{constructor(){this.name="CloudSearch"}install(e){this._core=e,w.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:d,params:c})}searchCloudMessages(g){return L(this,void 0,void 0,function*(){try{let{OuterConstant:i,helper:n,ssoLog:e}=this._core,r=e.createSSOLogData({method:"searchCloudMessages"}),{conversationID:t,timePeriod:o,timePosition:s}=g,a=f(g,["conversationID","timePeriod","timePosition"]),u=Object.assign({count:100},a);t&&(t.startsWith(i.CONV_C2C)?u.account=t.replace(i.CONV_C2C,""):t.startsWith(i.CONV_GROUP)&&(u.groupID=t.replace(i.CONV_GROUP,""))),this._setTimeRangeParams(u,{timePeriod:o,timePosition:s});var c=yield function(d){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,senderUserIDList:o,messageTypeList:s,endTime:a,startTime:i,cursor:n,account:u,groupID:c}=d,e={Count:e,KeywordList:r,MatchType:t,SendUserIDList:o,MsgTypeList:s,EndTime:a,StartTime:i,Cursor:n,PeerAccount:u,GroupID:c};return w.core.common.buildAndSendPacket({servcmd:"message_search.query",data:e})})}(u);if(!c)return{code:0,data:{}};var{ErrorCode:d,ErrorInfo:l,TotalCount:h,Cursor:p="",ConversationMsgs:y=[]}=c;if(0!==d)throw{errorCode:d,errorInfo:l};var m=`keywordList:${g.keywordList} keywordListMatchType:${g.keywordListMatchType} cursor:${g.cursor} res: totalCount:`+h,C=(r.setLogInfo({message:m}).end(),y.map(e=>{let{MsgList:r,Count:t,GroupID:s,UserID:o}=e,a=s?""+i.CONV_GROUP+s:""+i.CONV_C2C+o;return this._isSearchingAllConversations(g)&&1<t?{conversationID:a,messageCount:t,messageList:[]}:{conversationID:a,messageCount:t,messageList:r.map(e=>{return n.isEmpty(s)?(r=this._core,t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),(r=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}))).setElement(o.elements),r):(t=this._core,o=t.OuterConstant.CONV_GROUP,r=t.message.messageHelper.parseServerGroupMessage(e),(t=t.message.messageFactory.createMessage(Object.assign(Object.assign({},r),{conversationType:o,flow:"in"}))).setElement(r.elements),t);var r,t,o})}}));return{code:0,data:{searchResultList:C,cursor:p,totalCount:h}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:n,functionName:"searchCloudMessages"})}})}searchCloudUsers(y){return L(this,void 0,void 0,function*(){var a;try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:r,count:t=20}=y,o=f(y,["keywordListMatchType","count"]),s=Object.assign({count:t,keywordListMatchType:r===m.AND?1:0},o);this._setBirthdayRangeParams(s,y);var i=yield function(n){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,miniBirthday:o,maxBirthday:s,cursor:a,gender:i}=n,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:a,UserBirthStart:o,UserBirthEnd:s,Gender:i};return w.core.common.buildAndSendPacket({servcmd:"user_search.query",data:e})})}(s);if(!i)return{error:0,data:{}};var{ErrorCode:n,ErrorInfo:u,TotalCount:c,Cursor:d="",Users:l=[]}=i;if(0!==n)throw{errorCode:n,errorInfo:u};var h=`keywordList:${y.keywordList} keywordListMatchType:${y.keywordListMatchType} cursor:${y.cursor} count:${y.count} res: totalCount:`+c,p=(e.setLogInfo({message:h}).end(),[]);for(let e=0,r=l.length;e<r;e++){let{UserID:t,ProfileItems:o}=l[e];if(t!==this._core.OuterConstant.USER_NOT_FOUND&&""!==t){let e=o.map(e=>({tag:e.Tag,value:e.StrValue})),r=null==(a=this._core.user.userProfile)?void 0:a.createProfile(t,e);p.push(r)}}return{code:0,data:{searchResultList:p,cursor:d,totalCount:c}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudUsers"})}})}searchCloudGroupMembers(p){return L(this,void 0,void 0,function*(){try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:r=20,keywordListMatchType:t}=p,o=f(p,["count","keywordListMatchType"]),s=Object.assign({count:r,keywordListMatchType:t===m.AND?1:0},o),a=yield function(i){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,groupTypeList:o,cursor:s,groupIDList:a}=i,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:s,GroupType:o,GroupIdList:a};return w.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:e})})}(s);if(!a)return{code:0,data:{}};var{ErrorCode:i,ErrorInfo:n,GroupMembers:c=[],Cursor:d,TotalCount:l}=a;if(0!==i)throw{errorCode:i,errorInfo:n};var h=`keywordList:${p.keywordList} keywordListMatchType:${p.keywordListMatchType} cursor:${p.cursor} count:${p.count} res: totalCount:`+l;e.setLogInfo({message:h}).end();let u=new Map;return c.forEach(e=>{var{GroupID:r,GroupName:e,GroupType:t,GroupFaceUrl:o,GroupMemberUserName:s,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:n=""}=e,e={groupID:r,name:e,type:t,avatar:o},t={userID:a,nick:s,nameCard:i,avatar:n};if(u.has(r)){let e=u.get(r);e.memberList.push(t),u.set(r,e)}else u.set(r,{groupInfo:e,memberList:[t]})}),{code:0,data:{searchResultList:[...u.values()],cursor:d,totalCount:l}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudGroupMembers"})}})}searchCloudGroups(h){return L(this,void 0,void 0,function*(){try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:r=20,keywordListMatchType:t}=h,o=f(h,["count","keywordListMatchType"]),s=Object.assign({count:r,keywordListMatchType:t===m.AND?1:0},o),a=yield function(a){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,groupTypeList:o,cursor:s}=a,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:s,GroupType:o};return w.core.common.buildAndSendPacket({servcmd:"group_search.query",data:e})})}(s);if(!a)return{code:0,data:{}};var{ErrorCode:i,ErrorInfo:n,Groups:u,Cursor:c,TotalCount:d}=a;if(0!==i)throw{errorCode:i,errorInfo:n};var l=`keywordList:${h.keywordList} keywordListMatchType:${h.keywordListMatchType} cursor:${h.cursor} count:${h.count} res: totalCount:`+d;return e.setLogInfo({message:l}).end(),{code:0,data:{searchResultList:(null==u?void 0:u.map(e=>{var{GroupFaceUrl:e,GroupID:r,GroupIntroduction:t,GroupMemberNum:o,GroupName:s,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:n,GroupType:u,GroupAddOption:c,GroupInviteOption:d}=e;return{avatar:e,groupID:r,introduction:t,memberCount:o,name:s,ownerTinyID:a,ownerID:i,ownerNick:n,type:u,joinOption:c,inviteOption:d}}))||[],cursor:c,totalCount:d}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudGroups"})}})}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&0<r&&(e.startTime=t&&0<t?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&0<t&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:o}){var{ssoLog:s,helper:a}=this._core;let i=e;60020===e?i="SearchUnable":t!==n&&27003===e?i="SearchParamsError":t!==n&&60018===e&&(i="SearchOverLimit");t=new a.ChatError({code:i,message:r});throw s.getSSOLogData(o).setError(t).end(),t}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){var{miniBirthday:r,maxBirthday:t}=r;void 0!==r&&(e.miniBirthday=r,void 0===t)&&(e.maxBirthday=4294967295),void 0!==t&&(e.maxBirthday=t)}}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=new class{constructor(){this._conversationGroupMap=new Map}init(e){this._core=e}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(e){return this._conversationGroupMap.get(e)}setConversationGroup(e,t){this._conversationGroupMap.set(e,t)}};function o(e,s,i,c){return new(i=i||Promise)(function(o,t){function r(e){try{a(c.next(e))}catch(e){t(e)}}function n(e){try{a(c.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?o(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(r,n)}a((c=c.apply(e,s||[])).next())})}let e=new class{init(e){this.core=e}},n="CONV_GROUP",r=2500,s=2503,a=1,i=2,c="NOT_STARTED",u="FETCHING",p="FINISHED",d="FAILED",v=0,l=1,C=1,h=2,m=3,f=1,I=2;function G(t){var{helper:o,constants:r}=e.core;if(!o.checkBusinessCapabilityBits(n))throw new o.ChatError({functionName:t,code:r.ERROR_CODE.NO_USE,replacement1:t})}function g(){var{notificationCenter:o,OuterEvent:r}=e.core;o.emitOuterEvent(r.CONVERSATION_GROUP_LIST_UPDATED,{name:r.CONVERSATION_GROUP_LIST_UPDATED,data:[...t.getConversationGroupMap().values()]})}function _(t){var{utils:{isUndefined:o},constants:{OuterConstant:r}}=e.core,{Type:t,To_Account:n,GroupId:s,ToGroupId:s=s,Peer_Account:c}=t;let u="";return t===a?o(c)?o(n)||(u=""+r.CONV_C2C+n):u=""+r.CONV_C2C+c:t===i&&(u=""+r.CONV_GROUP+s),u}function D(t){let o=[],{OuterConstant:r,common:{isC2CConv:n,isGroupConv:s}}=e.core,{conversationIDList:c,failureConversationIDList:u,additionalData:p={}}=t;return c.forEach(e=>{L(e,u),n(e)?o.push(Object.assign({ContactItem:{Type:a,To_Account:e.replace(r.CONV_C2C,"")}},p)):s(e)&&o.push(Object.assign({ContactItem:{Type:i,ToGroupId:e.replace(r.CONV_GROUP,"")}},p))}),o}function L(t,o){var{appStore:{conversationStore:n},common:{isC2CConv:a,isGroupConv:i}}=e.core;n.getConversation(t)?a(t)||i(t)||o.push({conversationID:t,code:s}):o.push({conversationID:t,code:r})}function N(t){var{isString:o}=e.core["utils"],r=[];if(o(t)){var n=t.length;if(0!==n)for(let e=n-1;0<=e;e--)"1"===t[e]&&r.push(Math.pow(2,n-e-1))}return r}function E(a){null!=a&&a.forEach((t,o)=>{var r=e.core["appStore"],{conversationID:t,data:n}=t,o=o===a.length-1;r.conversationStore.updateConversation(t,n,{emit:o})})}function S(t){var{conversationInfoList:t,fromAccount:o}=t,o={From_Account:o,MarkItem:t};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:o})}function O(t){var{fromAccount:t,groupName:o,conversationInfoList:r}=t,t={From_Account:t,UpdateType:1,UpdateGroup:{UpdateGroupType:I,OldGroupName:o,ContactUpdateItem:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:t})}var R=new class{init(e){var{registerApi:t}=e["helper"];this._core=e,t({apiName:"createConversationGroup",context:this})}createConversationGroup(a){return o(this,void 0,void 0,function*(){let{utils:{isPlainObject:s,isArray:i},appStore:c,ssoLog:o}=this._core;G("createConversationGroup");var u=o.createSSOLogData({method:"createConversationGroup"});u.setLogInfo({message:JSON.stringify(a)});let{groupName:p,conversationIDList:r}=a,l=[],n=this._generateConversationInfo(r,l);if(l.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:l}};try{let a=yield function(t){var{buildAndSendPacket:o,getCurrentUserID:r}=e.core["common"],{item:t,groupName:n}=t;return o({servcmd:"recentcontact.create_contact_group",data:{From_Account:r(),GroupContactItem:[{GroupName:n,ContactItem:t}]}})}({groupName:p,item:n});if(a){u.end();let{GroupResultItem:e=[]}=a,{GroupItem:r,ResultItem:o}=(null==e?void 0:e[0])||{},n=[];if(s(r)){let{GroupName:e,GroupId:o}=r;t.setConversationGroup(o,e),g()}if(i(o)){let a=[];o.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:r}=e,n=_(t);if(0===o){let t=c.conversationStore.getConversation(n);if(t&&!t.conversationGroupList.includes(p)){let e=t.conversationGroupList.slice();e.push(p),a.push({conversationID:n,data:{conversationGroupList:e}})}}else l.push({conversationID:n,code:o,message:r})}),0<a.length&&(E(a),g())}return{code:0,data:{successConversationIDList:n,failureConversationIDList:l}}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"createConversationGroup",code:t,message:o});throw u.setError(r).end(),r}})}_generateConversationInfo(e,t,o={}){let r=[],{OuterConstant:n,common:{isC2CConv:s,isGroupConv:c}}=this._core;return e.forEach(e=>{L(e,t),s(e)?r.push(Object.assign({Type:a,To_Account:e.replace(n.CONV_C2C,"")},o)):c(e)&&r.push(Object.assign({Type:i,ToGroupId:e.replace(n.CONV_GROUP,"")},o))}),r}},A=new class{constructor(){this._fetchConversationGroupStatus=c}init(e){var{helper:{registerApi:t,registerWorkflowStep:o},constants:{WORKFLOW_NAME:r,WORKFLOW_STEP:n}}=e;this._core=e,t({apiName:"getConversationGroupList",context:this}),o(r.SYNC_SERVER_INFO_AFTER_LOGIN,n.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),o(r.SYNC_SERVER_INFO_AFTER_LOGIN,n.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,function*(){return G("getConversationGroupList"),this._fetchConversationGroupStatus===d&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...t.getConversationGroupMap().values()]}})}_syncConversationGroupList(){return o(this,void 0,void 0,function*(){return yield this._fetchConversationGroupList(0)})}_fetchConversationGroupList(r){return o(this,arguments,void 0,function*(n,s=[]){let{common:{getCurrentUserID:o},utils:{isArray:i}}=this._core;this._fetchConversationGroupStatus=u;try{let r=o(),a=yield function(){var{fromAccount:t,startIndex:o}={fromAccount:r,startIndex:n},t={From_Account:t,StartIndex:o};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:t})}();if(a){let{CompleteFlag:e,ContactItem:o=[],NextStartIndex:r=0,GroupItem:n=[]}=a;return(i(n)&&n.forEach(e=>{var{GroupName:e,GroupId:o}=e;t.setConversationGroup(o,e)}),s.push(...o),e===v)?this._fetchConversationGroupList(r):e===l?(this._fetchConversationGroupStatus=p,s):void 0}}catch(e){this._fetchConversationGroupStatus=d,console.error(e)}})}_updateConversation(e){var t=this._core["constants"]["WORKFLOW_STEP"],e=(null==(e=null==e?void 0:e.result)?void 0:e[t.CONVERSATION_GROUP_LIST_SYNC])||[];E(this._generateConversationUpdateFields(e)),g()}_generateConversationUpdateFields(e){let{utils:{isArray:i},appStore:c}=this._core,u=[];if(i(e)){let s;e.forEach(e=>{let o=[],{StandardMark:r,CustomMark:n="",ContactGroupId:a}=e;i(a)&&a.forEach(e=>{t.getConversationGroupMap().has(e)&&o.push(t.getConversationGroup(e))});e=_(e);(s=c.conversationStore.getConversation(e))&&u.push({conversationID:e,data:{markList:N(r),customData:n,conversationGroupList:[...o]}})})}return u}reset(){this._fetchConversationGroupStatus=c}dispose(){this.reset()}},T=new class{init(e){var{notificationCenter:t,helper:{registerApi:o},InnerEvent:{MESSAGE_PUSH:r},InnerEventSubType:{CONVERSATION_MARK_UPDATED:n,CONVERSATION_GROUP_ADD:a,CONVERSATION_GROUP_DELETED:s,CONVERSATION_GROUP_UPDATED:i}}=e;this._core=e,o({apiName:"renameConversationGroup",context:this}),o({apiName:"deleteConversationGroup",context:this}),o({apiName:"markConversation",context:this}),o({apiName:"setConversationCustomData",context:this}),o({apiName:"deleteConversationsFromGroup",context:this}),o({apiName:"addConversationsToGroup",context:this}),t.subscribeInnerEvent(r,a,this._handleConversationGroupAdd,this),t.subscribeInnerEvent(r,s,this._handleConversationGroupDeleted,this),t.subscribeInnerEvent(r,i,this._handleConversationGroupUpdated,this),t.subscribeInnerEvent(r,n,this._handleConversationMarkUpdated,this)}renameConversationGroup(r){return o(this,void 0,void 0,function*(){G("renameConversationGroup");let{common:{getCurrentUserID:n},ssoLog:o}=this._core,{oldName:a,newName:s}=r,i=o.createSSOLogData({method:"renameConversationGroup"});i.setLogInfo({message:`oldName:${a} newName:`+s});try{let r=yield function(){var{fromAccount:t,oldName:o,newName:r}={fromAccount:n(),oldName:a,newName:s},t={From_Account:t,UpdateType:1,UpdateGroup:{UpdateGroupType:f,OldGroupName:o,NewGroupName:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:t})}();if(r){i.end();let e=r["UpdateGroupResult"],o=e["GroupId"];t.setConversationGroup(o,s),g(),this._updateLocalConversationGroupName({oldName:a,newName:s})}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"renameConversationGroup",code:t,message:o});throw i.setError(r).end(),r}})}deleteConversationGroup(a){return o(this,void 0,void 0,function*(){G("deleteConversationGroup");let{common:{getCurrentUserID:r},ssoLog:o}=this._core,n=o.createSSOLogData({method:"deleteConversationGroup"});n.setLogInfo({message:"groupName:"+a});try{let o=yield function(){var{fromAccount:t,groupName:o}={fromAccount:r(),groupName:a},t={From_Account:t,GroupName:[o]};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:t})}();if(o){let e=o["GroupItem"],r=!1;null!=e&&e.forEach(e=>{var e=e["GroupId"],o=t.getConversationGroupMap();o.has(e)&&(o.delete(e),r=!0)}),r&&g(),this._deleteLocalConversationGroupName([a])}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:t,message:o});throw n.setError(r).end(),r}})}markConversation(h){return o(this,void 0,void 0,function*(){G("markConversation");let{utils:{isNumber:e},common:{getCurrentUserID:o},ssoLog:t,appStore:s}=this._core,{conversationIDList:r,markType:i,enableMark:c}=h,n=this._getFlagBit(i),u=[],p=[],a,l;var d=t.createSSOLogData({method:"markConversation"}),v=(d.setLogInfo({message:JSON.stringify(h)}),!0===c&&e(n)?a=[n]:l=[n],D({conversationIDList:r,failureConversationIDList:u,additionalData:{SetMark:a,ClearMark:l,OptType:C}}));if(u.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:u}};try{let t=yield S({conversationInfoList:v,fromAccount:o()});if(t){d.end();let e=t["ResultItem"],a=[];e.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:r}=e,n=_(t);if(0===o){p.push(n);let o=s.conversationStore.getConversation(n);if(o){let t=o.markList.indexOf(i),e=!1===c&&-1!==t;if(!0===c&&-1===t)a.push({conversationID:n,data:{markList:[...o.markList,i]}});else if(e){let e=o.markList.slice();e.splice(t,1),a.push({conversationID:n,data:{markList:e}})}}}else u.push({conversationID:n,code:o,message:r})}),E(a)}return{code:0,data:{successConversationIDList:p,failureConversationIDList:u}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"markConversation",code:t,message:o});throw d.setError(r).end(),r}})}setConversationCustomData(n){return o(this,void 0,void 0,function*(){G("setConversationCustomData");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,{conversationIDList:o,customData:s}=n,i=[],c=[],u=t.createSSOLogData({method:"setConversationCustomData"});u.setLogInfo({message:JSON.stringify(n)});var r=D({conversationIDList:o,failureConversationIDList:i,additionalData:{CustomMark:s,OptType:h}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield S({fromAccount:e(),conversationInfoList:r});if(t){u.end();let e=t["ResultItem"],n=[];null!=e&&e.forEach(e=>{let{ContactItem:o,ResultCode:t,ResultInfo:r}=e;if(0===t){let e=_(o),t=(c.push(e),a.conversationStore.getConversation(e));t&&t.customData!==s&&n.push({conversationID:e,data:{customData:s}})}else i.push({conversationID:conversationID,code:t,message:r})}),E(n)}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"setConversationCustomData",code:t,message:o});throw u.setError(r).end(),r}})}deleteConversationsFromGroup(n){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,s=t.createSSOLogData({method:"deleteConversationsFromGroup"}),{conversationIDList:o,groupName:i}=(s.setLogInfo({message:JSON.stringify(n)}),n),c=[],u=[],r=D({conversationIDList:o,failureConversationIDList:c,additionalData:{ContactOptType:2}});if(c.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{let t=yield O({fromAccount:e(),groupName:i,conversationInfoList:r});if(t){s.end();let n=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o,r=_(e.ContactItem);if(0===e.ResultCode){let t=a.conversationStore.getConversation(r);if(t){let e=t.conversationGroupList.indexOf(i);-1!==e&&((o=t.conversationGroupList.slice()).splice(e,1),u.push(r),n.push({conversationID:r,data:{conversationGroupList:o}}))}}else c.push({conversationID:r,code:e.ResultCode,message:e.ResultInfo})}),0<n.length&&(g(),E(n))}return{code:0,data:{successConversationIDList:u,failureConversationIDList:c}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw s.setError(r).end(),r}})}addConversationsToGroup(u){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:n}=this._core,a=t.createSSOLogData({method:"addConversationsToGroup"}),{conversationIDList:o,groupName:s}=(a.setLogInfo({message:JSON.stringify(u)}),u),i=[],c=[],r=D({conversationIDList:o,failureConversationIDList:i,additionalData:{ContactOptType:1}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield O({fromAccount:e(),groupName:s,conversationInfoList:r});if(t){a.end();let r=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o=_(e.ContactItem);if(0===e.ResultCode){let t=n.conversationStore.getConversation(o);if(t&&-1===t.conversationGroupList.indexOf(s)){let e=t.conversationGroupList.slice();e.push(s),c.push(o),r.push({conversationID:o,data:{conversationGroupList:e}})}}else i.push({conversationID:o,code:e.ResultCode,message:e.ResultInfo})}),0<r.length&&(g(),E(r))}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw a.setError(r).end(),r}})}_updateLocalConversationGroupName(e){let t=this._core["appStore"],{oldName:o,newName:r}=e,n=[],a=[],s;Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var t;n=e.conversationGroupList,-1!==(s=n.indexOf(o))&&((t=n.slice()).splice(s,1,r),a.push({conversationID:e.conversationID,data:{conversationGroupList:t}}))}),E(a)}_deleteLocalConversationGroupName(n){var{utils:{isEmpty:e},appStore:t}=this._core;if(!e(n)){let r=[];Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var{conversationID:e,conversationGroupList:t}=e,o=t.filter(e=>!n.includes(e));o.length<t.length&&r.push({conversationID:e,data:{conversationGroupList:o}})}),E(r)}}_getFlagBit(e){var t=e.toString(2),o=t.length;for(let e=o-1;0<=e;e--)if("1"===t[e])return o-e-1}_handleConversationGroupAdd(e){let o,{utils:{isArray:c},appStore:u}=this._core;null!=(o=null==e?void 0:e.RecentContactMod)&&o.forEach(e=>{var e=e["RecentContactCreateContactGroup"]["MsgContactGroupContactItem"];let i=!1;null!=e&&e.forEach(e=>{let{MsgGroupItem:o,MsgRecentContactItem:r}=e,{GroupId:n,GroupName:a}=o,s=[];t.getConversationGroup(n)!==a&&(t.setConversationGroup(n,a),i=!0),c(r)&&r.forEach(e=>{var t=_(e),o=u.conversationStore.getConversation(t);if(o&&(null==(e=o.conversationGroupList)||!e.includes(a))){let e=o.conversationGroupList.slice();e.push(a),s.push({conversationID:t,data:{conversationGroupList:e}})}}),i&&g(),E(s)})})}_handleConversationGroupDeleted(e){let o,{isArray:r}=this._core.utils;null!=(o=null==e?void 0:e.RecentContactMod)&&o.forEach(e=>{e=((null==e?void 0:e.RecentContactDelContactGroup)||{}).MsgGroupItem;if(r(e)){let n=!1,a=[];e.forEach(e=>{var{GroupId:e,GroupName:o}=e,r=t.getConversationGroupMap();r.has(e)&&(r.delete(e),n=!0,a.push(o))}),n&&g(),0<a.length&&this._deleteLocalConversationGroupName(a)}})}_handleConversationGroupUpdated(e){null!=(e=e.RecentContactMod)&&e.forEach(e=>{var{GroupId:e,GroupName:t,OldGroupName:o,RecentContactUpdateGroupItem:r,UpdateGroupType:n}=e["RecentContactUpdateContactGroup"]["MsgUpdateGroup"];1===n?this._handleGroupNameUpdated({groupID:e,newName:t,oldName:o}):2===n&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:r,groupName:o})})}_handleConversationMarkUpdated(e){let t,a=this._core.appStore;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{let{RecentContactMarkContactItem:t}=e["RecentContactMarkContact"],n=[];null!=t&&t.forEach(e=>{var{RecentContactItem:e,CustomMark:t,StandardMark:o,OptType:r}=e,e=_(e),e=a.conversationStore.getConversation(e);e&&(r===C?this._updateStandMark({conversation:e,standardMark:o,updateConversationList:n}):r===h?this._updateCustomMark({conversation:e,customMark:t,updateConversationList:n}):r===m&&(this._updateStandMark({conversation:e,standardMark:o,updateConversationList:n}),this._updateCustomMark({conversation:e,customMark:t,updateConversationList:n})))}),E(n)})}_updateStandMark(e){var{conversation:e,standardMark:t,updateConversationList:o}=e,t=N(t);!function(o,r){if(o===r)return 1;if(o&&r&&o.length===r.length){o.sort(),r.sort();for(let e=0,t=o.length;e<t;e++)if(o[e]!==r[e])return;return 1}}(e.markList,t)&&o.push({conversationID:e.conversationID,data:{markList:t}})}_updateCustomMark(e){var{conversation:e,customMark:t,updateConversationList:o}=e;e.customData!==t&&void 0!==t&&(e.customData=t,o.push({conversationID:e.conversationID,data:{customData:t}}))}_handleGroupNameUpdated(e){var{groupID:e,oldName:o,newName:r}=e;t.getConversationGroup(e)!==r&&(t.setConversationGroup(e,r),g(),this._updateLocalConversationGroupName({oldName:o,newName:r}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:e,groupName:a}){let s=this._core["appStore"],i=[];e.forEach(e=>{var{RecentContactItem:e,ContactOptType:t}=e,o=_(e),r=s.conversationStore.getConversation(o),n=r.conversationGroupList.indexOf(a);if(r){let e=r.conversationGroupList.slice();1===t&&-1===n?(e.push(a),i.push({conversationID:o,data:{conversationGroupList:e}})):2===t&&-1!==n&&(e.splice(n,1),i.push({conversationID:o,data:{conversationGroupList:e}}))}}),E(i)}dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t},InnerEventSubType:{CONVERSATION_MARK_UPDATED:o,CONVERSATION_GROUP_ADD:r,CONVERSATION_GROUP_DELETED:n,CONVERSATION_GROUP_UPDATED:a}}=this._core;e.unSubscribeInnerEvent(t,r,this._handleConversationGroupAdd,this),e.unSubscribeInnerEvent(t,n,this._handleConversationGroupDeleted,this),e.unSubscribeInnerEvent(t,a,this._handleConversationGroupUpdated,this),e.unSubscribeInnerEvent(t,o,this._handleConversationMarkUpdated,this)}};let y={required:!0,rules:["string"],allowEmpty:!1},U={required:!0,rules:["array"],allowEmpty:!1},M={createConversationGroup:{groupName:y,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:y,newName:Object.assign(Object.assign({},y),{customValidator:e=>!(32<e.length)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:U,groupName:y},deleteConversationsFromGroup:{conversationIDList:U,groupName:y},markConversation:{conversationIDList:U,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:e=>e<=0?"markType must be greater than 0":!(e>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:U,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>"string"!=typeof e?"customData must be string":!(256<e.length)||"customData length cannot longer than 256"}}},k={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};var b=new class{install(o){this._core=o,e.init(o),t.init(o),R.init(o),A.init(o),T.init(o),o.helper.registerValidateConfig({auth:k,params:M}),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.LOGOUT,this.reset,this),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.DESTROY,this.dispose,this)}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.DESTROY,this.dispose,this),T.dispose(),A.dispose()}reset(){A.reset()}};export{b as default};
|
|
1
|
+
var t=new class{constructor(){this._conversationGroupMap=new Map}init(e){this._core=e}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(e){return this._conversationGroupMap.get(e)}setConversationGroup(e,t){this._conversationGroupMap.set(e,t)}};function o(e,s,i,c){return new(i=i||Promise)(function(o,t){function r(e){try{a(c.next(e))}catch(e){t(e)}}function n(e){try{a(c.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?o(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(r,n)}a((c=c.apply(e,s||[])).next())})}let e=new class{init(e){this.core=e}},n="CONV_GROUP",r=2500,s=2503,a=1,i=2,c="NOT_STARTED",u="FETCHING",p="FINISHED",d="FAILED",v=0,l=1,C=1,h=2,m=3,f=1,I=2;function G(t){var{helper:o,constants:r}=e.core;if(!o.checkBusinessCapabilityBits(n))throw new o.ChatError({functionName:t,code:r.ERROR_CODE.NO_USE,replacement1:t})}function g(){var{notificationCenter:o,OuterEvent:r}=e.core;o.emitOuterEvent(r.CONVERSATION_GROUP_LIST_UPDATED,{name:r.CONVERSATION_GROUP_LIST_UPDATED,data:[...t.getConversationGroupMap().values()]})}function _(t){var{utils:{isUndefined:o},constants:{OuterConstant:r}}=e.core,{Type:t,To_Account:n,GroupId:s,ToGroupId:s=s,Peer_Account:c}=t;let u="";return t===a?o(c)?o(n)||(u=""+r.CONV_C2C+n):u=""+r.CONV_C2C+c:t===i&&(u=""+r.CONV_GROUP+s),u}function D(t){let o=[],{OuterConstant:r,common:{isC2CConv:n,isGroupConv:s}}=e.core,{conversationIDList:c,failureConversationIDList:u,additionalData:p={}}=t;return c.forEach(e=>{L(e,u),n(e)?o.push(Object.assign({ContactItem:{Type:a,To_Account:e.replace(r.CONV_C2C,"")}},p)):s(e)&&o.push(Object.assign({ContactItem:{Type:i,ToGroupId:e.replace(r.CONV_GROUP,"")}},p))}),o}function L(t,o){var{appStore:{conversationStore:n},common:{isC2CConv:a,isGroupConv:i}}=e.core;n.getConversation(t)?a(t)||i(t)||o.push({conversationID:t,code:s}):o.push({conversationID:t,code:r})}function N(t){var{isString:o}=e.core["utils"],r=[];if(o(t)){var n=t.length;if(0!==n)for(let e=n-1;0<=e;e--)"1"===t[e]&&r.push(Math.pow(2,n-e-1))}return r}function E(a){null!=a&&a.forEach((t,o)=>{var r=e.core["appStore"],{conversationID:t,data:n}=t,o=o===a.length-1;r.conversationStore.updateConversation(t,n,{emit:o})})}function S(t){var{conversationInfoList:t,fromAccount:o}=t,o={From_Account:o,MarkItem:t};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:o})}function O(t){var{fromAccount:t,groupName:o,conversationInfoList:r}=t,t={From_Account:t,UpdateType:1,UpdateGroup:{UpdateGroupType:I,OldGroupName:o,ContactUpdateItem:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:t})}var R=new class{init(e){var{registerApi:t}=e["helper"];this._core=e,t({apiName:"createConversationGroup",context:this})}createConversationGroup(a){return o(this,void 0,void 0,function*(){let{utils:{isPlainObject:s,isArray:i},appStore:c,ssoLog:o}=this._core;G("createConversationGroup");var u=o.createSSOLogData({method:"createConversationGroup"});u.setLogInfo({message:JSON.stringify(a)});let{groupName:p,conversationIDList:r}=a,l=[],n=this._generateConversationInfo(r,l);if(l.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:l}};try{let a=yield function(t){var{buildAndSendPacket:o,getCurrentUserID:r}=e.core["common"],{item:t,groupName:n}=t;return o({servcmd:"recentcontact.create_contact_group",data:{From_Account:r(),GroupContactItem:[{GroupName:n,ContactItem:t}]}})}({groupName:p,item:n});if(a){u.end();let{GroupResultItem:e=[]}=a,{GroupItem:r,ResultItem:o}=(null==e?void 0:e[0])||{},n=[];if(s(r)){let{GroupName:e,GroupId:o}=r;t.setConversationGroup(o,e),g()}if(i(o)){let a=[];o.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:r}=e,n=_(t);if(0===o){let t=c.conversationStore.getConversation(n);if(t&&!t.conversationGroupList.includes(p)){let e=t.conversationGroupList.slice();e.push(p),a.push({conversationID:n,data:{conversationGroupList:e}})}}else l.push({conversationID:n,code:o,message:r})}),0<a.length&&(E(a),g())}return{code:0,data:{successConversationIDList:n,failureConversationIDList:l}}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"createConversationGroup",code:t,message:o});throw u.setError(r).end(),r}})}_generateConversationInfo(e,t,o={}){let r=[],{OuterConstant:n,common:{isC2CConv:s,isGroupConv:c}}=this._core;return e.forEach(e=>{L(e,t),s(e)?r.push(Object.assign({Type:a,To_Account:e.replace(n.CONV_C2C,"")},o)):c(e)&&r.push(Object.assign({Type:i,ToGroupId:e.replace(n.CONV_GROUP,"")},o))}),r}},A=new class{constructor(){this._fetchConversationGroupStatus=c}init(e){var{helper:{registerApi:t,registerWorkflowStep:o},constants:{WORKFLOW_NAME:r,WORKFLOW_STEP:n}}=e;this._core=e,t({apiName:"getConversationGroupList",context:this}),o(r.SYNC_SERVER_INFO_AFTER_LOGIN,n.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),o(r.SYNC_SERVER_INFO_AFTER_LOGIN,n.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,function*(){return G("getConversationGroupList"),this._fetchConversationGroupStatus===d&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...t.getConversationGroupMap().values()]}})}_syncConversationGroupList(){return o(this,void 0,void 0,function*(){return yield this._fetchConversationGroupList(0)})}_fetchConversationGroupList(r){return o(this,arguments,void 0,function*(n,s=[]){let{common:{getCurrentUserID:o},utils:{isArray:i}}=this._core;this._fetchConversationGroupStatus=u;try{let r=o(),a=yield function(){var{fromAccount:t,startIndex:o}={fromAccount:r,startIndex:n},t={From_Account:t,StartIndex:o};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:t})}();if(a){let{CompleteFlag:e,ContactItem:o=[],NextStartIndex:r=0,GroupItem:n=[]}=a;return(i(n)&&n.forEach(e=>{var{GroupName:e,GroupId:o}=e;t.setConversationGroup(o,e)}),s.push(...o),e===v)?this._fetchConversationGroupList(r):e===l?(this._fetchConversationGroupStatus=p,s):void 0}}catch(e){this._fetchConversationGroupStatus=d,console.error(e)}})}_updateConversation(e){var t=this._core["constants"]["WORKFLOW_STEP"],e=(null==(e=null==e?void 0:e.result)?void 0:e[t.CONVERSATION_GROUP_LIST_SYNC])||[];E(this._generateConversationUpdateFields(e)),g()}_generateConversationUpdateFields(e){let{utils:{isArray:i},appStore:c}=this._core,u=[];if(i(e)){let s;e.forEach(e=>{let o=[],{StandardMark:r,CustomMark:n="",ContactGroupId:a}=e;i(a)&&a.forEach(e=>{t.getConversationGroupMap().has(e)&&o.push(t.getConversationGroup(e))});e=_(e);(s=c.conversationStore.getConversation(e))&&u.push({conversationID:e,data:{markList:N(r),customData:n,conversationGroupList:[...o]}})})}return u}reset(){this._fetchConversationGroupStatus=c}dispose(){this.reset()}},T=new class{init(e){var{notificationCenter:t,helper:{registerApi:o},InnerEvent:{MESSAGE_PUSH:r},InnerEventSubType:{CONVERSATION_MARK_UPDATED:n,CONVERSATION_GROUP_ADD:a,CONVERSATION_GROUP_DELETED:s,CONVERSATION_GROUP_UPDATED:i}}=e;this._core=e,o({apiName:"renameConversationGroup",context:this}),o({apiName:"deleteConversationGroup",context:this}),o({apiName:"markConversation",context:this}),o({apiName:"setConversationCustomData",context:this}),o({apiName:"deleteConversationsFromGroup",context:this}),o({apiName:"addConversationsToGroup",context:this}),t.subscribeInnerEvent(r,a,this._handleConversationGroupAdd,this),t.subscribeInnerEvent(r,s,this._handleConversationGroupDeleted,this),t.subscribeInnerEvent(r,i,this._handleConversationGroupUpdated,this),t.subscribeInnerEvent(r,n,this._handleConversationMarkUpdated,this)}renameConversationGroup(r){return o(this,void 0,void 0,function*(){G("renameConversationGroup");let{common:{getCurrentUserID:n},ssoLog:o}=this._core,{oldName:a,newName:s}=r,i=o.createSSOLogData({method:"renameConversationGroup"});i.setLogInfo({message:`oldName:${a} newName:`+s});try{let r=yield function(){var{fromAccount:t,oldName:o,newName:r}={fromAccount:n(),oldName:a,newName:s},t={From_Account:t,UpdateType:1,UpdateGroup:{UpdateGroupType:f,OldGroupName:o,NewGroupName:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:t})}();if(r){i.end();let e=r["UpdateGroupResult"],o=e["GroupId"];t.setConversationGroup(o,s),g(),this._updateLocalConversationGroupName({oldName:a,newName:s})}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"renameConversationGroup",code:t,message:o});throw i.setError(r).end(),r}})}deleteConversationGroup(a){return o(this,void 0,void 0,function*(){G("deleteConversationGroup");let{common:{getCurrentUserID:r},ssoLog:o}=this._core,n=o.createSSOLogData({method:"deleteConversationGroup"});n.setLogInfo({message:"groupName:"+a});try{let o=yield function(){var{fromAccount:t,groupName:o}={fromAccount:r(),groupName:a},t={From_Account:t,GroupName:[o]};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:t})}();if(o){let e=o["GroupItem"],r=!1;null!=e&&e.forEach(e=>{var e=e["GroupId"],o=t.getConversationGroupMap();o.has(e)&&(o.delete(e),r=!0)}),r&&g(),this._deleteLocalConversationGroupName([a])}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:t,message:o});throw n.setError(r).end(),r}})}markConversation(h){return o(this,void 0,void 0,function*(){G("markConversation");let{utils:{isNumber:e},common:{getCurrentUserID:o},ssoLog:t,appStore:s}=this._core,{conversationIDList:r,markType:i,enableMark:c}=h,n=this._getFlagBit(i),u=[],p=[],a,l;var d=t.createSSOLogData({method:"markConversation"}),v=(d.setLogInfo({message:JSON.stringify(h)}),!0===c&&e(n)?a=[n]:l=[n],D({conversationIDList:r,failureConversationIDList:u,additionalData:{SetMark:a,ClearMark:l,OptType:C}}));if(u.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:u}};try{let t=yield S({conversationInfoList:v,fromAccount:o()});if(t){d.end();let e=t["ResultItem"],a=[];e.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:r}=e,n=_(t);if(0===o){p.push(n);let o=s.conversationStore.getConversation(n);if(o){let t=o.markList.indexOf(i),e=!1===c&&-1!==t;if(!0===c&&-1===t)a.push({conversationID:n,data:{markList:[...o.markList,i]}});else if(e){let e=o.markList.slice();e.splice(t,1),a.push({conversationID:n,data:{markList:e}})}}}else u.push({conversationID:n,code:o,message:r})}),E(a)}return{code:0,data:{successConversationIDList:p,failureConversationIDList:u}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"markConversation",code:t,message:o});throw d.setError(r).end(),r}})}setConversationCustomData(n){return o(this,void 0,void 0,function*(){G("setConversationCustomData");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,{conversationIDList:o,customData:s}=n,i=[],c=[],u=t.createSSOLogData({method:"setConversationCustomData"});u.setLogInfo({message:JSON.stringify(n)});var r=D({conversationIDList:o,failureConversationIDList:i,additionalData:{CustomMark:s,OptType:h}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield S({fromAccount:e(),conversationInfoList:r});if(t){u.end();let e=t["ResultItem"],n=[];null!=e&&e.forEach(e=>{let{ContactItem:o,ResultCode:t,ResultInfo:r}=e;if(0===t){let e=_(o),t=(c.push(e),a.conversationStore.getConversation(e));t&&t.customData!==s&&n.push({conversationID:e,data:{customData:s}})}else i.push({conversationID:conversationID,code:t,message:r})}),E(n)}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"setConversationCustomData",code:t,message:o});throw u.setError(r).end(),r}})}deleteConversationsFromGroup(n){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,s=t.createSSOLogData({method:"deleteConversationsFromGroup"}),{conversationIDList:o,groupName:i}=(s.setLogInfo({message:JSON.stringify(n)}),n),c=[],u=[],r=D({conversationIDList:o,failureConversationIDList:c,additionalData:{ContactOptType:2}});if(c.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{let t=yield O({fromAccount:e(),groupName:i,conversationInfoList:r});if(t){s.end();let n=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o,r=_(e.ContactItem);if(0===e.ResultCode){let t=a.conversationStore.getConversation(r);if(t){let e=t.conversationGroupList.indexOf(i);-1!==e&&((o=t.conversationGroupList.slice()).splice(e,1),u.push(r),n.push({conversationID:r,data:{conversationGroupList:o}}))}}else c.push({conversationID:r,code:e.ResultCode,message:e.ResultInfo})}),0<n.length&&(g(),E(n))}return{code:0,data:{successConversationIDList:u,failureConversationIDList:c}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw s.setError(r).end(),r}})}addConversationsToGroup(u){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:n}=this._core,a=t.createSSOLogData({method:"addConversationsToGroup"}),{conversationIDList:o,groupName:s}=(a.setLogInfo({message:JSON.stringify(u)}),u),i=[],c=[],r=D({conversationIDList:o,failureConversationIDList:i,additionalData:{ContactOptType:1}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield O({fromAccount:e(),groupName:s,conversationInfoList:r});if(t){a.end();let r=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o=_(e.ContactItem);if(0===e.ResultCode){let t=n.conversationStore.getConversation(o);if(t&&-1===t.conversationGroupList.indexOf(s)){let e=t.conversationGroupList.slice();e.push(s),c.push(o),r.push({conversationID:o,data:{conversationGroupList:e}})}}else i.push({conversationID:o,code:e.ResultCode,message:e.ResultInfo})}),0<r.length&&(g(),E(r))}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw a.setError(r).end(),r}})}_updateLocalConversationGroupName(e){let t=this._core["appStore"],{oldName:o,newName:r}=e,n=[],a=[],s;Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var t;n=e.conversationGroupList,-1!==(s=n.indexOf(o))&&((t=n.slice()).splice(s,1,r),a.push({conversationID:e.conversationID,data:{conversationGroupList:t}}))}),E(a)}_deleteLocalConversationGroupName(n){var{utils:{isEmpty:e},appStore:t}=this._core;if(!e(n)){let r=[];Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var{conversationID:e,conversationGroupList:t}=e,o=t.filter(e=>!n.includes(e));o.length<t.length&&r.push({conversationID:e,data:{conversationGroupList:o}})}),E(r)}}_getFlagBit(e){var t=e.toString(2),o=t.length;for(let e=o-1;0<=e;e--)if("1"===t[e])return o-e-1}_handleConversationGroupAdd(e){let o,{utils:{isArray:c},appStore:u}=this._core;null!=(o=null==e?void 0:e.RecentContactMod)&&o.forEach(e=>{var e=e["RecentContactCreateContactGroup"]["MsgContactGroupContactItem"];let i=!1;null!=e&&e.forEach(e=>{let{MsgGroupItem:o,MsgRecentContactItem:r}=e,{GroupId:n,GroupName:a}=o,s=[];t.getConversationGroup(n)!==a&&(t.setConversationGroup(n,a),i=!0),c(r)&&r.forEach(e=>{var t=_(e),o=u.conversationStore.getConversation(t);if(o&&(null==(e=o.conversationGroupList)||!e.includes(a))){let e=o.conversationGroupList.slice();e.push(a),s.push({conversationID:t,data:{conversationGroupList:e}})}}),i&&g(),E(s)})})}_handleConversationGroupDeleted(e){let o,{isArray:r}=this._core.utils;null!=(o=null==e?void 0:e.RecentContactMod)&&o.forEach(e=>{e=((null==e?void 0:e.RecentContactDelContactGroup)||{}).MsgGroupItem;if(r(e)){let n=!1,a=[];e.forEach(e=>{var{GroupId:e,GroupName:o}=e,r=t.getConversationGroupMap();r.has(e)&&(r.delete(e),n=!0,a.push(o))}),n&&g(),0<a.length&&this._deleteLocalConversationGroupName(a)}})}_handleConversationGroupUpdated(e){null!=(e=e.RecentContactMod)&&e.forEach(e=>{var{GroupId:e,GroupName:t,OldGroupName:o,RecentContactUpdateGroupItem:r,UpdateGroupType:n}=e["RecentContactUpdateContactGroup"]["MsgUpdateGroup"];1===n?this._handleGroupNameUpdated({groupID:e,newName:t,oldName:o}):2===n&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:r,groupName:o})})}_handleConversationMarkUpdated(e){let t,a=this._core.appStore;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{let{RecentContactMarkContactItem:t}=e["RecentContactMarkContact"],n=[];null!=t&&t.forEach(e=>{var{RecentContactItem:e,CustomMark:t,StandardMark:o,OptType:r}=e,e=_(e),e=a.conversationStore.getConversation(e);e&&(r===C?this._updateStandMark({conversation:e,standardMark:o,updateConversationList:n}):r===h?this._updateCustomMark({conversation:e,customMark:t,updateConversationList:n}):r===m&&(this._updateStandMark({conversation:e,standardMark:o,updateConversationList:n}),this._updateCustomMark({conversation:e,customMark:t,updateConversationList:n})))}),E(n)})}_updateStandMark(e){var{conversation:e,standardMark:t,updateConversationList:o}=e,t=N(t);!function(o,r){if(o===r)return 1;if(o&&r&&o.length===r.length){o.sort(),r.sort();for(let e=0,t=o.length;e<t;e++)if(o[e]!==r[e])return;return 1}}(e.markList,t)&&o.push({conversationID:e.conversationID,data:{markList:t}})}_updateCustomMark(e){var{conversation:e,customMark:t,updateConversationList:o}=e;e.customData!==t&&void 0!==t&&(e.customData=t,o.push({conversationID:e.conversationID,data:{customData:t}}))}_handleGroupNameUpdated(e){var{groupID:e,oldName:o,newName:r}=e;t.getConversationGroup(e)!==r&&(t.setConversationGroup(e,r),g(),this._updateLocalConversationGroupName({oldName:o,newName:r}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:e,groupName:a}){let s=this._core["appStore"],i=[];e.forEach(e=>{var{RecentContactItem:e,ContactOptType:t}=e,o=_(e),r=s.conversationStore.getConversation(o),n=r.conversationGroupList.indexOf(a);if(r){let e=r.conversationGroupList.slice();1===t&&-1===n?(e.push(a),i.push({conversationID:o,data:{conversationGroupList:e}})):2===t&&-1!==n&&(e.splice(n,1),i.push({conversationID:o,data:{conversationGroupList:e}}))}}),E(i)}dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t},InnerEventSubType:{CONVERSATION_MARK_UPDATED:o,CONVERSATION_GROUP_ADD:r,CONVERSATION_GROUP_DELETED:n,CONVERSATION_GROUP_UPDATED:a}}=this._core;e.unSubscribeInnerEvent(t,r,this._handleConversationGroupAdd,this),e.unSubscribeInnerEvent(t,n,this._handleConversationGroupDeleted,this),e.unSubscribeInnerEvent(t,a,this._handleConversationGroupUpdated,this),e.unSubscribeInnerEvent(t,o,this._handleConversationMarkUpdated,this)}};let y={required:!0,rules:["string"],allowEmpty:!1},U={required:!0,rules:["array"],allowEmpty:!1},M={createConversationGroup:{groupName:y,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:y,newName:Object.assign(Object.assign({},y),{customValidator:e=>!(32<e.length)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:U,groupName:y},deleteConversationsFromGroup:{conversationIDList:U,groupName:y},markConversation:{conversationIDList:U,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:e=>e<=0?"markType must be greater than 0":!(e>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:U,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>"string"!=typeof e?"customData must be string":!(256<e.length)||"customData length cannot longer than 256"}}},k={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};var b=new class{constructor(){this.name="ConversationGroup"}install(o){this._core=o,e.init(o),t.init(o),R.init(o),A.init(o),T.init(o),o.helper.registerValidateConfig({auth:k,params:M}),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.LOGOUT,this.reset,this),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.DESTROY,this.dispose,this)}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.DESTROY,this.dispose,this),T.dispose(),A.dispose()}reset(){A.reset()}};export{b as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatConversation-group"]=t()}(this,function(){var l=new class{constructor(){this._conversationGroupMap=new Map}init(e){this._core=e}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(e){return this._conversationGroupMap.get(e)}setConversationGroup(e,t){this._conversationGroupMap.set(e,t)}};function o(e,s,i,c){return new(i=i||Promise)(function(o,t){function n(e){try{a(c.next(e))}catch(e){t(e)}}function r(e){try{a(c.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?o(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(n,r)}a((c=c.apply(e,s||[])).next())})}let d=new class{init(e){this.core=e}},e="NOT_STARTED",t="FAILED";function h(e){var{helper:t,constants:o}=d.core;if(!t.checkBusinessCapabilityBits("CONV_GROUP"))throw new t.ChatError({functionName:e,code:o.ERROR_CODE.NO_USE,replacement1:e})}function v(){var{notificationCenter:e,OuterEvent:t}=d.core;e.emitOuterEvent(t.CONVERSATION_GROUP_LIST_UPDATED,{name:t.CONVERSATION_GROUP_LIST_UPDATED,data:[...l.getConversationGroupMap().values()]})}function m(e){var{utils:{isUndefined:t},constants:{OuterConstant:o}}=d.core,{Type:e,To_Account:n,GroupId:r,ToGroupId:r=r,Peer_Account:a}=e;let s="";return 1===e?t(a)?t(n)||(s=""+o.CONV_C2C+n):s=""+o.CONV_C2C+a:2===e&&(s=""+o.CONV_GROUP+r),s}function f(e){let t=[],{OuterConstant:o,common:{isC2CConv:n,isGroupConv:r}}=d.core,{conversationIDList:a,failureConversationIDList:s,additionalData:i={}}=e;return a.forEach(e=>{c(e,s),n(e)?t.push(Object.assign({ContactItem:{Type:1,To_Account:e.replace(o.CONV_C2C,"")}},i)):r(e)&&t.push(Object.assign({ContactItem:{Type:2,ToGroupId:e.replace(o.CONV_GROUP,"")}},i))}),t}function c(e,t){var{appStore:{conversationStore:o},common:{isC2CConv:n,isGroupConv:r}}=d.core;o.getConversation(e)?n(e)||r(e)||t.push({conversationID:e,code:2503}):t.push({conversationID:e,code:2500})}function u(t){var{isString:e}=d.core["utils"],o=[];if(e(t)){var n=t.length;if(0!==n)for(let e=n-1;0<=e;e--)"1"===t[e]&&o.push(Math.pow(2,n-e-1))}return o}function I(r){null!=r&&r.forEach((e,t)=>{var o=d.core["appStore"],{conversationID:e,data:n}=e,t=t===r.length-1;o.conversationStore.updateConversation(e,n,{emit:t})})}function G(e){var{conversationInfoList:e,fromAccount:t}=e,t={From_Account:t,MarkItem:e};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:t})}function p(e){var{fromAccount:e,groupName:t,conversationInfoList:o}=e,e={From_Account:e,UpdateType:1,UpdateGroup:{UpdateGroupType:2,OldGroupName:t,ContactUpdateItem:o}};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:e})}var n=new class{init(e){var{registerApi:t}=e["helper"];this._core=e,t({apiName:"createConversationGroup",context:this})}createConversationGroup(n){return o(this,void 0,void 0,function*(){let{utils:{isPlainObject:a,isArray:s},appStore:i,ssoLog:e}=this._core;h("createConversationGroup");var c=e.createSSOLogData({method:"createConversationGroup"});c.setLogInfo({message:JSON.stringify(n)});let{groupName:u,conversationIDList:t}=n,p=[],o=this._generateConversationInfo(t,p);if(p.length===t.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:p}};try{let r=yield function(e){var{buildAndSendPacket:t,getCurrentUserID:o}=d.core["common"],{item:e,groupName:n}=e;return t({servcmd:"recentcontact.create_contact_group",data:{From_Account:o(),GroupContactItem:[{GroupName:n,ContactItem:e}]}})}({groupName:u,item:o});if(r){c.end();let{GroupResultItem:e=[]}=r,{GroupItem:o,ResultItem:t}=(null==e?void 0:e[0])||{},n=[];if(a(o)){let{GroupName:e,GroupId:t}=o;l.setConversationGroup(t,e),v()}if(s(t)){let a=[];t.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:n}=e,r=m(t);if(0===o){let t=i.conversationStore.getConversation(r);if(t&&!t.conversationGroupList.includes(u)){let e=t.conversationGroupList.slice();e.push(u),a.push({conversationID:r,data:{conversationGroupList:e}})}}else p.push({conversationID:r,code:o,message:n})}),0<a.length&&(I(a),v())}return{code:0,data:{successConversationIDList:n,failureConversationIDList:p}}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"createConversationGroup",code:t,message:o});throw c.setError(n).end(),n}})}_generateConversationInfo(e,t,o={}){let n=[],{OuterConstant:r,common:{isC2CConv:a,isGroupConv:s}}=this._core;return e.forEach(e=>{c(e,t),a(e)?n.push(Object.assign({Type:1,To_Account:e.replace(r.CONV_C2C,"")},o)):s(e)&&n.push(Object.assign({Type:2,ToGroupId:e.replace(r.CONV_GROUP,"")},o))}),n}},r=new class{constructor(){this._fetchConversationGroupStatus=e}init(e){var{helper:{registerApi:t,registerWorkflowStep:o},constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:r}}=e;this._core=e,t({apiName:"getConversationGroupList",context:this}),o(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),o(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,function*(){return h("getConversationGroupList"),this._fetchConversationGroupStatus===t&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...l.getConversationGroupMap().values()]}})}_syncConversationGroupList(){return o(this,void 0,void 0,function*(){return yield this._fetchConversationGroupList(0)})}_fetchConversationGroupList(e){return o(this,arguments,void 0,function*(n,a=[]){let{common:{getCurrentUserID:e},utils:{isArray:s}}=this._core;this._fetchConversationGroupStatus="FETCHING";try{let o=e(),r=yield function(){var{fromAccount:e,startIndex:t}={fromAccount:o,startIndex:n},e={From_Account:e,StartIndex:t};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:e})}();if(r){let{CompleteFlag:e,ContactItem:t=[],NextStartIndex:o=0,GroupItem:n=[]}=r;return(s(n)&&n.forEach(e=>{var{GroupName:e,GroupId:t}=e;l.setConversationGroup(t,e)}),a.push(...t),0===e)?this._fetchConversationGroupList(o):1===e?(this._fetchConversationGroupStatus="FINISHED",a):void 0}}catch(e){this._fetchConversationGroupStatus=t,console.error(e)}})}_updateConversation(e){var t=this._core["constants"]["WORKFLOW_STEP"],e=(null==(e=null==e?void 0:e.result)?void 0:e[t.CONVERSATION_GROUP_LIST_SYNC])||[];I(this._generateConversationUpdateFields(e)),v()}_generateConversationUpdateFields(e){let{utils:{isArray:s},appStore:i}=this._core,c=[];if(s(e)){let a;e.forEach(e=>{let t=[],{StandardMark:o,CustomMark:n="",ContactGroupId:r}=e;s(r)&&r.forEach(e=>{l.getConversationGroupMap().has(e)&&t.push(l.getConversationGroup(e))});e=m(e);(a=i.conversationStore.getConversation(e))&&c.push({conversationID:e,data:{markList:u(o),customData:n,conversationGroupList:[...t]}})})}return c}reset(){this._fetchConversationGroupStatus=e}dispose(){this.reset()}},a=new class{init(e){var{notificationCenter:t,helper:{registerApi:o},InnerEvent:{MESSAGE_PUSH:n},InnerEventSubType:{CONVERSATION_MARK_UPDATED:r,CONVERSATION_GROUP_ADD:a,CONVERSATION_GROUP_DELETED:s,CONVERSATION_GROUP_UPDATED:i}}=e;this._core=e,o({apiName:"renameConversationGroup",context:this}),o({apiName:"deleteConversationGroup",context:this}),o({apiName:"markConversation",context:this}),o({apiName:"setConversationCustomData",context:this}),o({apiName:"deleteConversationsFromGroup",context:this}),o({apiName:"addConversationsToGroup",context:this}),t.subscribeInnerEvent(n,a,this._handleConversationGroupAdd,this),t.subscribeInnerEvent(n,s,this._handleConversationGroupDeleted,this),t.subscribeInnerEvent(n,i,this._handleConversationGroupUpdated,this),t.subscribeInnerEvent(n,r,this._handleConversationMarkUpdated,this)}renameConversationGroup(t){return o(this,void 0,void 0,function*(){h("renameConversationGroup");let{common:{getCurrentUserID:n},ssoLog:e}=this._core,{oldName:r,newName:a}=t,s=e.createSSOLogData({method:"renameConversationGroup"});s.setLogInfo({message:`oldName:${r} newName:`+a});try{let o=yield function(){var{fromAccount:e,oldName:t,newName:o}={fromAccount:n(),oldName:r,newName:a},e={From_Account:e,UpdateType:1,UpdateGroup:{UpdateGroupType:1,OldGroupName:t,NewGroupName:o}};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:e})}();if(o){s.end();let e=o["UpdateGroupResult"],t=e["GroupId"];l.setConversationGroup(t,a),v(),this._updateLocalConversationGroupName({oldName:r,newName:a})}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"renameConversationGroup",code:t,message:o});throw s.setError(n).end(),n}})}deleteConversationGroup(n){return o(this,void 0,void 0,function*(){h("deleteConversationGroup");let{common:{getCurrentUserID:o},ssoLog:e}=this._core,r=e.createSSOLogData({method:"deleteConversationGroup"});r.setLogInfo({message:"groupName:"+n});try{let t=yield function(){var{fromAccount:e,groupName:t}={fromAccount:o(),groupName:n},e={From_Account:e,GroupName:[t]};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:e})}();if(t){let e=t["GroupItem"],o=!1;null!=e&&e.forEach(e=>{var e=e["GroupId"],t=l.getConversationGroupMap();t.has(e)&&(t.delete(e),o=!0)}),o&&v(),this._deleteLocalConversationGroupName([n])}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:t,message:o});throw r.setError(n).end(),n}})}markConversation(C){return o(this,void 0,void 0,function*(){h("markConversation");let{utils:{isNumber:e},common:{getCurrentUserID:o},ssoLog:t,appStore:s}=this._core,{conversationIDList:n,markType:i,enableMark:c}=C,r=this._getFlagBit(i),u=[],p=[],a,l;var d=t.createSSOLogData({method:"markConversation"}),v=(d.setLogInfo({message:JSON.stringify(C)}),!0===c&&e(r)?a=[r]:l=[r],f({conversationIDList:n,failureConversationIDList:u,additionalData:{SetMark:a,ClearMark:l,OptType:1}}));if(u.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:u}};try{let t=yield G({conversationInfoList:v,fromAccount:o()});if(t){d.end();let e=t["ResultItem"],a=[];e.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:n}=e,r=m(t);if(0===o){p.push(r);let o=s.conversationStore.getConversation(r);if(o){let t=o.markList.indexOf(i),e=!1===c&&-1!==t;if(!0===c&&-1===t)a.push({conversationID:r,data:{markList:[...o.markList,i]}});else if(e){let e=o.markList.slice();e.splice(t,1),a.push({conversationID:r,data:{markList:e}})}}}else u.push({conversationID:r,code:o,message:n})}),I(a)}return{code:0,data:{successConversationIDList:p,failureConversationIDList:u}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"markConversation",code:t,message:o});throw d.setError(n).end(),n}})}setConversationCustomData(r){return o(this,void 0,void 0,function*(){h("setConversationCustomData");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,{conversationIDList:o,customData:s}=r,i=[],c=[],u=t.createSSOLogData({method:"setConversationCustomData"});u.setLogInfo({message:JSON.stringify(r)});var n=f({conversationIDList:o,failureConversationIDList:i,additionalData:{CustomMark:s,OptType:2}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield G({fromAccount:e(),conversationInfoList:n});if(t){u.end();let e=t["ResultItem"],r=[];null!=e&&e.forEach(e=>{let{ContactItem:o,ResultCode:t,ResultInfo:n}=e;if(0===t){let e=m(o),t=(c.push(e),a.conversationStore.getConversation(e));t&&t.customData!==s&&r.push({conversationID:e,data:{customData:s}})}else i.push({conversationID:conversationID,code:t,message:n})}),I(r)}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"setConversationCustomData",code:t,message:o});throw u.setError(n).end(),n}})}deleteConversationsFromGroup(r){return o(this,void 0,void 0,function*(){h("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,s=t.createSSOLogData({method:"deleteConversationsFromGroup"}),{conversationIDList:o,groupName:i}=(s.setLogInfo({message:JSON.stringify(r)}),r),c=[],u=[],n=f({conversationIDList:o,failureConversationIDList:c,additionalData:{ContactOptType:2}});if(c.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{let t=yield p({fromAccount:e(),groupName:i,conversationInfoList:n});if(t){s.end();let r=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o,n=m(e.ContactItem);if(0===e.ResultCode){let t=a.conversationStore.getConversation(n);if(t){let e=t.conversationGroupList.indexOf(i);-1!==e&&((o=t.conversationGroupList.slice()).splice(e,1),u.push(n),r.push({conversationID:n,data:{conversationGroupList:o}}))}}else c.push({conversationID:n,code:e.ResultCode,message:e.ResultInfo})}),0<r.length&&(v(),I(r))}return{code:0,data:{successConversationIDList:u,failureConversationIDList:c}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw s.setError(n).end(),n}})}addConversationsToGroup(u){return o(this,void 0,void 0,function*(){h("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:r}=this._core,a=t.createSSOLogData({method:"addConversationsToGroup"}),{conversationIDList:o,groupName:s}=(a.setLogInfo({message:JSON.stringify(u)}),u),i=[],c=[],n=f({conversationIDList:o,failureConversationIDList:i,additionalData:{ContactOptType:1}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield p({fromAccount:e(),groupName:s,conversationInfoList:n});if(t){a.end();let n=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o=m(e.ContactItem);if(0===e.ResultCode){let t=r.conversationStore.getConversation(o);if(t&&-1===t.conversationGroupList.indexOf(s)){let e=t.conversationGroupList.slice();e.push(s),c.push(o),n.push({conversationID:o,data:{conversationGroupList:e}})}}else i.push({conversationID:o,code:e.ResultCode,message:e.ResultInfo})}),0<n.length&&(v(),I(n))}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw a.setError(n).end(),n}})}_updateLocalConversationGroupName(e){let t=this._core["appStore"],{oldName:o,newName:n}=e,r=[],a=[],s;Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var t;r=e.conversationGroupList,-1!==(s=r.indexOf(o))&&((t=r.slice()).splice(s,1,n),a.push({conversationID:e.conversationID,data:{conversationGroupList:t}}))}),I(a)}_deleteLocalConversationGroupName(r){var{utils:{isEmpty:e},appStore:t}=this._core;if(!e(r)){let n=[];Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var{conversationID:e,conversationGroupList:t}=e,o=t.filter(e=>!r.includes(e));o.length<t.length&&n.push({conversationID:e,data:{conversationGroupList:o}})}),I(n)}}_getFlagBit(e){var t=e.toString(2),o=t.length;for(let e=o-1;0<=e;e--)if("1"===t[e])return o-e-1}_handleConversationGroupAdd(e){let t,{utils:{isArray:i},appStore:c}=this._core;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{var e=e["RecentContactCreateContactGroup"]["MsgContactGroupContactItem"];let s=!1;null!=e&&e.forEach(e=>{let{MsgGroupItem:t,MsgRecentContactItem:o}=e,{GroupId:n,GroupName:r}=t,a=[];l.getConversationGroup(n)!==r&&(l.setConversationGroup(n,r),s=!0),i(o)&&o.forEach(e=>{var t=m(e),o=c.conversationStore.getConversation(t);if(o&&(null==(e=o.conversationGroupList)||!e.includes(r))){let e=o.conversationGroupList.slice();e.push(r),a.push({conversationID:t,data:{conversationGroupList:e}})}}),s&&v(),I(a)})})}_handleConversationGroupDeleted(e){let t,{isArray:o}=this._core.utils;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{e=((null==e?void 0:e.RecentContactDelContactGroup)||{}).MsgGroupItem;if(o(e)){let n=!1,r=[];e.forEach(e=>{var{GroupId:e,GroupName:t}=e,o=l.getConversationGroupMap();o.has(e)&&(o.delete(e),n=!0,r.push(t))}),n&&v(),0<r.length&&this._deleteLocalConversationGroupName(r)}})}_handleConversationGroupUpdated(e){null!=(e=e.RecentContactMod)&&e.forEach(e=>{var{GroupId:e,GroupName:t,OldGroupName:o,RecentContactUpdateGroupItem:n,UpdateGroupType:r}=e["RecentContactUpdateContactGroup"]["MsgUpdateGroup"];1===r?this._handleGroupNameUpdated({groupID:e,newName:t,oldName:o}):2===r&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:n,groupName:o})})}_handleConversationMarkUpdated(e){let t,a=this._core.appStore;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{let{RecentContactMarkContactItem:t}=e["RecentContactMarkContact"],r=[];null!=t&&t.forEach(e=>{var{RecentContactItem:e,CustomMark:t,StandardMark:o,OptType:n}=e,e=m(e),e=a.conversationStore.getConversation(e);e&&(1===n?this._updateStandMark({conversation:e,standardMark:o,updateConversationList:r}):2===n?this._updateCustomMark({conversation:e,customMark:t,updateConversationList:r}):3===n&&(this._updateStandMark({conversation:e,standardMark:o,updateConversationList:r}),this._updateCustomMark({conversation:e,customMark:t,updateConversationList:r})))}),I(r)})}_updateStandMark(e){var{conversation:e,standardMark:t,updateConversationList:o}=e,t=u(t);!function(o,n){if(o===n)return 1;if(o&&n&&o.length===n.length){o.sort(),n.sort();for(let e=0,t=o.length;e<t;e++)if(o[e]!==n[e])return;return 1}}(e.markList,t)&&o.push({conversationID:e.conversationID,data:{markList:t}})}_updateCustomMark(e){var{conversation:e,customMark:t,updateConversationList:o}=e;e.customData!==t&&void 0!==t&&(e.customData=t,o.push({conversationID:e.conversationID,data:{customData:t}}))}_handleGroupNameUpdated(e){var{groupID:e,oldName:t,newName:o}=e;l.getConversationGroup(e)!==o&&(l.setConversationGroup(e,o),v(),this._updateLocalConversationGroupName({oldName:t,newName:o}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:e,groupName:a}){let s=this._core["appStore"],i=[];e.forEach(e=>{var{RecentContactItem:e,ContactOptType:t}=e,o=m(e),n=s.conversationStore.getConversation(o),r=n.conversationGroupList.indexOf(a);if(n){let e=n.conversationGroupList.slice();1===t&&-1===r?(e.push(a),i.push({conversationID:o,data:{conversationGroupList:e}})):2===t&&-1!==r&&(e.splice(r,1),i.push({conversationID:o,data:{conversationGroupList:e}}))}}),I(i)}dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t},InnerEventSubType:{CONVERSATION_MARK_UPDATED:o,CONVERSATION_GROUP_ADD:n,CONVERSATION_GROUP_DELETED:r,CONVERSATION_GROUP_UPDATED:a}}=this._core;e.unSubscribeInnerEvent(t,n,this._handleConversationGroupAdd,this),e.unSubscribeInnerEvent(t,r,this._handleConversationGroupDeleted,this),e.unSubscribeInnerEvent(t,a,this._handleConversationGroupUpdated,this),e.unSubscribeInnerEvent(t,o,this._handleConversationMarkUpdated,this)}};let s={required:!0,rules:["string"],allowEmpty:!1},i={required:!0,rules:["array"],allowEmpty:!1},C={createConversationGroup:{groupName:s,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:s,newName:Object.assign(Object.assign({},s),{customValidator:e=>!(32<e.length)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:i,groupName:s},deleteConversationsFromGroup:{conversationIDList:i,groupName:s},markConversation:{conversationIDList:i,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:e=>e<=0?"markType must be greater than 0":!(e>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:i,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>"string"!=typeof e?"customData must be string":!(256<e.length)||"customData length cannot longer than 256"}}},g={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};return new class{install(e){this._core=e,d.init(e),l.init(e),n.init(e),r.init(e),a.init(e),e.helper.registerValidateConfig({auth:g,params:C}),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.LOGOUT,this.reset,this),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.DESTROY,this.dispose,this)}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.DESTROY,this.dispose,this),a.dispose(),r.dispose()}reset(){r.reset()}}});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatConversation-group"]=t()}(this,function(){var l=new class{constructor(){this._conversationGroupMap=new Map}init(e){this._core=e}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(e){return this._conversationGroupMap.get(e)}setConversationGroup(e,t){this._conversationGroupMap.set(e,t)}};function o(e,s,i,c){return new(i=i||Promise)(function(o,t){function n(e){try{a(c.next(e))}catch(e){t(e)}}function r(e){try{a(c.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?o(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(n,r)}a((c=c.apply(e,s||[])).next())})}let d=new class{init(e){this.core=e}},e="NOT_STARTED",t="FAILED";function h(e){var{helper:t,constants:o}=d.core;if(!t.checkBusinessCapabilityBits("CONV_GROUP"))throw new t.ChatError({functionName:e,code:o.ERROR_CODE.NO_USE,replacement1:e})}function v(){var{notificationCenter:e,OuterEvent:t}=d.core;e.emitOuterEvent(t.CONVERSATION_GROUP_LIST_UPDATED,{name:t.CONVERSATION_GROUP_LIST_UPDATED,data:[...l.getConversationGroupMap().values()]})}function m(e){var{utils:{isUndefined:t},constants:{OuterConstant:o}}=d.core,{Type:e,To_Account:n,GroupId:r,ToGroupId:r=r,Peer_Account:a}=e;let s="";return 1===e?t(a)?t(n)||(s=""+o.CONV_C2C+n):s=""+o.CONV_C2C+a:2===e&&(s=""+o.CONV_GROUP+r),s}function f(e){let t=[],{OuterConstant:o,common:{isC2CConv:n,isGroupConv:r}}=d.core,{conversationIDList:a,failureConversationIDList:s,additionalData:i={}}=e;return a.forEach(e=>{c(e,s),n(e)?t.push(Object.assign({ContactItem:{Type:1,To_Account:e.replace(o.CONV_C2C,"")}},i)):r(e)&&t.push(Object.assign({ContactItem:{Type:2,ToGroupId:e.replace(o.CONV_GROUP,"")}},i))}),t}function c(e,t){var{appStore:{conversationStore:o},common:{isC2CConv:n,isGroupConv:r}}=d.core;o.getConversation(e)?n(e)||r(e)||t.push({conversationID:e,code:2503}):t.push({conversationID:e,code:2500})}function u(t){var{isString:e}=d.core["utils"],o=[];if(e(t)){var n=t.length;if(0!==n)for(let e=n-1;0<=e;e--)"1"===t[e]&&o.push(Math.pow(2,n-e-1))}return o}function I(r){null!=r&&r.forEach((e,t)=>{var o=d.core["appStore"],{conversationID:e,data:n}=e,t=t===r.length-1;o.conversationStore.updateConversation(e,n,{emit:t})})}function G(e){var{conversationInfoList:e,fromAccount:t}=e,t={From_Account:t,MarkItem:e};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:t})}function p(e){var{fromAccount:e,groupName:t,conversationInfoList:o}=e,e={From_Account:e,UpdateType:1,UpdateGroup:{UpdateGroupType:2,OldGroupName:t,ContactUpdateItem:o}};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:e})}var n=new class{init(e){var{registerApi:t}=e["helper"];this._core=e,t({apiName:"createConversationGroup",context:this})}createConversationGroup(n){return o(this,void 0,void 0,function*(){let{utils:{isPlainObject:a,isArray:s},appStore:i,ssoLog:e}=this._core;h("createConversationGroup");var c=e.createSSOLogData({method:"createConversationGroup"});c.setLogInfo({message:JSON.stringify(n)});let{groupName:u,conversationIDList:t}=n,p=[],o=this._generateConversationInfo(t,p);if(p.length===t.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:p}};try{let r=yield function(e){var{buildAndSendPacket:t,getCurrentUserID:o}=d.core["common"],{item:e,groupName:n}=e;return t({servcmd:"recentcontact.create_contact_group",data:{From_Account:o(),GroupContactItem:[{GroupName:n,ContactItem:e}]}})}({groupName:u,item:o});if(r){c.end();let{GroupResultItem:e=[]}=r,{GroupItem:o,ResultItem:t}=(null==e?void 0:e[0])||{},n=[];if(a(o)){let{GroupName:e,GroupId:t}=o;l.setConversationGroup(t,e),v()}if(s(t)){let a=[];t.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:n}=e,r=m(t);if(0===o){let t=i.conversationStore.getConversation(r);if(t&&!t.conversationGroupList.includes(u)){let e=t.conversationGroupList.slice();e.push(u),a.push({conversationID:r,data:{conversationGroupList:e}})}}else p.push({conversationID:r,code:o,message:n})}),0<a.length&&(I(a),v())}return{code:0,data:{successConversationIDList:n,failureConversationIDList:p}}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"createConversationGroup",code:t,message:o});throw c.setError(n).end(),n}})}_generateConversationInfo(e,t,o={}){let n=[],{OuterConstant:r,common:{isC2CConv:a,isGroupConv:s}}=this._core;return e.forEach(e=>{c(e,t),a(e)?n.push(Object.assign({Type:1,To_Account:e.replace(r.CONV_C2C,"")},o)):s(e)&&n.push(Object.assign({Type:2,ToGroupId:e.replace(r.CONV_GROUP,"")},o))}),n}},r=new class{constructor(){this._fetchConversationGroupStatus=e}init(e){var{helper:{registerApi:t,registerWorkflowStep:o},constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:r}}=e;this._core=e,t({apiName:"getConversationGroupList",context:this}),o(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),o(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,function*(){return h("getConversationGroupList"),this._fetchConversationGroupStatus===t&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...l.getConversationGroupMap().values()]}})}_syncConversationGroupList(){return o(this,void 0,void 0,function*(){return yield this._fetchConversationGroupList(0)})}_fetchConversationGroupList(e){return o(this,arguments,void 0,function*(n,a=[]){let{common:{getCurrentUserID:e},utils:{isArray:s}}=this._core;this._fetchConversationGroupStatus="FETCHING";try{let o=e(),r=yield function(){var{fromAccount:e,startIndex:t}={fromAccount:o,startIndex:n},e={From_Account:e,StartIndex:t};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:e})}();if(r){let{CompleteFlag:e,ContactItem:t=[],NextStartIndex:o=0,GroupItem:n=[]}=r;return(s(n)&&n.forEach(e=>{var{GroupName:e,GroupId:t}=e;l.setConversationGroup(t,e)}),a.push(...t),0===e)?this._fetchConversationGroupList(o):1===e?(this._fetchConversationGroupStatus="FINISHED",a):void 0}}catch(e){this._fetchConversationGroupStatus=t,console.error(e)}})}_updateConversation(e){var t=this._core["constants"]["WORKFLOW_STEP"],e=(null==(e=null==e?void 0:e.result)?void 0:e[t.CONVERSATION_GROUP_LIST_SYNC])||[];I(this._generateConversationUpdateFields(e)),v()}_generateConversationUpdateFields(e){let{utils:{isArray:s},appStore:i}=this._core,c=[];if(s(e)){let a;e.forEach(e=>{let t=[],{StandardMark:o,CustomMark:n="",ContactGroupId:r}=e;s(r)&&r.forEach(e=>{l.getConversationGroupMap().has(e)&&t.push(l.getConversationGroup(e))});e=m(e);(a=i.conversationStore.getConversation(e))&&c.push({conversationID:e,data:{markList:u(o),customData:n,conversationGroupList:[...t]}})})}return c}reset(){this._fetchConversationGroupStatus=e}dispose(){this.reset()}},a=new class{init(e){var{notificationCenter:t,helper:{registerApi:o},InnerEvent:{MESSAGE_PUSH:n},InnerEventSubType:{CONVERSATION_MARK_UPDATED:r,CONVERSATION_GROUP_ADD:a,CONVERSATION_GROUP_DELETED:s,CONVERSATION_GROUP_UPDATED:i}}=e;this._core=e,o({apiName:"renameConversationGroup",context:this}),o({apiName:"deleteConversationGroup",context:this}),o({apiName:"markConversation",context:this}),o({apiName:"setConversationCustomData",context:this}),o({apiName:"deleteConversationsFromGroup",context:this}),o({apiName:"addConversationsToGroup",context:this}),t.subscribeInnerEvent(n,a,this._handleConversationGroupAdd,this),t.subscribeInnerEvent(n,s,this._handleConversationGroupDeleted,this),t.subscribeInnerEvent(n,i,this._handleConversationGroupUpdated,this),t.subscribeInnerEvent(n,r,this._handleConversationMarkUpdated,this)}renameConversationGroup(t){return o(this,void 0,void 0,function*(){h("renameConversationGroup");let{common:{getCurrentUserID:n},ssoLog:e}=this._core,{oldName:r,newName:a}=t,s=e.createSSOLogData({method:"renameConversationGroup"});s.setLogInfo({message:`oldName:${r} newName:`+a});try{let o=yield function(){var{fromAccount:e,oldName:t,newName:o}={fromAccount:n(),oldName:r,newName:a},e={From_Account:e,UpdateType:1,UpdateGroup:{UpdateGroupType:1,OldGroupName:t,NewGroupName:o}};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:e})}();if(o){s.end();let e=o["UpdateGroupResult"],t=e["GroupId"];l.setConversationGroup(t,a),v(),this._updateLocalConversationGroupName({oldName:r,newName:a})}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"renameConversationGroup",code:t,message:o});throw s.setError(n).end(),n}})}deleteConversationGroup(n){return o(this,void 0,void 0,function*(){h("deleteConversationGroup");let{common:{getCurrentUserID:o},ssoLog:e}=this._core,r=e.createSSOLogData({method:"deleteConversationGroup"});r.setLogInfo({message:"groupName:"+n});try{let t=yield function(){var{fromAccount:e,groupName:t}={fromAccount:o(),groupName:n},e={From_Account:e,GroupName:[t]};return d.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:e})}();if(t){let e=t["GroupItem"],o=!1;null!=e&&e.forEach(e=>{var e=e["GroupId"],t=l.getConversationGroupMap();t.has(e)&&(t.delete(e),o=!0)}),o&&v(),this._deleteLocalConversationGroupName([n])}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:t,message:o});throw r.setError(n).end(),n}})}markConversation(C){return o(this,void 0,void 0,function*(){h("markConversation");let{utils:{isNumber:e},common:{getCurrentUserID:o},ssoLog:t,appStore:s}=this._core,{conversationIDList:n,markType:i,enableMark:c}=C,r=this._getFlagBit(i),u=[],p=[],a,l;var d=t.createSSOLogData({method:"markConversation"}),v=(d.setLogInfo({message:JSON.stringify(C)}),!0===c&&e(r)?a=[r]:l=[r],f({conversationIDList:n,failureConversationIDList:u,additionalData:{SetMark:a,ClearMark:l,OptType:1}}));if(u.length===n.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:u}};try{let t=yield G({conversationInfoList:v,fromAccount:o()});if(t){d.end();let e=t["ResultItem"],a=[];e.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:n}=e,r=m(t);if(0===o){p.push(r);let o=s.conversationStore.getConversation(r);if(o){let t=o.markList.indexOf(i),e=!1===c&&-1!==t;if(!0===c&&-1===t)a.push({conversationID:r,data:{markList:[...o.markList,i]}});else if(e){let e=o.markList.slice();e.splice(t,1),a.push({conversationID:r,data:{markList:e}})}}}else u.push({conversationID:r,code:o,message:n})}),I(a)}return{code:0,data:{successConversationIDList:p,failureConversationIDList:u}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"markConversation",code:t,message:o});throw d.setError(n).end(),n}})}setConversationCustomData(r){return o(this,void 0,void 0,function*(){h("setConversationCustomData");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,{conversationIDList:o,customData:s}=r,i=[],c=[],u=t.createSSOLogData({method:"setConversationCustomData"});u.setLogInfo({message:JSON.stringify(r)});var n=f({conversationIDList:o,failureConversationIDList:i,additionalData:{CustomMark:s,OptType:2}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield G({fromAccount:e(),conversationInfoList:n});if(t){u.end();let e=t["ResultItem"],r=[];null!=e&&e.forEach(e=>{let{ContactItem:o,ResultCode:t,ResultInfo:n}=e;if(0===t){let e=m(o),t=(c.push(e),a.conversationStore.getConversation(e));t&&t.customData!==s&&r.push({conversationID:e,data:{customData:s}})}else i.push({conversationID:conversationID,code:t,message:n})}),I(r)}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"setConversationCustomData",code:t,message:o});throw u.setError(n).end(),n}})}deleteConversationsFromGroup(r){return o(this,void 0,void 0,function*(){h("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,s=t.createSSOLogData({method:"deleteConversationsFromGroup"}),{conversationIDList:o,groupName:i}=(s.setLogInfo({message:JSON.stringify(r)}),r),c=[],u=[],n=f({conversationIDList:o,failureConversationIDList:c,additionalData:{ContactOptType:2}});if(c.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{let t=yield p({fromAccount:e(),groupName:i,conversationInfoList:n});if(t){s.end();let r=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o,n=m(e.ContactItem);if(0===e.ResultCode){let t=a.conversationStore.getConversation(n);if(t){let e=t.conversationGroupList.indexOf(i);-1!==e&&((o=t.conversationGroupList.slice()).splice(e,1),u.push(n),r.push({conversationID:n,data:{conversationGroupList:o}}))}}else c.push({conversationID:n,code:e.ResultCode,message:e.ResultInfo})}),0<r.length&&(v(),I(r))}return{code:0,data:{successConversationIDList:u,failureConversationIDList:c}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw s.setError(n).end(),n}})}addConversationsToGroup(u){return o(this,void 0,void 0,function*(){h("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:r}=this._core,a=t.createSSOLogData({method:"addConversationsToGroup"}),{conversationIDList:o,groupName:s}=(a.setLogInfo({message:JSON.stringify(u)}),u),i=[],c=[],n=f({conversationIDList:o,failureConversationIDList:i,additionalData:{ContactOptType:1}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield p({fromAccount:e(),groupName:s,conversationInfoList:n});if(t){a.end();let n=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o=m(e.ContactItem);if(0===e.ResultCode){let t=r.conversationStore.getConversation(o);if(t&&-1===t.conversationGroupList.indexOf(s)){let e=t.conversationGroupList.slice();e.push(s),c.push(o),n.push({conversationID:o,data:{conversationGroupList:e}})}}else i.push({conversationID:o,code:e.ResultCode,message:e.ResultInfo})}),0<n.length&&(v(),I(n))}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,n=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw a.setError(n).end(),n}})}_updateLocalConversationGroupName(e){let t=this._core["appStore"],{oldName:o,newName:n}=e,r=[],a=[],s;Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var t;r=e.conversationGroupList,-1!==(s=r.indexOf(o))&&((t=r.slice()).splice(s,1,n),a.push({conversationID:e.conversationID,data:{conversationGroupList:t}}))}),I(a)}_deleteLocalConversationGroupName(r){var{utils:{isEmpty:e},appStore:t}=this._core;if(!e(r)){let n=[];Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var{conversationID:e,conversationGroupList:t}=e,o=t.filter(e=>!r.includes(e));o.length<t.length&&n.push({conversationID:e,data:{conversationGroupList:o}})}),I(n)}}_getFlagBit(e){var t=e.toString(2),o=t.length;for(let e=o-1;0<=e;e--)if("1"===t[e])return o-e-1}_handleConversationGroupAdd(e){let t,{utils:{isArray:i},appStore:c}=this._core;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{var e=e["RecentContactCreateContactGroup"]["MsgContactGroupContactItem"];let s=!1;null!=e&&e.forEach(e=>{let{MsgGroupItem:t,MsgRecentContactItem:o}=e,{GroupId:n,GroupName:r}=t,a=[];l.getConversationGroup(n)!==r&&(l.setConversationGroup(n,r),s=!0),i(o)&&o.forEach(e=>{var t=m(e),o=c.conversationStore.getConversation(t);if(o&&(null==(e=o.conversationGroupList)||!e.includes(r))){let e=o.conversationGroupList.slice();e.push(r),a.push({conversationID:t,data:{conversationGroupList:e}})}}),s&&v(),I(a)})})}_handleConversationGroupDeleted(e){let t,{isArray:o}=this._core.utils;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{e=((null==e?void 0:e.RecentContactDelContactGroup)||{}).MsgGroupItem;if(o(e)){let n=!1,r=[];e.forEach(e=>{var{GroupId:e,GroupName:t}=e,o=l.getConversationGroupMap();o.has(e)&&(o.delete(e),n=!0,r.push(t))}),n&&v(),0<r.length&&this._deleteLocalConversationGroupName(r)}})}_handleConversationGroupUpdated(e){null!=(e=e.RecentContactMod)&&e.forEach(e=>{var{GroupId:e,GroupName:t,OldGroupName:o,RecentContactUpdateGroupItem:n,UpdateGroupType:r}=e["RecentContactUpdateContactGroup"]["MsgUpdateGroup"];1===r?this._handleGroupNameUpdated({groupID:e,newName:t,oldName:o}):2===r&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:n,groupName:o})})}_handleConversationMarkUpdated(e){let t,a=this._core.appStore;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{let{RecentContactMarkContactItem:t}=e["RecentContactMarkContact"],r=[];null!=t&&t.forEach(e=>{var{RecentContactItem:e,CustomMark:t,StandardMark:o,OptType:n}=e,e=m(e),e=a.conversationStore.getConversation(e);e&&(1===n?this._updateStandMark({conversation:e,standardMark:o,updateConversationList:r}):2===n?this._updateCustomMark({conversation:e,customMark:t,updateConversationList:r}):3===n&&(this._updateStandMark({conversation:e,standardMark:o,updateConversationList:r}),this._updateCustomMark({conversation:e,customMark:t,updateConversationList:r})))}),I(r)})}_updateStandMark(e){var{conversation:e,standardMark:t,updateConversationList:o}=e,t=u(t);!function(o,n){if(o===n)return 1;if(o&&n&&o.length===n.length){o.sort(),n.sort();for(let e=0,t=o.length;e<t;e++)if(o[e]!==n[e])return;return 1}}(e.markList,t)&&o.push({conversationID:e.conversationID,data:{markList:t}})}_updateCustomMark(e){var{conversation:e,customMark:t,updateConversationList:o}=e;e.customData!==t&&void 0!==t&&(e.customData=t,o.push({conversationID:e.conversationID,data:{customData:t}}))}_handleGroupNameUpdated(e){var{groupID:e,oldName:t,newName:o}=e;l.getConversationGroup(e)!==o&&(l.setConversationGroup(e,o),v(),this._updateLocalConversationGroupName({oldName:t,newName:o}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:e,groupName:a}){let s=this._core["appStore"],i=[];e.forEach(e=>{var{RecentContactItem:e,ContactOptType:t}=e,o=m(e),n=s.conversationStore.getConversation(o),r=n.conversationGroupList.indexOf(a);if(n){let e=n.conversationGroupList.slice();1===t&&-1===r?(e.push(a),i.push({conversationID:o,data:{conversationGroupList:e}})):2===t&&-1!==r&&(e.splice(r,1),i.push({conversationID:o,data:{conversationGroupList:e}}))}}),I(i)}dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t},InnerEventSubType:{CONVERSATION_MARK_UPDATED:o,CONVERSATION_GROUP_ADD:n,CONVERSATION_GROUP_DELETED:r,CONVERSATION_GROUP_UPDATED:a}}=this._core;e.unSubscribeInnerEvent(t,n,this._handleConversationGroupAdd,this),e.unSubscribeInnerEvent(t,r,this._handleConversationGroupDeleted,this),e.unSubscribeInnerEvent(t,a,this._handleConversationGroupUpdated,this),e.unSubscribeInnerEvent(t,o,this._handleConversationMarkUpdated,this)}};let s={required:!0,rules:["string"],allowEmpty:!1},i={required:!0,rules:["array"],allowEmpty:!1},C={createConversationGroup:{groupName:s,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:s,newName:Object.assign(Object.assign({},s),{customValidator:e=>!(32<e.length)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:i,groupName:s},deleteConversationsFromGroup:{conversationIDList:i,groupName:s},markConversation:{conversationIDList:i,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:e=>e<=0?"markType must be greater than 0":!(e>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:i,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>"string"!=typeof e?"customData must be string":!(256<e.length)||"customData length cannot longer than 256"}}},g={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};return new class{constructor(){this.name="ConversationGroup"}install(e){this._core=e,d.init(e),l.init(e),n.init(e),r.init(e),a.init(e),e.helper.registerValidateConfig({auth:g,params:C}),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.LOGOUT,this.reset,this),e.notificationCenter.subscribeInnerEvent(e.InnerEvent.DESTROY,this.dispose,this)}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.DESTROY,this.dispose,this),a.dispose(),r.dispose()}reset(){r.reset()}}});
|