@tencentcloud/chat
Version:
Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut
1 lines • 20.4 kB
JavaScript
let e=4,t=11,s=12,o=20,n=23,i=27;class r{constructor(e=0,t=0){this.high=e,this.low=t}equal(e){return null!==e&&this.low===e.low&&this.high===e.high}toString(){var e=Number(this.high).toString(16);let t=Number(this.low).toString(16);if(t.length<8){let e=8-t.length;for(;e;)t="0"+t,e--}return e+t}}let u={TEST:{CHINA:{DEFAULT:"wss://wss-dev.tim.qq.com"},OVERSEA:{DEFAULT:"wss://wss-dev.tim.qq.com"},SINGAPORE:{DEFAULT:"wss://wsssgp-dev.im.qcloud.com"},KOREA:{DEFAULT:"wss://wsskr-dev.im.qcloud.com"},GERMANY:{DEFAULT:"wss://wssger-dev.im.qcloud.com"},IND:{DEFAULT:"wss://wssind-dev.im.qcloud.com"},JPN:{DEFAULT:"wss://wssjpn-dev.im.qcloud.com"},USA:{DEFAULT:"wss://wssusa-dev.im.qcloud.com"},INDONESIA:{DEFAULT:"wss://wssidn-dev.im.qcloud.com"}},PRODUCTION:{CHINA:{DEFAULT0:"wss://*w4c.my-imcloud.com",DEFAULT:"wss://wss.im.qcloud.com",IPV6:"wss://wssv6.im.qcloud.com",BACKUP:"wss://wss.tim.qq.com",BACKUP_WEB:"wss://*w4c.my-cpaas.com",STAT:"https://events.im.qcloud.com",ANYCAST:"wss://162.14.13.203"},OVERSEA:{DEFAULT0:"wss://*w4c.my-imcloud.com",DEFAULT:"wss://wss.im.qcloud.com",IPV6:"wss://wssv6.im.qcloud.com",BACKUP:"wss://wss.my-imcloud.com",BACKUP_WEB:"wss://*w4c.my-cpaas.com",STAT:"https://api.my-imcloud.com"},SINGAPORE:{DEFAULT0:"wss://*w4s.my-imcloud.com",DEFAULT:"wss://wsssgp.im.qcloud.com",IPV6:"wss://wsssgpv6.im.qcloud.com",BACKUP:"wss://wsssgp.my-imcloud.com",BACKUP_WEB:"wss://*w4s.my-cpaas.com",STAT:"https://apisgp.my-imcloud.com",ANYCAST:"wss://162.14.19.159"},KOREA:{DEFAULT0:"wss://*w4k.my-imcloud.com",DEFAULT:"wss://wsskr.im.qcloud.com",IPV6:"wss://wsskrv6.im.qcloud.com",BACKUP:"wss://wsskr.my-imcloud.com",BACKUP_WEB:"wss://*w4k.my-cpaas.com",STAT:"https://apikr.my-imcloud.com",ANYCAST:"wss://162.14.13.104"},GERMANY:{DEFAULT0:"wss://*w4g.my-imcloud.com",DEFAULT:"wss://wssger.im.qcloud.com",IPV6:"wss://wssgerv6.im.qcloud.com",BACKUP:"wss://wssger.my-imcloud.com",BACKUP_WEB:"wss://*w4g.my-cpaas.com",STAT:"https://apiger.my-imcloud.com",ANYCAST:"wss://162.14.3.17"},IND:{DEFAULT0:"wss://*w4i.my-imcloud.com",DEFAULT:"wss://wssind.my-imcloud.com",IPV6:"wss://wssindv6.im.qcloud.com",BACKUP:"wss://wssind.im.qcloud.com",BACKUP_WEB:"wss://*w4i.my-cpaas.com",STAT:"https://apiind.my-imcloud.com",ANYCAST:"wss://162.14.19.46"},JPN:{DEFAULT0:"wss://*w4j.my-imcloud.com",DEFAULT:"wss://wssjpn.im.qcloud.com",IPV6:"wss://wssjpnv6.im.qcloud.com",BACKUP:"wss://wssjpn.my-imcloud.com",BACKUP_WEB:"wss://*w4j.my-cpaas.com",STAT:"https://apijpn.my-imcloud.com"},USA:{DEFAULT0:"wss://*w4u.my-imcloud.com",DEFAULT:"wss://wssusa.im.qcloud.com",IPV6:"wss://wssusav6.im.qcloud.com",BACKUP:"wss://wssusa.my-imcloud.com",BACKUP_WEB:"wss://*w4u.my-cpaas.com",STAT:"https://apiusa.my-imcloud.com",ANYCAST:"wss://162.14.10.42"},INDONESIA:{DEFAULT0:"wss://*w4y.my-imcloud.com",DEFAULT:"wss://wssidn.im.qcloud.com",IPV6:"wss://wssidnv6.im.qcloud.com",BACKUP:"wss://wssidn.my-imcloud.com",BACKUP_WEB:"wss://*w4y.my-cpaas.com",STAT:"https://apiidn.my-imcloud.com",ANYCAST:"wss://43.129.34.169"}}},c={ANDROID:2,IOS:3,MAC:4,WEB:7,WX_MP:8,QQ_MP:9,TT_MP:10,BAIDU_MP:11,ALI_MP:12,IPAD:13,UNI_NATIVE_APP:15,DONUT_NATIVE_APP:19,NS_NATIVE_APP:20,RN_NATIVE_APP:21},m="CHINA",a={HOST:{CURRENT:{DEFAULT:"wss://wss.im.qcloud.com",STAT:"https://events.im.qcloud.com"},setCurrent(e=m){this.CURRENT=u.PRODUCTION[e]}},NAME:{OPEN_IM:"openim",OPEN_IM_MSG_EXT:"openim_msg_ext_http_svc",GRP:"group_open_http_svc",GRP_AV:"group_open_avchatroom_http_svc",GRP_COMMUNITY:"million_group_open_http_svc",GRP_ATTR:"group_open_attr_http_svc",FD:"sns",PROFILE:"profile",RECENT_CONTACT:"recentcontact",PIC:"openpic",BIG_GRP_NO_AUTH:"group_open_http_noauth_svc",BIG_GRP_POLLING:"group_open_long_polling_http_svc",BIG_GRP_POLLING_NO_AUTH:"group_open_long_polling_http_noauth_svc",IM_OPEN_STAT:"imopenstat",WEB_IM:"webim",IM_COS_SIGN:"im_cos_sign_svr",CUSTOM_UPLOAD:"im_cos_msg",HEARTBEAT:"heartbeat",IM_OPEN_PUSH:"im_open_push",IM_OPEN_STATUS:"im_open_status",IM_LONG_MSG:"im_long_msg",IM_CONFIG_MANAGER:"im_sdk_config_mgr",STAT_SERVICE:"StatSvc",OVERLOAD_PUSH:"OverLoadPush",IM_MSG_AUDIT_MGR:"im_msg_audit_mgr",TUIROOM_SVR:"tui_room_svr",IM_OPEN_TRANSLATE:"im_open_translate",IM_OPEN_SPEECH:"im_open_speech",MSG_SEARCH:"message_search",GRP_SEARCH:"group_search",GRP_MEMBER_SEARCH:"group_member_search",USER_SEARCH:"user_search",FOLLOW:"follow",OFFLINE_PUSH_REPORT:"offline_push_report",IM_MSG_LOGIC:"im_msg_db_logic"}},l=(new r(0,Math.pow(2,1)).toString(),new r(0,Math.pow(2,2)).toString(),new r(0,Math.pow(2,3)).toString(),new r(0,Math.pow(2,4)).toString(),new r(0,Math.pow(2,6)).toString(),new r(0,Math.pow(2,7)).toString(),new r(0,Math.pow(2,9)).toString(),new r(0,Math.pow(2,10)).toString(),new r(0,Math.pow(2,11)).toString(),new r(0,Math.pow(2,13)).toString(),new r(0,Math.pow(2,15)).toString(),new r(Math.pow(2,6)).toString(),new r(Math.pow(2,7)).toString(),new r(Math.pow(2,8)).toString(),new r(Math.pow(2,9)).toString(),new r(Math.pow(2,10)).toString(),new r(Math.pow(2,16)).toString(),new r(Math.pow(2,20)).toString(),a.HOST.setCurrent(m),"undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting)),g=(l&&wx.createGamePortal,"undefined"!=typeof qq&&"function"==typeof qq.getSystemInfoSync&&Boolean(qq.getSystemInfoSync().fontSizeSetting)),h="undefined"!=typeof tt&&"function"==typeof tt.getSystemInfoSync&&Boolean(tt.getSystemInfoSync().fontSizeSetting),d="undefined"!=typeof swan&&"function"==typeof swan.getSystemInfoSync&&Boolean(swan.getSystemInfoSync().fontSizeSetting),p="undefined"!=typeof my&&"function"==typeof my.getSystemInfoSync&&Boolean(my.getSystemInfoSync().fontSizeSetting),f="undefined"!=typeof jd&&"function"==typeof jd.getSystemInfoSync,_="undefined"!=typeof uni&&"undefined"==typeof window&&"function"==typeof uni.requireNativePlugin,w=l&&"object"==typeof wx.miniapp,S=l||g||h||d||p||_||f,y="undefined"==typeof window&&!S&&"undefined"!=typeof global&&void 0!==global.NativeScriptGlobals,T="undefined"!=typeof global&&(void 0!==global.nativeModuleProxy||void 0!==global.ReactNative),M="undefined"!=typeof uni?!S:"undefined"!=typeof window&&!S&&!T,A=(g?qq:h?tt:d?swan:p?my:l?wx:_?uni:f&&jd,M&&window&&window.navigator&&window.navigator.userAgent||""),I=/(micromessenger|webbrowser)/i.test(A),E=function(){let e="WEB";return I?e="WEB":g?e="QQ_MP":h?e="TT_MP":d?e="BAIDU_MP":p?e="ALI_MP":l?e=w?"DONUT_NATIVE_APP":"WX_MP":_?e="UNI_NATIVE_APP":y?e="NS_NATIVE_APP":T&&(e="RN_NATIVE_APP"),c[e]}(),P=(!function(){var e=A.match(/OS (\d+)_/i);e&&e[1]&&e[1]}(),function(){var e,t,s=A.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);s&&(e=s[1]&&parseFloat(s[1]),t=s[2]&&parseFloat(s[2]),e)&&t&&parseFloat(s[1]+"."+s[2])}(),/MSIE/.test(A)||-1<A.indexOf("Trident")&&-1<A.indexOf("rv:11.0")),C,N,v=(!function(){var e=/MSIE\s(\d+)\.\d/.exec(A),e=e&&parseFloat(e[1]);!e&&/Trident\/7.0/i.test(A)&&/rv:11.0/.test(A)}(),C="undefined"!=typeof console?console:"undefined"!=typeof global&&global.console?global.console:"undefined"!=typeof window&&window.console?window.console:{},function(){}),b=["assert","clear","count","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"],D=b.length;for(;D--;)N=b[D],console[N]||(C[N]=v);var U=C;let O="C2C",L="GROUP",R=function(){return(new Date).getTime()+0},q=Object.prototype.hasOwnProperty,F=function(e){return"map"===H(e)},x=function(e){return"set"===H(e)},B=function(e){return"file"===H(e)},k=function(e){return null!==e&&("number"==typeof e&&!isNaN(+e)||"object"==typeof e&&e.constructor===Number)},G=function(e){return"string"==typeof e},j=function(e){if("object"!=typeof e||null===e)return!1;e=Object.getPrototypeOf(e);if(null===e)return!0;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return e===t},$=function(e){return"function"==typeof Array.isArray?Array.isArray(e):"array"===H(e)},K=function(e){return $(e)&&0<e.length},V=function(e){return void 0===e},W=function(e){return $(e)||null!==e&&"object"==typeof e},H=function(e){return Object.prototype.toString.call(e).match(/^\[object (.*)\]$/)[1].toLowerCase()},Y=(Date.now||(Date.now=function(){return(new Date).getTime()}),function(s,r,o,i){if(!W(s)||!W(r))return 0;let n=0;var a,u=Object.keys(r);for(let e=0,t=u.length;e<t;e++)if(a=u[e],!(V(r[a])||o&&o.includes(a)))if(W(s[a])&&W(r[a]))n+=Y(s[a],r[a],o,i);else{if(i&&i.includes(r[a]))continue;s[a]!==r[a]&&(s[a]=r[a],n+=1)}return n});function z(){return!P&&!S}let J=0;function Q(){return z()?"%c Chat %c":"Chat"}function X(){(e=new Date).setTime(R());var e;return e.toLocaleTimeString("en-US",{hour12:!1})+"."+function(e){let t;switch(e.toString().length){case 1:t="00"+e;break;case 2:t="0"+e;break;default:t=e}return t}(e.getMilliseconds())}let Z={arguments2String(s){let r="";if(1===s.length)r=s[0];else for(let e=0,t=s.length;e<t;e++){if(W(s[e]))try{r+=s[e]instanceof Error?JSON.stringify(s[e],["message","code"]):JSON.stringify(s[e])}catch(e){r+=e?e.message:"";break}else r+=s[e];r+=" "}return r},_exec(e,t){z()?U[e](Q(),"background:#0abf5b; padding:1px; border-radius:3px; color: #fff","background:transparent",X(),t):U[e](`${Q()} ${X()} `+t)},d:function(){var e;J<=-1&&(e=this.arguments2String(arguments),this._exec("debug",e))},l:function(){var e;J<=0&&(e=this.arguments2String(arguments),this._exec("log",e))},log:function(){var e;J<=0&&(e=this.arguments2String(arguments),this._exec("log",e))},i:function(){var e;J<=1&&(e=this.arguments2String(arguments),this._exec("info",e))},w:function(){var e;J<=2&&(e=this.arguments2String(arguments),this._exec("warn",e))},e:function(){var e;J<=3&&(e=this.arguments2String(arguments),this._exec("error",e))},setLevel:function(e){e<4&&this._exec("log","set level from "+J+" to "+e),J=e},getLevel:function(){return J}},ee=function(e){return{code:0,data:e||{}}};class te extends Error{constructor(e){super();var{code:e,message:t,data:s}=e;this.code=e,t?this.message=t:this._getErrMsg&&(this.message=this._getErrMsg(this.code)),this.data=s||{}}}let se=2805,oe=2903,ne=3122,ie=3153,re="error",ue=null,ce=function(e,t=!1){if(e instanceof te)return t&&null!==ue&&ue.emit(re,e),Promise.reject(e);if(e instanceof Error){let e=new te({code:oe});return t&&null!==ue&&ue.emit(re,e),Promise.reject(e)}return V(e)||V(e.code)?Promise.reject(new te({code:oe})):(e=new te(e),t&&null!==ue&&ue.emit(re,e),Promise.reject(e))},me="query",ae="query_grp",le="query_grp_member",ge="query_user",he={info:4,warning:5,error:6},de={wifi:1,"2g":2,"3g":3,"4g":4,"5g":5,unknown:6,none:7,online:8},pe={login:4,plugin_search:16,plugin_translate:16,plugin_voice_to_text:16,plugin_cs:16,plugin_push:16,plugin_bot:16,plugin_emoji_reaction:16,tui_key_features:16};class fe{constructor(e){this._n="SSOLogData",this.eventType=pe[e]||0,this.timestamp=0,this.networkType=8,this.code=0,this.message="",this.moreMessage="",this.extension=e,this.costTime=0,this.duplicate=!1,this.level=4,this.uiPlatform=void 0,this._sentFlag=!1,this._startts=R()}static bindEventStatModule(e){fe.prototype._eventStatModule=e}static bindNetMonitorModule(e){fe.prototype._netMonitorModule=e}updateTimeStamp(){this.timestamp=R()}start(e){return this._startts=e,this}end(e=!1){if(!this._sentFlag){if(this._netMonitorModule){let e=this._netMonitorModule.getNetworkType();this.setNetworkType(e)}var t=R();0===this.costTime&&(this.costTime=t-this._startts),this.setMoreMessage(`startts:${this._startts} endts:`+t),e?(this._sentFlag=!0,this._eventStatModule&&this._eventStatModule.pushIn(this)):setTimeout(()=>{this._sentFlag=!0,this._eventStatModule&&this._eventStatModule.pushIn(this)},0)}}setError(t){if(t instanceof Error){if(!this._sentFlag){let e=!0;if(e=this._netMonitorModule?this._netMonitorModule.isOnline():e)t.code&&this.setCode(t.code),t.message&&this.setMoreMessage(t.message);else{let e=se;this.setCode(e)}this.setLevel("error")}}else Z.w(this._n+".setError value not instanceof Error, please check!");return this}setCode(e){return V(e)||this._sentFlag||("ECONNABORTED"===e&&(this.code=103),k(e)?this.code=e:Z.w(this._n+".setCode value not a number, please check!",e,typeof e)),this}setMessage(e){return V(e)||this._sentFlag||(k(e)&&(this.message=e.toString()),G(e)&&(this.message=e)),this}setCostTime(e){return this.costTime=e,this}setLevel(e){return V(e)||this._sentFlag||(this.level=he[e]),this}setMoreMessage(e){return function(e){if(null==e)return 1;if("boolean"!=typeof e){if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(j(e)){for(var t in e)if(q.call(e,t))return;return 1}return(F(e)||x(e)||B(e))&&0===e.size}}(this.moreMessage)?this.moreMessage=""+e:this.moreMessage+=" "+e,this}setNetworkType(e){return V(e)?Z.w(this._n+".setNetworkType value is undefined, please check!"):(e=de[e.toLowerCase()],V(e)||(this.networkType=e)),this}getStartTs(){return this._startts}setUIPlatform(e){return this.uiPlatform=e,this}setExtension(e){return this.extension=e,this}setEventType(e){return this.eventType=e,this}}let _e=["groupID","name","avatar","type","introduction","notification","ownerID","selfInfo","createTime","infoSequence","lastInfoTime","lastMessage","nextMessageSeq","memberNum","maxMemberNum","memberList","joinOption","groupCustomField","muteAllMembers","isSupportTopic","inviteOption","_lastRevokedTime"];class we{constructor(e){this.groupID="",this.name="",this.avatar="",this.type="",this.introduction="",this.notification="",this.ownerID="",this.createTime="",this.infoSequence="",this.lastInfoTime="",this.selfInfo={messageRemindType:"",joinTime:"",nameCard:"",role:"",userID:"",memberCustomField:void 0,readedSequence:0,excludedUnreadSequenceList:void 0},this.lastMessage={lastTime:"",lastSequence:"",fromAccount:"",messageForShow:""},this.nextMessageSeq="",this.memberNum="",this.memberCount="",this.maxMemberNum="",this.maxMemberCount="",this.joinOption="",this.inviteOption="",this.groupCustomField=[],this.muteAllMembers=!1,this.isSupportTopic=!1,this._lastRevokedTime=0,this._initGroup(e)}set memberNum(e){}set maxMemberNum(e){}get memberNum(){return this.memberCount}get maxMemberNum(){return this.maxMemberCount}_initGroup(e){for(var t in e)_e.indexOf(t)<0||("selfInfo"!==t?("memberNum"===t&&(this.memberCount=e[t]),"maxMemberNum"===t&&(this.maxMemberCount=e[t]),"isSupportTopic"!==t?this[t]=e[t]:this.isSupportTopic=1===e[t]):this.updateSelfInfo(e[t]))}updateGroup(e){e.appid=void 0,e.grossTopicNextMsgSeq=void 0,e.selfInfo&&(e.selfInfo.grossTopicReadSeq=void 0);e=JSON.parse(JSON.stringify(e));if(e.lastMsgTime&&(this.lastMessage.lastTime=e.lastMsgTime),V(e.muteAllMembers)||("On"===e.muteAllMembers?e.muteAllMembers=!0:e.muteAllMembers=!1),e.groupCustomField){var o=this.groupCustomField,t=e.groupCustomField;if($(o)&&$(t)){let r=!1;t.forEach(({key:t,value:e})=>{var s=o.find(e=>e.key===t);s?s.value!==e&&(s.value=e,r=!0):(o.push({key:t,value:e}),r=!0)})}}V(e.memberNum)||(this.memberCount=e.memberNum),V(e.maxMemberNum)||(this.maxMemberCount=e.maxMemberNum),V(e.isSupportTopic)||(this.isSupportTopic=k(e.isSupportTopic)?1===e.isSupportTopic:e.isSupportTopic),Y(this,e,["members","errorCode","lastMsgTime","groupCustomField","memberNum","maxMemberNum","isSupportTopic"]),$(e.members)&&0<e.members.length&&e.members.forEach(e=>{e.userID===this.selfInfo.userID&&Y(this.selfInfo,e,["sequence"])})}updateSelfInfo({nameCard:e,joinTime:t,role:s,messageRemindType:r,readedSequence:o,excludedUnreadSequenceList:i}){e={nameCard:e,joinTime:t,role:s,messageRemindType:r,readedSequence:o,excludedUnreadSequenceList:i};Y(this.selfInfo,{...e},[],["",null,void 0,0,NaN])}setSelfNameCard(e){this.selfInfo.nameCard=e}}let Se="Message",ye="User",Te="Group",Me="GroupMember",Ae={[Se]:me,[ye]:ge,[Te]:ae,[Me]:le};class Ie extends class{constructor(e){this._m=e,this._n=""}isLoggedIn(){return this._m.get(s).isLoggedIn()}isOversea(){return this._m.get(s).isOversea()}isPrivateNetWork(){var e=this._m.get(s);return e.isPrivateNetWork()&&!e.getFileDownloadProxy()}getFileDownloadProxy(){return this._m.get(s).getFileDownloadProxy()}getDownloadFileAuthKey(){return this._m.get(s).getDownloadFileAuthKey()}getMyUserID(){return this._m.get(s).getUserID()}getMyTinyID(){return this._m.get(s).getTinyID()}getSDKAppID(){return this._m.get(s).getSDKAppID()}isIntl(){return this._m.get(s).isIntl()}isUsingChatCore(){return this._m.get(s).isUsingChatCore()}isDevMode(){return this._m.get(s).isDevMode()}get(e){return this._m.get(e)}getPlatform(){return E}getCloudConfig(e){return this._m.get(n).getCloudConfig(e)}emitOEvt(e,t){this._m.getOEmitInst().emit(e,t)}emitIEvt(e,t){this._m.getIEmitInst().emit(e,t)}getIEmitInst(){return this._m.getIEmitInst()}req(e){return this._m.get(o).req(e)}canIUse(e){return this._m.get(i).canIUse(e)}getErrMsg(e,t,s){return this._m.getErrMsg(e,t,s)}warn(e,t,s){e=this.getErrMsg(e,t,s);e&&Z.w(e)}noUse(e){var t=ne;return ce({code:t,message:this.getErrMsg(t,e)})}}{constructor(e){super(e),this._n="CSModule"}searchCloudMessages(e){return this.search(Se,e)}searchCloudUsers(e){return this.search(ye,e)}searchCloudGroups(e){return this.search(Te,e)}searchCloudGroupMembers(e){return this.search(Me,e)}search(n,s){let e=`searchCloud${n}s`,a=this._n+"."+e;if(!s)return ce({code:ie,message:this.getErrMsg(ie,e)});var t=s["keywordList"],r=K(t);let o=s.count;if(s.count&&(o=parseInt(o)),n===Se&&!r&&!K(s.senderUserIDList)&&!K(s.messageTypeList)||n!==Se&&!r)throw Z.e(`[${e}] Missing required params: "keywordList".`),new Error("Params validate failed.");let u=Date.now(),m=new fe(e),c=`keywordList:${t} keywordListMatchType:${s.keywordListMatchType} cursor:${s.cursor} count:`+o;return Z.l(a+" "+c),this.req({P:Ae[n],data:this._genParams(n,s)}).then(e=>{var{code:r,message:o}=e.data;if(0!==r){let e=r,t=(60020===r?e="SearchUnable":n!==Se&&27003===r?e="SearchParamsError":n!==Se&&60018===r&&(e="SearchOverLimit"),this.getErrMsg(e)||o),s=new te({code:r,message:t});return m.setMessage(c).setError(s).end(),ce(s)}this.get(i).isCSPluginEnabled();var{cursor:o="",totalCount:r}=e.data,t=`totalCount:${r} cost:`+(t=u,Date.now()-t)+" ms",t=(Z.l(a+` ok. cursor:${o} `+t),m.setMessage(c+" "+t).end(),this._genRes(n,s,e.data));return ee({searchResultList:t,cursor:o,totalCount:r})}).catch(e=>(m.setMessage(c).setError(e).end(),ce(e)))}_genParams(e,t){let{count:s,...r}=t;var o;return s&&(r.count=parseInt(s)),e===Se?this._genMsgParams(r):({keywordList:t,keywordListMatchType:o}=t,r.keywords=t,r.keywordMatchType="and"===o?1:0,e===ye?this._genUserParams(r):r)}_genMsgParams(e){let{conversationID:t,timePosition:s,timePeriod:r,...o}=e;return V(t)||(e=t,G(e)&&e.slice(0,3)===O&&(o.account=t.replace(O,"")),e=t,G(e)&&e.slice(0,5)===L&&(o.groupID=t.replace(L,""))),k(r)&&0<r&&(k(s)&&0<s?o.startTime=s-r:o.startTime=Math.floor(R()/1e3)-r),o.startTime&&o.startTime<0&&(o.startTime=void 0),k(s)&&0<s&&(o.endTime=s),o}_genUserParams(e){let{miniBirthday:t,maxBirthday:s,...r}=e;return k(t)&&(r.miniBirthday=parseInt(t),k(s)||(r.maxBirthday=4294967295)),k(s)&&(r.maxBirthday=parseInt(s)),r}_genRes(e,t,s){switch(e){case Se:return this._genMsgRes(s.searchResult,!t.conversationID);case ye:return this._genUserRes(s.userList);case Te:return this._genGrpRes(s.groupList);case Me:return this._genMemberRes(s.groupMemberList);default:return[]}}_genMsgRes(e,n){let a=this.get(t);return $(e)&&0!==e.length?e.map(({groupID:t,userID:e,messageCount:s,messageList:r=[]})=>{var o=t?""+L+t:""+O+e,i={conversationID:o,messageCount:s,messageList:[]};if(!(n&&1<s)){s=r.filter(e=>!!e);if(0<s.length){let e=a.onRoamingMessage(s,o,!1);t&&e.reverse(),i.messageList=e,i.messageCount=e.length}}return i}):[]}_genUserRes(s){var r=this.get(e)._profileHandler;if(!$(s))return[];var o=[];for(let e=0,t=s.length;e<t;e++){var{userID:i,profileItems:n}=s[e];"@TLS#NOT_FOUND"!==i&&""!==i&&(i=r._update(i,r._getLatestProfileFromResponse(i,n))["latestProfile"],o.push(i))}return o}_genGrpRes(s){if(!$(s))return[];var r=[];for(let e=0,t=s.length;e<t;e++)s[e]&&s[e].groupID&&r.push(new we(s[e]));return r}_genMemberRes(s){if(!$(s))return[];var r=new Map;for(let e=0,t=s.length;e<t;e++)if(s[e]&&s[e].userID&&s[e].groupID){var{groupID:o,name:i,type:n,avatar:a,nick:u,userID:m,nameCard:c}=s[e],i={groupID:o,name:i,type:n,avatar:a},n={userID:m,nick:u,nameCard:c};if(r.has(o)){let e=r.get(o);e.memberList.push(n),r.set(o,e)}else r.set(o,{groupInfo:i,memberList:[n]})}return[...r.values()]}}export{Ie as default};