"use strict";const e=require("../../../common/vendor.js"),t=require("../../constant.js"),a=require("../../utils/env.js"),n=require("../../../common/assets.js"),r=require("../../utils/enableSampleTaskStatus.js");class s{constructor(){this.hideConversationHeader=()=>{e.Jt.update(e.o.CUSTOM,"isShowConversationHeader",!1)},e.R.registerService(e.E.TUIConversation.SERVICE.NAME,this),e.R.registerExtension(e.E.TUISearch.EXTENSION.SEARCH_MORE.EXT_ID,this),this.onCallParamsMap=new Map,this.onCallCallbackMap=new Map,this.constants=e.E}static getInstance(){return s.instance||(s.instance=new s),s.instance}getOnCallParams(e){return this.onCallParamsMap.get(e)}getOnCallCallback(e){return this.onCallCallbackMap.get(e)}onCall(t,a,n){switch(this.onCallParamsMap.set(t,a),this.onCallCallbackMap.set(t,n),t){case e.E.TUIConversation.SERVICE.METHOD.CREATE_CONVERSATION:this.createConversation(a);break;case e.E.TUIConversation.SERVICE.METHOD.HIDE_CONVERSATION_HEADER:this.hideConversationHeader()}}onGetExtension(a){if(a===e.E.TUISearch.EXTENSION.SEARCH_MORE.EXT_ID){return[{weight:100,icon:n.C2C,text:e.Wt.t("TUIConversation.发起单聊"),data:{name:t.CONV_CREATE_TYPE.TYPEC2C},listener:{onClicked:this.createConversation.bind(this)}},{weight:100,icon:n.createGroup,text:e.Wt.t("TUIConversation.发起群聊"),data:{name:t.CONV_CREATE_TYPE.TYPEGROUP},listener:{onClicked:this.createConversation.bind(this)}}]}}createConversation(a){e.R.callService({serviceName:e.E.TUIContact.SERVICE.NAME,method:e.E.TUIContact.SERVICE.METHOD.SELECT_FRIEND,params:{title:a.text,isRadio:a.data.name!==t.CONV_CREATE_TYPE.TYPEGROUP,isNeedSearch:!e.Jt.getData(e.o.APP,"isOfficial")},callback:async e=>{if(!e||0===e.length)return this.routerForward(null);if(a.data.name===t.CONV_CREATE_TYPE.TYPEGROUP)this.createGroup(e);else{const{userID:t}=e[0];await this.generateConversation(`C2C${t}`),this.routerForward(`C2C${t}`)}}})}createGroup(t){e.R.callService({serviceName:e.E.TUIGroup.SERVICE.NAME,method:e.E.TUIGroup.SERVICE.METHOD.CREATE_GROUP,params:{title:e.Wt.t("TUIConversation.发起群聊"),memberList:t},callback:async e=>{let t=null;if(e){const{groupID:a}=e;await this.generateConversation(`GROUP${a}`),t=`GROUP${a}`}this.routerForward(t)}})}async routerForward(t){var n,r;a.isUniFrameWork&&(await(null==(n=e.i)?void 0:n.reLaunch({url:"/TUIKit/components/TUIConversation/index"})),t&&(null==(r=e.i)||r.navigateTo({url:"/TUIKit/components/TUIChat/index"})))}generateConversation(t){e.Xt.switchConversation(t).then((()=>{t.startsWith("GROUP")&&r.enableSampleTaskStatus("groupChat"),console.warn("打开会话成功")})).catch((e=>{console.warn("打开会话失败",e.code,e.msg)}))}}exports.TUIConversationServer=s;
