@rongcloud/electron 5.8.2-enterprise-lz.28 → 5.8.2-enterprise-lz.30

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/index.esm.js CHANGED
@@ -1 +1 @@
1
- import{resolve as e}from"path";import{app as t,ipcMain as n}from"electron";import*as o from"os";import{platform as r,arch as s}from"os";import{existsSync as i,mkdirSync as a,writeFileSync as c,readFileSync as u}from"fs";import{getUUID as p,BasicLogger as l,BasicStatistic as d,appendUrl as f,ErrorCode as h,HTTP_TIMEOUT as C,LogTagId as g,StoreKeys as v,BasicReporter as _,REAT_TIME_LOG_SIZE as S,notEmptyObject as y,NAVI_CACHE_DURATION as m,BasicNavi as P,NAVI_REQ_TIMEOUT as E,FORMATED_VERSION as R,getbundleId as I,StatisticsVersion as T,StatisticsTag as N,RCConnectionStatus as O,ProtocalType as M,ConnectType as U,AConnectionMgr as w,ConversationType as x,urlCenter as b,SEND_MESSAGE_TYPE_OPTION as A,isObject as L,isUndefined as D,pushJSONToConfigs as k,MessageDirection as J,NotificationStatus as j,MessageType as B,ReceivedStatus as H,NotificationLevel as F,transformNotificationLevel as V,MentionedType as G,pushConfigsToJSON as q,isArray as W,getUploadFileName as K,getMinionURL as Q}from"@rongcloud/engine";import{fork as Y}from"child_process";import{Agent as X,request as z}from"http";import{Agent as $,request as Z}from"https";import{parse as ee}from"url";import{isIP as te,Socket as ne}from"net";import{EventEmitter as oe}from"events";import{connect as re}from"tls";import{createHash as se}from"crypto";var ie=process.versions.electron.replace(/\.\d+$/,""),ae=e(__dirname,"binding","electron-v".concat(ie,"-").concat(r(),"-").concat(s(),".node")),ce=function(t){try{return require(ae)}catch(n){throw function(t,n){try{i(e(t,"RongCloud"))||a(e(t,"RongCloud"));var o=e(t,"RongCloud/addon-load-error.txt");c(o,n.toString())}catch(e){console.error(e)}}(t,n),n}},ue=function(e,t){return ue=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},ue(e,t)};function pe(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}ue(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var le,de=function(){return de=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},de.apply(this,arguments)};function fe(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}function he(e,t){var n,o,r,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],o=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function Ce(e,t,n){if(n||2===arguments.length)for(var o,r=0,s=t.length;r<s;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_DB_OP_E="P-db_op-E",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_E="P-connect-E",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_R="P-connect-R",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_E="P-parse_json-E",e.P_SEARCH_CONVERSATIONS_T="P-search_conversations-T",e.P_SEARCH_CONVERSATIONS_R="P-search_conversations-R",e.L_FORMAT_CONVERSATIONS_S="L-format_conversations-S",e.L_JS_GET_NOW_TIME_S="L-js_get_now_time-S",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R"}(le||(le={}));var ge,ve={flushTimestamp:Date.now(),queue:[],locked:!1};function _e(){ge&&clearInterval(ge)}function Se(e,t){_e(),ge=setInterval((function(){return Pe(e,t)}),1e4)}function ye(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(e=ve.queue).push.apply(e,t)}var me=200;function Pe(e,t){var n=ve.queue,o=ve.flushTimestamp;if(!(ve.locked||0===n.length||Date.now()-o<3e4&&n.length<me)){ve.locked=!0;var r=t.createTraceId(),s=n.splice(0,me).map((function(e){var t=e.sessionId,n=e.level,o=e.time,r=e.type,s=e.tag,i=e.loggerId,a=e.content,c=e.traceId;return{level:n,time:o,type:r,tag:s,content:encodeURIComponent(JSON.stringify({loggerId:i,sessionId:t,content:a,traceId:c})).replace(/'/g,"%27")}}));t.debug(le.P_WRITE_LOG_T,"writingLen: ".concat(s.length,", queueLen: ").concat(n.length),r);var i=JSON.stringify(s);e.writeLog(i),t.debug(le.P_WRITE_LOG_R,"write done, queueLen: ".concat(n.length),r),ve.flushTimestamp=Date.now(),ve.locked=!1,setTimeout((function(){return Pe(e,t)}))}}var Ee=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return pe(t,e),t.prototype.flush=function(e){ye(e)},t}(l),Re=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return pe(t,e),t.prototype.flush=function(e){ye(e)},t}(d),Ie=function(e,t){var n,o=Buffer.from(e),r=o.length;for(t.push(r),n=0;n<r;n++)t.push(o[n])},Te=function(e){return"string"==typeof e},Ne=function(e){return Te(e)?e.toUpperCase():""},Oe=function(e,t){var n="";return 2!==e.length?n="Unexpected number of bytes received.":5!==e[0]?n="Unexpected SOCKS version number: ".concat(e[0],"."):255===e[1]?n="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(n="Unexpected SOCKS authentication method: ".concat(e[1],".")),n},Me=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: ".concat(e[0],"."):0!==e[1]&&(t="Username and password authentication failure: ".concat(e[1],".")),t},Ue=function(e){var t=Ne(e.method)||"GET",n=e.pathname||"/",o=e.headers||{},r=e.search||"";o.Host=e.host||"loclahost";var s="";for(var i in s="".concat(t," ").concat(n+r," HTTP/1.1\n"),o)if(Object.hasOwnProperty.call(o,i)){var a=o[i];s+="".concat(i,": ").concat(a,"\n")}return e.body&&(s+="Content-Length: ".concat(e.body.length,"\n")),s+="\n","POST"===t&&e.body&&(s+="".concat(e.body)),s},we=function(e){return new Promise((function(t){var n,o;e.socket.once("data",(function(o){var r,s=Oe(o,n);if(!s)return 2===o[1]?(e.socket.once("data",(function(n){var o=Me(n);o?e.emit("error",new Error("SOCKS authentication failed. ".concat(o))):t()})),r=[1],Ie(e.socksUsername,r),Ie(e.socksPassword,r),void e.write(Buffer.from(r))):void t();e.emit("error",new Error("SOCKS authentication failed. ".concat(s)))})),n=[0],e.socksUsername&&n.push(2),(o=Buffer.alloc(2+n.length))[0]=5,o[1]=n.length,n.forEach((function(e,t){o[2+t]=e})),e.write(o)}))},xe=function(e,t,n){return new Promise((function(o){var r,s;switch(e.socket.once("data",(function(t){var n;5!==t[0]?n="Unexpected SOCKS version number: ".concat(t[0],"."):0!==t[1]?n="".concat(function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code ".concat(e)}}(t[1]),"."):0!==t[2]&&(n="The reserved byte must be 0x00."),n?e.emit("error",new Error("SOCKS connection failed. ".concat(n))):o()})),(r=[]).push(5),r.push(1),r.push(0),te(t)){case 0:r.push(3),Ie(t,r);break;case 4:r.push(1),function(e,t){var n,o,r=e.split(".");for(n=0;n<4;n++)o=parseInt(r[n],10),t.push(o)}(t,r);break;case 6:e.emit("error",new Error("Does not support IPV6"))}r.length+=2,(s=Buffer.from(r)).writeUInt16BE(n,s.length-2),e.write(s)}))},be=function(e){function t(t){var n=e.call(this)||this;return n.readable=!0,n.socket=new ne,n.options=t,n.socksHost=t.socksHost||"localhost",n.socksPort=t.socksPort||1080,n.socksUsername=t.socksUsername||"",n.socksPassword=t.socksPassword||"",n.socket.on("error",(function(e){n.emit("error",e)})),n.on("error",(function(){n.socket.destroyed||n.socket.destroy()})),n.on("end",n.end),n}return pe(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var n=this.socket.end(e,t);return this.writable=this.socket.writable,n},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,n){return this.socket.write(e,t,n)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var n=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: ".concat(e));if(!t||"string"!=typeof t)throw new TypeError("Invalid host: ".concat(t));return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return fe(n,void 0,void 0,(function(){var n;return he(this,(function(o){switch(o.label){case 0:return[4,we(this)];case 1:return o.sent(),[4,xe(this,t,e)];case 2:return o.sent(),this.onProxied(),n=Ue(this.options),this.socket.write(Buffer.from(n)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(oe),Ae=function(e){var t,n=e.hostname,o=e.port;return!e.host||n&&o||(t=e.host.split(":")),!o&&t&&(o=parseInt(t[1],10)||0),!n&&t&&(n=t[0]),new be(e).connect(o,n)},Le=function(e){function t(t){var n=e.call(this)||this;return n.createConnection=Ae,n}return pe(t,e),t}(X),De=function(e,t,n){return(t=de(de({},t),ee(e))).port||(t.port=80),t.agent=new Le(t),z(t,n)},ke=function(e){var t,n;return t=Ae(e),n=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=re(e,(function(){t.authorized=t.socket.authorized,n.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},Je=function(e){function t(t,n){var o=e.call(this,n)||this;return o.url=t,o.socksHost=n.socksHost||"localhost",o.socksPort=n.socksPort||1080,o.createConnection=ke,o}return pe(t,e),t}($),je=function(e,t,n,o){var r,s;return t.protocol="https:",!t.port&&t.host&&(r=t.host.split(":"),t.port=r[0],t.port=r[1]),t.port||(t.port=443),s=new Je(e,t),t.agent=s,Z(e,t,n)},Be=null;function He(e,t,n){void 0===n&&(n=!1);var o=t.url,r=t.headers,s=t.body,i=t.method,a=t.query,c=t.timeout,u=void 0===c?C:c;return new Promise((function(t){var c=/^https/.test(o),p={headers:r,method:i};c&&(p.rejectUnauthorized=n);var l=null;Be?((p=de(de({},p),Be)).body=s,l=c?je:De):(l=z,c&&(p.agent=new $(p),l=Z));var d=l(f(o,a),p,(function(e){var n=e.statusCode,o="";e.setEncoding("utf8"),e.on("data",(function(e){o+=e})),e.once("end",(function(){t({status:n||0,data:o})}))}));d.once("timeout",(function(){e.warn(le.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:o,method:i,query:a,timeout:u})),t({status:0})})),d.setTimeout(u),d.once("error",(function(n){e.warn(le.P_HTTP_REQ_E,JSON.stringify({msg:n.stack,url:o,method:i,query:a,timeout:u})),t({status:0})})),d.write(s),d.end()}))}function Fe(e,t){return e?(Be=de(de({},Be),e),t.info(g.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:Be})),{code:h.SUCCESS}):(Be=null,t.info(g.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:h.SUCCESS})}function Ve(){var e=Be||void 0;return{code:h.SUCCESS,data:e}}var Ge,qe=[],We=!1,Ke=function(){return fe(void 0,void 0,void 0,(function(){var e,t,n,o,r,s,i,a,c,u,p;return he(this,(function(l){return We||0===qe.length||(We=!0,e=qe.shift(),t=e.args,n=e.resolve,o=t.addon,r=t.startTime,s=t.endTime,i=t.level,a=t.realtimeReport,c=0,u=0,p=[],o.setLogEventListener((function(e){c+=e.length;var t=e.split(","),o=t[0],r=t[1],s=t[2],l=t[3],d=t[4],f=t.slice(5);if(c>S&&parseInt(r,10)!==u)n(p);else{u=parseInt(r,10);try{var h=JSON.parse(decodeURIComponent(f.join(","))),C=h.loggerId,g=h.sessionId,v=h.content,_=h.traceId;if(!a&&i<0)return;var y={time:parseInt(r,10),level:parseInt(l,10),sessionId:"".concat(o,":").concat(g),type:s,tag:d,loggerId:C,content:v,traceId:_};p.push(y)}catch(e){console.error(e)}}}),(function(e){n(p),We=!1,Ke()}),(function(e,t,n){})),o.pullFullLog(i,r,s,!1)),[2]}))}))},Qe=function(e){function t(t,n,o,r,s){var i=this,a=process.versions.electron,c="Electron|".concat(a,"|").concat(process.arch,"|").concat(process.platform);return i=e.call(this,n,o,c,{getLogs:function(e,n,o,r){return fe(this,void 0,void 0,(function(){return he(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:n,level:o,realtimeReport:r,addon:t},fe(void 0,void 0,void 0,(function(){return he(this,(function(e){return[2,new Promise((function(e){qe.push({resolve:e,args:i}),Ke()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var e=t.getStoreValue(v.REALTIME_LOG_TIMESTAMP);return parseInt(e,10)||0},setTimestamp4RealtimeLog:function(e){t.setStoreValue(v.REALTIME_LOG_TIMESTAMP,e.toString())}},r)||this,i.subProcess=s,i}return pe(t,e),t.prototype.send=function(e){return He(this.logger,e)},t.prototype.compressLogs=function(e){return fe(this,void 0,void 0,(function(){var t,n,o;return he(this,(function(r){switch(r.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=r.sent(),n=t.success,o=t.data,n?[2,{success:n,data:o}]:[2,{success:n,data:""}]}}))}))},t}(_),Ye=null,Xe=function(){var e,t=Date.now(),n=[s(),r(),process.pid,t,Math.floor(Math.random()*t)].join("__");return e=n,se("md5").update(e).digest("hex")},ze=function(t){if(Ye)return Ye;var n=e(t,"deviceId");return i(n)?Ye=u(n).toString():(Ye=Xe(),c(n,Ye),Ye)},$e=function(){function e(e){this._cppProto=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,n,o,r,s){var i=JSON.stringify(r);"{}"!==i&&e.info(le.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:o,ext:r})),this._cppProto.setMessageExtension(t,n,o,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime;if(i&&0!==Object.keys(i).length){var c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,o,r,s,c,n||"")}},e.prototype.setLocalFromExtMsg=function(e,t){var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._cppProto.getMessage(a.mid),p=JSON.parse(u).extMsg,l=JSON.parse(p||"{}");if(c)for(var d in c){var f=l[d];f&&f.ts<i-this._setTime?(f.v=c[d],f.ts=i-this._setTime):(l[d]={v:"",ts:0},l[d].v=c[d],l[d].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete l[e]})),this._setToProtocol(e,o,r,a.mid,l,n||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),n={};for(var o in t)n[o]=t[o].v;return n},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),n=JSON.parse(t||"{}"),o={};for(var r in n)o[r]=n[r].v;return o},e}(),Ze=function(){function e(e){var t=this;this.p=e,this.count=0,this.maps={},this.p.on("message",(function(e){var n=e.reqId,o=e.success,r=e.data,s=t.maps[n];s&&(s({success:o,data:r}),delete t.maps[n])}))}return e.prototype.call=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return fe(this,void 0,void 0,(function(){var n=this;return he(this,(function(o){return this.p.killed?[2,{success:!1}]:[2,new Promise((function(o){var r=++n.count;n.maps[r]=o;var s={reqId:r,method:e,args:t};n.p.send(s)}))]}))}))},e.prototype.destroy=function(){this.p.kill()},e}();!function(e){e[e.RMTP=1]="RMTP",e[e.TLS=2]="TLS",e[e.RPP=3]="RPP",e[e.QUIC=4]="QUIC",e[e.WS=5]="WS",e[e.WSS=6]="WSS",e[e.HTTP=11]="HTTP",e[e.HTTPS=12]="HTTPS"}(Ge||(Ge={}));var et,tt=[Ge.RMTP,Ge.TLS,Ge.QUIC],nt=function(e){function t(t,n,o,r,s,i){var a=e.call(this,t,n,o)||this;return a.addon=s,a.httpRequestProxy=i,a.naviPath="",a._caches={},a.naviPath="".concat(r,"/navi-cache.json"),a}return pe(t,e),t.prototype.httpRequest=function(e,t,n,o){return fe(this,void 0,void 0,(function(){var r,s,i,a,c,u,p,l,d=this;return he(this,(function(f){switch(f.label){case 0:r="token=".concat(encodeURIComponent(n),"&v=").concat(R,"&p=PC&ev=").concat("5.8.2-enterprise-lz.28"),s="".concat(e,"/navi.json?r=").concat(Date.now(),"&env=").concat(this._environment),this.logger.info(g.L_REQUEST_T,JSON.stringify({url:s,body:r}),o),c=function(){a&&(clearTimeout(a),a=null)},f.label=1;case 1:return f.trys.push([1,3,,4]),[4,new Promise((function(e){a=setTimeout((function(){d.logger.warn(g.L_REQUEST_E,JSON.stringify({url:s,body:r,info:"http response timeout"}),o),e({status:0})}),E+5e3),d.httpRequestProxy?d.httpRequestProxy({url:s,method:"POST",headers:{appId:t},body:r,timeout:E}).then((function(t){c(),e(t)})).catch((function(t){d.logger.error(g.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),o),c(),e({status:0})})):He(d.logger,{method:"POST",headers:{appId:t},body:r,url:s,timeout:E}).then((function(t){c(),e(t)})).catch((function(t){d.logger.error(g.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),o),c(),e({status:0})}))}))];case 2:return i=f.sent(),[3,4];case 3:return u=f.sent(),this.logger.error(g.L_REQUEST_E,JSON.stringify({stack:null==u?void 0:u.stack,info:"Code execution error"}),o),c(),[2,{code:h.RC_NAVI_REQ_FAILED}];case 4:if(200!==i.status)return this.logger.warn(g.L_REQUEST_R,JSON.stringify({url:s,code:i.status}),o),[2,{code:this.transHttpCode(i.status)}];try{return p=JSON.parse(i.data),l=/^https/.test(s)?"https":"http",p.protocol=l,p.code&&200!==p.code?[2,{code:this.transHttpCode(p.code)}]:[2,{code:h.SUCCESS,data:p}]}catch(e){return this.logger.error(g.L_PARSE_NAVI_E,i.data,o),[2,{code:h.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.httpRequestV2=function(e,t,n,o){return fe(this,void 0,void 0,(function(){var r,s,i,a;return he(this,(function(c){switch(c.label){case 0:return r=this.getNaviV2RequestOption({appkey:t,token:n,uri:e,platform:"electron",protocol:tt.join(",")}),this.logger.debug(g.L_REQUEST_T,JSON.stringify({url:r.url,body:r.body,headers:r.headers}),o),[4,He(this.logger,r)];case 1:if(200!==(s=c.sent()).status)return this.logger.warn(g.L_REQUEST_R,JSON.stringify({url:r.url,code:s.status}),o),[2,{code:this.transHttpCode(s.status)}];try{return i=JSON.parse(s.data),a=/^https/.test(r.url)?"https":"http",i.protocol=a,[2,{code:h.SUCCESS,data:i}]}catch(e){return this.logger.error(g.L_PARSE_NAVI_E,s.data,o),[2,{code:h.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.getNaviCache=function(e){var t=this.getCatchKey(e),n=this._caches[t];if(n)return n;if(!i(this.naviPath))return null;var o=u(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(o),this._caches[t]}catch(e){this.logger.error(g.L_PARSE_NAVI_E,o)}return null},t.prototype.setNaviCache=function(e,t){var n=Date.now(),o=this.getCatchKey(e);if(y(this._caches))for(var r in this._caches){(n-this._caches[r].timestamp>m||o===r)&&delete this._caches[r]}this._caches[o]={token:e,naviInfo:t,timestamp:Date.now(),environment:this._environment},c(this.naviPath,JSON.stringify(this._caches))},t.prototype.setEnvironment=function(e){this._environment=e},t}(P);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(et||(et={}));var ot,rt=function(e){function t(t,n,o,r,s,i){var a=e.call(this,t,o,r,s,i)||this;return a.addon=n,a._listener=i,a._connectedTime=0,a._naviInfo=null,a.connectResolve=null,a._startTime=0,a._tcpDuration=0,a.pingResolve=null,a.addon.setConnectionStatusListener(a._onConnectComplete.bind(a),(function(e){a.logger.info(le.P_DB_OPEN_O,e)}),(function(){return a.recvPong(h.SUCCESS)}),a._onAddonDisconnected.bind(a),a._onTcpConnectResponse.bind(a),(function(e){a.logger.error(le.P_DB_OP_E,"Database operation failed with code: ".concat(e)),a._listener.onDatabaseOperationFailed(e)})),a}return pe(t,e),t.prototype.getConnectedTime=function(){return this._connectedTime},t.prototype.connectWithToken=function(e,t,n,o){var r=this;return new Promise((function(s){r._naviInfo=t,r.connectResolve={resolve:s,traceId:o,userId:t.userId};var i={},a=Ve().data;a&&(i={proxy_passwd:a.socksPassword||"",proxy_name:a.socksUsername||"",proxy_port:a.socksPort||1082,proxy_host:a.socksHost||"localhost",proxy_type:0});var c=JSON.stringify(de(de({},i),{call_plus:r._openCallPlus})),u=r.getCmpList(t,!0).filter((function(e){return tt.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),p=[];u.forEach((function(e){var t=p.find((function(t){return t.addr===e.addr}));t?t.protocol!==Ge.QUIC&&e.protocol!==Ge.QUIC||(t.race=!0,t.protocol=Ge.QUIC):(e.race=!1,p.push(e))}));var l=de(de({},t),{serverAddr:p});r.logger.info(le.P_CONNECT_T,JSON.stringify({use:p,catche:r.cmpWeightCache,proxy:i,FORMATED_VERSION:R,reconnectKickEnable:n,naviInfo:l}),o),r._startTime=Date.now();try{r.addon.connectWithToken(e,R,JSON.stringify(l),n,c)}catch(e){r.logger.error(le.P_CALL_ADDON_E,null==e?void 0:e.stack,o),r._onConnectComplete(h.RC_SOCKET_NOT_CREATED)}}))},t.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.addon.disconnect(t)},t.prototype.sendPing=function(e){var t=this;return new Promise((function(n){t.pingResolve=n,t.addon.sendHeartbeat(),setTimeout((function(){return t.recvPong(h.TIMEOUT)}),e)}))},t.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},t.prototype._onConnectComplete=function(e){if(this.connectResolve&&10!==e){var t=this.connectResolve,n=t.resolve,o=t.userId,r=t.traceId;this.logger.info(le.P_CONNECT_R,JSON.stringify({code:e,userId:o}),r);var s=Date.now()-(this._startTime+this._tcpDuration),i={bid:I(),cod:e,net:this.getNetwork().type,dur:s,spr:1,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:T.CURRENT,count:this.retryCount};this.statisticLog.__statistics(N.IM_CMP_RMTP,JSON.stringify(i)),e===h.SUCCESS&&(this._connectedTime=Date.now()-this.addon.getDeltaTime()),n({code:e,data:o}),this.connectResolve=null}},t.prototype._onAddonDisconnected=function(e,t){switch(this.logger.info(le.P_CONNECT_S,JSON.stringify({code:e,delay:t})),e){case h.RC_CONN_REDIRECTED:this._handleDisconnected(h.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case h.CONNECTION_REFUSED:case h.RC_SOCKET_DISCONNECTED:case h.RC_SOCKET_NOT_CREATED:case h.RC_CONN_ACK_TIMEOUT:case h.RC_TCP_RESET:this._handleDisconnected(e,!1);break;case h.RC_UDP_DISCONNECTED:this._handleDisconnected(e,!0,t);break;default:this._handleDisconnected(e,!0)}},t.prototype._handleDisconnected=function(e,t,n){if(t)this.onDisconnectByServer(e,n);else{if(e===h.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==O.CONNECTED)return;this.onDisconenctUnusual(e)}},t.prototype._onTcpConnectResponse=function(e,t,n,o,r,s,i){var a,c=this.cmpWeightCache.findIndex((function(e){return e.addr==="".concat(t,":").concat(n)})),u={bid:I(),ptc:M.TCP,cod:e,net:this.getNetwork().type,dur:o,spr:1,pr:(null===(a=this._naviInfo)||void 0===a?void 0:a.type)||0,hos:"".concat(t,":").concat(n),idx:c,rct:this.retryCount?U.RECONNECT:U.CONNECT,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:T.CURRENT,rsn:this.reason,ddu:r,count:this.retryCount,weight:this.cmpWeightCache[c].weight};this.statisticLog.__statistics(N.IM_CMP,JSON.stringify(u)),this.logger.info(le.P_CONNECT_ENTRY_S,JSON.stringify({code:e,host:t,port:n,duration:o,dnsDuration:r,index:s,isQuic:i})),e===et.SUCCESS&&(this.curCmpUrl="".concat(t,":").concat(n),this.updateCmpWeight("".concat(t,":").concat(n),!0,i))},t}(w),st=function(t){if(!i(t)){var n=e(t,"..");i(n)||st(n),a(t)}},it=function(){function r(o,r,s,i,a){var c=this;this._appkey=o,this._cppProtocol=r,this._dbpath=s,this._logOutputLevel=i,this._httpRequestProxy=a,this._customMessageType={},this._senders={},this._chatroomCache=[],this.rtcHeartbeatResolves={};var u=this._dbpath||e(t.getPath("userData")),l=ze(u);this._cppProtocol.initWithAppkey(o,u,R);var d=Y(e(__dirname,"sub-process.js"));this.subProxy=new Ze(d);var f=e(u,"RongCloud/rclogs",o);st(f),function(e,t,n){n.initLogModule(t,e,p())}(o,f,this._cppProtocol),this.logger=new Ee(this._appkey,"RC-M","IM"),this.statisticLog=new Re(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),Se(this._cppProtocol,this.logger),this.reporter=new Qe(this._cppProtocol,o,l,this.logger,this.subProxy),this.logger.info(le.P_INIT_O,JSON.stringify({appkey:o,dbpath:u,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:l,commit:"cf68cd3cffddd652296b7952f5bf603ee9470f11"})),this._callCppProxy("setDeviceId",l);var C=e(u,"RongCloud/navis",o);st(C),this.navi=new nt(o,this.logger,this.statisticLog,C,this._cppProtocol,this._httpRequestProxy),this.tcpMgr=new rt(o,this._cppProtocol,this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this),onDatabaseOperationFailed:function(e){c._send2AllRenderer("onDatabaseOperationFailed",e)}}),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setReadReceiptListener(),n.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return fe(c,void 0,void 0,(function(){var o,r,s;return he(this,(function(i){switch(i.label){case 0:if("function"!=typeof(o=this[t]))return this.logger.error(le.P_CALL_MAIN_SYNC_E,JSON.stringify({method:t,error:"not found"})),e.returnValue=h.NOT_SUPPORT,[2];r=h.EXTRA_METHOD_UNDEFINED,i.label=1;case 1:return i.trys.push([1,3,,4]),[4,o.call.apply(o,Ce([this],n,!1))];case 2:return r=i.sent(),[3,4];case 3:return s=i.sent(),this.logger.error(le.P_CALL_MAIN_SYNC_E,JSON.stringify({error:null==s?void 0:s.stack,method:t})),[3,4];case 4:return e.returnValue=r,[2]}}))}))})),n.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var o=[],r=3;r<arguments.length;r++)o[r-3]=arguments[r];return fe(c,void 0,void 0,(function(){var r,s,i,a,c=this;return he(this,(function(u){switch(u.label){case 0:if("function"!=typeof(r=this[n]))return this.logger.error(le.P_CALL_MAIN_E,JSON.stringify({method:n,error:"not found"})),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,h.NOT_SUPPORT),[2];"sendMessage"===n&&(s=o[3],o[3]=function(t){c._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",s,t)}),i=h.EXTRA_METHOD_UNDEFINED,u.label=1;case 1:return u.trys.push([1,3,,4]),[4,r.call.apply(r,Ce([this],o,!1))];case 2:return i=u.sent(),[3,4];case 3:return a=u.sent(),this.logger.error(le.P_CALL_MAIN_E,JSON.stringify({error:null==a?void 0:a.stack,method:n})),[3,4];case 4:return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,i),[2]}}))}))})),n.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];var r=c[t];if("function"==typeof r)try{r.call.apply(r,Ce([c],n,!1))}catch(e){c.logger.error(le.P_SEND_2_MAIN_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}else c.logger.error(le.P_SEND_2_MAIN_E,JSON.stringify({method:t,error:"not found"}))})),n.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this)),this._msgExpansionHandler=new $e(this._cppProtocol)}return r.prototype.onConnected=function(){var e=this.getNaviInfoFromCache();this.reporter.checkStart(e),this._try2RejoinChatroom(),this._send2AllRenderer("onConnected",this.getMainProcessCache())},r.prototype.onConnecting=function(){this._send2AllRenderer("onConnecting",void 0)},r.prototype.onSuspend=function(e){this._send2AllRenderer("onSuspend",e)},r.prototype.onDisconnected=function(e){this._send2AllRenderer("onDisconnected",e)},r.prototype._callCppProxy=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];var r=this.logger.createTraceId();try{return this.logger.info(le.P_CALL_ADDON_O,JSON.stringify({method:e,args:n}),r),(t=this._cppProtocol)[e].apply(t,n)}catch(t){this.logger.error(le.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),r)}},r.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},r.prototype.sendHTTPRequest=function(e){return He(this.logger,e)},r.prototype.onRendererLogsReceived=function(e){ye.apply(void 0,e)},r.prototype.onRendererNetworkStatusReceived=function(e,t){this.tcpMgr.setNetwork(e,t)},r.prototype.destroy=function(){var e;this.reporter.stop(),this.subProxy.destroy(),e=this._cppProtocol,_e(),e.deinitLogModule(),this._cppProtocol.destroy()},r.prototype.callExtra=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var o=this[e];if(!o)return this.logger.warn(le.P_CALL_EXTRA_E,JSON.stringify({method:e,error:"not found"})),Promise.resolve({code:h.EXTRA_METHOD_UNDEFINED});try{return o.call.apply(o,Ce([this],t,!1))}catch(t){this.logger.error(le.P_CALL_EXTRA_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return Promise.resolve({code:h.MAIN_PROCESS_ERROR})},r.prototype.getConversationsByPage=function(e,t,n,o,r){var s,i=this,a=this._callCppProxy("getConversationListByPageWithTopPriority",e,t,n,r||!1,o||"");try{s=JSON.parse(a).list.map((function(e){return i._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:s})},r.prototype.getUnreadConversationList=function(e){var t,n=this,o=this._callCppProxy("getUnreadConversationList",e);try{t=JSON.parse(o).list.map((function(e){return n._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:t})},r.prototype.getConversationListWithAllChannel=function(){var e,t=this,n=[x.PRIVATE,x.GROUP,x.SYSTEM,x.APP_PUBLIC_SERVICE,x.PUBLIC_SERVICE],o=this._callCppProxy("getConversationListWithAllChannel",n);try{e=JSON.parse(o).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:e})},r.prototype.getConversationListWithAllChannelByPage=function(e,t){var n,o=this,r=[x.PRIVATE,x.GROUP,x.SYSTEM,x.APP_PUBLIC_SERVICE,x.PUBLIC_SERVICE],s=this._callCppProxy("getConversationListWithAllChannelByPage",r,e,t);try{n=JSON.parse(s).list.map((function(e){return o._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:n})},r.prototype.getHistoryMessagesByObjectNames=function(e,t,n,o,r,s,i){var a=0===s,c=o+1,u=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,n,c,r,a,i||""),p=[];try{var l=JSON.parse(u).list;l.reverse();for(var d=0;d<l.length;d++){var f=this._buildMessage(l[d].obj);p[d]=f}}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:{list:c===p.length?p.slice(1,c):p,hasMore:o<p.length}})},r.prototype.updateMessageReceiptStatus=function(e,t,n,o){void 0===o&&(o="");var r=this._callCppProxy("updateMessageReceiptStatus",e,t,n,o);return Promise.resolve({code:h.SUCCESS,data:r})},r.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==O.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},r.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new Ee(this._appkey,e,t)},r.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},r.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},r.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},r.prototype._send2Renderer=function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,Ce([t],n,!1))},r.prototype._send2AllRenderer=function(e,t,n){var o=this;void 0===n&&(n=[]),Object.keys(this._senders).forEach((function(r){var s=o._senders[r];n.includes(s)||o._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},r.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),n=this.getNaviInfoFromCache(),o=this.tcpMgr.getCurrentUserId();return{connectedTime:e,deviceId:this.getDeviceId(),crtUserId:o,naviInfo:n,connectionStatus:t}},r.prototype._registerRenderers=function(e,t){var n=this,o=e.sender,r=o.id,s=t.navigators,i=t.areaCode,a=t.logServerUrl,c=t.environment;this._environment=c||"default",this.navi.setEnvironment(c),b.init({areaCode:i,navigators:s,logServerUrl:a}),this._senders[r]||(this._senders[r]=o,o.once("destroyed",(function(){delete n._senders[r]})))},r.prototype._registerMsgTypes=function(){for(var e in A["RC:RcCmd"]={isCounted:!1,isPersited:!1},A){var t=A[e],n=t.isCounted,o=t.isPersited,r=t.searchProps,s=0;o&&(s|=1),n&&(s|=2),"RC:TypSts"===e&&(s=16),this._callCppProxy("registerMessageType",e,s,r||[])}},r.prototype._buildIsMentioned=function(e,t){var n,o=!1;if(L(e))n=e;else try{n=e?JSON.parse(e):e}catch(o){n=e,this.logger.error(le.P_PARSE_JSON_MSGS_E,JSON.stringify({messageId:t}))}return L(n)&&(o=!!n.mentionedInfo),{isMentioned:o,msgContent:n}},r.prototype._buildMsgOption=function(e){var t={isCounted:!1,isPersited:!1};return e in A?t=A[e]:e in this._customMessageType&&(t=this._customMessageType[e]),t},r.prototype._buildSupportExt=function(e,t){var n=null;return e&&(n=this._msgExpansionHandler.parseReceiveExpansion(t)),n},r.prototype._transICppMessage2IReceivedMessage=function(e,t){var n=e.channelId,o=e.conversationType,r=e.targetId,s=e.senderUserId,i=e.content,a=e.objectName,c=e.messageUid,u=e.direction,p=e.status,l=e.messageId,d=e.sentTime,f=e.readReceiptRequest,h=e.supportExt,C=e.pushContent,g=e.pushTitle,v=e.pushId,_=e.pushConfig,S=e.templateId,y=e.disableTitle,m=e.forcePushDetail,P=e.needReceipt,E=e.sendReceipt,R=this._buildIsMentioned(i,l),I=R.isMentioned,T=R.msgContent,N=this._buildMsgOption(a),O=this._buildSupportExt(h,e),M=D(t)?d<this.tcpMgr.getConnectedTime():t,U={};_&&(U=k(this.logger,_,v));var w=de(de({},U),{pushTitle:g,pushContent:C,pushData:C,disablePushTitle:y,forceShowDetailContent:m,templateId:S}),x={channelId:n,conversationType:o,targetId:r,senderUserId:s,content:T||{},messageType:a,messageUId:c||"",messageDirection:u,isOffLineMessage:M,sentTime:d,receivedTime:0,isPersited:N.isPersited,isCounted:N.isCounted,isMentioned:I,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:h,expansion:h?O:null,receivedStatus:p,messageId:l,pushConfig:w,needReceipt:P,sentReceipt:E};u===J.RECEIVE?x.receivedStatus=p:u===J.SEND&&(x.sentStatus=p);var b=this.getNaviInfoFromCache();if(f&&1===(null==b?void 0:b.grpRRVer)){var A=JSON.parse(f),L=A.hasRespond,j=A.readerInfo,B={hasRespond:L,readCount:A.readCount,totalCount:A.totalCount},H=[];if(j)for(var F in j)H.push({userId:F,readTime:j[F]});B.readerList=H,x.readReceiptInfo=B}return x},r.prototype._buildMessage=function(e,t){void 0===t&&(t=!1);var n=JSON.parse(e);return this._transICppMessage2IReceivedMessage(n,t)},r.prototype._updateReadReceiptInfo=function(e,t){var n=this._callCppProxy("getMessage",e),o=JSON.parse(n),r=o.readReceiptRequest?JSON.parse(o.readReceiptRequest):{},s=de(de({},r),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},r.prototype._transICppConversation2IReceivedConversation=function(e){var t=e.channelId,n=e.conversationType,o=e.targetId,r=e.unreadCount,s=e.lastestMsg,i=e.isTop,a=e.isBlocked,c=e.matchCount,u=e.hasUnreadMention,p=e.draft,l=e.conversationTime,d=a?j.OPEN:j.CLOSE;return{channelId:t,conversationType:n,targetId:o,unreadMessageCount:r,latestMessage:-1===JSON.parse(s).messageId?null:this._buildMessage(s),hasMentioned:u,mentionedInfo:null,notificationStatus:d,isTop:i,lastUnreadTime:0,matchCount:c,draft:p,operationTime:l}},r.prototype._buildConversation=function(e){var t=JSON.parse(e);return this._transICppConversation2IReceivedConversation(t)},r.prototype._convertResultList=function(e,t){var n=JSON.parse(e).list;return n=n.map((function(e){var n=JSON.parse(e.obj);return t?t(n):n}))},r.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,n,o,r){var s,i=e._buildMessage(t,o),a=i.messageType,c=i.channelId,u=void 0===c?"":c;if(a!==B.LOG_COMMAND||"rongcloudsystem"!==i.senderUserId){if(a===B.GROUP_READ_RECEIPT_REQUEST){var p=i.content,l=p.msgId,d=p.rrn,f=p.tmn;e._updateReadReceiptInfo(l,{readCount:d,totalCount:f})}if("RC:MsgExMsg"===a)return e._msgExpansionHandler.setLocalFromExtMsg(e.logger,i),void e._sendMessageExpansion(i);if(i.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(e.logger,i),a!==B.SYNC_READ_STATUS||i.senderUserId===e.tcpMgr.getCurrentUserId()){(a===B.SYNC_READ_STATUS||a===B.READ_RECEIPT&&i.senderUserId===e.tcpMgr.getCurrentUserId())&&e._callCppProxy("clearUnreadCountByTimestamp",i.conversationType,i.targetId,i.content.lastMessageSendTime,u);var h=!0;if(0!==n||r||(h=!1),a===B.DELIVERED)return e._callCppProxy("setMessageDeliverTime",JSON.stringify(i.content)),void e._sendMessageDelivered(i.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}})));if(a!==B.DELIVERED_MSG){var C=i.conversationType,g=i.targetId;if(a===B.RECALL){e.handleRecalledMessage(i);var v=e._fixRecallContentInfo(i);C=v.conversationType,g=v.targetId}e._sendMessageNotification(Object.assign(i,{hasMoreMsg:h,conversationType:C,targetId:g}))}else{var _={totalCount:i.content.tmn,list:null===(s=i.content.dl)||void 0===s?void 0:s.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};e._sendGroupMessageDeliveredStatus(_)}}}else{var S=i.content,y=S.startTime,m=S.endTime,P=S.platform,E=S.logId,R=S.uri;e.reporter.report(parseInt(y,10),parseInt(m,10),P,R,E,i.messageUId)}}),(function(){e._sendPullOfflineFinished()}))},r.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,n=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,n=e.content.targetId||n),{conversationType:t,targetId:n}},r.prototype.handleRecalledMessage=function(e,t){void 0===t&&(t=!1);var n=e.content.messageUId;if(n){var o=this._callCppProxy("getMessage",n),r=this._buildMessage(o);if(r.messageId){var s={recallTime:e.sentTime,admin:!!e.content.isAdmin,originalObjectName:r.messageType,originalMessageContent:r.content,recallActionTime:0,operatorId:e.senderUserId};t&&(s.recallActionTime=Date.now()),e.content.user&&(s.user=e.content.user),e.content.extra&&(s.extra=e.content.extra),r.messageType===B.TextMessage&&(s.recallContent=r.content.content),e.content.isDelete?this._callCppProxy("deleteMessages",[r.messageId]):(r.receivedStatus!==H.UNREAD&&r.receivedStatus!==H.RETRIEVED||this.setMessageReceivedStatus(r.messageId,1),this._callCppProxy("setMessageContent",r.messageId,JSON.stringify(s),B.RECALL_NOTIFICATION_MESSAGE))}}},r.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var n=e.channelId,o=e.content,r=o.put,s=o.del,i=o.mid,a={};r&&(a.updatedExpansion={channelId:n,messageUId:i,expansion:r}),s&&(a.deletedExpansion={channelId:n,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},r.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},r.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},r.prototype._sendMessageDelivered=function(e){this._send2AllRenderer("messageDelivered",e)},r.prototype._sendGroupMessageDeliveredStatus=function(e){this._send2AllRenderer("groupMessageDeliveredStatus",e)},r.prototype._sendChatroomStatus=function(e){this._send2AllRenderer("chatroom",e)},r.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var n=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj),n={channelId:t.channelId,conversationType:t.conversationType,targetId:t.targetId,updatedItems:{}};return t.status.forEach((function(e){var t=JSON.parse(e.item),o=t.type,r=t.value;if(1===o){var s=Number(r)||F.NOT_SET;n.updatedItems.notificationLevel={val:s,time:0},n.updatedItems.notificationStatus={val:V(s),time:0}}else 2===o&&(n.updatedItems.isTop={val:"1"===r,time:0})})),n}));e._send2AllRenderer("conversation",n)}),(function(t){e._send2AllRenderer("conversationTag",t)}))},r.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._send2AllRenderer("tag",t),e._getRTCProfile()}))},r.prototype._setReadReceiptListener=function(){var e=this;this._cppProtocol.setReadReceiptListener((function(t){try{var n=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId,messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));e._send2AllRenderer("messageReadReceipt",n)}catch(n){e.logger.info(le.P_PARSE_JSON_MSGS_E,t)}}))},r.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var n=this.navi.getNaviInfoFromCache(t);this._send2AllRenderer("onNaviDataChange",n)}},r.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var n=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",n)}))},r.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,n){e._sendChatroomStatus({chatroomDestroyed:t})}))},r.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){var n=[];try{JSON.parse(t).list.forEach((function(e){Object.entries(e).forEach((function(e){var t=e[0],o=e[1];n.push({key:t,value:o})}))}))}catch(t){e.logger.error(le.P_PARSE_JSON_E,null==t?void 0:t.stack)}e._send2AllRenderer("callInfo",JSON.stringify({list:n}))}))},r.prototype._updateMentionedInfo=function(e,t,n){var o,r,s;return{userIdList:(null===(o=e.mentionedInfo)||void 0===o?void 0:o.userIdList)||t,type:(null===(r=e.mentionedInfo)||void 0===r?void 0:r.type)||n||G.ALL,mentionedContent:(null===(s=e.mentionedInfo)||void 0===s?void 0:s.mentionedContent)||""}},r.prototype.registerMessageType=function(e,t,n,o){void 0===o&&(o=[]);var r=0;t&&(r|=1),n&&(r|=2),this._customMessageType[e]={isCounted:n,isPersited:t},this.logger.info(le.P_REGTYP_O,JSON.stringify({type:e,opt:r,search:o})),this._callCppProxy("registerMessageType",e,r,o)},r.prototype.connect=function(e,t,n,o){return this.tcpMgr.connect(e,t,n,o)},r.prototype.reportSDKInfo=function(e){var t,n,o=JSON.stringify(de(de({},e),{"electron-main":"5.8.2-enterprise-lz.28"}));this.logger.info(le.P_REPORT_VER_O,o),null===(n=(t=this._cppProtocol).uploadSDKVersion)||void 0===n||n.call(t,o)},r.prototype.disconnect=function(e){this._chatroomCache.length=0,this.reporter.stop(),Fe(null,this.logger),this.tcpMgr.disconnect(e)},r.prototype.logout=function(){this.disconnect()},r.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,n){t({userId:e,status:n})}));var n=e.userIds||[];n.length&&this.subscribeUserStatus(n)},r.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("subscribeUserStatus",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.setUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("setUserStatus",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.getUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getUserStatus",e,(function(e){n({code:h.SUCCESS,data:{status:e}})}),(function(e){n({code:e})}))}))},r.prototype.sendMessage=function(e,t,n,o,r){var s=this;void 0===r&&(r=this.logger.createTraceId());var i=n.messageType,a=n.content,c=n.expansion,u=n.pushConfig,p=n.isMentioned,l=n.mentionedType,d=n.mentionedUserIdList,f=void 0===d?[]:d,C=n.pushContent,g=void 0===C?"":C,v=n.pushData,_=void 0===v?"":v,S=n.directionalUserIdList,y=void 0===S?[]:S,m=n.disableNotification,P=void 0!==m&&m,E=n.canIncludeExpansion,R=void 0!==E&&E,I=n.isVoipPush,T=void 0!==I&&I,N=n.channelId,O=void 0===N?"":N,M=n.messageId,U=void 0===M?0:M,w=n.encrypted,b=void 0!==w&&w,A=n.needReceipt,L=void 0!==A&&A,D=u||{},k=D.iOSConfig,J=D.androidConfig,j=D.templateId,H=void 0===j?"":j,F=D.pushTitle,V=void 0===F?"":F,G=D.pushContent,W=void 0===G?g:G,K=D.pushData,Q=void 0===K?_:K,Y=D.disablePushTitle,X=void 0!==Y&&Y,z=D.forceShowDetailContent,$=void 0!==z&&z,Z=q(k,J);return new Promise((function(n){g=W,_=Q;var u=(null==J?void 0:J.notificationId)||"";e===x.GROUP&&p&&a&&(a.mentionedInfo=s._updateMentionedInfo(a,f,l));var d=e===x.GROUP;if(d&&i===B.READ_RECEIPT_RESPONSE&&a.receiptMessageDic)for(var C in a.receiptMessageDic)y.push(C);d&&i===B.SYNC_READ_STATUS&&(y=[s.getCurrentUserId()]);var v={};for(var C in c)v[C]={v:""},v[C].v=c[C];var S=H;s.logger.info(le.P_SEND_MSG_T,JSON.stringify({messageType:i,conversationType:e,targetId:t,channelId:O,messageId:U}),r);var m=s._callCppProxy("sendMessage",(function(e,t){var o=s._buildMessage(e);return s.logger.info(le.P_SEND_MSG_R,JSON.stringify({code:t,messageUId:o.messageUId,messageId:o.messageId}),r),t===h.SENSITIVE_REPLACE?n({code:t}):("RC:MsgExMsg"===o.messageType&&s._msgExpansionHandler.setLocalFromExtMsg(s.logger,o),o.canIncludeExpansion&&s._msgExpansionHandler.setLocalFromReceiveMsg(s.logger,o),n({code:h.SUCCESS,data:o}))}),(function(e,t){var o=s._buildMessage(e);return s.logger.warn(le.P_SEND_MSG_R,JSON.stringify({code:t,messageId:o.messageId}),r),o.sentTime=Date.now()-s._cppProtocol.getDeltaTime(),n({code:t,data:o})}),e,t,i,JSON.stringify(a),y,P,X,$,g,_,u,V,Z,S,R,JSON.stringify(v),T,O,U,b,L),E=JSON.parse(m);null==o||o(E.messageId)}))},r.prototype.recallMsg=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){var c,u=r.user,p=r.pushContent,l=r.channelId,d=r.extra,f=r.pushConfig,C=r.disableNotification,g=r.isDelete,v={conversationType:e,targetId:t,messageUId:n,sentTime:o,user:u,extra:d,channelId:l,isDelete:g||!1};u&&(v.user=u),d&&(v.extra=d);s._callCppProxy("recallMessage",(function(o){var r={conversationType:e,targetId:t,senderUserId:s.tcpMgr.getCurrentUserId(),content:v,objectName:B.RECALL,messageUid:n,direction:J.SEND,status:H.UNREAD,sentTime:Number(o),channelId:l},a=s._buildMessage(JSON.stringify(r));s.handleRecalledMessage(a,!0),i({code:h.SUCCESS,data:a})}),(function(e){i({code:e})}),B.RECALL,JSON.stringify(v),C||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,p||"",(null==f?void 0:f.pushData)||"",(null===(c=null==f?void 0:f.androidConfig)||void 0===c?void 0:c.notificationId)||"",(null==f?void 0:f.pushTitle)||"",q(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",l)}))},r.prototype.getHistoryMessage=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c,u){n=n||0;var p=0===r,l=o+1,d=a._callCppProxy("getHistoryMessages",e,t,n,l,i,p,s),f=JSON.parse(d).list,C=[];f.reverse();for(var g=0;g<f.length;g++){var v=a._buildMessage(f[g].obj);C[g]=v}c({code:h.SUCCESS,data:{list:l===C.length?C.slice(1,l):C,hasMore:o<C.length}})}))},r.prototype.getRemoteHistoryMessages=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,c){n=n||0;i._callCppProxy("getRemoteHistoryMessages",e,t,n,o,(function(e,t){var n=JSON.parse(e).list,o=[];n.reverse();for(var r=0;r<n.length;r++){var s=i._buildMessage(n[r].obj);o[r]=s}a({code:h.SUCCESS,data:{list:o,hasMore:!!t}})}),(function(e){a({code:e})}),r,!0,s)}))},r.prototype.deleteRemoteMessage=function(e,t,n,o){var r=this;return new Promise((function(s,i){var a=JSON.stringify(n);r._callCppProxy("deleteRemoteHistoryMessages",e,t,a,!1,o,(function(){s(h.SUCCESS)}),s)}))},r.prototype.deleteRemoteMessageByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearRemoteHistoryMessages",e,t,n,(function(){s(h.SUCCESS)}),(function(e){s(e)}),o)}))},r.prototype.clearMessages=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("clearMessages",e,t,n),r(h.SUCCESS)}))},r.prototype.getConversationList=function(e,t,n,o,r){var s=this;return void 0===r&&(r=""),new Promise((function(e,t){for(var n=s._callCppProxy("getConversationList",[1,3,6,7],r),o=JSON.parse(n).list,i=[],a=0;a<o.length;a++)i.push(s._buildConversation(o[a].obj));e({code:h.SUCCESS,data:i})}))},r.prototype.getConversation=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversation",e,t,n);if(i)r({code:h.SUCCESS,data:o._buildConversation(i)});else{var a=o._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,n),c=void 0;try{c=JSON.parse(a).list}catch(e){o.logger.error(le.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=o._buildMessage(c[0].obj));var p=o._callCppProxy("getConversationNotificationStatus",e,t,n),l=o._callCppProxy("getConversationTopStatus",e,t,n);r({code:h.SUCCESS,data:{conversationType:e,targetId:t,channelId:n,unreadMessageCount:0,latestMessage:u,notificationStatus:p?j.OPEN:j.CLOSE,isTop:Boolean(l),lastUnreadTime:0}})}}))},r.prototype.removeConversation=function(e,t,n){var o=this._callCppProxy("removeConversation",e,t,n);return Promise.resolve(o?h.SUCCESS:h.UNKNOWN)},r.prototype.clearConversations=function(e,t){var n=this;return new Promise((function(o,r){var s=[];s=W(e)?e:[x.PRIVATE,x.GROUP,x.SYSTEM,x.PUBLIC_SERVICE],n._callCppProxy("clearConversations",s,t),o(h.SUCCESS)}))},r.prototype.getAllConversationUnreadCount=function(e,t,n){var o=this._callCppProxy("getTotalUnreadCount",t,n,e);return Promise.resolve({code:h.SUCCESS,data:o})},r.prototype.getConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r){var s=o._callCppProxy("getUnreadCount",e,t,n);r({code:h.SUCCESS,data:s})}))},r.prototype.clearConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r,s){o._callCppProxy("clearUnreadCount",e,t,n),r(h.SUCCESS)}))},r.prototype.clearUnreadCountByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearUnreadCountByTimestamp",e,t,n,o),s(h.SUCCESS)}))},r.prototype.getFirstUnreadMessage=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getTheFirstUnreadMessage",e,t,n),a=o._buildMessage(i);r({code:h.SUCCESS,data:-1!==a.messageId?a:null})}))},r.prototype.setConversationToTop=function(e,t,n,o){var r=this;return void 0===o&&(o=""),new Promise((function(s,i){r._callCppProxy("setConversationToTop",e,t,n,o,!0),s(h.SUCCESS)}))},r.prototype.setConversationHidden=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationHidden",e,t,n,o),s(h.SUCCESS)}))},r.prototype.setConversationNotificationStatus=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationNotificationStatus",e,t,n,(function(){s(h.SUCCESS)}),s,o)}))},r.prototype.setConversationStatus=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("setConversationStatus",e,t,n,o,(function(){a(h.SUCCESS)}),a,r,!0,s)}))},r.prototype.getConversationNotificationStatus=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversationNotificationStatus",e,t,n);r({code:h.SUCCESS,data:i?j.OPEN:j.CLOSE})}))},r.prototype.setConversationTypeNotificationLevel=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setBlockPushLevelForType",e,t,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.getConversationTypeNotificationLevel=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getBlockPushLevelForType",e);n({code:h.SUCCESS,data:r})}))},r.prototype.searchConversationByContent=function(e,t,n,o,r){var s=this;return new Promise((function(i){o=o||[1,3,6,7],s._callCppProxy("searchConversationsByContentIncludeDeleted",o,e,t,n,!!r,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return s._transICppConversation2IReceivedConversation(e)}));i({code:h.SUCCESS,data:n})}else i({code:e})}))}))},r.prototype.searchConversationsByPage=function(e,t){var n=this,o=e.conversationTypes,r=e.keyword,s=e.messageTypes,i=e.includeDeleted,a=e.startTime,c=e.count;return new Promise((function(e){n.logger.info(le.P_SEARCH_CONVERSATIONS_T,"start",t),n._callCppProxy("searchConversationsByContentIncludeDeletedByPage",o,r,s||[],"",!!i,(function(o,r,s){if(n.logger.info(le.P_SEARCH_CONVERSATIONS_R,JSON.stringify({code:o}),t),o===h.SUCCESS){var i=JSON.parse(r).map((function(e){return n._transICppConversation2IReceivedConversation(e)}));n.logger.info(le.L_FORMAT_CONVERSATIONS_S,"done",t),e({code:h.SUCCESS,data:{list:i,totalCount:s}})}else e({code:o})}),a,c),n.logger.info(le.L_JS_GET_NOW_TIME_S,Date.now(),t)}))},r.prototype.searchConversationByContentWithAllChannel=function(e,t,n){var o=this;return new Promise((function(r,s){n=n||[1,3,6,7],o._callCppProxy("searchConversationByContentWithAllChannel",n,e,t,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return o._transICppConversation2IReceivedConversation(e)}));r({code:h.SUCCESS,data:n})}else r({code:e})}))}))},r.prototype.searchMessageByContent=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(s,c){a._callCppProxy("searchMessageByContent",e,t,n,o,r,!0,(function(e,t,n){if(e===h.SUCCESS){var o=JSON.parse(t).map((function(e){return a._transICppMessage2IReceivedMessage(e)}));s({code:h.SUCCESS,data:{messages:o,count:n}})}else s({code:e})}),i)}))},r.prototype.searchMessageByContentAndMessageType=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c){a._callCppProxy("searchMessageByContentAndObjectName",t,e,i||"",void 0===i,n,s,r,o,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return a._transICppMessage2IReceivedMessage(e)}));c({code:h.SUCCESS,data:{messages:n}})}else c({code:e})}))}))},r.prototype.searchMessagesByUser=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("getMessageBySender",e,t,n,o,r,s,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],o=0;o<t.length;o++)n[o]=i._buildMessage(t[o].obj);a({code:h.SUCCESS,data:{messages:n}})}))}))},r.prototype.searchMessageByContentWithAllChannel=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("searchMessageByContentWithAllChannel",e,t,n,o,r,!0,(function(e,t,n){if(e===h.SUCCESS){var o=JSON.parse(t).map((function(e){return s._transICppMessage2IReceivedMessage(e)}));i({code:h.SUCCESS,data:{messages:o,count:n}})}else i({code:e})}))}))},r.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c,u){a._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,n,o,r,s,i,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return a._transICppMessage2IReceivedMessage(e)}));c({code:h.SUCCESS,data:{messages:n}})}else c({code:e})}))}))},r.prototype.getUnreadMentionedMessages=function(e,t,n){for(var o=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,n)).list,r=0;r<o.length;r++)o[r]=this._buildMessage(o[r].obj);return o},r.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addToBlacklist",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("removeFromBlacklist",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,n){e._callCppProxy("getBlacklist",(function(e){t({code:h.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},r.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getBlacklistStatus",e,(function(e){n({code:h.SUCCESS,data:e})}),(function(e){n({code:e})}))}))},r.prototype.insertMessage=function(e,t,n){var o=this,r=n.content,s=n.senderUserId,i=n.messageType,a=n.messageDirection,c=n.readStatus,u=n.sentStatus,p=n.sentTime,l=n.searchContent,d=n.isUnread,f=n.messageUId,C=n.disableNotification,g=n.canIncludeExpansion,v=n.expansionMsg,_=n.channelId;r=JSON.stringify(r);var S={};if(p=p||0,v){var y=JSON.parse(v);for(var m in y)S[m]={v:"",ts:0},S[m].v=y[m],S[m].ts=p}return new Promise((function(n,v){var y=d?0:1,m=o._callCppProxy("insertMessage",e,t,s,i,r,(function(){}),(function(e){n({code:e})}),a,c||0,u||10,p,l||"",y,f||"",!!C,!!g,JSON.stringify(S),_||""),P=o._buildMessage(m);P.messageUId=f,P.sentTime=p,n({code:-1===P.messageId?h.MSG_INSERT_ERROR:h.SUCCESS,data:P})}))},r.prototype.batchInsertMessage=function(e,t){var n=this;return void 0===t&&(t=!1),new Promise((function(o){var r=e.map((function(e){var t=e.content,n=e.senderUserId,o=e.messageType,r=e.messageDirection,s=e.receivedStatus,i=e.sentStatus,a=e.sentTime,c=e.searchContent,u=e.isUnread,p=e.messageUId,l=e.disableNotification,d=e.canIncludeExpansion,f=e.expansion,h=e.channelId,C=e.conversationType,g=e.targetId,v=e.source,_=e.isMentioned,S={};if(a=a||0,f)for(var y in f)S[y]={v:"",ts:0},S[y].v=f[y],S[y].ts=a;return{conversationType:C,targetId:g,channelId:h||"",direction:r,senderUserId:n,status:i||10,sentTime:a,objectName:o,content:JSON.stringify(t),messageUid:p||"",noNotification:!!l,supportExt:!!d,extMsg:JSON.stringify(S),readStatus:s||0,searchContent:c||"",isUnread:!!u,source:v||"",isMention:_}})),s=n._callCppProxy("insertMessages",JSON.stringify(r),t);o({code:s?h.SUCCESS:h.MSG_INSERT_ERROR,data:s||!1})}))},r.prototype.getMessageCount=function(e,t,n){var o=this;return new Promise((function(r){var s=o._callCppProxy("getMessageCount",e,t,n);r({code:h.SUCCESS,data:s})}))},r.prototype.deleteMessages=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("deleteMessages",e),n(h.SUCCESS)}))},r.prototype.deleteMessagesByTimestamp=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("deleteMessagesByTimestamp",e,t,n,o,r),i(h.SUCCESS)}))},r.prototype.getMessage=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getMessage",e),s=t._buildMessage(r);n({code:h.SUCCESS,data:s})}))},r.prototype.setMessageContent=function(e,t,n){var o=this;return new Promise((function(r,s){t=JSON.stringify(t),o._callCppProxy("setMessageContent",e,t,n),r(h.SUCCESS)}))},r.prototype.setMessageSearchField=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageSearchField",e,t,n),r(h.SUCCESS)}))},r.prototype.setMessageSentStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageSentStatus",e,t),o(h.SUCCESS)}))},r.prototype.setMessageReceivedStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageReceivedStatus",e,t),o(h.SUCCESS)}))},r.prototype.saveConversationMessageDraft=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("saveTextMessageDraft",e,t,n,o||"")&&s(h.SUCCESS),s(h.DRAF_SAVE_ERROR)}))},r.prototype.getConversationMessageDraft=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getTextMessageDraft",e,t,n||"");r({code:h.SUCCESS,data:i})}))},r.prototype.clearConversationMessageDraft=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("clearTextMessageDraft",e,t,n||"")&&r(h.SUCCESS),r(h.DRAF_REMOVE_ERROR)}))},r.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},r.prototype.batchSetConversationStatus=function(e){var t=e[0],n=t.conversationType,o=t.targetId,r=t.isTop,s=t.notificationLevel,i=t.channelId,a=t.isUpdateTime,c=void 0===a||a,u=this._callCppProxy("getConversationNotificationStatus",n,o,i||""),p=this._callCppProxy("getConversationTopStatus",n,o,i||""),l=D(s)?Boolean(u):s>F.NOT_SET,d=D(r)?Boolean(p):r;return this.setConversationStatus(n,o,l,d,i,c)},r.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},r.prototype.sendReadReceiptMessage=function(e,t,n){var o=this;return new Promise((function(r){o._callCppProxy("sendReadReceipt",e,n||"",t,(function(){t.forEach((function(e){o._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(o._callCppProxy("getMessage",e)).messageId;o.setMessageReceivedStatus(t,1)}catch(t){o.logger.error(le.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),r({code:h.SUCCESS})}),(function(e){r({code:e})}))}))},r.prototype.getMessageReader=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getMessageReader",e,n,t,(function(e,n){var s=[],i={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),n=t.id,o=t.time;s.push({userId:n,readTime:o}),i[n]=o}));var a={readerInfo:i,readCount:s.length,totalCount:n};o._updateReadReceiptInfo(t,a),r({code:h.SUCCESS,data:{list:s,totalMemberCount:n}})}),(function(e){r({code:e})}))}))},r.prototype.sendReadReceipt=function(e,t){var n=this;return new Promise((function(o,r){var s=e.conversationType,i=e.targetId,a=e.channelId,c=void 0===a?"":a,u=n._callCppProxy("sendReadReceiptByReadReceiptType",s,i,c,0,t.map((function(e){return e.messageUId})),(function(e){e===h.SUCCESS&&t.forEach((function(e){n.setMessageReceivedStatus(e.messageId,H.READ)})),o({code:e})}));u!==h.SUCCESS&&o({code:u})}))},r.prototype._addChatroomCache=function(e,t,n){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:n,count:t})},r.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},r.prototype._try2RejoinChatroom=function(){var e=this;if(0!==this._chatroomCache.length){var t=this.logger.createTraceId();this._chatroomCache.forEach((function(n){return fe(e,void 0,void 0,(function(){var e,o,r,s;return he(this,(function(i){switch(i.label){case 0:return e=n.chatroomId,o=n.joinExist,r=n.count,this.logger.info(g.L_REJOIN_CHATROOM_T,e,t),[4,this._joinChrm(e,r,o,!1)];case 1:return(s=i.sent())===h.SUCCESS?(this.logger.info(g.L_REJOIN_CHATROOM_R,e,t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,count:r}}),[2]):(s===h.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(e),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,errorCode:s}}),this.logger.warn(g.L_REJOIN_CHATROOM_R,"chrmId: ".concat(e,", code: ").concat(s),t),[2])}}))}))}))}},r.prototype._joinChrm=function(e,t,n,o){var r=this,s=n?"joinExistChatRoom":"joinChatRoom";return new Promise((function(i){o&&r._callCppProxy("clearMessages",x.CHATROOM,e,""),r._callCppProxy(s,e,t,(function(){r._addChatroomCache(e,t,n),i(h.SUCCESS)}),i)}))},r.prototype.joinChatroom=function(e,t){return this._joinChrm(e,t,!1,!0)},r.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},r.prototype.quitChatroom=function(e){var t=this;return this._rmChatroomCache(e),new Promise((function(n,o){t._callCppProxy("quitChatRoom",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.getChatroomInfo=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getChatroomInfo",e,t,n,(function(e,t){var n=e?JSON.parse(e).list:[],o=[];if(n.length>0)for(var s=0;s<n.length;s++)o.push(JSON.parse(n[s].obj));r({code:h.SUCCESS,data:{userInfos:o,userCount:t}})}),(function(e){r({code:e})}))}))},r.prototype.getChatroomHistoryMessages=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomHistoryMessage",e,t,n,o,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var n=t.list;if(n&&n.length)try{t.list=n.map((function(e){return r._buildMessage(e.obj)}))}catch(e){t.list=[]}s({code:h.SUCCESS,data:t})}),(function(e){s({code:e})}),"")}))},r.prototype.setChatroomEntry=function(e,t){var n=this;return new Promise((function(o,r){var s='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');n._callCppProxy("setChatroomKV",e,s,!!t.isAutoDelete,!!t.isOverwrite,(function(){o(h.SUCCESS)}),(function(e){o(e)}))}))},r.prototype.setChatroomEntries=function(e,t){var n=this;return new Promise((function(o){n._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},r.prototype.removeChatroomEntry=function(e,t){var n=this,o=[t.key];return new Promise((function(r,s){n._callCppProxy("deleteChatroomKV",e,o,!!t.isOverwrite,(function(){r(h.SUCCESS)}),(function(e){r(e)}))}))},r.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},r.prototype.removeChatroomEntries=function(e,t){var n=this;return new Promise((function(o){var r=t.entries.map((function(e){return e.key}));n._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.getChatroomEntry=function(e,t){return fe(this,void 0,void 0,(function(){var n;return he(this,(function(o){switch(o.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(n=o.sent()).code===h.SUCCESS?[2,{code:h.SUCCESS,data:n.data?n.data[t]:null}]:[2,{code:n.code}]}}))}))},r.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}n({code:h.SUCCESS,data:t})}),(function(e){n({code:e})}))}))},r.prototype.getFileToken=function(e,t,n,o,r){var s=this;return void 0===r&&(r=""),n=n||"",o=o||"",new Promise((function(i){var a;a=o&&"uploads"!==o?t||"":K(e,t);var c=s.getNaviInfoFromCache(),u={uploadDomain:Q(c,s.logger),env:s._environment};s._callCppProxy("getUploadToken",e,a,n,o,r,JSON.stringify(u),(function(e,t,n,o,r,s,c,u,p,l,d,f,C,g,v,_,S,y,m,P,E,R,I){i({code:h.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:n,path:o,osskeyId:r,ossPolicy:s,ossSign:c,ossBucketName:u,fileName:a,s3Credential:p,s3Algorithm:l,s3Date:d,s3Policy:f,s3Signature:C,s3BucketName:g,stcAuthorization:v,stcContentSha256:_,stcDate:S,stcBucketName:y,minioAuthorization:m,minioContentSha256:P,minioDate:E,minioBucketName:R,downloadAuthInfo:I?JSON.parse(I):null}})}),(function(e){i({code:e})}))}))},r.prototype.getFileUrl=function(e,t,n,o){var r=this;return new Promise((function(s){var i=r.getNaviInfoFromCache(),a={url:Q(i,r.logger)};r._callCppProxy("getDownloadUrl",e,n,o,t-1,JSON.stringify(a),(function(e){s({code:h.SUCCESS,data:{downloadUrl:e}})}),(function(e){s({code:e})}))}))},r.prototype.clearData=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("clearData");t({code:h.SUCCESS,data:o})}))},r.prototype.getDeviceId=function(){var n=this._dbpath||e(t.getPath("userData"));return ze(n)},r.prototype.getVoIPKey=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("getVoIPKey",e,t,"",(function(e){o({code:h.SUCCESS,data:e})}),(function(e){o({code:e})}))}))},r.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(n,o){var r=e.chatRoomId,s=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",r,s,(function(){n(h.SUCCESS)}),(function(e){n(e)}))}))},r.prototype.getGroupMessageDeliverList=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getGroupMessageDeliverList",e,n,t,(function(e,t){var n=JSON.parse(e).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));r({code:h.SUCCESS,data:{totalCount:t,list:n}})}),(function(e){r({code:e})}))}))},r.prototype.getPrivateMessageDeliverTime=function(e,t){var n=this;return new Promise((function(o,r){var s=n._callCppProxy("getMessageDeliverTime",e);if(s)o({code:h.SUCCESS,data:s});else{n._callCppProxy("getPrivateMessageDeliverList",t,e,(function(e){var t=0,n=JSON.parse(e).list;n.length>0&&(t=JSON.parse(n[0].obj).time);o({code:h.SUCCESS,data:t})}),(function(e){o({code:e})}))}}))},r.prototype.rtcSignaling=function(e,t,n,o){var r=this,s=Array.prototype.slice.call(new Uint8Array(o));return new Promise((function(o){r._callCppProxy("rtcSignaling",e,t,n,s,(function(e){var t=new Uint8Array(e).buffer;o({code:h.SUCCESS,buffer:t})}),(function(e){o({code:e})}))}))},r.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,n){var o=e.rtcHeartbeatResolves[t];if(o){var r=o.find((function(e){return""===e.seqId}));r&&(r.seqId=n)}}),(function(t,n,o,r){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===o}));-1!==i&&s.splice(i,1)[0].resolve({code:n,data:{version:Number(r)}})}}))},r.prototype.rtcPing=function(e,t,n){var o=this;return new Promise((function(t){var n={resolve:t,seqId:""},r=o.rtcHeartbeatResolves[e];r?r.push(n):o.rtcHeartbeatResolves[e]=[n],o._callCppProxy("sendRTCHeartbeat",[e])}))},r.prototype.createTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){n({code:h.SUCCESS})}),(function(e){n({code:e})}))}))},r.prototype.removeTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("deleteTag",e,(function(){n({code:h.SUCCESS})}),(function(e){n({code:e})}))}))},r.prototype.updateTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){n({code:h.SUCCESS})}),(function(e){n({code:e})}))}))},r.prototype.getTagList=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("getTags"),r=e._convertResultList(o,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:h.SUCCESS,data:r})}))},r.prototype.addTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));n._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.removeTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),n._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.removeTagsForConversation=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.getConversationListByTag=function(e,t,n,o){var r=this;return new Promise((function(s){var i=r._callCppProxy("getConversationsForTagByPage",e,t,n||20,o||""),a=r._convertResultList(i,(function(e){return de(de({},r._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));s({code:h.SUCCESS,data:a})}))},r.prototype.getUnreadCountByTag=function(e,t){var n=this;return new Promise((function(o,r){var s=n._callCppProxy("getConversationUnreadCountForTag",e,t);o({code:h.SUCCESS,data:s})}))},r.prototype.setConversationStatusInTag=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",n.isTop||!1,(function(){r({code:h.SUCCESS})}),(function(e){r({code:e})}))}))},r.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||""),s=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));n({code:h.SUCCESS,data:s})}))},r.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},r.prototype.getTopConversationList=function(e,t){var n=this;return new Promise((function(o){var r=D(t)?n._callCppProxy("getTopConversations",e):n._callCppProxy("getTopConversations",e,t),s=JSON.parse(r).list.map((function(e){return n._buildConversation(e.obj)}));o({code:h.SUCCESS,data:s})}))},r.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},r.prototype.getAllUnreadMentionedCount=function(){var e=this;return new Promise((function(t){var n=e._callCppProxy("getUnreadAndMentionCount",[x.GROUP],"");t({code:h.SUCCESS,data:n})}))},r.prototype.getOSInfo=function(){return fe(this,void 0,void 0,(function(){var e;return he(this,(function(t){return e={arch:o.arch(),platform:o.platform(),type:o.type(),version:o.version(),release:o.release(),uptime:o.uptime(),cpus:o.cpus(),freemem:o.freemem(),totalmem:o.totalmem(),networkInterfaces:o.networkInterfaces()},[2,{code:h.SUCCESS,data:e}]}))}))},r.prototype.getMainProcessInfo=function(){return fe(this,void 0,void 0,(function(){return he(this,(function(e){return[2,{code:h.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},r.prototype.setCallInfo=function(e,t,n){var o=this;return new Promise((function(r){o._callCppProxy("callInfoSignaling",e,t,n,(function(e,t){r({code:h.SUCCESS,data:{key:e,value:t}})}),(function(e){r({code:e})}))}))},r.prototype.setProxy=function(e){return this.tcpMgr.getConnectionStatus()!==O.DISCONNECTED?Promise.resolve({code:h.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(Fe(e,this.logger))},r.prototype.getProxy=function(){return Promise.resolve(Ve())},r.prototype.testProxy=function(e,t){return function(e,t,n){return new Promise((function(o){var r=/^https/.test(t)?je:De;n.info(g.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:e,testHost:t}));var s=r(t,e,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var n="";e.on("data",(function(e){n+=e})),e.once("end",(function(){o({status:t||0,data:n})}))}));s.once("timeout",(function(){return o({status:0})})),s.once("error",(function(e){return o({status:0,data:e.stack})})),s.end()}))}(e,t,this.logger)},r.prototype.checkDuplicateMessage=function(e){var t=this;return new Promise((function(n){t._callCppProxy("checkDuplicateMessage",e),n({code:h.SUCCESS})}))},r.prototype.initAndOpenDatabase=function(e){var t=this;return new Promise((function(n){t._callCppProxy("initAndOpenDatabase",e),n({code:h.SUCCESS})}))},r.prototype.closeDatabase=function(){var e=this;return new Promise((function(t){e._callCppProxy("closeDatabase"),t({code:h.SUCCESS})}))},r.prototype.getMessagesByObjectNamesAcrossConversations=function(e,t,n,o,r,s,i,a){var c=0===s,u=i+1,p=this._callCppProxy("getMessagesByObjectNamesAcrossConversations",a,e,t,n,o,r,c,u),l=[];try{var d=JSON.parse(p).list;d.reverse();for(var f=0;f<d.length;f++){var C=this._buildMessage(d[f].obj);l[f]=C}}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:{list:u===l.length?l.slice(1,u):l,hasMore:i<l.length}})},r.prototype.getReadReceiptUsers=function(e,t){var n=this;return new Promise((function(o){var r=n._callCppProxy("getReadReceiptUsersByUid",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t,r){var s,i;try{var a=JSON.parse(t).list,c=JSON.parse(r).list;s=a.map((function(e){return JSON.parse(e.obj)})),i=c.map((function(e){return JSON.parse(e.obj)})),o({code:e,data:{userInfoRead:s,userInfoUnread:i}})}catch(e){n.logger.error(le.P_PARSE_JSON_MSGS_E,t,r),o({code:h.MAIN_PROCESS_ERROR})}}));r!==h.SUCCESS&&o({code:r})}))},r.prototype.getMessageReadReceiptInfos=function(e,t){var n=this;return new Promise((function(o){var r=n._callCppProxy("getReadReceiptCount",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t){try{var r=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));o({code:e,data:r})}catch(e){n.logger.error(le.P_PARSE_JSON_MSGS_E,t),o({code:h.MAIN_PROCESS_ERROR})}}));r!==h.SUCCESS&&o({code:r})}))},r}(),at=function(){function e(e,t,n,o,r){void 0===n&&(n=""),this._cppService=new it(e,t,n,o,r)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._cppService.destroy()},e.prototype.getDeviceId=function(){return this._cppService.getDeviceId()},e.prototype.getServerTime=function(){return this._cppService.getServerTime()},e.prototype.__createLogger=function(e,t){return null},e}(),ct=function(n){return function(e,t,n){if(ot)return ot;if(!t)throw new Error("Initializ failed, `appkey` is required!");return ot=new at(t,e,null==n?void 0:n.dbpath,null==n?void 0:n.logOutputLevel,null==n?void 0:n.httpRequestProxy)}(ce(n.dbpath||e(t.getPath("userData"))),n.appkey,n)};export{ct as default};
1
+ import{resolve as e}from"path";import{app as t,ipcMain as n}from"electron";import*as o from"os";import{platform as r,arch as s}from"os";import{existsSync as i,mkdirSync as a,writeFileSync as c,readFileSync as u}from"fs";import{getUUID as p,BasicLogger as l,BasicStatistic as d,appendUrl as f,ErrorCode as h,HTTP_TIMEOUT as C,LogTagId as g,StoreKeys as v,BasicReporter as _,REAT_TIME_LOG_SIZE as S,notEmptyObject as y,NAVI_CACHE_DURATION as m,BasicNavi as P,NAVI_REQ_TIMEOUT as E,FORMATED_VERSION as R,getbundleId as I,StatisticsVersion as T,StatisticsTag as N,RCConnectionStatus as O,ProtocalType as M,ConnectType as U,AConnectionMgr as w,ConversationType as x,urlCenter as b,SEND_MESSAGE_TYPE_OPTION as A,isObject as L,isUndefined as D,pushJSONToConfigs as k,MessageDirection as J,NotificationStatus as j,MessageType as B,ReceivedStatus as H,NotificationLevel as F,transformNotificationLevel as V,MentionedType as G,pushConfigsToJSON as q,isArray as W,getUploadFileName as K,getMinionURL as Q}from"@rongcloud/engine";import{fork as Y}from"child_process";import{Agent as X,request as z}from"http";import{Agent as $,request as Z}from"https";import{parse as ee}from"url";import{isIP as te,Socket as ne}from"net";import{EventEmitter as oe}from"events";import{connect as re}from"tls";import{createHash as se}from"crypto";var ie=process.versions.electron.replace(/\.\d+$/,""),ae=e(__dirname,"binding","electron-v".concat(ie,"-").concat(r(),"-").concat(s(),".node")),ce=function(t){try{return require(ae)}catch(n){throw function(t,n){try{i(e(t,"RongCloud"))||a(e(t,"RongCloud"));var o=e(t,"RongCloud/addon-load-error.txt");c(o,n.toString())}catch(e){console.error(e)}}(t,n),n}},ue=function(e,t){return ue=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},ue(e,t)};function pe(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}ue(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var le,de=function(){return de=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},de.apply(this,arguments)};function fe(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}function he(e,t){var n,o,r,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],o=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function Ce(e,t,n){if(n||2===arguments.length)for(var o,r=0,s=t.length;r<s;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_DB_OP_E="P-db_op-E",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_E="P-connect-E",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_R="P-connect-R",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_E="P-parse_json-E",e.P_SEARCH_CONVERSATIONS_T="P-search_conversations-T",e.P_SEARCH_CONVERSATIONS_R="P-search_conversations-R",e.L_FORMAT_CONVERSATIONS_S="L-format_conversations-S",e.L_JS_GET_NOW_TIME_S="L-js_get_now_time-S",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R"}(le||(le={}));var ge,ve={flushTimestamp:Date.now(),queue:[],locked:!1};function _e(){ge&&clearInterval(ge)}function Se(e,t){_e(),ge=setInterval((function(){return Pe(e,t)}),1e4)}function ye(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(e=ve.queue).push.apply(e,t)}var me=200;function Pe(e,t){var n=ve.queue,o=ve.flushTimestamp;if(!(ve.locked||0===n.length||Date.now()-o<3e4&&n.length<me)){ve.locked=!0;var r=t.createTraceId(),s=n.splice(0,me).map((function(e){var t=e.sessionId,n=e.level,o=e.time,r=e.type,s=e.tag,i=e.loggerId,a=e.content,c=e.traceId;return{level:n,time:o,type:r,tag:s,content:encodeURIComponent(JSON.stringify({loggerId:i,sessionId:t,content:a,traceId:c})).replace(/'/g,"%27")}}));t.debug(le.P_WRITE_LOG_T,"writingLen: ".concat(s.length,", queueLen: ").concat(n.length),r);var i=JSON.stringify(s);e.writeLog(i),t.debug(le.P_WRITE_LOG_R,"write done, queueLen: ".concat(n.length),r),ve.flushTimestamp=Date.now(),ve.locked=!1,setTimeout((function(){return Pe(e,t)}))}}var Ee=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return pe(t,e),t.prototype.flush=function(e){ye(e)},t}(l),Re=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return pe(t,e),t.prototype.flush=function(e){ye(e)},t}(d),Ie=function(e,t){var n,o=Buffer.from(e),r=o.length;for(t.push(r),n=0;n<r;n++)t.push(o[n])},Te=function(e){return"string"==typeof e},Ne=function(e){return Te(e)?e.toUpperCase():""},Oe=function(e,t){var n="";return 2!==e.length?n="Unexpected number of bytes received.":5!==e[0]?n="Unexpected SOCKS version number: ".concat(e[0],"."):255===e[1]?n="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(n="Unexpected SOCKS authentication method: ".concat(e[1],".")),n},Me=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: ".concat(e[0],"."):0!==e[1]&&(t="Username and password authentication failure: ".concat(e[1],".")),t},Ue=function(e){var t=Ne(e.method)||"GET",n=e.pathname||"/",o=e.headers||{},r=e.search||"";o.Host=e.host||"loclahost";var s="";for(var i in s="".concat(t," ").concat(n+r," HTTP/1.1\n"),o)if(Object.hasOwnProperty.call(o,i)){var a=o[i];s+="".concat(i,": ").concat(a,"\n")}return e.body&&(s+="Content-Length: ".concat(e.body.length,"\n")),s+="\n","POST"===t&&e.body&&(s+="".concat(e.body)),s},we=function(e){return new Promise((function(t){var n,o;e.socket.once("data",(function(o){var r,s=Oe(o,n);if(!s)return 2===o[1]?(e.socket.once("data",(function(n){var o=Me(n);o?e.emit("error",new Error("SOCKS authentication failed. ".concat(o))):t()})),r=[1],Ie(e.socksUsername,r),Ie(e.socksPassword,r),void e.write(Buffer.from(r))):void t();e.emit("error",new Error("SOCKS authentication failed. ".concat(s)))})),n=[0],e.socksUsername&&n.push(2),(o=Buffer.alloc(2+n.length))[0]=5,o[1]=n.length,n.forEach((function(e,t){o[2+t]=e})),e.write(o)}))},xe=function(e,t,n){return new Promise((function(o){var r,s;switch(e.socket.once("data",(function(t){var n;5!==t[0]?n="Unexpected SOCKS version number: ".concat(t[0],"."):0!==t[1]?n="".concat(function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code ".concat(e)}}(t[1]),"."):0!==t[2]&&(n="The reserved byte must be 0x00."),n?e.emit("error",new Error("SOCKS connection failed. ".concat(n))):o()})),(r=[]).push(5),r.push(1),r.push(0),te(t)){case 0:r.push(3),Ie(t,r);break;case 4:r.push(1),function(e,t){var n,o,r=e.split(".");for(n=0;n<4;n++)o=parseInt(r[n],10),t.push(o)}(t,r);break;case 6:e.emit("error",new Error("Does not support IPV6"))}r.length+=2,(s=Buffer.from(r)).writeUInt16BE(n,s.length-2),e.write(s)}))},be=function(e){function t(t){var n=e.call(this)||this;return n.readable=!0,n.socket=new ne,n.options=t,n.socksHost=t.socksHost||"localhost",n.socksPort=t.socksPort||1080,n.socksUsername=t.socksUsername||"",n.socksPassword=t.socksPassword||"",n.socket.on("error",(function(e){n.emit("error",e)})),n.on("error",(function(){n.socket.destroyed||n.socket.destroy()})),n.on("end",n.end),n}return pe(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var n=this.socket.end(e,t);return this.writable=this.socket.writable,n},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,n){return this.socket.write(e,t,n)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var n=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: ".concat(e));if(!t||"string"!=typeof t)throw new TypeError("Invalid host: ".concat(t));return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return fe(n,void 0,void 0,(function(){var n;return he(this,(function(o){switch(o.label){case 0:return[4,we(this)];case 1:return o.sent(),[4,xe(this,t,e)];case 2:return o.sent(),this.onProxied(),n=Ue(this.options),this.socket.write(Buffer.from(n)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(oe),Ae=function(e){var t,n=e.hostname,o=e.port;return!e.host||n&&o||(t=e.host.split(":")),!o&&t&&(o=parseInt(t[1],10)||0),!n&&t&&(n=t[0]),new be(e).connect(o,n)},Le=function(e){function t(t){var n=e.call(this)||this;return n.createConnection=Ae,n}return pe(t,e),t}(X),De=function(e,t,n){return(t=de(de({},t),ee(e))).port||(t.port=80),t.agent=new Le(t),z(t,n)},ke=function(e){var t,n;return t=Ae(e),n=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=re(e,(function(){t.authorized=t.socket.authorized,n.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},Je=function(e){function t(t,n){var o=e.call(this,n)||this;return o.url=t,o.socksHost=n.socksHost||"localhost",o.socksPort=n.socksPort||1080,o.createConnection=ke,o}return pe(t,e),t}($),je=function(e,t,n,o){var r,s;return t.protocol="https:",!t.port&&t.host&&(r=t.host.split(":"),t.port=r[0],t.port=r[1]),t.port||(t.port=443),s=new Je(e,t),t.agent=s,Z(e,t,n)},Be=null;function He(e,t,n){void 0===n&&(n=!1);var o=t.url,r=t.headers,s=t.body,i=t.method,a=t.query,c=t.timeout,u=void 0===c?C:c;return new Promise((function(t){var c=/^https/.test(o),p={headers:r,method:i};c&&(p.rejectUnauthorized=n);var l=null;Be?((p=de(de({},p),Be)).body=s,l=c?je:De):(l=z,c&&(p.agent=new $(p),l=Z));var d=l(f(o,a),p,(function(e){var n=e.statusCode,o="";e.setEncoding("utf8"),e.on("data",(function(e){o+=e})),e.once("end",(function(){t({status:n||0,data:o})}))}));d.once("timeout",(function(){e.warn(le.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:o,method:i,query:a,timeout:u})),t({status:0})})),d.setTimeout(u),d.once("error",(function(n){e.warn(le.P_HTTP_REQ_E,JSON.stringify({msg:n.stack,url:o,method:i,query:a,timeout:u})),t({status:0})})),d.write(s),d.end()}))}function Fe(e,t){return e?(Be=de(de({},Be),e),t.info(g.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:Be})),{code:h.SUCCESS}):(Be=null,t.info(g.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:h.SUCCESS})}function Ve(){var e=Be||void 0;return{code:h.SUCCESS,data:e}}var Ge,qe=[],We=!1,Ke=function(){return fe(void 0,void 0,void 0,(function(){var e,t,n,o,r,s,i,a,c,u,p;return he(this,(function(l){return We||0===qe.length||(We=!0,e=qe.shift(),t=e.args,n=e.resolve,o=t.addon,r=t.startTime,s=t.endTime,i=t.level,a=t.realtimeReport,c=0,u=0,p=[],o.setLogEventListener((function(e){c+=e.length;var t=e.split(","),o=t[0],r=t[1],s=t[2],l=t[3],d=t[4],f=t.slice(5);if(c>S&&parseInt(r,10)!==u)n(p);else{u=parseInt(r,10);try{var h=JSON.parse(decodeURIComponent(f.join(","))),C=h.loggerId,g=h.sessionId,v=h.content,_=h.traceId;if(!a&&i<0)return;var y={time:parseInt(r,10),level:parseInt(l,10),sessionId:"".concat(o,":").concat(g),type:s,tag:d,loggerId:C,content:v,traceId:_};p.push(y)}catch(e){console.error(e)}}}),(function(e){n(p),We=!1,Ke()}),(function(e,t,n){})),o.pullFullLog(i,r,s,!1)),[2]}))}))},Qe=function(e){function t(t,n,o,r,s){var i=this,a=process.versions.electron,c="Electron|".concat(a,"|").concat(process.arch,"|").concat(process.platform);return i=e.call(this,n,o,c,{getLogs:function(e,n,o,r){return fe(this,void 0,void 0,(function(){return he(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:n,level:o,realtimeReport:r,addon:t},fe(void 0,void 0,void 0,(function(){return he(this,(function(e){return[2,new Promise((function(e){qe.push({resolve:e,args:i}),Ke()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var e=t.getStoreValue(v.REALTIME_LOG_TIMESTAMP);return parseInt(e,10)||0},setTimestamp4RealtimeLog:function(e){t.setStoreValue(v.REALTIME_LOG_TIMESTAMP,e.toString())}},r)||this,i.subProcess=s,i}return pe(t,e),t.prototype.send=function(e){return He(this.logger,e)},t.prototype.compressLogs=function(e){return fe(this,void 0,void 0,(function(){var t,n,o;return he(this,(function(r){switch(r.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=r.sent(),n=t.success,o=t.data,n?[2,{success:n,data:o}]:[2,{success:n,data:""}]}}))}))},t}(_),Ye=null,Xe=function(){var e,t=Date.now(),n=[s(),r(),process.pid,t,Math.floor(Math.random()*t)].join("__");return e=n,se("md5").update(e).digest("hex")},ze=function(t){if(Ye)return Ye;var n=e(t,"deviceId");return i(n)?Ye=u(n).toString():(Ye=Xe(),c(n,Ye),Ye)},$e=function(){function e(e){this._cppProto=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,n,o,r,s){var i=JSON.stringify(r);"{}"!==i&&e.info(le.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:o,ext:r})),this._cppProto.setMessageExtension(t,n,o,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime;if(i&&0!==Object.keys(i).length){var c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,o,r,s,c,n||"")}},e.prototype.setLocalFromExtMsg=function(e,t){var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._cppProto.getMessage(a.mid),p=JSON.parse(u).extMsg,l=JSON.parse(p||"{}");if(c)for(var d in c){var f=l[d];f&&f.ts<i-this._setTime?(f.v=c[d],f.ts=i-this._setTime):(l[d]={v:"",ts:0},l[d].v=c[d],l[d].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete l[e]})),this._setToProtocol(e,o,r,a.mid,l,n||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),n={};for(var o in t)n[o]=t[o].v;return n},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),n=JSON.parse(t||"{}"),o={};for(var r in n)o[r]=n[r].v;return o},e}(),Ze=function(){function e(e){var t=this;this.p=e,this.count=0,this.maps={},this.p.on("message",(function(e){var n=e.reqId,o=e.success,r=e.data,s=t.maps[n];s&&(s({success:o,data:r}),delete t.maps[n])}))}return e.prototype.call=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return fe(this,void 0,void 0,(function(){var n=this;return he(this,(function(o){return this.p.killed?[2,{success:!1}]:[2,new Promise((function(o){var r=++n.count;n.maps[r]=o;var s={reqId:r,method:e,args:t};n.p.send(s)}))]}))}))},e.prototype.destroy=function(){this.p.kill()},e}();!function(e){e[e.RMTP=1]="RMTP",e[e.TLS=2]="TLS",e[e.RPP=3]="RPP",e[e.QUIC=4]="QUIC",e[e.WS=5]="WS",e[e.WSS=6]="WSS",e[e.HTTP=11]="HTTP",e[e.HTTPS=12]="HTTPS"}(Ge||(Ge={}));var et,tt=[Ge.RMTP,Ge.TLS,Ge.QUIC],nt=function(e){function t(t,n,o,r,s,i){var a=e.call(this,t,n,o)||this;return a.addon=s,a.httpRequestProxy=i,a.naviPath="",a._caches={},a.naviPath="".concat(r,"/navi-cache.json"),a}return pe(t,e),t.prototype.httpRequest=function(e,t,n,o){return fe(this,void 0,void 0,(function(){var r,s,i,a,c,u,p,l,d=this;return he(this,(function(f){switch(f.label){case 0:r="token=".concat(encodeURIComponent(n),"&v=").concat(R,"&p=PC&ev=").concat("5.8.2-enterprise-lz.30"),s="".concat(e,"/navi.json?r=").concat(Date.now(),"&env=").concat(this._environment),this.logger.info(g.L_REQUEST_T,JSON.stringify({url:s,body:r}),o),c=function(){a&&(clearTimeout(a),a=null)},f.label=1;case 1:return f.trys.push([1,3,,4]),[4,new Promise((function(e){a=setTimeout((function(){d.logger.warn(g.L_REQUEST_E,JSON.stringify({url:s,body:r,info:"http response timeout"}),o),e({status:0})}),E+5e3),d.httpRequestProxy?d.httpRequestProxy({url:s,method:"POST",headers:{appId:t},body:r,timeout:E}).then((function(t){c(),e(t)})).catch((function(t){d.logger.error(g.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),o),c(),e({status:0})})):He(d.logger,{method:"POST",headers:{appId:t},body:r,url:s,timeout:E}).then((function(t){c(),e(t)})).catch((function(t){d.logger.error(g.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),o),c(),e({status:0})}))}))];case 2:return i=f.sent(),[3,4];case 3:return u=f.sent(),this.logger.error(g.L_REQUEST_E,JSON.stringify({stack:null==u?void 0:u.stack,info:"Code execution error"}),o),c(),[2,{code:h.RC_NAVI_REQ_FAILED}];case 4:if(200!==i.status)return this.logger.warn(g.L_REQUEST_R,JSON.stringify({url:s,code:i.status}),o),[2,{code:this.transHttpCode(i.status)}];try{return p=JSON.parse(i.data),l=/^https/.test(s)?"https":"http",p.protocol=l,p.code&&200!==p.code?[2,{code:this.transHttpCode(p.code)}]:[2,{code:h.SUCCESS,data:p}]}catch(e){return this.logger.error(g.L_PARSE_NAVI_E,i.data,o),[2,{code:h.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.httpRequestV2=function(e,t,n,o){return fe(this,void 0,void 0,(function(){var r,s,i,a;return he(this,(function(c){switch(c.label){case 0:return r=this.getNaviV2RequestOption({appkey:t,token:n,uri:e,platform:"electron",protocol:tt.join(",")}),this.logger.debug(g.L_REQUEST_T,JSON.stringify({url:r.url,body:r.body,headers:r.headers}),o),[4,He(this.logger,r)];case 1:if(200!==(s=c.sent()).status)return this.logger.warn(g.L_REQUEST_R,JSON.stringify({url:r.url,code:s.status}),o),[2,{code:this.transHttpCode(s.status)}];try{return i=JSON.parse(s.data),a=/^https/.test(r.url)?"https":"http",i.protocol=a,[2,{code:h.SUCCESS,data:i}]}catch(e){return this.logger.error(g.L_PARSE_NAVI_E,s.data,o),[2,{code:h.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.getNaviCache=function(e){var t=this.getCatchKey(e),n=this._caches[t];if(n)return n;if(!i(this.naviPath))return null;var o=u(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(o),this._caches[t]}catch(e){this.logger.error(g.L_PARSE_NAVI_E,o)}return null},t.prototype.setNaviCache=function(e,t){var n=Date.now(),o=this.getCatchKey(e);if(y(this._caches))for(var r in this._caches){(n-this._caches[r].timestamp>m||o===r)&&delete this._caches[r]}this._caches[o]={token:e,naviInfo:t,timestamp:Date.now(),environment:this._environment},c(this.naviPath,JSON.stringify(this._caches))},t.prototype.setEnvironment=function(e){this._environment=e},t}(P);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(et||(et={}));var ot,rt=function(e){function t(t,n,o,r,s,i){var a=e.call(this,t,o,r,s,i)||this;return a.addon=n,a._listener=i,a._connectedTime=0,a._naviInfo=null,a.connectResolve=null,a._startTime=0,a._tcpDuration=0,a.pingResolve=null,a.addon.setConnectionStatusListener(a._onConnectComplete.bind(a),(function(e){a.logger.info(le.P_DB_OPEN_O,e)}),(function(){return a.recvPong(h.SUCCESS)}),a._onAddonDisconnected.bind(a),a._onTcpConnectResponse.bind(a),(function(e){a.logger.error(le.P_DB_OP_E,"Database operation failed with code: ".concat(e)),a._listener.onDatabaseOperationFailed(e)})),a}return pe(t,e),t.prototype.getConnectedTime=function(){return this._connectedTime},t.prototype.connectWithToken=function(e,t,n,o){var r=this;return new Promise((function(s){r._naviInfo=t,r.connectResolve={resolve:s,traceId:o,userId:t.userId};var i={},a=Ve().data;a&&(i={proxy_passwd:a.socksPassword||"",proxy_name:a.socksUsername||"",proxy_port:a.socksPort||1082,proxy_host:a.socksHost||"localhost",proxy_type:0});var c=JSON.stringify(de(de({},i),{call_plus:r._openCallPlus})),u=r.getCmpList(t,!0).filter((function(e){return tt.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),p=[];u.forEach((function(e){var t=p.find((function(t){return t.addr===e.addr}));t?t.protocol!==Ge.QUIC&&e.protocol!==Ge.QUIC||(t.race=!0,t.protocol=Ge.QUIC):(e.race=!1,p.push(e))}));var l=de(de({},t),{serverAddr:p});r.logger.info(le.P_CONNECT_T,JSON.stringify({use:p,catche:r.cmpWeightCache,proxy:i,FORMATED_VERSION:R,reconnectKickEnable:n,naviInfo:l}),o),r._startTime=Date.now();try{r.addon.connectWithToken(e,R,JSON.stringify(l),n,c)}catch(e){r.logger.error(le.P_CALL_ADDON_E,null==e?void 0:e.stack,o),r._onConnectComplete(h.RC_SOCKET_NOT_CREATED)}}))},t.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.addon.disconnect(t)},t.prototype.sendPing=function(e){var t=this;return new Promise((function(n){t.pingResolve=n,t.addon.sendHeartbeat(),setTimeout((function(){return t.recvPong(h.TIMEOUT)}),e)}))},t.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},t.prototype._onConnectComplete=function(e){if(this.connectResolve&&10!==e){var t=this.connectResolve,n=t.resolve,o=t.userId,r=t.traceId;this.logger.info(le.P_CONNECT_R,JSON.stringify({code:e,userId:o}),r);var s=Date.now()-(this._startTime+this._tcpDuration),i={bid:I(),cod:e,net:this.getNetwork().type,dur:s,spr:1,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:T.CURRENT,count:this.retryCount};this.statisticLog.__statistics(N.IM_CMP_RMTP,JSON.stringify(i)),e===h.SUCCESS&&(this._connectedTime=Date.now()-this.addon.getDeltaTime()),n({code:e,data:o}),this.connectResolve=null}},t.prototype._onAddonDisconnected=function(e,t){switch(this.logger.info(le.P_CONNECT_S,JSON.stringify({code:e,delay:t})),e){case h.RC_CONN_REDIRECTED:this._handleDisconnected(h.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case h.CONNECTION_REFUSED:case h.RC_SOCKET_DISCONNECTED:case h.RC_SOCKET_NOT_CREATED:case h.RC_CONN_ACK_TIMEOUT:case h.RC_TCP_RESET:this._handleDisconnected(e,!1);break;case h.RC_UDP_DISCONNECTED:this._handleDisconnected(e,!0,t);break;default:this._handleDisconnected(e,!0)}},t.prototype._handleDisconnected=function(e,t,n){if(t)this.onDisconnectByServer(e,n);else{if(e===h.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==O.CONNECTED)return;this.onDisconenctUnusual(e)}},t.prototype._onTcpConnectResponse=function(e,t,n,o,r,s,i){var a,c=this.cmpWeightCache.findIndex((function(e){return e.addr==="".concat(t,":").concat(n)})),u={bid:I(),ptc:M.TCP,cod:e,net:this.getNetwork().type,dur:o,spr:1,pr:(null===(a=this._naviInfo)||void 0===a?void 0:a.type)||0,hos:"".concat(t,":").concat(n),idx:c,rct:this.retryCount?U.RECONNECT:U.CONNECT,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:T.CURRENT,rsn:this.reason,ddu:r,count:this.retryCount,weight:this.cmpWeightCache[c].weight};this.statisticLog.__statistics(N.IM_CMP,JSON.stringify(u)),this.logger.info(le.P_CONNECT_ENTRY_S,JSON.stringify({code:e,host:t,port:n,duration:o,dnsDuration:r,index:s,isQuic:i})),e===et.SUCCESS&&(this.curCmpUrl="".concat(t,":").concat(n),this.updateCmpWeight("".concat(t,":").concat(n),!0,i))},t}(w),st=function(t){if(!i(t)){var n=e(t,"..");i(n)||st(n),a(t)}},it=function(){function r(o,r,s,i,a){var c=this;this._appkey=o,this._cppProtocol=r,this._dbpath=s,this._logOutputLevel=i,this._httpRequestProxy=a,this._customMessageType={},this._senders={},this._chatroomCache=[],this.rtcHeartbeatResolves={};var u=this._dbpath||e(t.getPath("userData")),l=ze(u);this._cppProtocol.initWithAppkey(o,u,R);var d=Y(e(__dirname,"sub-process.js"));this.subProxy=new Ze(d);var f=e(u,"RongCloud/rclogs",o);st(f),function(e,t,n){n.initLogModule(t,e,p())}(o,f,this._cppProtocol),this.logger=new Ee(this._appkey,"RC-M","IM"),this.statisticLog=new Re(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),Se(this._cppProtocol,this.logger),this.reporter=new Qe(this._cppProtocol,o,l,this.logger,this.subProxy),this.logger.info(le.P_INIT_O,JSON.stringify({appkey:o,dbpath:u,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:l,commit:"b856cac2f213bdd4b672b83019bdcde51e22c6af"})),this._callCppProxy("setDeviceId",l);var C=e(u,"RongCloud/navis",o);st(C),this.navi=new nt(o,this.logger,this.statisticLog,C,this._cppProtocol,this._httpRequestProxy),this.tcpMgr=new rt(o,this._cppProtocol,this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this),onDatabaseOperationFailed:function(e){c._send2AllRenderer("onDatabaseOperationFailed",e)}}),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setReadReceiptListener(),n.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return fe(c,void 0,void 0,(function(){var o,r,s;return he(this,(function(i){switch(i.label){case 0:if("function"!=typeof(o=this[t]))return this.logger.error(le.P_CALL_MAIN_SYNC_E,JSON.stringify({method:t,error:"not found"})),e.returnValue=h.NOT_SUPPORT,[2];r=h.EXTRA_METHOD_UNDEFINED,i.label=1;case 1:return i.trys.push([1,3,,4]),[4,o.call.apply(o,Ce([this],n,!1))];case 2:return r=i.sent(),[3,4];case 3:return s=i.sent(),this.logger.error(le.P_CALL_MAIN_SYNC_E,JSON.stringify({error:null==s?void 0:s.stack,method:t})),[3,4];case 4:return e.returnValue=r,[2]}}))}))})),n.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var o=[],r=3;r<arguments.length;r++)o[r-3]=arguments[r];return fe(c,void 0,void 0,(function(){var r,s,i,a,c=this;return he(this,(function(u){switch(u.label){case 0:if("function"!=typeof(r=this[n]))return this.logger.error(le.P_CALL_MAIN_E,JSON.stringify({method:n,error:"not found"})),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,h.NOT_SUPPORT),[2];"sendMessage"===n&&(s=o[3],o[3]=function(t){c._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",s,t)}),i=h.EXTRA_METHOD_UNDEFINED,u.label=1;case 1:return u.trys.push([1,3,,4]),[4,r.call.apply(r,Ce([this],o,!1))];case 2:return i=u.sent(),[3,4];case 3:return a=u.sent(),this.logger.error(le.P_CALL_MAIN_E,JSON.stringify({error:null==a?void 0:a.stack,method:n})),[3,4];case 4:return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,i),[2]}}))}))})),n.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];var r=c[t];if("function"==typeof r)try{r.call.apply(r,Ce([c],n,!1))}catch(e){c.logger.error(le.P_SEND_2_MAIN_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}else c.logger.error(le.P_SEND_2_MAIN_E,JSON.stringify({method:t,error:"not found"}))})),n.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this)),this._msgExpansionHandler=new $e(this._cppProtocol)}return r.prototype.onConnected=function(){var e=this.getNaviInfoFromCache();this.reporter.checkStart(e),this._try2RejoinChatroom(),this._send2AllRenderer("onConnected",this.getMainProcessCache())},r.prototype.onConnecting=function(){this._send2AllRenderer("onConnecting",void 0)},r.prototype.onSuspend=function(e){this._send2AllRenderer("onSuspend",e)},r.prototype.onDisconnected=function(e){this._send2AllRenderer("onDisconnected",e)},r.prototype._callCppProxy=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];var r=this.logger.createTraceId();try{return this.logger.info(le.P_CALL_ADDON_O,JSON.stringify({method:e,args:n}),r),(t=this._cppProtocol)[e].apply(t,n)}catch(t){this.logger.error(le.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),r)}},r.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},r.prototype.sendHTTPRequest=function(e){return He(this.logger,e)},r.prototype.onRendererLogsReceived=function(e){ye.apply(void 0,e)},r.prototype.onRendererNetworkStatusReceived=function(e,t){this.tcpMgr.setNetwork(e,t)},r.prototype.destroy=function(){var e;this.reporter.stop(),this.subProxy.destroy(),e=this._cppProtocol,_e(),e.deinitLogModule(),this._cppProtocol.destroy()},r.prototype.callExtra=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var o=this[e];if(!o)return this.logger.warn(le.P_CALL_EXTRA_E,JSON.stringify({method:e,error:"not found"})),Promise.resolve({code:h.EXTRA_METHOD_UNDEFINED});try{return o.call.apply(o,Ce([this],t,!1))}catch(t){this.logger.error(le.P_CALL_EXTRA_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return Promise.resolve({code:h.MAIN_PROCESS_ERROR})},r.prototype.getConversationsByPage=function(e,t,n,o,r){var s,i=this,a=this._callCppProxy("getConversationListByPageWithTopPriority",e,t,n,r||!1,o||"");try{s=JSON.parse(a).list.map((function(e){return i._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:s})},r.prototype.getUnreadConversationList=function(e){var t,n=this,o=this._callCppProxy("getUnreadConversationList",e);try{t=JSON.parse(o).list.map((function(e){return n._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:t})},r.prototype.getConversationListWithAllChannel=function(){var e,t=this,n=[x.PRIVATE,x.GROUP,x.SYSTEM,x.APP_PUBLIC_SERVICE,x.PUBLIC_SERVICE],o=this._callCppProxy("getConversationListWithAllChannel",n);try{e=JSON.parse(o).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:e})},r.prototype.getConversationListWithAllChannelByPage=function(e,t){var n,o=this,r=[x.PRIVATE,x.GROUP,x.SYSTEM,x.APP_PUBLIC_SERVICE,x.PUBLIC_SERVICE],s=this._callCppProxy("getConversationListWithAllChannelByPage",r,e,t);try{n=JSON.parse(s).list.map((function(e){return o._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:n})},r.prototype.getHistoryMessagesByObjectNames=function(e,t,n,o,r,s,i){var a=0===s,c=o+1,u=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,n,c,r,a,i||""),p=[];try{var l=JSON.parse(u).list;l.reverse();for(var d=0;d<l.length;d++){var f=this._buildMessage(l[d].obj);p[d]=f}}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:{list:c===p.length?p.slice(1,c):p,hasMore:o<p.length}})},r.prototype.updateMessageReceiptStatus=function(e,t,n,o){void 0===o&&(o="");var r=this._callCppProxy("updateMessageReceiptStatus",e,t,n,o);return Promise.resolve({code:h.SUCCESS,data:r})},r.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==O.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},r.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new Ee(this._appkey,e,t)},r.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},r.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},r.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},r.prototype._send2Renderer=function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,Ce([t],n,!1))},r.prototype._send2AllRenderer=function(e,t,n){var o=this;void 0===n&&(n=[]),Object.keys(this._senders).forEach((function(r){var s=o._senders[r];n.includes(s)||o._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},r.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),n=this.getNaviInfoFromCache(),o=this.tcpMgr.getCurrentUserId();return{connectedTime:e,deviceId:this.getDeviceId(),crtUserId:o,naviInfo:n,connectionStatus:t}},r.prototype._registerRenderers=function(e,t){var n=this,o=e.sender,r=o.id,s=t.navigators,i=t.areaCode,a=t.logServerUrl,c=t.environment;this._environment=c||"default",this.navi.setEnvironment(c),b.init({areaCode:i,navigators:s,logServerUrl:a}),this._senders[r]||(this._senders[r]=o,o.once("destroyed",(function(){delete n._senders[r]})))},r.prototype._registerMsgTypes=function(){for(var e in A["RC:RcCmd"]={isCounted:!1,isPersited:!1},A){var t=A[e],n=t.isCounted,o=t.isPersited,r=t.searchProps,s=0;o&&(s|=1),n&&(s|=2),"RC:TypSts"===e&&(s=16),this._callCppProxy("registerMessageType",e,s,r||[])}},r.prototype._buildIsMentioned=function(e,t){var n,o=!1;if(L(e))n=e;else try{n=e?JSON.parse(e):e}catch(o){n=e,this.logger.error(le.P_PARSE_JSON_MSGS_E,JSON.stringify({messageId:t}))}return L(n)&&(o=!!n.mentionedInfo),{isMentioned:o,msgContent:n}},r.prototype._buildMsgOption=function(e){var t={isCounted:!1,isPersited:!1};return e in A?t=A[e]:e in this._customMessageType&&(t=this._customMessageType[e]),t},r.prototype._buildSupportExt=function(e,t){var n=null;return e&&(n=this._msgExpansionHandler.parseReceiveExpansion(t)),n},r.prototype._transICppMessage2IReceivedMessage=function(e,t){var n=e.channelId,o=e.conversationType,r=e.targetId,s=e.senderUserId,i=e.content,a=e.objectName,c=e.messageUid,u=e.direction,p=e.status,l=e.messageId,d=e.sentTime,f=e.readReceiptRequest,h=e.supportExt,C=e.pushContent,g=e.pushTitle,v=e.pushId,_=e.pushConfig,S=e.templateId,y=e.disableTitle,m=e.forcePushDetail,P=e.needReceipt,E=e.sendReceipt,R=this._buildIsMentioned(i,l),I=R.isMentioned,T=R.msgContent,N=this._buildMsgOption(a),O=this._buildSupportExt(h,e),M=D(t)?d<this.tcpMgr.getConnectedTime():t,U={};_&&(U=k(this.logger,_,v));var w=de(de({},U),{pushTitle:g,pushContent:C,pushData:C,disablePushTitle:y,forceShowDetailContent:m,templateId:S}),x={channelId:n,conversationType:o,targetId:r,senderUserId:s,content:T||{},messageType:a,messageUId:c||"",messageDirection:u,isOffLineMessage:M,sentTime:d,receivedTime:0,isPersited:N.isPersited,isCounted:N.isCounted,isMentioned:I,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:h,expansion:h?O:null,receivedStatus:p,messageId:l,pushConfig:w,needReceipt:P,sentReceipt:E};u===J.RECEIVE?x.receivedStatus=p:u===J.SEND&&(x.sentStatus=p);var b=this.getNaviInfoFromCache();if(f&&1===(null==b?void 0:b.grpRRVer)){var A=JSON.parse(f),L=A.hasRespond,j=A.readerInfo,B={hasRespond:L,readCount:A.readCount,totalCount:A.totalCount},H=[];if(j)for(var F in j)H.push({userId:F,readTime:j[F]});B.readerList=H,x.readReceiptInfo=B}return x},r.prototype._buildMessage=function(e,t){void 0===t&&(t=!1);var n=JSON.parse(e);return this._transICppMessage2IReceivedMessage(n,t)},r.prototype._updateReadReceiptInfo=function(e,t){var n=this._callCppProxy("getMessage",e),o=JSON.parse(n),r=o.readReceiptRequest?JSON.parse(o.readReceiptRequest):{},s=de(de({},r),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},r.prototype._transICppConversation2IReceivedConversation=function(e){var t=e.channelId,n=e.conversationType,o=e.targetId,r=e.unreadCount,s=e.lastestMsg,i=e.isTop,a=e.isBlocked,c=e.matchCount,u=e.hasUnreadMention,p=e.draft,l=e.conversationTime,d=a?j.OPEN:j.CLOSE;return{channelId:t,conversationType:n,targetId:o,unreadMessageCount:r,latestMessage:-1===JSON.parse(s).messageId?null:this._buildMessage(s),hasMentioned:u,mentionedInfo:null,notificationStatus:d,isTop:i,lastUnreadTime:0,matchCount:c,draft:p,operationTime:l}},r.prototype._buildConversation=function(e){var t=JSON.parse(e);return this._transICppConversation2IReceivedConversation(t)},r.prototype._convertResultList=function(e,t){var n=JSON.parse(e).list;return n=n.map((function(e){var n=JSON.parse(e.obj);return t?t(n):n}))},r.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,n,o,r){var s,i=e._buildMessage(t,o),a=i.messageType,c=i.channelId,u=void 0===c?"":c;if(a!==B.LOG_COMMAND||"rongcloudsystem"!==i.senderUserId){if(a===B.GROUP_READ_RECEIPT_REQUEST){var p=i.content,l=p.msgId,d=p.rrn,f=p.tmn;e._updateReadReceiptInfo(l,{readCount:d,totalCount:f})}if("RC:MsgExMsg"===a)return e._msgExpansionHandler.setLocalFromExtMsg(e.logger,i),void e._sendMessageExpansion(i);if(i.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(e.logger,i),a!==B.SYNC_READ_STATUS||i.senderUserId===e.tcpMgr.getCurrentUserId()){(a===B.SYNC_READ_STATUS||a===B.READ_RECEIPT&&i.senderUserId===e.tcpMgr.getCurrentUserId())&&e._callCppProxy("clearUnreadCountByTimestamp",i.conversationType,i.targetId,i.content.lastMessageSendTime,u);var h=!0;if(0!==n||r||(h=!1),a===B.DELIVERED)return e._callCppProxy("setMessageDeliverTime",JSON.stringify(i.content)),void e._sendMessageDelivered(i.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}})));if(a!==B.DELIVERED_MSG){var C=i.conversationType,g=i.targetId;if(a===B.RECALL){e.handleRecalledMessage(i);var v=e._fixRecallContentInfo(i);C=v.conversationType,g=v.targetId}e._sendMessageNotification(Object.assign(i,{hasMoreMsg:h,conversationType:C,targetId:g}))}else{var _={totalCount:i.content.tmn,list:null===(s=i.content.dl)||void 0===s?void 0:s.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};e._sendGroupMessageDeliveredStatus(_)}}}else{var S=i.content,y=S.startTime,m=S.endTime,P=S.platform,E=S.logId,R=S.uri;e.reporter.report(parseInt(y,10),parseInt(m,10),P,R,E,i.messageUId)}}),(function(){e._sendPullOfflineFinished()}))},r.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,n=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,n=e.content.targetId||n),{conversationType:t,targetId:n}},r.prototype.handleRecalledMessage=function(e,t){void 0===t&&(t=!1);var n=e.content.messageUId;if(n){var o=this._callCppProxy("getMessage",n),r=this._buildMessage(o);if(r.messageId){var s={recallTime:e.sentTime,admin:!!e.content.isAdmin,originalObjectName:r.messageType,originalMessageContent:r.content,recallActionTime:0,operatorId:e.senderUserId};t&&(s.recallActionTime=Date.now()),e.content.user&&(s.user=e.content.user),e.content.extra&&(s.extra=e.content.extra),r.messageType===B.TextMessage&&(s.recallContent=r.content.content),e.content.isDelete?this._callCppProxy("deleteMessages",[r.messageId]):(r.receivedStatus!==H.UNREAD&&r.receivedStatus!==H.RETRIEVED||this.setMessageReceivedStatus(r.messageId,1),this._callCppProxy("setMessageContent",r.messageId,JSON.stringify(s),B.RECALL_NOTIFICATION_MESSAGE))}}},r.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var n=e.channelId,o=e.content,r=o.put,s=o.del,i=o.mid,a={};r&&(a.updatedExpansion={channelId:n,messageUId:i,expansion:r}),s&&(a.deletedExpansion={channelId:n,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},r.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},r.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},r.prototype._sendMessageDelivered=function(e){this._send2AllRenderer("messageDelivered",e)},r.prototype._sendGroupMessageDeliveredStatus=function(e){this._send2AllRenderer("groupMessageDeliveredStatus",e)},r.prototype._sendChatroomStatus=function(e){this._send2AllRenderer("chatroom",e)},r.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var n=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj),n={channelId:t.channelId,conversationType:t.conversationType,targetId:t.targetId,updatedItems:{}};return t.status.forEach((function(e){var t=JSON.parse(e.item),o=t.type,r=t.value;if(1===o){var s=Number(r)||F.NOT_SET;n.updatedItems.notificationLevel={val:s,time:0},n.updatedItems.notificationStatus={val:V(s),time:0}}else 2===o&&(n.updatedItems.isTop={val:"1"===r,time:0})})),n}));e._send2AllRenderer("conversation",n)}),(function(t){e._send2AllRenderer("conversationTag",t)}))},r.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._send2AllRenderer("tag",t),e._getRTCProfile()}))},r.prototype._setReadReceiptListener=function(){var e=this;this._cppProtocol.setReadReceiptListener((function(t){try{var n=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId,messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));e._send2AllRenderer("messageReadReceipt",n)}catch(n){e.logger.info(le.P_PARSE_JSON_MSGS_E,t)}}))},r.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var n=this.navi.getNaviInfoFromCache(t);this._send2AllRenderer("onNaviDataChange",n)}},r.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var n=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",n)}))},r.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,n){e._sendChatroomStatus({chatroomDestroyed:t})}))},r.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){var n=[];try{JSON.parse(t).list.forEach((function(e){Object.entries(e).forEach((function(e){var t=e[0],o=e[1];n.push({key:t,value:o})}))}))}catch(t){e.logger.error(le.P_PARSE_JSON_E,null==t?void 0:t.stack)}e._send2AllRenderer("callInfo",JSON.stringify({list:n}))}))},r.prototype._updateMentionedInfo=function(e,t,n){var o,r,s;return{userIdList:(null===(o=e.mentionedInfo)||void 0===o?void 0:o.userIdList)||t,type:(null===(r=e.mentionedInfo)||void 0===r?void 0:r.type)||n||G.ALL,mentionedContent:(null===(s=e.mentionedInfo)||void 0===s?void 0:s.mentionedContent)||""}},r.prototype.registerMessageType=function(e,t,n,o){void 0===o&&(o=[]);var r=0;t&&(r|=1),n&&(r|=2),this._customMessageType[e]={isCounted:n,isPersited:t},this.logger.info(le.P_REGTYP_O,JSON.stringify({type:e,opt:r,search:o})),this._callCppProxy("registerMessageType",e,r,o)},r.prototype.connect=function(e,t,n,o){return this.tcpMgr.connect(e,t,n,o)},r.prototype.reportSDKInfo=function(e){var t,n,o=JSON.stringify(de(de({},e),{"electron-main":"5.8.2-enterprise-lz.30"}));this.logger.info(le.P_REPORT_VER_O,o),null===(n=(t=this._cppProtocol).uploadSDKVersion)||void 0===n||n.call(t,o)},r.prototype.disconnect=function(e){this._chatroomCache.length=0,this.reporter.stop(),Fe(null,this.logger),this.tcpMgr.disconnect(e)},r.prototype.logout=function(){this.disconnect()},r.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,n){t({userId:e,status:n})}));var n=e.userIds||[];n.length&&this.subscribeUserStatus(n)},r.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("subscribeUserStatus",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.setUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("setUserStatus",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.getUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getUserStatus",e,(function(e){n({code:h.SUCCESS,data:{status:e}})}),(function(e){n({code:e})}))}))},r.prototype.sendMessage=function(e,t,n,o,r){var s=this;void 0===r&&(r=this.logger.createTraceId());var i=n.messageType,a=n.content,c=n.expansion,u=n.pushConfig,p=n.isMentioned,l=n.mentionedType,d=n.mentionedUserIdList,f=void 0===d?[]:d,C=n.pushContent,g=void 0===C?"":C,v=n.pushData,_=void 0===v?"":v,S=n.directionalUserIdList,y=void 0===S?[]:S,m=n.disableNotification,P=void 0!==m&&m,E=n.canIncludeExpansion,R=void 0!==E&&E,I=n.isVoipPush,T=void 0!==I&&I,N=n.channelId,O=void 0===N?"":N,M=n.messageId,U=void 0===M?0:M,w=n.encrypted,b=void 0!==w&&w,A=n.needReceipt,L=void 0!==A&&A,D=u||{},k=D.iOSConfig,J=D.androidConfig,j=D.templateId,H=void 0===j?"":j,F=D.pushTitle,V=void 0===F?"":F,G=D.pushContent,W=void 0===G?g:G,K=D.pushData,Q=void 0===K?_:K,Y=D.disablePushTitle,X=void 0!==Y&&Y,z=D.forceShowDetailContent,$=void 0!==z&&z,Z=q(k,J);return new Promise((function(n){g=W,_=Q;var u=(null==J?void 0:J.notificationId)||"";e===x.GROUP&&p&&a&&(a.mentionedInfo=s._updateMentionedInfo(a,f,l));var d=e===x.GROUP;if(d&&i===B.READ_RECEIPT_RESPONSE&&a.receiptMessageDic)for(var C in a.receiptMessageDic)y.push(C);d&&i===B.SYNC_READ_STATUS&&(y=[s.getCurrentUserId()]);var v={};for(var C in c)v[C]={v:""},v[C].v=c[C];var S=H;s.logger.info(le.P_SEND_MSG_T,JSON.stringify({messageType:i,conversationType:e,targetId:t,channelId:O,messageId:U}),r);var m=s._callCppProxy("sendMessage",(function(e,t){var o=s._buildMessage(e);return s.logger.info(le.P_SEND_MSG_R,JSON.stringify({code:t,messageUId:o.messageUId,messageId:o.messageId}),r),t===h.SENSITIVE_REPLACE?n({code:t}):("RC:MsgExMsg"===o.messageType&&s._msgExpansionHandler.setLocalFromExtMsg(s.logger,o),o.canIncludeExpansion&&s._msgExpansionHandler.setLocalFromReceiveMsg(s.logger,o),n({code:h.SUCCESS,data:o}))}),(function(e,t){var o=s._buildMessage(e);return s.logger.warn(le.P_SEND_MSG_R,JSON.stringify({code:t,messageId:o.messageId}),r),o.sentTime=Date.now()-s._cppProtocol.getDeltaTime(),n({code:t,data:o})}),e,t,i,JSON.stringify(a),y,P,X,$,g,_,u,V,Z,S,R,JSON.stringify(v),T,O,U,b,L),E=JSON.parse(m);null==o||o(E.messageId)}))},r.prototype.recallMsg=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){var c,u=r.user,p=r.pushContent,l=r.channelId,d=r.extra,f=r.pushConfig,C=r.disableNotification,g=r.isDelete,v={conversationType:e,targetId:t,messageUId:n,sentTime:o,user:u,extra:d,channelId:l,isDelete:g||!1};u&&(v.user=u),d&&(v.extra=d);s._callCppProxy("recallMessage",(function(o){var r={conversationType:e,targetId:t,senderUserId:s.tcpMgr.getCurrentUserId(),content:v,objectName:B.RECALL,messageUid:n,direction:J.SEND,status:H.UNREAD,sentTime:Number(o),channelId:l},a=s._buildMessage(JSON.stringify(r));s.handleRecalledMessage(a,!0),i({code:h.SUCCESS,data:a})}),(function(e){i({code:e})}),B.RECALL,JSON.stringify(v),C||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,p||"",(null==f?void 0:f.pushData)||"",(null===(c=null==f?void 0:f.androidConfig)||void 0===c?void 0:c.notificationId)||"",(null==f?void 0:f.pushTitle)||"",q(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",l)}))},r.prototype.getHistoryMessage=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c,u){n=n||0;var p=0===r,l=o+1,d=a._callCppProxy("getHistoryMessages",e,t,n,l,i,p,s),f=JSON.parse(d).list,C=[];f.reverse();for(var g=0;g<f.length;g++){var v=a._buildMessage(f[g].obj);C[g]=v}c({code:h.SUCCESS,data:{list:l===C.length?C.slice(1,l):C,hasMore:o<C.length}})}))},r.prototype.getRemoteHistoryMessages=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,c){n=n||0;i._callCppProxy("getRemoteHistoryMessages",e,t,n,o,(function(e,t){var n=JSON.parse(e).list,o=[];n.reverse();for(var r=0;r<n.length;r++){var s=i._buildMessage(n[r].obj);o[r]=s}a({code:h.SUCCESS,data:{list:o,hasMore:!!t}})}),(function(e){a({code:e})}),r,!0,s)}))},r.prototype.deleteRemoteMessage=function(e,t,n,o){var r=this;return new Promise((function(s,i){var a=JSON.stringify(n);r._callCppProxy("deleteRemoteHistoryMessages",e,t,a,!1,o,(function(){s(h.SUCCESS)}),s)}))},r.prototype.deleteRemoteMessageByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearRemoteHistoryMessages",e,t,n,(function(){s(h.SUCCESS)}),(function(e){s(e)}),o)}))},r.prototype.clearMessages=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("clearMessages",e,t,n),r(h.SUCCESS)}))},r.prototype.getConversationList=function(e,t,n,o,r){var s=this;return void 0===r&&(r=""),new Promise((function(e,t){for(var n=s._callCppProxy("getConversationList",[1,3,6,7],r),o=JSON.parse(n).list,i=[],a=0;a<o.length;a++)i.push(s._buildConversation(o[a].obj));e({code:h.SUCCESS,data:i})}))},r.prototype.getConversation=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversation",e,t,n);if(i)r({code:h.SUCCESS,data:o._buildConversation(i)});else{var a=o._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,n),c=void 0;try{c=JSON.parse(a).list}catch(e){o.logger.error(le.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=o._buildMessage(c[0].obj));var p=o._callCppProxy("getConversationNotificationStatus",e,t,n),l=o._callCppProxy("getConversationTopStatus",e,t,n);r({code:h.SUCCESS,data:{conversationType:e,targetId:t,channelId:n,unreadMessageCount:0,latestMessage:u,notificationStatus:p?j.OPEN:j.CLOSE,isTop:Boolean(l),lastUnreadTime:0}})}}))},r.prototype.removeConversation=function(e,t,n){var o=this._callCppProxy("removeConversation",e,t,n);return Promise.resolve(o?h.SUCCESS:h.UNKNOWN)},r.prototype.clearConversations=function(e,t){var n=this;return new Promise((function(o,r){var s=[];s=W(e)?e:[x.PRIVATE,x.GROUP,x.SYSTEM,x.PUBLIC_SERVICE],n._callCppProxy("clearConversations",s,t),o(h.SUCCESS)}))},r.prototype.getAllConversationUnreadCount=function(e,t,n){var o=this._callCppProxy("getTotalUnreadCount",t,n,e);return Promise.resolve({code:h.SUCCESS,data:o})},r.prototype.getConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r){var s=o._callCppProxy("getUnreadCount",e,t,n);r({code:h.SUCCESS,data:s})}))},r.prototype.clearConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r,s){o._callCppProxy("clearUnreadCount",e,t,n),r(h.SUCCESS)}))},r.prototype.clearUnreadCountByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearUnreadCountByTimestamp",e,t,n,o),s(h.SUCCESS)}))},r.prototype.getFirstUnreadMessage=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getTheFirstUnreadMessage",e,t,n),a=o._buildMessage(i);r({code:h.SUCCESS,data:-1!==a.messageId?a:null})}))},r.prototype.setConversationToTop=function(e,t,n,o){var r=this;return void 0===o&&(o=""),new Promise((function(s,i){r._callCppProxy("setConversationToTop",e,t,n,o,!0),s(h.SUCCESS)}))},r.prototype.setConversationHidden=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationHidden",e,t,n,o),s(h.SUCCESS)}))},r.prototype.setConversationNotificationStatus=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationNotificationStatus",e,t,n,(function(){s(h.SUCCESS)}),s,o)}))},r.prototype.setConversationStatus=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("setConversationStatus",e,t,n,o,(function(){a(h.SUCCESS)}),a,r,!0,s)}))},r.prototype.getConversationNotificationStatus=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversationNotificationStatus",e,t,n);r({code:h.SUCCESS,data:i?j.OPEN:j.CLOSE})}))},r.prototype.setConversationTypeNotificationLevel=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setBlockPushLevelForType",e,t,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.getConversationTypeNotificationLevel=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getBlockPushLevelForType",e);n({code:h.SUCCESS,data:r})}))},r.prototype.searchConversationByContent=function(e,t,n,o,r){var s=this;return new Promise((function(i){o=o||[1,3,6,7],s._callCppProxy("searchConversationsByContentIncludeDeleted",o,e,t,n,!!r,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return s._transICppConversation2IReceivedConversation(e)}));i({code:h.SUCCESS,data:n})}else i({code:e})}))}))},r.prototype.searchConversationsByPage=function(e,t){var n=this,o=e.conversationTypes,r=e.keyword,s=e.messageTypes,i=e.includeDeleted,a=e.startTime,c=e.count;return new Promise((function(e){n.logger.info(le.P_SEARCH_CONVERSATIONS_T,"start",t),n._callCppProxy("searchConversationsByContentIncludeDeletedByPage",o,r,s||[],"",!!i,(function(o,r,s){if(n.logger.info(le.P_SEARCH_CONVERSATIONS_R,JSON.stringify({code:o}),t),o===h.SUCCESS){var i=JSON.parse(r).map((function(e){return n._transICppConversation2IReceivedConversation(e)}));n.logger.info(le.L_FORMAT_CONVERSATIONS_S,"done",t),e({code:h.SUCCESS,data:{list:i,totalCount:s}})}else e({code:o})}),a,c),n.logger.info(le.L_JS_GET_NOW_TIME_S,Date.now(),t)}))},r.prototype.searchConversationByContentWithAllChannel=function(e,t,n){var o=this;return new Promise((function(r,s){n=n||[1,3,6,7],o._callCppProxy("searchConversationByContentWithAllChannel",n,e,t,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return o._transICppConversation2IReceivedConversation(e)}));r({code:h.SUCCESS,data:n})}else r({code:e})}))}))},r.prototype.searchMessageByContent=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(s,c){a._callCppProxy("searchMessageByContent",e,t,n,o,r,!0,(function(e,t,n){if(e===h.SUCCESS){var o=JSON.parse(t).map((function(e){return a._transICppMessage2IReceivedMessage(e)}));s({code:h.SUCCESS,data:{messages:o,count:n}})}else s({code:e})}),i)}))},r.prototype.searchMessageByContentAndMessageType=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c){a._callCppProxy("searchMessageByContentAndObjectName",t,e,i||"",void 0===i,n,s,r,o,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return a._transICppMessage2IReceivedMessage(e)}));c({code:h.SUCCESS,data:{messages:n}})}else c({code:e})}))}))},r.prototype.searchMessagesByUser=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("getMessageBySender",e,t,n,o,r,s,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],o=0;o<t.length;o++)n[o]=i._buildMessage(t[o].obj);a({code:h.SUCCESS,data:{messages:n}})}))}))},r.prototype.searchMessageByContentWithAllChannel=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("searchMessageByContentWithAllChannel",e,t,n,o,r,!0,(function(e,t,n){if(e===h.SUCCESS){var o=JSON.parse(t).map((function(e){return s._transICppMessage2IReceivedMessage(e)}));i({code:h.SUCCESS,data:{messages:o,count:n}})}else i({code:e})}))}))},r.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c,u){a._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,n,o,r,s,i,(function(e,t){if(e===h.SUCCESS){var n=JSON.parse(t).map((function(e){return a._transICppMessage2IReceivedMessage(e)}));c({code:h.SUCCESS,data:{messages:n}})}else c({code:e})}))}))},r.prototype.getUnreadMentionedMessages=function(e,t,n){for(var o=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,n)).list,r=0;r<o.length;r++)o[r]=this._buildMessage(o[r].obj);return o},r.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addToBlacklist",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("removeFromBlacklist",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,n){e._callCppProxy("getBlacklist",(function(e){t({code:h.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},r.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getBlacklistStatus",e,(function(e){n({code:h.SUCCESS,data:e})}),(function(e){n({code:e})}))}))},r.prototype.insertMessage=function(e,t,n){var o=this,r=n.content,s=n.senderUserId,i=n.messageType,a=n.messageDirection,c=n.readStatus,u=n.sentStatus,p=n.sentTime,l=n.searchContent,d=n.isUnread,f=n.messageUId,C=n.disableNotification,g=n.canIncludeExpansion,v=n.expansionMsg,_=n.channelId;r=JSON.stringify(r);var S={};if(p=p||0,v){var y=JSON.parse(v);for(var m in y)S[m]={v:"",ts:0},S[m].v=y[m],S[m].ts=p}return new Promise((function(n,v){var y=d?0:1,m=o._callCppProxy("insertMessage",e,t,s,i,r,(function(){}),(function(e){n({code:e})}),a,c||0,u||10,p,l||"",y,f||"",!!C,!!g,JSON.stringify(S),_||""),P=o._buildMessage(m);P.messageUId=f,P.sentTime=p,n({code:-1===P.messageId?h.MSG_INSERT_ERROR:h.SUCCESS,data:P})}))},r.prototype.batchInsertMessage=function(e,t){var n=this;return void 0===t&&(t=!1),new Promise((function(o){var r=e.map((function(e){var t=e.content,n=e.senderUserId,o=e.messageType,r=e.messageDirection,s=e.receivedStatus,i=e.sentStatus,a=e.sentTime,c=e.searchContent,u=e.isUnread,p=e.messageUId,l=e.disableNotification,d=e.canIncludeExpansion,f=e.expansion,h=e.channelId,C=e.conversationType,g=e.targetId,v=e.source,_=e.isMentioned,S={};if(a=a||0,f)for(var y in f)S[y]={v:"",ts:0},S[y].v=f[y],S[y].ts=a;return{conversationType:C,targetId:g,channelId:h||"",direction:r,senderUserId:n,status:i||10,sentTime:a,objectName:o,content:JSON.stringify(t),messageUid:p||"",noNotification:!!l,supportExt:!!d,extMsg:JSON.stringify(S),readStatus:s||0,searchContent:c||"",isUnread:!!u,source:v||"",isMention:_}})),s=n._callCppProxy("insertMessages",JSON.stringify(r),t);o({code:s?h.SUCCESS:h.MSG_INSERT_ERROR,data:s||!1})}))},r.prototype.getMessageCount=function(e,t,n){var o=this;return new Promise((function(r){var s=o._callCppProxy("getMessageCount",e,t,n);r({code:h.SUCCESS,data:s})}))},r.prototype.deleteMessages=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("deleteMessages",e),n(h.SUCCESS)}))},r.prototype.deleteMessagesByTimestamp=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("deleteMessagesByTimestamp",e,t,n,o,r),i(h.SUCCESS)}))},r.prototype.getMessage=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getMessage",e),s=t._buildMessage(r);n({code:h.SUCCESS,data:s})}))},r.prototype.setMessageContent=function(e,t,n){var o=this;return new Promise((function(r,s){t=JSON.stringify(t),o._callCppProxy("setMessageContent",e,t,n),r(h.SUCCESS)}))},r.prototype.setMessageSearchField=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageSearchField",e,t,n),r(h.SUCCESS)}))},r.prototype.setMessageSentStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageSentStatus",e,t),o(h.SUCCESS)}))},r.prototype.setMessageReceivedStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageReceivedStatus",e,t),o(h.SUCCESS)}))},r.prototype.saveConversationMessageDraft=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("saveTextMessageDraft",e,t,n,o||"")&&s(h.SUCCESS),s(h.DRAF_SAVE_ERROR)}))},r.prototype.getConversationMessageDraft=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getTextMessageDraft",e,t,n||"");r({code:h.SUCCESS,data:i})}))},r.prototype.clearConversationMessageDraft=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("clearTextMessageDraft",e,t,n||"")&&r(h.SUCCESS),r(h.DRAF_REMOVE_ERROR)}))},r.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},r.prototype.batchSetConversationStatus=function(e){var t=e[0],n=t.conversationType,o=t.targetId,r=t.isTop,s=t.notificationLevel,i=t.channelId,a=t.isUpdateTime,c=void 0===a||a,u=this._callCppProxy("getConversationNotificationStatus",n,o,i||""),p=this._callCppProxy("getConversationTopStatus",n,o,i||""),l=D(s)?Boolean(u):s>F.NOT_SET,d=D(r)?Boolean(p):r;return this.setConversationStatus(n,o,l,d,i,c)},r.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},r.prototype.sendReadReceiptMessage=function(e,t,n){var o=this;return new Promise((function(r){o._callCppProxy("sendReadReceipt",e,n||"",t,(function(){t.forEach((function(e){o._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(o._callCppProxy("getMessage",e)).messageId;o.setMessageReceivedStatus(t,1)}catch(t){o.logger.error(le.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),r({code:h.SUCCESS})}),(function(e){r({code:e})}))}))},r.prototype.getMessageReader=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getMessageReader",e,n,t,(function(e,n){var s=[],i={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),n=t.id,o=t.time;s.push({userId:n,readTime:o}),i[n]=o}));var a={readerInfo:i,readCount:s.length,totalCount:n};o._updateReadReceiptInfo(t,a),r({code:h.SUCCESS,data:{list:s,totalMemberCount:n}})}),(function(e){r({code:e})}))}))},r.prototype.sendReadReceipt=function(e,t){var n=this;return new Promise((function(o,r){var s=e.conversationType,i=e.targetId,a=e.channelId,c=void 0===a?"":a,u=n._callCppProxy("sendReadReceiptByReadReceiptType",s,i,c,0,t.map((function(e){return e.messageUId})),(function(e){e===h.SUCCESS&&t.forEach((function(e){n.setMessageReceivedStatus(e.messageId,H.READ)})),o({code:e})}));u!==h.SUCCESS&&o({code:u})}))},r.prototype._addChatroomCache=function(e,t,n){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:n,count:t})},r.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},r.prototype._try2RejoinChatroom=function(){var e=this;if(0!==this._chatroomCache.length){var t=this.logger.createTraceId();this._chatroomCache.forEach((function(n){return fe(e,void 0,void 0,(function(){var e,o,r,s;return he(this,(function(i){switch(i.label){case 0:return e=n.chatroomId,o=n.joinExist,r=n.count,this.logger.info(g.L_REJOIN_CHATROOM_T,e,t),[4,this._joinChrm(e,r,o,!1)];case 1:return(s=i.sent())===h.SUCCESS?(this.logger.info(g.L_REJOIN_CHATROOM_R,e,t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,count:r}}),[2]):(s===h.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(e),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,errorCode:s}}),this.logger.warn(g.L_REJOIN_CHATROOM_R,"chrmId: ".concat(e,", code: ").concat(s),t),[2])}}))}))}))}},r.prototype._joinChrm=function(e,t,n,o){var r=this,s=n?"joinExistChatRoom":"joinChatRoom";return new Promise((function(i){o&&r._callCppProxy("clearMessages",x.CHATROOM,e,""),r._callCppProxy(s,e,t,(function(){r._addChatroomCache(e,t,n),i(h.SUCCESS)}),i)}))},r.prototype.joinChatroom=function(e,t){return this._joinChrm(e,t,!1,!0)},r.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},r.prototype.quitChatroom=function(e){var t=this;return this._rmChatroomCache(e),new Promise((function(n,o){t._callCppProxy("quitChatRoom",e,(function(){n(h.SUCCESS)}),n)}))},r.prototype.getChatroomInfo=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getChatroomInfo",e,t,n,(function(e,t){var n=e?JSON.parse(e).list:[],o=[];if(n.length>0)for(var s=0;s<n.length;s++)o.push(JSON.parse(n[s].obj));r({code:h.SUCCESS,data:{userInfos:o,userCount:t}})}),(function(e){r({code:e})}))}))},r.prototype.getChatroomHistoryMessages=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomHistoryMessage",e,t,n,o,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var n=t.list;if(n&&n.length)try{t.list=n.map((function(e){return r._buildMessage(e.obj)}))}catch(e){t.list=[]}s({code:h.SUCCESS,data:t})}),(function(e){s({code:e})}),"")}))},r.prototype.setChatroomEntry=function(e,t){var n=this;return new Promise((function(o,r){var s='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');n._callCppProxy("setChatroomKV",e,s,!!t.isAutoDelete,!!t.isOverwrite,(function(){o(h.SUCCESS)}),(function(e){o(e)}))}))},r.prototype.setChatroomEntries=function(e,t){var n=this;return new Promise((function(o){n._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},r.prototype.removeChatroomEntry=function(e,t){var n=this,o=[t.key];return new Promise((function(r,s){n._callCppProxy("deleteChatroomKV",e,o,!!t.isOverwrite,(function(){r(h.SUCCESS)}),(function(e){r(e)}))}))},r.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},r.prototype.removeChatroomEntries=function(e,t){var n=this;return new Promise((function(o){var r=t.entries.map((function(e){return e.key}));n._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.getChatroomEntry=function(e,t){return fe(this,void 0,void 0,(function(){var n;return he(this,(function(o){switch(o.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(n=o.sent()).code===h.SUCCESS?[2,{code:h.SUCCESS,data:n.data?n.data[t]:null}]:[2,{code:n.code}]}}))}))},r.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}n({code:h.SUCCESS,data:t})}),(function(e){n({code:e})}))}))},r.prototype.getFileToken=function(e,t,n,o,r){var s=this;return void 0===r&&(r=""),n=n||"",o=o||"",new Promise((function(i){var a;a=o&&"uploads"!==o?t||"":K(e,t);var c=s.getNaviInfoFromCache(),u={uploadDomain:Q(c,s.logger),env:s._environment};s._callCppProxy("getUploadToken",e,a,n,o,r,JSON.stringify(u),(function(e,t,n,o,r,s,c,u,p,l,d,f,C,g,v,_,S,y,m,P,E,R,I){i({code:h.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:n,path:o,osskeyId:r,ossPolicy:s,ossSign:c,ossBucketName:u,fileName:a,s3Credential:p,s3Algorithm:l,s3Date:d,s3Policy:f,s3Signature:C,s3BucketName:g,stcAuthorization:v,stcContentSha256:_,stcDate:S,stcBucketName:y,minioAuthorization:m,minioContentSha256:P,minioDate:E,minioBucketName:R,downloadAuthInfo:I?JSON.parse(I):null}})}),(function(e){i({code:e})}))}))},r.prototype.getFileUrl=function(e,t,n,o){var r=this;return new Promise((function(s){var i=r.getNaviInfoFromCache(),a={url:Q(i,r.logger)};r._callCppProxy("getDownloadUrl",e,n,o,t-1,JSON.stringify(a),(function(e){s({code:h.SUCCESS,data:{downloadUrl:e}})}),(function(e){s({code:e})}))}))},r.prototype.clearData=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("clearData");t({code:h.SUCCESS,data:o})}))},r.prototype.getDeviceId=function(){var n=this._dbpath||e(t.getPath("userData"));return ze(n)},r.prototype.getVoIPKey=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("getVoIPKey",e,t,"",(function(e){o({code:h.SUCCESS,data:e})}),(function(e){o({code:e})}))}))},r.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(n,o){var r=e.chatRoomId,s=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",r,s,(function(){n(h.SUCCESS)}),(function(e){n(e)}))}))},r.prototype.getGroupMessageDeliverList=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getGroupMessageDeliverList",e,n,t,(function(e,t){var n=JSON.parse(e).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));r({code:h.SUCCESS,data:{totalCount:t,list:n}})}),(function(e){r({code:e})}))}))},r.prototype.getPrivateMessageDeliverTime=function(e,t){var n=this;return new Promise((function(o,r){var s=n._callCppProxy("getMessageDeliverTime",e);if(s)o({code:h.SUCCESS,data:s});else{n._callCppProxy("getPrivateMessageDeliverList",t,e,(function(e){var t=0,n=JSON.parse(e).list;n.length>0&&(t=JSON.parse(n[0].obj).time);o({code:h.SUCCESS,data:t})}),(function(e){o({code:e})}))}}))},r.prototype.rtcSignaling=function(e,t,n,o){var r=this,s=Array.prototype.slice.call(new Uint8Array(o));return new Promise((function(o){r._callCppProxy("rtcSignaling",e,t,n,s,(function(e){var t=new Uint8Array(e).buffer;o({code:h.SUCCESS,buffer:t})}),(function(e){o({code:e})}))}))},r.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,n){var o=e.rtcHeartbeatResolves[t];if(o){var r=o.find((function(e){return""===e.seqId}));r&&(r.seqId=n)}}),(function(t,n,o,r){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===o}));-1!==i&&s.splice(i,1)[0].resolve({code:n,data:{version:Number(r)}})}}))},r.prototype.rtcPing=function(e,t,n){var o=this;return new Promise((function(t){var n={resolve:t,seqId:""},r=o.rtcHeartbeatResolves[e];r?r.push(n):o.rtcHeartbeatResolves[e]=[n],o._callCppProxy("sendRTCHeartbeat",[e])}))},r.prototype.createTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){n({code:h.SUCCESS})}),(function(e){n({code:e})}))}))},r.prototype.removeTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("deleteTag",e,(function(){n({code:h.SUCCESS})}),(function(e){n({code:e})}))}))},r.prototype.updateTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){n({code:h.SUCCESS})}),(function(e){n({code:e})}))}))},r.prototype.getTagList=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("getTags"),r=e._convertResultList(o,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:h.SUCCESS,data:r})}))},r.prototype.addTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));n._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.removeTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),n._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.removeTagsForConversation=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){o({code:h.SUCCESS})}),(function(e){o({code:e})}))}))},r.prototype.getConversationListByTag=function(e,t,n,o){var r=this;return new Promise((function(s){var i=r._callCppProxy("getConversationsForTagByPage",e,t,n||20,o||""),a=r._convertResultList(i,(function(e){return de(de({},r._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));s({code:h.SUCCESS,data:a})}))},r.prototype.getUnreadCountByTag=function(e,t){var n=this;return new Promise((function(o,r){var s=n._callCppProxy("getConversationUnreadCountForTag",e,t);o({code:h.SUCCESS,data:s})}))},r.prototype.setConversationStatusInTag=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",n.isTop||!1,(function(){r({code:h.SUCCESS})}),(function(e){r({code:e})}))}))},r.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||""),s=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));n({code:h.SUCCESS,data:s})}))},r.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},r.prototype.getTopConversationList=function(e,t){var n=this;return new Promise((function(o){var r=D(t)?n._callCppProxy("getTopConversations",e):n._callCppProxy("getTopConversations",e,t),s=JSON.parse(r).list.map((function(e){return n._buildConversation(e.obj)}));o({code:h.SUCCESS,data:s})}))},r.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},r.prototype.getAllUnreadMentionedCount=function(){var e=this;return new Promise((function(t){var n=e._callCppProxy("getUnreadAndMentionCount",[x.GROUP],"");t({code:h.SUCCESS,data:n})}))},r.prototype.getOSInfo=function(){return fe(this,void 0,void 0,(function(){var e;return he(this,(function(t){return e={arch:o.arch(),platform:o.platform(),type:o.type(),version:o.version(),release:o.release(),uptime:o.uptime(),cpus:o.cpus(),freemem:o.freemem(),totalmem:o.totalmem(),networkInterfaces:o.networkInterfaces()},[2,{code:h.SUCCESS,data:e}]}))}))},r.prototype.getMainProcessInfo=function(){return fe(this,void 0,void 0,(function(){return he(this,(function(e){return[2,{code:h.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},r.prototype.setCallInfo=function(e,t,n){var o=this;return new Promise((function(r){o._callCppProxy("callInfoSignaling",e,t,n,(function(e,t){r({code:h.SUCCESS,data:{key:e,value:t}})}),(function(e){r({code:e})}))}))},r.prototype.setProxy=function(e){return this.tcpMgr.getConnectionStatus()!==O.DISCONNECTED?Promise.resolve({code:h.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(Fe(e,this.logger))},r.prototype.getProxy=function(){return Promise.resolve(Ve())},r.prototype.testProxy=function(e,t){return function(e,t,n){return new Promise((function(o){var r=/^https/.test(t)?je:De;n.info(g.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:e,testHost:t}));var s=r(t,e,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var n="";e.on("data",(function(e){n+=e})),e.once("end",(function(){o({status:t||0,data:n})}))}));s.once("timeout",(function(){return o({status:0})})),s.once("error",(function(e){return o({status:0,data:e.stack})})),s.end()}))}(e,t,this.logger)},r.prototype.checkDuplicateMessage=function(e){var t=this;return new Promise((function(n){t._callCppProxy("checkDuplicateMessage",e),n({code:h.SUCCESS})}))},r.prototype.initAndOpenDatabase=function(e){var t=this;return new Promise((function(n){t._callCppProxy("initAndOpenDatabase",e),n({code:h.SUCCESS})}))},r.prototype.closeDatabase=function(){var e=this;return new Promise((function(t){e._callCppProxy("closeDatabase"),t({code:h.SUCCESS})}))},r.prototype.getMessagesByObjectNamesAcrossConversations=function(e,t,n,o,r,s,i,a){var c=0===s,u=i+1,p=this._callCppProxy("getMessagesByObjectNamesAcrossConversations",a,e,t,n,o,r,c,u),l=[];try{var d=JSON.parse(p).list;d.reverse();for(var f=0;f<d.length;f++){var C=this._buildMessage(d[f].obj);l[f]=C}}catch(e){return Promise.resolve({code:h.MAIN_PROCESS_ERROR})}return Promise.resolve({code:h.SUCCESS,data:{list:u===l.length?l.slice(1,u):l,hasMore:i<l.length}})},r.prototype.getReadReceiptUsers=function(e,t){var n=this;return new Promise((function(o){var r=n._callCppProxy("getReadReceiptUsersByUid",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t,r){var s,i;try{var a=JSON.parse(t).list,c=JSON.parse(r).list;s=a.map((function(e){return JSON.parse(e.obj)})),i=c.map((function(e){return JSON.parse(e.obj)})),o({code:e,data:{userInfoRead:s,userInfoUnread:i}})}catch(e){n.logger.error(le.P_PARSE_JSON_MSGS_E,t,r),o({code:h.MAIN_PROCESS_ERROR})}}));r!==h.SUCCESS&&o({code:r})}))},r.prototype.getMessageReadReceiptInfos=function(e,t){var n=this;return new Promise((function(o){var r=n._callCppProxy("getReadReceiptCount",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t){try{var r=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));o({code:e,data:r})}catch(e){n.logger.error(le.P_PARSE_JSON_MSGS_E,t),o({code:h.MAIN_PROCESS_ERROR})}}));r!==h.SUCCESS&&o({code:r})}))},r}(),at=function(){function e(e,t,n,o,r){void 0===n&&(n=""),this._cppService=new it(e,t,n,o,r)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._cppService.destroy()},e.prototype.getDeviceId=function(){return this._cppService.getDeviceId()},e.prototype.getServerTime=function(){return this._cppService.getServerTime()},e.prototype.__createLogger=function(e,t){return null},e}(),ct=function(n){return function(e,t,n){if(ot)return ot;if(!t)throw new Error("Initializ failed, `appkey` is required!");return ot=new at(t,e,null==n?void 0:n.dbpath,null==n?void 0:n.logOutputLevel,null==n?void 0:n.httpRequestProxy)}(ce(n.dbpath||e(t.getPath("userData"))),n.appkey,n)};export{ct as default};
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("path"),t=require("electron"),o=require("os"),r=require("fs"),n=require("@rongcloud/engine"),s=require("child_process"),i=require("http"),a=require("https"),c=require("url"),u=require("net"),p=require("events"),d=require("tls"),l=require("crypto");function C(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var f=C(o),h=process.versions.electron.replace(/\.\d+$/,""),g=e.resolve(__dirname,"binding","electron-v".concat(h,"-").concat(o.platform(),"-").concat(o.arch(),".node")),v=function(t,o){try{r.existsSync(e.resolve(t,"RongCloud"))||r.mkdirSync(e.resolve(t,"RongCloud"));var n=e.resolve(t,"RongCloud/addon-load-error.txt");r.writeFileSync(n,o.toString())}catch(e){console.error(e)}},_=function(e,t){return _=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},_(e,t)};function S(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}_(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var y,E=function(){return E=Object.assign||function(e){for(var t,o=1,r=arguments.length;o<r;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},E.apply(this,arguments)};function m(e,t,o,r){return new(o||(o=Promise))((function(n,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))}function P(e,t){var o,r,n,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(o=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){s.label=a[1];break}if(6===a[0]&&s.label<n[1]){s.label=n[1],n=a;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(a);break}n[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{o=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function T(e,t,o){if(o||2===arguments.length)for(var r,n=0,s=t.length;n<s;n++)!r&&n in t||(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_DB_OP_E="P-db_op-E",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_E="P-connect-E",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_R="P-connect-R",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_E="P-parse_json-E",e.P_SEARCH_CONVERSATIONS_T="P-search_conversations-T",e.P_SEARCH_CONVERSATIONS_R="P-search_conversations-R",e.L_FORMAT_CONVERSATIONS_S="L-format_conversations-S",e.L_JS_GET_NOW_TIME_S="L-js_get_now_time-S",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R"}(y||(y={}));var I,R={flushTimestamp:Date.now(),queue:[],locked:!1};function N(){I&&clearInterval(I)}function O(e,t){N(),I=setInterval((function(){return w(e,t)}),1e4)}function M(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=R.queue).push.apply(e,t)}var U=200;function w(e,t){var o=R.queue,r=R.flushTimestamp;if(!(R.locked||0===o.length||Date.now()-r<3e4&&o.length<U)){R.locked=!0;var n=t.createTraceId(),s=o.splice(0,U).map((function(e){var t=e.sessionId,o=e.level,r=e.time,n=e.type,s=e.tag,i=e.loggerId,a=e.content,c=e.traceId;return{level:o,time:r,type:n,tag:s,content:encodeURIComponent(JSON.stringify({loggerId:i,sessionId:t,content:a,traceId:c})).replace(/'/g,"%27")}}));t.debug(y.P_WRITE_LOG_T,"writingLen: ".concat(s.length,", queueLen: ").concat(o.length),n);var i=JSON.stringify(s);e.writeLog(i),t.debug(y.P_WRITE_LOG_R,"write done, queueLen: ".concat(o.length),n),R.flushTimestamp=Date.now(),R.locked=!1,setTimeout((function(){return w(e,t)}))}}var b=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return S(t,e),t.prototype.flush=function(e){M(e)},t}(n.BasicLogger),x=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return S(t,e),t.prototype.flush=function(e){M(e)},t}(n.BasicStatistic),A=function(e,t){var o,r=Buffer.from(e),n=r.length;for(t.push(n),o=0;o<n;o++)t.push(r[o])},L=function(e){return"string"==typeof e},D=function(e){return L(e)?e.toUpperCase():""},k=function(e,t){var o="";return 2!==e.length?o="Unexpected number of bytes received.":5!==e[0]?o="Unexpected SOCKS version number: ".concat(e[0],"."):255===e[1]?o="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(o="Unexpected SOCKS authentication method: ".concat(e[1],".")),o},J=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: ".concat(e[0],"."):0!==e[1]&&(t="Username and password authentication failure: ".concat(e[1],".")),t},j=function(e){var t=D(e.method)||"GET",o=e.pathname||"/",r=e.headers||{},n=e.search||"";r.Host=e.host||"loclahost";var s="";for(var i in s="".concat(t," ").concat(o+n," HTTP/1.1\n"),r)if(Object.hasOwnProperty.call(r,i)){var a=r[i];s+="".concat(i,": ").concat(a,"\n")}return e.body&&(s+="Content-Length: ".concat(e.body.length,"\n")),s+="\n","POST"===t&&e.body&&(s+="".concat(e.body)),s},B=function(e){return new Promise((function(t){var o,r;e.socket.once("data",(function(r){var n,s=k(r,o);if(!s)return 2===r[1]?(e.socket.once("data",(function(o){var r=J(o);r?e.emit("error",new Error("SOCKS authentication failed. ".concat(r))):t()})),n=[1],A(e.socksUsername,n),A(e.socksPassword,n),void e.write(Buffer.from(n))):void t();e.emit("error",new Error("SOCKS authentication failed. ".concat(s)))})),o=[0],e.socksUsername&&o.push(2),(r=Buffer.alloc(2+o.length))[0]=5,r[1]=o.length,o.forEach((function(e,t){r[2+t]=e})),e.write(r)}))},F=function(e,t,o){return new Promise((function(r){var n,s;switch(e.socket.once("data",(function(t){var o;5!==t[0]?o="Unexpected SOCKS version number: ".concat(t[0],"."):0!==t[1]?o="".concat(function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code ".concat(e)}}(t[1]),"."):0!==t[2]&&(o="The reserved byte must be 0x00."),o?e.emit("error",new Error("SOCKS connection failed. ".concat(o))):r()})),(n=[]).push(5),n.push(1),n.push(0),u.isIP(t)){case 0:n.push(3),A(t,n);break;case 4:n.push(1),function(e,t){var o,r,n=e.split(".");for(o=0;o<4;o++)r=parseInt(n[o],10),t.push(r)}(t,n);break;case 6:e.emit("error",new Error("Does not support IPV6"))}n.length+=2,(s=Buffer.from(n)).writeUInt16BE(o,s.length-2),e.write(s)}))},H=function(e){function t(t){var o=e.call(this)||this;return o.readable=!0,o.socket=new u.Socket,o.options=t,o.socksHost=t.socksHost||"localhost",o.socksPort=t.socksPort||1080,o.socksUsername=t.socksUsername||"",o.socksPassword=t.socksPassword||"",o.socket.on("error",(function(e){o.emit("error",e)})),o.on("error",(function(){o.socket.destroyed||o.socket.destroy()})),o.on("end",o.end),o}return S(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var o=this.socket.end(e,t);return this.writable=this.socket.writable,o},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,o){return this.socket.write(e,t,o)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var o=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: ".concat(e));if(!t||"string"!=typeof t)throw new TypeError("Invalid host: ".concat(t));return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return m(o,void 0,void 0,(function(){var o;return P(this,(function(r){switch(r.label){case 0:return[4,B(this)];case 1:return r.sent(),[4,F(this,t,e)];case 2:return r.sent(),this.onProxied(),o=j(this.options),this.socket.write(Buffer.from(o)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(p.EventEmitter),V=function(e){var t,o=e.hostname,r=e.port;return!e.host||o&&r||(t=e.host.split(":")),!r&&t&&(r=parseInt(t[1],10)||0),!o&&t&&(o=t[0]),new H(e).connect(r,o)},q=function(e){function t(t){var o=e.call(this)||this;return o.createConnection=V,o}return S(t,e),t}(i.Agent),G=function(e,t,o){return(t=E(E({},t),c.parse(e))).port||(t.port=80),t.agent=new q(t),i.request(t,o)},K=function(e){var t,o;return t=V(e),o=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=d.connect(e,(function(){t.authorized=t.socket.authorized,o.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},W=function(e){function t(t,o){var r=e.call(this,o)||this;return r.url=t,r.socksHost=o.socksHost||"localhost",r.socksPort=o.socksPort||1080,r.createConnection=K,r}return S(t,e),t}(a.Agent),Q=function(e,t,o,r){var n,s;return t.protocol="https:",!t.port&&t.host&&(n=t.host.split(":"),t.port=n[0],t.port=n[1]),t.port||(t.port=443),s=new W(e,t),t.agent=s,a.request(e,t,o)},Y=null;function X(e,t,o){void 0===o&&(o=!1);var r=t.url,s=t.headers,c=t.body,u=t.method,p=t.query,d=t.timeout,l=void 0===d?n.HTTP_TIMEOUT:d;return new Promise((function(t){var d=/^https/.test(r),C={headers:s,method:u};d&&(C.rejectUnauthorized=o);var f=null;Y?((C=E(E({},C),Y)).body=c,f=d?Q:G):(f=i.request,d&&(C.agent=new a.Agent(C),f=a.request));var h=f(n.appendUrl(r,p),C,(function(e){var o=e.statusCode,r="";e.setEncoding("utf8"),e.on("data",(function(e){r+=e})),e.once("end",(function(){t({status:o||0,data:r})}))}));h.once("timeout",(function(){e.warn(y.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:r,method:u,query:p,timeout:l})),t({status:0})})),h.setTimeout(l),h.once("error",(function(o){e.warn(y.P_HTTP_REQ_E,JSON.stringify({msg:o.stack,url:r,method:u,query:p,timeout:l})),t({status:0})})),h.write(c),h.end()}))}function z(e,t){return e?(Y=E(E({},Y),e),t.info(n.LogTagId.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:Y})),{code:n.ErrorCode.SUCCESS}):(Y=null,t.info(n.LogTagId.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:n.ErrorCode.SUCCESS})}function $(){var e=Y||void 0;return{code:n.ErrorCode.SUCCESS,data:e}}var Z,ee=[],te=!1,oe=function(){return m(void 0,void 0,void 0,(function(){var e,t,o,r,s,i,a,c,u,p,d;return P(this,(function(l){return te||0===ee.length||(te=!0,e=ee.shift(),t=e.args,o=e.resolve,r=t.addon,s=t.startTime,i=t.endTime,a=t.level,c=t.realtimeReport,u=0,p=0,d=[],r.setLogEventListener((function(e){u+=e.length;var t=e.split(","),r=t[0],s=t[1],i=t[2],l=t[3],C=t[4],f=t.slice(5);if(u>n.REAT_TIME_LOG_SIZE&&parseInt(s,10)!==p)o(d);else{p=parseInt(s,10);try{var h=JSON.parse(decodeURIComponent(f.join(","))),g=h.loggerId,v=h.sessionId,_=h.content,S=h.traceId;if(!c&&a<0)return;var y={time:parseInt(s,10),level:parseInt(l,10),sessionId:"".concat(r,":").concat(v),type:i,tag:C,loggerId:g,content:_,traceId:S};d.push(y)}catch(e){console.error(e)}}}),(function(e){o(d),te=!1,oe()}),(function(e,t,o){})),r.pullFullLog(a,s,i,!1)),[2]}))}))},re=function(e){function t(t,o,r,s,i){var a=this,c=process.versions.electron,u="Electron|".concat(c,"|").concat(process.arch,"|").concat(process.platform);return(a=e.call(this,o,r,u,{getLogs:function(e,o,r,n){return m(this,void 0,void 0,(function(){return P(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:o,level:r,realtimeReport:n,addon:t},m(void 0,void 0,void 0,(function(){return P(this,(function(e){return[2,new Promise((function(e){ee.push({resolve:e,args:i}),oe()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var e=t.getStoreValue(n.StoreKeys.REALTIME_LOG_TIMESTAMP);return parseInt(e,10)||0},setTimestamp4RealtimeLog:function(e){t.setStoreValue(n.StoreKeys.REALTIME_LOG_TIMESTAMP,e.toString())}},s)||this).subProcess=i,a}return S(t,e),t.prototype.send=function(e){return X(this.logger,e)},t.prototype.compressLogs=function(e){return m(this,void 0,void 0,(function(){var t,o,r;return P(this,(function(n){switch(n.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=n.sent(),o=t.success,r=t.data,o?[2,{success:o,data:r}]:[2,{success:o,data:""}]}}))}))},t}(n.BasicReporter),ne=null,se=function(){var e,t=Date.now(),r=[o.arch(),o.platform(),process.pid,t,Math.floor(Math.random()*t)].join("__");return e=r,l.createHash("md5").update(e).digest("hex")},ie=function(t){if(ne)return ne;var o=e.resolve(t,"deviceId");return r.existsSync(o)?ne=r.readFileSync(o).toString():(ne=se(),r.writeFileSync(o,ne),ne)},ae=function(){function e(e){this._cppProto=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,o,r,n,s){var i=JSON.stringify(n);"{}"!==i&&e.info(y.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:r,ext:n})),this._cppProto.setMessageExtension(t,o,r,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime;if(i&&0!==Object.keys(i).length){var c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,r,n,s,c,o||"")}},e.prototype.setLocalFromExtMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._cppProto.getMessage(a.mid),p=JSON.parse(u).extMsg,d=JSON.parse(p||"{}");if(c)for(var l in c){var C=d[l];C&&C.ts<i-this._setTime?(C.v=c[l],C.ts=i-this._setTime):(d[l]={v:"",ts:0},d[l].v=c[l],d[l].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete d[e]})),this._setToProtocol(e,r,n,a.mid,d,o||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),o={};for(var r in t)o[r]=t[r].v;return o},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),o=JSON.parse(t||"{}"),r={};for(var n in o)r[n]=o[n].v;return r},e}(),ce=function(){function e(e){var t=this;this.p=e,this.count=0,this.maps={},this.p.on("message",(function(e){var o=e.reqId,r=e.success,n=e.data,s=t.maps[o];s&&(s({success:r,data:n}),delete t.maps[o])}))}return e.prototype.call=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return m(this,void 0,void 0,(function(){var o=this;return P(this,(function(r){return this.p.killed?[2,{success:!1}]:[2,new Promise((function(r){var n=++o.count;o.maps[n]=r;var s={reqId:n,method:e,args:t};o.p.send(s)}))]}))}))},e.prototype.destroy=function(){this.p.kill()},e}();!function(e){e[e.RMTP=1]="RMTP",e[e.TLS=2]="TLS",e[e.RPP=3]="RPP",e[e.QUIC=4]="QUIC",e[e.WS=5]="WS",e[e.WSS=6]="WSS",e[e.HTTP=11]="HTTP",e[e.HTTPS=12]="HTTPS"}(Z||(Z={}));var ue,pe=[Z.RMTP,Z.TLS,Z.QUIC],de=function(e){function t(t,o,r,n,s,i){var a=e.call(this,t,o,r)||this;return a.addon=s,a.httpRequestProxy=i,a.naviPath="",a._caches={},a.naviPath="".concat(n,"/navi-cache.json"),a}return S(t,e),t.prototype.httpRequest=function(e,t,o,r){return m(this,void 0,void 0,(function(){var s,i,a,c,u,p,d,l,C=this;return P(this,(function(f){switch(f.label){case 0:s="token=".concat(encodeURIComponent(o),"&v=").concat(n.FORMATED_VERSION,"&p=PC&ev=").concat("5.8.2-enterprise-lz.28"),i="".concat(e,"/navi.json?r=").concat(Date.now(),"&env=").concat(this._environment),this.logger.info(n.LogTagId.L_REQUEST_T,JSON.stringify({url:i,body:s}),r),u=function(){c&&(clearTimeout(c),c=null)},f.label=1;case 1:return f.trys.push([1,3,,4]),[4,new Promise((function(e){c=setTimeout((function(){C.logger.warn(n.LogTagId.L_REQUEST_E,JSON.stringify({url:i,body:s,info:"http response timeout"}),r),e({status:0})}),n.NAVI_REQ_TIMEOUT+5e3),C.httpRequestProxy?C.httpRequestProxy({url:i,method:"POST",headers:{appId:t},body:s,timeout:n.NAVI_REQ_TIMEOUT}).then((function(t){u(),e(t)})).catch((function(t){C.logger.error(n.LogTagId.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),r),u(),e({status:0})})):X(C.logger,{method:"POST",headers:{appId:t},body:s,url:i,timeout:n.NAVI_REQ_TIMEOUT}).then((function(t){u(),e(t)})).catch((function(t){C.logger.error(n.LogTagId.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),r),u(),e({status:0})}))}))];case 2:return a=f.sent(),[3,4];case 3:return p=f.sent(),this.logger.error(n.LogTagId.L_REQUEST_E,JSON.stringify({stack:null==p?void 0:p.stack,info:"Code execution error"}),r),u(),[2,{code:n.ErrorCode.RC_NAVI_REQ_FAILED}];case 4:if(200!==a.status)return this.logger.warn(n.LogTagId.L_REQUEST_R,JSON.stringify({url:i,code:a.status}),r),[2,{code:this.transHttpCode(a.status)}];try{return d=JSON.parse(a.data),l=/^https/.test(i)?"https":"http",d.protocol=l,d.code&&200!==d.code?[2,{code:this.transHttpCode(d.code)}]:[2,{code:n.ErrorCode.SUCCESS,data:d}]}catch(e){return this.logger.error(n.LogTagId.L_PARSE_NAVI_E,a.data,r),[2,{code:n.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.httpRequestV2=function(e,t,o,r){return m(this,void 0,void 0,(function(){var s,i,a,c;return P(this,(function(u){switch(u.label){case 0:return s=this.getNaviV2RequestOption({appkey:t,token:o,uri:e,platform:"electron",protocol:pe.join(",")}),this.logger.debug(n.LogTagId.L_REQUEST_T,JSON.stringify({url:s.url,body:s.body,headers:s.headers}),r),[4,X(this.logger,s)];case 1:if(200!==(i=u.sent()).status)return this.logger.warn(n.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,code:i.status}),r),[2,{code:this.transHttpCode(i.status)}];try{return a=JSON.parse(i.data),c=/^https/.test(s.url)?"https":"http",a.protocol=c,[2,{code:n.ErrorCode.SUCCESS,data:a}]}catch(e){return this.logger.error(n.LogTagId.L_PARSE_NAVI_E,i.data,r),[2,{code:n.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.getNaviCache=function(e){var t=this.getCatchKey(e),o=this._caches[t];if(o)return o;if(!r.existsSync(this.naviPath))return null;var s=r.readFileSync(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(s),this._caches[t]}catch(e){this.logger.error(n.LogTagId.L_PARSE_NAVI_E,s)}return null},t.prototype.setNaviCache=function(e,t){var o=Date.now(),s=this.getCatchKey(e);if(n.notEmptyObject(this._caches))for(var i in this._caches){(o-this._caches[i].timestamp>n.NAVI_CACHE_DURATION||s===i)&&delete this._caches[i]}this._caches[s]={token:e,naviInfo:t,timestamp:Date.now(),environment:this._environment},r.writeFileSync(this.naviPath,JSON.stringify(this._caches))},t.prototype.setEnvironment=function(e){this._environment=e},t}(n.BasicNavi);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(ue||(ue={}));var le,Ce=function(e){function t(t,o,r,s,i,a){var c=e.call(this,t,r,s,i,a)||this;return c.addon=o,c._listener=a,c._connectedTime=0,c._naviInfo=null,c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.addon.setConnectionStatusListener(c._onConnectComplete.bind(c),(function(e){c.logger.info(y.P_DB_OPEN_O,e)}),(function(){return c.recvPong(n.ErrorCode.SUCCESS)}),c._onAddonDisconnected.bind(c),c._onTcpConnectResponse.bind(c),(function(e){c.logger.error(y.P_DB_OP_E,"Database operation failed with code: ".concat(e)),c._listener.onDatabaseOperationFailed(e)})),c}return S(t,e),t.prototype.getConnectedTime=function(){return this._connectedTime},t.prototype.connectWithToken=function(e,t,o,r){var s=this;return new Promise((function(i){s._naviInfo=t,s.connectResolve={resolve:i,traceId:r,userId:t.userId};var a={},c=$().data;c&&(a={proxy_passwd:c.socksPassword||"",proxy_name:c.socksUsername||"",proxy_port:c.socksPort||1082,proxy_host:c.socksHost||"localhost",proxy_type:0});var u=JSON.stringify(E(E({},a),{call_plus:s._openCallPlus})),p=s.getCmpList(t,!0).filter((function(e){return pe.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];p.forEach((function(e){var t=d.find((function(t){return t.addr===e.addr}));t?t.protocol!==Z.QUIC&&e.protocol!==Z.QUIC||(t.race=!0,t.protocol=Z.QUIC):(e.race=!1,d.push(e))}));var l=E(E({},t),{serverAddr:d});s.logger.info(y.P_CONNECT_T,JSON.stringify({use:d,catche:s.cmpWeightCache,proxy:a,FORMATED_VERSION:n.FORMATED_VERSION,reconnectKickEnable:o,naviInfo:l}),r),s._startTime=Date.now();try{s.addon.connectWithToken(e,n.FORMATED_VERSION,JSON.stringify(l),o,u)}catch(e){s.logger.error(y.P_CALL_ADDON_E,null==e?void 0:e.stack,r),s._onConnectComplete(n.ErrorCode.RC_SOCKET_NOT_CREATED)}}))},t.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.addon.disconnect(t)},t.prototype.sendPing=function(e){var t=this;return new Promise((function(o){t.pingResolve=o,t.addon.sendHeartbeat(),setTimeout((function(){return t.recvPong(n.ErrorCode.TIMEOUT)}),e)}))},t.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},t.prototype._onConnectComplete=function(e){if(this.connectResolve&&10!==e){var t=this.connectResolve,o=t.resolve,r=t.userId,s=t.traceId;this.logger.info(y.P_CONNECT_R,JSON.stringify({code:e,userId:r}),s);var i=Date.now()-(this._startTime+this._tcpDuration),a={bid:n.getbundleId(),cod:e,net:this.getNetwork().type,dur:i,spr:1,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:n.StatisticsVersion.CURRENT,count:this.retryCount};this.statisticLog.__statistics(n.StatisticsTag.IM_CMP_RMTP,JSON.stringify(a)),e===n.ErrorCode.SUCCESS&&(this._connectedTime=Date.now()-this.addon.getDeltaTime()),o({code:e,data:r}),this.connectResolve=null}},t.prototype._onAddonDisconnected=function(e,t){switch(this.logger.info(y.P_CONNECT_S,JSON.stringify({code:e,delay:t})),e){case n.ErrorCode.RC_CONN_REDIRECTED:this._handleDisconnected(n.ErrorCode.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case n.ErrorCode.CONNECTION_REFUSED:case n.ErrorCode.RC_SOCKET_DISCONNECTED:case n.ErrorCode.RC_SOCKET_NOT_CREATED:case n.ErrorCode.RC_CONN_ACK_TIMEOUT:case n.ErrorCode.RC_TCP_RESET:this._handleDisconnected(e,!1);break;case n.ErrorCode.RC_UDP_DISCONNECTED:this._handleDisconnected(e,!0,t);break;default:this._handleDisconnected(e,!0)}},t.prototype._handleDisconnected=function(e,t,o){if(t)this.onDisconnectByServer(e,o);else{if(e===n.ErrorCode.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==n.RCConnectionStatus.CONNECTED)return;this.onDisconenctUnusual(e)}},t.prototype._onTcpConnectResponse=function(e,t,o,r,s,i,a){var c,u=this.cmpWeightCache.findIndex((function(e){return e.addr==="".concat(t,":").concat(o)})),p={bid:n.getbundleId(),ptc:n.ProtocalType.TCP,cod:e,net:this.getNetwork().type,dur:r,spr:1,pr:(null===(c=this._naviInfo)||void 0===c?void 0:c.type)||0,hos:"".concat(t,":").concat(o),idx:u,rct:this.retryCount?n.ConnectType.RECONNECT:n.ConnectType.CONNECT,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:n.StatisticsVersion.CURRENT,rsn:this.reason,ddu:s,count:this.retryCount,weight:this.cmpWeightCache[u].weight};this.statisticLog.__statistics(n.StatisticsTag.IM_CMP,JSON.stringify(p)),this.logger.info(y.P_CONNECT_ENTRY_S,JSON.stringify({code:e,host:t,port:o,duration:r,dnsDuration:s,index:i,isQuic:a})),e===ue.SUCCESS&&(this.curCmpUrl="".concat(t,":").concat(o),this.updateCmpWeight("".concat(t,":").concat(o),!0,a))},t}(n.AConnectionMgr),fe=function(t){if(!r.existsSync(t)){var o=e.resolve(t,"..");r.existsSync(o)||fe(o),r.mkdirSync(t)}},he=function(){function o(o,r,i,a,c){var u=this;this._appkey=o,this._cppProtocol=r,this._dbpath=i,this._logOutputLevel=a,this._httpRequestProxy=c,this._customMessageType={},this._senders={},this._chatroomCache=[],this.rtcHeartbeatResolves={};var p=this._dbpath||e.resolve(t.app.getPath("userData")),d=ie(p);this._cppProtocol.initWithAppkey(o,p,n.FORMATED_VERSION);var l=s.fork(e.resolve(__dirname,"sub-process.js"));this.subProxy=new ce(l);var C=e.resolve(p,"RongCloud/rclogs",o);fe(C),function(e,t,o){o.initLogModule(t,e,n.getUUID())}(o,C,this._cppProtocol),this.logger=new b(this._appkey,"RC-M","IM"),this.statisticLog=new x(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),O(this._cppProtocol,this.logger),this.reporter=new re(this._cppProtocol,o,d,this.logger,this.subProxy),this.logger.info(y.P_INIT_O,JSON.stringify({appkey:o,dbpath:p,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:d,commit:"cf68cd3cffddd652296b7952f5bf603ee9470f11"})),this._callCppProxy("setDeviceId",d);var f=e.resolve(p,"RongCloud/navis",o);fe(f),this.navi=new de(o,this.logger,this.statisticLog,f,this._cppProtocol,this._httpRequestProxy),this.tcpMgr=new Ce(o,this._cppProtocol,this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this),onDatabaseOperationFailed:function(e){u._send2AllRenderer("onDatabaseOperationFailed",e)}}),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setReadReceiptListener(),t.ipcMain.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];return m(u,void 0,void 0,(function(){var r,s,i;return P(this,(function(a){switch(a.label){case 0:if("function"!=typeof(r=this[t]))return this.logger.error(y.P_CALL_MAIN_SYNC_E,JSON.stringify({method:t,error:"not found"})),e.returnValue=n.ErrorCode.NOT_SUPPORT,[2];s=n.ErrorCode.EXTRA_METHOD_UNDEFINED,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,r.call.apply(r,T([this],o,!1))];case 2:return s=a.sent(),[3,4];case 3:return i=a.sent(),this.logger.error(y.P_CALL_MAIN_SYNC_E,JSON.stringify({error:null==i?void 0:i.stack,method:t})),[3,4];case 4:return e.returnValue=s,[2]}}))}))})),t.ipcMain.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,o){for(var r=[],s=3;s<arguments.length;s++)r[s-3]=arguments[s];return m(u,void 0,void 0,(function(){var s,i,a,c,u=this;return P(this,(function(p){switch(p.label){case 0:if("function"!=typeof(s=this[o]))return this.logger.error(y.P_CALL_MAIN_E,JSON.stringify({method:o,error:"not found"})),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,n.ErrorCode.NOT_SUPPORT),[2];"sendMessage"===o&&(i=r[3],r[3]=function(t){u._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",i,t)}),a=n.ErrorCode.EXTRA_METHOD_UNDEFINED,p.label=1;case 1:return p.trys.push([1,3,,4]),[4,s.call.apply(s,T([this],r,!1))];case 2:return a=p.sent(),[3,4];case 3:return c=p.sent(),this.logger.error(y.P_CALL_MAIN_E,JSON.stringify({error:null==c?void 0:c.stack,method:o})),[3,4];case 4:return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,a),[2]}}))}))})),t.ipcMain.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];var n=u[t];if("function"==typeof n)try{n.call.apply(n,T([u],o,!1))}catch(e){u.logger.error(y.P_SEND_2_MAIN_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}else u.logger.error(y.P_SEND_2_MAIN_E,JSON.stringify({method:t,error:"not found"}))})),t.ipcMain.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this)),this._msgExpansionHandler=new ae(this._cppProtocol)}return o.prototype.onConnected=function(){var e=this.getNaviInfoFromCache();this.reporter.checkStart(e),this._try2RejoinChatroom(),this._send2AllRenderer("onConnected",this.getMainProcessCache())},o.prototype.onConnecting=function(){this._send2AllRenderer("onConnecting",void 0)},o.prototype.onSuspend=function(e){this._send2AllRenderer("onSuspend",e)},o.prototype.onDisconnected=function(e){this._send2AllRenderer("onDisconnected",e)},o.prototype._callCppProxy=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this.logger.createTraceId();try{return this.logger.info(y.P_CALL_ADDON_O,JSON.stringify({method:e,args:o}),n),(t=this._cppProtocol)[e].apply(t,o)}catch(t){this.logger.error(y.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),n)}},o.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},o.prototype.sendHTTPRequest=function(e){return X(this.logger,e)},o.prototype.onRendererLogsReceived=function(e){M.apply(void 0,e)},o.prototype.onRendererNetworkStatusReceived=function(e,t){this.tcpMgr.setNetwork(e,t)},o.prototype.destroy=function(){var e;this.reporter.stop(),this.subProxy.destroy(),e=this._cppProtocol,N(),e.deinitLogModule(),this._cppProtocol.destroy()},o.prototype.callExtra=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];var r=this[e];if(!r)return this.logger.warn(y.P_CALL_EXTRA_E,JSON.stringify({method:e,error:"not found"})),Promise.resolve({code:n.ErrorCode.EXTRA_METHOD_UNDEFINED});try{return r.call.apply(r,T([this],t,!1))}catch(t){this.logger.error(y.P_CALL_EXTRA_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})},o.prototype.getConversationsByPage=function(e,t,o,r,s){var i,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",e,t,o,s||!1,r||"");try{i=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:i})},o.prototype.getUnreadConversationList=function(e){var t,o=this,r=this._callCppProxy("getUnreadConversationList",e);try{t=JSON.parse(r).list.map((function(e){return o._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:t})},o.prototype.getConversationListWithAllChannel=function(){var e,t=this,o=[n.ConversationType.PRIVATE,n.ConversationType.GROUP,n.ConversationType.SYSTEM,n.ConversationType.APP_PUBLIC_SERVICE,n.ConversationType.PUBLIC_SERVICE],r=this._callCppProxy("getConversationListWithAllChannel",o);try{e=JSON.parse(r).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:e})},o.prototype.getConversationListWithAllChannelByPage=function(e,t){var o,r=this,s=[n.ConversationType.PRIVATE,n.ConversationType.GROUP,n.ConversationType.SYSTEM,n.ConversationType.APP_PUBLIC_SERVICE,n.ConversationType.PUBLIC_SERVICE],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,e,t);try{o=JSON.parse(i).list.map((function(e){return r._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:o})},o.prototype.getHistoryMessagesByObjectNames=function(e,t,o,r,s,i,a){var c=0===i,u=r+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,o,u,s,c,a||""),d=[];try{var l=JSON.parse(p).list;l.reverse();for(var C=0;C<l.length;C++){var f=this._buildMessage(l[C].obj);d[C]=f}}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:{list:u===d.length?d.slice(1,u):d,hasMore:r<d.length}})},o.prototype.updateMessageReceiptStatus=function(e,t,o,r){void 0===r&&(r="");var s=this._callCppProxy("updateMessageReceiptStatus",e,t,o,r);return Promise.resolve({code:n.ErrorCode.SUCCESS,data:s})},o.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==n.RCConnectionStatus.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},o.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new b(this._appkey,e,t)},o.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},o.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},o.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},o.prototype._send2Renderer=function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,T([t],o,!1))},o.prototype._send2AllRenderer=function(e,t,o){var r=this;void 0===o&&(o=[]),Object.keys(this._senders).forEach((function(n){var s=r._senders[n];o.includes(s)||r._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},o.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),o=this.getNaviInfoFromCache(),r=this.tcpMgr.getCurrentUserId();return{connectedTime:e,deviceId:this.getDeviceId(),crtUserId:r,naviInfo:o,connectionStatus:t}},o.prototype._registerRenderers=function(e,t){var o=this,r=e.sender,s=r.id,i=t.navigators,a=t.areaCode,c=t.logServerUrl,u=t.environment;this._environment=u||"default",this.navi.setEnvironment(u),n.urlCenter.init({areaCode:a,navigators:i,logServerUrl:c}),this._senders[s]||(this._senders[s]=r,r.once("destroyed",(function(){delete o._senders[s]})))},o.prototype._registerMsgTypes=function(){for(var e in n.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},n.SEND_MESSAGE_TYPE_OPTION){var t=n.SEND_MESSAGE_TYPE_OPTION[e],o=t.isCounted,r=t.isPersited,s=t.searchProps,i=0;r&&(i|=1),o&&(i|=2),"RC:TypSts"===e&&(i=16),this._callCppProxy("registerMessageType",e,i,s||[])}},o.prototype._buildIsMentioned=function(e,t){var o,r=!1;if(n.isObject(e))o=e;else try{o=e?JSON.parse(e):e}catch(r){o=e,this.logger.error(y.P_PARSE_JSON_MSGS_E,JSON.stringify({messageId:t}))}return n.isObject(o)&&(r=!!o.mentionedInfo),{isMentioned:r,msgContent:o}},o.prototype._buildMsgOption=function(e){var t={isCounted:!1,isPersited:!1};return e in n.SEND_MESSAGE_TYPE_OPTION?t=n.SEND_MESSAGE_TYPE_OPTION[e]:e in this._customMessageType&&(t=this._customMessageType[e]),t},o.prototype._buildSupportExt=function(e,t){var o=null;return e&&(o=this._msgExpansionHandler.parseReceiveExpansion(t)),o},o.prototype._transICppMessage2IReceivedMessage=function(e,t){var o=e.channelId,r=e.conversationType,s=e.targetId,i=e.senderUserId,a=e.content,c=e.objectName,u=e.messageUid,p=e.direction,d=e.status,l=e.messageId,C=e.sentTime,f=e.readReceiptRequest,h=e.supportExt,g=e.pushContent,v=e.pushTitle,_=e.pushId,S=e.pushConfig,y=e.templateId,m=e.disableTitle,P=e.forcePushDetail,T=e.needReceipt,I=e.sendReceipt,R=this._buildIsMentioned(a,l),N=R.isMentioned,O=R.msgContent,M=this._buildMsgOption(c),U=this._buildSupportExt(h,e),w=n.isUndefined(t)?C<this.tcpMgr.getConnectedTime():t,b={};S&&(b=n.pushJSONToConfigs(this.logger,S,_));var x=E(E({},b),{pushTitle:v,pushContent:g,pushData:g,disablePushTitle:m,forceShowDetailContent:P,templateId:y}),A={channelId:o,conversationType:r,targetId:s,senderUserId:i,content:O||{},messageType:c,messageUId:u||"",messageDirection:p,isOffLineMessage:w,sentTime:C,receivedTime:0,isPersited:M.isPersited,isCounted:M.isCounted,isMentioned:N,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:h,expansion:h?U:null,receivedStatus:d,messageId:l,pushConfig:x,needReceipt:T,sentReceipt:I};p===n.MessageDirection.RECEIVE?A.receivedStatus=d:p===n.MessageDirection.SEND&&(A.sentStatus=d);var L=this.getNaviInfoFromCache();if(f&&1===(null==L?void 0:L.grpRRVer)){var D=JSON.parse(f),k=D.hasRespond,J=D.readerInfo,j={hasRespond:k,readCount:D.readCount,totalCount:D.totalCount},B=[];if(J)for(var F in J)B.push({userId:F,readTime:J[F]});j.readerList=B,A.readReceiptInfo=j}return A},o.prototype._buildMessage=function(e,t){void 0===t&&(t=!1);var o=JSON.parse(e);return this._transICppMessage2IReceivedMessage(o,t)},o.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),r=JSON.parse(o),n=r.readReceiptRequest?JSON.parse(r.readReceiptRequest):{},s=E(E({},n),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},o.prototype._transICppConversation2IReceivedConversation=function(e){var t=e.channelId,o=e.conversationType,r=e.targetId,s=e.unreadCount,i=e.lastestMsg,a=e.isTop,c=e.isBlocked,u=e.matchCount,p=e.hasUnreadMention,d=e.draft,l=e.conversationTime,C=c?n.NotificationStatus.OPEN:n.NotificationStatus.CLOSE;return{channelId:t,conversationType:o,targetId:r,unreadMessageCount:s,latestMessage:-1===JSON.parse(i).messageId?null:this._buildMessage(i),hasMentioned:p,mentionedInfo:null,notificationStatus:C,isTop:a,lastUnreadTime:0,matchCount:u,draft:d,operationTime:l}},o.prototype._buildConversation=function(e){var t=JSON.parse(e);return this._transICppConversation2IReceivedConversation(t)},o.prototype._convertResultList=function(e,t){var o=JSON.parse(e).list;return o=o.map((function(e){var o=JSON.parse(e.obj);return t?t(o):o}))},o.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,o,r,s){var i,a=e._buildMessage(t,r),c=a.messageType,u=a.channelId,p=void 0===u?"":u;if(c!==n.MessageType.LOG_COMMAND||"rongcloudsystem"!==a.senderUserId){if(c===n.MessageType.GROUP_READ_RECEIPT_REQUEST){var d=a.content,l=d.msgId,C=d.rrn,f=d.tmn;e._updateReadReceiptInfo(l,{readCount:C,totalCount:f})}if("RC:MsgExMsg"===c)return e._msgExpansionHandler.setLocalFromExtMsg(e.logger,a),void e._sendMessageExpansion(a);if(a.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(e.logger,a),c!==n.MessageType.SYNC_READ_STATUS||a.senderUserId===e.tcpMgr.getCurrentUserId()){(c===n.MessageType.SYNC_READ_STATUS||c===n.MessageType.READ_RECEIPT&&a.senderUserId===e.tcpMgr.getCurrentUserId())&&e._callCppProxy("clearUnreadCountByTimestamp",a.conversationType,a.targetId,a.content.lastMessageSendTime,p);var h=!0;if(0!==o||s||(h=!1),c===n.MessageType.DELIVERED)return e._callCppProxy("setMessageDeliverTime",JSON.stringify(a.content)),void e._sendMessageDelivered(a.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}})));if(c!==n.MessageType.DELIVERED_MSG){var g=a.conversationType,v=a.targetId;if(c===n.MessageType.RECALL){e.handleRecalledMessage(a);var _=e._fixRecallContentInfo(a);g=_.conversationType,v=_.targetId}e._sendMessageNotification(Object.assign(a,{hasMoreMsg:h,conversationType:g,targetId:v}))}else{var S={totalCount:a.content.tmn,list:null===(i=a.content.dl)||void 0===i?void 0:i.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};e._sendGroupMessageDeliveredStatus(S)}}}else{var y=a.content,E=y.startTime,m=y.endTime,P=y.platform,T=y.logId,I=y.uri;e.reporter.report(parseInt(E,10),parseInt(m,10),P,I,T,a.messageUId)}}),(function(){e._sendPullOfflineFinished()}))},o.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,o=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,o=e.content.targetId||o),{conversationType:t,targetId:o}},o.prototype.handleRecalledMessage=function(e,t){void 0===t&&(t=!1);var o=e.content.messageUId;if(o){var r=this._callCppProxy("getMessage",o),s=this._buildMessage(r);if(s.messageId){var i={recallTime:e.sentTime,admin:!!e.content.isAdmin,originalObjectName:s.messageType,originalMessageContent:s.content,recallActionTime:0,operatorId:e.senderUserId};t&&(i.recallActionTime=Date.now()),e.content.user&&(i.user=e.content.user),e.content.extra&&(i.extra=e.content.extra),s.messageType===n.MessageType.TextMessage&&(i.recallContent=s.content.content),e.content.isDelete?this._callCppProxy("deleteMessages",[s.messageId]):(s.receivedStatus!==n.ReceivedStatus.UNREAD&&s.receivedStatus!==n.ReceivedStatus.RETRIEVED||this.setMessageReceivedStatus(s.messageId,1),this._callCppProxy("setMessageContent",s.messageId,JSON.stringify(i),n.MessageType.RECALL_NOTIFICATION_MESSAGE))}}},o.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var o=e.channelId,r=e.content,n=r.put,s=r.del,i=r.mid,a={};n&&(a.updatedExpansion={channelId:o,messageUId:i,expansion:n}),s&&(a.deletedExpansion={channelId:o,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},o.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},o.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},o.prototype._sendMessageDelivered=function(e){this._send2AllRenderer("messageDelivered",e)},o.prototype._sendGroupMessageDeliveredStatus=function(e){this._send2AllRenderer("groupMessageDeliveredStatus",e)},o.prototype._sendChatroomStatus=function(e){this._send2AllRenderer("chatroom",e)},o.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var o=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj),o={channelId:t.channelId,conversationType:t.conversationType,targetId:t.targetId,updatedItems:{}};return t.status.forEach((function(e){var t=JSON.parse(e.item),r=t.type,s=t.value;if(1===r){var i=Number(s)||n.NotificationLevel.NOT_SET;o.updatedItems.notificationLevel={val:i,time:0},o.updatedItems.notificationStatus={val:n.transformNotificationLevel(i),time:0}}else 2===r&&(o.updatedItems.isTop={val:"1"===s,time:0})})),o}));e._send2AllRenderer("conversation",o)}),(function(t){e._send2AllRenderer("conversationTag",t)}))},o.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._send2AllRenderer("tag",t),e._getRTCProfile()}))},o.prototype._setReadReceiptListener=function(){var e=this;this._cppProtocol.setReadReceiptListener((function(t){try{var o=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId,messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));e._send2AllRenderer("messageReadReceipt",o)}catch(o){e.logger.info(y.P_PARSE_JSON_MSGS_E,t)}}))},o.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var o=this.navi.getNaviInfoFromCache(t);this._send2AllRenderer("onNaviDataChange",o)}},o.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var o=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",o)}))},o.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._sendChatroomStatus({chatroomDestroyed:t})}))},o.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){var o=[];try{JSON.parse(t).list.forEach((function(e){Object.entries(e).forEach((function(e){var t=e[0],r=e[1];o.push({key:t,value:r})}))}))}catch(t){e.logger.error(y.P_PARSE_JSON_E,null==t?void 0:t.stack)}e._send2AllRenderer("callInfo",JSON.stringify({list:o}))}))},o.prototype._updateMentionedInfo=function(e,t,o){var r,s,i;return{userIdList:(null===(r=e.mentionedInfo)||void 0===r?void 0:r.userIdList)||t,type:(null===(s=e.mentionedInfo)||void 0===s?void 0:s.type)||o||n.MentionedType.ALL,mentionedContent:(null===(i=e.mentionedInfo)||void 0===i?void 0:i.mentionedContent)||""}},o.prototype.registerMessageType=function(e,t,o,r){void 0===r&&(r=[]);var n=0;t&&(n|=1),o&&(n|=2),this._customMessageType[e]={isCounted:o,isPersited:t},this.logger.info(y.P_REGTYP_O,JSON.stringify({type:e,opt:n,search:r})),this._callCppProxy("registerMessageType",e,n,r)},o.prototype.connect=function(e,t,o,r){return this.tcpMgr.connect(e,t,o,r)},o.prototype.reportSDKInfo=function(e){var t,o,r=JSON.stringify(E(E({},e),{"electron-main":"5.8.2-enterprise-lz.28"}));this.logger.info(y.P_REPORT_VER_O,r),null===(o=(t=this._cppProtocol).uploadSDKVersion)||void 0===o||o.call(t,r)},o.prototype.disconnect=function(e){this._chatroomCache.length=0,this.reporter.stop(),z(null,this.logger),this.tcpMgr.disconnect(e)},o.prototype.logout=function(){this.disconnect()},o.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,o){t({userId:e,status:o})}));var o=e.userIds||[];o.length&&this.subscribeUserStatus(o)},o.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("subscribeUserStatus",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.setUserStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("setUserStatus",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.getUserStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("getUserStatus",e,(function(e){o({code:n.ErrorCode.SUCCESS,data:{status:e}})}),(function(e){o({code:e})}))}))},o.prototype.sendMessage=function(e,t,o,r,s){var i=this;void 0===s&&(s=this.logger.createTraceId());var a=o.messageType,c=o.content,u=o.expansion,p=o.pushConfig,d=o.isMentioned,l=o.mentionedType,C=o.mentionedUserIdList,f=void 0===C?[]:C,h=o.pushContent,g=void 0===h?"":h,v=o.pushData,_=void 0===v?"":v,S=o.directionalUserIdList,E=void 0===S?[]:S,m=o.disableNotification,P=void 0!==m&&m,T=o.canIncludeExpansion,I=void 0!==T&&T,R=o.isVoipPush,N=void 0!==R&&R,O=o.channelId,M=void 0===O?"":O,U=o.messageId,w=void 0===U?0:U,b=o.encrypted,x=void 0!==b&&b,A=o.needReceipt,L=void 0!==A&&A,D=p||{},k=D.iOSConfig,J=D.androidConfig,j=D.templateId,B=void 0===j?"":j,F=D.pushTitle,H=void 0===F?"":F,V=D.pushContent,q=void 0===V?g:V,G=D.pushData,K=void 0===G?_:G,W=D.disablePushTitle,Q=void 0!==W&&W,Y=D.forceShowDetailContent,X=void 0!==Y&&Y,z=n.pushConfigsToJSON(k,J);return new Promise((function(o){g=q,_=K;var p=(null==J?void 0:J.notificationId)||"";e===n.ConversationType.GROUP&&d&&c&&(c.mentionedInfo=i._updateMentionedInfo(c,f,l));var C=e===n.ConversationType.GROUP;if(C&&a===n.MessageType.READ_RECEIPT_RESPONSE&&c.receiptMessageDic)for(var h in c.receiptMessageDic)E.push(h);C&&a===n.MessageType.SYNC_READ_STATUS&&(E=[i.getCurrentUserId()]);var v={};for(var h in u)v[h]={v:""},v[h].v=u[h];var S=B;i.logger.info(y.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:e,targetId:t,channelId:M,messageId:w}),s);var m=i._callCppProxy("sendMessage",(function(e,t){var r=i._buildMessage(e);return i.logger.info(y.P_SEND_MSG_R,JSON.stringify({code:t,messageUId:r.messageUId,messageId:r.messageId}),s),t===n.ErrorCode.SENSITIVE_REPLACE?o({code:t}):("RC:MsgExMsg"===r.messageType&&i._msgExpansionHandler.setLocalFromExtMsg(i.logger,r),r.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(i.logger,r),o({code:n.ErrorCode.SUCCESS,data:r}))}),(function(e,t){var r=i._buildMessage(e);return i.logger.warn(y.P_SEND_MSG_R,JSON.stringify({code:t,messageId:r.messageId}),s),r.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),o({code:t,data:r})}),e,t,a,JSON.stringify(c),E,P,Q,X,g,_,p,H,z,S,I,JSON.stringify(v),N,M,w,x,L),T=JSON.parse(m);null==r||r(T.messageId)}))},o.prototype.recallMsg=function(e,t,o,r,s){var i=this;return new Promise((function(a,c){var u,p=s.user,d=s.pushContent,l=s.channelId,C=s.extra,f=s.pushConfig,h=s.disableNotification,g=s.isDelete,v={conversationType:e,targetId:t,messageUId:o,sentTime:r,user:p,extra:C,channelId:l,isDelete:g||!1};p&&(v.user=p),C&&(v.extra=C);i._callCppProxy("recallMessage",(function(r){var s={conversationType:e,targetId:t,senderUserId:i.tcpMgr.getCurrentUserId(),content:v,objectName:n.MessageType.RECALL,messageUid:o,direction:n.MessageDirection.SEND,status:n.ReceivedStatus.UNREAD,sentTime:Number(r),channelId:l},c=i._buildMessage(JSON.stringify(s));i.handleRecalledMessage(c,!0),a({code:n.ErrorCode.SUCCESS,data:c})}),(function(e){a({code:e})}),n.MessageType.RECALL,JSON.stringify(v),h||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,d||"",(null==f?void 0:f.pushData)||"",(null===(u=null==f?void 0:f.androidConfig)||void 0===u?void 0:u.notificationId)||"",(null==f?void 0:f.pushTitle)||"",n.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",l)}))},o.prototype.getHistoryMessage=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(u,p){o=o||0;var d=0===s,l=r+1,C=c._callCppProxy("getHistoryMessages",e,t,o,l,a,d,i),f=JSON.parse(C).list,h=[];f.reverse();for(var g=0;g<f.length;g++){var v=c._buildMessage(f[g].obj);h[g]=v}u({code:n.ErrorCode.SUCCESS,data:{list:l===h.length?h.slice(1,l):h,hasMore:r<h.length}})}))},o.prototype.getRemoteHistoryMessages=function(e,t,o,r,s,i){var a=this;return new Promise((function(c,u){o=o||0;a._callCppProxy("getRemoteHistoryMessages",e,t,o,r,(function(e,t){var o=JSON.parse(e).list,r=[];o.reverse();for(var s=0;s<o.length;s++){var i=a._buildMessage(o[s].obj);r[s]=i}c({code:n.ErrorCode.SUCCESS,data:{list:r,hasMore:!!t}})}),(function(e){c({code:e})}),s,!0,i)}))},o.prototype.deleteRemoteMessage=function(e,t,o,r){var s=this;return new Promise((function(i,a){var c=JSON.stringify(o);s._callCppProxy("deleteRemoteHistoryMessages",e,t,c,!1,r,(function(){i(n.ErrorCode.SUCCESS)}),i)}))},o.prototype.deleteRemoteMessageByTimestamp=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearRemoteHistoryMessages",e,t,o,(function(){i(n.ErrorCode.SUCCESS)}),(function(e){i(e)}),r)}))},o.prototype.clearMessages=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearMessages",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.getConversationList=function(e,t,o,r,s){var i=this;return void 0===s&&(s=""),new Promise((function(e,t){for(var o=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(o).list,a=[],c=0;c<r.length;c++)a.push(i._buildConversation(r[c].obj));e({code:n.ErrorCode.SUCCESS,data:a})}))},o.prototype.getConversation=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversation",e,t,o);if(a)s({code:n.ErrorCode.SUCCESS,data:r._buildConversation(a)});else{var c=r._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,o),u=void 0;try{u=JSON.parse(c).list}catch(e){r.logger.error(y.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),u=[]}var p=null;u.length>0&&(p=r._buildMessage(u[0].obj));var d=r._callCppProxy("getConversationNotificationStatus",e,t,o),l=r._callCppProxy("getConversationTopStatus",e,t,o);s({code:n.ErrorCode.SUCCESS,data:{conversationType:e,targetId:t,channelId:o,unreadMessageCount:0,latestMessage:p,notificationStatus:d?n.NotificationStatus.OPEN:n.NotificationStatus.CLOSE,isTop:Boolean(l),lastUnreadTime:0}})}}))},o.prototype.removeConversation=function(e,t,o){var r=this._callCppProxy("removeConversation",e,t,o);return Promise.resolve(r?n.ErrorCode.SUCCESS:n.ErrorCode.UNKNOWN)},o.prototype.clearConversations=function(e,t){var o=this;return new Promise((function(r,s){var i=[];i=n.isArray(e)?e:[n.ConversationType.PRIVATE,n.ConversationType.GROUP,n.ConversationType.SYSTEM,n.ConversationType.PUBLIC_SERVICE],o._callCppProxy("clearConversations",i,t),r(n.ErrorCode.SUCCESS)}))},o.prototype.getAllConversationUnreadCount=function(e,t,o){var r=this._callCppProxy("getTotalUnreadCount",t,o,e);return Promise.resolve({code:n.ErrorCode.SUCCESS,data:r})},o.prototype.getConversationUnreadCount=function(e,t,o){var r=this;return void 0===o&&(o=""),new Promise((function(s){var i=r._callCppProxy("getUnreadCount",e,t,o);s({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.clearConversationUnreadCount=function(e,t,o){var r=this;return void 0===o&&(o=""),new Promise((function(s,i){r._callCppProxy("clearUnreadCount",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.clearUnreadCountByTimestamp=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearUnreadCountByTimestamp",e,t,o,r),i(n.ErrorCode.SUCCESS)}))},o.prototype.getFirstUnreadMessage=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getTheFirstUnreadMessage",e,t,o),c=r._buildMessage(a);s({code:n.ErrorCode.SUCCESS,data:-1!==c.messageId?c:null})}))},o.prototype.setConversationToTop=function(e,t,o,r){var s=this;return void 0===r&&(r=""),new Promise((function(i,a){s._callCppProxy("setConversationToTop",e,t,o,r,!0),i(n.ErrorCode.SUCCESS)}))},o.prototype.setConversationHidden=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("setConversationHidden",e,t,o,r),i(n.ErrorCode.SUCCESS)}))},o.prototype.setConversationNotificationStatus=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("setConversationNotificationStatus",e,t,o,(function(){i(n.ErrorCode.SUCCESS)}),i,r)}))},o.prototype.setConversationStatus=function(e,t,o,r,s,i){var a=this;return new Promise((function(c,u){a._callCppProxy("setConversationStatus",e,t,o,r,(function(){c(n.ErrorCode.SUCCESS)}),c,s,!0,i)}))},o.prototype.getConversationNotificationStatus=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversationNotificationStatus",e,t,o);s({code:n.ErrorCode.SUCCESS,data:a?n.NotificationStatus.OPEN:n.NotificationStatus.CLOSE})}))},o.prototype.setConversationTypeNotificationLevel=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("setBlockPushLevelForType",e,t,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.getConversationTypeNotificationLevel=function(e){var t=this;return new Promise((function(o,r){var s=t._callCppProxy("getBlockPushLevelForType",e);o({code:n.ErrorCode.SUCCESS,data:s})}))},o.prototype.searchConversationByContent=function(e,t,o,r,s){var i=this;return new Promise((function(a){r=r||[1,3,6,7],i._callCppProxy("searchConversationsByContentIncludeDeleted",r,e,t,o,!!s,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return i._transICppConversation2IReceivedConversation(e)}));a({code:n.ErrorCode.SUCCESS,data:o})}else a({code:e})}))}))},o.prototype.searchConversationsByPage=function(e,t){var o=this,r=e.conversationTypes,s=e.keyword,i=e.messageTypes,a=e.includeDeleted,c=e.startTime,u=e.count;return new Promise((function(e){o.logger.info(y.P_SEARCH_CONVERSATIONS_T,"start",t),o._callCppProxy("searchConversationsByContentIncludeDeletedByPage",r,s,i||[],"",!!a,(function(r,s,i){if(o.logger.info(y.P_SEARCH_CONVERSATIONS_R,JSON.stringify({code:r}),t),r===n.ErrorCode.SUCCESS){var a=JSON.parse(s).map((function(e){return o._transICppConversation2IReceivedConversation(e)}));o.logger.info(y.L_FORMAT_CONVERSATIONS_S,"done",t),e({code:n.ErrorCode.SUCCESS,data:{list:a,totalCount:i}})}else e({code:r})}),c,u),o.logger.info(y.L_JS_GET_NOW_TIME_S,Date.now(),t)}))},o.prototype.searchConversationByContentWithAllChannel=function(e,t,o){var r=this;return new Promise((function(s,i){o=o||[1,3,6,7],r._callCppProxy("searchConversationByContentWithAllChannel",o,e,t,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return r._transICppConversation2IReceivedConversation(e)}));s({code:n.ErrorCode.SUCCESS,data:o})}else s({code:e})}))}))},o.prototype.searchMessageByContent=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(i,u){c._callCppProxy("searchMessageByContent",e,t,o,r,s,!0,(function(e,t,o){if(e===n.ErrorCode.SUCCESS){var r=JSON.parse(t).map((function(e){return c._transICppMessage2IReceivedMessage(e)}));i({code:n.ErrorCode.SUCCESS,data:{messages:r,count:o}})}else i({code:e})}),a)}))},o.prototype.searchMessageByContentAndMessageType=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByContentAndObjectName",t,e,a||"",void 0===a,o,i,s,r,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return c._transICppMessage2IReceivedMessage(e)}));u({code:n.ErrorCode.SUCCESS,data:{messages:o}})}else u({code:e})}))}))},o.prototype.searchMessagesByUser=function(e,t,o,r,s,i){var a=this;return new Promise((function(c,u){a._callCppProxy("getMessageBySender",e,t,o,r,s,i,(function(e){for(var t=e?JSON.parse(e).list:[],o=[],r=0;r<t.length;r++)o[r]=a._buildMessage(t[r].obj);c({code:n.ErrorCode.SUCCESS,data:{messages:o}})}))}))},o.prototype.searchMessageByContentWithAllChannel=function(e,t,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("searchMessageByContentWithAllChannel",e,t,o,r,s,!0,(function(e,t,o){if(e===n.ErrorCode.SUCCESS){var r=JSON.parse(t).map((function(e){return i._transICppMessage2IReceivedMessage(e)}));a({code:n.ErrorCode.SUCCESS,data:{messages:r,count:o}})}else a({code:e})}))}))},o.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(u,p){c._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,o,r,s,i,a,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return c._transICppMessage2IReceivedMessage(e)}));u({code:n.ErrorCode.SUCCESS,data:{messages:o}})}else u({code:e})}))}))},o.prototype.getUnreadMentionedMessages=function(e,t,o){for(var r=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,o)).list,n=0;n<r.length;n++)r[n]=this._buildMessage(r[n].obj);return r},o.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("addToBlacklist",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("removeFromBlacklist",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,o){e._callCppProxy("getBlacklist",(function(e){t({code:n.ErrorCode.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},o.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("getBlacklistStatus",e,(function(e){o({code:n.ErrorCode.SUCCESS,data:e})}),(function(e){o({code:e})}))}))},o.prototype.insertMessage=function(e,t,o){var r=this,s=o.content,i=o.senderUserId,a=o.messageType,c=o.messageDirection,u=o.readStatus,p=o.sentStatus,d=o.sentTime,l=o.searchContent,C=o.isUnread,f=o.messageUId,h=o.disableNotification,g=o.canIncludeExpansion,v=o.expansionMsg,_=o.channelId;s=JSON.stringify(s);var S={};if(d=d||0,v){var y=JSON.parse(v);for(var E in y)S[E]={v:"",ts:0},S[E].v=y[E],S[E].ts=d}return new Promise((function(o,v){var y=C?0:1,E=r._callCppProxy("insertMessage",e,t,i,a,s,(function(){}),(function(e){o({code:e})}),c,u||0,p||10,d,l||"",y,f||"",!!h,!!g,JSON.stringify(S),_||""),m=r._buildMessage(E);m.messageUId=f,m.sentTime=d,o({code:-1===m.messageId?n.ErrorCode.MSG_INSERT_ERROR:n.ErrorCode.SUCCESS,data:m})}))},o.prototype.batchInsertMessage=function(e,t){var o=this;return void 0===t&&(t=!1),new Promise((function(r){var s=e.map((function(e){var t=e.content,o=e.senderUserId,r=e.messageType,n=e.messageDirection,s=e.receivedStatus,i=e.sentStatus,a=e.sentTime,c=e.searchContent,u=e.isUnread,p=e.messageUId,d=e.disableNotification,l=e.canIncludeExpansion,C=e.expansion,f=e.channelId,h=e.conversationType,g=e.targetId,v=e.source,_=e.isMentioned,S={};if(a=a||0,C)for(var y in C)S[y]={v:"",ts:0},S[y].v=C[y],S[y].ts=a;return{conversationType:h,targetId:g,channelId:f||"",direction:n,senderUserId:o,status:i||10,sentTime:a,objectName:r,content:JSON.stringify(t),messageUid:p||"",noNotification:!!d,supportExt:!!l,extMsg:JSON.stringify(S),readStatus:s||0,searchContent:c||"",isUnread:!!u,source:v||"",isMention:_}})),i=o._callCppProxy("insertMessages",JSON.stringify(s),t);r({code:i?n.ErrorCode.SUCCESS:n.ErrorCode.MSG_INSERT_ERROR,data:i||!1})}))},o.prototype.getMessageCount=function(e,t,o){var r=this;return new Promise((function(s){var i=r._callCppProxy("getMessageCount",e,t,o);s({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.deleteMessages=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("deleteMessages",e),o(n.ErrorCode.SUCCESS)}))},o.prototype.deleteMessagesByTimestamp=function(e,t,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("deleteMessagesByTimestamp",e,t,o,r,s),a(n.ErrorCode.SUCCESS)}))},o.prototype.getMessage=function(e){var t=this;return new Promise((function(o,r){var s=t._callCppProxy("getMessage",e),i=t._buildMessage(s);o({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.setMessageContent=function(e,t,o){var r=this;return new Promise((function(s,i){t=JSON.stringify(t),r._callCppProxy("setMessageContent",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.setMessageSearchField=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setMessageSearchField",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.setMessageSentStatus=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageSentStatus",e,t),r(n.ErrorCode.SUCCESS)}))},o.prototype.setMessageReceivedStatus=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageReceivedStatus",e,t),r(n.ErrorCode.SUCCESS)}))},o.prototype.saveConversationMessageDraft=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("saveTextMessageDraft",e,t,o,r||"")&&i(n.ErrorCode.SUCCESS),i(n.ErrorCode.DRAF_SAVE_ERROR)}))},o.prototype.getConversationMessageDraft=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getTextMessageDraft",e,t,o||"");s({code:n.ErrorCode.SUCCESS,data:a})}))},o.prototype.clearConversationMessageDraft=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearTextMessageDraft",e,t,o||"")&&s(n.ErrorCode.SUCCESS),s(n.ErrorCode.DRAF_REMOVE_ERROR)}))},o.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},o.prototype.batchSetConversationStatus=function(e){var t=e[0],o=t.conversationType,r=t.targetId,s=t.isTop,i=t.notificationLevel,a=t.channelId,c=t.isUpdateTime,u=void 0===c||c,p=this._callCppProxy("getConversationNotificationStatus",o,r,a||""),d=this._callCppProxy("getConversationTopStatus",o,r,a||""),l=n.isUndefined(i)?Boolean(p):i>n.NotificationLevel.NOT_SET,C=n.isUndefined(s)?Boolean(d):s;return this.setConversationStatus(o,r,l,C,a,u)},o.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},o.prototype.sendReadReceiptMessage=function(e,t,o){var r=this;return new Promise((function(s){r._callCppProxy("sendReadReceipt",e,o||"",t,(function(){t.forEach((function(e){r._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(r._callCppProxy("getMessage",e)).messageId;r.setMessageReceivedStatus(t,1)}catch(t){r.logger.error(y.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),s({code:n.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},o.prototype.getMessageReader=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getMessageReader",e,o,t,(function(e,o){var i=[],a={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;i.push({userId:o,readTime:r}),a[o]=r}));var c={readerInfo:a,readCount:i.length,totalCount:o};r._updateReadReceiptInfo(t,c),s({code:n.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:o}})}),(function(e){s({code:e})}))}))},o.prototype.sendReadReceipt=function(e,t){var o=this;return new Promise((function(r,s){var i=e.conversationType,a=e.targetId,c=e.channelId,u=void 0===c?"":c,p=o._callCppProxy("sendReadReceiptByReadReceiptType",i,a,u,0,t.map((function(e){return e.messageUId})),(function(e){e===n.ErrorCode.SUCCESS&&t.forEach((function(e){o.setMessageReceivedStatus(e.messageId,n.ReceivedStatus.READ)})),r({code:e})}));p!==n.ErrorCode.SUCCESS&&r({code:p})}))},o.prototype._addChatroomCache=function(e,t,o){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:o,count:t})},o.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},o.prototype._try2RejoinChatroom=function(){var e=this;if(0!==this._chatroomCache.length){var t=this.logger.createTraceId();this._chatroomCache.forEach((function(o){return m(e,void 0,void 0,(function(){var e,r,s,i;return P(this,(function(a){switch(a.label){case 0:return e=o.chatroomId,r=o.joinExist,s=o.count,this.logger.info(n.LogTagId.L_REJOIN_CHATROOM_T,e,t),[4,this._joinChrm(e,s,r,!1)];case 1:return(i=a.sent())===n.ErrorCode.SUCCESS?(this.logger.info(n.LogTagId.L_REJOIN_CHATROOM_R,e,t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,count:s}}),[2]):(i===n.ErrorCode.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(e),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,errorCode:i}}),this.logger.warn(n.LogTagId.L_REJOIN_CHATROOM_R,"chrmId: ".concat(e,", code: ").concat(i),t),[2])}}))}))}))}},o.prototype._joinChrm=function(e,t,o,r){var s=this,i=o?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){r&&s._callCppProxy("clearMessages",n.ConversationType.CHATROOM,e,""),s._callCppProxy(i,e,t,(function(){s._addChatroomCache(e,t,o),a(n.ErrorCode.SUCCESS)}),a)}))},o.prototype.joinChatroom=function(e,t){return this._joinChrm(e,t,!1,!0)},o.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},o.prototype.quitChatroom=function(e){var t=this;return this._rmChatroomCache(e),new Promise((function(o,r){t._callCppProxy("quitChatRoom",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.getChatroomInfo=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomInfo",e,t,o,(function(e,t){var o=e?JSON.parse(e).list:[],r=[];if(o.length>0)for(var i=0;i<o.length;i++)r.push(JSON.parse(o[i].obj));s({code:n.ErrorCode.SUCCESS,data:{userInfos:r,userCount:t}})}),(function(e){s({code:e})}))}))},o.prototype.getChatroomHistoryMessages=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("getChatroomHistoryMessage",e,t,o,r,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var o=t.list;if(o&&o.length)try{t.list=o.map((function(e){return s._buildMessage(e.obj)}))}catch(e){t.list=[]}i({code:n.ErrorCode.SUCCESS,data:t})}),(function(e){i({code:e})}),"")}))},o.prototype.setChatroomEntry=function(e,t){var o=this;return new Promise((function(r,s){var i='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');o._callCppProxy("setChatroomKV",e,i,!!t.isAutoDelete,!!t.isOverwrite,(function(){r(n.ErrorCode.SUCCESS)}),(function(e){r(e)}))}))},o.prototype.setChatroomEntries=function(e,t){var o=this;return new Promise((function(r){o._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},o.prototype.removeChatroomEntry=function(e,t){var o=this,r=[t.key];return new Promise((function(s,i){o._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){s(n.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},o.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},o.prototype.removeChatroomEntries=function(e,t){var o=this;return new Promise((function(r){var s=t.entries.map((function(e){return e.key}));o._callCppProxy("deleteChatroomKV",e,s,!!t.isOverwrite,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.getChatroomEntry=function(e,t){return m(this,void 0,void 0,(function(){var o;return P(this,(function(r){switch(r.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(o=r.sent()).code===n.ErrorCode.SUCCESS?[2,{code:n.ErrorCode.SUCCESS,data:o.data?o.data[t]:null}]:[2,{code:o.code}]}}))}))},o.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}o({code:n.ErrorCode.SUCCESS,data:t})}),(function(e){o({code:e})}))}))},o.prototype.getFileToken=function(e,t,o,r,s){var i=this;return void 0===s&&(s=""),o=o||"",r=r||"",new Promise((function(a){var c;c=r&&"uploads"!==r?t||"":n.getUploadFileName(e,t);var u=i.getNaviInfoFromCache(),p={uploadDomain:n.getMinionURL(u,i.logger),env:i._environment};i._callCppProxy("getUploadToken",e,c,o,r,s,JSON.stringify(p),(function(e,t,o,r,s,i,u,p,d,l,C,f,h,g,v,_,S,y,E,m,P,T,I){a({code:n.ErrorCode.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:o,path:r,osskeyId:s,ossPolicy:i,ossSign:u,ossBucketName:p,fileName:c,s3Credential:d,s3Algorithm:l,s3Date:C,s3Policy:f,s3Signature:h,s3BucketName:g,stcAuthorization:v,stcContentSha256:_,stcDate:S,stcBucketName:y,minioAuthorization:E,minioContentSha256:m,minioDate:P,minioBucketName:T,downloadAuthInfo:I?JSON.parse(I):null}})}),(function(e){a({code:e})}))}))},o.prototype.getFileUrl=function(e,t,o,r){var s=this;return new Promise((function(i){var a=s.getNaviInfoFromCache(),c={url:n.getMinionURL(a,s.logger)};s._callCppProxy("getDownloadUrl",e,o,r,t-1,JSON.stringify(c),(function(e){i({code:n.ErrorCode.SUCCESS,data:{downloadUrl:e}})}),(function(e){i({code:e})}))}))},o.prototype.clearData=function(){var e=this;return new Promise((function(t,o){var r=e._callCppProxy("clearData");t({code:n.ErrorCode.SUCCESS,data:r})}))},o.prototype.getDeviceId=function(){var o=this._dbpath||e.resolve(t.app.getPath("userData"));return ie(o)},o.prototype.getVoIPKey=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("getVoIPKey",e,t,"",(function(e){r({code:n.ErrorCode.SUCCESS,data:e})}),(function(e){r({code:e})}))}))},o.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(o,r){var s=e.chatRoomId,i=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",s,i,(function(){o(n.ErrorCode.SUCCESS)}),(function(e){o(e)}))}))},o.prototype.getGroupMessageDeliverList=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getGroupMessageDeliverList",e,o,t,(function(e,t){var o=JSON.parse(e).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));s({code:n.ErrorCode.SUCCESS,data:{totalCount:t,list:o}})}),(function(e){s({code:e})}))}))},o.prototype.getPrivateMessageDeliverTime=function(e,t){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getMessageDeliverTime",e);if(i)r({code:n.ErrorCode.SUCCESS,data:i});else{o._callCppProxy("getPrivateMessageDeliverList",t,e,(function(e){var t=0,o=JSON.parse(e).list;o.length>0&&(t=JSON.parse(o[0].obj).time);r({code:n.ErrorCode.SUCCESS,data:t})}),(function(e){r({code:e})}))}}))},o.prototype.rtcSignaling=function(e,t,o,r){var s=this,i=Array.prototype.slice.call(new Uint8Array(r));return new Promise((function(r){s._callCppProxy("rtcSignaling",e,t,o,i,(function(e){var t=new Uint8Array(e).buffer;r({code:n.ErrorCode.SUCCESS,buffer:t})}),(function(e){r({code:e})}))}))},o.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,o){var r=e.rtcHeartbeatResolves[t];if(r){var n=r.find((function(e){return""===e.seqId}));n&&(n.seqId=o)}}),(function(t,o,r,n){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===r}));-1!==i&&s.splice(i,1)[0].resolve({code:o,data:{version:Number(n)}})}}))},o.prototype.rtcPing=function(e,t,o){var r=this;return new Promise((function(t){var o={resolve:t,seqId:""},n=r.rtcHeartbeatResolves[e];n?n.push(o):r.rtcHeartbeatResolves[e]=[o],r._callCppProxy("sendRTCHeartbeat",[e])}))},o.prototype.createTag=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){o({code:n.ErrorCode.SUCCESS})}),(function(e){o({code:e})}))}))},o.prototype.removeTag=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("deleteTag",e,(function(){o({code:n.ErrorCode.SUCCESS})}),(function(e){o({code:e})}))}))},o.prototype.updateTag=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){o({code:n.ErrorCode.SUCCESS})}),(function(e){o({code:e})}))}))},o.prototype.getTagList=function(){var e=this;return new Promise((function(t,o){var r=e._callCppProxy("getTags"),s=e._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:n.ErrorCode.SUCCESS,data:s})}))},o.prototype.addTagForConversations=function(e,t){var o=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));o._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.removeTagForConversations=function(e,t){var o=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),o._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.removeTagsForConversation=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.getConversationListByTag=function(e,t,o,r){var s=this;return new Promise((function(i){var a=s._callCppProxy("getConversationsForTagByPage",e,t,o||20,r||""),c=s._convertResultList(a,(function(e){return E(E({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:n.ErrorCode.SUCCESS,data:c})}))},o.prototype.getUnreadCountByTag=function(e,t){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversationUnreadCountForTag",e,t);r({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.setConversationStatusInTag=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",o.isTop||!1,(function(){s({code:n.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},o.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(o,r){var s=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||""),i=t._convertResultList(s,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));o({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},o.prototype.getTopConversationList=function(e,t){var o=this;return new Promise((function(r){var s=n.isUndefined(t)?o._callCppProxy("getTopConversations",e):o._callCppProxy("getTopConversations",e,t),i=JSON.parse(s).list.map((function(e){return o._buildConversation(e.obj)}));r({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},o.prototype.getAllUnreadMentionedCount=function(){var e=this;return new Promise((function(t){var o=e._callCppProxy("getUnreadAndMentionCount",[n.ConversationType.GROUP],"");t({code:n.ErrorCode.SUCCESS,data:o})}))},o.prototype.getOSInfo=function(){return m(this,void 0,void 0,(function(){var e;return P(this,(function(t){return e={arch:f.arch(),platform:f.platform(),type:f.type(),version:f.version(),release:f.release(),uptime:f.uptime(),cpus:f.cpus(),freemem:f.freemem(),totalmem:f.totalmem(),networkInterfaces:f.networkInterfaces()},[2,{code:n.ErrorCode.SUCCESS,data:e}]}))}))},o.prototype.getMainProcessInfo=function(){return m(this,void 0,void 0,(function(){return P(this,(function(e){return[2,{code:n.ErrorCode.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},o.prototype.setCallInfo=function(e,t,o){var r=this;return new Promise((function(s){r._callCppProxy("callInfoSignaling",e,t,o,(function(e,t){s({code:n.ErrorCode.SUCCESS,data:{key:e,value:t}})}),(function(e){s({code:e})}))}))},o.prototype.setProxy=function(e){return this.tcpMgr.getConnectionStatus()!==n.RCConnectionStatus.DISCONNECTED?Promise.resolve({code:n.ErrorCode.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(z(e,this.logger))},o.prototype.getProxy=function(){return Promise.resolve($())},o.prototype.testProxy=function(e,t){return function(e,t,o){return new Promise((function(r){var s=/^https/.test(t)?Q:G;o.info(n.LogTagId.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:e,testHost:t}));var i=s(t,e,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var o="";e.on("data",(function(e){o+=e})),e.once("end",(function(){r({status:t||0,data:o})}))}));i.once("timeout",(function(){return r({status:0})})),i.once("error",(function(e){return r({status:0,data:e.stack})})),i.end()}))}(e,t,this.logger)},o.prototype.checkDuplicateMessage=function(e){var t=this;return new Promise((function(o){t._callCppProxy("checkDuplicateMessage",e),o({code:n.ErrorCode.SUCCESS})}))},o.prototype.initAndOpenDatabase=function(e){var t=this;return new Promise((function(o){t._callCppProxy("initAndOpenDatabase",e),o({code:n.ErrorCode.SUCCESS})}))},o.prototype.closeDatabase=function(){var e=this;return new Promise((function(t){e._callCppProxy("closeDatabase"),t({code:n.ErrorCode.SUCCESS})}))},o.prototype.getMessagesByObjectNamesAcrossConversations=function(e,t,o,r,s,i,a,c){var u=0===i,p=a+1,d=this._callCppProxy("getMessagesByObjectNamesAcrossConversations",c,e,t,o,r,s,u,p),l=[];try{var C=JSON.parse(d).list;C.reverse();for(var f=0;f<C.length;f++){var h=this._buildMessage(C[f].obj);l[f]=h}}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:{list:p===l.length?l.slice(1,p):l,hasMore:a<l.length}})},o.prototype.getReadReceiptUsers=function(e,t){var o=this;return new Promise((function(r){var s=o._callCppProxy("getReadReceiptUsersByUid",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t,s){var i,a;try{var c=JSON.parse(t).list,u=JSON.parse(s).list;i=c.map((function(e){return JSON.parse(e.obj)})),a=u.map((function(e){return JSON.parse(e.obj)})),r({code:e,data:{userInfoRead:i,userInfoUnread:a}})}catch(e){o.logger.error(y.P_PARSE_JSON_MSGS_E,t,s),r({code:n.ErrorCode.MAIN_PROCESS_ERROR})}}));s!==n.ErrorCode.SUCCESS&&r({code:s})}))},o.prototype.getMessageReadReceiptInfos=function(e,t){var o=this;return new Promise((function(r){var s=o._callCppProxy("getReadReceiptCount",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t){try{var s=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));r({code:e,data:s})}catch(e){o.logger.error(y.P_PARSE_JSON_MSGS_E,t),r({code:n.ErrorCode.MAIN_PROCESS_ERROR})}}));s!==n.ErrorCode.SUCCESS&&r({code:s})}))},o}(),ge=function(){function e(e,t,o,r,n){void 0===o&&(o=""),this._cppService=new he(e,t,o,r,n)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._cppService.destroy()},e.prototype.getDeviceId=function(){return this._cppService.getDeviceId()},e.prototype.getServerTime=function(){return this._cppService.getServerTime()},e.prototype.__createLogger=function(e,t){return null},e}();module.exports=function(o){return function(e,t,o){if(le)return le;if(!t)throw new Error("Initializ failed, `appkey` is required!");return le=new ge(t,e,null==o?void 0:o.dbpath,null==o?void 0:o.logOutputLevel,null==o?void 0:o.httpRequestProxy)}(function(e){try{return require(g)}catch(t){throw v(e,t),t}}(o.dbpath||e.resolve(t.app.getPath("userData"))),o.appkey,o)};
1
+ "use strict";var e=require("path"),t=require("electron"),o=require("os"),r=require("fs"),n=require("@rongcloud/engine"),s=require("child_process"),i=require("http"),a=require("https"),c=require("url"),u=require("net"),p=require("events"),d=require("tls"),l=require("crypto");function C(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var f=C(o),h=process.versions.electron.replace(/\.\d+$/,""),g=e.resolve(__dirname,"binding","electron-v".concat(h,"-").concat(o.platform(),"-").concat(o.arch(),".node")),v=function(t,o){try{r.existsSync(e.resolve(t,"RongCloud"))||r.mkdirSync(e.resolve(t,"RongCloud"));var n=e.resolve(t,"RongCloud/addon-load-error.txt");r.writeFileSync(n,o.toString())}catch(e){console.error(e)}},_=function(e,t){return _=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},_(e,t)};function S(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}_(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var y,E=function(){return E=Object.assign||function(e){for(var t,o=1,r=arguments.length;o<r;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},E.apply(this,arguments)};function m(e,t,o,r){return new(o||(o=Promise))((function(n,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))}function P(e,t){var o,r,n,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(o=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){s.label=a[1];break}if(6===a[0]&&s.label<n[1]){s.label=n[1],n=a;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(a);break}n[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{o=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function T(e,t,o){if(o||2===arguments.length)for(var r,n=0,s=t.length;n<s;n++)!r&&n in t||(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_DB_OP_E="P-db_op-E",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_E="P-connect-E",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_R="P-connect-R",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_E="P-parse_json-E",e.P_SEARCH_CONVERSATIONS_T="P-search_conversations-T",e.P_SEARCH_CONVERSATIONS_R="P-search_conversations-R",e.L_FORMAT_CONVERSATIONS_S="L-format_conversations-S",e.L_JS_GET_NOW_TIME_S="L-js_get_now_time-S",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R"}(y||(y={}));var I,R={flushTimestamp:Date.now(),queue:[],locked:!1};function N(){I&&clearInterval(I)}function O(e,t){N(),I=setInterval((function(){return w(e,t)}),1e4)}function M(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=R.queue).push.apply(e,t)}var U=200;function w(e,t){var o=R.queue,r=R.flushTimestamp;if(!(R.locked||0===o.length||Date.now()-r<3e4&&o.length<U)){R.locked=!0;var n=t.createTraceId(),s=o.splice(0,U).map((function(e){var t=e.sessionId,o=e.level,r=e.time,n=e.type,s=e.tag,i=e.loggerId,a=e.content,c=e.traceId;return{level:o,time:r,type:n,tag:s,content:encodeURIComponent(JSON.stringify({loggerId:i,sessionId:t,content:a,traceId:c})).replace(/'/g,"%27")}}));t.debug(y.P_WRITE_LOG_T,"writingLen: ".concat(s.length,", queueLen: ").concat(o.length),n);var i=JSON.stringify(s);e.writeLog(i),t.debug(y.P_WRITE_LOG_R,"write done, queueLen: ".concat(o.length),n),R.flushTimestamp=Date.now(),R.locked=!1,setTimeout((function(){return w(e,t)}))}}var b=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return S(t,e),t.prototype.flush=function(e){M(e)},t}(n.BasicLogger),x=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return S(t,e),t.prototype.flush=function(e){M(e)},t}(n.BasicStatistic),A=function(e,t){var o,r=Buffer.from(e),n=r.length;for(t.push(n),o=0;o<n;o++)t.push(r[o])},L=function(e){return"string"==typeof e},D=function(e){return L(e)?e.toUpperCase():""},k=function(e,t){var o="";return 2!==e.length?o="Unexpected number of bytes received.":5!==e[0]?o="Unexpected SOCKS version number: ".concat(e[0],"."):255===e[1]?o="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(o="Unexpected SOCKS authentication method: ".concat(e[1],".")),o},J=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: ".concat(e[0],"."):0!==e[1]&&(t="Username and password authentication failure: ".concat(e[1],".")),t},j=function(e){var t=D(e.method)||"GET",o=e.pathname||"/",r=e.headers||{},n=e.search||"";r.Host=e.host||"loclahost";var s="";for(var i in s="".concat(t," ").concat(o+n," HTTP/1.1\n"),r)if(Object.hasOwnProperty.call(r,i)){var a=r[i];s+="".concat(i,": ").concat(a,"\n")}return e.body&&(s+="Content-Length: ".concat(e.body.length,"\n")),s+="\n","POST"===t&&e.body&&(s+="".concat(e.body)),s},B=function(e){return new Promise((function(t){var o,r;e.socket.once("data",(function(r){var n,s=k(r,o);if(!s)return 2===r[1]?(e.socket.once("data",(function(o){var r=J(o);r?e.emit("error",new Error("SOCKS authentication failed. ".concat(r))):t()})),n=[1],A(e.socksUsername,n),A(e.socksPassword,n),void e.write(Buffer.from(n))):void t();e.emit("error",new Error("SOCKS authentication failed. ".concat(s)))})),o=[0],e.socksUsername&&o.push(2),(r=Buffer.alloc(2+o.length))[0]=5,r[1]=o.length,o.forEach((function(e,t){r[2+t]=e})),e.write(r)}))},F=function(e,t,o){return new Promise((function(r){var n,s;switch(e.socket.once("data",(function(t){var o;5!==t[0]?o="Unexpected SOCKS version number: ".concat(t[0],"."):0!==t[1]?o="".concat(function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code ".concat(e)}}(t[1]),"."):0!==t[2]&&(o="The reserved byte must be 0x00."),o?e.emit("error",new Error("SOCKS connection failed. ".concat(o))):r()})),(n=[]).push(5),n.push(1),n.push(0),u.isIP(t)){case 0:n.push(3),A(t,n);break;case 4:n.push(1),function(e,t){var o,r,n=e.split(".");for(o=0;o<4;o++)r=parseInt(n[o],10),t.push(r)}(t,n);break;case 6:e.emit("error",new Error("Does not support IPV6"))}n.length+=2,(s=Buffer.from(n)).writeUInt16BE(o,s.length-2),e.write(s)}))},H=function(e){function t(t){var o=e.call(this)||this;return o.readable=!0,o.socket=new u.Socket,o.options=t,o.socksHost=t.socksHost||"localhost",o.socksPort=t.socksPort||1080,o.socksUsername=t.socksUsername||"",o.socksPassword=t.socksPassword||"",o.socket.on("error",(function(e){o.emit("error",e)})),o.on("error",(function(){o.socket.destroyed||o.socket.destroy()})),o.on("end",o.end),o}return S(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var o=this.socket.end(e,t);return this.writable=this.socket.writable,o},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,o){return this.socket.write(e,t,o)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var o=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: ".concat(e));if(!t||"string"!=typeof t)throw new TypeError("Invalid host: ".concat(t));return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return m(o,void 0,void 0,(function(){var o;return P(this,(function(r){switch(r.label){case 0:return[4,B(this)];case 1:return r.sent(),[4,F(this,t,e)];case 2:return r.sent(),this.onProxied(),o=j(this.options),this.socket.write(Buffer.from(o)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(p.EventEmitter),V=function(e){var t,o=e.hostname,r=e.port;return!e.host||o&&r||(t=e.host.split(":")),!r&&t&&(r=parseInt(t[1],10)||0),!o&&t&&(o=t[0]),new H(e).connect(r,o)},q=function(e){function t(t){var o=e.call(this)||this;return o.createConnection=V,o}return S(t,e),t}(i.Agent),G=function(e,t,o){return(t=E(E({},t),c.parse(e))).port||(t.port=80),t.agent=new q(t),i.request(t,o)},K=function(e){var t,o;return t=V(e),o=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=d.connect(e,(function(){t.authorized=t.socket.authorized,o.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},W=function(e){function t(t,o){var r=e.call(this,o)||this;return r.url=t,r.socksHost=o.socksHost||"localhost",r.socksPort=o.socksPort||1080,r.createConnection=K,r}return S(t,e),t}(a.Agent),Q=function(e,t,o,r){var n,s;return t.protocol="https:",!t.port&&t.host&&(n=t.host.split(":"),t.port=n[0],t.port=n[1]),t.port||(t.port=443),s=new W(e,t),t.agent=s,a.request(e,t,o)},Y=null;function X(e,t,o){void 0===o&&(o=!1);var r=t.url,s=t.headers,c=t.body,u=t.method,p=t.query,d=t.timeout,l=void 0===d?n.HTTP_TIMEOUT:d;return new Promise((function(t){var d=/^https/.test(r),C={headers:s,method:u};d&&(C.rejectUnauthorized=o);var f=null;Y?((C=E(E({},C),Y)).body=c,f=d?Q:G):(f=i.request,d&&(C.agent=new a.Agent(C),f=a.request));var h=f(n.appendUrl(r,p),C,(function(e){var o=e.statusCode,r="";e.setEncoding("utf8"),e.on("data",(function(e){r+=e})),e.once("end",(function(){t({status:o||0,data:r})}))}));h.once("timeout",(function(){e.warn(y.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:r,method:u,query:p,timeout:l})),t({status:0})})),h.setTimeout(l),h.once("error",(function(o){e.warn(y.P_HTTP_REQ_E,JSON.stringify({msg:o.stack,url:r,method:u,query:p,timeout:l})),t({status:0})})),h.write(c),h.end()}))}function z(e,t){return e?(Y=E(E({},Y),e),t.info(n.LogTagId.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:Y})),{code:n.ErrorCode.SUCCESS}):(Y=null,t.info(n.LogTagId.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:n.ErrorCode.SUCCESS})}function $(){var e=Y||void 0;return{code:n.ErrorCode.SUCCESS,data:e}}var Z,ee=[],te=!1,oe=function(){return m(void 0,void 0,void 0,(function(){var e,t,o,r,s,i,a,c,u,p,d;return P(this,(function(l){return te||0===ee.length||(te=!0,e=ee.shift(),t=e.args,o=e.resolve,r=t.addon,s=t.startTime,i=t.endTime,a=t.level,c=t.realtimeReport,u=0,p=0,d=[],r.setLogEventListener((function(e){u+=e.length;var t=e.split(","),r=t[0],s=t[1],i=t[2],l=t[3],C=t[4],f=t.slice(5);if(u>n.REAT_TIME_LOG_SIZE&&parseInt(s,10)!==p)o(d);else{p=parseInt(s,10);try{var h=JSON.parse(decodeURIComponent(f.join(","))),g=h.loggerId,v=h.sessionId,_=h.content,S=h.traceId;if(!c&&a<0)return;var y={time:parseInt(s,10),level:parseInt(l,10),sessionId:"".concat(r,":").concat(v),type:i,tag:C,loggerId:g,content:_,traceId:S};d.push(y)}catch(e){console.error(e)}}}),(function(e){o(d),te=!1,oe()}),(function(e,t,o){})),r.pullFullLog(a,s,i,!1)),[2]}))}))},re=function(e){function t(t,o,r,s,i){var a=this,c=process.versions.electron,u="Electron|".concat(c,"|").concat(process.arch,"|").concat(process.platform);return(a=e.call(this,o,r,u,{getLogs:function(e,o,r,n){return m(this,void 0,void 0,(function(){return P(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:o,level:r,realtimeReport:n,addon:t},m(void 0,void 0,void 0,(function(){return P(this,(function(e){return[2,new Promise((function(e){ee.push({resolve:e,args:i}),oe()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var e=t.getStoreValue(n.StoreKeys.REALTIME_LOG_TIMESTAMP);return parseInt(e,10)||0},setTimestamp4RealtimeLog:function(e){t.setStoreValue(n.StoreKeys.REALTIME_LOG_TIMESTAMP,e.toString())}},s)||this).subProcess=i,a}return S(t,e),t.prototype.send=function(e){return X(this.logger,e)},t.prototype.compressLogs=function(e){return m(this,void 0,void 0,(function(){var t,o,r;return P(this,(function(n){switch(n.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=n.sent(),o=t.success,r=t.data,o?[2,{success:o,data:r}]:[2,{success:o,data:""}]}}))}))},t}(n.BasicReporter),ne=null,se=function(){var e,t=Date.now(),r=[o.arch(),o.platform(),process.pid,t,Math.floor(Math.random()*t)].join("__");return e=r,l.createHash("md5").update(e).digest("hex")},ie=function(t){if(ne)return ne;var o=e.resolve(t,"deviceId");return r.existsSync(o)?ne=r.readFileSync(o).toString():(ne=se(),r.writeFileSync(o,ne),ne)},ae=function(){function e(e){this._cppProto=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,o,r,n,s){var i=JSON.stringify(n);"{}"!==i&&e.info(y.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:r,ext:n})),this._cppProto.setMessageExtension(t,o,r,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime;if(i&&0!==Object.keys(i).length){var c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,r,n,s,c,o||"")}},e.prototype.setLocalFromExtMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._cppProto.getMessage(a.mid),p=JSON.parse(u).extMsg,d=JSON.parse(p||"{}");if(c)for(var l in c){var C=d[l];C&&C.ts<i-this._setTime?(C.v=c[l],C.ts=i-this._setTime):(d[l]={v:"",ts:0},d[l].v=c[l],d[l].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete d[e]})),this._setToProtocol(e,r,n,a.mid,d,o||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),o={};for(var r in t)o[r]=t[r].v;return o},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),o=JSON.parse(t||"{}"),r={};for(var n in o)r[n]=o[n].v;return r},e}(),ce=function(){function e(e){var t=this;this.p=e,this.count=0,this.maps={},this.p.on("message",(function(e){var o=e.reqId,r=e.success,n=e.data,s=t.maps[o];s&&(s({success:r,data:n}),delete t.maps[o])}))}return e.prototype.call=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return m(this,void 0,void 0,(function(){var o=this;return P(this,(function(r){return this.p.killed?[2,{success:!1}]:[2,new Promise((function(r){var n=++o.count;o.maps[n]=r;var s={reqId:n,method:e,args:t};o.p.send(s)}))]}))}))},e.prototype.destroy=function(){this.p.kill()},e}();!function(e){e[e.RMTP=1]="RMTP",e[e.TLS=2]="TLS",e[e.RPP=3]="RPP",e[e.QUIC=4]="QUIC",e[e.WS=5]="WS",e[e.WSS=6]="WSS",e[e.HTTP=11]="HTTP",e[e.HTTPS=12]="HTTPS"}(Z||(Z={}));var ue,pe=[Z.RMTP,Z.TLS,Z.QUIC],de=function(e){function t(t,o,r,n,s,i){var a=e.call(this,t,o,r)||this;return a.addon=s,a.httpRequestProxy=i,a.naviPath="",a._caches={},a.naviPath="".concat(n,"/navi-cache.json"),a}return S(t,e),t.prototype.httpRequest=function(e,t,o,r){return m(this,void 0,void 0,(function(){var s,i,a,c,u,p,d,l,C=this;return P(this,(function(f){switch(f.label){case 0:s="token=".concat(encodeURIComponent(o),"&v=").concat(n.FORMATED_VERSION,"&p=PC&ev=").concat("5.8.2-enterprise-lz.30"),i="".concat(e,"/navi.json?r=").concat(Date.now(),"&env=").concat(this._environment),this.logger.info(n.LogTagId.L_REQUEST_T,JSON.stringify({url:i,body:s}),r),u=function(){c&&(clearTimeout(c),c=null)},f.label=1;case 1:return f.trys.push([1,3,,4]),[4,new Promise((function(e){c=setTimeout((function(){C.logger.warn(n.LogTagId.L_REQUEST_E,JSON.stringify({url:i,body:s,info:"http response timeout"}),r),e({status:0})}),n.NAVI_REQ_TIMEOUT+5e3),C.httpRequestProxy?C.httpRequestProxy({url:i,method:"POST",headers:{appId:t},body:s,timeout:n.NAVI_REQ_TIMEOUT}).then((function(t){u(),e(t)})).catch((function(t){C.logger.error(n.LogTagId.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),r),u(),e({status:0})})):X(C.logger,{method:"POST",headers:{appId:t},body:s,url:i,timeout:n.NAVI_REQ_TIMEOUT}).then((function(t){u(),e(t)})).catch((function(t){C.logger.error(n.LogTagId.L_REQUEST_E,JSON.stringify({stack:null==t?void 0:t.stack,info:"Code execution error"}),r),u(),e({status:0})}))}))];case 2:return a=f.sent(),[3,4];case 3:return p=f.sent(),this.logger.error(n.LogTagId.L_REQUEST_E,JSON.stringify({stack:null==p?void 0:p.stack,info:"Code execution error"}),r),u(),[2,{code:n.ErrorCode.RC_NAVI_REQ_FAILED}];case 4:if(200!==a.status)return this.logger.warn(n.LogTagId.L_REQUEST_R,JSON.stringify({url:i,code:a.status}),r),[2,{code:this.transHttpCode(a.status)}];try{return d=JSON.parse(a.data),l=/^https/.test(i)?"https":"http",d.protocol=l,d.code&&200!==d.code?[2,{code:this.transHttpCode(d.code)}]:[2,{code:n.ErrorCode.SUCCESS,data:d}]}catch(e){return this.logger.error(n.LogTagId.L_PARSE_NAVI_E,a.data,r),[2,{code:n.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.httpRequestV2=function(e,t,o,r){return m(this,void 0,void 0,(function(){var s,i,a,c;return P(this,(function(u){switch(u.label){case 0:return s=this.getNaviV2RequestOption({appkey:t,token:o,uri:e,platform:"electron",protocol:pe.join(",")}),this.logger.debug(n.LogTagId.L_REQUEST_T,JSON.stringify({url:s.url,body:s.body,headers:s.headers}),r),[4,X(this.logger,s)];case 1:if(200!==(i=u.sent()).status)return this.logger.warn(n.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,code:i.status}),r),[2,{code:this.transHttpCode(i.status)}];try{return a=JSON.parse(i.data),c=/^https/.test(s.url)?"https":"http",a.protocol=c,[2,{code:n.ErrorCode.SUCCESS,data:a}]}catch(e){return this.logger.error(n.LogTagId.L_PARSE_NAVI_E,i.data,r),[2,{code:n.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.getNaviCache=function(e){var t=this.getCatchKey(e),o=this._caches[t];if(o)return o;if(!r.existsSync(this.naviPath))return null;var s=r.readFileSync(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(s),this._caches[t]}catch(e){this.logger.error(n.LogTagId.L_PARSE_NAVI_E,s)}return null},t.prototype.setNaviCache=function(e,t){var o=Date.now(),s=this.getCatchKey(e);if(n.notEmptyObject(this._caches))for(var i in this._caches){(o-this._caches[i].timestamp>n.NAVI_CACHE_DURATION||s===i)&&delete this._caches[i]}this._caches[s]={token:e,naviInfo:t,timestamp:Date.now(),environment:this._environment},r.writeFileSync(this.naviPath,JSON.stringify(this._caches))},t.prototype.setEnvironment=function(e){this._environment=e},t}(n.BasicNavi);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(ue||(ue={}));var le,Ce=function(e){function t(t,o,r,s,i,a){var c=e.call(this,t,r,s,i,a)||this;return c.addon=o,c._listener=a,c._connectedTime=0,c._naviInfo=null,c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.addon.setConnectionStatusListener(c._onConnectComplete.bind(c),(function(e){c.logger.info(y.P_DB_OPEN_O,e)}),(function(){return c.recvPong(n.ErrorCode.SUCCESS)}),c._onAddonDisconnected.bind(c),c._onTcpConnectResponse.bind(c),(function(e){c.logger.error(y.P_DB_OP_E,"Database operation failed with code: ".concat(e)),c._listener.onDatabaseOperationFailed(e)})),c}return S(t,e),t.prototype.getConnectedTime=function(){return this._connectedTime},t.prototype.connectWithToken=function(e,t,o,r){var s=this;return new Promise((function(i){s._naviInfo=t,s.connectResolve={resolve:i,traceId:r,userId:t.userId};var a={},c=$().data;c&&(a={proxy_passwd:c.socksPassword||"",proxy_name:c.socksUsername||"",proxy_port:c.socksPort||1082,proxy_host:c.socksHost||"localhost",proxy_type:0});var u=JSON.stringify(E(E({},a),{call_plus:s._openCallPlus})),p=s.getCmpList(t,!0).filter((function(e){return pe.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];p.forEach((function(e){var t=d.find((function(t){return t.addr===e.addr}));t?t.protocol!==Z.QUIC&&e.protocol!==Z.QUIC||(t.race=!0,t.protocol=Z.QUIC):(e.race=!1,d.push(e))}));var l=E(E({},t),{serverAddr:d});s.logger.info(y.P_CONNECT_T,JSON.stringify({use:d,catche:s.cmpWeightCache,proxy:a,FORMATED_VERSION:n.FORMATED_VERSION,reconnectKickEnable:o,naviInfo:l}),r),s._startTime=Date.now();try{s.addon.connectWithToken(e,n.FORMATED_VERSION,JSON.stringify(l),o,u)}catch(e){s.logger.error(y.P_CALL_ADDON_E,null==e?void 0:e.stack,r),s._onConnectComplete(n.ErrorCode.RC_SOCKET_NOT_CREATED)}}))},t.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.addon.disconnect(t)},t.prototype.sendPing=function(e){var t=this;return new Promise((function(o){t.pingResolve=o,t.addon.sendHeartbeat(),setTimeout((function(){return t.recvPong(n.ErrorCode.TIMEOUT)}),e)}))},t.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},t.prototype._onConnectComplete=function(e){if(this.connectResolve&&10!==e){var t=this.connectResolve,o=t.resolve,r=t.userId,s=t.traceId;this.logger.info(y.P_CONNECT_R,JSON.stringify({code:e,userId:r}),s);var i=Date.now()-(this._startTime+this._tcpDuration),a={bid:n.getbundleId(),cod:e,net:this.getNetwork().type,dur:i,spr:1,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:n.StatisticsVersion.CURRENT,count:this.retryCount};this.statisticLog.__statistics(n.StatisticsTag.IM_CMP_RMTP,JSON.stringify(a)),e===n.ErrorCode.SUCCESS&&(this._connectedTime=Date.now()-this.addon.getDeltaTime()),o({code:e,data:r}),this.connectResolve=null}},t.prototype._onAddonDisconnected=function(e,t){switch(this.logger.info(y.P_CONNECT_S,JSON.stringify({code:e,delay:t})),e){case n.ErrorCode.RC_CONN_REDIRECTED:this._handleDisconnected(n.ErrorCode.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case n.ErrorCode.CONNECTION_REFUSED:case n.ErrorCode.RC_SOCKET_DISCONNECTED:case n.ErrorCode.RC_SOCKET_NOT_CREATED:case n.ErrorCode.RC_CONN_ACK_TIMEOUT:case n.ErrorCode.RC_TCP_RESET:this._handleDisconnected(e,!1);break;case n.ErrorCode.RC_UDP_DISCONNECTED:this._handleDisconnected(e,!0,t);break;default:this._handleDisconnected(e,!0)}},t.prototype._handleDisconnected=function(e,t,o){if(t)this.onDisconnectByServer(e,o);else{if(e===n.ErrorCode.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==n.RCConnectionStatus.CONNECTED)return;this.onDisconenctUnusual(e)}},t.prototype._onTcpConnectResponse=function(e,t,o,r,s,i,a){var c,u=this.cmpWeightCache.findIndex((function(e){return e.addr==="".concat(t,":").concat(o)})),p={bid:n.getbundleId(),ptc:n.ProtocalType.TCP,cod:e,net:this.getNetwork().type,dur:r,spr:1,pr:(null===(c=this._naviInfo)||void 0===c?void 0:c.type)||0,hos:"".concat(t,":").concat(o),idx:u,rct:this.retryCount?n.ConnectType.RECONNECT:n.ConnectType.CONNECT,cid:"".concat(this.uuid,"_").concat(this.retryCount),v:n.StatisticsVersion.CURRENT,rsn:this.reason,ddu:s,count:this.retryCount,weight:this.cmpWeightCache[u].weight};this.statisticLog.__statistics(n.StatisticsTag.IM_CMP,JSON.stringify(p)),this.logger.info(y.P_CONNECT_ENTRY_S,JSON.stringify({code:e,host:t,port:o,duration:r,dnsDuration:s,index:i,isQuic:a})),e===ue.SUCCESS&&(this.curCmpUrl="".concat(t,":").concat(o),this.updateCmpWeight("".concat(t,":").concat(o),!0,a))},t}(n.AConnectionMgr),fe=function(t){if(!r.existsSync(t)){var o=e.resolve(t,"..");r.existsSync(o)||fe(o),r.mkdirSync(t)}},he=function(){function o(o,r,i,a,c){var u=this;this._appkey=o,this._cppProtocol=r,this._dbpath=i,this._logOutputLevel=a,this._httpRequestProxy=c,this._customMessageType={},this._senders={},this._chatroomCache=[],this.rtcHeartbeatResolves={};var p=this._dbpath||e.resolve(t.app.getPath("userData")),d=ie(p);this._cppProtocol.initWithAppkey(o,p,n.FORMATED_VERSION);var l=s.fork(e.resolve(__dirname,"sub-process.js"));this.subProxy=new ce(l);var C=e.resolve(p,"RongCloud/rclogs",o);fe(C),function(e,t,o){o.initLogModule(t,e,n.getUUID())}(o,C,this._cppProtocol),this.logger=new b(this._appkey,"RC-M","IM"),this.statisticLog=new x(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),O(this._cppProtocol,this.logger),this.reporter=new re(this._cppProtocol,o,d,this.logger,this.subProxy),this.logger.info(y.P_INIT_O,JSON.stringify({appkey:o,dbpath:p,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:d,commit:"b856cac2f213bdd4b672b83019bdcde51e22c6af"})),this._callCppProxy("setDeviceId",d);var f=e.resolve(p,"RongCloud/navis",o);fe(f),this.navi=new de(o,this.logger,this.statisticLog,f,this._cppProtocol,this._httpRequestProxy),this.tcpMgr=new Ce(o,this._cppProtocol,this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this),onDatabaseOperationFailed:function(e){u._send2AllRenderer("onDatabaseOperationFailed",e)}}),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setReadReceiptListener(),t.ipcMain.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];return m(u,void 0,void 0,(function(){var r,s,i;return P(this,(function(a){switch(a.label){case 0:if("function"!=typeof(r=this[t]))return this.logger.error(y.P_CALL_MAIN_SYNC_E,JSON.stringify({method:t,error:"not found"})),e.returnValue=n.ErrorCode.NOT_SUPPORT,[2];s=n.ErrorCode.EXTRA_METHOD_UNDEFINED,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,r.call.apply(r,T([this],o,!1))];case 2:return s=a.sent(),[3,4];case 3:return i=a.sent(),this.logger.error(y.P_CALL_MAIN_SYNC_E,JSON.stringify({error:null==i?void 0:i.stack,method:t})),[3,4];case 4:return e.returnValue=s,[2]}}))}))})),t.ipcMain.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,o){for(var r=[],s=3;s<arguments.length;s++)r[s-3]=arguments[s];return m(u,void 0,void 0,(function(){var s,i,a,c,u=this;return P(this,(function(p){switch(p.label){case 0:if("function"!=typeof(s=this[o]))return this.logger.error(y.P_CALL_MAIN_E,JSON.stringify({method:o,error:"not found"})),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,n.ErrorCode.NOT_SUPPORT),[2];"sendMessage"===o&&(i=r[3],r[3]=function(t){u._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",i,t)}),a=n.ErrorCode.EXTRA_METHOD_UNDEFINED,p.label=1;case 1:return p.trys.push([1,3,,4]),[4,s.call.apply(s,T([this],r,!1))];case 2:return a=p.sent(),[3,4];case 3:return c=p.sent(),this.logger.error(y.P_CALL_MAIN_E,JSON.stringify({error:null==c?void 0:c.stack,method:o})),[3,4];case 4:return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,a),[2]}}))}))})),t.ipcMain.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];var n=u[t];if("function"==typeof n)try{n.call.apply(n,T([u],o,!1))}catch(e){u.logger.error(y.P_SEND_2_MAIN_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}else u.logger.error(y.P_SEND_2_MAIN_E,JSON.stringify({method:t,error:"not found"}))})),t.ipcMain.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this)),this._msgExpansionHandler=new ae(this._cppProtocol)}return o.prototype.onConnected=function(){var e=this.getNaviInfoFromCache();this.reporter.checkStart(e),this._try2RejoinChatroom(),this._send2AllRenderer("onConnected",this.getMainProcessCache())},o.prototype.onConnecting=function(){this._send2AllRenderer("onConnecting",void 0)},o.prototype.onSuspend=function(e){this._send2AllRenderer("onSuspend",e)},o.prototype.onDisconnected=function(e){this._send2AllRenderer("onDisconnected",e)},o.prototype._callCppProxy=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this.logger.createTraceId();try{return this.logger.info(y.P_CALL_ADDON_O,JSON.stringify({method:e,args:o}),n),(t=this._cppProtocol)[e].apply(t,o)}catch(t){this.logger.error(y.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),n)}},o.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},o.prototype.sendHTTPRequest=function(e){return X(this.logger,e)},o.prototype.onRendererLogsReceived=function(e){M.apply(void 0,e)},o.prototype.onRendererNetworkStatusReceived=function(e,t){this.tcpMgr.setNetwork(e,t)},o.prototype.destroy=function(){var e;this.reporter.stop(),this.subProxy.destroy(),e=this._cppProtocol,N(),e.deinitLogModule(),this._cppProtocol.destroy()},o.prototype.callExtra=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];var r=this[e];if(!r)return this.logger.warn(y.P_CALL_EXTRA_E,JSON.stringify({method:e,error:"not found"})),Promise.resolve({code:n.ErrorCode.EXTRA_METHOD_UNDEFINED});try{return r.call.apply(r,T([this],t,!1))}catch(t){this.logger.error(y.P_CALL_EXTRA_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})},o.prototype.getConversationsByPage=function(e,t,o,r,s){var i,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",e,t,o,s||!1,r||"");try{i=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:i})},o.prototype.getUnreadConversationList=function(e){var t,o=this,r=this._callCppProxy("getUnreadConversationList",e);try{t=JSON.parse(r).list.map((function(e){return o._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:t})},o.prototype.getConversationListWithAllChannel=function(){var e,t=this,o=[n.ConversationType.PRIVATE,n.ConversationType.GROUP,n.ConversationType.SYSTEM,n.ConversationType.APP_PUBLIC_SERVICE,n.ConversationType.PUBLIC_SERVICE],r=this._callCppProxy("getConversationListWithAllChannel",o);try{e=JSON.parse(r).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:e})},o.prototype.getConversationListWithAllChannelByPage=function(e,t){var o,r=this,s=[n.ConversationType.PRIVATE,n.ConversationType.GROUP,n.ConversationType.SYSTEM,n.ConversationType.APP_PUBLIC_SERVICE,n.ConversationType.PUBLIC_SERVICE],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,e,t);try{o=JSON.parse(i).list.map((function(e){return r._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:o})},o.prototype.getHistoryMessagesByObjectNames=function(e,t,o,r,s,i,a){var c=0===i,u=r+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,o,u,s,c,a||""),d=[];try{var l=JSON.parse(p).list;l.reverse();for(var C=0;C<l.length;C++){var f=this._buildMessage(l[C].obj);d[C]=f}}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:{list:u===d.length?d.slice(1,u):d,hasMore:r<d.length}})},o.prototype.updateMessageReceiptStatus=function(e,t,o,r){void 0===r&&(r="");var s=this._callCppProxy("updateMessageReceiptStatus",e,t,o,r);return Promise.resolve({code:n.ErrorCode.SUCCESS,data:s})},o.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==n.RCConnectionStatus.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},o.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new b(this._appkey,e,t)},o.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},o.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},o.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},o.prototype._send2Renderer=function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,T([t],o,!1))},o.prototype._send2AllRenderer=function(e,t,o){var r=this;void 0===o&&(o=[]),Object.keys(this._senders).forEach((function(n){var s=r._senders[n];o.includes(s)||r._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},o.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),o=this.getNaviInfoFromCache(),r=this.tcpMgr.getCurrentUserId();return{connectedTime:e,deviceId:this.getDeviceId(),crtUserId:r,naviInfo:o,connectionStatus:t}},o.prototype._registerRenderers=function(e,t){var o=this,r=e.sender,s=r.id,i=t.navigators,a=t.areaCode,c=t.logServerUrl,u=t.environment;this._environment=u||"default",this.navi.setEnvironment(u),n.urlCenter.init({areaCode:a,navigators:i,logServerUrl:c}),this._senders[s]||(this._senders[s]=r,r.once("destroyed",(function(){delete o._senders[s]})))},o.prototype._registerMsgTypes=function(){for(var e in n.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},n.SEND_MESSAGE_TYPE_OPTION){var t=n.SEND_MESSAGE_TYPE_OPTION[e],o=t.isCounted,r=t.isPersited,s=t.searchProps,i=0;r&&(i|=1),o&&(i|=2),"RC:TypSts"===e&&(i=16),this._callCppProxy("registerMessageType",e,i,s||[])}},o.prototype._buildIsMentioned=function(e,t){var o,r=!1;if(n.isObject(e))o=e;else try{o=e?JSON.parse(e):e}catch(r){o=e,this.logger.error(y.P_PARSE_JSON_MSGS_E,JSON.stringify({messageId:t}))}return n.isObject(o)&&(r=!!o.mentionedInfo),{isMentioned:r,msgContent:o}},o.prototype._buildMsgOption=function(e){var t={isCounted:!1,isPersited:!1};return e in n.SEND_MESSAGE_TYPE_OPTION?t=n.SEND_MESSAGE_TYPE_OPTION[e]:e in this._customMessageType&&(t=this._customMessageType[e]),t},o.prototype._buildSupportExt=function(e,t){var o=null;return e&&(o=this._msgExpansionHandler.parseReceiveExpansion(t)),o},o.prototype._transICppMessage2IReceivedMessage=function(e,t){var o=e.channelId,r=e.conversationType,s=e.targetId,i=e.senderUserId,a=e.content,c=e.objectName,u=e.messageUid,p=e.direction,d=e.status,l=e.messageId,C=e.sentTime,f=e.readReceiptRequest,h=e.supportExt,g=e.pushContent,v=e.pushTitle,_=e.pushId,S=e.pushConfig,y=e.templateId,m=e.disableTitle,P=e.forcePushDetail,T=e.needReceipt,I=e.sendReceipt,R=this._buildIsMentioned(a,l),N=R.isMentioned,O=R.msgContent,M=this._buildMsgOption(c),U=this._buildSupportExt(h,e),w=n.isUndefined(t)?C<this.tcpMgr.getConnectedTime():t,b={};S&&(b=n.pushJSONToConfigs(this.logger,S,_));var x=E(E({},b),{pushTitle:v,pushContent:g,pushData:g,disablePushTitle:m,forceShowDetailContent:P,templateId:y}),A={channelId:o,conversationType:r,targetId:s,senderUserId:i,content:O||{},messageType:c,messageUId:u||"",messageDirection:p,isOffLineMessage:w,sentTime:C,receivedTime:0,isPersited:M.isPersited,isCounted:M.isCounted,isMentioned:N,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:h,expansion:h?U:null,receivedStatus:d,messageId:l,pushConfig:x,needReceipt:T,sentReceipt:I};p===n.MessageDirection.RECEIVE?A.receivedStatus=d:p===n.MessageDirection.SEND&&(A.sentStatus=d);var L=this.getNaviInfoFromCache();if(f&&1===(null==L?void 0:L.grpRRVer)){var D=JSON.parse(f),k=D.hasRespond,J=D.readerInfo,j={hasRespond:k,readCount:D.readCount,totalCount:D.totalCount},B=[];if(J)for(var F in J)B.push({userId:F,readTime:J[F]});j.readerList=B,A.readReceiptInfo=j}return A},o.prototype._buildMessage=function(e,t){void 0===t&&(t=!1);var o=JSON.parse(e);return this._transICppMessage2IReceivedMessage(o,t)},o.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),r=JSON.parse(o),n=r.readReceiptRequest?JSON.parse(r.readReceiptRequest):{},s=E(E({},n),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},o.prototype._transICppConversation2IReceivedConversation=function(e){var t=e.channelId,o=e.conversationType,r=e.targetId,s=e.unreadCount,i=e.lastestMsg,a=e.isTop,c=e.isBlocked,u=e.matchCount,p=e.hasUnreadMention,d=e.draft,l=e.conversationTime,C=c?n.NotificationStatus.OPEN:n.NotificationStatus.CLOSE;return{channelId:t,conversationType:o,targetId:r,unreadMessageCount:s,latestMessage:-1===JSON.parse(i).messageId?null:this._buildMessage(i),hasMentioned:p,mentionedInfo:null,notificationStatus:C,isTop:a,lastUnreadTime:0,matchCount:u,draft:d,operationTime:l}},o.prototype._buildConversation=function(e){var t=JSON.parse(e);return this._transICppConversation2IReceivedConversation(t)},o.prototype._convertResultList=function(e,t){var o=JSON.parse(e).list;return o=o.map((function(e){var o=JSON.parse(e.obj);return t?t(o):o}))},o.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,o,r,s){var i,a=e._buildMessage(t,r),c=a.messageType,u=a.channelId,p=void 0===u?"":u;if(c!==n.MessageType.LOG_COMMAND||"rongcloudsystem"!==a.senderUserId){if(c===n.MessageType.GROUP_READ_RECEIPT_REQUEST){var d=a.content,l=d.msgId,C=d.rrn,f=d.tmn;e._updateReadReceiptInfo(l,{readCount:C,totalCount:f})}if("RC:MsgExMsg"===c)return e._msgExpansionHandler.setLocalFromExtMsg(e.logger,a),void e._sendMessageExpansion(a);if(a.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(e.logger,a),c!==n.MessageType.SYNC_READ_STATUS||a.senderUserId===e.tcpMgr.getCurrentUserId()){(c===n.MessageType.SYNC_READ_STATUS||c===n.MessageType.READ_RECEIPT&&a.senderUserId===e.tcpMgr.getCurrentUserId())&&e._callCppProxy("clearUnreadCountByTimestamp",a.conversationType,a.targetId,a.content.lastMessageSendTime,p);var h=!0;if(0!==o||s||(h=!1),c===n.MessageType.DELIVERED)return e._callCppProxy("setMessageDeliverTime",JSON.stringify(a.content)),void e._sendMessageDelivered(a.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}})));if(c!==n.MessageType.DELIVERED_MSG){var g=a.conversationType,v=a.targetId;if(c===n.MessageType.RECALL){e.handleRecalledMessage(a);var _=e._fixRecallContentInfo(a);g=_.conversationType,v=_.targetId}e._sendMessageNotification(Object.assign(a,{hasMoreMsg:h,conversationType:g,targetId:v}))}else{var S={totalCount:a.content.tmn,list:null===(i=a.content.dl)||void 0===i?void 0:i.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};e._sendGroupMessageDeliveredStatus(S)}}}else{var y=a.content,E=y.startTime,m=y.endTime,P=y.platform,T=y.logId,I=y.uri;e.reporter.report(parseInt(E,10),parseInt(m,10),P,I,T,a.messageUId)}}),(function(){e._sendPullOfflineFinished()}))},o.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,o=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,o=e.content.targetId||o),{conversationType:t,targetId:o}},o.prototype.handleRecalledMessage=function(e,t){void 0===t&&(t=!1);var o=e.content.messageUId;if(o){var r=this._callCppProxy("getMessage",o),s=this._buildMessage(r);if(s.messageId){var i={recallTime:e.sentTime,admin:!!e.content.isAdmin,originalObjectName:s.messageType,originalMessageContent:s.content,recallActionTime:0,operatorId:e.senderUserId};t&&(i.recallActionTime=Date.now()),e.content.user&&(i.user=e.content.user),e.content.extra&&(i.extra=e.content.extra),s.messageType===n.MessageType.TextMessage&&(i.recallContent=s.content.content),e.content.isDelete?this._callCppProxy("deleteMessages",[s.messageId]):(s.receivedStatus!==n.ReceivedStatus.UNREAD&&s.receivedStatus!==n.ReceivedStatus.RETRIEVED||this.setMessageReceivedStatus(s.messageId,1),this._callCppProxy("setMessageContent",s.messageId,JSON.stringify(i),n.MessageType.RECALL_NOTIFICATION_MESSAGE))}}},o.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var o=e.channelId,r=e.content,n=r.put,s=r.del,i=r.mid,a={};n&&(a.updatedExpansion={channelId:o,messageUId:i,expansion:n}),s&&(a.deletedExpansion={channelId:o,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},o.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},o.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},o.prototype._sendMessageDelivered=function(e){this._send2AllRenderer("messageDelivered",e)},o.prototype._sendGroupMessageDeliveredStatus=function(e){this._send2AllRenderer("groupMessageDeliveredStatus",e)},o.prototype._sendChatroomStatus=function(e){this._send2AllRenderer("chatroom",e)},o.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var o=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj),o={channelId:t.channelId,conversationType:t.conversationType,targetId:t.targetId,updatedItems:{}};return t.status.forEach((function(e){var t=JSON.parse(e.item),r=t.type,s=t.value;if(1===r){var i=Number(s)||n.NotificationLevel.NOT_SET;o.updatedItems.notificationLevel={val:i,time:0},o.updatedItems.notificationStatus={val:n.transformNotificationLevel(i),time:0}}else 2===r&&(o.updatedItems.isTop={val:"1"===s,time:0})})),o}));e._send2AllRenderer("conversation",o)}),(function(t){e._send2AllRenderer("conversationTag",t)}))},o.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._send2AllRenderer("tag",t),e._getRTCProfile()}))},o.prototype._setReadReceiptListener=function(){var e=this;this._cppProtocol.setReadReceiptListener((function(t){try{var o=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId,messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));e._send2AllRenderer("messageReadReceipt",o)}catch(o){e.logger.info(y.P_PARSE_JSON_MSGS_E,t)}}))},o.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var o=this.navi.getNaviInfoFromCache(t);this._send2AllRenderer("onNaviDataChange",o)}},o.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var o=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",o)}))},o.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._sendChatroomStatus({chatroomDestroyed:t})}))},o.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){var o=[];try{JSON.parse(t).list.forEach((function(e){Object.entries(e).forEach((function(e){var t=e[0],r=e[1];o.push({key:t,value:r})}))}))}catch(t){e.logger.error(y.P_PARSE_JSON_E,null==t?void 0:t.stack)}e._send2AllRenderer("callInfo",JSON.stringify({list:o}))}))},o.prototype._updateMentionedInfo=function(e,t,o){var r,s,i;return{userIdList:(null===(r=e.mentionedInfo)||void 0===r?void 0:r.userIdList)||t,type:(null===(s=e.mentionedInfo)||void 0===s?void 0:s.type)||o||n.MentionedType.ALL,mentionedContent:(null===(i=e.mentionedInfo)||void 0===i?void 0:i.mentionedContent)||""}},o.prototype.registerMessageType=function(e,t,o,r){void 0===r&&(r=[]);var n=0;t&&(n|=1),o&&(n|=2),this._customMessageType[e]={isCounted:o,isPersited:t},this.logger.info(y.P_REGTYP_O,JSON.stringify({type:e,opt:n,search:r})),this._callCppProxy("registerMessageType",e,n,r)},o.prototype.connect=function(e,t,o,r){return this.tcpMgr.connect(e,t,o,r)},o.prototype.reportSDKInfo=function(e){var t,o,r=JSON.stringify(E(E({},e),{"electron-main":"5.8.2-enterprise-lz.30"}));this.logger.info(y.P_REPORT_VER_O,r),null===(o=(t=this._cppProtocol).uploadSDKVersion)||void 0===o||o.call(t,r)},o.prototype.disconnect=function(e){this._chatroomCache.length=0,this.reporter.stop(),z(null,this.logger),this.tcpMgr.disconnect(e)},o.prototype.logout=function(){this.disconnect()},o.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,o){t({userId:e,status:o})}));var o=e.userIds||[];o.length&&this.subscribeUserStatus(o)},o.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("subscribeUserStatus",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.setUserStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("setUserStatus",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.getUserStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("getUserStatus",e,(function(e){o({code:n.ErrorCode.SUCCESS,data:{status:e}})}),(function(e){o({code:e})}))}))},o.prototype.sendMessage=function(e,t,o,r,s){var i=this;void 0===s&&(s=this.logger.createTraceId());var a=o.messageType,c=o.content,u=o.expansion,p=o.pushConfig,d=o.isMentioned,l=o.mentionedType,C=o.mentionedUserIdList,f=void 0===C?[]:C,h=o.pushContent,g=void 0===h?"":h,v=o.pushData,_=void 0===v?"":v,S=o.directionalUserIdList,E=void 0===S?[]:S,m=o.disableNotification,P=void 0!==m&&m,T=o.canIncludeExpansion,I=void 0!==T&&T,R=o.isVoipPush,N=void 0!==R&&R,O=o.channelId,M=void 0===O?"":O,U=o.messageId,w=void 0===U?0:U,b=o.encrypted,x=void 0!==b&&b,A=o.needReceipt,L=void 0!==A&&A,D=p||{},k=D.iOSConfig,J=D.androidConfig,j=D.templateId,B=void 0===j?"":j,F=D.pushTitle,H=void 0===F?"":F,V=D.pushContent,q=void 0===V?g:V,G=D.pushData,K=void 0===G?_:G,W=D.disablePushTitle,Q=void 0!==W&&W,Y=D.forceShowDetailContent,X=void 0!==Y&&Y,z=n.pushConfigsToJSON(k,J);return new Promise((function(o){g=q,_=K;var p=(null==J?void 0:J.notificationId)||"";e===n.ConversationType.GROUP&&d&&c&&(c.mentionedInfo=i._updateMentionedInfo(c,f,l));var C=e===n.ConversationType.GROUP;if(C&&a===n.MessageType.READ_RECEIPT_RESPONSE&&c.receiptMessageDic)for(var h in c.receiptMessageDic)E.push(h);C&&a===n.MessageType.SYNC_READ_STATUS&&(E=[i.getCurrentUserId()]);var v={};for(var h in u)v[h]={v:""},v[h].v=u[h];var S=B;i.logger.info(y.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:e,targetId:t,channelId:M,messageId:w}),s);var m=i._callCppProxy("sendMessage",(function(e,t){var r=i._buildMessage(e);return i.logger.info(y.P_SEND_MSG_R,JSON.stringify({code:t,messageUId:r.messageUId,messageId:r.messageId}),s),t===n.ErrorCode.SENSITIVE_REPLACE?o({code:t}):("RC:MsgExMsg"===r.messageType&&i._msgExpansionHandler.setLocalFromExtMsg(i.logger,r),r.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(i.logger,r),o({code:n.ErrorCode.SUCCESS,data:r}))}),(function(e,t){var r=i._buildMessage(e);return i.logger.warn(y.P_SEND_MSG_R,JSON.stringify({code:t,messageId:r.messageId}),s),r.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),o({code:t,data:r})}),e,t,a,JSON.stringify(c),E,P,Q,X,g,_,p,H,z,S,I,JSON.stringify(v),N,M,w,x,L),T=JSON.parse(m);null==r||r(T.messageId)}))},o.prototype.recallMsg=function(e,t,o,r,s){var i=this;return new Promise((function(a,c){var u,p=s.user,d=s.pushContent,l=s.channelId,C=s.extra,f=s.pushConfig,h=s.disableNotification,g=s.isDelete,v={conversationType:e,targetId:t,messageUId:o,sentTime:r,user:p,extra:C,channelId:l,isDelete:g||!1};p&&(v.user=p),C&&(v.extra=C);i._callCppProxy("recallMessage",(function(r){var s={conversationType:e,targetId:t,senderUserId:i.tcpMgr.getCurrentUserId(),content:v,objectName:n.MessageType.RECALL,messageUid:o,direction:n.MessageDirection.SEND,status:n.ReceivedStatus.UNREAD,sentTime:Number(r),channelId:l},c=i._buildMessage(JSON.stringify(s));i.handleRecalledMessage(c,!0),a({code:n.ErrorCode.SUCCESS,data:c})}),(function(e){a({code:e})}),n.MessageType.RECALL,JSON.stringify(v),h||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,d||"",(null==f?void 0:f.pushData)||"",(null===(u=null==f?void 0:f.androidConfig)||void 0===u?void 0:u.notificationId)||"",(null==f?void 0:f.pushTitle)||"",n.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",l)}))},o.prototype.getHistoryMessage=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(u,p){o=o||0;var d=0===s,l=r+1,C=c._callCppProxy("getHistoryMessages",e,t,o,l,a,d,i),f=JSON.parse(C).list,h=[];f.reverse();for(var g=0;g<f.length;g++){var v=c._buildMessage(f[g].obj);h[g]=v}u({code:n.ErrorCode.SUCCESS,data:{list:l===h.length?h.slice(1,l):h,hasMore:r<h.length}})}))},o.prototype.getRemoteHistoryMessages=function(e,t,o,r,s,i){var a=this;return new Promise((function(c,u){o=o||0;a._callCppProxy("getRemoteHistoryMessages",e,t,o,r,(function(e,t){var o=JSON.parse(e).list,r=[];o.reverse();for(var s=0;s<o.length;s++){var i=a._buildMessage(o[s].obj);r[s]=i}c({code:n.ErrorCode.SUCCESS,data:{list:r,hasMore:!!t}})}),(function(e){c({code:e})}),s,!0,i)}))},o.prototype.deleteRemoteMessage=function(e,t,o,r){var s=this;return new Promise((function(i,a){var c=JSON.stringify(o);s._callCppProxy("deleteRemoteHistoryMessages",e,t,c,!1,r,(function(){i(n.ErrorCode.SUCCESS)}),i)}))},o.prototype.deleteRemoteMessageByTimestamp=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearRemoteHistoryMessages",e,t,o,(function(){i(n.ErrorCode.SUCCESS)}),(function(e){i(e)}),r)}))},o.prototype.clearMessages=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearMessages",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.getConversationList=function(e,t,o,r,s){var i=this;return void 0===s&&(s=""),new Promise((function(e,t){for(var o=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(o).list,a=[],c=0;c<r.length;c++)a.push(i._buildConversation(r[c].obj));e({code:n.ErrorCode.SUCCESS,data:a})}))},o.prototype.getConversation=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversation",e,t,o);if(a)s({code:n.ErrorCode.SUCCESS,data:r._buildConversation(a)});else{var c=r._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,o),u=void 0;try{u=JSON.parse(c).list}catch(e){r.logger.error(y.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),u=[]}var p=null;u.length>0&&(p=r._buildMessage(u[0].obj));var d=r._callCppProxy("getConversationNotificationStatus",e,t,o),l=r._callCppProxy("getConversationTopStatus",e,t,o);s({code:n.ErrorCode.SUCCESS,data:{conversationType:e,targetId:t,channelId:o,unreadMessageCount:0,latestMessage:p,notificationStatus:d?n.NotificationStatus.OPEN:n.NotificationStatus.CLOSE,isTop:Boolean(l),lastUnreadTime:0}})}}))},o.prototype.removeConversation=function(e,t,o){var r=this._callCppProxy("removeConversation",e,t,o);return Promise.resolve(r?n.ErrorCode.SUCCESS:n.ErrorCode.UNKNOWN)},o.prototype.clearConversations=function(e,t){var o=this;return new Promise((function(r,s){var i=[];i=n.isArray(e)?e:[n.ConversationType.PRIVATE,n.ConversationType.GROUP,n.ConversationType.SYSTEM,n.ConversationType.PUBLIC_SERVICE],o._callCppProxy("clearConversations",i,t),r(n.ErrorCode.SUCCESS)}))},o.prototype.getAllConversationUnreadCount=function(e,t,o){var r=this._callCppProxy("getTotalUnreadCount",t,o,e);return Promise.resolve({code:n.ErrorCode.SUCCESS,data:r})},o.prototype.getConversationUnreadCount=function(e,t,o){var r=this;return void 0===o&&(o=""),new Promise((function(s){var i=r._callCppProxy("getUnreadCount",e,t,o);s({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.clearConversationUnreadCount=function(e,t,o){var r=this;return void 0===o&&(o=""),new Promise((function(s,i){r._callCppProxy("clearUnreadCount",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.clearUnreadCountByTimestamp=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearUnreadCountByTimestamp",e,t,o,r),i(n.ErrorCode.SUCCESS)}))},o.prototype.getFirstUnreadMessage=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getTheFirstUnreadMessage",e,t,o),c=r._buildMessage(a);s({code:n.ErrorCode.SUCCESS,data:-1!==c.messageId?c:null})}))},o.prototype.setConversationToTop=function(e,t,o,r){var s=this;return void 0===r&&(r=""),new Promise((function(i,a){s._callCppProxy("setConversationToTop",e,t,o,r,!0),i(n.ErrorCode.SUCCESS)}))},o.prototype.setConversationHidden=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("setConversationHidden",e,t,o,r),i(n.ErrorCode.SUCCESS)}))},o.prototype.setConversationNotificationStatus=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("setConversationNotificationStatus",e,t,o,(function(){i(n.ErrorCode.SUCCESS)}),i,r)}))},o.prototype.setConversationStatus=function(e,t,o,r,s,i){var a=this;return new Promise((function(c,u){a._callCppProxy("setConversationStatus",e,t,o,r,(function(){c(n.ErrorCode.SUCCESS)}),c,s,!0,i)}))},o.prototype.getConversationNotificationStatus=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversationNotificationStatus",e,t,o);s({code:n.ErrorCode.SUCCESS,data:a?n.NotificationStatus.OPEN:n.NotificationStatus.CLOSE})}))},o.prototype.setConversationTypeNotificationLevel=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("setBlockPushLevelForType",e,t,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.getConversationTypeNotificationLevel=function(e){var t=this;return new Promise((function(o,r){var s=t._callCppProxy("getBlockPushLevelForType",e);o({code:n.ErrorCode.SUCCESS,data:s})}))},o.prototype.searchConversationByContent=function(e,t,o,r,s){var i=this;return new Promise((function(a){r=r||[1,3,6,7],i._callCppProxy("searchConversationsByContentIncludeDeleted",r,e,t,o,!!s,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return i._transICppConversation2IReceivedConversation(e)}));a({code:n.ErrorCode.SUCCESS,data:o})}else a({code:e})}))}))},o.prototype.searchConversationsByPage=function(e,t){var o=this,r=e.conversationTypes,s=e.keyword,i=e.messageTypes,a=e.includeDeleted,c=e.startTime,u=e.count;return new Promise((function(e){o.logger.info(y.P_SEARCH_CONVERSATIONS_T,"start",t),o._callCppProxy("searchConversationsByContentIncludeDeletedByPage",r,s,i||[],"",!!a,(function(r,s,i){if(o.logger.info(y.P_SEARCH_CONVERSATIONS_R,JSON.stringify({code:r}),t),r===n.ErrorCode.SUCCESS){var a=JSON.parse(s).map((function(e){return o._transICppConversation2IReceivedConversation(e)}));o.logger.info(y.L_FORMAT_CONVERSATIONS_S,"done",t),e({code:n.ErrorCode.SUCCESS,data:{list:a,totalCount:i}})}else e({code:r})}),c,u),o.logger.info(y.L_JS_GET_NOW_TIME_S,Date.now(),t)}))},o.prototype.searchConversationByContentWithAllChannel=function(e,t,o){var r=this;return new Promise((function(s,i){o=o||[1,3,6,7],r._callCppProxy("searchConversationByContentWithAllChannel",o,e,t,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return r._transICppConversation2IReceivedConversation(e)}));s({code:n.ErrorCode.SUCCESS,data:o})}else s({code:e})}))}))},o.prototype.searchMessageByContent=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(i,u){c._callCppProxy("searchMessageByContent",e,t,o,r,s,!0,(function(e,t,o){if(e===n.ErrorCode.SUCCESS){var r=JSON.parse(t).map((function(e){return c._transICppMessage2IReceivedMessage(e)}));i({code:n.ErrorCode.SUCCESS,data:{messages:r,count:o}})}else i({code:e})}),a)}))},o.prototype.searchMessageByContentAndMessageType=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByContentAndObjectName",t,e,a||"",void 0===a,o,i,s,r,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return c._transICppMessage2IReceivedMessage(e)}));u({code:n.ErrorCode.SUCCESS,data:{messages:o}})}else u({code:e})}))}))},o.prototype.searchMessagesByUser=function(e,t,o,r,s,i){var a=this;return new Promise((function(c,u){a._callCppProxy("getMessageBySender",e,t,o,r,s,i,(function(e){for(var t=e?JSON.parse(e).list:[],o=[],r=0;r<t.length;r++)o[r]=a._buildMessage(t[r].obj);c({code:n.ErrorCode.SUCCESS,data:{messages:o}})}))}))},o.prototype.searchMessageByContentWithAllChannel=function(e,t,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("searchMessageByContentWithAllChannel",e,t,o,r,s,!0,(function(e,t,o){if(e===n.ErrorCode.SUCCESS){var r=JSON.parse(t).map((function(e){return i._transICppMessage2IReceivedMessage(e)}));a({code:n.ErrorCode.SUCCESS,data:{messages:r,count:o}})}else a({code:e})}))}))},o.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,o,r,s,i,a){var c=this;return new Promise((function(u,p){c._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,o,r,s,i,a,(function(e,t){if(e===n.ErrorCode.SUCCESS){var o=JSON.parse(t).map((function(e){return c._transICppMessage2IReceivedMessage(e)}));u({code:n.ErrorCode.SUCCESS,data:{messages:o}})}else u({code:e})}))}))},o.prototype.getUnreadMentionedMessages=function(e,t,o){for(var r=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,o)).list,n=0;n<r.length;n++)r[n]=this._buildMessage(r[n].obj);return r},o.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("addToBlacklist",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("removeFromBlacklist",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,o){e._callCppProxy("getBlacklist",(function(e){t({code:n.ErrorCode.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},o.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("getBlacklistStatus",e,(function(e){o({code:n.ErrorCode.SUCCESS,data:e})}),(function(e){o({code:e})}))}))},o.prototype.insertMessage=function(e,t,o){var r=this,s=o.content,i=o.senderUserId,a=o.messageType,c=o.messageDirection,u=o.readStatus,p=o.sentStatus,d=o.sentTime,l=o.searchContent,C=o.isUnread,f=o.messageUId,h=o.disableNotification,g=o.canIncludeExpansion,v=o.expansionMsg,_=o.channelId;s=JSON.stringify(s);var S={};if(d=d||0,v){var y=JSON.parse(v);for(var E in y)S[E]={v:"",ts:0},S[E].v=y[E],S[E].ts=d}return new Promise((function(o,v){var y=C?0:1,E=r._callCppProxy("insertMessage",e,t,i,a,s,(function(){}),(function(e){o({code:e})}),c,u||0,p||10,d,l||"",y,f||"",!!h,!!g,JSON.stringify(S),_||""),m=r._buildMessage(E);m.messageUId=f,m.sentTime=d,o({code:-1===m.messageId?n.ErrorCode.MSG_INSERT_ERROR:n.ErrorCode.SUCCESS,data:m})}))},o.prototype.batchInsertMessage=function(e,t){var o=this;return void 0===t&&(t=!1),new Promise((function(r){var s=e.map((function(e){var t=e.content,o=e.senderUserId,r=e.messageType,n=e.messageDirection,s=e.receivedStatus,i=e.sentStatus,a=e.sentTime,c=e.searchContent,u=e.isUnread,p=e.messageUId,d=e.disableNotification,l=e.canIncludeExpansion,C=e.expansion,f=e.channelId,h=e.conversationType,g=e.targetId,v=e.source,_=e.isMentioned,S={};if(a=a||0,C)for(var y in C)S[y]={v:"",ts:0},S[y].v=C[y],S[y].ts=a;return{conversationType:h,targetId:g,channelId:f||"",direction:n,senderUserId:o,status:i||10,sentTime:a,objectName:r,content:JSON.stringify(t),messageUid:p||"",noNotification:!!d,supportExt:!!l,extMsg:JSON.stringify(S),readStatus:s||0,searchContent:c||"",isUnread:!!u,source:v||"",isMention:_}})),i=o._callCppProxy("insertMessages",JSON.stringify(s),t);r({code:i?n.ErrorCode.SUCCESS:n.ErrorCode.MSG_INSERT_ERROR,data:i||!1})}))},o.prototype.getMessageCount=function(e,t,o){var r=this;return new Promise((function(s){var i=r._callCppProxy("getMessageCount",e,t,o);s({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.deleteMessages=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("deleteMessages",e),o(n.ErrorCode.SUCCESS)}))},o.prototype.deleteMessagesByTimestamp=function(e,t,o,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("deleteMessagesByTimestamp",e,t,o,r,s),a(n.ErrorCode.SUCCESS)}))},o.prototype.getMessage=function(e){var t=this;return new Promise((function(o,r){var s=t._callCppProxy("getMessage",e),i=t._buildMessage(s);o({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.setMessageContent=function(e,t,o){var r=this;return new Promise((function(s,i){t=JSON.stringify(t),r._callCppProxy("setMessageContent",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.setMessageSearchField=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setMessageSearchField",e,t,o),s(n.ErrorCode.SUCCESS)}))},o.prototype.setMessageSentStatus=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageSentStatus",e,t),r(n.ErrorCode.SUCCESS)}))},o.prototype.setMessageReceivedStatus=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageReceivedStatus",e,t),r(n.ErrorCode.SUCCESS)}))},o.prototype.saveConversationMessageDraft=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("saveTextMessageDraft",e,t,o,r||"")&&i(n.ErrorCode.SUCCESS),i(n.ErrorCode.DRAF_SAVE_ERROR)}))},o.prototype.getConversationMessageDraft=function(e,t,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getTextMessageDraft",e,t,o||"");s({code:n.ErrorCode.SUCCESS,data:a})}))},o.prototype.clearConversationMessageDraft=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearTextMessageDraft",e,t,o||"")&&s(n.ErrorCode.SUCCESS),s(n.ErrorCode.DRAF_REMOVE_ERROR)}))},o.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},o.prototype.batchSetConversationStatus=function(e){var t=e[0],o=t.conversationType,r=t.targetId,s=t.isTop,i=t.notificationLevel,a=t.channelId,c=t.isUpdateTime,u=void 0===c||c,p=this._callCppProxy("getConversationNotificationStatus",o,r,a||""),d=this._callCppProxy("getConversationTopStatus",o,r,a||""),l=n.isUndefined(i)?Boolean(p):i>n.NotificationLevel.NOT_SET,C=n.isUndefined(s)?Boolean(d):s;return this.setConversationStatus(o,r,l,C,a,u)},o.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},o.prototype.sendReadReceiptMessage=function(e,t,o){var r=this;return new Promise((function(s){r._callCppProxy("sendReadReceipt",e,o||"",t,(function(){t.forEach((function(e){r._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(r._callCppProxy("getMessage",e)).messageId;r.setMessageReceivedStatus(t,1)}catch(t){r.logger.error(y.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),s({code:n.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},o.prototype.getMessageReader=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getMessageReader",e,o,t,(function(e,o){var i=[],a={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;i.push({userId:o,readTime:r}),a[o]=r}));var c={readerInfo:a,readCount:i.length,totalCount:o};r._updateReadReceiptInfo(t,c),s({code:n.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:o}})}),(function(e){s({code:e})}))}))},o.prototype.sendReadReceipt=function(e,t){var o=this;return new Promise((function(r,s){var i=e.conversationType,a=e.targetId,c=e.channelId,u=void 0===c?"":c,p=o._callCppProxy("sendReadReceiptByReadReceiptType",i,a,u,0,t.map((function(e){return e.messageUId})),(function(e){e===n.ErrorCode.SUCCESS&&t.forEach((function(e){o.setMessageReceivedStatus(e.messageId,n.ReceivedStatus.READ)})),r({code:e})}));p!==n.ErrorCode.SUCCESS&&r({code:p})}))},o.prototype._addChatroomCache=function(e,t,o){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:o,count:t})},o.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},o.prototype._try2RejoinChatroom=function(){var e=this;if(0!==this._chatroomCache.length){var t=this.logger.createTraceId();this._chatroomCache.forEach((function(o){return m(e,void 0,void 0,(function(){var e,r,s,i;return P(this,(function(a){switch(a.label){case 0:return e=o.chatroomId,r=o.joinExist,s=o.count,this.logger.info(n.LogTagId.L_REJOIN_CHATROOM_T,e,t),[4,this._joinChrm(e,s,r,!1)];case 1:return(i=a.sent())===n.ErrorCode.SUCCESS?(this.logger.info(n.LogTagId.L_REJOIN_CHATROOM_R,e,t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,count:s}}),[2]):(i===n.ErrorCode.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(e),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,errorCode:i}}),this.logger.warn(n.LogTagId.L_REJOIN_CHATROOM_R,"chrmId: ".concat(e,", code: ").concat(i),t),[2])}}))}))}))}},o.prototype._joinChrm=function(e,t,o,r){var s=this,i=o?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){r&&s._callCppProxy("clearMessages",n.ConversationType.CHATROOM,e,""),s._callCppProxy(i,e,t,(function(){s._addChatroomCache(e,t,o),a(n.ErrorCode.SUCCESS)}),a)}))},o.prototype.joinChatroom=function(e,t){return this._joinChrm(e,t,!1,!0)},o.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},o.prototype.quitChatroom=function(e){var t=this;return this._rmChatroomCache(e),new Promise((function(o,r){t._callCppProxy("quitChatRoom",e,(function(){o(n.ErrorCode.SUCCESS)}),o)}))},o.prototype.getChatroomInfo=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomInfo",e,t,o,(function(e,t){var o=e?JSON.parse(e).list:[],r=[];if(o.length>0)for(var i=0;i<o.length;i++)r.push(JSON.parse(o[i].obj));s({code:n.ErrorCode.SUCCESS,data:{userInfos:r,userCount:t}})}),(function(e){s({code:e})}))}))},o.prototype.getChatroomHistoryMessages=function(e,t,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("getChatroomHistoryMessage",e,t,o,r,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var o=t.list;if(o&&o.length)try{t.list=o.map((function(e){return s._buildMessage(e.obj)}))}catch(e){t.list=[]}i({code:n.ErrorCode.SUCCESS,data:t})}),(function(e){i({code:e})}),"")}))},o.prototype.setChatroomEntry=function(e,t){var o=this;return new Promise((function(r,s){var i='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');o._callCppProxy("setChatroomKV",e,i,!!t.isAutoDelete,!!t.isOverwrite,(function(){r(n.ErrorCode.SUCCESS)}),(function(e){r(e)}))}))},o.prototype.setChatroomEntries=function(e,t){var o=this;return new Promise((function(r){o._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},o.prototype.removeChatroomEntry=function(e,t){var o=this,r=[t.key];return new Promise((function(s,i){o._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){s(n.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},o.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},o.prototype.removeChatroomEntries=function(e,t){var o=this;return new Promise((function(r){var s=t.entries.map((function(e){return e.key}));o._callCppProxy("deleteChatroomKV",e,s,!!t.isOverwrite,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.getChatroomEntry=function(e,t){return m(this,void 0,void 0,(function(){var o;return P(this,(function(r){switch(r.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(o=r.sent()).code===n.ErrorCode.SUCCESS?[2,{code:n.ErrorCode.SUCCESS,data:o.data?o.data[t]:null}]:[2,{code:o.code}]}}))}))},o.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}o({code:n.ErrorCode.SUCCESS,data:t})}),(function(e){o({code:e})}))}))},o.prototype.getFileToken=function(e,t,o,r,s){var i=this;return void 0===s&&(s=""),o=o||"",r=r||"",new Promise((function(a){var c;c=r&&"uploads"!==r?t||"":n.getUploadFileName(e,t);var u=i.getNaviInfoFromCache(),p={uploadDomain:n.getMinionURL(u,i.logger),env:i._environment};i._callCppProxy("getUploadToken",e,c,o,r,s,JSON.stringify(p),(function(e,t,o,r,s,i,u,p,d,l,C,f,h,g,v,_,S,y,E,m,P,T,I){a({code:n.ErrorCode.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:o,path:r,osskeyId:s,ossPolicy:i,ossSign:u,ossBucketName:p,fileName:c,s3Credential:d,s3Algorithm:l,s3Date:C,s3Policy:f,s3Signature:h,s3BucketName:g,stcAuthorization:v,stcContentSha256:_,stcDate:S,stcBucketName:y,minioAuthorization:E,minioContentSha256:m,minioDate:P,minioBucketName:T,downloadAuthInfo:I?JSON.parse(I):null}})}),(function(e){a({code:e})}))}))},o.prototype.getFileUrl=function(e,t,o,r){var s=this;return new Promise((function(i){var a=s.getNaviInfoFromCache(),c={url:n.getMinionURL(a,s.logger)};s._callCppProxy("getDownloadUrl",e,o,r,t-1,JSON.stringify(c),(function(e){i({code:n.ErrorCode.SUCCESS,data:{downloadUrl:e}})}),(function(e){i({code:e})}))}))},o.prototype.clearData=function(){var e=this;return new Promise((function(t,o){var r=e._callCppProxy("clearData");t({code:n.ErrorCode.SUCCESS,data:r})}))},o.prototype.getDeviceId=function(){var o=this._dbpath||e.resolve(t.app.getPath("userData"));return ie(o)},o.prototype.getVoIPKey=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("getVoIPKey",e,t,"",(function(e){r({code:n.ErrorCode.SUCCESS,data:e})}),(function(e){r({code:e})}))}))},o.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(o,r){var s=e.chatRoomId,i=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",s,i,(function(){o(n.ErrorCode.SUCCESS)}),(function(e){o(e)}))}))},o.prototype.getGroupMessageDeliverList=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getGroupMessageDeliverList",e,o,t,(function(e,t){var o=JSON.parse(e).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));s({code:n.ErrorCode.SUCCESS,data:{totalCount:t,list:o}})}),(function(e){s({code:e})}))}))},o.prototype.getPrivateMessageDeliverTime=function(e,t){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getMessageDeliverTime",e);if(i)r({code:n.ErrorCode.SUCCESS,data:i});else{o._callCppProxy("getPrivateMessageDeliverList",t,e,(function(e){var t=0,o=JSON.parse(e).list;o.length>0&&(t=JSON.parse(o[0].obj).time);r({code:n.ErrorCode.SUCCESS,data:t})}),(function(e){r({code:e})}))}}))},o.prototype.rtcSignaling=function(e,t,o,r){var s=this,i=Array.prototype.slice.call(new Uint8Array(r));return new Promise((function(r){s._callCppProxy("rtcSignaling",e,t,o,i,(function(e){var t=new Uint8Array(e).buffer;r({code:n.ErrorCode.SUCCESS,buffer:t})}),(function(e){r({code:e})}))}))},o.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,o){var r=e.rtcHeartbeatResolves[t];if(r){var n=r.find((function(e){return""===e.seqId}));n&&(n.seqId=o)}}),(function(t,o,r,n){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===r}));-1!==i&&s.splice(i,1)[0].resolve({code:o,data:{version:Number(n)}})}}))},o.prototype.rtcPing=function(e,t,o){var r=this;return new Promise((function(t){var o={resolve:t,seqId:""},n=r.rtcHeartbeatResolves[e];n?n.push(o):r.rtcHeartbeatResolves[e]=[o],r._callCppProxy("sendRTCHeartbeat",[e])}))},o.prototype.createTag=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){o({code:n.ErrorCode.SUCCESS})}),(function(e){o({code:e})}))}))},o.prototype.removeTag=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("deleteTag",e,(function(){o({code:n.ErrorCode.SUCCESS})}),(function(e){o({code:e})}))}))},o.prototype.updateTag=function(e){var t=this;return new Promise((function(o,r){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){o({code:n.ErrorCode.SUCCESS})}),(function(e){o({code:e})}))}))},o.prototype.getTagList=function(){var e=this;return new Promise((function(t,o){var r=e._callCppProxy("getTags"),s=e._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:n.ErrorCode.SUCCESS,data:s})}))},o.prototype.addTagForConversations=function(e,t){var o=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));o._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.removeTagForConversations=function(e,t){var o=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),o._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.removeTagsForConversation=function(e,t){var o=this;return new Promise((function(r,s){o._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){r({code:n.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},o.prototype.getConversationListByTag=function(e,t,o,r){var s=this;return new Promise((function(i){var a=s._callCppProxy("getConversationsForTagByPage",e,t,o||20,r||""),c=s._convertResultList(a,(function(e){return E(E({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:n.ErrorCode.SUCCESS,data:c})}))},o.prototype.getUnreadCountByTag=function(e,t){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversationUnreadCountForTag",e,t);r({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.setConversationStatusInTag=function(e,t,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",o.isTop||!1,(function(){s({code:n.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},o.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(o,r){var s=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||""),i=t._convertResultList(s,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));o({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},o.prototype.getTopConversationList=function(e,t){var o=this;return new Promise((function(r){var s=n.isUndefined(t)?o._callCppProxy("getTopConversations",e):o._callCppProxy("getTopConversations",e,t),i=JSON.parse(s).list.map((function(e){return o._buildConversation(e.obj)}));r({code:n.ErrorCode.SUCCESS,data:i})}))},o.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},o.prototype.getAllUnreadMentionedCount=function(){var e=this;return new Promise((function(t){var o=e._callCppProxy("getUnreadAndMentionCount",[n.ConversationType.GROUP],"");t({code:n.ErrorCode.SUCCESS,data:o})}))},o.prototype.getOSInfo=function(){return m(this,void 0,void 0,(function(){var e;return P(this,(function(t){return e={arch:f.arch(),platform:f.platform(),type:f.type(),version:f.version(),release:f.release(),uptime:f.uptime(),cpus:f.cpus(),freemem:f.freemem(),totalmem:f.totalmem(),networkInterfaces:f.networkInterfaces()},[2,{code:n.ErrorCode.SUCCESS,data:e}]}))}))},o.prototype.getMainProcessInfo=function(){return m(this,void 0,void 0,(function(){return P(this,(function(e){return[2,{code:n.ErrorCode.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},o.prototype.setCallInfo=function(e,t,o){var r=this;return new Promise((function(s){r._callCppProxy("callInfoSignaling",e,t,o,(function(e,t){s({code:n.ErrorCode.SUCCESS,data:{key:e,value:t}})}),(function(e){s({code:e})}))}))},o.prototype.setProxy=function(e){return this.tcpMgr.getConnectionStatus()!==n.RCConnectionStatus.DISCONNECTED?Promise.resolve({code:n.ErrorCode.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(z(e,this.logger))},o.prototype.getProxy=function(){return Promise.resolve($())},o.prototype.testProxy=function(e,t){return function(e,t,o){return new Promise((function(r){var s=/^https/.test(t)?Q:G;o.info(n.LogTagId.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:e,testHost:t}));var i=s(t,e,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var o="";e.on("data",(function(e){o+=e})),e.once("end",(function(){r({status:t||0,data:o})}))}));i.once("timeout",(function(){return r({status:0})})),i.once("error",(function(e){return r({status:0,data:e.stack})})),i.end()}))}(e,t,this.logger)},o.prototype.checkDuplicateMessage=function(e){var t=this;return new Promise((function(o){t._callCppProxy("checkDuplicateMessage",e),o({code:n.ErrorCode.SUCCESS})}))},o.prototype.initAndOpenDatabase=function(e){var t=this;return new Promise((function(o){t._callCppProxy("initAndOpenDatabase",e),o({code:n.ErrorCode.SUCCESS})}))},o.prototype.closeDatabase=function(){var e=this;return new Promise((function(t){e._callCppProxy("closeDatabase"),t({code:n.ErrorCode.SUCCESS})}))},o.prototype.getMessagesByObjectNamesAcrossConversations=function(e,t,o,r,s,i,a,c){var u=0===i,p=a+1,d=this._callCppProxy("getMessagesByObjectNamesAcrossConversations",c,e,t,o,r,s,u,p),l=[];try{var C=JSON.parse(d).list;C.reverse();for(var f=0;f<C.length;f++){var h=this._buildMessage(C[f].obj);l[f]=h}}catch(e){return Promise.resolve({code:n.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:n.ErrorCode.SUCCESS,data:{list:p===l.length?l.slice(1,p):l,hasMore:a<l.length}})},o.prototype.getReadReceiptUsers=function(e,t){var o=this;return new Promise((function(r){var s=o._callCppProxy("getReadReceiptUsersByUid",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t,s){var i,a;try{var c=JSON.parse(t).list,u=JSON.parse(s).list;i=c.map((function(e){return JSON.parse(e.obj)})),a=u.map((function(e){return JSON.parse(e.obj)})),r({code:e,data:{userInfoRead:i,userInfoUnread:a}})}catch(e){o.logger.error(y.P_PARSE_JSON_MSGS_E,t,s),r({code:n.ErrorCode.MAIN_PROCESS_ERROR})}}));s!==n.ErrorCode.SUCCESS&&r({code:s})}))},o.prototype.getMessageReadReceiptInfos=function(e,t){var o=this;return new Promise((function(r){var s=o._callCppProxy("getReadReceiptCount",e.conversationType,e.targetId,e.channelId||"",t,(function(e,t){try{var s=JSON.parse(t).list.map((function(e){var t=JSON.parse(e.obj);return{messageUId:t.msgUId,totalCount:t.totalCount,readCount:t.readCount}}));r({code:e,data:s})}catch(e){o.logger.error(y.P_PARSE_JSON_MSGS_E,t),r({code:n.ErrorCode.MAIN_PROCESS_ERROR})}}));s!==n.ErrorCode.SUCCESS&&r({code:s})}))},o}(),ge=function(){function e(e,t,o,r,n){void 0===o&&(o=""),this._cppService=new he(e,t,o,r,n)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._cppService.destroy()},e.prototype.getDeviceId=function(){return this._cppService.getDeviceId()},e.prototype.getServerTime=function(){return this._cppService.getServerTime()},e.prototype.__createLogger=function(e,t){return null},e}();module.exports=function(o){return function(e,t,o){if(le)return le;if(!t)throw new Error("Initializ failed, `appkey` is required!");return le=new ge(t,e,null==o?void 0:o.dbpath,null==o?void 0:o.logOutputLevel,null==o?void 0:o.httpRequestProxy)}(function(e){try{return require(g)}catch(t){throw v(e,t),t}}(o.dbpath||e.resolve(t.app.getPath("userData"))),o.appkey,o)};
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "types": "index.d.ts",
21
21
  "module": "index.esm.js",
22
- "version": "5.8.2-enterprise-lz.28",
22
+ "version": "5.8.2-enterprise-lz.30",
23
23
  "author": "pass-web@rongcloud.cn",
24
24
  "license": "LGPL 2.1",
25
25
  "homepage": "https://www.rongcloud.cn",
@@ -30,6 +30,6 @@
30
30
  "globals": "RCMain"
31
31
  },
32
32
  "peerDependencies": {
33
- "@rongcloud/engine": "=5.8.2-enterprise-lz.28"
33
+ "@rongcloud/engine": "=5.8.2-enterprise-lz.30"
34
34
  }
35
35
  }