@rongcloud/electron 5.9.9 → 5.10.2

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/README.md CHANGED
@@ -1 +1,84 @@
1
- # @rongcloud/electron
1
+ # @rongcloud/electron 融云官方即时通讯 Electron SDK
2
+
3
+ 通过 @rongcloud/electron 与 @rongcloud/electron-renderer 模块赋能开发者在自己的桌面端应用上快速拥有专业的、丰富、高质量的互联网通信能力。
4
+
5
+ 融云通过自身 PaaS 能力,解决了多进程连接共享、多进程消息同步问题,降低了开发者构建多窗口、多进程桌面端应用的复杂度。
6
+
7
+ **特性:**
8
+ * Electron SDK 主要提供了基于本地存储的一系列接口,可用于实现本地消息/会话的获取、搜索、删除等特性。
9
+
10
+ # 快速集成
11
+
12
+ **特别注意**
13
+ * 在 windows 平台需使用相应架构的 node。在 CMD 等命令行界面运行 `node -p process.arch` 查看当前 node 版本,需与列表中相匹配。
14
+
15
+ ## 支持平台
16
+ | 平台 | 架构 | 支持情况 |
17
+ |--------|-------|---------|
18
+ | | ia32 | ✔️ |
19
+ | Windows| x64 | ✔️ |
20
+ | | | |
21
+ | | x64 | ✔️ |
22
+ | Mac | arm64 | ✔️ |
23
+ | | | |
24
+ | | x64 | ✔️ |
25
+ | Linux | arm64 | ✔️ |
26
+
27
+ ## 导入 SDK
28
+
29
+ ```bash
30
+ npm install @rongcloud/engine@latest -S
31
+ npm install @rongcloud/imlib-next@latest -S
32
+ npm install @rongcloud/electron@latest -S
33
+ npm install @rongcloud/electron-renderer@latest -S
34
+ ```
35
+
36
+ ## 初始化
37
+
38
+ 初始化分为两步:
39
+ 1. 主进程初始化
40
+ 2. 渲染进程初始化
41
+
42
+ ### 主进程初始化
43
+ 在 app 的 ready 事件通知后进行初始化,建议在 main.js 中进行初始化。
44
+
45
+ ```js
46
+ // main.js
47
+ const { app, BrowserWindow } = require('electron')
48
+ const RCInit = require('@rongcloud/electron')
49
+
50
+ let rcService
51
+
52
+ app.on('ready', () => {
53
+ // 在 app 的 ready 事件通知后进行初始化
54
+ rcService = RCInit({
55
+ appkey: '<appkey>',
56
+ })
57
+
58
+ // 初始化 UI 窗口
59
+ const browserWin = new BrowserWindow({
60
+ webPreferences: {
61
+ preload: '<path/to/preload.js>',
62
+ // 需要将 contextIsolation 设置为 false
63
+ contextIsolation: false,
64
+ nodeIntegration: true
65
+ }
66
+ })
67
+
68
+ app.on('before-quit', () => {
69
+ // 在 app 退出时清理状态
70
+ rcService.destroy()
71
+ })
72
+ })
73
+ ```
74
+
75
+ ### 渲染进程初始化
76
+
77
+ 初始化渲染进程窗口时,通过设置 webPreferences.preload 来添加预加载的 js 文件,并在 js 中引用 @rongcloud/electron-renderer
78
+
79
+ 需要再 preload.js 中进行导入
80
+
81
+ ```js
82
+ // preload.js
83
+ const renderer = require('@rongcloud/electron-renderer');
84
+ ```
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1 +1 @@
1
- "use strict";var e=require("@rongcloud/engine"),t=require("os"),o=require("child_process"),r=require("path"),n=require("http"),s=require("https"),i=require("url"),a=require("net"),c=require("events"),u=require("tls"),p=require("fs"),d=require("crypto");function l(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=l(t),h=function(e,t){return h=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])},h(e,t)};function C(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}h(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var g,v=function(){return v=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},v.apply(this,arguments)};function S(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 y(e,t){var o,r,n,s,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)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 i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){i.label=a[1];break}if(6===a[0]&&i.label<n[1]){i.label=n[1],n=a;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(a);break}n[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}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 _(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_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_E="P-call_addon-E",e.P_CALL_ADDON_T="P-call_addon-T",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_R="P-call_addon-R",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_O="P-connect-O",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_PARSE_JSON_MSGS_R="P-parse_json_messsages-R",e.P_RECEIVE_MESSAGE_E="P-receive_message-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_SUBSCRIBE_DATA_E="P-parse_json_subscribe_data-E",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R",e.P_PARSE_JSON_E="P-parse_json-E"}(g||(g={}));var m,E={flushTimestamp:Date.now(),queue:[],locked:!1};function T(){m&&clearInterval(m)}function P(e,t){T(),m=setInterval((function(){return O(e,t)}),1e4)}function R(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=E.queue).push.apply(e,t)}var I=200;function O(e,t){var o=E.queue,r=E.flushTimestamp;if(!(E.locked||0===o.length||Date.now()-r<3e4&&o.length<I)){E.locked=!0;var n=t.createTraceId(),s=t.getSessionId(),i=o.splice(0,I).map((function(e){var t=e.sessionId,o=e.level,r=e.time,n=e.type,i=e.tag,a=e.loggerId,c=e.content,u=e.traceId;return{level:o,time:r,type:n,tag:i,sessionId:s+":"+t,content:JSON.stringify({loggerId:a,content:c,traceId:u})}}));t.debug(g.P_WRITE_LOG_T,"writingLen: "+i.length+", queueLen: "+o.length,n);var a=JSON.stringify(i);e.writeLog(a),t.debug(g.P_WRITE_LOG_R,"write done, queueLen: "+o.length,n),E.flushTimestamp=Date.now(),E.locked=!1,setTimeout((function(){return O(e,t)}))}}var M=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return C(t,e),t.prototype.flush=function(e){R(e)},t}(e.BasicLogger),N=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return C(t,e),t.prototype.flush=function(e){R(e)},t}(e.BasicStatistic),b=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])},U=function(e){return"string"==typeof e},x=function(e){return U(e)?e.toUpperCase():""},L=function(e,t){var o="";return 2!==e.length?o="Unexpected number of bytes received.":5!==e[0]?o="Unexpected SOCKS version number: "+e[0]+".":255===e[1]?o="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(o="Unexpected SOCKS authentication method: "+e[1]+"."),o},w=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: "+e[0]+".":0!==e[1]&&(t="Username and password authentication failure: "+e[1]+"."),t},A=function(e){var t=x(e.method)||"GET",o=e.pathname||"/",r=e.headers||{},n=e.search||"";r.Host=e.host||"loclahost";var s="";for(var i in s=t+" "+(o+n)+" HTTP/1.1\n",r){if(Object.hasOwnProperty.call(r,i))s+=i+": "+r[i]+"\n"}return e.body&&(s+="Content-Length: "+e.body.length+"\n"),s+="\n","POST"===t&&e.body&&(s+=""+e.body),s},D=function(e){return new Promise((function(t){var o,r;e.socket.once("data",(function(r){var n,s=L(r,o);if(!s)return 2===r[1]?(e.socket.once("data",(function(o){var r=w(o);r?e.emit("error",new Error("SOCKS authentication failed. "+r)):t()})),n=[1],b(e.socksUsername,n),b(e.socksPassword,n),void e.write(Buffer.from(n))):void t();e.emit("error",new Error("SOCKS authentication failed. "+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)}))},k=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: "+t[0]+".":0!==t[1]?o=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 "+e}}(t[1])+".":0!==t[2]&&(o="The reserved byte must be 0x00."),o?e.emit("error",new Error("SOCKS connection failed. "+o)):r()})),(n=[]).push(5),n.push(1),n.push(0),a.isIP(t)){case 0:n.push(3),b(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)}))},J=function(e){function t(t){var o=e.call(this)||this;return o.readable=!0,o.socket=new a.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 C(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: "+e);if(!t||"string"!=typeof t)throw new TypeError("Invalid host: "+t);return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return S(o,void 0,void 0,(function(){var o;return y(this,(function(r){switch(r.label){case 0:return[4,D(this)];case 1:return r.sent(),[4,k(this,t,e)];case 2:return r.sent(),this.onProxied(),o=A(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}(c.EventEmitter),B=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 J(e).connect(r,o)},j=function(e){function t(t){var o=e.call(this)||this;return o.createConnection=B,o}return C(t,e),t}(n.Agent),F=function(e,t,o){return(t=v(v({},t),i.parse(e))).port||(t.port=80),t.agent=new j(t),n.request(t,o)},V=function(e){var t,o;return t=B(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=u.connect(e,(function(){t.authorized=t.socket.authorized,o.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},H=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=V,r}return C(t,e),t}(s.Agent),q=function(e,t,o,r){var n,i;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),i=new H(e,t),t.agent=i,s.request(e,t,o)},G=null;function K(t,o,r){void 0===r&&(r=!1);var i=o.url,a=o.headers,c=o.body,u=o.method,p=o.query,d=o.timeout,l=void 0===d?e.HTTP_TIMEOUT:d;return new Promise((function(o){var d=/^https/.test(i),f={headers:a,method:u};d&&(f.rejectUnauthorized=r);var h=null;G?((f=v(v({},f),G)).body=c,h=d?q:F):(h=n.request,d&&(f.agent=new s.Agent(f),h=s.request));var C=h(e.appendUrl(i,p),f,(function(e){var t=e.statusCode,r="";e.setEncoding("utf8"),e.on("data",(function(e){r+=e})),e.once("end",(function(){o({status:t||0,data:r})}))}));C.once("timeout",(function(){t.warn(g.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:i,method:u,query:p,timeout:l})),o({status:0})})),C.setTimeout(l),C.once("error",(function(e){t.warn(g.P_HTTP_REQ_E,JSON.stringify({msg:e.stack,url:i,method:u,query:p,timeout:l})),o({status:0})})),C.write(c),C.end()}))}function W(t,o){return t?(G=v(v({},G),t),o.info(e.LogTagId.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:G})),{code:e.ErrorCode.SUCCESS}):(G=null,o.info(e.LogTagId.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:e.ErrorCode.SUCCESS})}function Q(){var t=G||void 0;return{code:e.ErrorCode.SUCCESS,data:t}}var Y,X=[],z=!1,$=function(){return S(void 0,void 0,void 0,(function(){var t,o,r,n,s,i,a,c,u,p,d,l,f;return y(this,(function(h){return z||0===X.length||(z=!0,t=X.shift(),o=t.args,r=t.resolve,n=o.addon,s=o.startTime,i=o.endTime,a=o.level,c=o.realtimeReport,u=0,p=0,d=[],l=function(t){u+=t.length;var o=t.split(","),n=o[0],s=o[1],i=o[2],l=o[3],f=o[4],h=o.slice(5);if(u>e.REAT_TIME_LOG_SIZE&&parseInt(s,10)!==p)r(d);else{p=parseInt(s,10);try{if(!c&&a<0)return;var C={time:parseInt(s,10),level:parseInt(l,10),sessionId:n,type:i,tag:f,content:h.join(",")};d.push(C)}catch(e){console.error(e)}}},f=function(e){r(d),z=!1,$()},n.getFullLog(a,s,i,!1,l,f)),[2]}))}))},Z=function(t){function o(o,r,n,s,i){var a=this,c="Electron|"+process.versions.electron+"|"+process.arch+"|"+process.platform;return(a=t.call(this,r,n,c,{getLogs:function(e,t,r,n){return S(this,void 0,void 0,(function(){return y(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:t,level:r,realtimeReport:n,addon:o},S(void 0,void 0,void 0,(function(){return y(this,(function(e){return[2,new Promise((function(e){X.push({resolve:e,args:i}),$()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var t=o.getStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP);return parseInt(t,10)||0},setTimestamp4RealtimeLog:function(t){o.setStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP,t.toString())}},s)||this).subProcess=i,a}return C(o,t),o.prototype.send=function(e){return K(this.logger,e)},o.prototype.compressLogs=function(e){return S(this,void 0,void 0,(function(){var t,o,r;return y(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.data}]:[2,{success:o,data:""}]}}))}))},o}(e.BasicReporter),ee=[e.EConnectProtocol.RMTP,e.EConnectProtocol.TLS,e.EConnectProtocol.QUIC],te=function(e){return"RongCloud/navis/"+e+"/navi-cache.json"},oe="deviceId",re=function(e){return"RongCloud/caches/"+e+"/staticConfig.json"},ne=function(e){return"RongCloud/cloudControl/"+e+"/cloudControl.json"},se=null,ie=function(){var e,o=Date.now(),r=[t.arch(),t.platform(),process.pid,o,Math.floor(Math.random()*o)].join("__");return e=r,d.createHash("md5").update(e).digest("hex")},ae=function(e){if(se)return se;var t=r.resolve(e,oe);return p.existsSync(t)?se=p.readFileSync(t).toString():(se=ie(),p.writeFileSync(t,se),se)},ce=function(){function e(e){this._callCppProxy=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,o,r,n,s){var i=JSON.stringify(n);"{}"!==i&&e.info(g.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:r,ext:n})),this._callCppProxy("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,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._callCppProxy("getMessage",a.mid),p=JSON.parse(u).extMsg,d=JSON.parse(p||"{}");if(c)for(var l in c){var f=d[l];f&&f.ts<i-this._setTime?(f.v=c[l],f.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}();!function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}(Y||(Y={}));var ue=function(){function t(t,o,r,n){var s=this;this.p=t,this.emit=o,this.callback=r,this.errorHandle=n,this.count=0,this.maps={},this.p.on("message",(function(e){var t=e.type,i=e.data;switch(t){case Y.EVENT:var a=i,c=a.eventName,u=a.data;null==o||o.apply(void 0,_([c],u,!1));break;case Y.RESPONSE:var p=i,d=p.reqId,l=p.success,f=p.data,h=s.maps[d];if(!h)return;h({success:l,data:f}),delete s.maps[d];break;case Y.CALLBACK:null==r||r(i);break;case Y.ERROR:var C=i.msg;null==n||n(C)}})),this.p.on("error",(function(e){null==n||n("SubProcessProxy error "+e)})),this.p.on("exit",(function(t,o){if(0!==t){for(var r in s.maps){if(Object.prototype.hasOwnProperty.call(s.maps,r))(0,s.maps[r])({success:!0,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==n||n("SubProcessProxy exit "+t+" "+o,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return t.prototype.call=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r=this;return y(this,(function(n){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(e){var n=++r.count;r.maps[n]=e;var s={reqId:n,method:t,args:o,hasResponse:!0};r.p.send(s)}))]}))}))},t.prototype.send=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r;return y(this,(function(n){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),r={reqId:-1,method:e,args:o},this.p.send(r),[2]}))}))},t.prototype.destroy=function(){this.send("destroy")},t}();function pe(e){void 0===e&&(e="IPv4");for(var o=t.networkInterfaces(),r=[],n=0,s=Object.values(o);n<s.length;n++){var i=s[n];if(i&&-1!==Object.prototype.toString.call(i).indexOf("Array")){var a=i.filter((function(t){return!(t.internal||(o=t.mac,/^(0{1,2}[:-]){5}0{1,2}$/.test(o))||t.family&&t.family!==e);var o})).map((function(e){return e.mac}));r.push.apply(r,a)}}return r.length?r.sort()[0]:""}var de,le=function(e,t,o){return S(void 0,void 0,void 0,(function(){var r,n;return y(this,(function(s){return r=d.createDecipheriv("aes-256-cbc",t,o),n=r.update(e,"base64","utf-8"),[2,n+=r.final("utf8")]}))}))},fe=function(e){if(!p.existsSync(e)){var t=r.resolve(e,"..");p.existsSync(t)||fe(t),p.mkdirSync(e)}},he=function(t){function o(e,o,n,s,i){var a=t.call(this,e,o,n,i)||this;a.naviPath="",a._caches={},a.naviPath=s+"/"+te(e);var c=r.dirname(a.naviPath);return p.existsSync(c)||fe(c),a}return C(o,t),o.prototype.httpRequest=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c,u;return y(this,(function(p){switch(p.label){case 0:return s="token="+encodeURIComponent(r)+"&v="+e.FORMATED_VERSION+"&p=PC&ev=5.9.9&m="+pe(),i=t+"/navi.json?r="+Date.now()+"&env="+this._environment,this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:i,body:s}),n),[4,K(this.logger,{method:"POST",headers:{appId:o},body:s,url:i,timeout:e.NAVI_REQ_TIMEOUT})];case 1:if(200!==(a=p.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,code:a.status}),n),[2,{code:this.transHttpCode(a.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,data:a.data}),n);try{return c=JSON.parse(a.data),u=/^https/.test(i)?"https":"http",c.protocol=u,c.code&&200!==c.code?[2,{code:this.transHttpCode(c.code)}]:[2,{code:e.ErrorCode.SUCCESS,data:c}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,a.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.httpRequestV2=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return s=this.getNaviV2RequestOption({appkey:o,token:r,uri:t,platform:"electron",protocol:ee.join(","),mac:pe()}),this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:s.url,body:s.body,headers:s.headers}),n),[4,K(this.logger,s)];case 1:if(200!==(i=u.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,code:i.status}),n),[2,{code:this.transHttpCode(i.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,data:i.data}),n);try{return a=JSON.parse(i.data),c=/^https/.test(s.url)?"https":"http",a.protocol=c,[2,{code:e.ErrorCode.SUCCESS,data:a}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,i.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.getNaviCache=function(t){var o=this.getCatchKey(t),r=this._caches[o];if(r)return r;if(!p.existsSync(this.naviPath))return null;var n=p.readFileSync(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(n),this._caches[o]}catch(t){this.logger.error(e.LogTagId.L_PARSE_NAVI_E,n)}return null},o.prototype.setNaviCache=function(t,o){var r=Date.now(),n=this.getCatchKey(t);if(e.notEmptyObject(this._caches))for(var s in this._caches){(r-this._caches[s].timestamp>e.NAVI_CACHE_DURATION||n===s)&&delete this._caches[s]}this._caches[n]={token:t,naviInfo:o,timestamp:Date.now(),environment:this._environment},p.writeFileSync(this.naviPath,JSON.stringify(this._caches))},o.prototype.setEnvironment=function(e){this._environment=e},o}(e.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"}(de||(de={}));var Ce,ge=function(t){function o(o,r,n,s,i,a){var c=t.call(this,o,n,s,i,a)||this;return c.callCppProxy=r,c._connectedTime=0,c._naviInfo=null,c._excludeLogTag=["P-RCGetValueForKey-T","P-RCGetValueForKey-E","P-RCGetValueForKey-R","P-RCSetValueForKey-T","P-RCSetValueForKey-E","P-RCSetValueForKey-R"],c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.callCppProxy("setConnectionStatusListener",c._onConnectionStatusChange.bind(c),(function(e){c.logger.info(g.P_DB_OPEN_O,e)}),(function(){return c.recvPong(e.ErrorCode.SUCCESS)}),c._onConnectionStatusChange.bind(c),c._onTcpConnectResponse.bind(c)),c}return C(o,t),o.prototype.getConnectedTime=function(){return this._connectedTime},o.prototype.connectWithToken=function(t,o,r,n){var s=this;return new Promise((function(i){s._naviInfo=o,s.connectResolve={resolve:i,traceId:n,userId:o.userId};var a={},c=Q().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(v(v({},a),{call_plus:s._openCallPlus})),p=s.getCmpList(o,!0).filter((function(e){return ee.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];p.forEach((function(t){var o=d.find((function(e){return e.addr===t.addr}));o?o.protocol!==e.EConnectProtocol.QUIC&&t.protocol!==e.EConnectProtocol.QUIC||(o.race=!0,o.protocol=e.EConnectProtocol.QUIC):(t.race=!1,d.push(t))})),s.logger.info(g.P_CONNECT_O,JSON.stringify({use:d,catche:s.cmpWeightCache,proxy:a,FORMATED_VERSION:e.FORMATED_VERSION,reconnectKickEnable:r}),n),s._startTime=Date.now();try{s.callCppProxy("connectWithToken",t,e.FORMATED_VERSION,JSON.stringify(v(v({},o),{serverAddr:d,tagBlacklist:s._excludeLogTag.join(",")})),r,u)}catch(t){s.logger.error(g.P_CALL_ADDON_E,null==t?void 0:t.stack,n),s.recvConnectRes(e.ErrorCode.RC_SOCKET_NOT_CREATED)}}))},o.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.callCppProxy("disconnect",t)},o.prototype.sendPing=function(t){var o=this;return new Promise((function(r){o.pingResolve=r,o.callCppProxy("sendHeartbeat"),setTimeout((function(){return o.recvPong(e.ErrorCode.TIMEOUT)}),t)}))},o.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},o.prototype._onConnectionStatusChange=function(t,o){switch(this.logger.info(g.P_CONNECT_S,JSON.stringify({status:t,delay:o})),t){case e.ErrorCode.SUCCESS:this.recvConnectRes(e.ErrorCode.SUCCESS);break;case e.ErrorCode.RC_CONN_REDIRECTED:case 32061:this.recvConnectRes(e.ErrorCode.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case e.ErrorCode.RC_SOCKET_DISCONNECTED:this.recvConnectRes(t,!1);break;case e.ErrorCode.RC_SOCKET_NOT_CREATED:case e.ErrorCode.RC_CONN_ACK_TIMEOUT:case e.ErrorCode.RC_TCP_RESET:this.recvConnectRes(t);break;case e.ErrorCode.RC_UDP_DISCONNECTED:this.recvConnectRes(t,!0,o);break;default:this.recvConnectRes(t,!0)}},o.prototype.recvConnectRes=function(t,o,r){if(this.connectResolve){var n=this.connectResolve,s=n.resolve,i=n.userId,a=Date.now()-(this._startTime+this._tcpDuration),c={bid:e.getbundleId(),cod:t,net:this.getNetwork().type,dur:a,spr:0,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,count:this.retryCount};return this.statisticLog.record(e.StatisticsTag.IM_CMP_RMTP,JSON.stringify(c)),t===e.ErrorCode.SUCCESS&&(this._connectedTime=Date.now()-this.callCppProxy("getDeltaTime")),s({code:t,data:i}),void(this.connectResolve=null)}if(o)this.onDisconnectByServer(t,r);else{if(t===e.ErrorCode.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED)return;this.onDisconenctUnusual(t)}},o.prototype._onTcpConnectResponse=function(t,o,r,n,s,i,a){var c,u=this.cmpWeightCache.findIndex((function(e){return e.addr===o+":"+r})),p={bid:e.getbundleId(),ptc:e.ProtocalType.TCP,cod:t,net:this.getNetwork().type,dur:n,spr:0,pr:(null===(c=this._naviInfo)||void 0===c?void 0:c.type)||0,hos:o+":"+r,idx:u,rct:this.retryCount?e.ConnectType.RECONNECT:e.ConnectType.CONNECT,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,rsn:this.reason,ddu:s,count:this.retryCount,weight:u>=0?this.cmpWeightCache[u].weight:-1};this.statisticLog.record(e.StatisticsTag.IM_CMP,JSON.stringify(p)),this.logger.info(g.P_CONNECT_ENTRY_S,JSON.stringify({code:t,host:o,port:r,duration:n,dnsDuration:s,index:i,isQuic:a})),t===de.SUCCESS&&(this.curCmpUrl=o+":"+r,this.updateCmpWeight(o+":"+r,!0,a))},o}(e.AConnectionMgr),ve=function(t){function o(e,o,n){var s=t.call(this,e,o)||this;s.appkey=e,s.logger=o,s.dbpath=n,s._cachePath="",s._cachePath=n+"/"+re(e);var i=r.dirname(s._cachePath);return p.existsSync(i)||fe(i),s}return C(o,t),o.prototype.getCache=function(){return p.existsSync(this._cachePath)&&p.readFileSync(this._cachePath,{encoding:"utf8"})||null},o.prototype.setCache=function(e){p.writeFileSync(this._cachePath,e)},o.prototype.clearCache=function(){p.writeFileSync(this._cachePath,"")},o.prototype.sendRequest=function(e){return S(this,void 0,void 0,(function(){var t,o,r;return y(this,(function(n){switch(n.label){case 0:return[4,K(this.logger,{url:e,body:""})];case 1:return t=n.sent(),o=t.status,r=t.data,[2,{code:o,data:r}]}}))}))},o.prototype.decryptData=function(t){return S(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,le(t,e.STATIC_CONFIG_KEY,e.STATIC_CONFIG_IV)];case 1:return o=n.sent(),[2,JSON.parse(o)];case 2:return r=n.sent(),this.logger.error(e.LogTagId.L_GET_STATIC_CONF_E,JSON.stringify({error:null==r?void 0:r.stack})),[3,3];case 3:return[2]}}))}))},o}(e.BasicStaticConfigManager),Se=function(t){function o(e,o,n,s,i,a,c){var u=t.call(this,o,e,n,a)||this;u.deviceId=s,u.model="",u.catchFilePath="",u.addon=c,u.model="Electron|"+process.platform+"|"+process.arch,u.catchFilePath=i+"/"+ne(e);var d=r.dirname(u.catchFilePath);return p.existsSync(d)||fe(d),u.init(),u}return C(o,t),o.prototype.httpRequest=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c,u,p,d,l;return y(this,(function(f){switch(f.label){case 0:return(s=n).deviceId=this.deviceId,s.model=this.model,i={url:t,method:o,headers:r,body:JSON.stringify(s)},this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify(i)),[4,K(this.logger,i)];case 1:a=f.sent(),c=a.status,u=a.data,p=void 0===u?"":u,this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({status:c,data:p}));try{return d=JSON.parse(p),l=d.data,[2,{code:c,data:l}]}catch(t){return this.logger.warn(e.LogTagId.L_CLOUD_CONFIG_DATA_E,JSON.stringify({status:c,data:p,error:t})),[2,{code:c,msg:t}]}return[2]}}))}))},o.prototype.setCloudControllerCache=function(t){p.writeFileSync(this.catchFilePath,JSON.stringify(t)),this.logger.info(e.LogTagId.L_CLOUD_SET_CACHE_O,JSON.stringify(t))},o.prototype.getLocalCloudControllerCache=function(){if(!p.existsSync(this.catchFilePath))return null;var t=p.readFileSync(this.catchFilePath,{encoding:"utf8"});return this.logger.info(e.LogTagId.L_CLOUD_GET_CACHE_O,JSON.stringify({appkey:this.appkey,data:t})),t},o.prototype.setMRTRConfig=function(t){var o={mrtrChatroom:t.chatroom,mrtrGroup:t.group,mrtrPrivate:t.private,mrtrUltraGroup:t.ultraGroup};this.logger.info(e.LogTagId.L_CLOUD_SET_MRTR_O,JSON.stringify(o)),this.addon.setCloudConfig(JSON.stringify(o))},o}(e.BaseCloudController);!function(e){e[e.cuid=1]="cuid",e[e.uid=2]="uid",e[e.all=4]="all"}(Ce||(Ce={}));var ye=function(){function t(t,n,s,i,a){var c=this;this._appkey=t,this._cppProtocol=n,this._dbpath=s,this._dispatchEvent=i,this._logOutputLevel=a,this._customMessageType={},this.cloudControllerUri="",this.cloudControllerLock=!0,this.cloudControllerMsgs=[],this._buildSubscribeEventData=function(e){var t=[];try{JSON.parse(e).list.forEach((function(e){var o=JSON.parse(e.obj),r=o.userId,n=o.subscribeType,s=o.subscribeTime,i=o.duration,a=o.operationType,c=o.details,u=void 0===c?[]:c;t.push({userId:r,subscribeType:n,subscribeTime:s,duration:i,operationType:a,details:u.map((function(e){var t=JSON.parse(e);return{changeTime:t.changeTime,eventValue:t.changeValue,platform:t.platform}}))})}))}catch(t){c.logger.error(g.P_PARSE_JSON_SUBSCRIBE_DATA_E,JSON.stringify({error:null==t?void 0:t.stack,data:e}))}return t},this._chatroomCache=[],this.rtcHeartbeatResolves={};var u=this._dbpath,p=ae(u);this.logger=new M(this._appkey,"RC-M","IM"),this._cppProtocol.initWithAppkey(t,u,e.FORMATED_VERSION,this.logger.getSessionId());var d=o.fork(r.resolve(__dirname,"sub-process.js"));this.subProxy=new ue(d),this.statisticLog=new N(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),P(this._cppProtocol,this.logger),this.reporter=new Z(this._cppProtocol,t,p,this.logger,this.subProxy),this.logger.info(g.P_INIT_O,JSON.stringify({appkey:t,dbpath:u,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:p,commit:"ac04313edeb4b97f5b9015d75bbe9396b2781d95"})),this._callCppProxy("setDeviceId",p),this._staticConfigManager=new ve(t,this.logger,u),this.navi=new he(t,this.logger,this.statisticLog,u,this._staticConfigManager),this.tcpMgr=new ge(t,this._callCppProxy.bind(this),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)}),this._initCloudController(p,u),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setSubscribeEventListener(),this._msgExpansionHandler=new ce(this._callCppProxy.bind(this))}return t.prototype._initCloudController=function(t,o){var r=e.urlCenter.getCloudControllerUrl();this.cloudControllerUri=r[0],this.cloudController=new Se(this._appkey,this.logger,this.reporter,t,o,this.statisticLog,this._cppProtocol),e.isStartCloudController()&&this.cloudControllerUri&&this.cloudController.request(this.cloudControllerUri,e.InvokerType.init)},t.prototype.callProxy=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r,n,s;return y(this,(function(i){switch(i.label){case 0:if(!(r=this[t]))return this.logger.warn(g.P_CALL_MAIN_E,JSON.stringify({method:t,error:"not found"})),[2,Promise.resolve({code:e.ErrorCode.NOT_SUPPORT})];n="",i.label=1;case 1:return i.trys.push([1,3,,4]),[4,r.call.apply(r,_([this],o,!1))];case 2:return[2,i.sent()];case 3:return s=i.sent(),n=JSON.stringify({error:null==s?void 0:s.stack,method:t}),this.logger.error(g.P_CALL_MAIN_E,n),[3,4];case 4:return[2,{code:e.ErrorCode.MAIN_PROCESS_ERROR,msg:n}]}}))}))},t.prototype.sendProxy=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return S(this,void 0,void 0,(function(){var o;return y(this,(function(r){if(!(o=this[e]))return this.logger.warn(g.P_CALL_MAIN_E,JSON.stringify({method:e,error:"not found"})),[2];try{o.call.apply(o,_([this],t,!1))}catch(t){this.logger.error(g.P_CALL_MAIN_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return[2]}))}))},t.prototype.registerRenderers=function(t){var o=t.navigators,r=t.areaCode,n=t.logServerUrl,s=t.environment;this._environment=s||"default",this.navi.setEnvironment(s),e.urlCenter.init({areaCode:r,navigators:o,logServerUrl:n})},t.prototype.onConnected=function(){return S(this,void 0,void 0,(function(){var e,t,o;return y(this,(function(r){switch(r.label){case 0:return e=this.getNaviInfoFromCache(),this.reporter.checkStart(e),this._try2RejoinChatroom(),t=this._dispatchEvent,o=["onConnected"],[4,this.getMainProcessCache()];case 1:return t.apply(this,o.concat([r.sent()])),[2]}}))}))},t.prototype.onConnecting=function(){this._dispatchEvent("onConnecting",void 0)},t.prototype.onSuspend=function(e){this._dispatchEvent("onSuspend",e)},t.prototype.onDisconnected=function(e){this._dispatchEvent("onDisconnected",e)},t.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.debug(g.P_CALL_ADDON_O,JSON.stringify({method:e,content:o}),n),(t=this._cppProtocol)[e].apply(t,o)}catch(t){throw this.logger.error(g.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),n),t}},t.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},t.prototype.sendHTTPRequest=function(e){return K(this.logger,e)},t.prototype.onRendererLogsReceived=function(e){R.apply(void 0,e)},t.prototype.onRendererNetworkStatusReceived=function(t,o){if(this.tcpMgr.setNetwork(t,o),t.status&&e.isStartCloudController()&&this.cloudController){var r=this.tcpMgr.getToken();this.cloudController.request(this.cloudControllerUri,e.InvokerType.newWorkChange,r)}},t.prototype.destroy=function(){this.reporter.stop(),this.subProxy.destroy(),this._cppProtocol,T(),this._cppProtocol.destroy(),process.exit(0)},t.prototype.callExtra=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this[t];if(!n)return this.logger.warn(g.P_CALL_EXTRA_E,JSON.stringify({method:t,error:"not found"})),Promise.resolve({code:e.ErrorCode.NOT_SUPPORT});try{return n.call.apply(n,_([this],o,!1))}catch(e){this.logger.error(g.P_CALL_EXTRA_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})},t.prototype.getConversationsByPage=function(t,o,r,n,s){var i,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",t,o,r,s||!1,n||"");try{i=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:i})},t.prototype.getUnreadConversationList=function(t){var o,r=this,n=this._callCppProxy("getUnreadConversationList",t);try{o=JSON.parse(n).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t.prototype.getConversationListWithAllChannel=function(){var t,o=this,r=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],n=this._callCppProxy("getConversationListWithAllChannel",r);try{t=JSON.parse(n).list.map((function(e){return o._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},t.prototype.getConversationListWithAllChannelByPage=function(t,o){var r,n=this,s=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,t,o);try{r=JSON.parse(i).list.map((function(e){return n._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},t.prototype.getHistoryMessagesByObjectNames=function(t,o,r,n,s,i,a){var c=0===i,u=n+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",t,o,r,u,s,c,a||""),d=[];try{var l=JSON.parse(p).list;l.reverse();for(var f=0;f<l.length;f++){var h=this._buildMessage(l[f].obj);d[f]=h}}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:{list:u===d.length?d.slice(1,u):d,hasMore:n<d.length}})},t.prototype.updateMessageReceiptStatus=function(t,o,r,n){void 0===n&&(n="");var s=this._callCppProxy("updateMessageReceiptStatus",t,o,r,n);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},t.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new M(this._appkey,e,t)},t.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},t.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},t.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},t.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),o=this.getNaviInfoFromCache(),r=this.tcpMgr.getCurrentUserId(),n=this.getDeviceId(),s=this._cppProtocol.getDeltaTime();return Promise.resolve({connectedTime:e,deviceId:n,crtUserId:r,naviInfo:o,connectionStatus:t,deltaTime:s})},t.prototype._registerMsgTypes=function(){for(var t in e.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},e.SEND_MESSAGE_TYPE_OPTION){var o=e.SEND_MESSAGE_TYPE_OPTION[t],r=o.isCounted,n=o.isPersited,s=o.searchProps,i=0;n&&(i|=1),r&&(i|=2),"RC:TypSts"===t&&(i=16),this._callCppProxy("registerMessageType",t,i,s||[])}},t.prototype._buildIsMentioned=function(t,o){var r,n=!1;if(e.isObject(t))r=t;else try{r=t?JSON.parse(t):t}catch(e){r=t,this.logger.error(g.P_PARSE_JSON_MSGS_E,JSON.stringify({content:t}))}return e.isObject(r)&&(n=!!r.mentionedInfo),{isMentioned:n,msgContent:r}},t.prototype._buildMsgOption=function(t){var o={isCounted:!1,isPersited:!1};return t in e.SEND_MESSAGE_TYPE_OPTION?o=e.SEND_MESSAGE_TYPE_OPTION[t]:t in this._customMessageType&&(o=this._customMessageType[t]),o},t.prototype._buildSupportExt=function(e,t,o){var r=null;return e&&(r=this._msgExpansionHandler.parseReceiveExpansion(o),"conversation"!==t&&"history"!==t||(r=this._msgExpansionHandler.parseConverOrHisExpansion(o))),r},t.prototype._handleReadReceiptRequest=function(e){var t=JSON.parse(e),o=this.getNaviInfoFromCache();if(!(null==o?void 0:o.grpRRVer))return t;var r=t,n=r.hasRespond,s=r.readerInfo,i=void 0===s?{}:s,a=r.readCount,c=r.totalCount,u=r.readerList,p=void 0===u?[]:u,d={readCount:a,totalCount:c};if(1===(null==o?void 0:o.grpRRVer)){var l=[];for(var f in i)l.push({userId:f,readTime:i[f]});d.readerList=l,d.hasRespond=n}return 3===(null==o?void 0:o.grpRRVer)&&(d.readerList=p),d},t.prototype._buildMessage=function(t,o){var r;void 0===o&&(o={});var n=o.isOffLineMessage,s=o.buildFrom,i=JSON.parse(t),a=i.channelId,c=i.conversationType,u=i.targetId,p=i.senderUserId,d=i.content,l=i.objectName,f=i.messageUid,h=i.direction,C=i.status,g=i.messageId,S=i.sentTime,y=i.readReceiptRequest,_=i.supportExt,m=i.pushContent,E=i.pushTitle,T=i.pushId,P=i.pushConfig,R=i.templateId,I=i.disableTitle,O=i.forcePushDetail,M=i.hasMore,N=i.directedUsers,b=i.noNotification,U=this._buildIsMentioned(d,g),x=U.isMentioned,L=U.msgContent,w=this._buildMsgOption(l),A=this._buildSupportExt(_,s,i),D=e.isUndefined(n)?S<this.tcpMgr.getConnectedTime():n,k={};P&&(k=e.pushJSONToConfigs(this.logger,P,T));var J=v(v({},k),{pushTitle:E,pushContent:m,pushData:m,disablePushTitle:I,forceShowDetailContent:O,templateId:R}),B={channelId:a,conversationType:c,targetId:u,senderUserId:p,content:L||{},messageType:l,messageUId:f||"",messageDirection:h,isOffLineMessage:D,sentTime:S,receivedTime:0,isPersited:w.isPersited,isCounted:w.isCounted,isMentioned:x,disableNotification:b,isStatusMessage:(null===(r=this._customMessageType[l])||void 0===r?void 0:r.isStatusMessage)||!1,canIncludeExpansion:_,expansion:_?A:null,receivedStatus:C,receivedStatusInfo:e.transformReceivedStatusInfo(C),messageId:g,pushConfig:J,hasMore:M,directedUserIds:N||[]};if(h===e.MessageDirection.RECEIVE?B.receivedStatus=this._compatibleReceivedStatus(B.receivedStatusInfo):h===e.MessageDirection.SEND&&(B.sentStatus=C),y){var j=this._handleReadReceiptRequest(y);B.readReceiptInfo=j}return B},t.prototype._compatibleReceivedStatus=function(t){var o=e.ReceivedStatus.UNREAD;return t.isRead?o=e.ReceivedStatus.READ:t.isListened?o=e.ReceivedStatus.LISTENED:t.isDownload?o=e.ReceivedStatus.DOWNLOADED:t.isRetrieved&&(o=e.ReceivedStatus.RETRIEVED),o},t.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),r=JSON.parse(o),n=r.readReceiptRequest?JSON.parse(r.readReceiptRequest):{},s=v(v({},n),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},t.prototype._processRRRspMsg=function(e,t,o){if(t!==this.getCurrentUserId())for(var r=0,n=e[this.getCurrentUserId()]||[];r<n.length;r++){h=n[r];var s=this._callCppProxy("getMessage",h),i=JSON.parse(s),a=i.readReceiptRequest?JSON.parse(i.readReceiptRequest):{},c=a.isReceiptRequestMessage,u=a.readerList,p=void 0===u?[]:u;c&&!p.includes(t)&&(p.push(t),this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:c,readerList:p})))}else for(var d in e)for(var l=0,f=e[d];l<f.length;l++){var h=f[l];this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:!0,hasRespond:!0}))}},t.prototype._processRSMsg=function(t){var o=t.conversationType,r=t.targetId,n=t.content,s=t.channelId,i=n.msgId,a=n.rrn,c=n.tmn,u=n.endMsgTime;o===e.ConversationType.PRIVATE?this.updateMessageReceiptStatus(o,r,u,s||""):this._updateReadReceiptInfo(i,{readCount:a,totalCount:c});var p={conversationType:o,targetId:r,channelId:s};this._sendMessageReadReceipt(o===e.ConversationType.PRIVATE?{privateReadReceipt:v(v({},p),{endMsgTime:n.endMsgTime})}:{groupReadReceipt:v(v({},p),{totalCount:n.tmn,readedCount:n.rrn,messageUId:n.msgId})})},t.prototype._processSRSMsg=function(e){var t=this.getNaviInfoFromCache(),o=e.conversationType,r=e.targetId,n=e.content,s=e.channelId,i=e.senderUserId,a=e.sentTime;return i===this.tcpMgr.getCurrentUserId()&&(this._callCppProxy("clearUnreadCountByTimestamp",o,r,n.lastMessageSendTime,s||""),1!==(null==t?void 0:t.sesDriven)||(a>this.tcpMgr.getConnectedTime()||this._sendsyncReadStatus({conversationType:o,targetId:r,channelId:s,timestamp:n.lastMessageSendTime}),!1))},t.prototype._buildConversation=function(t){var o=JSON.parse(t),r=o.channelId,n=o.conversationType,s=o.targetId,i=o.unreadCount,a=o.lastestMsg,c=o.isTop,u=o.blockStatus,p=o.matchCount,d=o.hasUnreadMention,l=o.conversationTime,f=o.draft,h=u>0?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE;return{channelId:r,conversationType:n,targetId:s,unreadMessageCount:i,latestMessage:-1===JSON.parse(a).messageId?null:this._buildMessage(a),hasMentioned:d,mentionedInfo:null,notificationStatus:h,isTop:c,lastUnreadTime:0,matchCount:p,operationTime:l,notificationLevel:u,draft:f}},t.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}))},t.prototype._handleNotNotificationMessage=function(t){var o,r=t.messageType,n=t.senderUserId,s=t.content;if(r===e.MessageType.LOG_COMMAND&&t.senderUserId===e.RC_DEFAULT_USER){var i=t.content,a=i.startTime,c=i.endTime,u=i.platform,p=i.logId,d=i.uri;return this.reporter.report(parseInt(a,10),parseInt(c,10),u,d,p,t.messageUId),!0}if(r===e.MessageType.CLOUD_CONTROL&&n===e.RC_DEFAULT_USER)return this.cloudControllerMsgs.push(t),this._ccMsgHandler(),!0;if(r===e.MessageType.READ_STATE)return this._processRSMsg(t),!0;if("RC:MsgExMsg"===r)return this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),this._sendMessageExpansion(t),!0;if(r===e.MessageType.SYNC_READ_STATUS&&!this._processSRSMsg(t))return!0;if(r===e.MessageType.DELIVERED)return this._callCppProxy("setMessageDeliverTime",JSON.stringify(s)),this._sendMessageDelivered(t.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}}))),!0;if(r===e.MessageType.DELIVERED_MSG){var l={totalCount:t.content.tmn,list:null===(o=t.content.dl)||void 0===o?void 0:o.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};return this._sendGroupMessageDeliveredStatus(l),!0}return!1},t.prototype._setOnReceiveMessageListener=function(){var t=this;this._cppProtocol.setOnReceiveMessageListener((function(o,r,n,s){try{var i=t._buildMessage(o,{isOffLineMessage:n}),a=i.messageType,c=i.channelId,u=void 0===c?"":c,p=i.senderUserId,d=i.content,l=i.sentTime,f=i.conversationType,h=i.targetId;if(t._handleNotNotificationMessage(i))return;if(a===e.MessageType.READ_RECEIPT_REQUEST&&d.messageUId&&t._updateReadReceiptInfo(d.messageUId,{isReceiptRequestMessage:!0,hasRespond:!1}),a===e.MessageType.READ_RECEIPT_RESPONSE&&d.receiptMessageDic&&t._processRRRspMsg(d.receiptMessageDic,p,l),a===e.MessageType.GROUP_READ_RECEIPT_REQUEST){var C=d.msgId,v=d.rrn,S=d.tmn;t._updateReadReceiptInfo(C,{readCount:v,totalCount:S})}i.canIncludeExpansion&&t._msgExpansionHandler.setLocalFromReceiveMsg(t.logger,i),a===e.MessageType.READ_RECEIPT&&p===t.tcpMgr.getCurrentUserId()&&t._callCppProxy("clearUnreadCountByTimestamp",f,h,d.lastMessageSendTime,u);var y=!0;if(0!==r||s||(y=!1),a===e.MessageType.RECALL){if(!t.handleRecalledMessage(i))return;var _=t._fixRecallContentInfo(i);f=_.conversationType,h=_.targetId}t._sendMessageNotification(Object.assign(i,{hasMoreMsg:y,conversationType:f,targetId:h}))}catch(e){t.logger.error(g.P_RECEIVE_MESSAGE_E,JSON.stringify({error:null==e?void 0:e.stack,message:o}))}}),(function(){t._sendPullOfflineFinished()}))},t.prototype._ccMsgHandler=function(){var t;return S(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return this.cloudControllerLock?(this.cloudControllerLock=!1,this.cloudControllerMsgs.shift()?(o=this.tcpMgr.getToken(),[4,null===(t=this.cloudController)||void 0===t?void 0:t.request(this.cloudControllerUri,e.InvokerType.other,o)]):[3,2]):[2];case 1:r=n.sent()||0,this.cloudControllerMsgs=this.cloudControllerMsgs.filter((function(e){return e.sentTime>r})),this.cloudControllerLock=!0,this._ccMsgHandler(),n.label=2;case 2:return[2]}}))}))},t.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}},t.prototype.handleRecalledMessage=function(t){var o=t.content,r=o.messageUId,n=o.sentTime;if(!r)return!0;var s=this._callCppProxy("getMessage",r),i=this._buildMessage(s,{isOffLineMessage:!1});if(t.content.isDelete)return-1===i.messageId||this._callCppProxy("deleteMessages",[i.messageId]),!0;if(i.messageType===e.MessageType.RECALL_NOTIFICATION_MESSAGE)return!1;var a={recallTime:Date.now(),admin:!!t.content.isAdmin,originalObjectName:i.messageType,originalMessageContent:i.content,recallActionTime:t.sentTime,operatorId:t.senderUserId};if(t.content.user&&(a.user=t.content.user),t.content.extra&&(a.extra=t.content.extra),i.messageType===e.MessageType.TextMessage&&(a.recallContent=i.content.content),-1===i.messageId){var c=t.conversationType,u=t.targetId,p=t.senderUserId,d=t.channelId,l=t.messageDirection;return this._callCppProxy("insertMessage",c,u,p,e.MessageType.RECALL_NOTIFICATION_MESSAGE,JSON.stringify(a),(function(){}),(function(){}),l,1,30,n,"",0,r,!1,!0,JSON.stringify({}),d||""),!0}return i.receivedStatus||this.setMessageReceivedStatus(i.messageId,1),this._callCppProxy("setMessageContent",i.messageId,JSON.stringify(a),e.MessageType.RECALL_NOTIFICATION_MESSAGE),!0},t.prototype._sendMessageExpansion=function(e){var t=e.channelId,o=void 0===t?"":t,r=e.content,n=e.conversationType,s=e.targetId,i=r,a=i.put,c=i.del,u=i.mid,p={};a&&(p.updatedExpansion={channelId:o,messageUId:u,expansion:a,conversationType:n,targetId:s}),c&&(p.deletedExpansion={channelId:o,messageUId:u,deletedKeys:c,conversationType:n,targetId:s}),this._dispatchEvent("expansion",p)},t.prototype._sendMessageNotification=function(e){this._dispatchEvent("batchMessage",e)},t.prototype._sendPullOfflineFinished=function(){this._dispatchEvent("pullFinished",null)},t.prototype._sendMessageDelivered=function(e){this._dispatchEvent("messageDelivered",e)},t.prototype._sendGroupMessageDeliveredStatus=function(e){this._dispatchEvent("groupMessageDeliveredStatus",e)},t.prototype._sendChatroomStatus=function(e){this._dispatchEvent("chatroom",e)},t.prototype._sendMessageReadReceipt=function(e){this._dispatchEvent("messageReadReceipt",e)},t.prototype._sendsyncReadStatus=function(e){this._dispatchEvent("syncReadStatus",e)},t.prototype._setConversationStatusListener=function(){var t=this;this._cppProtocol.setConversationStatusListener((function(o){var r=JSON.parse(o).list,n=[];r.forEach((function(t){var o=JSON.parse(t.obj),r=o.conversationType,s=o.targetId,i=o.status,a=o.channelId,c={notificationStatus:2,isTop:!1};i.forEach((function(t){var o=JSON.parse(t.item);1===o.type?c.notificationStatus=1===Number(o.value)?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE:c.isTop=1===Number(o.value)})),n.push({channelId:a,conversationType:r,targetId:s,updatedItems:{notificationStatus:{val:c.notificationStatus,time:0},isTop:{val:c.isTop,time:0}}})})),t._dispatchEvent("conversation",n)}),(function(e){t._dispatchEvent("conversationTag",e)}),(function(e,o,r,n){t._callCppProxy("clearUnreadCountByTimestamp",e,o,n,r||""),t._sendsyncReadStatus({conversationType:e,targetId:o,channelId:r,timestamp:n})}))},t.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._dispatchEvent("tag",t),e._getRTCProfile()}))},t.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._dispatchEvent("onNaviDataChange",o)}},t.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){e._dispatchEvent("onRTCDataChange",Array.prototype.slice.call(t))}))},t.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._sendChatroomStatus({chatroomDestroyed:t})}))},t.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._dispatchEvent("callInfo",t)}))},t.prototype._setSubscribeEventListener=function(){var e=this;this._cppProtocol.setSubscribeEventListener((function(){}),(function(){e._dispatchEvent("syncSubscribedUserStatusFinished")}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,operationType:e.operationType}}));e._dispatchEvent("subscribedRelationChange",o)}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,details:e.details}}));e._dispatchEvent("subscribedUserStatusChange",o)}))},t.prototype._updateMentionedInfo=function(t,o,r){var n,s,i;return{userIdList:(null===(n=t.mentionedInfo)||void 0===n?void 0:n.userIdList)||o,type:(null===(s=t.mentionedInfo)||void 0===s?void 0:s.type)||r||e.MentionedType.ALL,mentionedContent:(null===(i=t.mentionedInfo)||void 0===i?void 0:i.mentionedContent)||""}},t.prototype.registerMessageType=function(e,t,o,r,n){var s=0;t&&(s|=1),o&&(s|=2),n&&(s=16),this._customMessageType[e]={isCounted:o,isPersited:t,isStatusMessage:n},this.logger.info(g.P_REGTYP_O,JSON.stringify({type:e,opt:s,search:r})),this._callCppProxy("registerMessageType",e,s,r||[])},t.prototype.connect=function(e,t,o,r){return this.tcpMgr.connect(e,t,o,r)},t.prototype.reportSDKInfo=function(e){var t=JSON.stringify(v(v({},e),{"electron-main":"5.9.9"}));this.logger.info(g.P_REPORT_VER_O,t),this._callCppProxy("uploadSDKVersion",t,"")},t.prototype.disconnect=function(e){e=e||!0,this._chatroomCache.length=0,this.reporter.stop(),W(null,this.logger),this.tcpMgr.disconnect(e)},t.prototype.logout=function(){this.disconnect()},t.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)},t.prototype.subscribeUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("subscribeUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.setUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("setUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getUserStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:{status:t}})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype._handleDirectionalUserIdList=function(t){var o=t.messageType,r=t.content,n=t.directionalUserIdList,s=void 0===n?[]:n;if(o===e.MessageType.READ_RECEIPT_RESPONSE&&r.receiptMessageDic)for(var i in r.receiptMessageDic)s.push(i);return o===e.MessageType.SYNC_READ_STATUS&&(s=[this.getCurrentUserId()]),s},t.prototype._handleMessage2Callback=function(t,o){var r=this;if("RC:MsgExMsg"===t.messageType&&this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),t.messageType===e.MessageType.READ_RECEIPT_REQUEST)this._updateReadReceiptInfo(o.content.messageUId,{isReceiptRequestMessage:!0,readerList:[]});else if(t.messageType===e.MessageType.READ_RECEIPT_RESPONSE){var n=o.content.receiptMessageDic;if(!n)return;for(var s in n)n[s].forEach((function(e){r._updateReadReceiptInfo(e,{isReceiptRequestMessage:!0,hasRespond:!0})}))}},t.prototype.sendMessage=function(t,o,r,n,s){var i=this;void 0===s&&(s=this.logger.createTraceId());var a=r.messageType,c=r.content,u=r.expansion,p=r.pushConfig,d=r.isMentioned,l=r.mentionedType,f=r.mentionedUserIdList,h=void 0===f?[]:f,C=r.pushContent,v=void 0===C?"":C,S=r.pushData,y=void 0===S?"":S,_=r.directionalUserIdList,m=void 0===_?[]:_,E=r.disableNotification,T=void 0!==E&&E,P=r.canIncludeExpansion,R=void 0!==P&&P,I=r.isVoipPush,O=void 0!==I&&I,M=r.channelId,N=void 0===M?"":M,b=r.messageId,U=void 0===b?0:b,x=p||{},L=x.iOSConfig,w=x.androidConfig,A=x.templateId,D=void 0===A?"":A,k=x.pushTitle,J=void 0===k?"":k,B=x.pushContent,j=void 0===B?v:B,F=x.pushData,V=void 0===F?y:F,H=x.disablePushTitle,q=void 0!==H&&H,G=x.forceShowDetailContent,K=void 0!==G&&G,W=e.pushConfigsToJSON(L,w);return new Promise((function(p){v=j,y=V;var f=(null==w?void 0:w.notificationId)||"",C=t===e.ConversationType.GROUP;C&&d&&c&&(c.mentionedInfo=i._updateMentionedInfo(c,h,l)),C&&(m=i._handleDirectionalUserIdList(r));var S={};for(var _ in u)S[_]={v:""},S[_].v=u[_];var E=D;i.logger.info(g.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:t,targetId:o,channelId:N}),s);var P=i._callCppProxy("sendMessage",(function(t,o){var n=i._buildMessage(t,{isOffLineMessage:!1});if(i.logger.info(g.P_SEND_MSG_R,JSON.stringify({code:o,messageUId:n.messageUId}),s),o===e.ErrorCode.SENSITIVE_REPLACE)return setTimeout((function(){p({code:o})}),0);[e.MessageType.READ_RECEIPT_REQUEST,e.MessageType.READ_RECEIPT_RESPONSE,e.MessageType.EXPANSION_NOTIFY].findIndex((function(e){return e===n.messageType}))>-1&&i._handleMessage2Callback(n,r),n.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(i.logger,n),setTimeout((function(){p({code:e.ErrorCode.SUCCESS,data:n})}),0)}),(function(e,t){var o=i._buildMessage(e,{isOffLineMessage:!1});i.logger.warn(g.P_SEND_MSG_R,JSON.stringify({code:t,messageId:o.messageId}),s),o.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),setTimeout((function(){p({code:t,data:o})}),0)}),t,o,a,JSON.stringify(c),m,T,q,K,v,y,f,J,W,E,R,JSON.stringify(S),O,N,U),I=JSON.parse(P);null==n||n(I.messageId)}))},t.prototype.recallMsg=function(t,o,r,n,s){var i=this;return new Promise((function(a){var c,u=s.user,p=s.pushContent,d=s.channelId,l=s.extra,f=s.pushConfig,h=s.disableNotification,C=s.isDelete,g=s.directionalUserIdList,v={conversationType:t,targetId:o,messageUId:r,sentTime:n,user:u,extra:l,channelId:d,isDelete:C||!1};u&&(v.user=u),l&&(v.extra=l);var S={conversationType:t,targetId:o,senderUserId:i.tcpMgr.getCurrentUserId(),content:v,objectName:e.MessageType.RECALL,messageUid:r,direction:e.MessageDirection.SEND,status:e.ReceivedStatus.UNREAD,sentTime:n,channelId:d},y=i._buildMessage(JSON.stringify(S),{isOffLineMessage:!1});i._callCppProxy("recallMessage",(function(){i.handleRecalledMessage(y),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:y})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}),e.MessageType.RECALL,JSON.stringify(v),h||!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)||"",e.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",d,g||[])}))},t.prototype.getHistoryMessage=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){r=r||0;var p=0===s,d=n+1,l=c._callCppProxy("getHistoryMessages",t,o,r,d,a,p,i),f=JSON.parse(l).list,h=[];f.reverse();for(var C=0;C<f.length;C++){var g=c._buildMessage(f[C].obj);h[C]=g}u({code:e.ErrorCode.SUCCESS,data:{list:d===h.length?h.slice(1,d):h,hasMore:n<h.length}})}))},t.prototype.getMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){var u=0===s,p=r,d=0!==r,l=n+1;d&&(p+=u?1:-1,l++);for(var f=a._callCppProxy("getMessages",t,o,p,l,u,i),h=JSON.parse(f).list,C=[],g=0;g<h.length;g++){var v=a._buildMessage(h[g].obj);C[g]=v}var S=a._computeRepairInfo(C,u,r,p,l),y=S.isNeedRepair,_=void 0!==y&&y,m=S.repairTime,E=void 0===m?0:m;if(!_)return d&&(C.shift(),l--),C.reverse(),void c({code:e.ErrorCode.SUCCESS,data:{list:l===C.length?C.slice(1,l):C,hasMore:n<C.length}});a._processRepairHisMsg(t,o,r,n,s,i,E,c)}))},t.prototype._computeRepairInfo=function(e,t,o,r,n){var s=!1,i=0,a=this.getNaviInfoFromCache()||{},c=a.repairHisMsg,u=void 0===c?0:c,p=a.historyMsg;if(1!==u||!p)return{isNeedRepair:s,repairTime:i};var d=e.findIndex((function(e){return e.hasMore||0===Object.keys(e.content).length}));return t&&d>=0?(s=!0,i=e[d].hasMore?e[d].sentTime:e[d].sentTime+1):!t&&d>=1?(s=!0,i=e[d-1].sentTime):e.length<n||0===o?(s=!0,i=o):e.length>0&&e[0].sentTime!==o&&(s=!0,i=r),{isNeedRepair:s,repairTime:i}},t.prototype._processRepairHisMsg=function(e,t,o,r,n,s,i,a){var c=this,u=function(i){for(var u=0===n,p=r+1,d=c._callCppProxy("getMessages",e,t,o,p,u,s),l=JSON.parse(d).list,f=[],h=0;h<l.length;h++){var C=c._buildMessage(l[h].obj);f[h]=C}f.reverse(),a({code:i,data:{list:p<=f.length?f.slice(1,p):f,hasMore:r<f.length}})},p=r+10>100?100:r+10;this._callCppProxy("getRemoteHistoryMessages",e,t,i,p,(function(){return u(0)}),(function(e){u(e)}),n,!0,s,!1)},t.prototype.getContinuousMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;var u=0===s;a._callCppProxy("getContinuousMessages",t,o,r,n,(function(t,o,r){var n=JSON.parse(t).list,s=[];n.reverse();for(var i=0;i<n.length;i++){var u=a._buildMessage(n[i].obj);s[i]=u}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:s,timestamp:o,hasMore:r}})}))}),(function(e){setTimeout((function(){c({code:e})}),0)}),u,i)}))},t.prototype.getRemoteHistoryMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;a._callCppProxy("getRemoteHistoryMessages",t,o,r,n,(function(t,o){var r=JSON.parse(t).list,n=[];r.reverse();for(var s=0;s<r.length;s++){var i=a._buildMessage(r[s].obj);n[s]=i}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:n,hasMore:!!o}})}),0)}),(function(e){setTimeout((function(){c({code:e})}),0)}),s,!0,i,!0)}))},t.prototype.deleteRemoteMessage=function(t,o,r,n){var s=this;return new Promise((function(i){var a=JSON.stringify(r);s._callCppProxy("deleteRemoteHistoryMessages",t,o,a,!1,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),i)}))},t.prototype.deleteRemoteMessageByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearRemoteHistoryMessages",t,o,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),n)}))},t.prototype.clearMessages=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearMessages",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.getConversationList=function(t,o,r,n,s){var i=this;return void 0===s&&(s=""),new Promise((function(t){for(var o=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(o).list,n=[],a=0;a<r.length;a++)n.push(i._buildConversation(r[a].obj));t({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.getConversation=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversation",t,o,r);if(i)s({code:e.ErrorCode.SUCCESS,data:n._buildConversation(i)});else{var a=n._callCppProxy("getHistoryMessages",t,o,0,1,"",!0,r),c=void 0;try{c=JSON.parse(a).list}catch(e){n.logger.error(g.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=n._buildMessage(c[0].obj));var p=n._callCppProxy("getConversationNotificationStatus",t,o,r),d=n._callCppProxy("getConversationTopStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:{conversationType:t,targetId:o,channelId:r,unreadMessageCount:0,latestMessage:u,notificationStatus:p?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},t.prototype.removeConversation=function(t,o,r){var n=this._callCppProxy("removeConversation",t,o,r);return Promise.resolve(n?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.batchRemoveConversation=function(t){var o=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId}})),r=this._callCppProxy("removeConversationInBatches",JSON.stringify(o));return Promise.resolve(r?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.clearConversations=function(t,o){var r=this;return new Promise((function(n){var s=[];s=e.isArray(t)?t:[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.PUBLIC_SERVICE],r._callCppProxy("clearConversations",s,o||""),n(e.ErrorCode.SUCCESS)}))},t.prototype.getAllConversationUnreadCount=function(t,o,r){var n=this._callCppProxy("getTotalUnreadCount",o,r,t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){var i=n._callCppProxy("getUnreadCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){n._callCppProxy("clearUnreadCount",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.clearUnreadCountByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearUnreadCountByTimestamp",t,o,r,n),i(e.ErrorCode.SUCCESS)}))},t.prototype.getFirstUnreadMessage=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),a=n._buildMessage(i);s({code:e.ErrorCode.SUCCESS,data:-1!==a.messageId?a:null})}))},t.prototype.getFirstUnreadMessageInfo=function(t,o,r){var n=this;return new Promise((function(s,i){var a=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),c=n._buildMessage(a);s({code:e.ErrorCode.SUCCESS,data:-1!==c.messageId?{messageUId:c.messageUId,sentTime:c.sentTime}:null})}))},t.prototype.batchSetConversationToTop=function(t,o,r){var n=this;return new Promise((function(s,i){var a=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,is_top:o}}));n._callCppProxy("setIsTopInBatches",JSON.stringify(a),r||!1),s(e.ErrorCode.SUCCESS)}))},t.prototype.setConversationStatus=function(t,o,r,n,s,i){var a=this;return new Promise((function(i){a._callCppProxy("setConversationStatus",t,o,r,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),s,!0)}))},t.prototype.getConversationNotificationStatus=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversationNotificationStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE})}))},t.prototype.setConversationTypeNotificationLevel=function(t,o){var r=this;return new Promise((function(n,s){r._callCppProxy("setBlockPushLevelForType",t,o,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getConversationTypeNotificationLevel=function(t){var o=this;return new Promise((function(r,n){var s=o._callCppProxy("getBlockPushLevelForType",t);r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.searchConversationByContent=function(t,o,r,n){var s=this;return new Promise((function(i){n=n||[1,3,6,7];for(var a=s._callCppProxy("searchConversationByContent",n,t,o,r),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=s._buildConversation(c[p].obj);i({code:e.ErrorCode.SUCCESS,data:u})}))},t.prototype.searchConversationByContentWithAllChannel=function(t,o,r){var n=this;return new Promise((function(s){r=r||[1,3,6,7];for(var i=n._callCppProxy("searchConversationByContentWithAllChannel",r,t,o),a=JSON.parse(i).list,c=[],u=0;u<a.length;u++)c[u]=n._buildConversation(a[u].obj);s({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.searchMessageByContent=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(i){c._callCppProxy("searchMessageByContent",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=c._buildMessage(r[s].obj);setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}),a)}))},t.prototype.searchMessageByContentAndMessageType=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){for(var p=c._callCppProxy("searchMessageByContentAndObjectName",o,t,a||"",void 0===a,r,i,s,n),d=p?JSON.parse(p).list:[],l=[],f=0;f<d.length;f++)l[f]=c._buildMessage(d[f].obj);u({code:e.ErrorCode.SUCCESS,data:{messages:l}})}))},t.prototype.searchMessagesByUser=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){a._callCppProxy("getMessageBySender",t,o,r,n,s,i,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=a._buildMessage(o[n].obj);setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.searchMessageByContentWithAllChannel=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("searchMessageByContentWithAllChannel",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=i._buildMessage(r[s].obj);setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}))}))},t.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByTimestampWithAllChannel",t,o,r,n,s,i,a,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=c._buildMessage(o[n].obj);setTimeout((function(){u({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.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},t.prototype.addToBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addToBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.removeFromBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("removeFromBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getBlacklist=function(){var t=this;return new Promise((function(o){t._callCppProxy("getBlacklist",(function(t){setTimeout((function(){o({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){o({code:e})}),0)}))}))},t.prototype.getBlacklistStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getBlacklistStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.insertMessage=function(t,o,r){var n=this,s=r.content,i=r.senderUserId,a=r.messageType,c=r.messageDirection,u=r.readStatus,p=r.sentStatus,d=r.sentTime,l=r.searchContent,f=r.isUnread,h=r.messageUId,C=r.disableNotification,g=r.canIncludeExpansion,v=r.expansionMsg,S=r.channelId,y=r.directedUserIds;s=JSON.stringify(s);var _={};if(d=d||0,v){var m=JSON.parse(v);for(var E in m)_[E]={v:"",ts:0},_[E].v=m[E],_[E].ts=d}return new Promise((function(r){var v=f?0:1,m=n._callCppProxy("insertMessage",t,o,i,a,s,(function(){}),(function(e){setTimeout((function(){r({code:e})}),0)}),c,u||0,p||10,d,l||"",v,h||"",!!C,!!g,JSON.stringify(_),S||"",y||[]),E=n._buildMessage(m,{isOffLineMessage:!1});E.messageUId=h,E.sentTime=d,r({code:-1===E.messageId?e.ErrorCode.MSG_INSERT_ERROR:e.ErrorCode.SUCCESS,data:E})}))},t.prototype.batchInsertMessage=function(t,o){var r=this;return void 0===o&&(o=!1),new Promise((function(n){var s=t.map((function(t){var o=t.content,r=t.senderUserId,n=t.messageType,s=t.messageDirection,i=t.receivedStatus,a=void 0===i?0:i,c=t.sentStatus,u=t.sentTime,p=t.searchContent,d=t.isUnread,l=t.messageUId,f=t.disableNotification,h=t.canIncludeExpansion,C=t.expansion,g=t.channelId,v=t.conversationType,S=t.targetId,y=t.source,_=t.isMentioned,m=t.receivedStatusInfo,E=t.directedUserIds,T=a;m&&(T=e.transformReceivedStatusFlag(m));var P={};if(u=u||0,C)for(var R in C)P[R]={v:"",ts:0},P[R].v=C[R],P[R].ts=u;return{conversationType:v,targetId:S,channelId:g||"",direction:s,senderUserId:r,status:c||10,sentTime:u,objectName:n,content:JSON.stringify(o),messageUid:l||"",noNotification:!!f,supportExt:!!h,extMsg:JSON.stringify(P),readStatus:T,searchContent:p||"",isUnread:!!d,source:y||"",isMention:_,directedUsers:E}})),i=r._callCppProxy("insertMessages",JSON.stringify(s),o);n({code:i?e.ErrorCode.SUCCESS:e.ErrorCode.MSG_INSERT_ERROR,data:i||!1})}))},t.prototype.getMessageCount=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getMessageCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.deleteMessages=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteMessages",t),r(e.ErrorCode.SUCCESS)}))},t.prototype.deleteMessagesByTimestamp=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("deleteMessagesByTimestamp",t,o,r,n,s),a(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearMessagesByTimestamp=function(t){var o=this;return new Promise((function(r,n){var s=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));o._callCppProxy("deleteMessageBySendTimeInBatches",JSON.stringify(s)),r(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearRemoteHistoryMessages=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));r._callCppProxy("deleteRemoteMessageBySendTimeInBatches",JSON.stringify(i),o||!1,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getMessage",t),s=o._buildMessage(n,{isOffLineMessage:!1});r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setMessageContent=function(t,o,r){var n=this;return new Promise((function(s){o=JSON.stringify(o),n._callCppProxy("setMessageContent",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSearchField=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setMessageSearchField",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSentStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageSentStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageReceivedStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageReceivedStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.saveConversationMessageDraft=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("saveTextMessageDraft",t,o,r,n||"")&&i(e.ErrorCode.SUCCESS),i(e.ErrorCode.DRAFT_SAVE_ERROR)}))},t.prototype.getConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTextMessageDraft",t,o,r||"");s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearTextMessageDraft",t,o,r||"")&&s(e.ErrorCode.SUCCESS),s(e.ErrorCode.DRAFT_REMOVE_ERROR)}))},t.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},t.prototype.batchSetConversationStatus=function(t){var o=t[0],r=o.conversationType,n=o.targetId,s=o.isTop,i=o.notificationStatus,a=o.channelId,c=o.isUpdateTime,u=void 0===c||c,p=this._callCppProxy("getConversationNotificationStatus",r,n,a||""),d=this._callCppProxy("getConversationTopStatus",r,n,a||""),l=e.isUndefined(i)?Boolean(p):i===e.NotificationStatus.OPEN,f=e.isUndefined(s)?Boolean(d):s;return this.setConversationStatus(r,n,l,f,a,u)},t.prototype.getConversationNotificationLevel=function(t,o,r){return S(this,void 0,void 0,(function(){var n;return y(this,(function(s){return n=this._callCppProxy("getBlockPushLevelForConversation",o,r,t),[2,Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})]}))}))},t.prototype.setConversationNotificationLevel=function(t,o,r,n){var s=this;return void 0===n&&(n=""),new Promise((function(i){s._callCppProxy("setBlockPushLevelForConversation",o,n,t,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}))}))},t.prototype.batchSetConversationNotificationLevel=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,level:o}}));r._callCppProxy("setBlockPushLevelInBatches",JSON.stringify(i),(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getTotalUnreadCountByLevels=function(t,o,r){if(r){var n=this._callCppProxy("getUnreadMentionedCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})}var s=this._callCppProxy("getUnreadCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},t.prototype.sendReadReceiptMessage=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("sendReadReceipt",t,r||"",o,(function(){o.forEach((function(e){n._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(n._callCppProxy("getMessage",e)).messageId;n.setMessageReceivedStatus(t,1)}catch(t){n.logger.error(g.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReader=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getMessageReader",t,r,o,(function(t,r){var i=[],a={};(t=JSON.parse(t)).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:r};n._updateReadReceiptInfo(o,c),setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.sendReadReceiptMessageV4=function(t,o,r){var n=this;return new Promise((function(s){var i=t.conversationType,a=t.targetId,c=t.channelId;n._callCppProxy("sendMessageReadReceipt",i,a,c||"",o,r,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReadReceiptV4=function(t,o){var r=this;return new Promise((function(n){var s=t.targetId,i=t.channelId;r._callCppProxy("getMessageReadReceipt",s,i||"",o,(function(t,s,i){var a=[],c=r._callCppProxy("getMessage",o),u=JSON.parse(c);try{JSON.parse(i).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;a.push({userId:o,readTime:r})}))}catch(e){r.logger.error(g.P_PARSE_JSON_E,"method: getMessageReadReceipt, info: "+i+", error: "+e)}var p=JSON.parse(u.readReceiptRequest||"{}"),d=p.readerList,l=void 0===d?[]:d,f=p.readCount,h=void 0===f?0:f,C=!1;l.length<a.length&&(l=a,C=!0),h<s&&(h=s,C=!0),C&&r._callCppProxy("updateReadReceiptRequestInfo",o,JSON.stringify({readerList:l,readCount:h,totalCount:t})),setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:{list:a,totalCount:t,readCount:h}})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.updateConversationReadTime=function(t,o){var r=this;return new Promise((function(n){var s=t.conversationType,i=t.targetId,a=t.channelId;r._callCppProxy("updateConversationReadTime",s,i,a||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype._addChatroomCache=function(e,t,o){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:o,count:t})},t.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},t.prototype._try2RejoinChatroom=function(){var t=this;if(0!==this._chatroomCache.length){var o=this.logger.createTraceId();this._chatroomCache.forEach((function(r){return S(t,void 0,void 0,(function(){var t,n,s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return t=r.chatroomId,n=r.joinExist,s=r.count,this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_T,t,o),[4,this._joinChrm(t,s,n,!1)];case 1:return i=u.sent(),a=i.code,c=i.data,a===e.ErrorCode.SUCCESS?(this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_R,t,o),this._sendChatroomStatus({rejoinedRoom:v({chatroomId:t,count:s},c)}),[2]):(a===e.ErrorCode.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:t,errorCode:a}}),this.logger.warn(e.LogTagId.L_REJOIN_CHATROOM_R,"chrmId: "+t+", code: "+a,o),[2])}}))}))}))}},t.prototype._joinChrm=function(t,o,r,n){var s=this,i=r?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){n&&s._callCppProxy("clearMessages",e.ConversationType.CHATROOM,t,""),s._callCppProxy(i,t,o,(function(n,i,c,u,p,d){s._addChatroomCache(t,o,r),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{createTime:Number(n),memberCount:i,isAllChatroomBanned:c,isCurrentUserBanned:u,isCurrentChatroomBanned:p,isCurrentChatroomInWhitelist:d}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.joinChatroom=function(e,t){return S(this,void 0,void 0,(function(){return y(this,(function(o){switch(o.label){case 0:return[4,this._joinChrm(e,t,!1,!0)];case 1:return[2,o.sent().code]}}))}))},t.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},t.prototype.quitChatroom=function(t){var o=this;return this._rmChatroomCache(t),new Promise((function(r){o._callCppProxy("quitChatRoom",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getChatroomInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getChatroomInfo",t,o,r,(function(t,o){var r=t?JSON.parse(t).list:[],n=[];if(r.length>0)for(var i=0;i<r.length;i++)n.push(JSON.parse(r[i].obj));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{userInfos:n,userCount:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getChatroomHistoryMessages=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("getChatroomHistoryMessage",t,o,r,n,(function(t){var o;try{o=JSON.parse(t)}catch(e){o={list:[],hasMore:!1}}var r=o.list;if(r&&r.length)try{o.list=r.map((function(e){return s._buildMessage(e.obj)}))}catch(e){o.list=[]}setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}),"")}))},t.prototype.setChatroomEntry=function(t,o){var r=this;return new Promise((function(n){var s='[{"key":"'+o.key+'", "value":"'+o.value+'"}]';r._callCppProxy("setChatroomKV",t,s,!!o.isAutoDelete,!!o.isOverwrite,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.setChatroomEntries=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setChatroomKV",t,JSON.stringify(o.entries),!!o.isAutoDelete,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},t.prototype.removeChatroomEntry=function(t,o){var r=this,n=[o.key];return new Promise((function(s){r._callCppProxy("deleteChatroomKV",t,n,!!o.isOverwrite,(function(){s(e.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},t.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},t.prototype.removeChatroomEntries=function(t,o){var r=this;return new Promise((function(n){var s=o.entries.map((function(e){return e.key}));r._callCppProxy("deleteChatroomKV",t,s,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getChatroomEntry=function(t,o){return S(this,void 0,void 0,(function(){var r;return y(this,(function(n){switch(n.label){case 0:return[4,this.getAllChatroomEntry(t)];case 1:return(r=n.sent()).code===e.ErrorCode.SUCCESS?[2,{code:e.ErrorCode.SUCCESS,data:r.data?r.data[o]:null}]:[2,{code:r.code}]}}))}))},t.prototype.getAllChatroomEntry=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getChatroomKV",t,(function(t){var o={};try{(t?JSON.parse(t):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){o[e.key]=e.value?e.value:""}))}catch(e){}setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getFileToken=function(t,o,r,n,s){var i=this;return r=r||"",n=n||"",s=s||"",new Promise((function(a){var c;c=n&&"uploads"!==n?o||"":e.getUploadFileName(t,o);var u=i.getNaviInfoFromCache(),p={uploadDomain:e.getMinionURL(u,i.logger),env:i._environment};i._callCppProxy("getUploadToken",t,c,r,n,s,JSON.stringify(p),(function(t,o,r,n,s,i,u,p,d,l,f,h,C,g,v,S,y,_,m,E,T,P,R){setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{token:t,deadline:0,bosToken:o,bosDate:r,path:n,osskeyId:s,ossPolicy:i,ossSign:u,ossBucketName:p,fileName:c,s3Credential:d,s3Algorithm:l,s3Date:f,s3Policy:h,s3Signature:C,s3BucketName:g,stcAuthorization:v,stcContentSha256:S,stcDate:y,stcBucketName:_,minioAuthorization:m,minioContentSha256:E,minioDate:T,minioBucketName:P,downloadAuthInfo:R?JSON.parse(R):null}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.getFileUrl=function(t,o,r,n){var s=this;return new Promise((function(i){var a=s.getNaviInfoFromCache(),c={url:e.getMinionURL(a,s.logger)};s._callCppProxy("getDownloadUrl",t,r,n,o-1,JSON.stringify(c),(function(t){setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{downloadUrl:t}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.clearData=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("clearData");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getDeviceId=function(){var e=this._dbpath;return ae(e)},t.prototype.getVoIPKey=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("getVoIPKey",t,o,"",(function(t){setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.bindRTCRoomForChatroom=function(t){var o=this;return new Promise((function(r){var n=t.chatRoomId,s=t.rtcRoomId;o._callCppProxy("bindRTCRoomForChatroom",n,s,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getGroupMessageDeliverList=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getGroupMessageDeliverList",t,r,o,(function(t,o){var r=JSON.parse(t).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{totalCount:o,list:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getPrivateMessageDeliverTime=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getMessageDeliverTime",t);if(s)n({code:e.ErrorCode.SUCCESS,data:s});else{r._callCppProxy("getPrivateMessageDeliverList",o,t,(function(t){var o=0,r=JSON.parse(t).list;if(r.length>0){var s=JSON.parse(r[0].obj).time;o=s}setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}}))},t.prototype.rtcSignaling=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("rtcSignaling",t,o,r,n,(function(t){var o=Array.prototype.slice.call(t);i({code:e.ErrorCode.SUCCESS,buffer:o})}),(function(e){i({code:e})}),30)}))},t.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)}})}}))},t.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],30)}))},t.prototype.createTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.removeTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteTag",t,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.updateTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("renameTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getTagList=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getTags"),n=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));o({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.addTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));r._callCppProxy("addConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),r._callCppProxy("removeConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagsForConversation=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("removeTagsForConversation",t.conversationType,t.targetId,t.channelId||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.getConversationListByTag=function(t,o,r,n){var s=this;return new Promise((function(i){var a=s._callCppProxy("getConversationsForTagByPage",t,o,r||20,n||""),c=s._convertResultList(a,(function(e){return v(v({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.getUnreadCountByTag=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getConversationUnreadCountForTag",t,o);n({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setConversationStatusInTag=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setConversationToTopForTag",t,o.conversationType,o.targetId,o.channelId||"",r.isTop||!1,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getTagsForConversation=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getTagsForConversation",t.conversationType,t.targetId,t.channelId||""),s=o._convertResultList(n,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getTopConversationList=function(t,o){var r=this;return new Promise((function(n){var s=e.isUndefined(o)?r._callCppProxy("getTopConversations",t):r._callCppProxy("getTopConversations",t,o),i=JSON.parse(s).list.map((function(e){return r._buildConversation(e.obj)}));n({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},t.prototype.getAllUnreadMentionedCount=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getUnreadAndMentionCount",[e.ConversationType.GROUP],"");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getOSInfo=function(){return S(this,void 0,void 0,(function(){var t;return y(this,(function(o){return t={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:e.ErrorCode.SUCCESS,data:t}]}))}))},t.prototype.getMainProcessInfo=function(){return S(this,void 0,void 0,(function(){return y(this,(function(t){return[2,{code:e.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()}}]}))}))},t.prototype.setCallInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("callInfoSignaling",t,o,r,(function(t,o){setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{key:t,value:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.setProxy=function(t){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.DISCONNECTED?Promise.resolve({code:e.ErrorCode.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(W(t,this.logger))},t.prototype.getProxy=function(){return Promise.resolve(Q())},t.prototype.testProxy=function(t,o){return function(t,o,r){return new Promise((function(n){var s=/^https/.test(o)?q:F;r.info(e.LogTagId.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:t,testHost:o}));var i=s(o,t,(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(){n({status:t||0,data:o})}))}));i.once("timeout",(function(){return n({status:0})})),i.once("error",(function(e){return n({status:0,data:e.stack})})),i.end()}))}(t,o,this.logger)},t.prototype.checkDuplicateMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("checkDuplicateMessage",t);r({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.subscribeUser=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.SUBSCRIBE,t,(function(){s({code:e.ErrorCode.SUCCESS})}),(function(e,t){s({code:e,data:t})}),r)}))},t.prototype.unSubscribeUser=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.UNSUBSCRIBE,t,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}),0)}))},t.prototype.getSubscribeUserList=function(t,o,r){var n=this._callCppProxy("getSubscribeUserList",t,o,r),s=this._buildSubscribeEventData(n).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.setDuplicateMessageConfig=function(t){var o=this._callCppProxy("setDuplicateMessageConfig",[e.ConversationType.CHATROOM],Ce.cuid,t);return Promise.resolve({code:o})},t.prototype.getSubscribeUserStatus=function(t,o){var r=this._callCppProxy("getSubscribeStatusByUserIds",t,o),n=this._buildSubscribeEventData(r).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getMatchedMessage=function(t,o,r,n){var s,i=this._callCppProxy("getMatchedMessage",t.conversationType,t.targetId,o,r,n,t.channelId||""),a=[];try{s=JSON.parse(i).list;for(var c=0;c<s.length;c++){var u=this._buildMessage(s[c].obj);a.push(u)}}catch(t){return this.logger.error(g.P_PARSE_JSON_MSGS_E,i),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:a})},t.prototype.getConversations=function(t){var o,r=this,n=t.map((function(e){var t=e.conversationType,o=e.targetId,r=e.channelId;return{targetId:o,channelId:void 0===r?"":r,type:t}})),s=this._callCppProxy("getConversations",JSON.stringify(n));try{o=JSON.parse(s).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return this.logger.error(g.P_PARSE_JSON_MSGS_E,s),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t}(),_e=function(e){return{sendError:function(t){e.send({type:Y.ERROR,data:{msg:t}})},sendEvent:function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];e.send({type:Y.EVENT,data:{eventName:t,data:o}})},sendResponse:function(t){e.send({type:Y.RESPONSE,data:t})},sendCallback:function(t){e.send({type:Y.CALLBACK,data:t})}}},me=r.resolve(__dirname,"binding","electron-"+t.platform()+"-"+t.arch()+".node"),Ee={addon:null},Te=_e(process).sendError;try{Ee.addon=require(me)}catch(e){console.error("error ->",me,"\n",e),Te(e.toString())}Ee.addon||console.error("error -> cannot find module: ",me);var Pe=Ee.addon;!function(t){var o=this,r=t.argv.slice(2),n=r[0],s=r[1],i=r[2],a=_e(t),c=a.sendCallback,u=a.sendError,p=a.sendEvent,d=a.sendResponse,l=Pe?new ye(n,Pe,s,p,~~i):null;t.on("message",(function(t){return S(o,void 0,void 0,(function(){var o,r,n,s,i,a;return y(this,(function(u){switch(u.label){case 0:return o=t.reqId,r=t.method,n=t.args,s=t.hasResponse,l?s?("sendMessage"===r&&(i=n[3],n[3]=function(e){c({reqId:i,data:e})}),[4,l.callProxy.apply(l,_([r],n,!1))]):[3,2]:[2,d({reqId:o,success:!0,data:{code:e.ErrorCode.ADDON_NOT_EXIST,msg:"Cannot find module "+me}})];case 1:return a=u.sent(),!0,d({reqId:o,success:true,data:a}),[3,3];case 2:l.sendProxy.apply(l,_([r],n,!1)),u.label=3;case 3:return[2]}}))}))})),t.on("beforeExit",(function(e){null==l||l.destroy()})),t.on("uncaughtException",(function(e){u("uncaughtException "+(e.stack||e.toString()))})),t.on("unhandledRejection",(function(e){u("unhandledRejection "+e.stack)}))}(process);
1
+ "use strict";var e=require("@rongcloud/engine"),t=require("os"),o=require("child_process"),r=require("path"),n=require("http"),i=require("https"),s=require("zlib"),a=require("url"),c=require("net"),u=require("events"),p=require("tls"),d=require("fs"),l=require("crypto");function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function h(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 C=h(t),g=f(s),v=function(e,t){return v=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])},v(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}v(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var y,_=function(){return _=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},_.apply(this,arguments)};function m(e,t,o,r){return new(o||(o=Promise))((function(n,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(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(s,a)}c((r=r.apply(e,t||[])).next())}))}function E(e,t){var o,r,n,i,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,r&&(n=2&i[0]?r.return:i[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,i[1])).done)return n;switch(r=0,n&&(i=[2&i[0],n.value]),i[0]){case 0:case 1:n=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!n||i[1]>n[0]&&i[1]<n[3])){s.label=i[1];break}if(6===i[0]&&s.label<n[1]){s.label=n[1],n=i;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(i);break}n[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{o=n=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function T(e,t,o){if(o||2===arguments.length)for(var r,n=0,i=t.length;n<i;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(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",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_E="P-call_addon-E",e.P_CALL_ADDON_T="P-call_addon-T",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_R="P-call_addon-R",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_O="P-connect-O",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_PARSE_JSON_MSGS_R="P-parse_json_messsages-R",e.P_RECEIVE_MESSAGE_E="P-receive_message-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_SUBSCRIBE_DATA_E="P-parse_json_subscribe_data-E",e.P_PARSE_JSON_USER_PROFILE_E="P-parse_json_user_profile-E",e.P_PARSE_JSON_USER_PROFILE_LIST_E="P-parse_json_user_profile_list-E",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R",e.P_PARSE_JSON_E="P-parse_json-E"}(y||(y={}));var P,R={flushTimestamp:Date.now(),queue:[],locked:!1};function I(){P&&clearInterval(P)}function O(e,t){I(),P=setInterval((function(){return b(e,t)}),1e4)}function N(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=R.queue).push.apply(e,t)}var M=200;function b(e,t){var o=R.queue,r=R.flushTimestamp;if(!(R.locked||0===o.length||Date.now()-r<3e4&&o.length<M)){R.locked=!0;var n=t.createTraceId(),i=t.getSessionId(),s=o.splice(0,M).map((function(e){var t=e.sessionId,o=e.level,r=e.time,n=e.type,s=e.tag,a=e.loggerId,c=e.content,u=e.traceId;return{level:o,time:r,type:n,tag:s,sessionId:i+":"+t,content:JSON.stringify({loggerId:a,content:c,traceId:u})}}));t.debug(y.P_WRITE_LOG_T,"writingLen: "+s.length+", queueLen: "+o.length,n);var a=JSON.stringify(s);e.writeLog(a),t.debug(y.P_WRITE_LOG_R,"write done, queueLen: "+o.length,n),R.flushTimestamp=Date.now(),R.locked=!1,setTimeout((function(){return b(e,t)}))}}var U=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return S(t,e),t.prototype.flush=function(e){N(e)},t}(e.BasicLogger),x=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return S(t,e),t.prototype.flush=function(e){N(e)},t}(e.BasicStatistic),L=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])},w=function(e){return"string"==typeof e},A=function(e){return w(e)?e.toUpperCase():""},D=function(e,t){var o="";return 2!==e.length?o="Unexpected number of bytes received.":5!==e[0]?o="Unexpected SOCKS version number: "+e[0]+".":255===e[1]?o="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(o="Unexpected SOCKS authentication method: "+e[1]+"."),o},k=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: "+e[0]+".":0!==e[1]&&(t="Username and password authentication failure: "+e[1]+"."),t},J=function(e){var t=A(e.method)||"GET",o=e.pathname||"/",r=e.headers||{},n=e.search||"";r.Host=e.host||"loclahost";var i="";for(var s in i=t+" "+(o+n)+" HTTP/1.1\n",r){if(Object.hasOwnProperty.call(r,s))i+=s+": "+r[s]+"\n"}return e.body&&(i+="Content-Length: "+e.body.length+"\n"),i+="\n","POST"===t&&e.body&&(i+=""+e.body),i},B=function(e){return new Promise((function(t){var o,r;e.socket.once("data",(function(r){var n,i=D(r,o);if(!i)return 2===r[1]?(e.socket.once("data",(function(o){var r=k(o);r?e.emit("error",new Error("SOCKS authentication failed. "+r)):t()})),n=[1],L(e.socksUsername,n),L(e.socksPassword,n),void e.write(Buffer.from(n))):void t();e.emit("error",new Error("SOCKS authentication failed. "+i))})),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,i;switch(e.socket.once("data",(function(t){var o;5!==t[0]?o="Unexpected SOCKS version number: "+t[0]+".":0!==t[1]?o=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 "+e}}(t[1])+".":0!==t[2]&&(o="The reserved byte must be 0x00."),o?e.emit("error",new Error("SOCKS connection failed. "+o)):r()})),(n=[]).push(5),n.push(1),n.push(0),c.isIP(t)){case 0:n.push(3),L(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,(i=Buffer.from(n)).writeUInt16BE(o,i.length-2),e.write(i)}))},j=function(e){function t(t){var o=e.call(this)||this;return o.readable=!0,o.socket=new c.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: "+e);if(!t||"string"!=typeof t)throw new TypeError("Invalid host: "+t);return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return m(o,void 0,void 0,(function(){var o;return E(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}(u.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 j(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}(n.Agent),H=function(e,t,o){return(t=_(_({},t),a.parse(e))).port||(t.port=80),t.agent=new q(t),n.request(t,o)},G=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=p.connect(e,(function(){t.authorized=t.socket.authorized,o.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},K=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=G,r}return S(t,e),t}(i.Agent),W=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 K(e,t),t.agent=s,i.request(e,t,o)},Q=null;function Y(t,o,r){void 0===r&&(r=!1);var s=o.url,a=o.headers,c=o.body,u=o.method,p=o.query,d=o.timeout,l=void 0===d?e.HTTP_TIMEOUT:d;return new Promise((function(o){var d=/^https/.test(s),f={headers:_(_({},a),{"Accept-Encoding":"gzip, br"}),method:u};d&&(f.rejectUnauthorized=r);var h=null;Q?((f=_(_({},f),Q)).body=c,h=d?W:H):(h=n.request,d&&(f.agent=new i.Agent(f),h=i.request));var C=h(e.appendUrl(s,p),f,(function(e){var t,r,n=e.statusCode,i="";if("gzip"===(null===(t=e.headers)||void 0===t?void 0:t["content-encoding"])){var s=g.default.createGunzip();e.pipe(s),s.on("data",(function(e){i+=e})),s.on("end",(function(){o({status:n,data:i})}))}else if("br"===(null===(r=e.headers)||void 0===r?void 0:r["content-encoding"])){var a=g.default.createBrotliDecompress();e.pipe(a),a.on("data",(function(e){i+=e})),a.on("end",(function(){o({status:n,data:i})}))}else e.setEncoding("utf8"),e.on("data",(function(e){i+=e})),e.once("end",(function(){o({status:n||0,data:i})}))}));C.once("timeout",(function(){t.warn(y.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:s,method:u,query:p,timeout:l})),o({status:0})})),C.setTimeout(l),C.once("error",(function(e){t.warn(y.P_HTTP_REQ_E,JSON.stringify({msg:e.stack,url:s,method:u,query:p,timeout:l})),o({status:0})})),C.write(c),C.end()}))}function X(t,o){return t?(Q=_(_({},Q),t),o.info(e.LogTagId.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:Q})),{code:e.ErrorCode.SUCCESS}):(Q=null,o.info(e.LogTagId.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:e.ErrorCode.SUCCESS})}function z(){var t=Q||void 0;return{code:e.ErrorCode.SUCCESS,data:t}}var $,Z=[],ee=!1,te=function(){return m(void 0,void 0,void 0,(function(){var t,o,r,n,i,s,a,c,u,p,d,l,f;return E(this,(function(h){return ee||0===Z.length||(ee=!0,t=Z.shift(),o=t.args,r=t.resolve,n=o.addon,i=o.startTime,s=o.endTime,a=o.level,c=o.realtimeReport,u=0,p=0,d=[],l=function(t){u+=t.length;var o=t.split(","),n=o[0],i=o[1],s=o[2],l=o[3],f=o[4],h=o.slice(5);if(u>e.REAT_TIME_LOG_SIZE&&parseInt(i,10)!==p)r(d);else{p=parseInt(i,10);try{if(!c&&a<0)return;var C={time:parseInt(i,10),level:parseInt(l,10),sessionId:n,type:s,tag:f,content:h.join(",")};d.push(C)}catch(e){console.error(e)}}},f=function(e){r(d),ee=!1,te()},n.getFullLog(a,i,s,!1,l,f)),[2]}))}))},oe=function(t){function o(o,r,n,i,s){var a=this,c="Electron|"+process.versions.electron+"|"+process.arch+"|"+process.platform;return(a=t.call(this,r,n,c,{getLogs:function(e,t,r,n){return m(this,void 0,void 0,(function(){return E(this,(function(i){switch(i.label){case 0:return[4,(s={startTime:e,endTime:t,level:r,realtimeReport:n,addon:o},m(void 0,void 0,void 0,(function(){return E(this,(function(e){return[2,new Promise((function(e){Z.push({resolve:e,args:s}),te()}))]}))})))];case 1:return[2,{logs:i.sent(),dbReady:!0}]}var s}))}))},getTimestamp4RealtimeLog:function(){var t=o.getStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP);return parseInt(t,10)||0},setTimestamp4RealtimeLog:function(t){o.setStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP,t.toString())}},i)||this).subProcess=s,a}return S(o,t),o.prototype.send=function(e){return Y(this.logger,e)},o.prototype.compressLogs=function(e){return m(this,void 0,void 0,(function(){var t,o,r;return E(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.data}]:[2,{success:o,data:""}]}}))}))},o}(e.BasicReporter),re=[e.EConnectProtocol.RMTP,e.EConnectProtocol.TLS,e.EConnectProtocol.QUIC],ne=function(e){return"RongCloud/navis/"+e+"/navi-cache.json"},ie="deviceId",se=function(e){return"RongCloud/caches/"+e+"/staticConfig.json"},ae=function(e){return"RongCloud/cloudControl/"+e+"/cloudControl.json"},ce=null,ue=function(){var e,o=Date.now(),r=[t.arch(),t.platform(),process.pid,o,Math.floor(Math.random()*o)].join("__");return e=r,l.createHash("md5").update(e).digest("hex")},pe=function(e){if(ce)return ce;var t=r.resolve(e,ie);return d.existsSync(t)?ce=d.readFileSync(t).toString():(ce=ue(),d.writeFileSync(t,ce),ce)},de=function(){function e(e){this._callCppProxy=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,o,r,n,i){var s=JSON.stringify(n);"{}"!==s&&e.info(y.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:r,ext:n})),this._callCppProxy("setMessageExtension",t,o,r,s,i)},e.prototype.setLocalFromReceiveMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,i=t.messageUId,s=t.expansion,a=t.sentTime,c={};for(var u in s)c[u]={v:"",ts:0},c[u].v=s[u],c[u].ts=a;this._setToProtocol(e,r,n,i,c,o||"")},e.prototype.setLocalFromExtMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,i=t.content,s=t.sentTime,a=i,c=a.put,u=this._callCppProxy("getMessage",a.mid),p=JSON.parse(u).extMsg,d=JSON.parse(p||"{}");if(c)for(var l in c){var f=d[l];f&&f.ts<s-this._setTime?(f.v=c[l],f.ts=s-this._setTime):(d[l]={v:"",ts:0},d[l].v=c[l],d[l].ts=s-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}();!function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}($||($={}));var le=function(){function t(t,o,r,n){var i=this;this.p=t,this.emit=o,this.callback=r,this.errorHandle=n,this.count=0,this.maps={},this.p.on("message",(function(e){var t=e.type,s=e.data;switch(t){case $.EVENT:var a=s,c=a.eventName,u=a.data;null==o||o.apply(void 0,T([c],u,!1));break;case $.RESPONSE:var p=s,d=p.reqId,l=p.success,f=p.data,h=i.maps[d];if(!h)return;h({success:l,data:f}),delete i.maps[d];break;case $.CALLBACK:null==r||r(s);break;case $.ERROR:var C=s.msg;null==n||n(C)}})),this.p.on("error",(function(e){null==n||n("SubProcessProxy error "+e)})),this.p.on("exit",(function(t,o){if(0!==t){for(var r in i.maps){if(Object.prototype.hasOwnProperty.call(i.maps,r))(0,i.maps[r])({success:!0,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==n||n("SubProcessProxy exit "+t+" "+o,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return t.prototype.call=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return m(this,void 0,void 0,(function(){var r=this;return E(this,(function(n){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(e){var n=++r.count;r.maps[n]=e;var i={reqId:n,method:t,args:o,hasResponse:!0};r.p.send(i)}))]}))}))},t.prototype.send=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return m(this,void 0,void 0,(function(){var r;return E(this,(function(n){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),r={reqId:-1,method:e,args:o},this.p.send(r),[2]}))}))},t.prototype.destroy=function(){this.send("destroy")},t}();function fe(e){void 0===e&&(e="IPv4");for(var o=t.networkInterfaces(),r=[],n=0,i=Object.values(o);n<i.length;n++){var s=i[n];if(s&&-1!==Object.prototype.toString.call(s).indexOf("Array")){var a=s.filter((function(t){return!(t.internal||(o=t.mac,/^(0{1,2}[:-]){5}0{1,2}$/.test(o))||t.family&&t.family!==e);var o})).map((function(e){return e.mac}));r.push.apply(r,a)}}return r.length?T([],r,!0).sort()[0]:""}var he,Ce=function(e,t,o){return m(void 0,void 0,void 0,(function(){var r,n;return E(this,(function(i){return r=l.createDecipheriv("aes-256-cbc",t,o),n=r.update(e,"base64","utf-8"),[2,n+=r.final("utf8")]}))}))},ge=function(e){if(!d.existsSync(e)){var t=r.resolve(e,"..");d.existsSync(t)||ge(t),d.mkdirSync(e)}},ve=function(t){function o(e,o,n,i,s){var a=t.call(this,e,o,n,s)||this;a.naviPath="",a._caches={},a.naviPath=i+"/"+ne(e);var c=r.dirname(a.naviPath);return d.existsSync(c)||ge(c),a}return S(o,t),o.prototype.httpRequest=function(t,o,r,n){return m(this,void 0,void 0,(function(){var i,s,a,c,u;return E(this,(function(p){switch(p.label){case 0:return i="token="+encodeURIComponent(r)+"&v="+e.FORMATED_VERSION+"&p=PC&ev=5.10.2&m="+fe(),s=t+"/navi.json?r="+Date.now()+"&env="+this._environment,this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:s,body:i}),n),[4,Y(this.logger,{method:"POST",headers:{appId:o},body:i,url:s,timeout:e.NAVI_REQ_TIMEOUT})];case 1:if(200!==(a=p.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s,code:a.status}),n),[2,{code:this.transHttpCode(a.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s,data:a.data}),n);try{return c=JSON.parse(a.data),u=/^https/.test(s)?"https":"http",c.protocol=u,c.code&&200!==c.code?[2,{code:this.transHttpCode(c.code)}]:[2,{code:e.ErrorCode.SUCCESS,data:c}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,a.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.httpRequestV2=function(t,o,r,n){return m(this,void 0,void 0,(function(){var i,s,a,c;return E(this,(function(u){switch(u.label){case 0:return i=this.getNaviV2RequestOption({appkey:o,token:r,uri:t,platform:"electron",protocol:re.join(","),mac:fe()}),this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:i.url,body:i.body,headers:i.headers}),n),[4,Y(this.logger,i)];case 1:if(200!==(s=u.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i.url,code:s.status}),n),[2,{code:this.transHttpCode(s.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i.url,data:s.data}),n);try{return a=JSON.parse(s.data),c=/^https/.test(i.url)?"https":"http",a.protocol=c,[2,{code:e.ErrorCode.SUCCESS,data:a}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,s.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.getNaviCache=function(t){var o=this.getCatchKey(t),r=this._caches[o];if(r)return r;if(!d.existsSync(this.naviPath))return null;var n=d.readFileSync(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(n),this._caches[o]}catch(t){this.logger.error(e.LogTagId.L_PARSE_NAVI_E,n)}return null},o.prototype.setNaviCache=function(t,o){var r=Date.now(),n=this.getCatchKey(t);if(e.notEmptyObject(this._caches))for(var i in this._caches){(r-this._caches[i].timestamp>e.NAVI_CACHE_DURATION||n===i)&&delete this._caches[i]}this._caches[n]={token:t,naviInfo:o,timestamp:Date.now(),environment:this._environment},d.writeFileSync(this.naviPath,JSON.stringify(this._caches))},o.prototype.setEnvironment=function(e){this._environment=e},o}(e.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"}(he||(he={}));var Se,ye=function(t){function o(o,r,n,i,s,a){var c=t.call(this,o,n,i,s,a)||this;return c.callCppProxy=r,c._connectedTime=0,c._naviInfo=null,c._excludeLogTag=["P-RCGetValueForKey-T","P-RCGetValueForKey-E","P-RCGetValueForKey-R","P-RCSetValueForKey-T","P-RCSetValueForKey-E","P-RCSetValueForKey-R"],c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.callCppProxy("setConnectionStatusListener",c._onConnectionStatusChange.bind(c),(function(e){c.logger.info(y.P_DB_OPEN_O,e)}),(function(){return c.recvPong(e.ErrorCode.SUCCESS)}),c._onConnectionStatusChange.bind(c),c._onTcpConnectResponse.bind(c)),c}return S(o,t),o.prototype.getConnectedTime=function(){return this._connectedTime},o.prototype.connectWithToken=function(t,o,r,n){var i=this;return new Promise((function(s){i._naviInfo=o,i.connectResolve={resolve:s,traceId:n,userId:o.userId};var a={},c=z().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(_(_({},a),{call_plus:i._openCallPlus})),p=i.getCmpList(o,!0).filter((function(e){return re.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];p.forEach((function(t){var o=d.find((function(e){return e.addr===t.addr}));o?o.protocol!==e.EConnectProtocol.QUIC&&t.protocol!==e.EConnectProtocol.QUIC||(o.race=!0,o.protocol=e.EConnectProtocol.QUIC):(t.race=!1,d.push(t))})),i.logger.info(y.P_CONNECT_O,JSON.stringify({use:d,catche:i.cmpWeightCache,proxy:a,FORMATED_VERSION:e.FORMATED_VERSION,reconnectKickEnable:r}),n),i._startTime=Date.now();try{i.callCppProxy("connectWithToken",t,e.FORMATED_VERSION,JSON.stringify(_(_({},o),{serverAddr:d,tagBlacklist:i._excludeLogTag.join(",")})),r,u)}catch(t){i.logger.error(y.P_CALL_ADDON_E,null==t?void 0:t.stack,n),i.recvConnectRes(e.ErrorCode.RC_SOCKET_NOT_CREATED)}}))},o.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.callCppProxy("disconnect",t)},o.prototype.sendPing=function(t){var o=this;return new Promise((function(r){o.pingResolve=r,o.callCppProxy("sendHeartbeat"),setTimeout((function(){return o.recvPong(e.ErrorCode.TIMEOUT)}),t)}))},o.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},o.prototype._onConnectionStatusChange=function(t,o){switch(this.logger.info(y.P_CONNECT_S,JSON.stringify({status:t,delay:o})),t){case e.ErrorCode.SUCCESS:this.recvConnectRes(e.ErrorCode.SUCCESS);break;case e.ErrorCode.RC_CONN_REDIRECTED:case 32061:this.recvConnectRes(e.ErrorCode.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case e.ErrorCode.RC_SOCKET_DISCONNECTED:this.recvConnectRes(t,!1);break;case e.ErrorCode.RC_SOCKET_NOT_CREATED:case e.ErrorCode.RC_CONN_ACK_TIMEOUT:case e.ErrorCode.RC_TCP_RESET:this.recvConnectRes(t);break;case e.ErrorCode.RC_UDP_DISCONNECTED:this.recvConnectRes(t,!0,o);break;default:this.recvConnectRes(t,!0)}},o.prototype.recvConnectRes=function(t,o,r){if(this.connectResolve){var n=this.connectResolve,i=n.resolve,s=n.userId,a=Date.now()-(this._startTime+this._tcpDuration),c={bid:e.getbundleId(),cod:t,net:this.getNetwork().type,dur:a,spr:0,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,count:this.retryCount};return this.statisticLog.record(e.StatisticsTag.IM_CMP_RMTP,JSON.stringify(c)),t===e.ErrorCode.SUCCESS&&(this._connectedTime=Date.now()-this.callCppProxy("getDeltaTime")),i({code:t,data:s}),void(this.connectResolve=null)}if(o)this.onDisconnectByServer(t,r);else{if(t===e.ErrorCode.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED)return;this.onDisconenctUnusual(t)}},o.prototype._onTcpConnectResponse=function(t,o,r,n,i,s,a){var c,u=this.cmpWeightCache.findIndex((function(e){return e.addr===o+":"+r})),p={bid:e.getbundleId(),ptc:e.ProtocalType.TCP,cod:t,net:this.getNetwork().type,dur:n,spr:0,pr:(null===(c=this._naviInfo)||void 0===c?void 0:c.type)||0,hos:o+":"+r,idx:u,rct:this.retryCount?e.ConnectType.RECONNECT:e.ConnectType.CONNECT,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,rsn:this.reason,ddu:i,count:this.retryCount,weight:u>=0?this.cmpWeightCache[u].weight:-1};this.statisticLog.record(e.StatisticsTag.IM_CMP,JSON.stringify(p)),this.logger.info(y.P_CONNECT_ENTRY_S,JSON.stringify({code:t,host:o,port:r,duration:n,dnsDuration:i,index:s,isQuic:a})),t===he.SUCCESS&&(this.curCmpUrl=o+":"+r,this.updateCmpWeight(o+":"+r,!0,a))},o}(e.AConnectionMgr),_e=function(t){function o(e,o,n){var i=t.call(this,e,o)||this;i.appkey=e,i.logger=o,i.dbpath=n,i._cachePath="",i._cachePath=n+"/"+se(e);var s=r.dirname(i._cachePath);return d.existsSync(s)||ge(s),i}return S(o,t),o.prototype.getCache=function(){return d.existsSync(this._cachePath)&&d.readFileSync(this._cachePath,{encoding:"utf8"})||null},o.prototype.setCache=function(e){d.writeFileSync(this._cachePath,e)},o.prototype.clearCache=function(){d.writeFileSync(this._cachePath,"")},o.prototype.sendRequest=function(e){return m(this,void 0,void 0,(function(){var t,o,r;return E(this,(function(n){switch(n.label){case 0:return[4,Y(this.logger,{url:e,body:""})];case 1:return t=n.sent(),o=t.status,r=t.data,[2,{code:o,data:r}]}}))}))},o.prototype.decryptData=function(t){return m(this,void 0,void 0,(function(){var o,r;return E(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,Ce(t,e.STATIC_CONFIG_KEY,e.STATIC_CONFIG_IV)];case 1:return o=n.sent(),[2,JSON.parse(o)];case 2:return r=n.sent(),this.logger.error(e.LogTagId.L_GET_STATIC_CONF_E,JSON.stringify({error:null==r?void 0:r.stack})),[3,3];case 3:return[2]}}))}))},o}(e.BasicStaticConfigManager),me=function(t){function o(e,o,n,i,s,a,c){var u=t.call(this,o,e,n,a)||this;u.deviceId=i,u.model="",u.catchFilePath="",u.addon=c,u.model="Electron|"+process.platform+"|"+process.arch,u.catchFilePath=s+"/"+ae(e);var p=r.dirname(u.catchFilePath);return d.existsSync(p)||ge(p),u.init(),u}return S(o,t),o.prototype.httpRequest=function(t,o,r,n){return m(this,void 0,void 0,(function(){var i,s,a,c,u,p,d,l;return E(this,(function(f){switch(f.label){case 0:return(i=n).deviceId=this.deviceId,i.model=this.model,s={url:t,method:o,headers:r,body:JSON.stringify(i)},this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify(s)),[4,Y(this.logger,s)];case 1:a=f.sent(),c=a.status,u=a.data,p=void 0===u?"":u,this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({status:c,data:p}));try{return d=JSON.parse(p),l=d.data,[2,{code:c,data:l}]}catch(t){return this.logger.warn(e.LogTagId.L_CLOUD_CONFIG_DATA_E,JSON.stringify({status:c,data:p,error:t})),[2,{code:c,msg:t}]}return[2]}}))}))},o.prototype.setCloudControllerCache=function(t){d.writeFileSync(this.catchFilePath,JSON.stringify(t)),this.logger.info(e.LogTagId.L_CLOUD_SET_CACHE_O,JSON.stringify(t))},o.prototype.getLocalCloudControllerCache=function(){if(!d.existsSync(this.catchFilePath))return null;var t=d.readFileSync(this.catchFilePath,{encoding:"utf8"});return this.logger.info(e.LogTagId.L_CLOUD_GET_CACHE_O,JSON.stringify({appkey:this.appkey,data:t})),t},o.prototype.setMRTRConfig=function(t){var o={mrtrChatroom:t.chatroom,mrtrGroup:t.group,mrtrPrivate:t.private,mrtrUltraGroup:t.ultraGroup};this.logger.info(e.LogTagId.L_CLOUD_SET_MRTR_O,JSON.stringify(o)),this.addon.setCloudConfig(JSON.stringify(o))},o}(e.BaseCloudController);!function(e){e[e.cuid=1]="cuid",e[e.uid=2]="uid",e[e.all=4]="all"}(Se||(Se={}));var Ee=function(){function t(t,n,i,s,a,c){var u=this;this._appkey=t,this._cppProtocol=n,this._dbpath=i,this._dispatchEvent=s,this._enableSyncEmptyTopConversation=a,this._logOutputLevel=c,this._customMessageType={},this.cloudControllerUri="",this.cloudControllerLock=!0,this.cloudControllerMsgs=[],this._buildSubscribeEventData=function(t){var o=[];try{JSON.parse(t).list.forEach((function(t){var r=JSON.parse(t.obj),n=r.userId,i=r.subscribeType,s=r.subscribeTime,a=r.duration,c=r.operationType,p=r.details,d=void 0===p?[]:p,l=r.userProfile,f={userId:n,subscribeType:i,subscribeTime:s,expiry:a,operationType:c};i===e.SubscribeType.ONLINE_STATUS&&(f.details=d.map((function(e){var t=JSON.parse(e);return{changeTime:t.changeTime,eventValue:t.changeValue,platform:t.platform}}))),i===e.SubscribeType.USER_PROFILE&&(f.userProfile=u._string2userProfileInfo(l)),o.push(f)}))}catch(e){u.logger.error(y.P_PARSE_JSON_SUBSCRIBE_DATA_E,JSON.stringify({error:null==e?void 0:e.stack,data:t}))}return o},this._chatroomCache=[],this.rtcHeartbeatResolves={};var p=this._dbpath,d=pe(p);this.logger=new U(this._appkey,"RC-M","IM"),this._cppProtocol.initWithAppkey(t,p,e.FORMATED_VERSION,this.logger.getSessionId());var l=o.fork(r.resolve(__dirname,"sub-process.js"));this.subProxy=new le(l),this.statisticLog=new x(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),O(this._cppProtocol,this.logger),this.reporter=new oe(this._cppProtocol,t,d,this.logger,this.subProxy),this.logger.info(y.P_INIT_O,JSON.stringify({appkey:t,dbpath:p,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:d,commit:"3cbfa0729fd40ab8df50322aa87f2e7cc2601fcc"})),this._callCppProxy("setDeviceId",d),this._staticConfigManager=new _e(t,this.logger,p),this.navi=new ve(t,this.logger,this.statisticLog,p,this._staticConfigManager),this.tcpMgr=new ye(t,this._callCppProxy.bind(this),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)}),this._enableCreateEmptyTopConversation(this._enableSyncEmptyTopConversation),this._initCloudController(d,p),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setPushNotificationListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setSubscribeEventListener(),this._setUserProfileListener(),this._msgExpansionHandler=new de(this._callCppProxy.bind(this))}return t.prototype._initCloudController=function(t,o){var r=e.urlCenter.getCloudControllerUrl();this.cloudControllerUri=r[0],this.cloudController=new me(this._appkey,this.logger,this.reporter,t,o,this.statisticLog,this._cppProtocol),e.isStartCloudController()&&this.cloudControllerUri&&this.cloudController.request(this.cloudControllerUri,e.InvokerType.init)},t.prototype.callProxy=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return m(this,void 0,void 0,(function(){var r,n,i;return E(this,(function(s){switch(s.label){case 0:if(!(r=this[t]))return this.logger.warn(y.P_CALL_MAIN_E,JSON.stringify({method:t,error:"not found"})),[2,Promise.resolve({code:e.ErrorCode.NOT_SUPPORT})];n="",s.label=1;case 1:return s.trys.push([1,3,,4]),[4,r.call.apply(r,T([this],o,!1))];case 2:return[2,s.sent()];case 3:return i=s.sent(),n=JSON.stringify({error:null==i?void 0:i.stack,method:t}),this.logger.error(y.P_CALL_MAIN_E,n),[3,4];case 4:return[2,{code:e.ErrorCode.MAIN_PROCESS_ERROR,msg:n}]}}))}))},t.prototype.sendProxy=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;return E(this,(function(r){if(!(o=this[e]))return this.logger.warn(y.P_CALL_MAIN_E,JSON.stringify({method:e,error:"not found"})),[2];try{o.call.apply(o,T([this],t,!1))}catch(t){this.logger.error(y.P_CALL_MAIN_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return[2]}))}))},t.prototype.registerRenderers=function(t){var o=t.navigators,r=t.areaCode,n=t.logServerUrl,i=t.environment;this._environment=i||"default",this.navi.setEnvironment(i),e.urlCenter.init({areaCode:r,navigators:o,logServerUrl:n})},t.prototype.onConnected=function(){return m(this,void 0,void 0,(function(){var e,t,o;return E(this,(function(r){switch(r.label){case 0:return e=this.getNaviInfoFromCache(),this.reporter.checkStart(e),this._try2RejoinChatroom(),t=this._dispatchEvent,o=["onConnected"],[4,this.getMainProcessCache()];case 1:return t.apply(this,o.concat([r.sent()])),[2]}}))}))},t.prototype.onConnecting=function(){this._dispatchEvent("onConnecting",void 0)},t.prototype.onSuspend=function(e){this._dispatchEvent("onSuspend",e)},t.prototype.onDisconnected=function(e){this._dispatchEvent("onDisconnected",e)},t.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.debug(y.P_CALL_ADDON_O,JSON.stringify({method:e,content:o}),n),(t=this._cppProtocol)[e].apply(t,o)}catch(t){throw this.logger.error(y.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),n),t}},t.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},t.prototype.sendHTTPRequest=function(e){return Y(this.logger,e)},t.prototype.onRendererLogsReceived=function(e){N.apply(void 0,e)},t.prototype.onRendererNetworkStatusReceived=function(t,o){if(this.tcpMgr.setNetwork(t,o),t.status&&e.isStartCloudController()&&this.cloudController){var r=this.tcpMgr.getToken();this.cloudController.request(this.cloudControllerUri,e.InvokerType.newWorkChange,r)}},t.prototype.destroy=function(){this.reporter.stop(),this.subProxy.destroy(),this._cppProtocol,I(),this._cppProtocol.destroy(),process.exit(0)},t.prototype.callExtra=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this[t];if(!n)return this.logger.warn(y.P_CALL_EXTRA_E,JSON.stringify({method:t,error:"not found"})),Promise.resolve({code:e.ErrorCode.NOT_SUPPORT});try{return n.call.apply(n,T([this],o,!1))}catch(e){this.logger.error(y.P_CALL_EXTRA_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})},t.prototype.getConversationsByPage=function(t,o,r,n,i){var s,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",t,o,r,i||!1,n||"");try{s=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.getUnreadConversationList=function(t){var o,r=this,n=this._callCppProxy("getUnreadConversationList",t);try{o=JSON.parse(n).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t.prototype.getConversationListWithAllChannel=function(){var t,o=this,r=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],n=this._callCppProxy("getConversationListWithAllChannel",r);try{t=JSON.parse(n).list.map((function(e){return o._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},t.prototype.getConversationListWithAllChannelByPage=function(t,o){var r,n=this,i=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],s=this._callCppProxy("getConversationListWithAllChannelByPage",i,t,o);try{r=JSON.parse(s).list.map((function(e){return n._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},t.prototype.getHistoryMessagesByObjectNames=function(t,o,r,n,i,s,a){var c=0===s,u=n+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",t,o,r,u,i,c,a||""),d=[];try{var l=JSON.parse(p).list;l.reverse();for(var f=0;f<l.length;f++){var h=this._buildMessage(l[f].obj);d[f]=h}}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:{list:u===d.length?d.slice(1,u):d,hasMore:n<d.length}})},t.prototype.updateMessageReceiptStatus=function(t,o,r,n){void 0===n&&(n="");var i=this._callCppProxy("updateMessageReceiptStatus",t,o,r,n);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:i})},t.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},t.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new U(this._appkey,e,t)},t.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},t.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},t.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},t.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),o=this.getNaviInfoFromCache(),r=this.tcpMgr.getCurrentUserId(),n=this.getDeviceId(),i=this._cppProtocol.getDeltaTime();return Promise.resolve({connectedTime:e,deviceId:n,crtUserId:r,naviInfo:o,connectionStatus:t,deltaTime:i})},t.prototype._enableCreateEmptyTopConversation=function(e){this._callCppProxy("enableCreateEmptyTopConversation",e)},t.prototype._registerMsgTypes=function(){for(var t in e.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},e.SEND_MESSAGE_TYPE_OPTION){var o=e.SEND_MESSAGE_TYPE_OPTION[t],r=o.isCounted,n=o.isPersited,i=o.searchProps,s=0;n&&(s|=1),r&&(s|=2),"RC:TypSts"===t&&(s=16),this._callCppProxy("registerMessageType",t,s,i||[])}},t.prototype._buildIsMentioned=function(t,o){var r,n=!1;if(e.isObject(t))r=t;else try{r=t?JSON.parse(t):t}catch(e){r=t,this.logger.error(y.P_PARSE_JSON_MSGS_E,JSON.stringify({content:t}))}return e.isObject(r)&&(n=!!r.mentionedInfo),{isMentioned:n,msgContent:r}},t.prototype._buildMsgOption=function(t){var o={isCounted:!1,isPersited:!1};return t in e.SEND_MESSAGE_TYPE_OPTION?o=e.SEND_MESSAGE_TYPE_OPTION[t]:t in this._customMessageType&&(o=this._customMessageType[t]),o},t.prototype._buildSupportExt=function(e,t,o){var r=null;return e&&(r=this._msgExpansionHandler.parseReceiveExpansion(o),"conversation"!==t&&"history"!==t||(r=this._msgExpansionHandler.parseConverOrHisExpansion(o))),r},t.prototype._handleReadReceiptRequest=function(e){var t=JSON.parse(e),o=this.getNaviInfoFromCache();if(!(null==o?void 0:o.grpRRVer))return t;var r=t,n=r.hasRespond,i=r.readerInfo,s=void 0===i?{}:i,a=r.readCount,c=r.totalCount,u=r.readerList,p=void 0===u?[]:u,d={readCount:a,totalCount:c};if(1===(null==o?void 0:o.grpRRVer)){var l=[];for(var f in s)l.push({userId:f,readTime:s[f]});d.readerList=l,d.hasRespond=n}return 3===(null==o?void 0:o.grpRRVer)&&(d.readerList=p),d},t.prototype._buildMessage=function(t,o){var r;void 0===o&&(o={});var n=o.isOffLineMessage,i=o.buildFrom,s=JSON.parse(t),a=s.channelId,c=s.conversationType,u=s.targetId,p=s.senderUserId,d=s.content,l=s.objectName,f=s.messageUid,h=s.direction,C=s.status,g=s.messageId,v=s.sentTime,S=s.readReceiptRequest,y=s.supportExt,m=s.pushContent,E=s.pushTitle,T=s.pushId,P=s.pushConfig,R=s.templateId,I=s.disableTitle,O=s.forcePushDetail,N=s.hasMore,M=s.directedUsers,b=s.noNotification,U=this._buildIsMentioned(d,g),x=U.isMentioned,L=U.msgContent,w=this._buildMsgOption(l),A=this._buildSupportExt(y,i,s),D=e.isUndefined(n)?v<this.tcpMgr.getConnectedTime():n,k={};P&&(k=e.pushJSONToConfigs(this.logger,P,T));var J=_(_({},k),{pushTitle:E,pushContent:m,pushData:m,disablePushTitle:I,forceShowDetailContent:O,templateId:R}),B={channelId:a,conversationType:c,targetId:u,senderUserId:p,content:L||{},messageType:l,messageUId:f||"",messageDirection:h,isOffLineMessage:D,sentTime:v,receivedTime:0,isPersited:w.isPersited,isCounted:w.isCounted,isMentioned:x,disableNotification:b,isStatusMessage:(null===(r=this._customMessageType[l])||void 0===r?void 0:r.isStatusMessage)||!1,canIncludeExpansion:y,expansion:y?A:null,receivedStatus:C,receivedStatusInfo:e.transformReceivedStatusInfo(C),messageId:g,pushConfig:J,hasMore:N,directedUserIds:M||[]};if(h===e.MessageDirection.RECEIVE?B.receivedStatus=this._compatibleReceivedStatus(B.receivedStatusInfo):h===e.MessageDirection.SEND&&(B.sentStatus=C),S){var F=this._handleReadReceiptRequest(S);B.readReceiptInfo=F}return B},t.prototype._compatibleReceivedStatus=function(t){var o=e.ReceivedStatus.UNREAD;return t.isRead?o=e.ReceivedStatus.READ:t.isListened?o=e.ReceivedStatus.LISTENED:t.isDownload?o=e.ReceivedStatus.DOWNLOADED:t.isRetrieved&&(o=e.ReceivedStatus.RETRIEVED),o},t.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),r=JSON.parse(o),n=r.readReceiptRequest?JSON.parse(r.readReceiptRequest):{},i=_(_({},n),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(i))},t.prototype._processRRRspMsg=function(e,t,o){if(t!==this.getCurrentUserId())for(var r=0,n=e[this.getCurrentUserId()]||[];r<n.length;r++){h=n[r];var i=this._callCppProxy("getMessage",h),s=JSON.parse(i),a=s.readReceiptRequest?JSON.parse(s.readReceiptRequest):{},c=a.isReceiptRequestMessage,u=a.readerList,p=void 0===u?[]:u;c&&!p.includes(t)&&(p.push(t),this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:c,readerList:p})))}else for(var d in e)for(var l=0,f=e[d];l<f.length;l++){var h=f[l];this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:!0,hasRespond:!0}))}},t.prototype._processRSMsg=function(t){var o=t.conversationType,r=t.targetId,n=t.content,i=t.channelId,s=n.msgId,a=n.rrn,c=n.tmn,u=n.endMsgTime;o===e.ConversationType.PRIVATE?this.updateMessageReceiptStatus(o,r,u,i||""):this._updateReadReceiptInfo(s,{readCount:a,totalCount:c});var p={conversationType:o,targetId:r,channelId:i};this._sendMessageReadReceipt(o===e.ConversationType.PRIVATE?{privateReadReceipt:_(_({},p),{endMsgTime:n.endMsgTime})}:{groupReadReceipt:_(_({},p),{totalCount:n.tmn,readedCount:n.rrn,messageUId:n.msgId})})},t.prototype._processSRSMsg=function(e){var t=this.getNaviInfoFromCache(),o=e.conversationType,r=e.targetId,n=e.content,i=e.channelId,s=e.senderUserId,a=e.sentTime;return s===this.tcpMgr.getCurrentUserId()&&(this._callCppProxy("clearUnreadCountByTimestamp",o,r,n.lastMessageSendTime,i||""),1!==(null==t?void 0:t.sesDriven)||(a>this.tcpMgr.getConnectedTime()||this._sendsyncReadStatus({conversationType:o,targetId:r,channelId:i,timestamp:n.lastMessageSendTime}),!1))},t.prototype._buildConversation=function(t){var o=JSON.parse(t),r=o.channelId,n=o.conversationType,i=o.targetId,s=o.unreadCount,a=o.lastestMsg,c=o.isTop,u=o.blockStatus,p=o.matchCount,d=o.hasUnreadMention,l=o.conversationTime,f=o.draft,h=u>0?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE;return{channelId:r,conversationType:n,targetId:i,unreadMessageCount:s,latestMessage:-1===JSON.parse(a).messageId?null:this._buildMessage(a),hasMentioned:d,mentionedInfo:null,notificationStatus:h,isTop:c,lastUnreadTime:0,matchCount:p,operationTime:l,notificationLevel:u,draft:f}},t.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}))},t.prototype._handleNotNotificationMessage=function(t){var o,r=t.messageType,n=t.senderUserId,i=t.content;if(r===e.MessageType.LOG_COMMAND&&t.senderUserId===e.RC_DEFAULT_USER){var s=t.content,a=s.startTime,c=s.endTime,u=s.platform,p=s.logId,d=s.uri;return this.reporter.report(parseInt(a,10),parseInt(c,10),u,d,p,t.messageUId),!0}if(r===e.MessageType.CLOUD_CONTROL&&n===e.RC_DEFAULT_USER)return this.cloudControllerMsgs.push(t),this._ccMsgHandler(),!0;if(r===e.MessageType.READ_STATE)return this._processRSMsg(t),!0;if("RC:MsgExMsg"===r)return this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),this._sendMessageExpansion(t),!0;if(r===e.MessageType.SYNC_READ_STATUS&&!this._processSRSMsg(t))return!0;if(r===e.MessageType.DELIVERED)return this._callCppProxy("setMessageDeliverTime",JSON.stringify(i)),this._sendMessageDelivered(t.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}}))),!0;if(r===e.MessageType.DELIVERED_MSG){var l={totalCount:t.content.tmn,list:null===(o=t.content.dl)||void 0===o?void 0:o.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};return this._sendGroupMessageDeliveredStatus(l),!0}return!1},t.prototype._setOnReceiveMessageListener=function(){var t=this;this._cppProtocol.setOnReceiveMessageListener((function(o,r,n,i){try{var s=t._buildMessage(o,{isOffLineMessage:n}),a=s.messageType,c=s.channelId,u=void 0===c?"":c,p=s.senderUserId,d=s.content,l=s.sentTime,f=s.conversationType,h=s.targetId;if(t._handleNotNotificationMessage(s))return;if(a===e.MessageType.READ_RECEIPT_REQUEST&&d.messageUId&&t._updateReadReceiptInfo(d.messageUId,{isReceiptRequestMessage:!0,hasRespond:!1}),a===e.MessageType.READ_RECEIPT_RESPONSE&&d.receiptMessageDic&&t._processRRRspMsg(d.receiptMessageDic,p,l),a===e.MessageType.GROUP_READ_RECEIPT_REQUEST){var C=d.msgId,g=d.rrn,v=d.tmn;t._updateReadReceiptInfo(C,{readCount:g,totalCount:v})}s.canIncludeExpansion&&t._msgExpansionHandler.setLocalFromReceiveMsg(t.logger,s),a===e.MessageType.READ_RECEIPT&&p===t.tcpMgr.getCurrentUserId()&&t._callCppProxy("clearUnreadCountByTimestamp",f,h,d.lastMessageSendTime,u);var S=!0;if(0!==r||i||(S=!1),a===e.MessageType.RECALL){if(!t.handleRecalledMessage(s))return;var _=t._fixRecallContentInfo(s);f=_.conversationType,h=_.targetId}t._sendMessageNotification(Object.assign(s,{hasMoreMsg:S,conversationType:f,targetId:h}))}catch(e){t.logger.error(y.P_RECEIVE_MESSAGE_E,JSON.stringify({error:null==e?void 0:e.stack,message:o}))}}),(function(){t._sendPullOfflineFinished()}))},t.prototype._ccMsgHandler=function(){var t;return m(this,void 0,void 0,(function(){var o,r;return E(this,(function(n){switch(n.label){case 0:return this.cloudControllerLock?(this.cloudControllerLock=!1,this.cloudControllerMsgs.shift()?(o=this.tcpMgr.getToken(),[4,null===(t=this.cloudController)||void 0===t?void 0:t.request(this.cloudControllerUri,e.InvokerType.other,o)]):[3,2]):[2];case 1:r=n.sent()||0,this.cloudControllerMsgs=this.cloudControllerMsgs.filter((function(e){return e.sentTime>r})),this.cloudControllerLock=!0,this._ccMsgHandler(),n.label=2;case 2:return[2]}}))}))},t.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}},t.prototype.handleRecalledMessage=function(t){var o=t.content,r=o.messageUId,n=o.sentTime;if(!r)return!0;var i=this._callCppProxy("getMessage",r),s=this._buildMessage(i,{isOffLineMessage:!1});if(t.content.isDelete)return-1===s.messageId||this._callCppProxy("deleteMessages",[s.messageId]),!0;if(s.messageType===e.MessageType.RECALL_NOTIFICATION_MESSAGE)return!1;var a={recallTime:Date.now(),admin:!!t.content.isAdmin,originalObjectName:s.messageType,originalMessageContent:s.content,recallActionTime:t.sentTime,operatorId:t.senderUserId};if(t.content.user&&(a.user=t.content.user),t.content.extra&&(a.extra=t.content.extra),s.messageType===e.MessageType.TextMessage&&(a.recallContent=s.content.content),-1===s.messageId){var c=t.conversationType,u=t.targetId,p=t.senderUserId,d=t.channelId,l=t.messageDirection;return this._callCppProxy("insertMessage",c,u,p,e.MessageType.RECALL_NOTIFICATION_MESSAGE,JSON.stringify(a),(function(){}),(function(){}),l,1,30,n,"",0,r,!1,!0,JSON.stringify({}),d||""),!0}return s.receivedStatus||this.setMessageReceivedStatus(s.messageId,1),this._callCppProxy("setMessageContent",s.messageId,JSON.stringify(a),e.MessageType.RECALL_NOTIFICATION_MESSAGE),!0},t.prototype._sendMessageExpansion=function(e){var t=e.channelId,o=void 0===t?"":t,r=e.content,n=e.conversationType,i=e.targetId,s=r,a=s.put,c=s.del,u=s.mid,p={};a&&(p.updatedExpansion={channelId:o,messageUId:u,expansion:a,conversationType:n,targetId:i}),c&&(p.deletedExpansion={channelId:o,messageUId:u,deletedKeys:c,conversationType:n,targetId:i}),this._dispatchEvent("expansion",p)},t.prototype._sendMessageNotification=function(e){this._dispatchEvent("batchMessage",e)},t.prototype._sendPullOfflineFinished=function(){this._dispatchEvent("pullFinished",null)},t.prototype._sendMessageDelivered=function(e){this._dispatchEvent("messageDelivered",e)},t.prototype._sendGroupMessageDeliveredStatus=function(e){this._dispatchEvent("groupMessageDeliveredStatus",e)},t.prototype._sendChatroomStatus=function(e){this._dispatchEvent("chatroom",e)},t.prototype._sendMessageReadReceipt=function(e){this._dispatchEvent("messageReadReceipt",e)},t.prototype._sendsyncReadStatus=function(e){this._dispatchEvent("syncReadStatus",e)},t.prototype._setConversationStatusListener=function(){var t=this;this._cppProtocol.setConversationStatusListener((function(o){var r=JSON.parse(o).list,n=[];r.forEach((function(t){var o=JSON.parse(t.obj),r=o.conversationType,i=o.targetId,s=o.status,a=o.channelId,c={notificationStatus:2,isTop:!1};s.forEach((function(t){var o=JSON.parse(t.item);1===o.type?c.notificationStatus=1===Number(o.value)?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE:c.isTop=1===Number(o.value)})),n.push({channelId:a,conversationType:r,targetId:i,updatedItems:{notificationStatus:{val:c.notificationStatus,time:0},isTop:{val:c.isTop,time:0}}})})),t._dispatchEvent("conversation",n)}),(function(e){t._dispatchEvent("conversationTag",e)}),(function(e,o,r,n){t._callCppProxy("clearUnreadCountByTimestamp",e,o,n,r||""),t._sendsyncReadStatus({conversationType:e,targetId:o,channelId:r,timestamp:n})}))},t.prototype._setPushNotificationListener=function(){var e=this;this._cppProtocol.setPushNotificationListener((function(){}),(function(t){e._dispatchEvent("tag",t),e._getRTCProfile()}))},t.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._dispatchEvent("onNaviDataChange",o)}},t.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){e._dispatchEvent("onRTCDataChange",Array.prototype.slice.call(t))}))},t.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._sendChatroomStatus({chatroomDestroyed:t})}))},t.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._dispatchEvent("callInfo",t)}))},t.prototype._setSubscribeEventListener=function(){var t=this;this._cppProtocol.setSubscribeEventListener((function(){}),(function(){t._dispatchEvent("syncSubscribedUserStatusFinished",e.SubscribeType.ONLINE_STATUS)}),(function(e){var o=t._buildSubscribeEventData(e).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.expiry,operationType:e.operationType}}));t._dispatchEvent("subscribedRelationChange",o)}),(function(o){var r=t._buildSubscribeEventData(o).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,i=t.expiry,s=t.details,a=t.userProfile,c={userId:o,subscribeType:r,subscribeTime:n,expiry:i};return r===e.SubscribeType.ONLINE_STATUS?c.details=s:r===e.SubscribeType.USER_PROFILE&&(c.userProfile=a),c}));t._dispatchEvent("subscribedUserStatusChange",r)}))},t.prototype._setUserProfileListener=function(){var t=this;this._cppProtocol.setUserProfileListener((function(){t._dispatchEvent("syncSubscribedUserStatusFinished",e.SubscribeType.USER_PROFILE)}),(function(e){t._dispatchEvent("ownUserProfileChanged",t._string2userProfileInfo(e))}))},t.prototype.registerMessageType=function(e,t,o,r,n){var i=0;t&&(i|=1),o&&(i|=2),n&&(i=16),this._customMessageType[e]={isCounted:o,isPersited:t,isStatusMessage:n},this.logger.info(y.P_REGTYP_O,JSON.stringify({type:e,opt:i,search:r})),this._callCppProxy("registerMessageType",e,i,r||[])},t.prototype.connect=function(e,t,o,r){return this.tcpMgr.connect(e,t,o,r)},t.prototype.reportSDKInfo=function(e){var t=JSON.stringify(_(_({},e),{"electron-main":"5.10.2"}));this.logger.info(y.P_REPORT_VER_O,t),this._callCppProxy("uploadSDKVersion",t,"")},t.prototype.disconnect=function(e){e=e||!0,this._chatroomCache.length=0,this.reporter.stop(),X(null,this.logger),this.tcpMgr.disconnect(e)},t.prototype.logout=function(){this.disconnect()},t.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)},t.prototype.subscribeUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("subscribeUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.setUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("setUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getUserStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:{status:t}})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype._handleDirectionalUserIdList=function(t){var o=t.messageType,r=t.content,n=t.directionalUserIdList,i=void 0===n?[]:n;if(o===e.MessageType.READ_RECEIPT_RESPONSE&&r.receiptMessageDic)for(var s in r.receiptMessageDic)i.push(s);return o===e.MessageType.SYNC_READ_STATUS&&(i=[this.getCurrentUserId()]),i},t.prototype._handleMessage2Callback=function(t,o){var r=this;if("RC:MsgExMsg"===t.messageType&&this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),t.messageType===e.MessageType.READ_RECEIPT_REQUEST)this._updateReadReceiptInfo(o.content.messageUId,{isReceiptRequestMessage:!0,readerList:[]});else if(t.messageType===e.MessageType.READ_RECEIPT_RESPONSE){var n=o.content.receiptMessageDic;if(!n)return;for(var i in n)n[i].forEach((function(e){r._updateReadReceiptInfo(e,{isReceiptRequestMessage:!0,hasRespond:!0})}))}},t.prototype.sendMessage=function(t,o,r,n,i){var s=this;void 0===i&&(i=this.logger.createTraceId());var a=r.messageType,c=r.content,u=r.expansion,p=r.pushConfig,d=r.pushContent,l=void 0===d?"":d,f=r.pushData,h=void 0===f?"":f,C=r.directionalUserIdList,g=void 0===C?[]:C,v=r.disableNotification,S=void 0!==v&&v,_=r.canIncludeExpansion,m=void 0!==_&&_,E=r.isVoipPush,T=void 0!==E&&E,P=r.channelId,R=void 0===P?"":P,I=r.messageId,O=void 0===I?0:I,N=p||{},M=N.iOSConfig,b=N.androidConfig,U=N.templateId,x=void 0===U?"":U,L=N.pushTitle,w=void 0===L?"":L,A=N.pushContent,D=void 0===A?l:A,k=N.pushData,J=void 0===k?h:k,B=N.disablePushTitle,F=void 0!==B&&B,j=N.forceShowDetailContent,V=void 0!==j&&j,q=e.pushConfigsToJSON(M,b);return new Promise((function(p){l=D,h=J;var d=(null==b?void 0:b.notificationId)||"";t===e.ConversationType.GROUP&&(g=s._handleDirectionalUserIdList(r));var f={};for(var C in u)f[C]={v:""},f[C].v=u[C];var v=x;s.logger.info(y.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:t,targetId:o,channelId:R}),i);var _=s._callCppProxy("sendMessage",(function(t,o){var n=s._buildMessage(t,{isOffLineMessage:!1});if(s.logger.info(y.P_SEND_MSG_R,JSON.stringify({code:o,messageUId:n.messageUId}),i),o===e.ErrorCode.SENSITIVE_REPLACE)return setTimeout((function(){p({code:o})}),0);[e.MessageType.READ_RECEIPT_REQUEST,e.MessageType.READ_RECEIPT_RESPONSE,e.MessageType.EXPANSION_NOTIFY].findIndex((function(e){return e===n.messageType}))>-1&&s._handleMessage2Callback(n,r),n.canIncludeExpansion&&s._msgExpansionHandler.setLocalFromReceiveMsg(s.logger,n),setTimeout((function(){p({code:e.ErrorCode.SUCCESS,data:n})}),0)}),(function(e,t){var o=s._buildMessage(e,{isOffLineMessage:!1});s.logger.warn(y.P_SEND_MSG_R,JSON.stringify({code:t,messageId:o.messageId}),i),o.sentTime=Date.now()-s._cppProtocol.getDeltaTime(),setTimeout((function(){p({code:t,data:o})}),0)}),t,o,a,JSON.stringify(c),g,S,F,V,l,h,d,w,q,v,m,JSON.stringify(f),T,R,O),E=JSON.parse(_);null==n||n(E.messageId)}))},t.prototype.recallMsg=function(t,o,r,n,i){var s=this;return new Promise((function(a){var c,u=i.user,p=i.pushContent,d=i.channelId,l=i.extra,f=i.pushConfig,h=i.disableNotification,C=i.isDelete,g=i.directionalUserIdList,v={conversationType:t,targetId:o,messageUId:r,sentTime:n,user:u,extra:l,channelId:d,isDelete:C||!1};u&&(v.user=u),l&&(v.extra=l);var S={conversationType:t,targetId:o,senderUserId:s.tcpMgr.getCurrentUserId(),content:v,objectName:e.MessageType.RECALL,messageUid:r,direction:e.MessageDirection.SEND,status:e.ReceivedStatus.UNREAD,sentTime:n,channelId:d},y=s._buildMessage(JSON.stringify(S),{isOffLineMessage:!1});s._callCppProxy("recallMessage",(function(){s.handleRecalledMessage(y),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:y})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}),e.MessageType.RECALL,JSON.stringify(v),h||!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)||"",e.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",d,g||[])}))},t.prototype.getHistoryMessage=function(t,o,r,n,i,s,a){var c=this;return new Promise((function(u){r=r||0;var p=0===i,d=n+1,l=c._callCppProxy("getHistoryMessages",t,o,r,d,a,p,s),f=JSON.parse(l).list,h=[];f.reverse();for(var C=0;C<f.length;C++){var g=c._buildMessage(f[C].obj);h[C]=g}u({code:e.ErrorCode.SUCCESS,data:{list:d===h.length?h.slice(1,d):h,hasMore:n<h.length}})}))},t.prototype.getMessages=function(t,o,r,n,i,s){var a=this;return new Promise((function(c){var u=0===i,p=r,d=0!==r,l=n+1;d&&(p+=u?1:-1,l++);for(var f=a._callCppProxy("getMessages",t,o,p,l,u,s),h=JSON.parse(f).list,C=[],g=0;g<h.length;g++){var v=a._buildMessage(h[g].obj);C[g]=v}var S=a._computeRepairInfo(C,u,r,p,l),y=S.isNeedRepair,_=void 0!==y&&y,m=S.repairTime,E=void 0===m?0:m;if(!_)return d&&(C.shift(),l--),C.reverse(),void c({code:e.ErrorCode.SUCCESS,data:{list:l===C.length?C.slice(1,l):C,hasMore:n<C.length}});a._processRepairHisMsg(t,o,r,n,i,s,E,c)}))},t.prototype._computeRepairInfo=function(e,t,o,r,n){var i=!1,s=0,a=this.getNaviInfoFromCache()||{},c=a.repairHisMsg,u=void 0===c?0:c,p=a.historyMsg;if(1!==u||!p)return{isNeedRepair:i,repairTime:s};var d=e.findIndex((function(e){return e.hasMore||0===Object.keys(e.content).length}));return t&&d>=0?(i=!0,s=e[d].hasMore?e[d].sentTime:e[d].sentTime+1):!t&&d>=1?(i=!0,s=e[d-1].sentTime):e.length<n||0===o?(i=!0,s=o):e.length>0&&e[0].sentTime!==o&&(i=!0,s=r),{isNeedRepair:i,repairTime:s}},t.prototype._processRepairHisMsg=function(e,t,o,r,n,i,s,a){var c=this,u=function(s){for(var u=0===n,p=r+1,d=c._callCppProxy("getMessages",e,t,o,p,u,i),l=JSON.parse(d).list,f=[],h=0;h<l.length;h++){var C=c._buildMessage(l[h].obj);f[h]=C}f.reverse(),a({code:s,data:{list:p<=f.length?f.slice(1,p):f,hasMore:r<f.length}})},p=r+10>100?100:r+10;this._callCppProxy("getRemoteHistoryMessages",e,t,s,p,(function(){return u(0)}),(function(e){u(e)}),n,!0,i,!1)},t.prototype.getContinuousMessages=function(t,o,r,n,i,s){var a=this;return new Promise((function(c){r=r||0;var u=0===i;a._callCppProxy("getContinuousMessages",t,o,r,n,(function(t,o,r){var n=JSON.parse(t).list,i=[];n.reverse();for(var s=0;s<n.length;s++){var u=a._buildMessage(n[s].obj);i[s]=u}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:i,timestamp:o,hasMore:r}})}))}),(function(e){setTimeout((function(){c({code:e})}),0)}),u,s)}))},t.prototype.getRemoteHistoryMessages=function(t,o,r,n,i,s){var a=this;return new Promise((function(c){r=r||0;a._callCppProxy("getRemoteHistoryMessages",t,o,r,n,(function(t,o){var r=JSON.parse(t).list,n=[];r.reverse();for(var i=0;i<r.length;i++){var s=a._buildMessage(r[i].obj);n[i]=s}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:n,hasMore:!!o}})}),0)}),(function(e){setTimeout((function(){c({code:e})}),0)}),i,!0,s,!0)}))},t.prototype.deleteRemoteMessage=function(t,o,r,n){var i=this;return new Promise((function(s){var a=JSON.stringify(r);i._callCppProxy("deleteRemoteHistoryMessages",t,o,a,!1,n,(function(){setTimeout((function(){s(e.ErrorCode.SUCCESS)}),0)}),s)}))},t.prototype.deleteRemoteMessageByTimestamp=function(t,o,r,n){var i=this;return new Promise((function(s){i._callCppProxy("clearRemoteHistoryMessages",t,o,r,(function(){setTimeout((function(){s(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){s(e)}),0)}),n)}))},t.prototype.clearMessages=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("clearMessages",t,o,r),i(e.ErrorCode.SUCCESS)}))},t.prototype.getConversationList=function(t,o,r,n,i){var s=this;return void 0===i&&(i=""),new Promise((function(t){for(var o=s._callCppProxy("getConversationList",[1,3,6,7],i),r=JSON.parse(o).list,n=[],a=0;a<r.length;a++)n.push(s._buildConversation(r[a].obj));t({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.getConversation=function(t,o,r){var n=this;return new Promise((function(i){var s=n._callCppProxy("getConversation",t,o,r);if(s)i({code:e.ErrorCode.SUCCESS,data:n._buildConversation(s)});else{var a=n._callCppProxy("getHistoryMessages",t,o,0,1,"",!0,r),c=void 0;try{c=JSON.parse(a).list}catch(e){n.logger.error(y.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=n._buildMessage(c[0].obj));var p=n._callCppProxy("getConversationNotificationStatus",t,o,r),d=n._callCppProxy("getConversationTopStatus",t,o,r);i({code:e.ErrorCode.SUCCESS,data:{conversationType:t,targetId:o,channelId:r,unreadMessageCount:0,latestMessage:u,notificationStatus:p?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},t.prototype.removeConversation=function(t,o,r){var n=this._callCppProxy("removeConversation",t,o,r);return Promise.resolve(n?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.batchRemoveConversation=function(t){var o=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId}})),r=this._callCppProxy("removeConversationInBatches",JSON.stringify(o));return Promise.resolve(r?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.clearConversations=function(t,o){var r=this;return new Promise((function(n){var i=[];i=e.isArray(t)?t:[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.PUBLIC_SERVICE],r._callCppProxy("clearConversations",i,o||""),n(e.ErrorCode.SUCCESS)}))},t.prototype.getAllConversationUnreadCount=function(t,o,r){var n=this._callCppProxy("getTotalUnreadCount",o,r,t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(i){var s=n._callCppProxy("getUnreadCount",t,o,r);i({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.clearConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(i){n._callCppProxy("clearUnreadCount",t,o,r),i(e.ErrorCode.SUCCESS)}))},t.prototype.clearUnreadCountByTimestamp=function(t,o,r,n){var i=this;return new Promise((function(s){i._callCppProxy("clearUnreadCountByTimestamp",t,o,r,n),s(e.ErrorCode.SUCCESS)}))},t.prototype.getFirstUnreadMessage=function(t,o,r){var n=this;return new Promise((function(i){var s=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),a=n._buildMessage(s);i({code:e.ErrorCode.SUCCESS,data:-1!==a.messageId?a:null})}))},t.prototype.getFirstUnreadMessageInfo=function(t,o,r){var n=this;return new Promise((function(i,s){var a=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),c=n._buildMessage(a);i({code:e.ErrorCode.SUCCESS,data:-1!==c.messageId?{messageUId:c.messageUId,sentTime:c.sentTime}:null})}))},t.prototype.batchSetConversationToTop=function(t,o,r){var n=this;return new Promise((function(i,s){var a=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,is_top:o}}));n._callCppProxy("setIsTopInBatches",JSON.stringify(a),r||!1),i(e.ErrorCode.SUCCESS)}))},t.prototype.setConversationStatus=function(t,o,r,n,i,s){var a=this;return new Promise((function(s){a._callCppProxy("setConversationStatus",t,o,r,n,(function(){setTimeout((function(){s(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){s(e)}),0)}),i,!0)}))},t.prototype.getConversationNotificationStatus=function(t,o,r){var n=this;return new Promise((function(i){var s=n._callCppProxy("getConversationNotificationStatus",t,o,r);i({code:e.ErrorCode.SUCCESS,data:s?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE})}))},t.prototype.setConversationTypeNotificationLevel=function(t,o){var r=this;return new Promise((function(n,i){r._callCppProxy("setBlockPushLevelForType",t,o,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getConversationTypeNotificationLevel=function(t){var o=this;return new Promise((function(r,n){var i=o._callCppProxy("getBlockPushLevelForType",t);r({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.searchConversationByContent=function(t,o,r,n){var i=this;return new Promise((function(s){n=n||[1,3,6,7];for(var a=i._callCppProxy("searchConversationByContent",n,t,o,r),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=i._buildConversation(c[p].obj);s({code:e.ErrorCode.SUCCESS,data:u})}))},t.prototype.searchConversationByContentWithAllChannel=function(t,o,r){var n=this;return new Promise((function(i){r=r||[1,3,6,7];for(var s=n._callCppProxy("searchConversationByContentWithAllChannel",r,t,o),a=JSON.parse(s).list,c=[],u=0;u<a.length;u++)c[u]=n._buildConversation(a[u].obj);i({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.searchMessageByContent=function(t,o,r,n,i,s,a){var c=this;return new Promise((function(s){c._callCppProxy("searchMessageByContent",t,o,r,n,i,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],i=0;i<r.length;i++)n[i]=c._buildMessage(r[i].obj);setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}),a)}))},t.prototype.searchMessageByContentAndMessageType=function(t,o,r,n,i,s,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByContentAndObjectName",o,t,a||"",void 0===a,r,s,i,n,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],i=0;i<r.length;i++)n[i]=c._buildMessage(r[i].obj);setTimeout((function(){u({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}))}))},t.prototype.searchMessagesByUser=function(t,o,r,n,i,s){var a=this;return new Promise((function(c){a._callCppProxy("getMessageBySender",t,o,r,n,i,s,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=a._buildMessage(o[n].obj);setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.searchMessageByContentWithAllChannel=function(t,o,r,n,i){var s=this;return new Promise((function(a){s._callCppProxy("searchMessageByContentWithAllChannel",t,o,r,n,i,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],i=0;i<r.length;i++)n[i]=s._buildMessage(r[i].obj);setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}))}))},t.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(t,o,r,n,i,s,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByTimestampWithAllChannel",t,o,r,n,i,s,a,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=c._buildMessage(o[n].obj);setTimeout((function(){u({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.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},t.prototype.addToBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addToBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.removeFromBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("removeFromBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getBlacklist=function(){var t=this;return new Promise((function(o){t._callCppProxy("getBlacklist",(function(t){setTimeout((function(){o({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){o({code:e})}),0)}))}))},t.prototype.getBlacklistStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getBlacklistStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.insertMessage=function(t,o,r){var n=this,i=r.content,s=r.senderUserId,a=r.messageType,c=r.messageDirection,u=r.readStatus,p=r.sentStatus,d=r.sentTime,l=r.searchContent,f=r.isUnread,h=r.messageUId,C=r.disableNotification,g=r.canIncludeExpansion,v=r.expansionMsg,S=r.channelId,y=r.directedUserIds;i=JSON.stringify(i);var _={};if(d=d||0,v){var m=JSON.parse(v);for(var E in m)_[E]={v:"",ts:0},_[E].v=m[E],_[E].ts=d}return new Promise((function(r){var v=f?0:1,m=n._callCppProxy("insertMessage",t,o,s,a,i,(function(){}),(function(e){setTimeout((function(){r({code:e})}),0)}),c,u||0,p||10,d,l||"",v,h||"",!!C,!!g,JSON.stringify(_),S||"",y||[]),E=n._buildMessage(m,{isOffLineMessage:!1});E.messageUId=h,E.sentTime=d,r({code:-1===E.messageId?e.ErrorCode.MSG_INSERT_ERROR:e.ErrorCode.SUCCESS,data:E})}))},t.prototype.batchInsertMessage=function(t,o){var r=this;return void 0===o&&(o=!1),new Promise((function(n){var i=t.map((function(t){var o=t.content,r=t.senderUserId,n=t.messageType,i=t.messageDirection,s=t.receivedStatus,a=void 0===s?0:s,c=t.sentStatus,u=t.sentTime,p=t.searchContent,d=t.isUnread,l=t.messageUId,f=t.disableNotification,h=t.canIncludeExpansion,C=t.expansion,g=t.channelId,v=t.conversationType,S=t.targetId,y=t.source,_=t.isMentioned,m=t.receivedStatusInfo,E=t.directedUserIds,T=a;m&&(T=e.transformReceivedStatusFlag(m));var P={};if(u=u||0,C)for(var R in C)P[R]={v:"",ts:0},P[R].v=C[R],P[R].ts=u;return{conversationType:v,targetId:S,channelId:g||"",direction:i,senderUserId:r,status:c||10,sentTime:u,objectName:n,content:JSON.stringify(o),messageUid:l||"",noNotification:!!f,supportExt:!!h,extMsg:JSON.stringify(P),readStatus:T,searchContent:p||"",isUnread:!!d,source:y||"",isMention:_,directedUsers:E}})),s=r._callCppProxy("insertMessages",JSON.stringify(i),o);n({code:s?e.ErrorCode.SUCCESS:e.ErrorCode.MSG_INSERT_ERROR,data:s||!1})}))},t.prototype.getMessageCount=function(t,o,r){var n=this;return new Promise((function(i){var s=n._callCppProxy("getMessageCount",t,o,r);i({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.deleteMessages=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteMessages",t),r(e.ErrorCode.SUCCESS)}))},t.prototype.deleteMessagesByTimestamp=function(t,o,r,n,i){var s=this;return new Promise((function(a){s._callCppProxy("deleteMessagesByTimestamp",t,o,r,n,i),a(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearMessagesByTimestamp=function(t){var o=this;return new Promise((function(r,n){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));o._callCppProxy("deleteMessageBySendTimeInBatches",JSON.stringify(i)),r(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearRemoteHistoryMessages=function(t,o){var r=this;return new Promise((function(n,i){var s=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));r._callCppProxy("deleteRemoteMessageBySendTimeInBatches",JSON.stringify(s),o||!1,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getMessage",t),i=o._buildMessage(n,{isOffLineMessage:!1});r({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.setMessageContent=function(t,o,r){var n=this;return new Promise((function(i){o=JSON.stringify(o),n._callCppProxy("setMessageContent",t,o,r),i(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSearchField=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("setMessageSearchField",t,o,r),i(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSentStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageSentStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageReceivedStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageReceivedStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.saveConversationMessageDraft=function(t,o,r,n){var i=this;return new Promise((function(s){i._callCppProxy("saveTextMessageDraft",t,o,r,n||"")&&s(e.ErrorCode.SUCCESS),s(e.ErrorCode.DRAFT_SAVE_ERROR)}))},t.prototype.getConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(i){var s=n._callCppProxy("getTextMessageDraft",t,o,r||"");i({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.clearConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("clearTextMessageDraft",t,o,r||"")&&i(e.ErrorCode.SUCCESS),i(e.ErrorCode.DRAFT_REMOVE_ERROR)}))},t.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},t.prototype.batchSetConversationStatus=function(t){var o=t[0],r=o.conversationType,n=o.targetId,i=o.isTop,s=o.notificationStatus,a=o.channelId,c=o.isUpdateTime,u=void 0===c||c,p=this._callCppProxy("getConversationNotificationStatus",r,n,a||""),d=this._callCppProxy("getConversationTopStatus",r,n,a||""),l=e.isUndefined(s)?Boolean(p):s===e.NotificationStatus.OPEN,f=e.isUndefined(i)?Boolean(d):i;return this.setConversationStatus(r,n,l,f,a,u)},t.prototype.getConversationNotificationLevel=function(t,o,r){return m(this,void 0,void 0,(function(){var n;return E(this,(function(i){return n=this._callCppProxy("getBlockPushLevelForConversation",o,r,t),[2,Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})]}))}))},t.prototype.setConversationNotificationLevel=function(t,o,r,n){var i=this;return void 0===n&&(n=""),new Promise((function(s){i._callCppProxy("setBlockPushLevelForConversation",o,n,t,r,(function(){setTimeout((function(){s(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){s(e)}),0)}))}))},t.prototype.batchSetConversationNotificationLevel=function(t,o){var r=this;return new Promise((function(n,i){var s=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,level:o}}));r._callCppProxy("setBlockPushLevelInBatches",JSON.stringify(s),(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getTotalUnreadCountByLevels=function(t,o,r){if(r){var n=this._callCppProxy("getUnreadMentionedCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})}var i=this._callCppProxy("getUnreadCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:i})},t.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},t.prototype.sendReadReceiptMessage=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("sendReadReceipt",t,r||"",o,(function(){o.forEach((function(e){n._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(n._callCppProxy("getMessage",e)).messageId;n.setMessageReceivedStatus(t,1)}catch(t){n.logger.error(y.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),setTimeout((function(){i({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.getMessageReader=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("getMessageReader",t,r,o,(function(t,r){var s=[],a={};(t=JSON.parse(t)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;s.push({userId:o,readTime:r}),a[o]=r}));var c={readerInfo:a,readCount:s.length,totalCount:r};n._updateReadReceiptInfo(o,c),setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{list:s,totalMemberCount:r}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.sendReadReceiptMessageV4=function(t,o,r){var n=this;return new Promise((function(i){var s=t.conversationType,a=t.targetId,c=t.channelId;n._callCppProxy("sendMessageReadReceipt",s,a,c||"",o,r,(function(){setTimeout((function(){i({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.getMessageReadReceiptV4=function(t,o){var r=this;return new Promise((function(n){var i=t.targetId,s=t.channelId;r._callCppProxy("getMessageReadReceipt",i,s||"",o,(function(t,i,s){var a=[],c=r._callCppProxy("getMessage",o),u=JSON.parse(c);try{JSON.parse(s).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;a.push({userId:o,readTime:r})}))}catch(e){r.logger.error(y.P_PARSE_JSON_E,"method: getMessageReadReceipt, info: "+s+", error: "+e)}var p=JSON.parse(u.readReceiptRequest||"{}"),d=p.readerList,l=void 0===d?[]:d,f=p.readCount,h=void 0===f?0:f,C=!1;l.length<a.length&&(l=a,C=!0),h<i&&(h=i,C=!0),C&&r._callCppProxy("updateReadReceiptRequestInfo",o,JSON.stringify({readerList:l,readCount:h,totalCount:t})),setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:{list:a,totalCount:t,readCount:h}})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.updateConversationReadTime=function(t,o){var r=this;return new Promise((function(n){var i=t.conversationType,s=t.targetId,a=t.channelId;r._callCppProxy("updateConversationReadTime",i,s,a||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype._addChatroomCache=function(e,t,o){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:o,count:t})},t.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},t.prototype._try2RejoinChatroom=function(){var t=this;if(0!==this._chatroomCache.length){var o=this.logger.createTraceId();this._chatroomCache.forEach((function(r){return m(t,void 0,void 0,(function(){var t,n,i,s,a,c;return E(this,(function(u){switch(u.label){case 0:return t=r.chatroomId,n=r.joinExist,i=r.count,this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_T,t,o),[4,this._joinChrm(t,i,n,!1)];case 1:return s=u.sent(),a=s.code,c=s.data,a===e.ErrorCode.SUCCESS?(this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_R,t,o),this._sendChatroomStatus({rejoinedRoom:_({chatroomId:t,count:i},c)}),[2]):(a===e.ErrorCode.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:t,errorCode:a}}),this.logger.warn(e.LogTagId.L_REJOIN_CHATROOM_R,"chrmId: "+t+", code: "+a,o),[2])}}))}))}))}},t.prototype._joinChrm=function(t,o,r,n){var i=this,s=r?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){n&&i._callCppProxy("clearMessages",e.ConversationType.CHATROOM,t,""),i._callCppProxy(s,t,o,(function(n,s,c,u,p,d){i._addChatroomCache(t,o,r),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{createTime:Number(n),memberCount:s,isAllChatroomBanned:c,isCurrentUserBanned:u,isCurrentChatroomBanned:p,isCurrentChatroomInWhitelist:d}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.joinChatroom=function(e,t){return m(this,void 0,void 0,(function(){return E(this,(function(o){switch(o.label){case 0:return[4,this._joinChrm(e,t,!1,!0)];case 1:return[2,o.sent().code]}}))}))},t.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},t.prototype.quitChatroom=function(t){var o=this;return this._rmChatroomCache(t),new Promise((function(r){o._callCppProxy("quitChatRoom",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getChatroomInfo=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("getChatroomInfo",t,o,r,(function(t,o){var r=t?JSON.parse(t).list:[],n=[];if(r.length>0)for(var s=0;s<r.length;s++)n.push(JSON.parse(r[s].obj));setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{userInfos:n,userCount:o}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.getChatroomHistoryMessages=function(t,o,r,n){var i=this;return new Promise((function(s){i._callCppProxy("getChatroomHistoryMessage",t,o,r,n,(function(t){var o;try{o=JSON.parse(t)}catch(e){o={list:[],hasMore:!1}}var r=o.list;if(r&&r.length)try{o.list=r.map((function(e){return i._buildMessage(e.obj)}))}catch(e){o.list=[]}setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}),"")}))},t.prototype.setChatroomEntry=function(t,o){var r=this;return new Promise((function(n){var i='[{"key":"'+o.key+'", "value":"'+o.value+'"}]';r._callCppProxy("setChatroomKV",t,i,!!o.isAutoDelete,!!o.isOverwrite,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.setChatroomEntries=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setChatroomKV",t,JSON.stringify(o.entries),!!o.isAutoDelete,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},t.prototype.removeChatroomEntry=function(t,o){var r=this,n=[o.key];return new Promise((function(i){r._callCppProxy("deleteChatroomKV",t,n,!!o.isOverwrite,(function(){i(e.ErrorCode.SUCCESS)}),(function(e){i(e)}))}))},t.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},t.prototype.removeChatroomEntries=function(t,o){var r=this;return new Promise((function(n){var i=o.entries.map((function(e){return e.key}));r._callCppProxy("deleteChatroomKV",t,i,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getChatroomEntry=function(t,o){return m(this,void 0,void 0,(function(){var r;return E(this,(function(n){switch(n.label){case 0:return[4,this.getAllChatroomEntry(t)];case 1:return(r=n.sent()).code===e.ErrorCode.SUCCESS?[2,{code:e.ErrorCode.SUCCESS,data:r.data?r.data[o]:null}]:[2,{code:r.code}]}}))}))},t.prototype.getAllChatroomEntry=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getChatroomKV",t,(function(t){var o={};try{(t?JSON.parse(t):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){o[e.key]=e.value?e.value:""}))}catch(e){}setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getFileToken=function(t,o,r,n,i){var s=this;return r=r||"",n=n||"",i=i||"",new Promise((function(a){var c;c=n&&"uploads"!==n?o||"":e.getUploadFileName(t,o);var u=s.getNaviInfoFromCache(),p={uploadDomain:e.getMinionURL(u,s.logger),env:s._environment};s._callCppProxy("getUploadToken",t,c,r,n,i,JSON.stringify(p),(function(t,o,r,n,i,s,u,p,d,l,f,h,C,g,v,S,y,_,m,E,T,P,R){setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{token:t,deadline:0,bosToken:o,bosDate:r,path:n,osskeyId:i,ossPolicy:s,ossSign:u,ossBucketName:p,fileName:c,s3Credential:d,s3Algorithm:l,s3Date:f,s3Policy:h,s3Signature:C,s3BucketName:g,stcAuthorization:v,stcContentSha256:S,stcDate:y,stcBucketName:_,minioAuthorization:m,minioContentSha256:E,minioDate:T,minioBucketName:P,downloadAuthInfo:R?JSON.parse(R):null}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.getFileUrl=function(t,o,r,n){var i=this;return new Promise((function(s){var a=i.getNaviInfoFromCache(),c={url:e.getMinionURL(a,i.logger)};i._callCppProxy("getDownloadUrl",t,r,n,o-1,JSON.stringify(c),(function(t){setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{downloadUrl:t}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.clearData=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("clearData");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getDeviceId=function(){var e=this._dbpath;return pe(e)},t.prototype.getVoIPKey=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("getVoIPKey",t,o,"",(function(t){setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.bindRTCRoomForChatroom=function(t){var o=this;return new Promise((function(r){var n=t.chatRoomId,i=t.rtcRoomId;o._callCppProxy("bindRTCRoomForChatroom",n,i,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getGroupMessageDeliverList=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("getGroupMessageDeliverList",t,r,o,(function(t,o){var r=JSON.parse(t).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{totalCount:o,list:r}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.getPrivateMessageDeliverTime=function(t,o){var r=this;return new Promise((function(n){var i=r._callCppProxy("getMessageDeliverTime",t);if(i)n({code:e.ErrorCode.SUCCESS,data:i});else{r._callCppProxy("getPrivateMessageDeliverList",o,t,(function(t){var o=0,r=JSON.parse(t).list;if(r.length>0){var i=JSON.parse(r[0].obj).time;o=i}setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}}))},t.prototype.rtcSignaling=function(t,o,r,n){var i=this;return new Promise((function(s){i._callCppProxy("rtcSignaling",t,o,r,n,(function(t){var o=Array.prototype.slice.call(t);s({code:e.ErrorCode.SUCCESS,buffer:o})}),(function(e){s({code:e})}),30)}))},t.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 i=e.rtcHeartbeatResolves[t];if(i){var s=i.findIndex((function(e){return e.seqId===r}));-1!==s&&i.splice(s,1)[0].resolve({code:o,data:{version:Number(n)}})}}))},t.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],30)}))},t.prototype.createTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.removeTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteTag",t,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.updateTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("renameTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getTagList=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getTags"),n=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));o({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.addTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));r._callCppProxy("addConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),r._callCppProxy("removeConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagsForConversation=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("removeTagsForConversation",t.conversationType,t.targetId,t.channelId||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.getConversationListByTag=function(t,o,r,n){var i=this;return new Promise((function(s){var a=i._callCppProxy("getConversationsForTagByPage",t,o,r||20,n||""),c=i._convertResultList(a,(function(e){return _(_({},i._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));s({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.getUnreadCountByTag=function(t,o){var r=this;return new Promise((function(n){var i=r._callCppProxy("getConversationUnreadCountForTag",t,o);n({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.setConversationStatusInTag=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("setConversationToTopForTag",t,o.conversationType,o.targetId,o.channelId||"",r.isTop||!1,(function(){setTimeout((function(){i({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.getTagsForConversation=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getTagsForConversation",t.conversationType,t.targetId,t.channelId||""),i=o._convertResultList(n,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));r({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getTopConversationList=function(t,o){var r=this;return new Promise((function(n){var i=e.isUndefined(o)?r._callCppProxy("getTopConversations",t):r._callCppProxy("getTopConversations",t,o),s=JSON.parse(i).list.map((function(e){return r._buildConversation(e.obj)}));n({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},t.prototype.getAllUnreadMentionedCount=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getUnreadAndMentionCount",[e.ConversationType.GROUP],"");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getOSInfo=function(){return m(this,void 0,void 0,(function(){var t;return E(this,(function(o){return t={arch:C.arch(),platform:C.platform(),type:C.type(),version:C.version(),release:C.release(),uptime:C.uptime(),cpus:C.cpus(),freemem:C.freemem(),totalmem:C.totalmem(),networkInterfaces:C.networkInterfaces()},[2,{code:e.ErrorCode.SUCCESS,data:t}]}))}))},t.prototype.getMainProcessInfo=function(){return m(this,void 0,void 0,(function(){return E(this,(function(t){return[2,{code:e.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()}}]}))}))},t.prototype.setCallInfo=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("callInfoSignaling",t,o,r,(function(t,o){setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{key:t,value:o}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.setProxy=function(t){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.DISCONNECTED?Promise.resolve({code:e.ErrorCode.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(X(t,this.logger))},t.prototype.getProxy=function(){return Promise.resolve(z())},t.prototype.testProxy=function(t,o){return function(t,o,r){return new Promise((function(n){var i=/^https/.test(o)?W:H;r.info(e.LogTagId.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:t,testHost:o}));var s=i(o,t,(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(){n({status:t||0,data:o})}))}));s.once("timeout",(function(){return n({status:0})})),s.once("error",(function(e){return n({status:0,data:e.stack})})),s.end()}))}(t,o,this.logger)},t.prototype.checkDuplicateMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("checkDuplicateMessage",t);r({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.subscribeUser=function(t,o,r){var n=this;return new Promise((function(i){n._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.SUBSCRIBE,t,(function(){i({code:e.ErrorCode.SUCCESS})}),(function(e,t){i({code:e,data:t})}),r)}))},t.prototype.unSubscribeUser=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.UNSUBSCRIBE,t,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}),0)}))},t.prototype.getSubscribeUserList=function(t,o,r){var n=this._callCppProxy("getSubscribeUserList",t,o,r),i=this._buildSubscribeEventData(n).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,i=t.expiry,s=t.details,a={userId:o,subscribeType:r,subscribeTime:n,expiry:i};return r===e.SubscribeType.ONLINE_STATUS&&(a.details=e.completeSubscriptionPlatformStatus(s)),a}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:i})},t.prototype.setDuplicateMessageConfig=function(t){var o=this._callCppProxy("setDuplicateMessageConfig",[e.ConversationType.CHATROOM],Se.cuid,t);return Promise.resolve({code:o})},t.prototype.getSubscribeUserStatus=function(t,o){var r=this._callCppProxy("getSubscribeStatusByUserIds",t,o),n=this._buildSubscribeEventData(r).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,i=t.expiry,s=t.details,a={userId:o,subscribeType:r,subscribeTime:n,expiry:i};return r===e.SubscribeType.ONLINE_STATUS&&(a.details=e.completeSubscriptionPlatformStatus(s)),a}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.updateMyUserProfile=function(e){var t=this;return new Promise((function(o){var r=[],n=[];Object.keys(e).forEach((function(t){var o;if("extraProfile"===t&&e.extraProfile){if(e.extraProfile){var i=e.extraProfile;Object.keys(i).forEach((function(e){n.push(JSON.stringify({key:e,value:i[e]||""}))}))}}else r.push(JSON.stringify({key:t,value:(null===(o=e[t])||void 0===o?void 0:o.toString())||""}))})),t._callCppProxy("updateUserProfile",r,n,(function(e,t){o({code:e,data:{errorKey:t}})}))}))},t.prototype.getUserProfiles=function(e){var t=this;return new Promise((function(o){t._callCppProxy("getUserProfiles",e,(function(e,r){o({code:e,data:t._string2UserProfileInfoList(r)})}))}))},t.prototype.getMyUserProfile=function(){var e=this;return new Promise((function(t){e._callCppProxy("getOwnUserProfile",(function(o,r){t({code:o,data:e._string2userProfileInfo(r)})}))}))},t.prototype._string2userProfileInfo=function(e){var t;try{var o=JSON.parse(e),r=o.userProfile.reduce((function(e,t){var o=JSON.parse(t);return["gender","role","level"].includes(o.key)?e[o.key]=Number(o.value):e[o.key]=o.value,e}),{});return r.userId=o.userId,r.extraProfile=(null===(t=o.userExtProfile)||void 0===t?void 0:t.reduce((function(e,t){var o=JSON.parse(t);return e[o.key]=o.value,e}),{}))||{},r}catch(t){this.logger.error(y.P_PARSE_JSON_USER_PROFILE_E,JSON.stringify({error:null==t?void 0:t.stack,str:e}))}return{}},t.prototype._string2UserProfileInfoList=function(e){var t=this;try{return JSON.parse(e).list.map((function(e){return t._string2userProfileInfo(e.obj)}))}catch(t){this.logger.error(y.P_PARSE_JSON_USER_PROFILE_E,JSON.stringify({error:null==t?void 0:t.stack,str:e}))}return[]},t.prototype.updateMyUserProfileVisibility=function(t){var o=this;return new Promise((function(r){o._callCppProxy("updateUserProfilePermission",t,(function(){r({code:e.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},t.prototype.getMyUserProfileVisibility=function(){var e=this;return new Promise((function(t){e._callCppProxy("getUserProfilePermission",(function(e,o){t({code:e,data:o})}))}))},t.prototype.searchUserProfileByUniqueId=function(e){var t=this;return new Promise((function(o){t._callCppProxy("getUserProfileByUniqueId",e,(function(e,r){o({code:e,data:t._string2userProfileInfo(r)})}))}))},t.prototype.getMatchedMessage=function(t,o,r,n){var i,s=this._callCppProxy("getMatchedMessage",t.conversationType,t.targetId,o,r,n,t.channelId||""),a=[];try{i=JSON.parse(s).list;for(var c=0;c<i.length;c++){var u=this._buildMessage(i[c].obj);a.push(u)}}catch(t){return this.logger.error(y.P_PARSE_JSON_MSGS_E,s),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:a})},t.prototype.getConversations=function(t){var o,r=this,n=t.map((function(e){var t=e.conversationType,o=e.targetId,r=e.channelId;return{targetId:o,channelId:void 0===r?"":r,type:t}})),i=this._callCppProxy("getConversations",JSON.stringify(n));try{o=JSON.parse(i).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return this.logger.error(y.P_PARSE_JSON_MSGS_E,i),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t}(),Te=function(e){return{sendError:function(t){e.send({type:$.ERROR,data:{msg:t}})},sendEvent:function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];e.send({type:$.EVENT,data:{eventName:t,data:o}})},sendResponse:function(t){e.send({type:$.RESPONSE,data:t})},sendCallback:function(t){e.send({type:$.CALLBACK,data:t})}}},Pe=r.resolve(__dirname,"binding","electron-"+t.platform()+"-"+t.arch()+".node"),Re={addon:null},Ie=Te(process).sendError;try{Re.addon=require(Pe)}catch(e){console.error("error ->",Pe,"\n",e),Ie(e.toString())}Re.addon||console.error("error -> cannot find module: ",Pe);var Oe=Re.addon;!function(t){var o=this,r=t.argv.slice(2),n=r[0],i=r[1],s=r[2],a=r[3],c="true"===s,u=Te(t),p=u.sendCallback,d=u.sendError,l=u.sendEvent,f=u.sendResponse,h=Oe?new Ee(n,Oe,i,l,c,~~a):null;t.on("message",(function(t){return m(o,void 0,void 0,(function(){var o,r,n,i,s,a;return E(this,(function(c){switch(c.label){case 0:return o=t.reqId,r=t.method,n=t.args,i=t.hasResponse,h?i?("sendMessage"===r&&(s=n[3],n[3]=function(e){p({reqId:s,data:e})}),[4,h.callProxy.apply(h,T([r],n,!1))]):[3,2]:[2,f({reqId:o,success:!0,data:{code:e.ErrorCode.ADDON_NOT_EXIST,msg:"Cannot find module "+Pe}})];case 1:return a=c.sent(),f({reqId:o,success:true,data:a}),[3,3];case 2:h.sendProxy.apply(h,T([r],n,!1)),c.label=3;case 3:return[2]}}))}))})),t.on("beforeExit",(function(e){null==h||h.destroy()})),t.on("uncaughtException",(function(e){d("uncaughtException "+(e.stack||e.toString()))})),t.on("unhandledRejection",(function(e){d("unhandledRejection "+e.stack)}))}(process);
package/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { EnableLogL } from '@rongcloud/engine';
2
2
 
3
3
  declare class RCMainProxy {
4
4
  private _rcMain;
5
- constructor(appkey: string, dbpath: string, logOutputLevel: EnableLogL, runInMainProcess: boolean);
5
+ constructor(appkey: string, dbpath: string, logOutputLevel: EnableLogL, runInMainProcess: boolean, enableSyncEmptyTopConversation: boolean);
6
6
  /**
7
7
  * @deprecated
8
8
  */
@@ -49,6 +49,10 @@ interface IInitOptions {
49
49
  * 是否在主进程中运行,默认值为 `false`
50
50
  */
51
51
  runInMainProcess?: boolean;
52
+ /**
53
+ * 是否同步空的置顶会话,默认值为 `false`
54
+ */
55
+ enableSyncEmptyTopConversation?: boolean;
52
56
  }
53
57
  declare const _default: (options: IInitOptions) => RCMainProxy;
54
58