@rongcloud/electron 5.5.5-beem → 5.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ConversationType, IChrmKVEntry, FileType, LogLevel } from '@rongcloud/engine';
1
+ import { ConversationType, IChrmKVEntry, FileType, IEngine, IExtraMethod, IAsyncRes, IReceivedConversation, IPromiseResult, IReceivedMessage, INaviInfo, ErrorCode, ISendMsgOptions, IRecallMsgOptions, MessageDirection, NotificationStatus, IInsertMsgOptions, IServerConversationStatus, ISetConversationStatusOptions, IServerUserSetting, IMessageReaderResponse, IChatroomInfo, IChrmKVEntries, IUploadAuth, UploadMethod, IRTCRoomBindOption, ITagParam, ITagInfo, IConversationOption, IReceivedConversationByTag, ITagStatus, IConversationTag, IBaseConversationInfo, IOSInfo, IProcessInfo, LogLevel } from '@rongcloud/engine';
2
2
 
3
3
  declare type IOnErrorCallBack = (code: number) => void;
4
4
  interface ICppProtocol {
@@ -7,7 +7,7 @@ interface ICppProtocol {
7
7
  * @param appkey App Key
8
8
  * @param dbPath 数据库路径,相对:相对于启动目录 绝对:绝对路径
9
9
  */
10
- initWithAppkey: (appkey: string, dbPath?: string, sdkVersion?: string) => string;
10
+ initWithAppkey: (appkey: string, dbPath?: string) => string;
11
11
  /**
12
12
  * 反初始化
13
13
  * @description
@@ -273,14 +273,6 @@ interface ICppProtocol {
273
273
  * 上报版本号
274
274
  */
275
275
  uploadSDKVersion: (version: string) => void;
276
- /**
277
- * 设置 callInfo
278
- */
279
- callInfoSignaling: (targetId: string, key: string, value: string, onSuccess: (key: string, value: string) => void, onError: IOnErrorCallBack) => void;
280
- /**
281
- * 设置监听
282
- */
283
- setCallInfoListener: (listener: Function) => void;
284
276
  /**
285
277
  * 添加标签
286
278
  */
@@ -326,22 +318,6 @@ interface ICppProtocol {
326
318
  * 获取指定标签下的会话消息未读数
327
319
  */
328
320
  getConversationUnreadCountForTag: (tagId: string, containBlocked: boolean) => number;
329
- /**
330
- * 获取群组消息送达列表
331
- */
332
- getGroupMessageDeliverList: (targetId: string, channelId: string, messageUId: string, onSuccess: (result: string, totalCount: number) => void, onError: IOnErrorCallBack) => string;
333
- /**
334
- * 获取单聊消息送达列表
335
- */
336
- getPrivateMessageDeliverList: (channelId: string, messageUId: string, onSuccess: (result: string) => void, onError: IOnErrorCallBack) => string;
337
- /**
338
- * 获取单聊本地消息送达时间
339
- */
340
- getMessageDeliverTime: (messsageUId: string) => number;
341
- /**
342
- * 设置消息送达时间
343
- */
344
- setMessageDeliverTime: (msgs: string) => string;
345
321
  /**
346
322
  * 加入黑名单
347
323
  */
@@ -458,22 +434,384 @@ interface ICppProtocol {
458
434
  destroy(): void;
459
435
  }
460
436
 
461
- declare class RCServiceProxy {
437
+ declare class RCCppService implements IEngine, IExtraMethod {
462
438
  private readonly _cppProtocol;
463
439
  private readonly _dbpath;
464
440
  private readonly _reconnectKickEnable;
465
- private _cppService;
441
+ private _currentToken;
442
+ private _connectionStatus;
443
+ private _promiseHandler;
444
+ private _customMessageType;
445
+ private _heartbeat?;
446
+ private _connectedTime;
447
+ private _currentUserId;
448
+ private _msgExpansionHandler;
449
+ private _inited;
450
+ private _initOptions;
451
+ private _naviInfo;
452
+ private _version;
466
453
  constructor(_cppProtocol: ICppProtocol, _dbpath?: string, _reconnectKickEnable?: boolean);
454
+ private _callCppProxy;
467
455
  /**
468
- * @deprecated
456
+ * 打印日志并发送给第一个 render
457
+ * @param method
458
+ * @param args
469
459
  */
470
- getCppProto(): {
471
- destroy: () => void;
472
- };
460
+ private _superElectronLog;
461
+ private _electronLogger;
462
+ private _logger;
463
+ private _superLog;
473
464
  /**
474
- * 退出应用前调用
465
+ * 获取协议栈引用
475
466
  */
476
- destroy(): void;
467
+ getCppProto(): ICppProtocol;
468
+ callExtra(method: keyof RCCppService, ...args: any[]): Promise<IAsyncRes<unknown>>;
469
+ getConversationsByPage(conversationTypes: ConversationType[], timestamp: number, count: number, channelId?: string): Promise<IAsyncRes<IReceivedConversation[]>>;
470
+ getConversationListWithAllChannel(): IPromiseResult<IReceivedConversation[]>;
471
+ getConversationListWithAllChannelByPage(index: number, limit: number): IPromiseResult<IReceivedConversation[]>;
472
+ getHistoryMessagesByObjectNames(conversationType: ConversationType, targetId: string, sentTime: number, count: number, objectNames: string[], desc: 0 | 1, tag: string): Promise<IAsyncRes<{
473
+ list: IReceivedMessage[];
474
+ hasMore: boolean;
475
+ }>>;
476
+ updateMessageReceiptStatus(conversationType: ConversationType, targetId: string, timestamp: number, channelId?: string): Promise<IAsyncRes<boolean>>;
477
+ requestNaviInfo(uris: string[], appkey: string, token: string, checkCA?: boolean): Promise<INaviInfo | null>;
478
+ updateNaviInfo(naviInfo: INaviInfo): void;
479
+ getNaviInfoFromCache(): INaviInfo | null;
480
+ getConnectedTime(): number;
481
+ getServerTime(): number;
482
+ getCurrentUserId(): string;
483
+ private _senders;
484
+ private _send2Renderer;
485
+ private _send2AllRenderer;
486
+ private _init;
487
+ /**
488
+ * 批量注册内置消息
489
+ */
490
+ private _registerMsgTypes;
491
+ /**
492
+ * 消息构建
493
+ */
494
+ private _buildMessage;
495
+ private _updateReadReceiptInfo;
496
+ /**
497
+ * 会话构建
498
+ */
499
+ private _buildConversation;
500
+ private _sendConnectionStatus2Renderer;
501
+ /**
502
+ * 返回列表数据的格式转换
503
+ */
504
+ private _convertResultList;
505
+ private _connectResolve;
506
+ /**
507
+ * 设置连接状态监听器
508
+ * ConnectionStatus_TokenIncorrect = 31004,
509
+ * ConnectionStatus_Connected = 0,
510
+ * ConnectionStatus_KickedOff = 6,// 其他设备登录
511
+ * ConnectionStatus_Connecting = 10,// 连接中
512
+ * ConnectionStatus_SignUp = 12, // 未登录
513
+ * ConnectionStatus_NetworkUnavailable = 1, // 连接断开
514
+ * ConnectionStatus_ServerInvalid = 8, // 断开
515
+ * ConnectionStatus_ValidateFailure = 9,//断开
516
+ * ConnectionStatus_Unconnected = 11,//断开
517
+ * ConnectionStatus_DisconnExecption = 31011 //断开
518
+ * RC_NAVI_MALLOC_ERROR = 30000,//断开
519
+ * RC_NAVI_NET_UNAVAILABLE= 30002,//断开
520
+ * RC_NAVI_SEND_FAIL = 30004,//断开
521
+ * RC_NAVI_REQ_TIMEOUT = 30005,//断开
522
+ * RC_NAVI_RECV_FAIL = 30006,//断开
523
+ * RC_NAVI_RESOURCE_ERROR = 30007,//断开
524
+ * RC_NAVI_NODE_NOT_FOUND = 30008,//断开
525
+ * RC_NAVI_DNS_ERROR = 30009,//断开
526
+ */
527
+ private _setConnectionStatusListener;
528
+ /**
529
+ * 心跳超时时重连
530
+ */
531
+ private _handleHeartTimeout;
532
+ /**
533
+ * 数据库初始化回调
534
+ */
535
+ private _dbOpenCallback;
536
+ /**
537
+ * 发送心跳
538
+ */
539
+ private _sendHeartbeat;
540
+ /**
541
+ * 设置消息监听器
542
+ */
543
+ private _setOnReceiveMessageListener;
544
+ private _sendMessageExpansion;
545
+ private _sendMessageNotification;
546
+ private _sendPullOfflineFinished;
547
+ /**
548
+ * 设置会话状态监听器
549
+ */
550
+ private _setConversationStatusListener;
551
+ private _setUserProfileListener;
552
+ private _getRTCProfile;
553
+ private _setRTCLivingRoomEventListener;
554
+ private _setChatroomEventListener;
555
+ /**
556
+ * 清空监听器
557
+ */
558
+ private _clearListener;
559
+ /**
560
+ * 注册自定义消息
561
+ */
562
+ registerMessageType(messageType: string, isPersited: boolean, isCounted: boolean, searchProps: string[]): void;
563
+ /**
564
+ * 连接
565
+ * @param reconnectKickEnable 设置断线重连时是否踢出当前正在重连的设备 (仅 Electron 环境有效) false: 踢其他端, true:踢自己
566
+ * 同一个账号在一台新设备上登录的时候,会把这个账号在之前登录的设备上踢出。
567
+ 由于 SDK 有断线重连功能,存在下面情况。
568
+ 用户在 A 设备登录,A 设备网络不稳定,没有连接成功,SDK 启动重连机制。
569
+ 用户此时又在 B 设备登录,B 设备连接成功。
570
+ A 设备网络稳定之后,用户在 A 设备连接成功,B 设备被踢出。
571
+ 这个字段就是为这种情况加的。
572
+ 设置 reconnectKickEnable 为 true 时,SDK 重连的时候发现此时已有别的设备连接成功,不再强行踢出已有设备,而是踢出重连设备。
573
+ */
574
+ connect(token: string, naviInfo: INaviInfo, reconnectKickEnable?: boolean, traceId?: string): Promise<ErrorCode>;
575
+ private _doConnect;
576
+ reportSDKInfo(version: {
577
+ [name: string]: string;
578
+ }): void;
579
+ /**
580
+ * 断开链接
581
+ */
582
+ disconnect(): void;
583
+ /**
584
+ * 注销登录
585
+ */
586
+ logout(): void;
587
+ /**
588
+ * 设置用户在线状态监听器
589
+ */
590
+ setUserStatusListener(config: {
591
+ userIds: string[];
592
+ }, listener: Function): void;
593
+ /**
594
+ * 订阅用户在线状态
595
+ */
596
+ subscribeUserStatus(userIds: string[]): Promise<ErrorCode>;
597
+ /**
598
+ * 设置当前用户在线状态
599
+ */
600
+ setUserStatus(status: number): Promise<ErrorCode>;
601
+ /**
602
+ * 获取用户状态
603
+ */
604
+ getUserStatus(userId: string): IPromiseResult<{
605
+ status: string;
606
+ }>;
607
+ /**
608
+ * 发送消息
609
+ */
610
+ sendMessage(conversationType: ConversationType, targetId: string, options: ISendMsgOptions, onBefore?: (messageId: number) => void, traceId?: string): IPromiseResult<IReceivedMessage>;
611
+ /**
612
+ * 撤回消息
613
+ */
614
+ recallMsg(conversationType: ConversationType, targetId: string, messageUId: string, sentTime: number, recallMsgOptions: IRecallMsgOptions): IPromiseResult<IReceivedMessage>;
615
+ getHistoryMessage(conversationType: ConversationType, targetId: string, timestamp: number, count: number, order: 0 | 1, channelId: string, objectName: string): IPromiseResult<{
616
+ list: IReceivedMessage[];
617
+ hasMore: boolean;
618
+ }>;
619
+ getRemoteHistoryMessages(conversationType: ConversationType, targetId: string, timestamp: number, count: number, order: 0 | 1, channelId: string): IPromiseResult<{
620
+ list: IReceivedMessage[];
621
+ hasMore: boolean;
622
+ }>;
623
+ deleteRemoteMessage(conversationType: ConversationType, targetId: string, messages: {
624
+ messageUId: string;
625
+ sentTime: number;
626
+ messageDirection: MessageDirection;
627
+ }[], channelId: string): Promise<ErrorCode>;
628
+ deleteRemoteMessageByTimestamp(conversationType: ConversationType, targetId: string, timestamp: number, channelId: string): Promise<ErrorCode>;
629
+ clearMessages(conversationType: ConversationType, targetId: string, channelId: string): Promise<ErrorCode>;
630
+ /**
631
+ * 获取全部会话列表
632
+ */
633
+ getConversationList(count: number, conversationType?: ConversationType, startTime?: number, order?: 0 | 1, channelId?: string): IPromiseResult<IReceivedConversation[]>;
634
+ /**
635
+ * 获取指定会话
636
+ */
637
+ getConversation(conversationType: ConversationType, targetId: string, channelId: string): IPromiseResult<IReceivedConversation | null>;
638
+ /**
639
+ * 删除指定会话
640
+ */
641
+ removeConversation(conversationType: ConversationType, targetId: string, channelId: string): Promise<ErrorCode>;
642
+ /**
643
+ * 删除所有会话
644
+ */
645
+ clearConversations(conversationTypes?: ConversationType[], channelId?: string): Promise<ErrorCode>;
646
+ /**
647
+ * 获取所有会话未读数
648
+ */
649
+ getAllConversationUnreadCount(channelId: string, conversationTypes: ConversationType[], includeMuted: boolean): IPromiseResult<number>;
650
+ /**
651
+ * 获取指定会话未读数
652
+ */
653
+ getConversationUnreadCount(conversationType: ConversationType, targetId: string, channelId?: string): IPromiseResult<number>;
654
+ /**
655
+ * 清除指定会话未读数
656
+ */
657
+ clearConversationUnreadCount(conversationType: ConversationType, targetId: string, channelId?: string): Promise<ErrorCode>;
658
+ /**
659
+ * 清除时间戳之前的未读数
660
+ */
661
+ clearUnreadCountByTimestamp(conversationType: ConversationType, targetId: string, timestamp: number, channelId: string): Promise<ErrorCode>;
662
+ /**
663
+ * 获取第一个未读消息
664
+ */
665
+ getFirstUnreadMessage(conversationType: ConversationType, targetId: string, channelId: string): IPromiseResult<IReceivedMessage | null>;
666
+ /**
667
+ * 设置会话置顶
668
+ */
669
+ setConversationToTop(conversationType: ConversationType, targetId: string, isTop: boolean, channelId?: string): Promise<ErrorCode>;
670
+ /**
671
+ * 设置会话隐藏
672
+ */
673
+ setConversationHidden(conversationType: ConversationType, targetId: string, isHidden: boolean, channelId: string): Promise<ErrorCode>;
674
+ /**
675
+ * 设置会话置顶
676
+ */
677
+ setConversationNotificationStatus(conversationType: ConversationType, targetId: string, isNotify: boolean, channelId: string): Promise<ErrorCode>;
678
+ /**
679
+ * 设置会话置顶、免打扰
680
+ */
681
+ setConversationStatus(conversationType: ConversationType, targetId: string, isBlocked: boolean, isTop: boolean, channelId: string): Promise<ErrorCode>;
682
+ /**
683
+ * 获取会话置顶状态
684
+ */
685
+ getConversationNotificationStatus(conversationType: ConversationType, targetId: string, channelId: string): IPromiseResult<NotificationStatus>;
686
+ /**
687
+ * 通过关键字搜索会话
688
+ * @description
689
+ * 不传 messageTypes 默认仅支持 文本消息、文件消息, 自定义消息类型需传
690
+ */
691
+ searchConversationByContent(keyword: string, customMessageTypes: string[], channelId: string, conversationTypes?: ConversationType[]): IPromiseResult<IReceivedConversation[]>;
692
+ searchConversationByContentWithAllChannel(keyword: string, customMessageTypes: string[], conversationTypes?: ConversationType[]): IPromiseResult<IReceivedConversation[]>;
693
+ /**
694
+ * 按内容搜索会话内的消息
695
+ */
696
+ searchMessageByContent(conversationType: ConversationType, targetId: string, keyword: string, timestamp: number, count: number, total: number, channelId: string): IPromiseResult<{
697
+ messages: IReceivedMessage[];
698
+ count: number;
699
+ }>;
700
+ /**
701
+ * 按内容搜索会话(全部 channelId )内的消息
702
+ */
703
+ searchMessageByContentWithAllChannel(conversationType: ConversationType, targetId: string, keyword: string, timestamp: number, count: number): IPromiseResult<{
704
+ messages: IReceivedMessage[];
705
+ count: number;
706
+ }>;
707
+ /**
708
+ * 按内容搜索会话(全部 channelId )指定时间段内的消息
709
+ */
710
+ searchMessageByContentInTimeRangeWithAllChannel(conversationType: ConversationType, targetId: string, keyword: string, startTime: number, endTime: number, offset: number, limit: number): IPromiseResult<{
711
+ messages: IReceivedMessage[];
712
+ }>;
713
+ /**
714
+ * 获取会话下所有未读的 @ 消息
715
+ * @description
716
+ * 什么时机变为已读: 清除会话未读数或者设置消息已读状态时
717
+ */
718
+ getUnreadMentionedMessages(conversationType: ConversationType, targetId: string, channelId: string): IReceivedMessage[];
719
+ addToBlacklist(userId: string): Promise<ErrorCode>;
720
+ removeFromBlacklist(userId: string): Promise<ErrorCode>;
721
+ getBlacklist(): IPromiseResult<string[]>;
722
+ getBlacklistStatus(userId: string): IPromiseResult<number>;
723
+ insertMessage(conversationType: ConversationType, targetId: string, insertOptions: IInsertMsgOptions): IPromiseResult<IReceivedMessage>;
724
+ deleteMessages(messageIds: number[]): Promise<ErrorCode>;
725
+ deleteMessagesByTimestamp(conversationType: ConversationType, targetId: string, timestamp: number, cleanSpace: boolean, channelId: string): Promise<ErrorCode>;
726
+ getMessage(messageId: number | string): IPromiseResult<IReceivedMessage>;
727
+ setMessageContent(messageId: number, content: any, messageType: string): Promise<ErrorCode>;
728
+ setMessageSearchField(messageId: number, content: any, searchFiles: string): Promise<ErrorCode>;
729
+ setMessageSentStatus(messageId: number, sentStatus: number): Promise<ErrorCode>;
730
+ setMessageReceivedStatus(messageId: number, receivedStatus: number): Promise<ErrorCode>;
731
+ saveConversationMessageDraft(conversationType: ConversationType, targetId: string, draft: string, channelId: string): Promise<ErrorCode>;
732
+ getConversationMessageDraft(conversationType: ConversationType, targetId: string, channelId: string): IPromiseResult<string>;
733
+ clearConversationMessageDraft(conversationType: ConversationType, targetId: string, channelId: string): Promise<ErrorCode>;
734
+ pullConversationStatus(timestamp: number): Promise<IAsyncRes<IServerConversationStatus[]>>;
735
+ /**
736
+ * 协议栈暂时仅支持单独设置免打扰和置顶
737
+ */
738
+ batchSetConversationStatus(statusList: ISetConversationStatusOptions[]): Promise<ErrorCode>;
739
+ pullUserSettings(version: number): IPromiseResult<IServerUserSetting>;
740
+ /**
741
+ * 发送已读回执
742
+ */
743
+ sendReadReceiptMessage(targetId: string, messageUIds: string[], channelId?: string): IPromiseResult<IAsyncRes>;
744
+ /**
745
+ * 获取已读列表
746
+ */
747
+ getMessageReader(targetId: string, messageUId: string, channelId: string): IPromiseResult<IMessageReaderResponse>;
748
+ joinChatroom(chatroomId: string, count: number): Promise<ErrorCode>;
749
+ joinExistChatroom(chatroomId: string, count: number): Promise<ErrorCode>;
750
+ quitChatroom(chatroomId: string): Promise<ErrorCode>;
751
+ /**
752
+ * 获取聊天室信息
753
+ * @description
754
+ * 协议栈返回数据里不带用户加入时间
755
+ */
756
+ getChatroomInfo(chatroomId: string, count: number, order: number): IPromiseResult<IChatroomInfo>;
757
+ getChatroomHistoryMessages(chatroomId: string, timestamp: number, count: number, order: number): IPromiseResult<{
758
+ list: IReceivedMessage[];
759
+ hasMore: boolean;
760
+ }>;
761
+ setChatroomEntry(chatroomId: string, entry: IChrmKVEntry): Promise<ErrorCode>;
762
+ setChatroomEntries(chatroomId: string, entriesOptions: IChrmKVEntries): Promise<{
763
+ code: ErrorCode;
764
+ data?: any;
765
+ }>;
766
+ forceSetChatroomEntry(chatroomId: string, entry: IChrmKVEntry): Promise<ErrorCode>;
767
+ removeChatroomEntry(chatroomId: string, entry: IChrmKVEntry): Promise<ErrorCode>;
768
+ forceRemoveChatroomEntry(chatroomId: string, entry: IChrmKVEntry): Promise<ErrorCode>;
769
+ removeChatroomEntries(chatroomId: string, entriesOptions: IChrmKVEntries): Promise<{
770
+ code: ErrorCode;
771
+ data?: any;
772
+ }>;
773
+ getChatroomEntry(chatroomId: string, key: string): IPromiseResult<string | null>;
774
+ getAllChatroomEntry(chatroomId: string): IPromiseResult<{
775
+ [key: string]: string;
776
+ }>;
777
+ getFileToken(fileType: FileType, fileName?: string, httpMethod?: string, queryUriString?: string): Promise<IAsyncRes<IUploadAuth>>;
778
+ getFileUrl(fileType: FileType, uploadMethod: UploadMethod, fileName: string, originName: string): IPromiseResult<{
779
+ downloadUrl: string;
780
+ }>;
781
+ clearData(): IPromiseResult<boolean>;
782
+ getDeviceId(): string;
783
+ getVoIPKey(engineType: number, channelName: string): IPromiseResult<string>;
784
+ bindRTCRoomForChatroom(options: IRTCRoomBindOption): Promise<ErrorCode>;
785
+ rtcSignaling(roomId: string, method: string, isQuery: boolean, sourceData: ArrayBuffer): Promise<{
786
+ code: ErrorCode;
787
+ buffer?: ArrayBuffer;
788
+ }>;
789
+ private rtcHeartbeatResolves;
790
+ private _setRTCHeartbeatListener;
791
+ rtcPing(roomId: string, mode: number, broadcastType?: number): Promise<ErrorCode>;
792
+ createTag(tag: ITagParam): IPromiseResult<IAsyncRes>;
793
+ removeTag(tagId: string): IPromiseResult<IAsyncRes>;
794
+ updateTag(tag: ITagParam): IPromiseResult<IAsyncRes>;
795
+ getTagList(): IPromiseResult<Array<ITagInfo>>;
796
+ addTagForConversations(tagId: string, conversations: IConversationOption[]): IPromiseResult<IAsyncRes>;
797
+ removeTagForConversations(tagId: string, conversations: IConversationOption[]): IPromiseResult<IAsyncRes>;
798
+ removeTagsForConversation(conversation: IConversationOption, tagIds: string[]): IPromiseResult<IAsyncRes>;
799
+ getConversationListByTag(tagId: string, startTime: number, count?: number, channelId?: string): IPromiseResult<IReceivedConversationByTag[]>;
800
+ getUnreadCountByTag(tagId: string, containMuted: boolean): IPromiseResult<number>;
801
+ setConversationStatusInTag(tagId: string, conversation: IConversationOption, status: ITagStatus): IPromiseResult<IAsyncRes>;
802
+ getTagsForConversation(conversation: IConversationOption): IPromiseResult<IConversationTag[]>;
803
+ getBlockConversationList(): Promise<IAsyncRes<IBaseConversationInfo[]>>;
804
+ getTopConversationList(): Promise<IAsyncRes<IBaseConversationInfo[]>>;
805
+ getUnreadMentionedCount(conversation: IConversationOption): Promise<IAsyncRes<number>>;
806
+ getAllUnreadMentionedCount(): Promise<IAsyncRes<number>>;
807
+ /**
808
+ * 获取运行时的系统信息,仅限 Electron 平台可用
809
+ */
810
+ getOSInfo(): IPromiseResult<IOSInfo>;
811
+ /**
812
+ * 获取应用主进程信息,仅限 Electron 平台可用
813
+ */
814
+ getMainProcessInfo(): IPromiseResult<IProcessInfo>;
477
815
  }
478
816
 
479
817
  declare const _default: (options: {
@@ -493,6 +831,6 @@ declare const _default: (options: {
493
831
  * 断线重连时,若已有其他 PC 设备登录,是否将其他设备踢下线,默认值为 `false`,true 是踢自己,false 是踢其他端
494
832
  */
495
833
  reconnectKickEnable: boolean;
496
- }) => RCServiceProxy;
834
+ }) => RCCppService;
497
835
 
498
836
  export { _default as default };
package/index.esm.js CHANGED
@@ -1 +1 @@
1
- import*as e from"os";import{platform as t,arch as n}from"os";import{resolve as o}from"path";import{Logger as r,appendUrl as s,HTTP_TIMEOUT as i,ConnectionStatus as a,LogLevel as c,logger as u,ErrorCode as p,ConversationType as l,LogTagId as d,SEND_MESSAGE_TYPE_OPTION as f,isObject as g,isUndefined as h,pushJSONToConfigs as _,MessageDirection as C,NotificationStatus as v,MessageType as S,pushConfigsToJSON as y,MentionedType as m,ReceivedStatus as E,isArray as P,getUploadFileName as T,assert as I,AssertRules as R}from"@rongcloud/engine";import{ipcMain as N,app as M}from"electron";import{existsSync as L,readFileSync as b,writeFileSync as U}from"fs";import{createHash as O}from"crypto";import{request as x}from"http";import{Agent as w,request as A}from"https";var D=process.versions.electron.replace(/\.\d+$/,""),H=o(__dirname,"binding","electron-v".concat(D,"-").concat(t(),"-").concat(n(),".node")),k={addon:null};try{k.addon=require(H)}catch(e){console.error("error ->",H,"\n",e)}var J=k.addon,B=function(){return B=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},B.apply(this,arguments)};function F(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}function j(e,t){var n,o,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}function K(e,t,n){if(n||2===arguments.length)for(var o,r=0,s=t.length;r<s;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}var V,G=new r("RCMain"),q=null,W=function(){var e,o=Date.now(),r=[n(),t(),process.pid,o,Math.floor(Math.random()*o)].join("__");return e=r,O("md5").update(e).digest("hex")},Y=function(e){if(q)return q;var t=o(e,"deviceId");return G.debug("deviceIdPath -> ".concat(t)),L(t)?q=b(t).toString():(q=W(),G.debug("createDeviceId -> ".concat(q)),U(t,q),q)},X=function(){function e(e,t){this._timerId=0,this._heartbeatTimeoutId=0,this._isFirstPing=!0,this._lossCount=0,this._hasPingRes=e,this._reconnect=t}return e.init=function(t,n){return V?(V.stop(),V):V=new e(t,n)},e.prototype.start=function(e){var t=this,n=this,o=function(){var r=t._isFirstPing?0:15e3;n._timerId=setTimeout((function(){n._isFirstPing=!1,G.debug("current lossCount: ".concat(n._lossCount)),n._hasPingRes?(e(),n._hasPingRes=!1,o()):n._lossCount<4?(n._lossCount++,e(),o()):n._reconnect()}),r)};o()},e.prototype.stop=function(){this._lossCount=0,clearTimeout(this._timerId)},e.prototype.setHeartbeatRes=function(e){G.debug("receive ping"),this._hasPingRes=e,this._lossCount=0},e}(),z=function(){function e(e){this._setTime=15962112e5,this._cppProto=e}return e.prototype._setToProtocol=function(e,t,n,o,r){var s=JSON.stringify(o);G.info("MsgExpansion._setToProtocol ===>",e,t,n,s,r),this._cppProto.setMessageExtension(e,t,n,s,r)},e.prototype.setLocalFromReceiveMsg=function(e){G.info("MsgExpansion.setLocalFromReceiveMsg ===>",e);var t=e.channelId,n=e.conversationType,o=e.targetId,r=e.messageUId,s=e.expansion,i=e.sentTime,a={};for(var c in s)a[c]={v:"",ts:0},a[c].v=s[c],a[c].ts=i;this._setToProtocol(n,o,r,a,t||"")},e.prototype.setLocalFromExtMsg=function(e){G.info("MsgExpansion.setLocalFromExtMsg ===>",e);var t=e.channelId,n=e.conversationType,o=e.targetId;e.messageUId;var r=e.content,s=e.sentTime,i=r,a=i.put,c=this._cppProto.getMessage(i.mid),u=JSON.parse(c).extMsg,p=JSON.parse(u||"{}");if(G.info("MsgExpansion.setLocalFromExtMsg, serverExtObj",a,"localExt",p),a)for(var l in a){var d=p[l];d&&d.ts<s-this._setTime?(d.v=a[l],d.ts=s-this._setTime):(p[l]={v:"",ts:0},p[l].v=a[l],p[l].ts=s-this._setTime)}i.del&&i.del.forEach((function(e){delete p[e]})),this._setToProtocol(n,o,i.mid,p,t||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),n={};for(var o in t)n[o]=t[o].v;return n},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),n=JSON.parse(t||"{}"),o={};for(var r in n)o[r]=n[r].v;return o},e}();function Q(e,t){void 0===t&&(t=!1);var n=e.url,o=e.headers,r=e.body,a=e.method,c=e.query,u=e.timeout,p=void 0===u?i:u;return new Promise((function(e){var i=/^https/.test(n),u={headers:o,method:a};i&&(u.rejectUnauthorized=t,u.agent=new w(u));var l=(i?A:x)(s(n,c),u,(function(t){var n=t.statusCode,o="";t.setEncoding("utf8"),t.on("data",(function(e){o+=e})),t.once("end",(function(){e({status:n||0,data:o})}))}));l.once("timeout",(function(){G.error("HTTP-Request-Timeout -> ".concat(JSON.stringify(u))),e({status:0})})),l.setTimeout(p),l.once("error",(function(t){G.error("HTTP-Request-Error -> ".concat(JSON.stringify(u))),G.error(t),e({status:0})})),l.write(r),l.end()}))}var $=null;function Z(e,t,n,o,r){return void 0===r&&(r=!0),F(this,void 0,void 0,(function(){var s;return j(this,(function(i){switch(i.label){case 0:return $?[2,$]:($=function(e,t,n,o,r){return void 0===r&&(r=!0),F(this,void 0,void 0,(function(){var s,i,a,c,u,p,l;return j(this,(function(d){switch(d.label){case 0:s="token=".concat(encodeURIComponent(o),"&v=").concat((f=e,f.match(/\d+(\.\d+){2}/)[0]),"&p=PC&ev=").concat("5.5.5-beem"),i=0,a=t.length,d.label=1;case 1:return i<a?(c="".concat(t[i],"/navi.json?r=").concat(Date.now()),G.info("request navi -> url: ".concat(c,", body: ").concat(s)),[4,Q({method:"POST",headers:{appId:n},body:s,url:c},r)]):[3,4];case 2:if(200!==(u=d.sent()).status)return G.error("request navi failed -> ".concat(c)),u.data&&G.error(u.data),[3,3];G.info("request navi success -> ".concat(c));try{return p=JSON.parse(u.data),l=/^https/.test(c)?"https":"http",p.protocol=l,[2,p]}catch(e){G.error("parse navi err => ".concat(u.data))}d.label=3;case 3:return i+=1,[3,1];case 4:return[2,null]}var f}))}))}(e,t,n,o,r),[4,$]);case 1:return s=i.sent(),$=null,[2,s]}}))}))}var ee=function(){function t(e,t,n){void 0===t&&(t=""),void 0===n&&(n=!1);var o=this;this._cppProtocol=e,this._dbpath=t,this._reconnectKickEnable=n,this._currentToken="",this._connectionStatus=a.DISCONNECTED,this._promiseHandler={},this._customMessageType={},this._connectedTime=0,this._currentUserId="",this._inited=!1,this._naviInfo=null,this._version="5.5.5-beem",this._electronLogger={debug:this._superElectronLog.bind(this,"debug",c.DEBUG),info:this._superElectronLog.bind(this,"info",c.INFO),warn:this._superElectronLog.bind(this,"warn",c.WARN),error:this._superElectronLog.bind(this,"error",c.ERROR),fatal:this._superElectronLog.bind(this,"fatal",c.FATAL)},this._logger={debug:this._superLog.bind(this,"debug",c.DEBUG),info:this._superLog.bind(this,"info",c.INFO),warn:this._superLog.bind(this,"warn",c.WARN),error:this._superLog.bind(this,"error",c.ERROR),fatal:this._superLog.bind(this,"fatal",c.FATAL)},this._senders={},this.rtcHeartbeatResolves={},N.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return F(o,void 0,void 0,(function(){var o,r,s,i;return j(this,(function(a){switch(a.label){case 0:if((i=this._electronLogger).debug.apply(i,K(["__RC_CHANNEL_CALL_MAIN_SYNC__",t],n,!1)),"function"!=typeof(o=this[t]))return e.returnValue=p.NOT_SUPPORT,[2];r=p.EXTRA_METHOD_UNDEFINED,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,o.call.apply(o,K([this],n,!1))];case 2:return r=a.sent(),[3,4];case 3:return s=a.sent(),this._electronLogger.error("call main process method `".concat(t,"` failed.")),this._electronLogger.error(s),[3,4];case 4:return e.returnValue=r,[2]}}))}))})),N.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var r=[],s=3;s<arguments.length;s++)r[s-3]=arguments[s];return F(o,void 0,void 0,(function(){var o,s,i,a,c,u=this;return j(this,(function(l){switch(l.label){case 0:if((c=this._electronLogger).debug.apply(c,K(["__RC_CHANNEL_CALL_MAIN__",t,n],r,!1)),"function"!=typeof(o=this[n]))return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,p.NOT_SUPPORT),[2];"sendMessage"===n&&(s=r[3],r[3]=function(t){u._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",s,t)}),i=p.EXTRA_METHOD_UNDEFINED,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,o.call.apply(o,K([this],r,!1))];case 2:return i=l.sent(),[3,4];case 3:return a=l.sent(),this._electronLogger.error("call main process method `".concat(n,"` failed.")),this._electronLogger.error(a),[3,4];case 4:return this._electronLogger.debug("__RC_CHANNEL_RESULT_FROM_MAIN__",t,n,i),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,i),[2]}}))}))})),N.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var n,r=[],s=2;s<arguments.length;s++)r[s-2]=arguments[s];(n=o._electronLogger).debug.apply(n,K(["__RC_CHANNEL_CALL_MAIN__",t],r,!1));var i=o[t];if("function"==typeof i)try{i.call.apply(i,K([o],r,!1))}catch(e){o._electronLogger.error("call main process method `".concat(t,"` failed.")),o._electronLogger.error(e)}else o._electronLogger.error("cannot not found method: ".concat(t))})),N.on("__RC_INNER_COMMAND_INIT__",this._init.bind(this)),this._msgExpansionHandler=new z(this._cppProtocol)}return t.prototype._callCppProxy=function(e){for(var t,n,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];try{return(t=this._cppProtocol)[e].apply(t,o)}catch(t){(n=this._electronLogger).error.apply(n,K([t,e],o,!1))}},t.prototype.sendHTTPRequest=function(e){return Q(e)},t.prototype._superElectronLog=function(e,t){for(var n,o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];if(null===(n=G[e])||void 0===n||n.call.apply(n,K([G],o,!1)),t!==c.DEBUG){var s=Object.keys(this._senders);if(s.length>0){var i=o.reduce((function(e,t){return e+JSON.stringify(t)}),"");this._senders[s[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,i,"RCMain")}}},t.prototype._superLog=function(e,t,n,o,r){var s;if(null===(s=u[e])||void 0===s||s.call(u,n,o,r),t!==c.DEBUG){var i=Object.keys(this._senders);i.length>0&&this._senders[i[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,o,n,null==r?void 0:r.logSource)}},t.prototype.getCppProto=function(){var e=this;return{destroy:function(){e._cppProtocol.destroy()}}},t.prototype.destroy=function(){this._cppProtocol.destroy()},t.prototype.callExtra=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];(t=this._electronLogger).info.apply(t,K(["callExtra -> ".concat(e)],n,!1));var r=this[e];if(!r)return this._electronLogger.warn("ExtraHandler.".concat(e," is undefined")),Promise.resolve({code:p.EXTRA_METHOD_UNDEFINED});try{return r.call.apply(r,K([this],n,!1))}catch(e){this._electronLogger.error(e)}return Promise.resolve({code:p.MAIN_PROCESS_ERROR})},t.prototype.getConversationsByPage=function(e,t,n,o){var r,s=this,i=this._callCppProxy("getConversationListByPage",e,t,n,o||"");try{r=JSON.parse(i).list.map((function(e){return s._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:p.MAIN_PROCESS_ERROR})}return Promise.resolve({code:p.SUCCESS,data:r})},t.prototype.getConversationListWithAllChannel=function(){var e,t=this,n=[l.PRIVATE,l.GROUP],o=this._callCppProxy("getConversationListWithAllChannel",n);try{e=JSON.parse(o).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:p.MAIN_PROCESS_ERROR})}return Promise.resolve({code:p.SUCCESS,data:e})},t.prototype.getConversationListWithAllChannelByPage=function(e,t){var n,o=this,r=[l.PRIVATE,l.GROUP],s=this._callCppProxy("getConversationListWithAllChannelByPage",r,e,t);try{n=JSON.parse(s).list.map((function(e){return o._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:p.MAIN_PROCESS_ERROR})}return Promise.resolve({code:p.SUCCESS,data:n})},t.prototype.getHistoryMessagesByObjectNames=function(e,t,n,o,r,s,i){var a=0===s,c=o+1,u=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,n,c,r,a,i||""),l=[];try{var d=JSON.parse(u).list;d.reverse();for(var f=0;f<d.length;f++){var g=this._buildMessage(d[f].obj);l[f]=g}}catch(e){return this._electronLogger.error(e),Promise.resolve({code:p.MAIN_PROCESS_ERROR})}return Promise.resolve({code:p.SUCCESS,data:{list:c===l.length?l.slice(1,c):l,hasMore:o<l.length}})},t.prototype.updateMessageReceiptStatus=function(e,t,n,o){void 0===o&&(o=""),this._electronLogger.info("updateMessageReceiptStatus ->",e,t,n,o);var r=this._callCppProxy("updateMessageReceiptStatus",e,t,n,o);return Promise.resolve({code:p.SUCCESS,data:r})},t.prototype.requestNaviInfo=function(e,t,n,o){return F(this,void 0,void 0,(function(){return j(this,(function(r){return[2,Z(this._initOptions.apiVersion,e,t,n,o)]}))}))},t.prototype.updateNaviInfo=function(e){this._naviInfo=e},t.prototype.getNaviInfoFromCache=function(){return this._naviInfo?B({},this._naviInfo):null},t.prototype.getConnectedTime=function(){return this._connectedTime},t.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},t.prototype.getCurrentUserId=function(){var e;return(null===(e=this._naviInfo)||void 0===e?void 0:e.userId)||""},t.prototype._send2Renderer=function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,K([t],n,!1))},t.prototype._send2AllRenderer=function(e,t,n){var o=this;void 0===n&&(n=[]),Object.keys(this._senders).forEach((function(r){var s=o._senders[r];n.includes(s)||o._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},t.prototype._init=function(e,t){var n=this,r=e.sender,s=r.id;if(this._senders[s]||(this._senders[s]=r,r.once("destroyed",(function(){delete n._senders[s]}))),!this._inited){this._inited=!0,this._initOptions=t,this._electronLogger.info("init ->",t);var i=this._dbpath||o(M.getPath("userData"));this._logger.info(d.P_INIT_O,{"proto-commitId":this._cppProtocol.getNodeVersion(),appkey:t.appkey,dbpath:i}),this._callCppProxy("initWithAppkey",t.appkey,i,t.apiVersion.replace(/-.*/,"")),this._electronLogger.warn("cppProto version ->",this._cppProtocol.getNodeVersion()),this._registerMsgTypes();var a=Y(i);this._electronLogger.info("deviceId -> ".concat(a)),this._callCppProxy("setDeviceId",a),this._setConnectionStatusListener(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener()}},t.prototype._registerMsgTypes=function(){for(var e in f["RC:RcCmd"]={isCounted:!1,isPersited:!1},f){var t=f[e],n=t.isCounted,o=0;t.isPersited&&(o|=1),n&&(o|=2),"RC:TypSts"===e&&(o=16),this._electronLogger.info("_registerMsgTypes ====>",e,o),this._callCppProxy("registerMessageType",e,o)}},t.prototype._buildMessage=function(e,t){void 0===t&&(t={});var n=t.isOffLineMessage,o=t.buildFrom,r=JSON.parse(e);this._electronLogger.debug("_buildMessage:",r);var s=r.channelId,i=r.conversationType,a=r.targetId,c=r.senderUserId,u=r.content,p=r.objectName,l=r.messageUid,d=r.direction,v=r.status;r.source;var S=r.messageId,y=r.sentTime,m=r.readReceiptRequest,E=r.supportExt;r.extMsg;var P,T=r.pushContent,I=r.pushTitle,R=r.pushId,N=r.pushConfig,M=r.templateId,L=r.disableTitle,b=r.forcePushDetail;if(g(u))P=u;else try{P=u?JSON.parse(u):u}catch(e){G.warn("cpp engine build messaga error:",e),P=u}var U={isCounted:!1,isPersited:!1};p in f?U=f[p]:p in this._customMessageType&&(U=this._customMessageType[p]);var O=null;E&&(O=this._msgExpansionHandler.parseReceiveExpansion(r),"conversation"!==o&&"history"!==o||(O=this._msgExpansionHandler.parseConverOrHisExpansion(r)));var x=h(n)?y<this._connectedTime:n,w={};N&&(w=_(N,R));var A=B(B({},w),{pushTitle:I,pushContent:T,pushData:T,disablePushTitle:L,forceShowDetailContent:b,templateId:M}),D={channelId:s,conversationType:i,targetId:a,senderUserId:c,content:P||{},messageType:p,messageUId:l,messageDirection:d,isOffLineMessage:x,sentTime:y,receivedTime:0,isPersited:U.isPersited,isCounted:U.isCounted,isMentioned:!1,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:E,expansion:E?O:null,receivedStatus:v,messageId:S,pushConfig:A};if(d===C.RECEIVE?D.receivedStatus=v:d===C.SEND&&(D.sentStatus=v),m){var H=JSON.parse(m),k=H.hasRespond,J=H.readerInfo,F={hasRespond:k,readCount:H.readCount,totalCount:H.totalCount},j=[];if(J)for(var K in J)j.push({userId:K,readTime:J[K]});F.readerList=j,D.readReceiptInfo=F}return D},t.prototype._updateReadReceiptInfo=function(e,t){var n=this._callCppProxy("getMessage",e),o=JSON.parse(n),r=o.readReceiptRequest?JSON.parse(o.readReceiptRequest):{},s=B(B({},r),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},t.prototype._buildConversation=function(e){var t=JSON.parse(e);this._electronLogger.debug("_buildConversation",t);var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.unreadCount,i=t.lastestMsg,a=t.isTop,c=t.isBlocked,u=t.matchCount,p=c?v.OPEN:v.CLOSE;return{channelId:n,conversationType:o,targetId:r,unreadMessageCount:s,latestMessage:-1===JSON.parse(i).messageId?null:this._buildMessage(i),hasMentioned:!1,mentionedInfo:null,notificationStatus:p,isTop:a,lastUnreadTime:0,matchCount:u}},t.prototype._sendConnectionStatus2Renderer=function(e){this._send2AllRenderer("status",e)},t.prototype._convertResultList=function(e,t){var n=JSON.parse(e).list;return n=n.map((function(e){var n=JSON.parse(e.obj);return t?t(n):n}))},t.prototype._connectResolve=function(e){this._promiseHandler.connect&&this._promiseHandler.connect.length>0&&(this._promiseHandler.connect.forEach((function(t){t.resolve(e)})),delete this._promiseHandler.connect)},t.prototype._setConnectionStatusListener=function(){var e=this;this._cppProtocol.setConnectionStatusListener((function(t){var n,o;switch(e._electronLogger.warn("protocol connection status changed:",t),t){case 10:o=a.CONNECTING;break;case 31004:return void setTimeout((function(){e._connectResolve(p.RC_CONN_USER_OR_PASSWD_ERROR)}));case 12:o=a.DISCONNECTED;break;case 13:o=a.BLOCKED,setTimeout((function(){e._connectResolve(p.RC_CONN_USER_BLOCKED)}));break;case 31023:o=a.FORBID_RECONNECT_BY_OTHER_SAME_CLIENT,setTimeout((function(){e._connectResolve(p.RC_DISCONN_SAME_CLIENT_ON_LINE)}));break;case 31029:o=a.USER_LOGOUT;break;case 1:case 9:case 11:case 31011:case 3e4:case 30002:o=a.NETWORK_UNAVAILABLE;break;case 30010:o=a.NETWORK_UNAVAILABLE,setTimeout((function(){e._connectionStatus===a.NETWORK_UNAVAILABLE&&e._doConnect()}),5e3);break;case 0:case 33005:o=a.CONNECTED,e._connectedTime=Date.now()-e._cppProtocol.getDeltaTime(),setTimeout((function(){e._connectResolve(p.SUCCESS),e._heartbeat=X.init(!0,e._handleHeartTimeout.bind(e)),e._heartbeat.start(e._sendHeartbeat.bind(e))}));break;case a.KICKED_OFFLINE_BY_OTHER_CLIENT:o=a.KICKED_OFFLINE_BY_OTHER_CLIENT;break;case 31030:o=a.RC_LICENSE_EXPIRED,setTimeout((function(){e._connectResolve(p.RC_LICENSE_EXPIRED)}));break;case 30004:return;case 8:case 31006:case 32061:case 32012:o=a.REDIRECT;break;default:o=t}o!==a.CONNECTED&&(null===(n=e._heartbeat)||void 0===n||n.stop()),e._connectionStatus=o,e._logger.info(d.P_CONNECT_S,{status:t}),e._sendConnectionStatus2Renderer(o)}),this._dbOpenCallback,(function(){var t;null===(t=e._heartbeat)||void 0===t||t.setHeartbeatRes(!0)}))},t.prototype._handleHeartTimeout=function(){var e,t=this;G.warn("network unavailable! try to reconnect!"),this._sendConnectionStatus2Renderer(a.NETWORK_UNAVAILABLE),null===(e=this._heartbeat)||void 0===e||e.stop(),setTimeout((function(){return t._doConnect()}),5e3)},t.prototype._dbOpenCallback=function(e){G.info("Sqlite DB Open -> ".concat(e))},t.prototype._sendHeartbeat=function(){G.debug("send ping"),this._cppProtocol.sendHeartbeat()},t.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,n,o,r){var s,i=e._buildMessage(t,{isOffLineMessage:o});if(i.messageType===S.GROUP_READ_RECEIPT_REQUEST){var a=i.content,c=a.msgId,u=a.rrn,p=a.tmn;e._updateReadReceiptInfo(c,{readCount:u,totalCount:p})}if("RC:MsgExMsg"===i.messageType)return e._msgExpansionHandler.setLocalFromExtMsg(i),void e._sendMessageExpansion(i);if(i.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(i),i.messageType===S.SYNC_READ_STATUS){if(i.senderUserId!==e._currentUserId)return;e._callCppProxy("clearUnreadCountByTimestamp",i.conversationType,i.targetId,i.content.lastMessageSendTime,i.channelId||"")}var l=!0;if(0!==n||r||(l=!1),i.messageType!==S.LOG_COMMAND||"rongcloudsystem"!==i.senderUserId){if(i.messageType===S.DELIVERED)return e._callCppProxy("setMessageDeliverTime",JSON.stringify(i.content)),void e._sendMessageDelivered(i.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}})));if(i.messageType!==S.DELIVERED_MSG){var d=i.conversationType,f=i.targetId;i.messageType===S.RECALL&&i.senderUserId===e._currentUserId&&(d=i.content.conversationType||d,f=i.content.targetId||f),e._sendMessageNotification(Object.assign(i,{hasMoreMsg:l,conversationType:d,targetId:f}))}else{var g={totalCount:i.content.tmn,list:null===(s=i.content.dl)||void 0===s?void 0:s.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};e._sendGroupMessageDeliveredStatus(g)}}else{var h=Object.keys(e._senders).map((function(t){return e._senders[t]}));h.length>0&&e._sendMessageNotification(Object.assign(i,{hasMoreMsg:l}),h.slice(1))}}),(function(){e._sendPullOfflineFinished()}))},t.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var n=e.channelId,o=e.content,r=o.put,s=o.del,i=o.mid,a={};r&&(a.updatedExpansion={channelId:n,messageUId:i,expansion:r}),s&&(a.deletedExpansion={channelId:n,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},t.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},t.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},t.prototype._sendMessageDelivered=function(e){this._send2AllRenderer("messageDelivered",e)},t.prototype._sendGroupMessageDeliveredStatus=function(e){this._send2AllRenderer("groupMessageDeliveredStatus",e)},t.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var n=JSON.parse(t).list,o=[];n.forEach((function(e){var t=JSON.parse(e.obj),n=t.conversationType,r=t.targetId,s=t.status,i=t.channelId,a={notificationStatus:2,isTop:!1};s.forEach((function(e){var t=JSON.parse(e.item);1===t.type?a.notificationStatus=1===Number(t.value)?v.OPEN:v.CLOSE:a.isTop=1===Number(t.value)})),o.push({channelId:i,conversationType:n,targetId:r,updatedItems:{notificationStatus:{val:a.notificationStatus,time:0},isTop:{val:a.isTop,time:0}}})})),e._send2AllRenderer("conversation",o)}),(function(t){e._electronLogger.info("会话标签状态变更",t),e._send2AllRenderer("conversationTag",t)}))},t.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._electronLogger.info("标签变更",t),e._send2AllRenderer("tag",t),e._getRTCProfile()}))},t.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e&&this._naviInfo&&this._naviInfo.voipCallInfo!==e){var t=B(B({},this._naviInfo),{voipCallInfo:e});this._naviInfo=t,this._send2AllRenderer("onNaviDataChange",t)}},t.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var n=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",n)}))},t.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,n){e._send2AllRenderer("chatroom",{chatroomDestroyed:t})}))},t.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._send2AllRenderer("callInfo",t)}))},t.prototype._clearListener=function(){this._cppProtocol.setOnReceiveMessageListener(),this._cppProtocol.setConnectionStatusListener(),this._cppProtocol.setOnReceiveStatusListener(),this._cppProtocol.setUserProfileListener()},t.prototype.registerMessageType=function(e,t,n,o){var r=0;t&&(r|=1),n&&(r|=2),this._customMessageType[e]={isCounted:n,isPersited:t},this._logger.info(d.P_REGTYP_O,{messageType:e,isCounted:n,searchProps:o,isPersited:t}),this._callCppProxy("registerMessageType",e,r,o)},t.prototype.connect=function(e,t,n,o){var r=this;return this._electronLogger.info("connect ->",e,t,n),this._logger.info(d.P_CONNECT_O,{token:e,reconnectKickEnable:n,version:this._version},{traceId:o}),this._currentToken===e&&this._connectionStatus===a.CONNECTED?(this._sendConnectionStatus2Renderer(this._connectionStatus),Promise.resolve(p.SUCCESS)):(this._currentToken=e,this._naviInfo=t,this._currentUserId=t.userId,this._promiseHandler.connect||this._doConnect(n),new Promise((function(e,t){r._promiseHandler.connect?r._promiseHandler.connect.push({resolve:e,reject:t}):r._promiseHandler.connect=[{resolve:e,reject:t}]})))},t.prototype._doConnect=function(e){var t=h(e)?!!this._reconnectKickEnable:!!e;this._callCppProxy("connectWithToken",this._currentToken,this._initOptions.apiVersion,JSON.stringify(this._naviInfo),t)},t.prototype.reportSDKInfo=function(e){var t,n;null===(n=(t=this._cppProtocol).uploadSDKVersion)||void 0===n||n.call(t,JSON.stringify(e)),this._electronLogger.info(e)},t.prototype.disconnect=function(){var e;this._cppProtocol.disconnect(!0),null===(e=this._heartbeat)||void 0===e||e.stop(),this._connectResolve(p.TIMEOUT)},t.prototype.logout=function(){this.disconnect()},t.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,n){t({userId:e,status:n})}));var n=e.userIds||[];n.length&&this.subscribeUserStatus(n)},t.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("subscribeUserStatus",e,(function(){n(p.SUCCESS)}),n)}))},t.prototype.setUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("setUserStatus",e,(function(){n(p.SUCCESS)}),n)}))},t.prototype.getUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getUserStatus",e,(function(e){n({code:p.SUCCESS,data:{status:e}})}),(function(e){n({code:e})}))}))},t.prototype.sendMessage=function(e,t,n,o,r){var s=this,i=n.messageType,a=n.content,c=n.pushContent,u=n.pushData,f=n.directionalUserIdList,g=n.disableNotification,h=n.canIncludeExpansion,_=n.expansion,C=n.isVoipPush,v=n.pushConfig,E=n.channelId,P=n.isMentioned,T=n.mentionedType,I=n.mentionedUserIdList,R=n.messageId,N=v||{},M=N.iOSConfig,L=N.androidConfig,b=N.pushTitle,U=N.pushContent,O=N.pushData,x=N.disablePushTitle,w=N.forceShowDetailContent,A=N.templateId,D=y(M,L);return new Promise((function(n){c=U||c||"",u=O||u||"",g=g||!1,C=C||!1,b=b||"",U=U||"",O=O||"",x=x||!1,w=w||!1,h=h||!1;var v=(null==L?void 0:L.notificationId)||"";if(f=f||[],R=R||0,E=E||"",e===l.GROUP&&P&&a&&(a.mentionedInfo={userIdList:I,type:T||m.ALL}),e===l.GROUP&&i===S.READ_RECEIPT_RESPONSE&&a.receiptMessageDic)for(var y in a.receiptMessageDic)f.push(y);var N={};for(var y in _)N[y]={v:""},N[y].v=_[y];var M=A||"";R&&s._callCppProxy("setMessageContent",R,JSON.stringify(a),i),s._logger.info(d.P_SEND_MSG_T,{messageType:i,conversationType:e,targetId:t,channelId:E},{traceId:r});var H=s._callCppProxy("sendMessage",(function(e,t){var o=s._buildMessage(e,{isOffLineMessage:!1});return s._logger.info(d.P_SEND_MSG_R,{code:t,messageUId:o.messageUId,messageId:o.messageId},{traceId:r}),t===p.SENSITIVE_REPLACE?n({code:t}):("RC:MsgExMsg"===o.messageType&&s._msgExpansionHandler.setLocalFromExtMsg(o),o.canIncludeExpansion&&s._msgExpansionHandler.setLocalFromReceiveMsg(o),n({code:p.SUCCESS,data:o}))}),(function(e,t){var o=s._buildMessage(e,{isOffLineMessage:!1});return s._logger.warn(d.P_SEND_MSG_R,{code:t,messageUId:o.messageUId,messageId:o.messageId},{traceId:r}),o.sentTime=Date.now()-s._cppProtocol.getDeltaTime(),n({code:t,data:o})}),e,t,i,JSON.stringify(a),f,g,x,w,c,u,v,b,D,M,h,JSON.stringify(N),C,E,R),k=JSON.parse(H);null==o||o(k.messageId)}))},t.prototype.recallMsg=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){var c,u=r.user,l=r.pushContent,d=r.channelId,f=r.extra,g=r.pushConfig,h=r.disableNotification,_=r.isDelete,v={conversationType:e,targetId:t,messageUId:n,sentTime:o,user:u,extra:f,channelId:d,isDelete:_||!1};u&&(v.user=u),f&&(v.extra=f);var m={conversationType:e,targetId:t,senderUserId:s._currentUserId,content:v,objectName:S.RECALL,messageUid:n,direction:C.SEND,status:E.UNREAD,sentTime:o,channelId:d},P=s._buildMessage(JSON.stringify(m),{isOffLineMessage:!1});s._callCppProxy("recallMessage",(function(){i({code:p.SUCCESS,data:P})}),(function(e){i({code:e})}),S.RECALL,JSON.stringify(v),h||!1,(null==g?void 0:g.disablePushTitle)||!1,(null==g?void 0:g.forceShowDetailContent)||!1,l||"",(null==g?void 0:g.pushData)||"",(null===(c=null==g?void 0:g.androidConfig)||void 0===c?void 0:c.notificationId)||"",(null==g?void 0:g.pushTitle)||"",y(null==g?void 0:g.iOSConfig,null==g?void 0:g.androidConfig),(null==g?void 0:g.templateId)||"",d)}))},t.prototype.getHistoryMessage=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c,u){n=n||0;var l=0===r,d=o+1,f=a._callCppProxy("getHistoryMessages",e,t,n,d,i,l,s),g=JSON.parse(f).list,h=[];g.reverse();for(var _=0;_<g.length;_++){var C=a._buildMessage(g[_].obj);h[_]=C}c({code:p.SUCCESS,data:{list:d===h.length?h.slice(1,d):h,hasMore:o<h.length}})}))},t.prototype.getRemoteHistoryMessages=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,c){n=n||0;i._callCppProxy("getRemoteHistoryMessages",e,t,n,o,(function(e,t){var n=JSON.parse(e).list,o=[];n.reverse();for(var r=0;r<n.length;r++){var s=i._buildMessage(n[r].obj);o[r]=s}a({code:p.SUCCESS,data:{list:o,hasMore:!!t}})}),(function(e){a({code:e})}),r,!0,s)}))},t.prototype.deleteRemoteMessage=function(e,t,n,o){var r=this;return new Promise((function(s,i){var a=JSON.stringify(n);r._callCppProxy("deleteRemoteHistoryMessages",e,t,a,!1,o,(function(){s(p.SUCCESS)}),s)}))},t.prototype.deleteRemoteMessageByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearRemoteHistoryMessages",e,t,n,(function(){s(p.SUCCESS)}),(function(e){s(e)}),o)}))},t.prototype.clearMessages=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("clearMessages",e,t,n),r(p.SUCCESS)}))},t.prototype.getConversationList=function(e,t,n,o,r){var s=this;return void 0===r&&(r=""),new Promise((function(e,t){for(var n=s._callCppProxy("getConversationList",[1,3,6,7],r),o=JSON.parse(n).list,i=[],a=0;a<o.length;a++)i.push(s._buildConversation(o[a].obj));e({code:p.SUCCESS,data:i})}))},t.prototype.getConversation=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversation",e,t,n);if(i)r({code:p.SUCCESS,data:o._buildConversation(i)});else{var a=o._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,n),c=void 0;try{c=JSON.parse(a).list}catch(e){o._electronLogger.warn("json parse cppMessagaes error",e),c=[]}var u=null;c.length>0&&(u=o._buildMessage(c[0].obj));var l=o._callCppProxy("getConversationNotificationStatus",e,t,n),d=o._callCppProxy("getConversationTopStatus",e,t,n);r({code:p.SUCCESS,data:{conversationType:e,targetId:t,channelId:n,unreadMessageCount:0,latestMessage:u,notificationStatus:l?v.OPEN:v.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},t.prototype.removeConversation=function(e,t,n){var o=this._callCppProxy("removeConversation",e,t,n);return this._electronLogger.info("removeConversation result -> ".concat(o)),Promise.resolve(o?p.SUCCESS:p.UNKNOWN)},t.prototype.clearConversations=function(e,t){var n=this;return new Promise((function(o,r){var s=[];s=P(e)?e:[l.PRIVATE,l.GROUP,l.SYSTEM,l.PUBLIC_SERVICE],n._callCppProxy("clearConversations",s,t),o(p.SUCCESS)}))},t.prototype.getAllConversationUnreadCount=function(e,t,n){var o=this._callCppProxy("getTotalUnreadCount",t,n,e);return Promise.resolve({code:p.SUCCESS,data:o})},t.prototype.getConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r){var s=o._callCppProxy("getUnreadCount",e,t,n);r({code:p.SUCCESS,data:s})}))},t.prototype.clearConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r,s){o._callCppProxy("clearUnreadCount",e,t,n),r(p.SUCCESS)}))},t.prototype.clearUnreadCountByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearUnreadCountByTimestamp",e,t,n,o),s(p.SUCCESS)}))},t.prototype.getFirstUnreadMessage=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getTheFirstUnreadMessage",e,t,n),a=o._buildMessage(i);r({code:p.SUCCESS,data:-1!==a.messageId?a:null})}))},t.prototype.setConversationToTop=function(e,t,n,o){var r=this;return void 0===o&&(o=""),new Promise((function(s,i){r._electronLogger.info("setConversationToTop",e,t,n,o,true),r._callCppProxy("setConversationToTop",e,t,n,o,true),s(p.SUCCESS)}))},t.prototype.setConversationHidden=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationHidden",e,t,n,o),s(p.SUCCESS)}))},t.prototype.setConversationNotificationStatus=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._electronLogger.info("setConversationNotificationStatus",e,t,n,o),r._callCppProxy("setConversationNotificationStatus",e,t,n,(function(){s(p.SUCCESS)}),s,o)}))},t.prototype.setConversationStatus=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._electronLogger.info("setConversationStatus",e,t,n,o,r,true),s._callCppProxy("setConversationStatus",e,t,n,o,(function(){i(p.SUCCESS)}),i,r,true)}))},t.prototype.getConversationNotificationStatus=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversationNotificationStatus",e,t,n);r({code:p.SUCCESS,data:i?v.OPEN:v.CLOSE})}))},t.prototype.searchConversationByContent=function(e,t,n,o){var r=this;return new Promise((function(s,i){o=o||[1,3,6,7];for(var a=r._callCppProxy("searchConversationByContent",o,e,t,n),c=JSON.parse(a).list,u=[],l=0;l<c.length;l++)u[l]=r._buildConversation(c[l].obj);s({code:p.SUCCESS,data:u})}))},t.prototype.searchConversationByContentWithAllChannel=function(e,t,n){var o=this;return new Promise((function(r,s){n=n||[1,3,6,7];for(var i=o._callCppProxy("searchConversationByContentWithAllChannel",n,e,t),a=JSON.parse(i).list,c=[],u=0;u<a.length;u++)c[u]=o._buildConversation(a[u].obj);r({code:p.SUCCESS,data:c})}))},t.prototype.searchMessageByContent=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(s,c){a._callCppProxy("searchMessageByContent",e,t,n,o,r,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],o=[],r=0;r<n.length;r++)o[r]=a._buildMessage(n[r].obj);s({code:p.SUCCESS,data:{messages:o,count:t}})}),i)}))},t.prototype.searchMessageByContentWithAllChannel=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("searchMessageByContentWithAllChannel",e,t,n,o,r,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],o=[],r=0;r<n.length;r++)o[r]=s._buildMessage(n[r].obj);i({code:p.SUCCESS,data:{messages:o,count:t}})}))}))},t.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(c,u){a._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,n,o,r,s,i,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],o=0;o<t.length;o++)n[o]=a._buildMessage(t[o].obj);c({code:p.SUCCESS,data:{messages:n}})}))}))},t.prototype.getUnreadMentionedMessages=function(e,t,n){for(var o=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,n)).list,r=0;r<o.length;r++)o[r]=this._buildMessage(o[r].obj);return o},t.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addToBlacklist",e,(function(){n(p.SUCCESS)}),n)}))},t.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("removeFromBlacklist",e,(function(){n(p.SUCCESS)}),n)}))},t.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,n){e._callCppProxy("getBlacklist",(function(e){t({code:p.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},t.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getBlacklistStatus",e,(function(e){n({code:p.SUCCESS,data:e})}),(function(e){n({code:e})}))}))},t.prototype.insertMessage=function(e,t,n){var o=this,r=n.content,s=n.senderUserId,i=n.messageType,a=n.messageDirection,c=n.readStatus,u=n.sentStatus,l=n.sentTime,d=n.searchContent,f=n.isUnread,g=n.messageUId,h=n.disableNotification,_=n.canIncludeExpansion,C=n.expansionMsg,v=n.channelId;return r=JSON.stringify(r),new Promise((function(n,S){var y=f?0:1,m=o._callCppProxy("insertMessage",e,t,s,i,r,(function(){}),(function(e){n({code:e})}),a,c,u,l,d,y,g,h,_,C,v);o._electronLogger.info("after insert msg",m);var E=o._buildMessage(m,{isOffLineMessage:!1});E.messageUId=g,E.sentTime=l,n({code:-1===E.messageId?p.MSG_INSERT_ERROR:p.SUCCESS,data:E})}))},t.prototype.deleteMessages=function(e){var t=this;return new Promise((function(n,o){t._logger.debug(d.P_DELETE_MSG_S,{messageIds:e}),t._callCppProxy("deleteMessages",e),n(p.SUCCESS)}))},t.prototype.deleteMessagesByTimestamp=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("deleteMessagesByTimestamp",e,t,n,o,r),i(p.SUCCESS)}))},t.prototype.getMessage=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getMessage",e);t._electronLogger.info("getMessage ===>",r);var s=t._buildMessage(r,{isOffLineMessage:!1});n({code:p.SUCCESS,data:s})}))},t.prototype.setMessageContent=function(e,t,n){var o=this;return new Promise((function(r,s){t=JSON.stringify(t),o._callCppProxy("setMessageContent",e,t,n),r(p.SUCCESS)}))},t.prototype.setMessageSearchField=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageSearchField",e,t,n),r(p.SUCCESS)}))},t.prototype.setMessageSentStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageSentStatus",e,t),o(p.SUCCESS)}))},t.prototype.setMessageReceivedStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageReceivedStatus",e,t),o(p.SUCCESS)}))},t.prototype.saveConversationMessageDraft=function(e,t,n,o){throw new Error("Method not implemented.")},t.prototype.getConversationMessageDraft=function(e,t,n){throw new Error("Method not implemented.")},t.prototype.clearConversationMessageDraft=function(e,t,n){throw new Error("Method not implemented.")},t.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},t.prototype.batchSetConversationStatus=function(e){var t=e[0],n=t.conversationType,o=t.targetId,r=t.isTop,s=t.notificationStatus,i=t.channelId;if(void 0!==r&&void 0===s)return this.setConversationToTop(n,o,r,i);if(void 0!==s&&void 0===r){var a=s===v.OPEN;return this.setConversationNotificationStatus(n,o,a,i)}var c=s===v.OPEN;return this.setConversationStatus(n,o,c,r,i)},t.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},t.prototype.sendReadReceiptMessage=function(e,t,n){var o=this;return new Promise((function(r){o._callCppProxy("sendReadReceipt",e,n||"",t,(function(){t.forEach((function(e){o._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(o._callCppProxy("getMessage",e)).messageId;o.setMessageReceivedStatus(t,1)}catch(t){o._electronLogger.warn("format message error, messageUId: ".concat(e))}})),r({code:p.SUCCESS})}),(function(e){r({code:e})}))}))},t.prototype.getMessageReader=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getMessageReader",e,n,t,(function(e,n){o._electronLogger.info("getMessageReader -> ",e,n);var s=[],i={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),n=t.id,o=t.time;s.push({userId:n,readTime:o}),i[n]=o}));var a={readerInfo:i,readCount:s.length,totalCount:n};o._updateReadReceiptInfo(t,a),r({code:p.SUCCESS,data:{list:s,totalMemberCount:n}})}),(function(e){r({code:e})}))}))},t.prototype.joinChatroom=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("clearMessages",l.CHATROOM,e,""),n._callCppProxy("joinChatRoom",e,t,(function(){o(p.SUCCESS)}),o)}))},t.prototype.joinExistChatroom=function(e,t){throw new Error("Method not implemented.")},t.prototype.quitChatroom=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("quitChatRoom",e,(function(){n(p.SUCCESS)}),n)}))},t.prototype.getChatroomInfo=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getChatroomInfo",e,t,n,(function(e,t){var n=e?JSON.parse(e).list:[],o=[];if(n.length>0)for(var s=0;s<n.length;s++)o.push(JSON.parse(n[s].obj));r({code:p.SUCCESS,data:{userInfos:o,userCount:t}})}),(function(e){r({code:e})}))}))},t.prototype.getChatroomHistoryMessages=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomHistoryMessage",e,t,n,o,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var n=t.list;if(n&&n.length)try{t.list=n.map((function(e){return r._buildMessage(e.obj)}))}catch(e){t.list=[]}s({code:p.SUCCESS,data:t})}),(function(e){s({code:e})}),"")}))},t.prototype.setChatroomEntry=function(e,t){var n=this;return new Promise((function(o,r){var s='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');n._callCppProxy("setChatroomKV",e,s,!!t.isAutoDelete,!!t.isOverwrite,(function(){o(p.SUCCESS)}),(function(e){o(e)}))}))},t.prototype.setChatroomEntries=function(e,t){var n=this;return new Promise((function(o){n._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){o({code:p.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.setChatroomEntry(e,t)},t.prototype.removeChatroomEntry=function(e,t){var n=this,o=[t.key];return new Promise((function(r,s){n._callCppProxy("deleteChatroomKV",e,o,!!t.isOverwrite,(function(){r(p.SUCCESS)}),(function(e){r(e)}))}))},t.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.removeChatroomEntry(e,t)},t.prototype.removeChatroomEntries=function(e,t){var n=this;return new Promise((function(o){var r=t.entries.map((function(e){return e.key}));n._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){o({code:p.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.getChatroomEntry=function(e,t){return F(this,void 0,void 0,(function(){var n;return j(this,(function(o){switch(o.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(n=o.sent()).code===p.SUCCESS?[2,{code:p.SUCCESS,data:n.data?n.data[t]:null}]:[2,{code:n.code}]}}))}))},t.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}n({code:p.SUCCESS,data:t})}),(function(e){n({code:e})}))}))},t.prototype.getFileToken=function(e,t,n,o){var r=this;return n=n||"",o=o||"",new Promise((function(s){var i;i=o&&"uploads"!==o?t||"":T(e,t),r._callCppProxy("getUploadToken",e,i,n,o,(function(e,t,n,o,r,a,c,u,l,d,f,g,h,_,C,v,S,y){s({code:p.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:n,path:o,osskeyId:r,ossPolicy:a,ossSign:c,ossBucketName:u,fileName:i,s3Credential:l,s3Algorithm:d,s3Date:f,s3Policy:g,s3Signature:h,s3BucketName:_,stcAuthorization:C,stcContentSha256:v,stcDate:S,stcBucketName:y}})}),(function(e){s({code:e})}))}))},t.prototype.getFileUrl=function(e,t,n,o){var r=this;return new Promise((function(s){r._callCppProxy("getDownloadUrl",e,n,o,t-1,(function(e){s({code:p.SUCCESS,data:{downloadUrl:e}})}),(function(e){s({code:e})}))}))},t.prototype.clearData=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("clearData");t({code:p.SUCCESS,data:o})}))},t.prototype.getDeviceId=function(){var e=this._dbpath||o(M.getPath("userData"));return Y(e)},t.prototype.getVoIPKey=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("getVoIPKey",e,t,"",(function(e){o({code:p.SUCCESS,data:e})}),(function(e){o({code:e})}))}))},t.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(n,o){var r=e.chatRoomId,s=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",r,s,(function(){n(p.SUCCESS)}),(function(e){n(e)}))}))},t.prototype.getGroupMessageDeliverList=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getGroupMessageDeliverList",e,n,t,(function(e,t){var n=JSON.parse(e).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));r({code:p.SUCCESS,data:{totalCount:t,list:n}})}),(function(e){r({code:e})}))}))},t.prototype.getPrivateMessageDeliverTime=function(e,t){var n=this;return new Promise((function(o,r){var s=n._callCppProxy("getMessageDeliverTime",e);if(s)o({code:p.SUCCESS,data:s});else{n._callCppProxy("getPrivateMessageDeliverList",t,e,(function(e){var t=0,n=JSON.parse(e).list;n.length>0&&(t=JSON.parse(n[0].obj).time);o({code:p.SUCCESS,data:t})}),(function(e){o({code:e})}))}}))},t.prototype.rtcSignaling=function(e,t,n,o){var r=this,s=Array.prototype.slice.call(new Uint8Array(o));return new Promise((function(o){r._callCppProxy("rtcSignaling",e,t,n,s,(function(e){var t=new Uint8Array(e).buffer;o({code:p.SUCCESS,buffer:t})}),(function(e){o({code:e})}))}))},t.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,n){var o=e.rtcHeartbeatResolves[t];if(o){var r=o.find((function(e){return""===e.seqId}));r&&(r.seqId=n)}}),(function(t,n,o){var r=e.rtcHeartbeatResolves[t];if(r){var s=r.findIndex((function(e){return e.seqId===o}));-1!==s&&r.splice(s,1)[0].resolve(n)}}))},t.prototype.rtcPing=function(e,t,n){var o=this;return new Promise((function(t){var n={resolve:t,seqId:""},r=o.rtcHeartbeatResolves[e];r?r.push(n):o.rtcHeartbeatResolves[e]=[n],o._callCppProxy("sendRTCHeartbeat",[e])}))},t.prototype.createTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){n({code:p.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.removeTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("deleteTag",e,(function(){n({code:p.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.updateTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){n({code:p.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getTagList=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("getTags");e._electronLogger.info("getTagList -> ",o);var r=e._convertResultList(o,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:p.SUCCESS,data:r})}))},t.prototype.addTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));n._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){o({code:p.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.removeTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),n._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){o({code:p.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.removeTagsForConversation=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){o({code:p.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.getConversationListByTag=function(e,t,n,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversationsForTagByPage",e,t,n||20,o||"");r._electronLogger.info("getConversationListByTag -> ",a);var c=r._convertResultList(a,(function(e){return B(B({},r._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));s({code:p.SUCCESS,data:c})}))},t.prototype.getUnreadCountByTag=function(e,t){var n=this;return new Promise((function(o,r){var s=n._callCppProxy("getConversationUnreadCountForTag",e,t);n._electronLogger.info("getUnreadCountByTag -> ",s),o({code:p.SUCCESS,data:s})}))},t.prototype.setConversationStatusInTag=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",n.isTop||!1,(function(){r({code:p.SUCCESS})}),(function(e){r({code:e})}))}))},t.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||"");t._electronLogger.info("getTagsForConversation -> ",r);var s=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));n({code:p.SUCCESS,data:s})}))},t.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getTopConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},t.prototype.getAllUnreadMentionedCount=function(){throw new Error("Method not implemented.")},t.prototype.getOSInfo=function(){return F(this,void 0,void 0,(function(){var t;return j(this,(function(n){return t={arch:e.arch(),platform:e.platform(),type:e.type(),version:e.version(),release:e.release(),uptime:e.uptime(),cpus:e.cpus(),freemem:e.freemem(),totalmem:e.totalmem(),networkInterfaces:e.networkInterfaces()},[2,{code:p.SUCCESS,data:t}]}))}))},t.prototype.getMainProcessInfo=function(){return F(this,void 0,void 0,(function(){return j(this,(function(e){return[2,{code:p.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(e,t,n){var o=this;return new Promise((function(r){o._callCppProxy("callInfoSignaling",e,t,n,(function(e,t){r({code:p.SUCCESS,data:{key:e,value:t}})}),(function(e){r({code:e})}))}))},t}(),te=function(){function e(e,t,n){void 0===t&&(t=""),void 0===n&&(n=!1),this._cppProtocol=e,this._dbpath=t,this._reconnectKickEnable=n,this._cppService=new ee(this._cppProtocol,this._dbpath,this._reconnectKickEnable)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){e._cppService.destroy()}}},e.prototype.destroy=function(){this._cppService.destroy()},e}(),ne=function(e){return function(e,t){return I("options.reconnectKickEnable",null==t?void 0:t.reconnectKickEnable,R.BOOLEAN),u.init({customLogPrint:null==t?void 0:t.logStdout,localLogLevel:null==t?void 0:t.logLevel}),G.setLogLevel(null==t?void 0:t.logLevel),G.setLogStdout(null==t?void 0:t.logStdout),new te(e,null==t?void 0:t.dbpath,null==t?void 0:t.reconnectKickEnable)}(J,e)};export{ne as default};
1
+ import*as e from"os";import{platform as t,arch as n}from"os";import{resolve as o}from"path";import{Logger as r,ConnectionStatus as s,LogLevel as i,logger as a,ErrorCode as c,ConversationType as u,LogTagId as p,SEND_MESSAGE_TYPE_OPTION as l,isObject as d,isUndefined as f,pushJSONToConfigs as g,MessageDirection as h,NotificationStatus as _,MessageType as C,pushConfigsToJSON as v,MentionedType as S,ReceivedStatus as y,isArray as m,getUploadFileName as E,assert as P,AssertRules as T}from"@rongcloud/engine";import{ipcMain as I,app as R}from"electron";import{existsSync as N,readFileSync as M,writeFileSync as L}from"fs";import{createHash as U}from"crypto";import{request as b}from"http";import{Agent as O,request as x}from"https";var w=process.versions.electron.replace(/\.\d+$/,""),A=o(__dirname,"binding","electron-v".concat(w,"-").concat(t(),"-").concat(n(),".node")),D={addon:null};try{D.addon=require(A)}catch(e){console.error("error ->",A,"\n",e)}var H=D.addon,k=function(){return k=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},k.apply(this,arguments)};function B(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}function F(e,t){var n,o,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}function J(e,t,n){if(n||2===arguments.length)for(var o,r=0,s=t.length;r<s;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}var j,K=new r("RCMain"),V=null,W=function(){var e,o=Date.now(),r=[n(),t(),process.pid,o,Math.floor(Math.random()*o)].join("__");return e=r,U("md5").update(e).digest("hex")},G=function(e){if(V)return V;var t=o(e,"deviceId");return K.debug("deviceIdPath -> ".concat(t)),N(t)?V=M(t).toString():(V=W(),K.debug("createDeviceId -> ".concat(V)),L(t,V),V)},q=function(){function e(e,t){this._timerId=0,this._heartbeatTimeoutId=0,this._isFirstPing=!0,this._lossCount=0,this._hasPingRes=e,this._reconnect=t}return e.init=function(t,n){return j?(j.stop(),j):j=new e(t,n)},e.prototype.start=function(e){var t=this,n=this,o=function(){var r=t._isFirstPing?0:15e3;n._timerId=setTimeout((function(){n._isFirstPing=!1,K.debug("current lossCount: ".concat(n._lossCount)),n._hasPingRes?(e(),n._hasPingRes=!1,o()):n._lossCount<4?(n._lossCount++,e(),o()):n._reconnect()}),r)};o()},e.prototype.stop=function(){this._lossCount=0,clearTimeout(this._timerId)},e.prototype.setHeartbeatRes=function(e){K.debug("receive ping"),this._hasPingRes=e,this._lossCount=0},e}(),Y=function(){function e(e){this._setTime=15962112e5,this._cppProto=e}return e.prototype._setToProtocol=function(e,t,n,o,r){var s=JSON.stringify(o);K.info("MsgExpansion._setToProtocol ===>",e,t,n,s,r),this._cppProto.setMessageExtension(e,t,n,s,r)},e.prototype.setLocalFromReceiveMsg=function(e){K.info("MsgExpansion.setLocalFromReceiveMsg ===>",e);var t=e.channelId,n=e.conversationType,o=e.targetId,r=e.messageUId,s=e.expansion,i=e.sentTime,a={};for(var c in s)a[c]={v:"",ts:0},a[c].v=s[c],a[c].ts=i;this._setToProtocol(n,o,r,a,t||"")},e.prototype.setLocalFromExtMsg=function(e){K.info("MsgExpansion.setLocalFromExtMsg ===>",e);var t=e.channelId,n=e.conversationType,o=e.targetId;e.messageUId;var r=e.content,s=e.sentTime,i=r,a=i.put,c=this._cppProto.getMessage(i.mid),u=JSON.parse(c).extMsg,p=JSON.parse(u||"{}");if(K.info("MsgExpansion.setLocalFromExtMsg, serverExtObj",a,"localExt",p),a)for(var l in a){var d=p[l];d&&d.ts<s-this._setTime?(d.v=a[l],d.ts=s-this._setTime):(p[l]={v:"",ts:0},p[l].v=a[l],p[l].ts=s-this._setTime)}i.del&&i.del.forEach((function(e){delete p[e]})),this._setToProtocol(n,o,i.mid,p,t||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),n={};for(var o in t)n[o]=t[o].v;return n},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),n=JSON.parse(t||"{}"),o={};for(var r in n)o[r]=n[r].v;return o},e}(),X=null;function z(e,t,n,o){return new Promise((function(r){var s=/^https/.test(e),i={headers:{appId:t},method:"POST"};s&&(i.rejectUnauthorized=o,i.agent=new O(i));var a=(s?x:b)(e,i,(function(e){var t=e.statusCode,n="";e.setEncoding("utf8"),e.on("data",(function(e){n+=e})),e.on("end",(function(){r({status:t||0,data:n})}))}));a.on("error",(function(e){K.error(e),r({status:0})})),a.write(n),a.end()}))}function Q(e,t,n,o,r){return void 0===r&&(r=!0),B(this,void 0,void 0,(function(){var s;return F(this,(function(i){switch(i.label){case 0:return X?[2,X]:(X=function(e,t,n,o,r){return void 0===r&&(r=!0),B(this,void 0,void 0,(function(){var s,i,a,c,u,p,l;return F(this,(function(d){switch(d.label){case 0:s="token=".concat(encodeURIComponent(o),"&v=").concat((f=e,f.match(/\d+(\.\d+){2}/)[0]),"&p=PC&ev=").concat("5.5.5"),i=0,a=t.length,d.label=1;case 1:return i<a?(c="".concat(t[i],"/navi.json?r=").concat(Date.now()),K.info("request navi -> url: ".concat(c,", body: ").concat(s)),[4,z(c,n,s,r)]):[3,4];case 2:if(200!==(u=d.sent()).status)return K.error("request navi failed -> ".concat(c)),u.data&&K.error(u.data),[3,3];K.info("request navi success -> ".concat(c));try{return p=JSON.parse(u.data),l=/^https/.test(c)?"https":"http",p.protocol=l,[2,p]}catch(e){K.error("parse navi err => ".concat(u.data))}d.label=3;case 3:return i+=1,[3,1];case 4:return[2,null]}var f}))}))}(e,t,n,o,r),[4,X]);case 1:return s=i.sent(),X=null,[2,s]}}))}))}var $=function(){function t(e,t,n){void 0===t&&(t=""),void 0===n&&(n=!1);var o=this;this._cppProtocol=e,this._dbpath=t,this._reconnectKickEnable=n,this._currentToken="",this._connectionStatus=s.DISCONNECTED,this._promiseHandler={},this._customMessageType={},this._connectedTime=0,this._currentUserId="",this._inited=!1,this._naviInfo=null,this._version="5.5.5",this._electronLogger={debug:this._superElectronLog.bind(this,"debug",i.DEBUG),info:this._superElectronLog.bind(this,"info",i.INFO),warn:this._superElectronLog.bind(this,"warn",i.WARN),error:this._superElectronLog.bind(this,"error",i.ERROR),fatal:this._superElectronLog.bind(this,"fatal",i.FATAL)},this._logger={debug:this._superLog.bind(this,"debug",i.DEBUG),info:this._superLog.bind(this,"info",i.INFO),warn:this._superLog.bind(this,"warn",i.WARN),error:this._superLog.bind(this,"error",i.ERROR),fatal:this._superLog.bind(this,"fatal",i.FATAL)},this._senders={},this.rtcHeartbeatResolves={},I.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return B(o,void 0,void 0,(function(){var o,r,s,i;return F(this,(function(a){switch(a.label){case 0:if((i=this._electronLogger).debug.apply(i,J(["__RC_CHANNEL_CALL_MAIN_SYNC__",t],n,!1)),"function"!=typeof(o=this[t]))return e.returnValue=c.NOT_SUPPORT,[2];r=c.EXTRA_METHOD_UNDEFINED,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,o.call.apply(o,J([this],n,!1))];case 2:return r=a.sent(),[3,4];case 3:return s=a.sent(),this._electronLogger.error("call main process method `".concat(t,"` failed.")),this._electronLogger.error(s),[3,4];case 4:return e.returnValue=r,[2]}}))}))})),I.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var r=[],s=3;s<arguments.length;s++)r[s-3]=arguments[s];return B(o,void 0,void 0,(function(){var o,s,i,a,u,p=this;return F(this,(function(l){switch(l.label){case 0:if((u=this._electronLogger).debug.apply(u,J(["__RC_CHANNEL_CALL_MAIN__",t,n],r,!1)),"function"!=typeof(o=this[n]))return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,c.NOT_SUPPORT),[2];"sendMessage"===n&&(s=r[3],r[3]=function(t){p._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",s,t)}),i=c.EXTRA_METHOD_UNDEFINED,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,o.call.apply(o,J([this],r,!1))];case 2:return i=l.sent(),[3,4];case 3:return a=l.sent(),this._electronLogger.error("call main process method `".concat(n,"` failed.")),this._electronLogger.error(a),[3,4];case 4:return this._electronLogger.debug("__RC_CHANNEL_RESULT_FROM_MAIN__",t,n,i),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,i),[2]}}))}))})),I.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var n,r=[],s=2;s<arguments.length;s++)r[s-2]=arguments[s];(n=o._electronLogger).debug.apply(n,J(["__RC_CHANNEL_CALL_MAIN__",t],r,!1));var i=o[t];if("function"==typeof i)try{i.call.apply(i,J([o],r,!1))}catch(e){o._electronLogger.error("call main process method `".concat(t,"` failed.")),o._electronLogger.error(e)}else o._electronLogger.error("cannot not found method: ".concat(t))})),I.on("__RC_INNER_COMMAND_INIT__",this._init.bind(this)),this._msgExpansionHandler=new Y(this._cppProtocol)}return t.prototype._callCppProxy=function(e){for(var t,n,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];try{return(t=this._cppProtocol)[e].apply(t,o)}catch(t){(n=this._electronLogger).error.apply(n,J([t,e],o,!1))}},t.prototype._superElectronLog=function(e,t){for(var n,o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];if(null===(n=K[e])||void 0===n||n.call.apply(n,J([K],o,!1)),t!==i.DEBUG){var s=Object.keys(this._senders);if(s.length>0){var a=o.reduce((function(e,t){return e+JSON.stringify(t)}),"");this._senders[s[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,a,"RCMain")}}},t.prototype._superLog=function(e,t,n,o,r){var s;if(null===(s=a[e])||void 0===s||s.call(a,n,o,r),t!==i.DEBUG){var c=Object.keys(this._senders);c.length>0&&this._senders[c[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,o,n,null==r?void 0:r.logSource)}},t.prototype.getCppProto=function(){return this._cppProtocol},t.prototype.callExtra=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];(t=this._electronLogger).info.apply(t,J(["callExtra -> ".concat(e)],n,!1));var r=this[e];if(!r)return this._electronLogger.warn("ExtraHandler.".concat(e," is undefined")),Promise.resolve({code:c.EXTRA_METHOD_UNDEFINED});try{return r.call.apply(r,J([this],n,!1))}catch(e){this._electronLogger.error(e)}return Promise.resolve({code:c.MAIN_PROCESS_ERROR})},t.prototype.getConversationsByPage=function(e,t,n,o){var r,s=this,i=this._callCppProxy("getConversationListByPage",e,t,n,o||"");try{r=JSON.parse(i).list.map((function(e){return s._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:c.MAIN_PROCESS_ERROR})}return Promise.resolve({code:c.SUCCESS,data:r})},t.prototype.getConversationListWithAllChannel=function(){var e,t=this,n=[u.PRIVATE,u.GROUP],o=this._callCppProxy("getConversationListWithAllChannel",n);try{e=JSON.parse(o).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:c.MAIN_PROCESS_ERROR})}return Promise.resolve({code:c.SUCCESS,data:e})},t.prototype.getConversationListWithAllChannelByPage=function(e,t){var n,o=this,r=[u.PRIVATE,u.GROUP],s=this._callCppProxy("getConversationListWithAllChannelByPage",r,e,t);try{n=JSON.parse(s).list.map((function(e){return o._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:c.MAIN_PROCESS_ERROR})}return Promise.resolve({code:c.SUCCESS,data:n})},t.prototype.getHistoryMessagesByObjectNames=function(e,t,n,o,r,s,i){var a=0===s,u=o+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,n,u,r,a,i||""),l=[];try{var d=JSON.parse(p).list;d.reverse();for(var f=0;f<d.length;f++){var g=this._buildMessage(d[f].obj);l[f]=g}}catch(e){return this._electronLogger.error(e),Promise.resolve({code:c.MAIN_PROCESS_ERROR})}return Promise.resolve({code:c.SUCCESS,data:{list:u===l.length?l.slice(1,u):l,hasMore:o<l.length}})},t.prototype.updateMessageReceiptStatus=function(e,t,n,o){void 0===o&&(o=""),this._electronLogger.info("updateMessageReceiptStatus ->",e,t,n,o);var r=this._callCppProxy("updateMessageReceiptStatus",e,t,n,o);return Promise.resolve({code:c.SUCCESS,data:r})},t.prototype.requestNaviInfo=function(e,t,n,o){return B(this,void 0,void 0,(function(){return F(this,(function(r){return[2,Q(this._initOptions.apiVersion,e,t,n,o)]}))}))},t.prototype.updateNaviInfo=function(e){this._naviInfo=e},t.prototype.getNaviInfoFromCache=function(){return this._naviInfo?k({},this._naviInfo):null},t.prototype.getConnectedTime=function(){return this._connectedTime},t.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},t.prototype.getCurrentUserId=function(){var e;return(null===(e=this._naviInfo)||void 0===e?void 0:e.userId)||""},t.prototype._send2Renderer=function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,J([t],n,!1))},t.prototype._send2AllRenderer=function(e,t,n){var o=this;void 0===n&&(n=[]),Object.keys(this._senders).forEach((function(r){var s=o._senders[r];n.includes(s)||o._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},t.prototype._init=function(e,t){var n=this,r=e.sender,s=r.id;if(this._senders[s]||(this._senders[s]=r,r.once("destroyed",(function(){delete n._senders[s]}))),!this._inited){this._inited=!0,this._initOptions=t,this._electronLogger.info("init ->",t);var i=this._dbpath||o(R.getPath("userData"));this._logger.info(p.P_INIT_O,{"proto-commitId":this._cppProtocol.getNodeVersion(),appkey:t.appkey,dbpath:i}),this._callCppProxy("initWithAppkey",t.appkey,i),this._electronLogger.warn("cppProto version ->",this._cppProtocol.getNodeVersion()),this._registerMsgTypes();var a=G(i);this._electronLogger.info("deviceId -> ".concat(a)),this._callCppProxy("setDeviceId",a),this._setConnectionStatusListener(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener()}},t.prototype._registerMsgTypes=function(){for(var e in l["RC:RcCmd"]={isCounted:!1,isPersited:!1},l){var t=l[e],n=t.isCounted,o=0;t.isPersited&&(o|=1),n&&(o|=2),"RC:TypSts"===e&&(o=16),this._electronLogger.info("_registerMsgTypes ====>",e,o),this._callCppProxy("registerMessageType",e,o)}},t.prototype._buildMessage=function(e,t){void 0===t&&(t={});var n=t.isOffLineMessage,o=t.buildFrom,r=JSON.parse(e);this._electronLogger.debug("_buildMessage:",r);var s=r.channelId,i=r.conversationType,a=r.targetId,c=r.senderUserId,u=r.content,p=r.objectName,_=r.messageUid,C=r.direction,v=r.status;r.source;var S=r.messageId,y=r.sentTime,m=r.readReceiptRequest,E=r.supportExt;r.extMsg;var P,T=r.pushContent,I=r.pushTitle,R=r.pushId,N=r.pushConfig,M=r.templateId,L=r.disableTitle,U=r.forcePushDetail;if(d(u))P=u;else try{P=u?JSON.parse(u):u}catch(e){K.warn("cpp engine build messaga error:",e),P=u}var b={isCounted:!1,isPersited:!1};p in l?b=l[p]:p in this._customMessageType&&(b=this._customMessageType[p]);var O=null;E&&(O=this._msgExpansionHandler.parseReceiveExpansion(r),"conversation"!==o&&"history"!==o||(O=this._msgExpansionHandler.parseConverOrHisExpansion(r)));var x=f(n)?y<this._connectedTime:n,w={};N&&(w=g(N,R));var A=k(k({},w),{pushTitle:I,pushContent:T,pushData:T,disablePushTitle:L,forceShowDetailContent:U,templateId:M}),D={channelId:s,conversationType:i,targetId:a,senderUserId:c,content:P||{},messageType:p,messageUId:_,messageDirection:C,isOffLineMessage:x,sentTime:y,receivedTime:0,isPersited:b.isPersited,isCounted:b.isCounted,isMentioned:!1,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:E,expansion:E?O:null,receivedStatus:v,messageId:S,pushConfig:A};if(C===h.RECEIVE?D.receivedStatus=v:C===h.SEND&&(D.sentStatus=v),m){var H=JSON.parse(m),B=H.hasRespond,F=H.readerInfo,J={hasRespond:B,readCount:H.readCount,totalCount:H.totalCount},j=[];if(F)for(var V in F)j.push({userId:V,readTime:F[V]});J.readerList=j,D.readReceiptInfo=J}return D},t.prototype._updateReadReceiptInfo=function(e,t){var n=this._callCppProxy("getMessage",e),o=JSON.parse(n),r=o.readReceiptRequest?JSON.parse(o.readReceiptRequest):{},s=k(k({},r),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},t.prototype._buildConversation=function(e){var t=JSON.parse(e);this._electronLogger.debug("_buildConversation",t);var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.unreadCount,i=t.lastestMsg,a=t.isTop,c=t.isBlocked,u=t.matchCount,p=c?_.OPEN:_.CLOSE;return{channelId:n,conversationType:o,targetId:r,unreadMessageCount:s,latestMessage:-1===JSON.parse(i).messageId?null:this._buildMessage(i),hasMentioned:!1,mentionedInfo:null,notificationStatus:p,isTop:a,lastUnreadTime:0,matchCount:u}},t.prototype._sendConnectionStatus2Renderer=function(e){this._send2AllRenderer("status",e)},t.prototype._convertResultList=function(e,t){var n=JSON.parse(e).list;return n=n.map((function(e){var n=JSON.parse(e.obj);return t?t(n):n}))},t.prototype._connectResolve=function(e){this._promiseHandler.connect&&this._promiseHandler.connect.length>0&&(this._promiseHandler.connect.forEach((function(t){t.resolve(e)})),delete this._promiseHandler.connect)},t.prototype._setConnectionStatusListener=function(){var e=this;this._cppProtocol.setConnectionStatusListener((function(t){var n,o;switch(e._electronLogger.warn("protocol connection status changed:",t),t){case 10:o=s.CONNECTING;break;case 31004:return void setTimeout((function(){e._connectResolve(c.RC_CONN_USER_OR_PASSWD_ERROR)}));case 12:o=s.DISCONNECTED;break;case 13:o=s.BLOCKED,setTimeout((function(){e._connectResolve(c.RC_CONN_USER_BLOCKED)}));break;case 31023:o=s.FORBID_RECONNECT_BY_OTHER_SAME_CLIENT,setTimeout((function(){e._connectResolve(c.RC_DISCONN_SAME_CLIENT_ON_LINE)}));break;case 1:case 9:case 11:case 31011:case 3e4:case 30002:o=s.NETWORK_UNAVAILABLE;break;case 30010:o=s.NETWORK_UNAVAILABLE,setTimeout((function(){e._connectionStatus===s.NETWORK_UNAVAILABLE&&e._doConnect()}),5e3);break;case 0:case 33005:o=s.CONNECTED,e._connectedTime=Date.now()-e._cppProtocol.getDeltaTime(),setTimeout((function(){e._connectResolve(c.SUCCESS),e._heartbeat=q.init(!0,e._handleHeartTimeout.bind(e)),e._heartbeat.start(e._sendHeartbeat.bind(e))}));break;case s.KICKED_OFFLINE_BY_OTHER_CLIENT:o=s.KICKED_OFFLINE_BY_OTHER_CLIENT;break;case 30004:return;case 8:case 31006:case 32061:case 32012:o=s.REDIRECT;break;default:o=t}o!==s.CONNECTED&&(null===(n=e._heartbeat)||void 0===n||n.stop()),e._connectionStatus=o,e._logger.info(p.P_CONNECT_S,{status:t}),e._sendConnectionStatus2Renderer(o)}),this._dbOpenCallback,(function(){var t;null===(t=e._heartbeat)||void 0===t||t.setHeartbeatRes(!0)}))},t.prototype._handleHeartTimeout=function(){var e,t=this;K.warn("network unavailable! try to reconnect!"),this._sendConnectionStatus2Renderer(s.NETWORK_UNAVAILABLE),null===(e=this._heartbeat)||void 0===e||e.stop(),setTimeout((function(){return t._doConnect()}),5e3)},t.prototype._dbOpenCallback=function(e){K.info("Sqlite DB Open -> ".concat(e))},t.prototype._sendHeartbeat=function(){K.debug("send ping"),this._cppProtocol.sendHeartbeat()},t.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,n,o,r){var s=e._buildMessage(t,{isOffLineMessage:o});if(s.messageType===C.GROUP_READ_RECEIPT_REQUEST){var i=s.content,a=i.msgId,c=i.rrn,u=i.tmn;e._updateReadReceiptInfo(a,{readCount:c,totalCount:u})}if("RC:MsgExMsg"===s.messageType)return e._msgExpansionHandler.setLocalFromExtMsg(s),void e._sendMessageExpansion(s);if(s.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(s),s.messageType===C.SYNC_READ_STATUS){if(s.senderUserId!==e._currentUserId)return;e._callCppProxy("clearUnreadCountByTimestamp",s.conversationType,s.targetId,s.content.lastMessageSendTime,s.channelId||"")}var p=!0;if(0!==n||r||(p=!1),s.messageType!==C.LOG_COMMAND||"rongcloudsystem"!==s.senderUserId){var l=s.conversationType,d=s.targetId;s.messageType===C.RECALL&&s.senderUserId===e._currentUserId&&(l=s.content.conversationType||l,d=s.content.targetId||d),e._sendMessageNotification(Object.assign(s,{hasMoreMsg:p,conversationType:l,targetId:d}))}else{var f=Object.keys(e._senders).map((function(t){return e._senders[t]}));f.length>0&&e._sendMessageNotification(Object.assign(s,{hasMoreMsg:p}),f.slice(1))}}),(function(){e._sendPullOfflineFinished()}))},t.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var n=e.channelId,o=e.content,r=o.put,s=o.del,i=o.mid,a={};r&&(a.updatedExpansion={channelId:n,messageUId:i,expansion:r}),s&&(a.deletedExpansion={channelId:n,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},t.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},t.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},t.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var n=JSON.parse(t).list,o=[];n.forEach((function(e){var t=JSON.parse(e.obj),n=t.conversationType,r=t.targetId,s=t.status,i=t.channelId,a={notificationStatus:2,isTop:!1};s.forEach((function(e){var t=JSON.parse(e.item);1===t.type?a.notificationStatus=1===Number(t.value)?_.OPEN:_.CLOSE:a.isTop=1===Number(t.value)})),o.push({channelId:i,conversationType:n,targetId:r,updatedItems:{notificationStatus:{val:a.notificationStatus,time:0},isTop:{val:a.isTop,time:0}}})})),e._send2AllRenderer("conversation",o)}),(function(t){e._electronLogger.info("会话标签状态变更",t),e._send2AllRenderer("conversationTag",t)}))},t.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._electronLogger.info("标签变更",t),e._send2AllRenderer("tag",t),e._getRTCProfile()}))},t.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e&&this._naviInfo&&this._naviInfo.voipCallInfo!==e){var t=k(k({},this._naviInfo),{voipCallInfo:e});this._naviInfo=t,this._send2AllRenderer("onNaviDataChange",t)}},t.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var n=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",n)}))},t.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,n){e._send2AllRenderer("chatroom",{chatroomDestroyed:t})}))},t.prototype._clearListener=function(){this._cppProtocol.setOnReceiveMessageListener(),this._cppProtocol.setConnectionStatusListener(),this._cppProtocol.setOnReceiveStatusListener(),this._cppProtocol.setUserProfileListener()},t.prototype.registerMessageType=function(e,t,n,o){var r=0;t&&(r|=1),n&&(r|=2),this._customMessageType[e]={isCounted:n,isPersited:t},this._logger.info(p.P_REGTYP_O,{messageType:e,isCounted:n,searchProps:o,isPersited:t}),this._callCppProxy("registerMessageType",e,r,o)},t.prototype.connect=function(e,t,n,o){var r=this;return this._electronLogger.info("connect ->",e,t,n),this._logger.info(p.P_CONNECT_O,{token:e,reconnectKickEnable:n,version:this._version},{traceId:o}),this._currentToken===e&&this._connectionStatus===s.CONNECTED?(this._sendConnectionStatus2Renderer(this._connectionStatus),Promise.resolve(c.SUCCESS)):(this._currentToken=e,this._naviInfo=t,this._currentUserId=t.userId,this._promiseHandler.connect||this._doConnect(n),new Promise((function(e,t){r._promiseHandler.connect?r._promiseHandler.connect.push({resolve:e,reject:t}):r._promiseHandler.connect=[{resolve:e,reject:t}]})))},t.prototype._doConnect=function(e){var t=f(e)?!!this._reconnectKickEnable:!!e;this._callCppProxy("connectWithToken",this._currentToken,this._initOptions.apiVersion,JSON.stringify(this._naviInfo),t)},t.prototype.reportSDKInfo=function(e){var t,n;null===(n=(t=this._cppProtocol).uploadSDKVersion)||void 0===n||n.call(t,JSON.stringify(e)),this._electronLogger.info(e)},t.prototype.disconnect=function(){var e;this._cppProtocol.disconnect(!0),null===(e=this._heartbeat)||void 0===e||e.stop(),this._connectResolve(c.TIMEOUT)},t.prototype.logout=function(){this.disconnect()},t.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,n){t({userId:e,status:n})}));var n=e.userIds||[];n.length&&this.subscribeUserStatus(n)},t.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("subscribeUserStatus",e,(function(){n(c.SUCCESS)}),n)}))},t.prototype.setUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("setUserStatus",e,(function(){n(c.SUCCESS)}),n)}))},t.prototype.getUserStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getUserStatus",e,(function(e){n({code:c.SUCCESS,data:{status:e}})}),(function(e){n({code:e})}))}))},t.prototype.sendMessage=function(e,t,n,o,r){var s=this,i=n.messageType,a=n.content,l=n.pushContent,d=n.pushData,f=n.directionalUserIdList,g=n.disableNotification,h=n.canIncludeExpansion,_=n.expansion,y=n.isVoipPush,m=n.pushConfig,E=n.channelId,P=n.isMentioned,T=n.mentionedType,I=n.mentionedUserIdList,R=n.messageId,N=m||{},M=N.iOSConfig,L=N.androidConfig,U=N.pushTitle,b=N.pushContent,O=N.pushData,x=N.disablePushTitle,w=N.forceShowDetailContent,A=N.templateId,D=v(M,L);return new Promise((function(n){l=b||l||"",d=O||d||"",g=g||!1,y=y||!1,U=U||"",b=b||"",O=O||"",x=x||!1,w=w||!1,h=h||!1;var v=(null==L?void 0:L.notificationId)||"";if(f=f||[],R=R||0,E=E||"",e===u.GROUP&&P&&a&&(a.mentionedInfo={userIdList:I,type:T||S.ALL}),e===u.GROUP&&i===C.READ_RECEIPT_RESPONSE&&a.receiptMessageDic)for(var m in a.receiptMessageDic)f.push(m);var N={};for(var m in _)N[m]={v:""},N[m].v=_[m];var M=A||"";R&&s._callCppProxy("setMessageContent",R,JSON.stringify(a),i),s._logger.info(p.P_SEND_MSG_T,{messageType:i,conversationType:e,targetId:t,channelId:E},{traceId:r});var H=s._callCppProxy("sendMessage",(function(e,t){var o=s._buildMessage(e,{isOffLineMessage:!1});return s._logger.info(p.P_SEND_MSG_R,{code:t,messageUId:o.messageUId,messageId:o.messageId},{traceId:r}),t===c.SENSITIVE_REPLACE?n({code:t}):("RC:MsgExMsg"===o.messageType&&s._msgExpansionHandler.setLocalFromExtMsg(o),o.canIncludeExpansion&&s._msgExpansionHandler.setLocalFromReceiveMsg(o),n({code:c.SUCCESS,data:o}))}),(function(e,t){var o=s._buildMessage(e,{isOffLineMessage:!1});return s._logger.warn(p.P_SEND_MSG_R,{code:t,messageUId:o.messageUId,messageId:o.messageId},{traceId:r}),o.sentTime=Date.now()-s._cppProtocol.getDeltaTime(),n({code:t,data:o})}),e,t,i,JSON.stringify(a),f,g,x,w,l,d,v,U,D,M,h,JSON.stringify(N),y,E,R),k=JSON.parse(H);null==o||o(k.messageId)}))},t.prototype.recallMsg=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){var u,p=r.user,l=r.pushContent,d=r.channelId,f=r.extra,g=r.pushConfig,_=r.disableNotification,S=r.isDelete,m={conversationType:e,targetId:t,messageUId:n,sentTime:o,user:p,extra:f,channelId:d,isDelete:S||!1};p&&(m.user=p),f&&(m.extra=f);var E={conversationType:e,targetId:t,senderUserId:s._currentUserId,content:m,objectName:C.RECALL,messageUid:n,direction:h.SEND,status:y.UNREAD,sentTime:o,channelId:d},P=s._buildMessage(JSON.stringify(E),{isOffLineMessage:!1});s._callCppProxy("recallMessage",(function(){i({code:c.SUCCESS,data:P})}),(function(e){i({code:e})}),C.RECALL,JSON.stringify(m),_||!1,(null==g?void 0:g.disablePushTitle)||!1,(null==g?void 0:g.forceShowDetailContent)||!1,l||"",(null==g?void 0:g.pushData)||"",(null===(u=null==g?void 0:g.androidConfig)||void 0===u?void 0:u.notificationId)||"",(null==g?void 0:g.pushTitle)||"",v(null==g?void 0:g.iOSConfig,null==g?void 0:g.androidConfig),(null==g?void 0:g.templateId)||"",d)}))},t.prototype.getHistoryMessage=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(u,p){n=n||0;var l=0===r,d=o+1,f=a._callCppProxy("getHistoryMessages",e,t,n,d,i,l,s),g=JSON.parse(f).list,h=[];g.reverse();for(var _=0;_<g.length;_++){var C=a._buildMessage(g[_].obj);h[_]=C}u({code:c.SUCCESS,data:{list:d===h.length?h.slice(1,d):h,hasMore:o<h.length}})}))},t.prototype.getRemoteHistoryMessages=function(e,t,n,o,r,s){var i=this;return new Promise((function(a,u){n=n||0;i._callCppProxy("getRemoteHistoryMessages",e,t,n,o,(function(e,t){var n=JSON.parse(e).list,o=[];n.reverse();for(var r=0;r<n.length;r++){var s=i._buildMessage(n[r].obj);o[r]=s}a({code:c.SUCCESS,data:{list:o,hasMore:!!t}})}),(function(e){a({code:e})}),r,!0,s)}))},t.prototype.deleteRemoteMessage=function(e,t,n,o){var r=this;return new Promise((function(s,i){var a=JSON.stringify(n);r._callCppProxy("deleteRemoteHistoryMessages",e,t,a,!1,o,(function(){s(c.SUCCESS)}),s)}))},t.prototype.deleteRemoteMessageByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearRemoteHistoryMessages",e,t,n,(function(){s(c.SUCCESS)}),(function(e){s(e)}),o)}))},t.prototype.clearMessages=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("clearMessages",e,t,n),r(c.SUCCESS)}))},t.prototype.getConversationList=function(e,t,n,o,r){var s=this;return void 0===r&&(r=""),new Promise((function(e,t){for(var n=s._callCppProxy("getConversationList",[1,3,6,7],r),o=JSON.parse(n).list,i=[],a=0;a<o.length;a++)i.push(s._buildConversation(o[a].obj));e({code:c.SUCCESS,data:i})}))},t.prototype.getConversation=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversation",e,t,n);if(i)r({code:c.SUCCESS,data:o._buildConversation(i)});else{var a=o._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,n),u=void 0;try{u=JSON.parse(a).list}catch(e){o._electronLogger.warn("json parse cppMessagaes error",e),u=[]}var p=null;u.length>0&&(p=o._buildMessage(u[0].obj));var l=o._callCppProxy("getConversationNotificationStatus",e,t,n),d=o._callCppProxy("getConversationTopStatus",e,t,n);r({code:c.SUCCESS,data:{conversationType:e,targetId:t,channelId:n,unreadMessageCount:0,latestMessage:p,notificationStatus:l?_.OPEN:_.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},t.prototype.removeConversation=function(e,t,n){var o=this._callCppProxy("removeConversation",e,t,n);return this._electronLogger.info("removeConversation result -> ".concat(o)),Promise.resolve(o?c.SUCCESS:c.UNKNOWN)},t.prototype.clearConversations=function(e,t){var n=this;return new Promise((function(o,r){var s=[];s=m(e)?e:[u.PRIVATE,u.GROUP,u.SYSTEM,u.PUBLIC_SERVICE],n._callCppProxy("clearConversations",s,t),o(c.SUCCESS)}))},t.prototype.getAllConversationUnreadCount=function(e,t,n){var o=this._callCppProxy("getTotalUnreadCount",t,n,e);return Promise.resolve({code:c.SUCCESS,data:o})},t.prototype.getConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r){var s=o._callCppProxy("getUnreadCount",e,t,n);r({code:c.SUCCESS,data:s})}))},t.prototype.clearConversationUnreadCount=function(e,t,n){var o=this;return void 0===n&&(n=""),new Promise((function(r,s){o._callCppProxy("clearUnreadCount",e,t,n),r(c.SUCCESS)}))},t.prototype.clearUnreadCountByTimestamp=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("clearUnreadCountByTimestamp",e,t,n,o),s(c.SUCCESS)}))},t.prototype.getFirstUnreadMessage=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getTheFirstUnreadMessage",e,t,n),a=o._buildMessage(i);r({code:c.SUCCESS,data:-1!==a.messageId?a:null})}))},t.prototype.setConversationToTop=function(e,t,n,o){var r=this;return void 0===o&&(o=""),new Promise((function(s,i){r._electronLogger.info("setConversationToTop",e,t,n,o,true),r._callCppProxy("setConversationToTop",e,t,n,o,true),s(c.SUCCESS)}))},t.prototype.setConversationHidden=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationHidden",e,t,n,o),s(c.SUCCESS)}))},t.prototype.setConversationNotificationStatus=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._electronLogger.info("setConversationNotificationStatus",e,t,n,o),r._callCppProxy("setConversationNotificationStatus",e,t,n,(function(){s(c.SUCCESS)}),s,o)}))},t.prototype.setConversationStatus=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._electronLogger.info("setConversationStatus",e,t,n,o,r,true),s._callCppProxy("setConversationStatus",e,t,n,o,(function(){i(c.SUCCESS)}),i,r,true)}))},t.prototype.getConversationNotificationStatus=function(e,t,n){var o=this;return new Promise((function(r,s){var i=o._callCppProxy("getConversationNotificationStatus",e,t,n);r({code:c.SUCCESS,data:i?_.OPEN:_.CLOSE})}))},t.prototype.searchConversationByContent=function(e,t,n,o){var r=this;return new Promise((function(s,i){o=o||[1,3,6,7];for(var a=r._callCppProxy("searchConversationByContent",o,e,t,n),u=JSON.parse(a).list,p=[],l=0;l<u.length;l++)p[l]=r._buildConversation(u[l].obj);s({code:c.SUCCESS,data:p})}))},t.prototype.searchConversationByContentWithAllChannel=function(e,t,n){var o=this;return new Promise((function(r,s){n=n||[1,3,6,7];for(var i=o._callCppProxy("searchConversationByContentWithAllChannel",n,e,t),a=JSON.parse(i).list,u=[],p=0;p<a.length;p++)u[p]=o._buildConversation(a[p].obj);r({code:c.SUCCESS,data:u})}))},t.prototype.searchMessageByContent=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(s,u){a._callCppProxy("searchMessageByContent",e,t,n,o,r,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],o=[],r=0;r<n.length;r++)o[r]=a._buildMessage(n[r].obj);s({code:c.SUCCESS,data:{messages:o,count:t}})}),i)}))},t.prototype.searchMessageByContentWithAllChannel=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("searchMessageByContentWithAllChannel",e,t,n,o,r,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],o=[],r=0;r<n.length;r++)o[r]=s._buildMessage(n[r].obj);i({code:c.SUCCESS,data:{messages:o,count:t}})}))}))},t.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,n,o,r,s,i){var a=this;return new Promise((function(u,p){a._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,n,o,r,s,i,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],o=0;o<t.length;o++)n[o]=a._buildMessage(t[o].obj);u({code:c.SUCCESS,data:{messages:n}})}))}))},t.prototype.getUnreadMentionedMessages=function(e,t,n){for(var o=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,n)).list,r=0;r<o.length;r++)o[r]=this._buildMessage(o[r].obj);return o},t.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addToBlacklist",e,(function(){n(c.SUCCESS)}),n)}))},t.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("removeFromBlacklist",e,(function(){n(c.SUCCESS)}),n)}))},t.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,n){e._callCppProxy("getBlacklist",(function(e){t({code:c.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},t.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getBlacklistStatus",e,(function(e){n({code:c.SUCCESS,data:e})}),(function(e){n({code:e})}))}))},t.prototype.insertMessage=function(e,t,n){var o=this,r=n.content,s=n.senderUserId,i=n.messageType,a=n.messageDirection,u=n.readStatus,p=n.sentStatus,l=n.sentTime,d=n.searchContent,f=n.isUnread,g=n.messageUId,h=n.disableNotification,_=n.canIncludeExpansion,C=n.expansionMsg,v=n.channelId;return r=JSON.stringify(r),new Promise((function(n,S){var y=f?0:1,m=o._callCppProxy("insertMessage",e,t,s,i,r,(function(){}),(function(e){n({code:e})}),a,u,p,l,d,y,g,h,_,C,v);o._electronLogger.info("after insert msg",m);var E=o._buildMessage(m,{isOffLineMessage:!1});E.messageUId=g,E.sentTime=l,n({code:-1===E.messageId?c.MSG_INSERT_ERROR:c.SUCCESS,data:E})}))},t.prototype.deleteMessages=function(e){var t=this;return new Promise((function(n,o){t._logger.debug(p.P_DELETE_MSG_S,{messageIds:e}),t._callCppProxy("deleteMessages",e),n(c.SUCCESS)}))},t.prototype.deleteMessagesByTimestamp=function(e,t,n,o,r){var s=this;return new Promise((function(i,a){s._callCppProxy("deleteMessagesByTimestamp",e,t,n,o,r),i(c.SUCCESS)}))},t.prototype.getMessage=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getMessage",e);t._electronLogger.info("getMessage ===>",r);var s=t._buildMessage(r,{isOffLineMessage:!1});n({code:c.SUCCESS,data:s})}))},t.prototype.setMessageContent=function(e,t,n){var o=this;return new Promise((function(r,s){t=JSON.stringify(t),o._callCppProxy("setMessageContent",e,t,n),r(c.SUCCESS)}))},t.prototype.setMessageSearchField=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setMessageSearchField",e,t,n),r(c.SUCCESS)}))},t.prototype.setMessageSentStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageSentStatus",e,t),o(c.SUCCESS)}))},t.prototype.setMessageReceivedStatus=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("setMessageReceivedStatus",e,t),o(c.SUCCESS)}))},t.prototype.saveConversationMessageDraft=function(e,t,n,o){throw new Error("Method not implemented.")},t.prototype.getConversationMessageDraft=function(e,t,n){throw new Error("Method not implemented.")},t.prototype.clearConversationMessageDraft=function(e,t,n){throw new Error("Method not implemented.")},t.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},t.prototype.batchSetConversationStatus=function(e){var t=e[0],n=t.conversationType,o=t.targetId,r=t.isTop,s=t.notificationStatus,i=t.channelId;if(void 0!==r&&void 0===s)return this.setConversationToTop(n,o,r,i);if(void 0!==s&&void 0===r){var a=s===_.OPEN;return this.setConversationNotificationStatus(n,o,a,i)}var c=s===_.OPEN;return this.setConversationStatus(n,o,c,r,i)},t.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},t.prototype.sendReadReceiptMessage=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("sendReadReceipt",e,n||"",t,(function(){t.forEach((function(e){o._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(o._callCppProxy("getMessage",e)).messageId;o.setMessageReceivedStatus(t,1)}catch(t){o._electronLogger.warn("format message error, messageUId: ".concat(e))}})),r({code:c.SUCCESS})}),(function(e){r({code:e})}))}))},t.prototype.getMessageReader=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getMessageReader",e,n,t,(function(e,n){o._electronLogger.info("getMessageReader -> ",e,n);var s=[],i={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),n=t.id,o=t.time;s.push({userId:n,readTime:o}),i[n]=o}));var a={readerInfo:i,readCount:s.length,totalCount:n};o._updateReadReceiptInfo(t,a),r({code:c.SUCCESS,data:{list:s,totalMemberCount:n}})}),(function(e){r({code:e})}))}))},t.prototype.joinChatroom=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("clearMessages",u.CHATROOM,e,""),n._callCppProxy("joinChatRoom",e,t,(function(){o(c.SUCCESS)}),o)}))},t.prototype.joinExistChatroom=function(e,t){throw new Error("Method not implemented.")},t.prototype.quitChatroom=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("quitChatRoom",e,(function(){n(c.SUCCESS)}),n)}))},t.prototype.getChatroomInfo=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("getChatroomInfo",e,t,n,(function(e,t){var n=e?JSON.parse(e).list:[],o=[];if(n.length>0)for(var s=0;s<n.length;s++)o.push(JSON.parse(n[s].obj));r({code:c.SUCCESS,data:{userInfos:o,userCount:t}})}),(function(e){r({code:e})}))}))},t.prototype.getChatroomHistoryMessages=function(e,t,n,o){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomHistoryMessage",e,t,n,o,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var n=t.list;if(n&&n.length)try{t.list=n.map((function(e){return r._buildMessage(e.obj)}))}catch(e){t.list=[]}s({code:c.SUCCESS,data:t})}),(function(e){s({code:e})}),"")}))},t.prototype.setChatroomEntry=function(e,t){var n=this;return new Promise((function(o,r){var s='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');n._callCppProxy("setChatroomKV",e,s,!!t.isAutoDelete,!!t.isOverwrite,(function(){o(c.SUCCESS)}),(function(e){o(e)}))}))},t.prototype.setChatroomEntries=function(e,t){var n=this;return new Promise((function(o){n._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){o({code:c.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.setChatroomEntry(e,t)},t.prototype.removeChatroomEntry=function(e,t){var n=this,o=[t.key];return new Promise((function(r,s){n._callCppProxy("deleteChatroomKV",e,o,!!t.isOverwrite,(function(){r(c.SUCCESS)}),(function(e){r(e)}))}))},t.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.removeChatroomEntry(e,t)},t.prototype.removeChatroomEntries=function(e,t){var n=this;return new Promise((function(o){var r=t.entries.map((function(e){return e.key}));n._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){o({code:c.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.getChatroomEntry=function(e,t){return B(this,void 0,void 0,(function(){var n;return F(this,(function(o){switch(o.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(n=o.sent()).code===c.SUCCESS?[2,{code:c.SUCCESS,data:n.data?n.data[t]:null}]:[2,{code:n.code}]}}))}))},t.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}n({code:c.SUCCESS,data:t})}),(function(e){n({code:e})}))}))},t.prototype.getFileToken=function(e,t,n,o){var r=this;return n=n||"",o=o||"",new Promise((function(s){var i;i=o&&"uploads"!==o?t||"":E(e,t),r._callCppProxy("getUploadToken",e,i,n,o,(function(e,t,n,o,r,a,u,p,l,d,f,g,h,_,C,v,S,y){s({code:c.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:n,path:o,osskeyId:r,ossPolicy:a,ossSign:u,ossBucketName:p,fileName:i,s3Credential:l,s3Algorithm:d,s3Date:f,s3Policy:g,s3Signature:h,s3BucketName:_,stcAuthorization:C,stcContentSha256:v,stcDate:S,stcBucketName:y}})}),(function(e){s({code:e})}))}))},t.prototype.getFileUrl=function(e,t,n,o){var r=this;return new Promise((function(s){r._callCppProxy("getDownloadUrl",e,n,o,t-1,(function(e){s({code:c.SUCCESS,data:{downloadUrl:e}})}),(function(e){s({code:e})}))}))},t.prototype.clearData=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("clearData");t({code:c.SUCCESS,data:o})}))},t.prototype.getDeviceId=function(){var e=this._dbpath||o(R.getPath("userData"));return G(e)},t.prototype.getVoIPKey=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("getVoIPKey",e,t,"",(function(e){o({code:c.SUCCESS,data:e})}),(function(e){o({code:e})}))}))},t.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(n,o){var r=e.chatRoomId,s=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",r,s,(function(){n(c.SUCCESS)}),(function(e){n(e)}))}))},t.prototype.rtcSignaling=function(e,t,n,o){var r=this,s=Array.prototype.slice.call(new Uint8Array(o));return new Promise((function(o){r._callCppProxy("rtcSignaling",e,t,n,s,(function(e){var t=new Uint8Array(e).buffer;o({code:c.SUCCESS,buffer:t})}),(function(e){o({code:e})}))}))},t.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,n){var o=e.rtcHeartbeatResolves[t];if(o){var r=o.find((function(e){return""===e.seqId}));r&&(r.seqId=n)}}),(function(t,n,o){var r=e.rtcHeartbeatResolves[t];if(r){var s=r.findIndex((function(e){return e.seqId===o}));-1!==s&&r.splice(s,1)[0].resolve(n)}}))},t.prototype.rtcPing=function(e,t,n){var o=this;return new Promise((function(t){var n={resolve:t,seqId:""},r=o.rtcHeartbeatResolves[e];r?r.push(n):o.rtcHeartbeatResolves[e]=[n],o._callCppProxy("sendRTCHeartbeat",[e])}))},t.prototype.createTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){n({code:c.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.removeTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("deleteTag",e,(function(){n({code:c.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.updateTag=function(e){var t=this;return new Promise((function(n,o){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){n({code:c.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getTagList=function(){var e=this;return new Promise((function(t,n){var o=e._callCppProxy("getTags");e._electronLogger.info("getTagList -> ",o);var r=e._convertResultList(o,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:c.SUCCESS,data:r})}))},t.prototype.addTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));n._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){o({code:c.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.removeTagForConversations=function(e,t){var n=this;return new Promise((function(o,r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),n._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){o({code:c.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.removeTagsForConversation=function(e,t){var n=this;return new Promise((function(o,r){n._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){o({code:c.SUCCESS})}),(function(e){o({code:e})}))}))},t.prototype.getConversationListByTag=function(e,t,n,o){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversationsForTagByPage",e,t,n||20,o||"");r._electronLogger.info("getConversationListByTag -> ",a);var u=r._convertResultList(a,(function(e){return k(k({},r._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));s({code:c.SUCCESS,data:u})}))},t.prototype.getUnreadCountByTag=function(e,t){var n=this;return new Promise((function(o,r){var s=n._callCppProxy("getConversationUnreadCountForTag",e,t);n._electronLogger.info("getUnreadCountByTag -> ",s),o({code:c.SUCCESS,data:s})}))},t.prototype.setConversationStatusInTag=function(e,t,n){var o=this;return new Promise((function(r,s){o._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",n.isTop||!1,(function(){r({code:c.SUCCESS})}),(function(e){r({code:e})}))}))},t.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(n,o){var r=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||"");t._electronLogger.info("getTagsForConversation -> ",r);var s=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));n({code:c.SUCCESS,data:s})}))},t.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getTopConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},t.prototype.getAllUnreadMentionedCount=function(){throw new Error("Method not implemented.")},t.prototype.getOSInfo=function(){return B(this,void 0,void 0,(function(){var t;return F(this,(function(n){return t={arch:e.arch(),platform:e.platform(),type:e.type(),version:e.version(),release:e.release(),uptime:e.uptime(),cpus:e.cpus(),freemem:e.freemem(),totalmem:e.totalmem(),networkInterfaces:e.networkInterfaces()},[2,{code:c.SUCCESS,data:t}]}))}))},t.prototype.getMainProcessInfo=function(){return B(this,void 0,void 0,(function(){return F(this,(function(e){return[2,{code:c.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}(),Z=function(e){return function(e,t){return P("options.reconnectKickEnable",null==t?void 0:t.reconnectKickEnable,T.BOOLEAN),a.init({customLogPrint:null==t?void 0:t.logStdout,localLogLevel:null==t?void 0:t.logLevel}),K.setLogLevel(null==t?void 0:t.logLevel),K.setLogStdout(null==t?void 0:t.logStdout),new $(e,null==t?void 0:t.dbpath,null==t?void 0:t.reconnectKickEnable)}(H,e)};export{Z as default};
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("os"),t=require("path"),o=require("@rongcloud/engine"),n=require("electron"),r=require("fs"),s=require("crypto"),i=require("http"),a=require("https");function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var u=c(e),p=process.versions.electron.replace(/\.\d+$/,""),l=t.resolve(__dirname,"binding","electron-v".concat(p,"-").concat(e.platform(),"-").concat(e.arch(),".node")),d={addon:null};try{d.addon=require(l)}catch(e){console.error("error ->",l,"\n",e)}var C=d.addon,f=function(){return f=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},f.apply(this,arguments)};function g(e,t,o,n){return new(o||(o=Promise))((function(r,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,a)}c((n=n.apply(e,t||[])).next())}))}function h(e,t){var o,n,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(s){return function(a){return function(s){if(o)throw new TypeError("Generator is already executing.");for(;i;)try{if(o=1,n&&(r=2&s[0]?n.return:s[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,s[1])).done)return r;switch(n=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],n=0}finally{o=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}function _(e,t,o){if(o||2===arguments.length)for(var n,r=0,s=t.length;r<s;r++)!n&&r in t||(n||(n=Array.prototype.slice.call(t,0,r)),n[r]=t[r]);return e.concat(n||Array.prototype.slice.call(t))}var v,S=new o.Logger("RCMain"),y=null,E=function(){var t,o=Date.now(),n=[e.arch(),e.platform(),process.pid,o,Math.floor(Math.random()*o)].join("__");return t=n,s.createHash("md5").update(t).digest("hex")},m=function(e){if(y)return y;var o=t.resolve(e,"deviceId");return S.debug("deviceIdPath -> ".concat(o)),r.existsSync(o)?y=r.readFileSync(o).toString():(y=E(),S.debug("createDeviceId -> ".concat(y)),r.writeFileSync(o,y),y)},P=function(){function e(e,t){this._timerId=0,this._heartbeatTimeoutId=0,this._isFirstPing=!0,this._lossCount=0,this._hasPingRes=e,this._reconnect=t}return e.init=function(t,o){return v?(v.stop(),v):v=new e(t,o)},e.prototype.start=function(e){var t=this,o=this,n=function(){var r=t._isFirstPing?0:15e3;o._timerId=setTimeout((function(){o._isFirstPing=!1,S.debug("current lossCount: ".concat(o._lossCount)),o._hasPingRes?(e(),o._hasPingRes=!1,n()):o._lossCount<4?(o._lossCount++,e(),n()):o._reconnect()}),r)};n()},e.prototype.stop=function(){this._lossCount=0,clearTimeout(this._timerId)},e.prototype.setHeartbeatRes=function(e){S.debug("receive ping"),this._hasPingRes=e,this._lossCount=0},e}(),T=function(){function e(e){this._setTime=15962112e5,this._cppProto=e}return e.prototype._setToProtocol=function(e,t,o,n,r){var s=JSON.stringify(n);S.info("MsgExpansion._setToProtocol ===>",e,t,o,s,r),this._cppProto.setMessageExtension(e,t,o,s,r)},e.prototype.setLocalFromReceiveMsg=function(e){S.info("MsgExpansion.setLocalFromReceiveMsg ===>",e);var t=e.channelId,o=e.conversationType,n=e.targetId,r=e.messageUId,s=e.expansion,i=e.sentTime,a={};for(var c in s)a[c]={v:"",ts:0},a[c].v=s[c],a[c].ts=i;this._setToProtocol(o,n,r,a,t||"")},e.prototype.setLocalFromExtMsg=function(e){S.info("MsgExpansion.setLocalFromExtMsg ===>",e);var t=e.channelId,o=e.conversationType,n=e.targetId;e.messageUId;var r=e.content,s=e.sentTime,i=r,a=i.put,c=this._cppProto.getMessage(i.mid),u=JSON.parse(c).extMsg,p=JSON.parse(u||"{}");if(S.info("MsgExpansion.setLocalFromExtMsg, serverExtObj",a,"localExt",p),a)for(var l in a){var d=p[l];d&&d.ts<s-this._setTime?(d.v=a[l],d.ts=s-this._setTime):(p[l]={v:"",ts:0},p[l].v=a[l],p[l].ts=s-this._setTime)}i.del&&i.del.forEach((function(e){delete p[e]})),this._setToProtocol(o,n,i.mid,p,t||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),o={};for(var n in t)o[n]=t[n].v;return o},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),o=JSON.parse(t||"{}"),n={};for(var r in o)n[r]=o[r].v;return n},e}();function I(e,t){void 0===t&&(t=!1);var n=e.url,r=e.headers,s=e.body,c=e.method,u=e.query,p=e.timeout,l=void 0===p?o.HTTP_TIMEOUT:p;return new Promise((function(e){var p=/^https/.test(n),d={headers:r,method:c};p&&(d.rejectUnauthorized=t,d.agent=new a.Agent(d));var C=(p?a.request:i.request)(o.appendUrl(n,u),d,(function(t){var o=t.statusCode,n="";t.setEncoding("utf8"),t.on("data",(function(e){n+=e})),t.once("end",(function(){e({status:o||0,data:n})}))}));C.once("timeout",(function(){S.error("HTTP-Request-Timeout -> ".concat(JSON.stringify(d))),e({status:0})})),C.setTimeout(l),C.once("error",(function(t){S.error("HTTP-Request-Error -> ".concat(JSON.stringify(d))),S.error(t),e({status:0})})),C.write(s),C.end()}))}var N=null;function R(e,t,o,n,r){return void 0===r&&(r=!0),g(this,void 0,void 0,(function(){var s;return h(this,(function(i){switch(i.label){case 0:return N?[2,N]:(N=function(e,t,o,n,r){return void 0===r&&(r=!0),g(this,void 0,void 0,(function(){var s,i,a,c,u,p,l;return h(this,(function(d){switch(d.label){case 0:s="token=".concat(encodeURIComponent(n),"&v=").concat((C=e,C.match(/\d+(\.\d+){2}/)[0]),"&p=PC&ev=").concat("5.5.5-beem"),i=0,a=t.length,d.label=1;case 1:return i<a?(c="".concat(t[i],"/navi.json?r=").concat(Date.now()),S.info("request navi -> url: ".concat(c,", body: ").concat(s)),[4,I({method:"POST",headers:{appId:o},body:s,url:c},r)]):[3,4];case 2:if(200!==(u=d.sent()).status)return S.error("request navi failed -> ".concat(c)),u.data&&S.error(u.data),[3,3];S.info("request navi success -> ".concat(c));try{return p=JSON.parse(u.data),l=/^https/.test(c)?"https":"http",p.protocol=l,[2,p]}catch(e){S.error("parse navi err => ".concat(u.data))}d.label=3;case 3:return i+=1,[3,1];case 4:return[2,null]}var C}))}))}(e,t,o,n,r),[4,N]);case 1:return s=i.sent(),N=null,[2,s]}}))}))}var M=function(){function e(e,t,r){void 0===t&&(t=""),void 0===r&&(r=!1);var s=this;this._cppProtocol=e,this._dbpath=t,this._reconnectKickEnable=r,this._currentToken="",this._connectionStatus=o.ConnectionStatus.DISCONNECTED,this._promiseHandler={},this._customMessageType={},this._connectedTime=0,this._currentUserId="",this._inited=!1,this._naviInfo=null,this._version="5.5.5-beem",this._electronLogger={debug:this._superElectronLog.bind(this,"debug",o.LogLevel.DEBUG),info:this._superElectronLog.bind(this,"info",o.LogLevel.INFO),warn:this._superElectronLog.bind(this,"warn",o.LogLevel.WARN),error:this._superElectronLog.bind(this,"error",o.LogLevel.ERROR),fatal:this._superElectronLog.bind(this,"fatal",o.LogLevel.FATAL)},this._logger={debug:this._superLog.bind(this,"debug",o.LogLevel.DEBUG),info:this._superLog.bind(this,"info",o.LogLevel.INFO),warn:this._superLog.bind(this,"warn",o.LogLevel.WARN),error:this._superLog.bind(this,"error",o.LogLevel.ERROR),fatal:this._superLog.bind(this,"fatal",o.LogLevel.FATAL)},this._senders={},this.rtcHeartbeatResolves={},n.ipcMain.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return g(s,void 0,void 0,(function(){var r,s,i,a;return h(this,(function(c){switch(c.label){case 0:if((a=this._electronLogger).debug.apply(a,_(["__RC_CHANNEL_CALL_MAIN_SYNC__",t],n,!1)),"function"!=typeof(r=this[t]))return e.returnValue=o.ErrorCode.NOT_SUPPORT,[2];s=o.ErrorCode.EXTRA_METHOD_UNDEFINED,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,r.call.apply(r,_([this],n,!1))];case 2:return s=c.sent(),[3,4];case 3:return i=c.sent(),this._electronLogger.error("call main process method `".concat(t,"` failed.")),this._electronLogger.error(i),[3,4];case 4:return e.returnValue=s,[2]}}))}))})),n.ipcMain.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var r=[],i=3;i<arguments.length;i++)r[i-3]=arguments[i];return g(s,void 0,void 0,(function(){var s,i,a,c,u,p=this;return h(this,(function(l){switch(l.label){case 0:if((u=this._electronLogger).debug.apply(u,_(["__RC_CHANNEL_CALL_MAIN__",t,n],r,!1)),"function"!=typeof(s=this[n]))return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,o.ErrorCode.NOT_SUPPORT),[2];"sendMessage"===n&&(i=r[3],r[3]=function(t){p._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",i,t)}),a=o.ErrorCode.EXTRA_METHOD_UNDEFINED,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,s.call.apply(s,_([this],r,!1))];case 2:return a=l.sent(),[3,4];case 3:return c=l.sent(),this._electronLogger.error("call main process method `".concat(n,"` failed.")),this._electronLogger.error(c),[3,4];case 4:return this._electronLogger.debug("__RC_CHANNEL_RESULT_FROM_MAIN__",t,n,a),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,a),[2]}}))}))})),n.ipcMain.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var o,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];(o=s._electronLogger).debug.apply(o,_(["__RC_CHANNEL_CALL_MAIN__",t],n,!1));var i=s[t];if("function"==typeof i)try{i.call.apply(i,_([s],n,!1))}catch(e){s._electronLogger.error("call main process method `".concat(t,"` failed.")),s._electronLogger.error(e)}else s._electronLogger.error("cannot not found method: ".concat(t))})),n.ipcMain.on("__RC_INNER_COMMAND_INIT__",this._init.bind(this)),this._msgExpansionHandler=new T(this._cppProtocol)}return e.prototype._callCppProxy=function(e){for(var t,o,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];try{return(t=this._cppProtocol)[e].apply(t,n)}catch(t){(o=this._electronLogger).error.apply(o,_([t,e],n,!1))}},e.prototype.sendHTTPRequest=function(e){return I(e)},e.prototype._superElectronLog=function(e,t){for(var n,r=[],s=2;s<arguments.length;s++)r[s-2]=arguments[s];if(null===(n=S[e])||void 0===n||n.call.apply(n,_([S],r,!1)),t!==o.LogLevel.DEBUG){var i=Object.keys(this._senders);if(i.length>0){var a=r.reduce((function(e,t){return e+JSON.stringify(t)}),"");this._senders[i[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,a,"RCMain")}}},e.prototype._superLog=function(e,t,n,r,s){var i;if(null===(i=o.logger[e])||void 0===i||i.call(o.logger,n,r,s),t!==o.LogLevel.DEBUG){var a=Object.keys(this._senders);a.length>0&&this._senders[a[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,r,n,null==s?void 0:s.logSource)}},e.prototype.getCppProto=function(){var e=this;return{destroy:function(){e._cppProtocol.destroy()}}},e.prototype.destroy=function(){this._cppProtocol.destroy()},e.prototype.callExtra=function(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];(t=this._electronLogger).info.apply(t,_(["callExtra -> ".concat(e)],n,!1));var s=this[e];if(!s)return this._electronLogger.warn("ExtraHandler.".concat(e," is undefined")),Promise.resolve({code:o.ErrorCode.EXTRA_METHOD_UNDEFINED});try{return s.call.apply(s,_([this],n,!1))}catch(e){this._electronLogger.error(e)}return Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})},e.prototype.getConversationsByPage=function(e,t,n,r){var s,i=this,a=this._callCppProxy("getConversationListByPage",e,t,n,r||"");try{s=JSON.parse(a).list.map((function(e){return i._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:s})},e.prototype.getConversationListWithAllChannel=function(){var e,t=this,n=[o.ConversationType.PRIVATE,o.ConversationType.GROUP],r=this._callCppProxy("getConversationListWithAllChannel",n);try{e=JSON.parse(r).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:e})},e.prototype.getConversationListWithAllChannelByPage=function(e,t){var n,r=this,s=[o.ConversationType.PRIVATE,o.ConversationType.GROUP],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,e,t);try{n=JSON.parse(i).list.map((function(e){return r._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:n})},e.prototype.getHistoryMessagesByObjectNames=function(e,t,n,r,s,i,a){var c=0===i,u=r+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,n,u,s,c,a||""),l=[];try{var d=JSON.parse(p).list;d.reverse();for(var C=0;C<d.length;C++){var f=this._buildMessage(d[C].obj);l[C]=f}}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:{list:u===l.length?l.slice(1,u):l,hasMore:r<l.length}})},e.prototype.updateMessageReceiptStatus=function(e,t,n,r){void 0===r&&(r=""),this._electronLogger.info("updateMessageReceiptStatus ->",e,t,n,r);var s=this._callCppProxy("updateMessageReceiptStatus",e,t,n,r);return Promise.resolve({code:o.ErrorCode.SUCCESS,data:s})},e.prototype.requestNaviInfo=function(e,t,o,n){return g(this,void 0,void 0,(function(){return h(this,(function(r){return[2,R(this._initOptions.apiVersion,e,t,o,n)]}))}))},e.prototype.updateNaviInfo=function(e){this._naviInfo=e},e.prototype.getNaviInfoFromCache=function(){return this._naviInfo?f({},this._naviInfo):null},e.prototype.getConnectedTime=function(){return this._connectedTime},e.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},e.prototype.getCurrentUserId=function(){var e;return(null===(e=this._naviInfo)||void 0===e?void 0:e.userId)||""},e.prototype._send2Renderer=function(e,t){for(var o=[],n=2;n<arguments.length;n++)o[n-2]=arguments[n];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,_([t],o,!1))},e.prototype._send2AllRenderer=function(e,t,o){var n=this;void 0===o&&(o=[]),Object.keys(this._senders).forEach((function(r){var s=n._senders[r];o.includes(s)||n._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},e.prototype._init=function(e,r){var s=this,i=e.sender,a=i.id;if(this._senders[a]||(this._senders[a]=i,i.once("destroyed",(function(){delete s._senders[a]}))),!this._inited){this._inited=!0,this._initOptions=r,this._electronLogger.info("init ->",r);var c=this._dbpath||t.resolve(n.app.getPath("userData"));this._logger.info(o.LogTagId.P_INIT_O,{"proto-commitId":this._cppProtocol.getNodeVersion(),appkey:r.appkey,dbpath:c}),this._callCppProxy("initWithAppkey",r.appkey,c,r.apiVersion.replace(/-.*/,"")),this._electronLogger.warn("cppProto version ->",this._cppProtocol.getNodeVersion()),this._registerMsgTypes();var u=m(c);this._electronLogger.info("deviceId -> ".concat(u)),this._callCppProxy("setDeviceId",u),this._setConnectionStatusListener(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener()}},e.prototype._registerMsgTypes=function(){for(var e in o.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},o.SEND_MESSAGE_TYPE_OPTION){var t=o.SEND_MESSAGE_TYPE_OPTION[e],n=t.isCounted,r=0;t.isPersited&&(r|=1),n&&(r|=2),"RC:TypSts"===e&&(r=16),this._electronLogger.info("_registerMsgTypes ====>",e,r),this._callCppProxy("registerMessageType",e,r)}},e.prototype._buildMessage=function(e,t){void 0===t&&(t={});var n=t.isOffLineMessage,r=t.buildFrom,s=JSON.parse(e);this._electronLogger.debug("_buildMessage:",s);var i=s.channelId,a=s.conversationType,c=s.targetId,u=s.senderUserId,p=s.content,l=s.objectName,d=s.messageUid,C=s.direction,g=s.status;s.source;var h=s.messageId,_=s.sentTime,v=s.readReceiptRequest,y=s.supportExt;s.extMsg;var E,m=s.pushContent,P=s.pushTitle,T=s.pushId,I=s.pushConfig,N=s.templateId,R=s.disableTitle,M=s.forcePushDetail;if(o.isObject(p))E=p;else try{E=p?JSON.parse(p):p}catch(e){S.warn("cpp engine build messaga error:",e),E=p}var L={isCounted:!1,isPersited:!1};l in o.SEND_MESSAGE_TYPE_OPTION?L=o.SEND_MESSAGE_TYPE_OPTION[l]:l in this._customMessageType&&(L=this._customMessageType[l]);var O=null;y&&(O=this._msgExpansionHandler.parseReceiveExpansion(s),"conversation"!==r&&"history"!==r||(O=this._msgExpansionHandler.parseConverOrHisExpansion(s)));var b=o.isUndefined(n)?_<this._connectedTime:n,U={};I&&(U=o.pushJSONToConfigs(I,T));var x=f(f({},U),{pushTitle:P,pushContent:m,pushData:m,disablePushTitle:R,forceShowDetailContent:M,templateId:N}),w={channelId:i,conversationType:a,targetId:c,senderUserId:u,content:E||{},messageType:l,messageUId:d,messageDirection:C,isOffLineMessage:b,sentTime:_,receivedTime:0,isPersited:L.isPersited,isCounted:L.isCounted,isMentioned:!1,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:y,expansion:y?O:null,receivedStatus:g,messageId:h,pushConfig:x};if(C===o.MessageDirection.RECEIVE?w.receivedStatus=g:C===o.MessageDirection.SEND&&(w.sentStatus=g),v){var A=JSON.parse(v),D=A.hasRespond,H=A.readerInfo,J={hasRespond:D,readCount:A.readCount,totalCount:A.totalCount},k=[];if(H)for(var F in H)k.push({userId:F,readTime:H[F]});J.readerList=k,w.readReceiptInfo=J}return w},e.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),n=JSON.parse(o),r=n.readReceiptRequest?JSON.parse(n.readReceiptRequest):{},s=f(f({},r),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},e.prototype._buildConversation=function(e){var t=JSON.parse(e);this._electronLogger.debug("_buildConversation",t);var n=t.channelId,r=t.conversationType,s=t.targetId,i=t.unreadCount,a=t.lastestMsg,c=t.isTop,u=t.isBlocked,p=t.matchCount,l=u?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE;return{channelId:n,conversationType:r,targetId:s,unreadMessageCount:i,latestMessage:-1===JSON.parse(a).messageId?null:this._buildMessage(a),hasMentioned:!1,mentionedInfo:null,notificationStatus:l,isTop:c,lastUnreadTime:0,matchCount:p}},e.prototype._sendConnectionStatus2Renderer=function(e){this._send2AllRenderer("status",e)},e.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}))},e.prototype._connectResolve=function(e){this._promiseHandler.connect&&this._promiseHandler.connect.length>0&&(this._promiseHandler.connect.forEach((function(t){t.resolve(e)})),delete this._promiseHandler.connect)},e.prototype._setConnectionStatusListener=function(){var e=this;this._cppProtocol.setConnectionStatusListener((function(t){var n,r;switch(e._electronLogger.warn("protocol connection status changed:",t),t){case 10:r=o.ConnectionStatus.CONNECTING;break;case 31004:return void setTimeout((function(){e._connectResolve(o.ErrorCode.RC_CONN_USER_OR_PASSWD_ERROR)}));case 12:r=o.ConnectionStatus.DISCONNECTED;break;case 13:r=o.ConnectionStatus.BLOCKED,setTimeout((function(){e._connectResolve(o.ErrorCode.RC_CONN_USER_BLOCKED)}));break;case 31023:r=o.ConnectionStatus.FORBID_RECONNECT_BY_OTHER_SAME_CLIENT,setTimeout((function(){e._connectResolve(o.ErrorCode.RC_DISCONN_SAME_CLIENT_ON_LINE)}));break;case 31029:r=o.ConnectionStatus.USER_LOGOUT;break;case 1:case 9:case 11:case 31011:case 3e4:case 30002:r=o.ConnectionStatus.NETWORK_UNAVAILABLE;break;case 30010:r=o.ConnectionStatus.NETWORK_UNAVAILABLE,setTimeout((function(){e._connectionStatus===o.ConnectionStatus.NETWORK_UNAVAILABLE&&e._doConnect()}),5e3);break;case 0:case 33005:r=o.ConnectionStatus.CONNECTED,e._connectedTime=Date.now()-e._cppProtocol.getDeltaTime(),setTimeout((function(){e._connectResolve(o.ErrorCode.SUCCESS),e._heartbeat=P.init(!0,e._handleHeartTimeout.bind(e)),e._heartbeat.start(e._sendHeartbeat.bind(e))}));break;case o.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT:r=o.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT;break;case 31030:r=o.ConnectionStatus.RC_LICENSE_EXPIRED,setTimeout((function(){e._connectResolve(o.ErrorCode.RC_LICENSE_EXPIRED)}));break;case 30004:return;case 8:case 31006:case 32061:case 32012:r=o.ConnectionStatus.REDIRECT;break;default:r=t}r!==o.ConnectionStatus.CONNECTED&&(null===(n=e._heartbeat)||void 0===n||n.stop()),e._connectionStatus=r,e._logger.info(o.LogTagId.P_CONNECT_S,{status:t}),e._sendConnectionStatus2Renderer(r)}),this._dbOpenCallback,(function(){var t;null===(t=e._heartbeat)||void 0===t||t.setHeartbeatRes(!0)}))},e.prototype._handleHeartTimeout=function(){var e,t=this;S.warn("network unavailable! try to reconnect!"),this._sendConnectionStatus2Renderer(o.ConnectionStatus.NETWORK_UNAVAILABLE),null===(e=this._heartbeat)||void 0===e||e.stop(),setTimeout((function(){return t._doConnect()}),5e3)},e.prototype._dbOpenCallback=function(e){S.info("Sqlite DB Open -> ".concat(e))},e.prototype._sendHeartbeat=function(){S.debug("send ping"),this._cppProtocol.sendHeartbeat()},e.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,n,r,s){var i,a=e._buildMessage(t,{isOffLineMessage:r});if(a.messageType===o.MessageType.GROUP_READ_RECEIPT_REQUEST){var c=a.content,u=c.msgId,p=c.rrn,l=c.tmn;e._updateReadReceiptInfo(u,{readCount:p,totalCount:l})}if("RC:MsgExMsg"===a.messageType)return e._msgExpansionHandler.setLocalFromExtMsg(a),void e._sendMessageExpansion(a);if(a.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(a),a.messageType===o.MessageType.SYNC_READ_STATUS){if(a.senderUserId!==e._currentUserId)return;e._callCppProxy("clearUnreadCountByTimestamp",a.conversationType,a.targetId,a.content.lastMessageSendTime,a.channelId||"")}var d=!0;if(0!==n||s||(d=!1),a.messageType!==o.MessageType.LOG_COMMAND||"rongcloudsystem"!==a.senderUserId){if(a.messageType===o.MessageType.DELIVERED)return e._callCppProxy("setMessageDeliverTime",JSON.stringify(a.content)),void e._sendMessageDelivered(a.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}})));if(a.messageType!==o.MessageType.DELIVERED_MSG){var C=a.conversationType,f=a.targetId;a.messageType===o.MessageType.RECALL&&a.senderUserId===e._currentUserId&&(C=a.content.conversationType||C,f=a.content.targetId||f),e._sendMessageNotification(Object.assign(a,{hasMoreMsg:d,conversationType:C,targetId:f}))}else{var g={totalCount:a.content.tmn,list:null===(i=a.content.dl)||void 0===i?void 0:i.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};e._sendGroupMessageDeliveredStatus(g)}}else{var h=Object.keys(e._senders).map((function(t){return e._senders[t]}));h.length>0&&e._sendMessageNotification(Object.assign(a,{hasMoreMsg:d}),h.slice(1))}}),(function(){e._sendPullOfflineFinished()}))},e.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var o=e.channelId,n=e.content,r=n.put,s=n.del,i=n.mid,a={};r&&(a.updatedExpansion={channelId:o,messageUId:i,expansion:r}),s&&(a.deletedExpansion={channelId:o,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},e.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},e.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},e.prototype._sendMessageDelivered=function(e){this._send2AllRenderer("messageDelivered",e)},e.prototype._sendGroupMessageDeliveredStatus=function(e){this._send2AllRenderer("groupMessageDeliveredStatus",e)},e.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var n=JSON.parse(t).list,r=[];n.forEach((function(e){var t=JSON.parse(e.obj),n=t.conversationType,s=t.targetId,i=t.status,a=t.channelId,c={notificationStatus:2,isTop:!1};i.forEach((function(e){var t=JSON.parse(e.item);1===t.type?c.notificationStatus=1===Number(t.value)?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE:c.isTop=1===Number(t.value)})),r.push({channelId:a,conversationType:n,targetId:s,updatedItems:{notificationStatus:{val:c.notificationStatus,time:0},isTop:{val:c.isTop,time:0}}})})),e._send2AllRenderer("conversation",r)}),(function(t){e._electronLogger.info("会话标签状态变更",t),e._send2AllRenderer("conversationTag",t)}))},e.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._electronLogger.info("标签变更",t),e._send2AllRenderer("tag",t),e._getRTCProfile()}))},e.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e&&this._naviInfo&&this._naviInfo.voipCallInfo!==e){var t=f(f({},this._naviInfo),{voipCallInfo:e});this._naviInfo=t,this._send2AllRenderer("onNaviDataChange",t)}},e.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var o=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",o)}))},e.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._send2AllRenderer("chatroom",{chatroomDestroyed:t})}))},e.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._send2AllRenderer("callInfo",t)}))},e.prototype._clearListener=function(){this._cppProtocol.setOnReceiveMessageListener(),this._cppProtocol.setConnectionStatusListener(),this._cppProtocol.setOnReceiveStatusListener(),this._cppProtocol.setUserProfileListener()},e.prototype.registerMessageType=function(e,t,n,r){var s=0;t&&(s|=1),n&&(s|=2),this._customMessageType[e]={isCounted:n,isPersited:t},this._logger.info(o.LogTagId.P_REGTYP_O,{messageType:e,isCounted:n,searchProps:r,isPersited:t}),this._callCppProxy("registerMessageType",e,s,r)},e.prototype.connect=function(e,t,n,r){var s=this;return this._electronLogger.info("connect ->",e,t,n),this._logger.info(o.LogTagId.P_CONNECT_O,{token:e,reconnectKickEnable:n,version:this._version},{traceId:r}),this._currentToken===e&&this._connectionStatus===o.ConnectionStatus.CONNECTED?(this._sendConnectionStatus2Renderer(this._connectionStatus),Promise.resolve(o.ErrorCode.SUCCESS)):(this._currentToken=e,this._naviInfo=t,this._currentUserId=t.userId,this._promiseHandler.connect||this._doConnect(n),new Promise((function(e,t){s._promiseHandler.connect?s._promiseHandler.connect.push({resolve:e,reject:t}):s._promiseHandler.connect=[{resolve:e,reject:t}]})))},e.prototype._doConnect=function(e){var t=o.isUndefined(e)?!!this._reconnectKickEnable:!!e;this._callCppProxy("connectWithToken",this._currentToken,this._initOptions.apiVersion,JSON.stringify(this._naviInfo),t)},e.prototype.reportSDKInfo=function(e){var t,o;null===(o=(t=this._cppProtocol).uploadSDKVersion)||void 0===o||o.call(t,JSON.stringify(e)),this._electronLogger.info(e)},e.prototype.disconnect=function(){var e;this._cppProtocol.disconnect(!0),null===(e=this._heartbeat)||void 0===e||e.stop(),this._connectResolve(o.ErrorCode.TIMEOUT)},e.prototype.logout=function(){this.disconnect()},e.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)},e.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("subscribeUserStatus",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.setUserStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("setUserStatus",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.getUserStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("getUserStatus",e,(function(e){n({code:o.ErrorCode.SUCCESS,data:{status:e}})}),(function(e){n({code:e})}))}))},e.prototype.sendMessage=function(e,t,n,r,s){var i=this,a=n.messageType,c=n.content,u=n.pushContent,p=n.pushData,l=n.directionalUserIdList,d=n.disableNotification,C=n.canIncludeExpansion,f=n.expansion,g=n.isVoipPush,h=n.pushConfig,_=n.channelId,v=n.isMentioned,S=n.mentionedType,y=n.mentionedUserIdList,E=n.messageId,m=h||{},P=m.iOSConfig,T=m.androidConfig,I=m.pushTitle,N=m.pushContent,R=m.pushData,M=m.disablePushTitle,L=m.forceShowDetailContent,O=m.templateId,b=o.pushConfigsToJSON(P,T);return new Promise((function(n){u=N||u||"",p=R||p||"",d=d||!1,g=g||!1,I=I||"",N=N||"",R=R||"",M=M||!1,L=L||!1,C=C||!1;var h=(null==T?void 0:T.notificationId)||"";if(l=l||[],E=E||0,_=_||"",e===o.ConversationType.GROUP&&v&&c&&(c.mentionedInfo={userIdList:y,type:S||o.MentionedType.ALL}),e===o.ConversationType.GROUP&&a===o.MessageType.READ_RECEIPT_RESPONSE&&c.receiptMessageDic)for(var m in c.receiptMessageDic)l.push(m);var P={};for(var m in f)P[m]={v:""},P[m].v=f[m];var U=O||"";E&&i._callCppProxy("setMessageContent",E,JSON.stringify(c),a),i._logger.info(o.LogTagId.P_SEND_MSG_T,{messageType:a,conversationType:e,targetId:t,channelId:_},{traceId:s});var x=i._callCppProxy("sendMessage",(function(e,t){var r=i._buildMessage(e,{isOffLineMessage:!1});return i._logger.info(o.LogTagId.P_SEND_MSG_R,{code:t,messageUId:r.messageUId,messageId:r.messageId},{traceId:s}),t===o.ErrorCode.SENSITIVE_REPLACE?n({code:t}):("RC:MsgExMsg"===r.messageType&&i._msgExpansionHandler.setLocalFromExtMsg(r),r.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(r),n({code:o.ErrorCode.SUCCESS,data:r}))}),(function(e,t){var r=i._buildMessage(e,{isOffLineMessage:!1});return i._logger.warn(o.LogTagId.P_SEND_MSG_R,{code:t,messageUId:r.messageUId,messageId:r.messageId},{traceId:s}),r.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),n({code:t,data:r})}),e,t,a,JSON.stringify(c),l,d,M,L,u,p,h,I,b,U,C,JSON.stringify(P),g,_,E),w=JSON.parse(x);null==r||r(w.messageId)}))},e.prototype.recallMsg=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){var u,p=s.user,l=s.pushContent,d=s.channelId,C=s.extra,f=s.pushConfig,g=s.disableNotification,h=s.isDelete,_={conversationType:e,targetId:t,messageUId:n,sentTime:r,user:p,extra:C,channelId:d,isDelete:h||!1};p&&(_.user=p),C&&(_.extra=C);var v={conversationType:e,targetId:t,senderUserId:i._currentUserId,content:_,objectName:o.MessageType.RECALL,messageUid:n,direction:o.MessageDirection.SEND,status:o.ReceivedStatus.UNREAD,sentTime:r,channelId:d},S=i._buildMessage(JSON.stringify(v),{isOffLineMessage:!1});i._callCppProxy("recallMessage",(function(){a({code:o.ErrorCode.SUCCESS,data:S})}),(function(e){a({code:e})}),o.MessageType.RECALL,JSON.stringify(_),g||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,l||"",(null==f?void 0:f.pushData)||"",(null===(u=null==f?void 0:f.androidConfig)||void 0===u?void 0:u.notificationId)||"",(null==f?void 0:f.pushTitle)||"",o.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",d)}))},e.prototype.getHistoryMessage=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(u,p){n=n||0;var l=0===s,d=r+1,C=c._callCppProxy("getHistoryMessages",e,t,n,d,a,l,i),f=JSON.parse(C).list,g=[];f.reverse();for(var h=0;h<f.length;h++){var _=c._buildMessage(f[h].obj);g[h]=_}u({code:o.ErrorCode.SUCCESS,data:{list:d===g.length?g.slice(1,d):g,hasMore:r<g.length}})}))},e.prototype.getRemoteHistoryMessages=function(e,t,n,r,s,i){var a=this;return new Promise((function(c,u){n=n||0;a._callCppProxy("getRemoteHistoryMessages",e,t,n,r,(function(e,t){var n=JSON.parse(e).list,r=[];n.reverse();for(var s=0;s<n.length;s++){var i=a._buildMessage(n[s].obj);r[s]=i}c({code:o.ErrorCode.SUCCESS,data:{list:r,hasMore:!!t}})}),(function(e){c({code:e})}),s,!0,i)}))},e.prototype.deleteRemoteMessage=function(e,t,n,r){var s=this;return new Promise((function(i,a){var c=JSON.stringify(n);s._callCppProxy("deleteRemoteHistoryMessages",e,t,c,!1,r,(function(){i(o.ErrorCode.SUCCESS)}),i)}))},e.prototype.deleteRemoteMessageByTimestamp=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearRemoteHistoryMessages",e,t,n,(function(){i(o.ErrorCode.SUCCESS)}),(function(e){i(e)}),r)}))},e.prototype.clearMessages=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("clearMessages",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.getConversationList=function(e,t,n,r,s){var i=this;return void 0===s&&(s=""),new Promise((function(e,t){for(var n=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(n).list,a=[],c=0;c<r.length;c++)a.push(i._buildConversation(r[c].obj));e({code:o.ErrorCode.SUCCESS,data:a})}))},e.prototype.getConversation=function(e,t,n){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversation",e,t,n);if(a)s({code:o.ErrorCode.SUCCESS,data:r._buildConversation(a)});else{var c=r._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,n),u=void 0;try{u=JSON.parse(c).list}catch(e){r._electronLogger.warn("json parse cppMessagaes error",e),u=[]}var p=null;u.length>0&&(p=r._buildMessage(u[0].obj));var l=r._callCppProxy("getConversationNotificationStatus",e,t,n),d=r._callCppProxy("getConversationTopStatus",e,t,n);s({code:o.ErrorCode.SUCCESS,data:{conversationType:e,targetId:t,channelId:n,unreadMessageCount:0,latestMessage:p,notificationStatus:l?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},e.prototype.removeConversation=function(e,t,n){var r=this._callCppProxy("removeConversation",e,t,n);return this._electronLogger.info("removeConversation result -> ".concat(r)),Promise.resolve(r?o.ErrorCode.SUCCESS:o.ErrorCode.UNKNOWN)},e.prototype.clearConversations=function(e,t){var n=this;return new Promise((function(r,s){var i=[];i=o.isArray(e)?e:[o.ConversationType.PRIVATE,o.ConversationType.GROUP,o.ConversationType.SYSTEM,o.ConversationType.PUBLIC_SERVICE],n._callCppProxy("clearConversations",i,t),r(o.ErrorCode.SUCCESS)}))},e.prototype.getAllConversationUnreadCount=function(e,t,n){var r=this._callCppProxy("getTotalUnreadCount",t,n,e);return Promise.resolve({code:o.ErrorCode.SUCCESS,data:r})},e.prototype.getConversationUnreadCount=function(e,t,n){var r=this;return void 0===n&&(n=""),new Promise((function(s){var i=r._callCppProxy("getUnreadCount",e,t,n);s({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.clearConversationUnreadCount=function(e,t,n){var r=this;return void 0===n&&(n=""),new Promise((function(s,i){r._callCppProxy("clearUnreadCount",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.clearUnreadCountByTimestamp=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearUnreadCountByTimestamp",e,t,n,r),i(o.ErrorCode.SUCCESS)}))},e.prototype.getFirstUnreadMessage=function(e,t,n){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getTheFirstUnreadMessage",e,t,n),c=r._buildMessage(a);s({code:o.ErrorCode.SUCCESS,data:-1!==c.messageId?c:null})}))},e.prototype.setConversationToTop=function(e,t,n,r){var s=this;return void 0===r&&(r=""),new Promise((function(i,a){s._electronLogger.info("setConversationToTop",e,t,n,r,true),s._callCppProxy("setConversationToTop",e,t,n,r,true),i(o.ErrorCode.SUCCESS)}))},e.prototype.setConversationHidden=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("setConversationHidden",e,t,n,r),i(o.ErrorCode.SUCCESS)}))},e.prototype.setConversationNotificationStatus=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._electronLogger.info("setConversationNotificationStatus",e,t,n,r),s._callCppProxy("setConversationNotificationStatus",e,t,n,(function(){i(o.ErrorCode.SUCCESS)}),i,r)}))},e.prototype.setConversationStatus=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){i._electronLogger.info("setConversationStatus",e,t,n,r,s,true),i._callCppProxy("setConversationStatus",e,t,n,r,(function(){a(o.ErrorCode.SUCCESS)}),a,s,true)}))},e.prototype.getConversationNotificationStatus=function(e,t,n){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversationNotificationStatus",e,t,n);s({code:o.ErrorCode.SUCCESS,data:a?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE})}))},e.prototype.searchConversationByContent=function(e,t,n,r){var s=this;return new Promise((function(i,a){r=r||[1,3,6,7];for(var c=s._callCppProxy("searchConversationByContent",r,e,t,n),u=JSON.parse(c).list,p=[],l=0;l<u.length;l++)p[l]=s._buildConversation(u[l].obj);i({code:o.ErrorCode.SUCCESS,data:p})}))},e.prototype.searchConversationByContentWithAllChannel=function(e,t,n){var r=this;return new Promise((function(s,i){n=n||[1,3,6,7];for(var a=r._callCppProxy("searchConversationByContentWithAllChannel",n,e,t),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=r._buildConversation(c[p].obj);s({code:o.ErrorCode.SUCCESS,data:u})}))},e.prototype.searchMessageByContent=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(i,u){c._callCppProxy("searchMessageByContent",e,t,n,r,s,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],r=[],s=0;s<n.length;s++)r[s]=c._buildMessage(n[s].obj);i({code:o.ErrorCode.SUCCESS,data:{messages:r,count:t}})}),a)}))},e.prototype.searchMessageByContentWithAllChannel=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("searchMessageByContentWithAllChannel",e,t,n,r,s,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],r=[],s=0;s<n.length;s++)r[s]=i._buildMessage(n[s].obj);a({code:o.ErrorCode.SUCCESS,data:{messages:r,count:t}})}))}))},e.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(u,p){c._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,n,r,s,i,a,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],r=0;r<t.length;r++)n[r]=c._buildMessage(t[r].obj);u({code:o.ErrorCode.SUCCESS,data:{messages:n}})}))}))},e.prototype.getUnreadMentionedMessages=function(e,t,o){for(var n=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,o)).list,r=0;r<n.length;r++)n[r]=this._buildMessage(n[r].obj);return n},e.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("addToBlacklist",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("removeFromBlacklist",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,n){e._callCppProxy("getBlacklist",(function(e){t({code:o.ErrorCode.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},e.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("getBlacklistStatus",e,(function(e){n({code:o.ErrorCode.SUCCESS,data:e})}),(function(e){n({code:e})}))}))},e.prototype.insertMessage=function(e,t,n){var r=this,s=n.content,i=n.senderUserId,a=n.messageType,c=n.messageDirection,u=n.readStatus,p=n.sentStatus,l=n.sentTime,d=n.searchContent,C=n.isUnread,f=n.messageUId,g=n.disableNotification,h=n.canIncludeExpansion,_=n.expansionMsg,v=n.channelId;return s=JSON.stringify(s),new Promise((function(n,S){var y=C?0:1,E=r._callCppProxy("insertMessage",e,t,i,a,s,(function(){}),(function(e){n({code:e})}),c,u,p,l,d,y,f,g,h,_,v);r._electronLogger.info("after insert msg",E);var m=r._buildMessage(E,{isOffLineMessage:!1});m.messageUId=f,m.sentTime=l,n({code:-1===m.messageId?o.ErrorCode.MSG_INSERT_ERROR:o.ErrorCode.SUCCESS,data:m})}))},e.prototype.deleteMessages=function(e){var t=this;return new Promise((function(n,r){t._logger.debug(o.LogTagId.P_DELETE_MSG_S,{messageIds:e}),t._callCppProxy("deleteMessages",e),n(o.ErrorCode.SUCCESS)}))},e.prototype.deleteMessagesByTimestamp=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("deleteMessagesByTimestamp",e,t,n,r,s),a(o.ErrorCode.SUCCESS)}))},e.prototype.getMessage=function(e){var t=this;return new Promise((function(n,r){var s=t._callCppProxy("getMessage",e);t._electronLogger.info("getMessage ===>",s);var i=t._buildMessage(s,{isOffLineMessage:!1});n({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.setMessageContent=function(e,t,n){var r=this;return new Promise((function(s,i){t=JSON.stringify(t),r._callCppProxy("setMessageContent",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.setMessageSearchField=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("setMessageSearchField",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.setMessageSentStatus=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("setMessageSentStatus",e,t),r(o.ErrorCode.SUCCESS)}))},e.prototype.setMessageReceivedStatus=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("setMessageReceivedStatus",e,t),r(o.ErrorCode.SUCCESS)}))},e.prototype.saveConversationMessageDraft=function(e,t,o,n){throw new Error("Method not implemented.")},e.prototype.getConversationMessageDraft=function(e,t,o){throw new Error("Method not implemented.")},e.prototype.clearConversationMessageDraft=function(e,t,o){throw new Error("Method not implemented.")},e.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},e.prototype.batchSetConversationStatus=function(e){var t=e[0],n=t.conversationType,r=t.targetId,s=t.isTop,i=t.notificationStatus,a=t.channelId;if(void 0!==s&&void 0===i)return this.setConversationToTop(n,r,s,a);if(void 0!==i&&void 0===s){var c=i===o.NotificationStatus.OPEN;return this.setConversationNotificationStatus(n,r,c,a)}var u=i===o.NotificationStatus.OPEN;return this.setConversationStatus(n,r,u,s,a)},e.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},e.prototype.sendReadReceiptMessage=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("sendReadReceipt",e,n||"",t,(function(){t.forEach((function(e){r._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(r._callCppProxy("getMessage",e)).messageId;r.setMessageReceivedStatus(t,1)}catch(t){r._electronLogger.warn("format message error, messageUId: ".concat(e))}})),s({code:o.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},e.prototype.getMessageReader=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("getMessageReader",e,n,t,(function(e,n){r._electronLogger.info("getMessageReader -> ",e,n);var i=[],a={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,n=t.time;i.push({userId:o,readTime:n}),a[o]=n}));var c={readerInfo:a,readCount:i.length,totalCount:n};r._updateReadReceiptInfo(t,c),s({code:o.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:n}})}),(function(e){s({code:e})}))}))},e.prototype.joinChatroom=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("clearMessages",o.ConversationType.CHATROOM,e,""),n._callCppProxy("joinChatRoom",e,t,(function(){r(o.ErrorCode.SUCCESS)}),r)}))},e.prototype.joinExistChatroom=function(e,t){throw new Error("Method not implemented.")},e.prototype.quitChatroom=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("quitChatRoom",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.getChatroomInfo=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomInfo",e,t,n,(function(e,t){var n=e?JSON.parse(e).list:[],r=[];if(n.length>0)for(var i=0;i<n.length;i++)r.push(JSON.parse(n[i].obj));s({code:o.ErrorCode.SUCCESS,data:{userInfos:r,userCount:t}})}),(function(e){s({code:e})}))}))},e.prototype.getChatroomHistoryMessages=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("getChatroomHistoryMessage",e,t,n,r,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var n=t.list;if(n&&n.length)try{t.list=n.map((function(e){return s._buildMessage(e.obj)}))}catch(e){t.list=[]}i({code:o.ErrorCode.SUCCESS,data:t})}),(function(e){i({code:e})}),"")}))},e.prototype.setChatroomEntry=function(e,t){var n=this;return new Promise((function(r,s){var i='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');n._callCppProxy("setChatroomKV",e,i,!!t.isAutoDelete,!!t.isOverwrite,(function(){r(o.ErrorCode.SUCCESS)}),(function(e){r(e)}))}))},e.prototype.setChatroomEntries=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.setChatroomEntry(e,t)},e.prototype.removeChatroomEntry=function(e,t){var n=this,r=[t.key];return new Promise((function(s,i){n._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){s(o.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},e.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.removeChatroomEntry(e,t)},e.prototype.removeChatroomEntries=function(e,t){var n=this;return new Promise((function(r){var s=t.entries.map((function(e){return e.key}));n._callCppProxy("deleteChatroomKV",e,s,!!t.isOverwrite,(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.getChatroomEntry=function(e,t){return g(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(n=r.sent()).code===o.ErrorCode.SUCCESS?[2,{code:o.ErrorCode.SUCCESS,data:n.data?n.data[t]:null}]:[2,{code:n.code}]}}))}))},e.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}n({code:o.ErrorCode.SUCCESS,data:t})}),(function(e){n({code:e})}))}))},e.prototype.getFileToken=function(e,t,n,r){var s=this;return n=n||"",r=r||"",new Promise((function(i){var a;a=r&&"uploads"!==r?t||"":o.getUploadFileName(e,t),s._callCppProxy("getUploadToken",e,a,n,r,(function(e,t,n,r,s,c,u,p,l,d,C,f,g,h,_,v,S,y){i({code:o.ErrorCode.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:n,path:r,osskeyId:s,ossPolicy:c,ossSign:u,ossBucketName:p,fileName:a,s3Credential:l,s3Algorithm:d,s3Date:C,s3Policy:f,s3Signature:g,s3BucketName:h,stcAuthorization:_,stcContentSha256:v,stcDate:S,stcBucketName:y}})}),(function(e){i({code:e})}))}))},e.prototype.getFileUrl=function(e,t,n,r){var s=this;return new Promise((function(i){s._callCppProxy("getDownloadUrl",e,n,r,t-1,(function(e){i({code:o.ErrorCode.SUCCESS,data:{downloadUrl:e}})}),(function(e){i({code:e})}))}))},e.prototype.clearData=function(){var e=this;return new Promise((function(t,n){var r=e._callCppProxy("clearData");t({code:o.ErrorCode.SUCCESS,data:r})}))},e.prototype.getDeviceId=function(){var e=this._dbpath||t.resolve(n.app.getPath("userData"));return m(e)},e.prototype.getVoIPKey=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("getVoIPKey",e,t,"",(function(e){r({code:o.ErrorCode.SUCCESS,data:e})}),(function(e){r({code:e})}))}))},e.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(n,r){var s=e.chatRoomId,i=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",s,i,(function(){n(o.ErrorCode.SUCCESS)}),(function(e){n(e)}))}))},e.prototype.getGroupMessageDeliverList=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("getGroupMessageDeliverList",e,n,t,(function(e,t){var n=JSON.parse(e).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));s({code:o.ErrorCode.SUCCESS,data:{totalCount:t,list:n}})}),(function(e){s({code:e})}))}))},e.prototype.getPrivateMessageDeliverTime=function(e,t){var n=this;return new Promise((function(r,s){var i=n._callCppProxy("getMessageDeliverTime",e);if(i)r({code:o.ErrorCode.SUCCESS,data:i});else{n._callCppProxy("getPrivateMessageDeliverList",t,e,(function(e){var t=0,n=JSON.parse(e).list;n.length>0&&(t=JSON.parse(n[0].obj).time);r({code:o.ErrorCode.SUCCESS,data:t})}),(function(e){r({code:e})}))}}))},e.prototype.rtcSignaling=function(e,t,n,r){var s=this,i=Array.prototype.slice.call(new Uint8Array(r));return new Promise((function(r){s._callCppProxy("rtcSignaling",e,t,n,i,(function(e){var t=new Uint8Array(e).buffer;r({code:o.ErrorCode.SUCCESS,buffer:t})}),(function(e){r({code:e})}))}))},e.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,o){var n=e.rtcHeartbeatResolves[t];if(n){var r=n.find((function(e){return""===e.seqId}));r&&(r.seqId=o)}}),(function(t,o,n){var r=e.rtcHeartbeatResolves[t];if(r){var s=r.findIndex((function(e){return e.seqId===n}));-1!==s&&r.splice(s,1)[0].resolve(o)}}))},e.prototype.rtcPing=function(e,t,o){var n=this;return new Promise((function(t){var o={resolve:t,seqId:""},r=n.rtcHeartbeatResolves[e];r?r.push(o):n.rtcHeartbeatResolves[e]=[o],n._callCppProxy("sendRTCHeartbeat",[e])}))},e.prototype.createTag=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){n({code:o.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},e.prototype.removeTag=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("deleteTag",e,(function(){n({code:o.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},e.prototype.updateTag=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){n({code:o.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},e.prototype.getTagList=function(){var e=this;return new Promise((function(t,n){var r=e._callCppProxy("getTags");e._electronLogger.info("getTagList -> ",r);var s=e._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:o.ErrorCode.SUCCESS,data:s})}))},e.prototype.addTagForConversations=function(e,t){var n=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));n._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.removeTagForConversations=function(e,t){var n=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),n._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.removeTagsForConversation=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.getConversationListByTag=function(e,t,n,r){var s=this;return new Promise((function(i,a){var c=s._callCppProxy("getConversationsForTagByPage",e,t,n||20,r||"");s._electronLogger.info("getConversationListByTag -> ",c);var u=s._convertResultList(c,(function(e){return f(f({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:o.ErrorCode.SUCCESS,data:u})}))},e.prototype.getUnreadCountByTag=function(e,t){var n=this;return new Promise((function(r,s){var i=n._callCppProxy("getConversationUnreadCountForTag",e,t);n._electronLogger.info("getUnreadCountByTag -> ",i),r({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.setConversationStatusInTag=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",n.isTop||!1,(function(){s({code:o.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},e.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(n,r){var s=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||"");t._electronLogger.info("getTagsForConversation -> ",s);var i=t._convertResultList(s,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));n({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},e.prototype.getTopConversationList=function(){throw new Error("Method not implemented.")},e.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},e.prototype.getAllUnreadMentionedCount=function(){throw new Error("Method not implemented.")},e.prototype.getOSInfo=function(){return g(this,void 0,void 0,(function(){var e;return h(this,(function(t){return e={arch:u.arch(),platform:u.platform(),type:u.type(),version:u.version(),release:u.release(),uptime:u.uptime(),cpus:u.cpus(),freemem:u.freemem(),totalmem:u.totalmem(),networkInterfaces:u.networkInterfaces()},[2,{code:o.ErrorCode.SUCCESS,data:e}]}))}))},e.prototype.getMainProcessInfo=function(){return g(this,void 0,void 0,(function(){return h(this,(function(e){return[2,{code:o.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()}}]}))}))},e.prototype.setCallInfo=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("callInfoSignaling",e,t,n,(function(e,t){s({code:o.ErrorCode.SUCCESS,data:{key:e,value:t}})}),(function(e){s({code:e})}))}))},e}(),L=function(){function e(e,t,o){void 0===t&&(t=""),void 0===o&&(o=!1),this._cppProtocol=e,this._dbpath=t,this._reconnectKickEnable=o,this._cppService=new M(this._cppProtocol,this._dbpath,this._reconnectKickEnable)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){e._cppService.destroy()}}},e.prototype.destroy=function(){this._cppService.destroy()},e}();module.exports=function(e){return function(e,t){return o.assert("options.reconnectKickEnable",null==t?void 0:t.reconnectKickEnable,o.AssertRules.BOOLEAN),o.logger.init({customLogPrint:null==t?void 0:t.logStdout,localLogLevel:null==t?void 0:t.logLevel}),S.setLogLevel(null==t?void 0:t.logLevel),S.setLogStdout(null==t?void 0:t.logStdout),new L(e,null==t?void 0:t.dbpath,null==t?void 0:t.reconnectKickEnable)}(C,e)};
1
+ "use strict";var e=require("os"),t=require("path"),o=require("@rongcloud/engine"),n=require("electron"),r=require("fs"),s=require("crypto"),i=require("http"),a=require("https");function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var u=c(e),p=process.versions.electron.replace(/\.\d+$/,""),l=t.resolve(__dirname,"binding","electron-v".concat(p,"-").concat(e.platform(),"-").concat(e.arch(),".node")),d={addon:null};try{d.addon=require(l)}catch(e){console.error("error ->",l,"\n",e)}var C=d.addon,f=function(){return f=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},f.apply(this,arguments)};function g(e,t,o,n){return new(o||(o=Promise))((function(r,s){function i(e){try{c(n.next(e))}catch(e){s(e)}}function a(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,a)}c((n=n.apply(e,t||[])).next())}))}function h(e,t){var o,n,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(s){return function(a){return function(s){if(o)throw new TypeError("Generator is already executing.");for(;i;)try{if(o=1,n&&(r=2&s[0]?n.return:s[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,s[1])).done)return r;switch(n=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],n=0}finally{o=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}function _(e,t,o){if(o||2===arguments.length)for(var n,r=0,s=t.length;r<s;r++)!n&&r in t||(n||(n=Array.prototype.slice.call(t,0,r)),n[r]=t[r]);return e.concat(n||Array.prototype.slice.call(t))}var v,S=new o.Logger("RCMain"),y=null,E=function(){var t,o=Date.now(),n=[e.arch(),e.platform(),process.pid,o,Math.floor(Math.random()*o)].join("__");return t=n,s.createHash("md5").update(t).digest("hex")},m=function(e){if(y)return y;var o=t.resolve(e,"deviceId");return S.debug("deviceIdPath -> ".concat(o)),r.existsSync(o)?y=r.readFileSync(o).toString():(y=E(),S.debug("createDeviceId -> ".concat(y)),r.writeFileSync(o,y),y)},P=function(){function e(e,t){this._timerId=0,this._heartbeatTimeoutId=0,this._isFirstPing=!0,this._lossCount=0,this._hasPingRes=e,this._reconnect=t}return e.init=function(t,o){return v?(v.stop(),v):v=new e(t,o)},e.prototype.start=function(e){var t=this,o=this,n=function(){var r=t._isFirstPing?0:15e3;o._timerId=setTimeout((function(){o._isFirstPing=!1,S.debug("current lossCount: ".concat(o._lossCount)),o._hasPingRes?(e(),o._hasPingRes=!1,n()):o._lossCount<4?(o._lossCount++,e(),n()):o._reconnect()}),r)};n()},e.prototype.stop=function(){this._lossCount=0,clearTimeout(this._timerId)},e.prototype.setHeartbeatRes=function(e){S.debug("receive ping"),this._hasPingRes=e,this._lossCount=0},e}(),T=function(){function e(e){this._setTime=15962112e5,this._cppProto=e}return e.prototype._setToProtocol=function(e,t,o,n,r){var s=JSON.stringify(n);S.info("MsgExpansion._setToProtocol ===>",e,t,o,s,r),this._cppProto.setMessageExtension(e,t,o,s,r)},e.prototype.setLocalFromReceiveMsg=function(e){S.info("MsgExpansion.setLocalFromReceiveMsg ===>",e);var t=e.channelId,o=e.conversationType,n=e.targetId,r=e.messageUId,s=e.expansion,i=e.sentTime,a={};for(var c in s)a[c]={v:"",ts:0},a[c].v=s[c],a[c].ts=i;this._setToProtocol(o,n,r,a,t||"")},e.prototype.setLocalFromExtMsg=function(e){S.info("MsgExpansion.setLocalFromExtMsg ===>",e);var t=e.channelId,o=e.conversationType,n=e.targetId;e.messageUId;var r=e.content,s=e.sentTime,i=r,a=i.put,c=this._cppProto.getMessage(i.mid),u=JSON.parse(c).extMsg,p=JSON.parse(u||"{}");if(S.info("MsgExpansion.setLocalFromExtMsg, serverExtObj",a,"localExt",p),a)for(var l in a){var d=p[l];d&&d.ts<s-this._setTime?(d.v=a[l],d.ts=s-this._setTime):(p[l]={v:"",ts:0},p[l].v=a[l],p[l].ts=s-this._setTime)}i.del&&i.del.forEach((function(e){delete p[e]})),this._setToProtocol(o,n,i.mid,p,t||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),o={};for(var n in t)o[n]=t[n].v;return o},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),o=JSON.parse(t||"{}"),n={};for(var r in o)n[r]=o[r].v;return n},e}(),I=null;function N(e,t,o,n){return new Promise((function(r){var s=/^https/.test(e),c={headers:{appId:t},method:"POST"};s&&(c.rejectUnauthorized=n,c.agent=new a.Agent(c));var u=(s?a.request:i.request)(e,c,(function(e){var t=e.statusCode,o="";e.setEncoding("utf8"),e.on("data",(function(e){o+=e})),e.on("end",(function(){r({status:t||0,data:o})}))}));u.on("error",(function(e){S.error(e),r({status:0})})),u.write(o),u.end()}))}function R(e,t,o,n,r){return void 0===r&&(r=!0),g(this,void 0,void 0,(function(){var s;return h(this,(function(i){switch(i.label){case 0:return I?[2,I]:(I=function(e,t,o,n,r){return void 0===r&&(r=!0),g(this,void 0,void 0,(function(){var s,i,a,c,u,p,l;return h(this,(function(d){switch(d.label){case 0:s="token=".concat(encodeURIComponent(n),"&v=").concat((C=e,C.match(/\d+(\.\d+){2}/)[0]),"&p=PC&ev=").concat("5.5.5"),i=0,a=t.length,d.label=1;case 1:return i<a?(c="".concat(t[i],"/navi.json?r=").concat(Date.now()),S.info("request navi -> url: ".concat(c,", body: ").concat(s)),[4,N(c,o,s,r)]):[3,4];case 2:if(200!==(u=d.sent()).status)return S.error("request navi failed -> ".concat(c)),u.data&&S.error(u.data),[3,3];S.info("request navi success -> ".concat(c));try{return p=JSON.parse(u.data),l=/^https/.test(c)?"https":"http",p.protocol=l,[2,p]}catch(e){S.error("parse navi err => ".concat(u.data))}d.label=3;case 3:return i+=1,[3,1];case 4:return[2,null]}var C}))}))}(e,t,o,n,r),[4,I]);case 1:return s=i.sent(),I=null,[2,s]}}))}))}var L=function(){function e(e,t,r){void 0===t&&(t=""),void 0===r&&(r=!1);var s=this;this._cppProtocol=e,this._dbpath=t,this._reconnectKickEnable=r,this._currentToken="",this._connectionStatus=o.ConnectionStatus.DISCONNECTED,this._promiseHandler={},this._customMessageType={},this._connectedTime=0,this._currentUserId="",this._inited=!1,this._naviInfo=null,this._version="5.5.5",this._electronLogger={debug:this._superElectronLog.bind(this,"debug",o.LogLevel.DEBUG),info:this._superElectronLog.bind(this,"info",o.LogLevel.INFO),warn:this._superElectronLog.bind(this,"warn",o.LogLevel.WARN),error:this._superElectronLog.bind(this,"error",o.LogLevel.ERROR),fatal:this._superElectronLog.bind(this,"fatal",o.LogLevel.FATAL)},this._logger={debug:this._superLog.bind(this,"debug",o.LogLevel.DEBUG),info:this._superLog.bind(this,"info",o.LogLevel.INFO),warn:this._superLog.bind(this,"warn",o.LogLevel.WARN),error:this._superLog.bind(this,"error",o.LogLevel.ERROR),fatal:this._superLog.bind(this,"fatal",o.LogLevel.FATAL)},this._senders={},this.rtcHeartbeatResolves={},n.ipcMain.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return g(s,void 0,void 0,(function(){var r,s,i,a;return h(this,(function(c){switch(c.label){case 0:if((a=this._electronLogger).debug.apply(a,_(["__RC_CHANNEL_CALL_MAIN_SYNC__",t],n,!1)),"function"!=typeof(r=this[t]))return e.returnValue=o.ErrorCode.NOT_SUPPORT,[2];s=o.ErrorCode.EXTRA_METHOD_UNDEFINED,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,r.call.apply(r,_([this],n,!1))];case 2:return s=c.sent(),[3,4];case 3:return i=c.sent(),this._electronLogger.error("call main process method `".concat(t,"` failed.")),this._electronLogger.error(i),[3,4];case 4:return e.returnValue=s,[2]}}))}))})),n.ipcMain.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var r=[],i=3;i<arguments.length;i++)r[i-3]=arguments[i];return g(s,void 0,void 0,(function(){var s,i,a,c,u,p=this;return h(this,(function(l){switch(l.label){case 0:if((u=this._electronLogger).debug.apply(u,_(["__RC_CHANNEL_CALL_MAIN__",t,n],r,!1)),"function"!=typeof(s=this[n]))return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,o.ErrorCode.NOT_SUPPORT),[2];"sendMessage"===n&&(i=r[3],r[3]=function(t){p._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",i,t)}),a=o.ErrorCode.EXTRA_METHOD_UNDEFINED,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,s.call.apply(s,_([this],r,!1))];case 2:return a=l.sent(),[3,4];case 3:return c=l.sent(),this._electronLogger.error("call main process method `".concat(n,"` failed.")),this._electronLogger.error(c),[3,4];case 4:return this._electronLogger.debug("__RC_CHANNEL_RESULT_FROM_MAIN__",t,n,a),this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,a),[2]}}))}))})),n.ipcMain.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var o,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];(o=s._electronLogger).debug.apply(o,_(["__RC_CHANNEL_CALL_MAIN__",t],n,!1));var i=s[t];if("function"==typeof i)try{i.call.apply(i,_([s],n,!1))}catch(e){s._electronLogger.error("call main process method `".concat(t,"` failed.")),s._electronLogger.error(e)}else s._electronLogger.error("cannot not found method: ".concat(t))})),n.ipcMain.on("__RC_INNER_COMMAND_INIT__",this._init.bind(this)),this._msgExpansionHandler=new T(this._cppProtocol)}return e.prototype._callCppProxy=function(e){for(var t,o,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];try{return(t=this._cppProtocol)[e].apply(t,n)}catch(t){(o=this._electronLogger).error.apply(o,_([t,e],n,!1))}},e.prototype._superElectronLog=function(e,t){for(var n,r=[],s=2;s<arguments.length;s++)r[s-2]=arguments[s];if(null===(n=S[e])||void 0===n||n.call.apply(n,_([S],r,!1)),t!==o.LogLevel.DEBUG){var i=Object.keys(this._senders);if(i.length>0){var a=r.reduce((function(e,t){return e+JSON.stringify(t)}),"");this._senders[i[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,a,"RCMain")}}},e.prototype._superLog=function(e,t,n,r,s){var i;if(null===(i=o.logger[e])||void 0===i||i.call(o.logger,n,r,s),t!==o.LogLevel.DEBUG){var a=Object.keys(this._senders);a.length>0&&this._senders[a[0]].send("__RC_CHANNEL_CALL_RENDER__","_insertLog2IndexDB",t,r,n,null==s?void 0:s.logSource)}},e.prototype.getCppProto=function(){return this._cppProtocol},e.prototype.callExtra=function(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];(t=this._electronLogger).info.apply(t,_(["callExtra -> ".concat(e)],n,!1));var s=this[e];if(!s)return this._electronLogger.warn("ExtraHandler.".concat(e," is undefined")),Promise.resolve({code:o.ErrorCode.EXTRA_METHOD_UNDEFINED});try{return s.call.apply(s,_([this],n,!1))}catch(e){this._electronLogger.error(e)}return Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})},e.prototype.getConversationsByPage=function(e,t,n,r){var s,i=this,a=this._callCppProxy("getConversationListByPage",e,t,n,r||"");try{s=JSON.parse(a).list.map((function(e){return i._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:s})},e.prototype.getConversationListWithAllChannel=function(){var e,t=this,n=[o.ConversationType.PRIVATE,o.ConversationType.GROUP],r=this._callCppProxy("getConversationListWithAllChannel",n);try{e=JSON.parse(r).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:e})},e.prototype.getConversationListWithAllChannelByPage=function(e,t){var n,r=this,s=[o.ConversationType.PRIVATE,o.ConversationType.GROUP],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,e,t);try{n=JSON.parse(i).list.map((function(e){return r._buildConversation(e.obj)}))}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:n})},e.prototype.getHistoryMessagesByObjectNames=function(e,t,n,r,s,i,a){var c=0===i,u=r+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,n,u,s,c,a||""),l=[];try{var d=JSON.parse(p).list;d.reverse();for(var C=0;C<d.length;C++){var f=this._buildMessage(d[C].obj);l[C]=f}}catch(e){return this._electronLogger.error(e),Promise.resolve({code:o.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.ErrorCode.SUCCESS,data:{list:u===l.length?l.slice(1,u):l,hasMore:r<l.length}})},e.prototype.updateMessageReceiptStatus=function(e,t,n,r){void 0===r&&(r=""),this._electronLogger.info("updateMessageReceiptStatus ->",e,t,n,r);var s=this._callCppProxy("updateMessageReceiptStatus",e,t,n,r);return Promise.resolve({code:o.ErrorCode.SUCCESS,data:s})},e.prototype.requestNaviInfo=function(e,t,o,n){return g(this,void 0,void 0,(function(){return h(this,(function(r){return[2,R(this._initOptions.apiVersion,e,t,o,n)]}))}))},e.prototype.updateNaviInfo=function(e){this._naviInfo=e},e.prototype.getNaviInfoFromCache=function(){return this._naviInfo?f({},this._naviInfo):null},e.prototype.getConnectedTime=function(){return this._connectedTime},e.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},e.prototype.getCurrentUserId=function(){var e;return(null===(e=this._naviInfo)||void 0===e?void 0:e.userId)||""},e.prototype._send2Renderer=function(e,t){for(var o=[],n=2;n<arguments.length;n++)o[n-2]=arguments[n];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,_([t],o,!1))},e.prototype._send2AllRenderer=function(e,t,o){var n=this;void 0===o&&(o=[]),Object.keys(this._senders).forEach((function(r){var s=n._senders[r];o.includes(s)||n._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},e.prototype._init=function(e,r){var s=this,i=e.sender,a=i.id;if(this._senders[a]||(this._senders[a]=i,i.once("destroyed",(function(){delete s._senders[a]}))),!this._inited){this._inited=!0,this._initOptions=r,this._electronLogger.info("init ->",r);var c=this._dbpath||t.resolve(n.app.getPath("userData"));this._logger.info(o.LogTagId.P_INIT_O,{"proto-commitId":this._cppProtocol.getNodeVersion(),appkey:r.appkey,dbpath:c}),this._callCppProxy("initWithAppkey",r.appkey,c),this._electronLogger.warn("cppProto version ->",this._cppProtocol.getNodeVersion()),this._registerMsgTypes();var u=m(c);this._electronLogger.info("deviceId -> ".concat(u)),this._callCppProxy("setDeviceId",u),this._setConnectionStatusListener(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener()}},e.prototype._registerMsgTypes=function(){for(var e in o.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},o.SEND_MESSAGE_TYPE_OPTION){var t=o.SEND_MESSAGE_TYPE_OPTION[e],n=t.isCounted,r=0;t.isPersited&&(r|=1),n&&(r|=2),"RC:TypSts"===e&&(r=16),this._electronLogger.info("_registerMsgTypes ====>",e,r),this._callCppProxy("registerMessageType",e,r)}},e.prototype._buildMessage=function(e,t){void 0===t&&(t={});var n=t.isOffLineMessage,r=t.buildFrom,s=JSON.parse(e);this._electronLogger.debug("_buildMessage:",s);var i=s.channelId,a=s.conversationType,c=s.targetId,u=s.senderUserId,p=s.content,l=s.objectName,d=s.messageUid,C=s.direction,g=s.status;s.source;var h=s.messageId,_=s.sentTime,v=s.readReceiptRequest,y=s.supportExt;s.extMsg;var E,m=s.pushContent,P=s.pushTitle,T=s.pushId,I=s.pushConfig,N=s.templateId,R=s.disableTitle,L=s.forcePushDetail;if(o.isObject(p))E=p;else try{E=p?JSON.parse(p):p}catch(e){S.warn("cpp engine build messaga error:",e),E=p}var M={isCounted:!1,isPersited:!1};l in o.SEND_MESSAGE_TYPE_OPTION?M=o.SEND_MESSAGE_TYPE_OPTION[l]:l in this._customMessageType&&(M=this._customMessageType[l]);var O=null;y&&(O=this._msgExpansionHandler.parseReceiveExpansion(s),"conversation"!==r&&"history"!==r||(O=this._msgExpansionHandler.parseConverOrHisExpansion(s)));var b=o.isUndefined(n)?_<this._connectedTime:n,U={};I&&(U=o.pushJSONToConfigs(I,T));var x=f(f({},U),{pushTitle:P,pushContent:m,pushData:m,disablePushTitle:R,forceShowDetailContent:L,templateId:N}),w={channelId:i,conversationType:a,targetId:c,senderUserId:u,content:E||{},messageType:l,messageUId:d,messageDirection:C,isOffLineMessage:b,sentTime:_,receivedTime:0,isPersited:M.isPersited,isCounted:M.isCounted,isMentioned:!1,disableNotification:!1,isStatusMessage:!1,canIncludeExpansion:y,expansion:y?O:null,receivedStatus:g,messageId:h,pushConfig:x};if(C===o.MessageDirection.RECEIVE?w.receivedStatus=g:C===o.MessageDirection.SEND&&(w.sentStatus=g),v){var A=JSON.parse(v),D=A.hasRespond,H=A.readerInfo,k={hasRespond:D,readCount:A.readCount,totalCount:A.totalCount},F=[];if(H)for(var J in H)F.push({userId:J,readTime:H[J]});k.readerList=F,w.readReceiptInfo=k}return w},e.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),n=JSON.parse(o),r=n.readReceiptRequest?JSON.parse(n.readReceiptRequest):{},s=f(f({},r),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},e.prototype._buildConversation=function(e){var t=JSON.parse(e);this._electronLogger.debug("_buildConversation",t);var n=t.channelId,r=t.conversationType,s=t.targetId,i=t.unreadCount,a=t.lastestMsg,c=t.isTop,u=t.isBlocked,p=t.matchCount,l=u?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE;return{channelId:n,conversationType:r,targetId:s,unreadMessageCount:i,latestMessage:-1===JSON.parse(a).messageId?null:this._buildMessage(a),hasMentioned:!1,mentionedInfo:null,notificationStatus:l,isTop:c,lastUnreadTime:0,matchCount:p}},e.prototype._sendConnectionStatus2Renderer=function(e){this._send2AllRenderer("status",e)},e.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}))},e.prototype._connectResolve=function(e){this._promiseHandler.connect&&this._promiseHandler.connect.length>0&&(this._promiseHandler.connect.forEach((function(t){t.resolve(e)})),delete this._promiseHandler.connect)},e.prototype._setConnectionStatusListener=function(){var e=this;this._cppProtocol.setConnectionStatusListener((function(t){var n,r;switch(e._electronLogger.warn("protocol connection status changed:",t),t){case 10:r=o.ConnectionStatus.CONNECTING;break;case 31004:return void setTimeout((function(){e._connectResolve(o.ErrorCode.RC_CONN_USER_OR_PASSWD_ERROR)}));case 12:r=o.ConnectionStatus.DISCONNECTED;break;case 13:r=o.ConnectionStatus.BLOCKED,setTimeout((function(){e._connectResolve(o.ErrorCode.RC_CONN_USER_BLOCKED)}));break;case 31023:r=o.ConnectionStatus.FORBID_RECONNECT_BY_OTHER_SAME_CLIENT,setTimeout((function(){e._connectResolve(o.ErrorCode.RC_DISCONN_SAME_CLIENT_ON_LINE)}));break;case 1:case 9:case 11:case 31011:case 3e4:case 30002:r=o.ConnectionStatus.NETWORK_UNAVAILABLE;break;case 30010:r=o.ConnectionStatus.NETWORK_UNAVAILABLE,setTimeout((function(){e._connectionStatus===o.ConnectionStatus.NETWORK_UNAVAILABLE&&e._doConnect()}),5e3);break;case 0:case 33005:r=o.ConnectionStatus.CONNECTED,e._connectedTime=Date.now()-e._cppProtocol.getDeltaTime(),setTimeout((function(){e._connectResolve(o.ErrorCode.SUCCESS),e._heartbeat=P.init(!0,e._handleHeartTimeout.bind(e)),e._heartbeat.start(e._sendHeartbeat.bind(e))}));break;case o.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT:r=o.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT;break;case 30004:return;case 8:case 31006:case 32061:case 32012:r=o.ConnectionStatus.REDIRECT;break;default:r=t}r!==o.ConnectionStatus.CONNECTED&&(null===(n=e._heartbeat)||void 0===n||n.stop()),e._connectionStatus=r,e._logger.info(o.LogTagId.P_CONNECT_S,{status:t}),e._sendConnectionStatus2Renderer(r)}),this._dbOpenCallback,(function(){var t;null===(t=e._heartbeat)||void 0===t||t.setHeartbeatRes(!0)}))},e.prototype._handleHeartTimeout=function(){var e,t=this;S.warn("network unavailable! try to reconnect!"),this._sendConnectionStatus2Renderer(o.ConnectionStatus.NETWORK_UNAVAILABLE),null===(e=this._heartbeat)||void 0===e||e.stop(),setTimeout((function(){return t._doConnect()}),5e3)},e.prototype._dbOpenCallback=function(e){S.info("Sqlite DB Open -> ".concat(e))},e.prototype._sendHeartbeat=function(){S.debug("send ping"),this._cppProtocol.sendHeartbeat()},e.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,n,r,s){var i=e._buildMessage(t,{isOffLineMessage:r});if(i.messageType===o.MessageType.GROUP_READ_RECEIPT_REQUEST){var a=i.content,c=a.msgId,u=a.rrn,p=a.tmn;e._updateReadReceiptInfo(c,{readCount:u,totalCount:p})}if("RC:MsgExMsg"===i.messageType)return e._msgExpansionHandler.setLocalFromExtMsg(i),void e._sendMessageExpansion(i);if(i.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(i),i.messageType===o.MessageType.SYNC_READ_STATUS){if(i.senderUserId!==e._currentUserId)return;e._callCppProxy("clearUnreadCountByTimestamp",i.conversationType,i.targetId,i.content.lastMessageSendTime,i.channelId||"")}var l=!0;if(0!==n||s||(l=!1),i.messageType!==o.MessageType.LOG_COMMAND||"rongcloudsystem"!==i.senderUserId){var d=i.conversationType,C=i.targetId;i.messageType===o.MessageType.RECALL&&i.senderUserId===e._currentUserId&&(d=i.content.conversationType||d,C=i.content.targetId||C),e._sendMessageNotification(Object.assign(i,{hasMoreMsg:l,conversationType:d,targetId:C}))}else{var f=Object.keys(e._senders).map((function(t){return e._senders[t]}));f.length>0&&e._sendMessageNotification(Object.assign(i,{hasMoreMsg:l}),f.slice(1))}}),(function(){e._sendPullOfflineFinished()}))},e.prototype._sendMessageExpansion=function(e,t){void 0===t&&(t=[]);var o=e.channelId,n=e.content,r=n.put,s=n.del,i=n.mid,a={};r&&(a.updatedExpansion={channelId:o,messageUId:i,expansion:r}),s&&(a.deletedExpansion={channelId:o,messageUId:i,deletedKeys:s}),this._send2AllRenderer("expansion",a,t)},e.prototype._sendMessageNotification=function(e,t){void 0===t&&(t=[]),this._send2AllRenderer("batchMessage",e,t)},e.prototype._sendPullOfflineFinished=function(){this._send2AllRenderer("pullFinished",null)},e.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var n=JSON.parse(t).list,r=[];n.forEach((function(e){var t=JSON.parse(e.obj),n=t.conversationType,s=t.targetId,i=t.status,a=t.channelId,c={notificationStatus:2,isTop:!1};i.forEach((function(e){var t=JSON.parse(e.item);1===t.type?c.notificationStatus=1===Number(t.value)?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE:c.isTop=1===Number(t.value)})),r.push({channelId:a,conversationType:n,targetId:s,updatedItems:{notificationStatus:{val:c.notificationStatus,time:0},isTop:{val:c.isTop,time:0}}})})),e._send2AllRenderer("conversation",r)}),(function(t){e._electronLogger.info("会话标签状态变更",t),e._send2AllRenderer("conversationTag",t)}))},e.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._electronLogger.info("标签变更",t),e._send2AllRenderer("tag",t),e._getRTCProfile()}))},e.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e&&this._naviInfo&&this._naviInfo.voipCallInfo!==e){var t=f(f({},this._naviInfo),{voipCallInfo:e});this._naviInfo=t,this._send2AllRenderer("onNaviDataChange",t)}},e.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var o=new Uint8Array(t).buffer;e._send2AllRenderer("onRTCDataChange",o)}))},e.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._send2AllRenderer("chatroom",{chatroomDestroyed:t})}))},e.prototype._clearListener=function(){this._cppProtocol.setOnReceiveMessageListener(),this._cppProtocol.setConnectionStatusListener(),this._cppProtocol.setOnReceiveStatusListener(),this._cppProtocol.setUserProfileListener()},e.prototype.registerMessageType=function(e,t,n,r){var s=0;t&&(s|=1),n&&(s|=2),this._customMessageType[e]={isCounted:n,isPersited:t},this._logger.info(o.LogTagId.P_REGTYP_O,{messageType:e,isCounted:n,searchProps:r,isPersited:t}),this._callCppProxy("registerMessageType",e,s,r)},e.prototype.connect=function(e,t,n,r){var s=this;return this._electronLogger.info("connect ->",e,t,n),this._logger.info(o.LogTagId.P_CONNECT_O,{token:e,reconnectKickEnable:n,version:this._version},{traceId:r}),this._currentToken===e&&this._connectionStatus===o.ConnectionStatus.CONNECTED?(this._sendConnectionStatus2Renderer(this._connectionStatus),Promise.resolve(o.ErrorCode.SUCCESS)):(this._currentToken=e,this._naviInfo=t,this._currentUserId=t.userId,this._promiseHandler.connect||this._doConnect(n),new Promise((function(e,t){s._promiseHandler.connect?s._promiseHandler.connect.push({resolve:e,reject:t}):s._promiseHandler.connect=[{resolve:e,reject:t}]})))},e.prototype._doConnect=function(e){var t=o.isUndefined(e)?!!this._reconnectKickEnable:!!e;this._callCppProxy("connectWithToken",this._currentToken,this._initOptions.apiVersion,JSON.stringify(this._naviInfo),t)},e.prototype.reportSDKInfo=function(e){var t,o;null===(o=(t=this._cppProtocol).uploadSDKVersion)||void 0===o||o.call(t,JSON.stringify(e)),this._electronLogger.info(e)},e.prototype.disconnect=function(){var e;this._cppProtocol.disconnect(!0),null===(e=this._heartbeat)||void 0===e||e.stop(),this._connectResolve(o.ErrorCode.TIMEOUT)},e.prototype.logout=function(){this.disconnect()},e.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)},e.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("subscribeUserStatus",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.setUserStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("setUserStatus",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.getUserStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("getUserStatus",e,(function(e){n({code:o.ErrorCode.SUCCESS,data:{status:e}})}),(function(e){n({code:e})}))}))},e.prototype.sendMessage=function(e,t,n,r,s){var i=this,a=n.messageType,c=n.content,u=n.pushContent,p=n.pushData,l=n.directionalUserIdList,d=n.disableNotification,C=n.canIncludeExpansion,f=n.expansion,g=n.isVoipPush,h=n.pushConfig,_=n.channelId,v=n.isMentioned,S=n.mentionedType,y=n.mentionedUserIdList,E=n.messageId,m=h||{},P=m.iOSConfig,T=m.androidConfig,I=m.pushTitle,N=m.pushContent,R=m.pushData,L=m.disablePushTitle,M=m.forceShowDetailContent,O=m.templateId,b=o.pushConfigsToJSON(P,T);return new Promise((function(n){u=N||u||"",p=R||p||"",d=d||!1,g=g||!1,I=I||"",N=N||"",R=R||"",L=L||!1,M=M||!1,C=C||!1;var h=(null==T?void 0:T.notificationId)||"";if(l=l||[],E=E||0,_=_||"",e===o.ConversationType.GROUP&&v&&c&&(c.mentionedInfo={userIdList:y,type:S||o.MentionedType.ALL}),e===o.ConversationType.GROUP&&a===o.MessageType.READ_RECEIPT_RESPONSE&&c.receiptMessageDic)for(var m in c.receiptMessageDic)l.push(m);var P={};for(var m in f)P[m]={v:""},P[m].v=f[m];var U=O||"";E&&i._callCppProxy("setMessageContent",E,JSON.stringify(c),a),i._logger.info(o.LogTagId.P_SEND_MSG_T,{messageType:a,conversationType:e,targetId:t,channelId:_},{traceId:s});var x=i._callCppProxy("sendMessage",(function(e,t){var r=i._buildMessage(e,{isOffLineMessage:!1});return i._logger.info(o.LogTagId.P_SEND_MSG_R,{code:t,messageUId:r.messageUId,messageId:r.messageId},{traceId:s}),t===o.ErrorCode.SENSITIVE_REPLACE?n({code:t}):("RC:MsgExMsg"===r.messageType&&i._msgExpansionHandler.setLocalFromExtMsg(r),r.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(r),n({code:o.ErrorCode.SUCCESS,data:r}))}),(function(e,t){var r=i._buildMessage(e,{isOffLineMessage:!1});return i._logger.warn(o.LogTagId.P_SEND_MSG_R,{code:t,messageUId:r.messageUId,messageId:r.messageId},{traceId:s}),r.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),n({code:t,data:r})}),e,t,a,JSON.stringify(c),l,d,L,M,u,p,h,I,b,U,C,JSON.stringify(P),g,_,E),w=JSON.parse(x);null==r||r(w.messageId)}))},e.prototype.recallMsg=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){var u,p=s.user,l=s.pushContent,d=s.channelId,C=s.extra,f=s.pushConfig,g=s.disableNotification,h=s.isDelete,_={conversationType:e,targetId:t,messageUId:n,sentTime:r,user:p,extra:C,channelId:d,isDelete:h||!1};p&&(_.user=p),C&&(_.extra=C);var v={conversationType:e,targetId:t,senderUserId:i._currentUserId,content:_,objectName:o.MessageType.RECALL,messageUid:n,direction:o.MessageDirection.SEND,status:o.ReceivedStatus.UNREAD,sentTime:r,channelId:d},S=i._buildMessage(JSON.stringify(v),{isOffLineMessage:!1});i._callCppProxy("recallMessage",(function(){a({code:o.ErrorCode.SUCCESS,data:S})}),(function(e){a({code:e})}),o.MessageType.RECALL,JSON.stringify(_),g||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,l||"",(null==f?void 0:f.pushData)||"",(null===(u=null==f?void 0:f.androidConfig)||void 0===u?void 0:u.notificationId)||"",(null==f?void 0:f.pushTitle)||"",o.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",d)}))},e.prototype.getHistoryMessage=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(u,p){n=n||0;var l=0===s,d=r+1,C=c._callCppProxy("getHistoryMessages",e,t,n,d,a,l,i),f=JSON.parse(C).list,g=[];f.reverse();for(var h=0;h<f.length;h++){var _=c._buildMessage(f[h].obj);g[h]=_}u({code:o.ErrorCode.SUCCESS,data:{list:d===g.length?g.slice(1,d):g,hasMore:r<g.length}})}))},e.prototype.getRemoteHistoryMessages=function(e,t,n,r,s,i){var a=this;return new Promise((function(c,u){n=n||0;a._callCppProxy("getRemoteHistoryMessages",e,t,n,r,(function(e,t){var n=JSON.parse(e).list,r=[];n.reverse();for(var s=0;s<n.length;s++){var i=a._buildMessage(n[s].obj);r[s]=i}c({code:o.ErrorCode.SUCCESS,data:{list:r,hasMore:!!t}})}),(function(e){c({code:e})}),s,!0,i)}))},e.prototype.deleteRemoteMessage=function(e,t,n,r){var s=this;return new Promise((function(i,a){var c=JSON.stringify(n);s._callCppProxy("deleteRemoteHistoryMessages",e,t,c,!1,r,(function(){i(o.ErrorCode.SUCCESS)}),i)}))},e.prototype.deleteRemoteMessageByTimestamp=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearRemoteHistoryMessages",e,t,n,(function(){i(o.ErrorCode.SUCCESS)}),(function(e){i(e)}),r)}))},e.prototype.clearMessages=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("clearMessages",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.getConversationList=function(e,t,n,r,s){var i=this;return void 0===s&&(s=""),new Promise((function(e,t){for(var n=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(n).list,a=[],c=0;c<r.length;c++)a.push(i._buildConversation(r[c].obj));e({code:o.ErrorCode.SUCCESS,data:a})}))},e.prototype.getConversation=function(e,t,n){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversation",e,t,n);if(a)s({code:o.ErrorCode.SUCCESS,data:r._buildConversation(a)});else{var c=r._cppProtocol.getHistoryMessages(e,t,0,1,"",!0,n),u=void 0;try{u=JSON.parse(c).list}catch(e){r._electronLogger.warn("json parse cppMessagaes error",e),u=[]}var p=null;u.length>0&&(p=r._buildMessage(u[0].obj));var l=r._callCppProxy("getConversationNotificationStatus",e,t,n),d=r._callCppProxy("getConversationTopStatus",e,t,n);s({code:o.ErrorCode.SUCCESS,data:{conversationType:e,targetId:t,channelId:n,unreadMessageCount:0,latestMessage:p,notificationStatus:l?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},e.prototype.removeConversation=function(e,t,n){var r=this._callCppProxy("removeConversation",e,t,n);return this._electronLogger.info("removeConversation result -> ".concat(r)),Promise.resolve(r?o.ErrorCode.SUCCESS:o.ErrorCode.UNKNOWN)},e.prototype.clearConversations=function(e,t){var n=this;return new Promise((function(r,s){var i=[];i=o.isArray(e)?e:[o.ConversationType.PRIVATE,o.ConversationType.GROUP,o.ConversationType.SYSTEM,o.ConversationType.PUBLIC_SERVICE],n._callCppProxy("clearConversations",i,t),r(o.ErrorCode.SUCCESS)}))},e.prototype.getAllConversationUnreadCount=function(e,t,n){var r=this._callCppProxy("getTotalUnreadCount",t,n,e);return Promise.resolve({code:o.ErrorCode.SUCCESS,data:r})},e.prototype.getConversationUnreadCount=function(e,t,n){var r=this;return void 0===n&&(n=""),new Promise((function(s){var i=r._callCppProxy("getUnreadCount",e,t,n);s({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.clearConversationUnreadCount=function(e,t,n){var r=this;return void 0===n&&(n=""),new Promise((function(s,i){r._callCppProxy("clearUnreadCount",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.clearUnreadCountByTimestamp=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("clearUnreadCountByTimestamp",e,t,n,r),i(o.ErrorCode.SUCCESS)}))},e.prototype.getFirstUnreadMessage=function(e,t,n){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getTheFirstUnreadMessage",e,t,n),c=r._buildMessage(a);s({code:o.ErrorCode.SUCCESS,data:-1!==c.messageId?c:null})}))},e.prototype.setConversationToTop=function(e,t,n,r){var s=this;return void 0===r&&(r=""),new Promise((function(i,a){s._electronLogger.info("setConversationToTop",e,t,n,r,true),s._callCppProxy("setConversationToTop",e,t,n,r,true),i(o.ErrorCode.SUCCESS)}))},e.prototype.setConversationHidden=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("setConversationHidden",e,t,n,r),i(o.ErrorCode.SUCCESS)}))},e.prototype.setConversationNotificationStatus=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._electronLogger.info("setConversationNotificationStatus",e,t,n,r),s._callCppProxy("setConversationNotificationStatus",e,t,n,(function(){i(o.ErrorCode.SUCCESS)}),i,r)}))},e.prototype.setConversationStatus=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){i._electronLogger.info("setConversationStatus",e,t,n,r,s,true),i._callCppProxy("setConversationStatus",e,t,n,r,(function(){a(o.ErrorCode.SUCCESS)}),a,s,true)}))},e.prototype.getConversationNotificationStatus=function(e,t,n){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getConversationNotificationStatus",e,t,n);s({code:o.ErrorCode.SUCCESS,data:a?o.NotificationStatus.OPEN:o.NotificationStatus.CLOSE})}))},e.prototype.searchConversationByContent=function(e,t,n,r){var s=this;return new Promise((function(i,a){r=r||[1,3,6,7];for(var c=s._callCppProxy("searchConversationByContent",r,e,t,n),u=JSON.parse(c).list,p=[],l=0;l<u.length;l++)p[l]=s._buildConversation(u[l].obj);i({code:o.ErrorCode.SUCCESS,data:p})}))},e.prototype.searchConversationByContentWithAllChannel=function(e,t,n){var r=this;return new Promise((function(s,i){n=n||[1,3,6,7];for(var a=r._callCppProxy("searchConversationByContentWithAllChannel",n,e,t),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=r._buildConversation(c[p].obj);s({code:o.ErrorCode.SUCCESS,data:u})}))},e.prototype.searchMessageByContent=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(i,u){c._callCppProxy("searchMessageByContent",e,t,n,r,s,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],r=[],s=0;s<n.length;s++)r[s]=c._buildMessage(n[s].obj);i({code:o.ErrorCode.SUCCESS,data:{messages:r,count:t}})}),a)}))},e.prototype.searchMessageByContentWithAllChannel=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("searchMessageByContentWithAllChannel",e,t,n,r,s,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],r=[],s=0;s<n.length;s++)r[s]=i._buildMessage(n[s].obj);a({code:o.ErrorCode.SUCCESS,data:{messages:r,count:t}})}))}))},e.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(u,p){c._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,n,r,s,i,a,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],r=0;r<t.length;r++)n[r]=c._buildMessage(t[r].obj);u({code:o.ErrorCode.SUCCESS,data:{messages:n}})}))}))},e.prototype.getUnreadMentionedMessages=function(e,t,o){for(var n=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,o)).list,r=0;r<n.length;r++)n[r]=this._buildMessage(n[r].obj);return n},e.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("addToBlacklist",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("removeFromBlacklist",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.getBlacklist=function(){var e=this;return new Promise((function(t,n){e._callCppProxy("getBlacklist",(function(e){t({code:o.ErrorCode.SUCCESS,data:e})}),(function(e){t({code:e})}))}))},e.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("getBlacklistStatus",e,(function(e){n({code:o.ErrorCode.SUCCESS,data:e})}),(function(e){n({code:e})}))}))},e.prototype.insertMessage=function(e,t,n){var r=this,s=n.content,i=n.senderUserId,a=n.messageType,c=n.messageDirection,u=n.readStatus,p=n.sentStatus,l=n.sentTime,d=n.searchContent,C=n.isUnread,f=n.messageUId,g=n.disableNotification,h=n.canIncludeExpansion,_=n.expansionMsg,v=n.channelId;return s=JSON.stringify(s),new Promise((function(n,S){var y=C?0:1,E=r._callCppProxy("insertMessage",e,t,i,a,s,(function(){}),(function(e){n({code:e})}),c,u,p,l,d,y,f,g,h,_,v);r._electronLogger.info("after insert msg",E);var m=r._buildMessage(E,{isOffLineMessage:!1});m.messageUId=f,m.sentTime=l,n({code:-1===m.messageId?o.ErrorCode.MSG_INSERT_ERROR:o.ErrorCode.SUCCESS,data:m})}))},e.prototype.deleteMessages=function(e){var t=this;return new Promise((function(n,r){t._logger.debug(o.LogTagId.P_DELETE_MSG_S,{messageIds:e}),t._callCppProxy("deleteMessages",e),n(o.ErrorCode.SUCCESS)}))},e.prototype.deleteMessagesByTimestamp=function(e,t,n,r,s){var i=this;return new Promise((function(a,c){i._callCppProxy("deleteMessagesByTimestamp",e,t,n,r,s),a(o.ErrorCode.SUCCESS)}))},e.prototype.getMessage=function(e){var t=this;return new Promise((function(n,r){var s=t._callCppProxy("getMessage",e);t._electronLogger.info("getMessage ===>",s);var i=t._buildMessage(s,{isOffLineMessage:!1});n({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.setMessageContent=function(e,t,n){var r=this;return new Promise((function(s,i){t=JSON.stringify(t),r._callCppProxy("setMessageContent",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.setMessageSearchField=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("setMessageSearchField",e,t,n),s(o.ErrorCode.SUCCESS)}))},e.prototype.setMessageSentStatus=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("setMessageSentStatus",e,t),r(o.ErrorCode.SUCCESS)}))},e.prototype.setMessageReceivedStatus=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("setMessageReceivedStatus",e,t),r(o.ErrorCode.SUCCESS)}))},e.prototype.saveConversationMessageDraft=function(e,t,o,n){throw new Error("Method not implemented.")},e.prototype.getConversationMessageDraft=function(e,t,o){throw new Error("Method not implemented.")},e.prototype.clearConversationMessageDraft=function(e,t,o){throw new Error("Method not implemented.")},e.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},e.prototype.batchSetConversationStatus=function(e){var t=e[0],n=t.conversationType,r=t.targetId,s=t.isTop,i=t.notificationStatus,a=t.channelId;if(void 0!==s&&void 0===i)return this.setConversationToTop(n,r,s,a);if(void 0!==i&&void 0===s){var c=i===o.NotificationStatus.OPEN;return this.setConversationNotificationStatus(n,r,c,a)}var u=i===o.NotificationStatus.OPEN;return this.setConversationStatus(n,r,u,s,a)},e.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},e.prototype.sendReadReceiptMessage=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("sendReadReceipt",e,n||"",t,(function(){t.forEach((function(e){r._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(r._callCppProxy("getMessage",e)).messageId;r.setMessageReceivedStatus(t,1)}catch(t){r._electronLogger.warn("format message error, messageUId: ".concat(e))}})),s({code:o.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},e.prototype.getMessageReader=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("getMessageReader",e,n,t,(function(e,n){r._electronLogger.info("getMessageReader -> ",e,n);var i=[],a={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,n=t.time;i.push({userId:o,readTime:n}),a[o]=n}));var c={readerInfo:a,readCount:i.length,totalCount:n};r._updateReadReceiptInfo(t,c),s({code:o.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:n}})}),(function(e){s({code:e})}))}))},e.prototype.joinChatroom=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("clearMessages",o.ConversationType.CHATROOM,e,""),n._callCppProxy("joinChatRoom",e,t,(function(){r(o.ErrorCode.SUCCESS)}),r)}))},e.prototype.joinExistChatroom=function(e,t){throw new Error("Method not implemented.")},e.prototype.quitChatroom=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("quitChatRoom",e,(function(){n(o.ErrorCode.SUCCESS)}),n)}))},e.prototype.getChatroomInfo=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("getChatroomInfo",e,t,n,(function(e,t){var n=e?JSON.parse(e).list:[],r=[];if(n.length>0)for(var i=0;i<n.length;i++)r.push(JSON.parse(n[i].obj));s({code:o.ErrorCode.SUCCESS,data:{userInfos:r,userCount:t}})}),(function(e){s({code:e})}))}))},e.prototype.getChatroomHistoryMessages=function(e,t,n,r){var s=this;return new Promise((function(i,a){s._callCppProxy("getChatroomHistoryMessage",e,t,n,r,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[]}}var n=t.list;if(n&&n.length)try{t.list=n.map((function(e){return s._buildMessage(e.obj)}))}catch(e){t.list=[]}i({code:o.ErrorCode.SUCCESS,data:t})}),(function(e){i({code:e})}),"")}))},e.prototype.setChatroomEntry=function(e,t){var n=this;return new Promise((function(r,s){var i='[{"key":"'.concat(t.key,'", "value":"').concat(t.value,'"}]');n._callCppProxy("setChatroomKV",e,i,!!t.isAutoDelete,!!t.isOverwrite,(function(){r(o.ErrorCode.SUCCESS)}),(function(e){r(e)}))}))},e.prototype.setChatroomEntries=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.setChatroomEntry(e,t)},e.prototype.removeChatroomEntry=function(e,t){var n=this,r=[t.key];return new Promise((function(s,i){n._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){s(o.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},e.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this._currentUserId,this.removeChatroomEntry(e,t)},e.prototype.removeChatroomEntries=function(e,t){var n=this;return new Promise((function(r){var s=t.entries.map((function(e){return e.key}));n._callCppProxy("deleteChatroomKV",e,s,!!t.isOverwrite,(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.getChatroomEntry=function(e,t){return g(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(n=r.sent()).code===o.ErrorCode.SUCCESS?[2,{code:o.ErrorCode.SUCCESS,data:n.data?n.data[t]:null}]:[2,{code:n.code}]}}))}))},e.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}n({code:o.ErrorCode.SUCCESS,data:t})}),(function(e){n({code:e})}))}))},e.prototype.getFileToken=function(e,t,n,r){var s=this;return n=n||"",r=r||"",new Promise((function(i){var a;a=r&&"uploads"!==r?t||"":o.getUploadFileName(e,t),s._callCppProxy("getUploadToken",e,a,n,r,(function(e,t,n,r,s,c,u,p,l,d,C,f,g,h,_,v,S,y){i({code:o.ErrorCode.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:n,path:r,osskeyId:s,ossPolicy:c,ossSign:u,ossBucketName:p,fileName:a,s3Credential:l,s3Algorithm:d,s3Date:C,s3Policy:f,s3Signature:g,s3BucketName:h,stcAuthorization:_,stcContentSha256:v,stcDate:S,stcBucketName:y}})}),(function(e){i({code:e})}))}))},e.prototype.getFileUrl=function(e,t,n,r){var s=this;return new Promise((function(i){s._callCppProxy("getDownloadUrl",e,n,r,t-1,(function(e){i({code:o.ErrorCode.SUCCESS,data:{downloadUrl:e}})}),(function(e){i({code:e})}))}))},e.prototype.clearData=function(){var e=this;return new Promise((function(t,n){var r=e._callCppProxy("clearData");t({code:o.ErrorCode.SUCCESS,data:r})}))},e.prototype.getDeviceId=function(){var e=this._dbpath||t.resolve(n.app.getPath("userData"));return m(e)},e.prototype.getVoIPKey=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("getVoIPKey",e,t,"",(function(e){r({code:o.ErrorCode.SUCCESS,data:e})}),(function(e){r({code:e})}))}))},e.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(n,r){var s=e.chatRoomId,i=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",s,i,(function(){n(o.ErrorCode.SUCCESS)}),(function(e){n(e)}))}))},e.prototype.rtcSignaling=function(e,t,n,r){var s=this,i=Array.prototype.slice.call(new Uint8Array(r));return new Promise((function(r){s._callCppProxy("rtcSignaling",e,t,n,i,(function(e){var t=new Uint8Array(e).buffer;r({code:o.ErrorCode.SUCCESS,buffer:t})}),(function(e){r({code:e})}))}))},e.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,o){var n=e.rtcHeartbeatResolves[t];if(n){var r=n.find((function(e){return""===e.seqId}));r&&(r.seqId=o)}}),(function(t,o,n){var r=e.rtcHeartbeatResolves[t];if(r){var s=r.findIndex((function(e){return e.seqId===n}));-1!==s&&r.splice(s,1)[0].resolve(o)}}))},e.prototype.rtcPing=function(e,t,o){var n=this;return new Promise((function(t){var o={resolve:t,seqId:""},r=n.rtcHeartbeatResolves[e];r?r.push(o):n.rtcHeartbeatResolves[e]=[o],n._callCppProxy("sendRTCHeartbeat",[e])}))},e.prototype.createTag=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){n({code:o.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},e.prototype.removeTag=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("deleteTag",e,(function(){n({code:o.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},e.prototype.updateTag=function(e){var t=this;return new Promise((function(n,r){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){n({code:o.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},e.prototype.getTagList=function(){var e=this;return new Promise((function(t,n){var r=e._callCppProxy("getTags");e._electronLogger.info("getTagList -> ",r);var s=e._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:o.ErrorCode.SUCCESS,data:s})}))},e.prototype.addTagForConversations=function(e,t){var n=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));n._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.removeTagForConversations=function(e,t){var n=this;return new Promise((function(r,s){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),n._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.removeTagsForConversation=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){r({code:o.ErrorCode.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.getConversationListByTag=function(e,t,n,r){var s=this;return new Promise((function(i,a){var c=s._callCppProxy("getConversationsForTagByPage",e,t,n||20,r||"");s._electronLogger.info("getConversationListByTag -> ",c);var u=s._convertResultList(c,(function(e){return f(f({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:o.ErrorCode.SUCCESS,data:u})}))},e.prototype.getUnreadCountByTag=function(e,t){var n=this;return new Promise((function(r,s){var i=n._callCppProxy("getConversationUnreadCountForTag",e,t);n._electronLogger.info("getUnreadCountByTag -> ",i),r({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.setConversationStatusInTag=function(e,t,n){var r=this;return new Promise((function(s,i){r._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",n.isTop||!1,(function(){s({code:o.ErrorCode.SUCCESS})}),(function(e){s({code:e})}))}))},e.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(n,r){var s=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||"");t._electronLogger.info("getTagsForConversation -> ",s);var i=t._convertResultList(s,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));n({code:o.ErrorCode.SUCCESS,data:i})}))},e.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},e.prototype.getTopConversationList=function(){throw new Error("Method not implemented.")},e.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},e.prototype.getAllUnreadMentionedCount=function(){throw new Error("Method not implemented.")},e.prototype.getOSInfo=function(){return g(this,void 0,void 0,(function(){var e;return h(this,(function(t){return e={arch:u.arch(),platform:u.platform(),type:u.type(),version:u.version(),release:u.release(),uptime:u.uptime(),cpus:u.cpus(),freemem:u.freemem(),totalmem:u.totalmem(),networkInterfaces:u.networkInterfaces()},[2,{code:o.ErrorCode.SUCCESS,data:e}]}))}))},e.prototype.getMainProcessInfo=function(){return g(this,void 0,void 0,(function(){return h(this,(function(e){return[2,{code:o.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()}}]}))}))},e}();module.exports=function(e){return function(e,t){return o.assert("options.reconnectKickEnable",null==t?void 0:t.reconnectKickEnable,o.AssertRules.BOOLEAN),o.logger.init({customLogPrint:null==t?void 0:t.logStdout,localLogLevel:null==t?void 0:t.logLevel}),S.setLogLevel(null==t?void 0:t.logLevel),S.setLogStdout(null==t?void 0:t.logStdout),new L(e,null==t?void 0:t.dbpath,null==t?void 0:t.reconnectKickEnable)}(C,e)};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "types": "index.d.ts",
13
13
  "module": "index.esm.js",
14
- "version": "5.5.5-beem",
14
+ "version": "5.5.5",
15
15
  "author": "pass-web@rongcloud.cn",
16
16
  "license": "LGPL 2.1",
17
17
  "homepage": "https://www.rongcloud.cn",
@@ -22,6 +22,6 @@
22
22
  "globals": "RCMain"
23
23
  },
24
24
  "peerDependencies": {
25
- "@rongcloud/engine": "=5.5.5-beem"
25
+ "@rongcloud/engine": "=5.5.5"
26
26
  }
27
27
  }