diff --git a/node_modules/@openim/client-sdk/lib/constant/api.d.ts b/node_modules/@openim/client-sdk/lib/constant/api.d.ts index a7694b8..0c00407 100644 --- a/node_modules/@openim/client-sdk/lib/constant/api.d.ts +++ b/node_modules/@openim/client-sdk/lib/constant/api.d.ts @@ -4,6 +4,7 @@ export declare enum RequestApi { Logout = "Logout", GetLoginStatus = "GetLoginStatus", GetLoginUserID = "GetLoginUserID", + ForceReconnect = "ForceReconnect", GetSelfUserInfo = "GetSelfUserInfo", SetSelfInfo = "SetSelfInfo", GetUsersInfo = "GetUsersInfo", @@ -53,6 +54,9 @@ export declare enum RequestApi { DismissGroup = "DismissGroup", QuitGroup = "QuitGroup", GetUsersInGroup = "GetUsersInGroup", + SendGroupMessageReadReceipt = "SendGroupMessageReadReceipt", + GetGroupMessageReaderList = "GetGroupMessageReaderList", + IsJoinGroup = "IsJoinGroup", GetAllConversationList = "GetAllConversationList", GetConversationListSplit = "GetConversationListSplit", GetOneConversation = "GetOneConversation", @@ -105,7 +109,17 @@ export declare enum RequestApi { InsertGroupMessageToLocalStorage = "InsertGroupMessageToLocalStorage", InsertSingleMessageToLocalStorage = "InsertSingleMessageToLocalStorage", SetMessageLocalEx = "SetMessageLocalEx", - SetConversation = "SetConversation" + SetConversation = "SetConversation", + SignalingInvite = "SignalingInvite", + SignalingInviteInGroup = "SignalingInviteInGroup", + SignalingAccept = "SignalingAccept", + SignalingReject = "SignalingReject", + SignalingCancel = "SignalingCancel", + SignalingHungUp = "SignalingHungUp", + SignalingGetRoomByGroupID = "SignalingGetRoomByGroupID", + SignalingGetTokenByRoomID = "SignalingGetTokenByRoomID", + GetSignalingInvitationInfoStartApp = "GetSignalingInvitationInfoStartApp", + SignalingSendCustomSignal = "SignalingSendCustomSignal" } export declare enum InternalRequestApi { GetFriendVersion = "GetFriendVersion", @@ -121,6 +135,13 @@ export declare enum InternalRequestApi { GetDesignatedConversation = "GetDesignatedConversation", GetNotNotifyConversationIDs = "GetNotNotifyConversationIDs", GetFullFriendUserIDs = "GetFullFriendUserIDs", - GetFullGroupMemberUserIDs = "GetFullGroupMemberUserIDs" + GetFullGroupMemberUserIDs = "GetFullGroupMemberUserIDs", + SignalGetRoomByGroupID = "SignalGetRoomByGroupID", + SignalSendCustomSignal = "SignalSendCustomSignal", + GetSignalInvitationInfoStartApp = "GetSignalInvitationInfoStartApp", + GetEncryptionKey = "GetEncryptionKey", + MarkGroupMessageRead = "MarkGroupMessageRead", + GetGroupMessageHasRead = "GetGroupMessageHasRead", + GetGroupMessageReadNum = "GetGroupMessageReadNum" } export declare const Api2Url: Partial>; diff --git a/node_modules/@openim/client-sdk/lib/core/api/conversation.d.ts b/node_modules/@openim/client-sdk/lib/core/api/conversation.d.ts index bc18c24..7d3cf2c 100644 --- a/node_modules/@openim/client-sdk/lib/core/api/conversation.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/api/conversation.d.ts @@ -6,7 +6,7 @@ export declare function setupConversation(apiService: MixinApiService): { getOneConversation: (params: GetOneConversationParams, operationID: string) => Promise>; getTotalUnreadMsgCount: (operationID: string) => Promise>; markConversationMessageAsRead: (params: string, operationID: string) => Promise>; - clearConversationAndDeleteAllMsg: (params: string, operationID: string) => Promise>; + deleteConversationAndDeleteAllMsg: (params: string, operationID: string) => Promise>; setConversation: (params: SetConversationParams, operationID: string) => Promise>; changeInputStates: (params: ChangeInputStatesParams, operationID: string) => Promise>; getInputStates: (params: GetInputstatesParams, operationID: string) => Promise>; @@ -16,7 +16,6 @@ export interface ConversationApi { getOneConversation: (params: GetOneConversationParams) => Promise>; getTotalUnreadMsgCount: () => Promise>; markConversationMessageAsRead: (params: string) => Promise>; - clearConversationAndDeleteAllMsg: (params: string) => Promise>; setConversation: (params: SetConversationParams) => Promise>; changeInputStates: (params: ChangeInputStatesParams) => Promise>; getInputStates: (params: GetInputstatesParams) => Promise>; diff --git a/node_modules/@openim/client-sdk/lib/core/api/group.d.ts b/node_modules/@openim/client-sdk/lib/core/api/group.d.ts index e795511..4d23f8d 100644 --- a/node_modules/@openim/client-sdk/lib/core/api/group.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/api/group.d.ts @@ -22,6 +22,7 @@ export declare function setupGroup(apiService: MixinApiService): { getGroupApplicationListAsRecipient: (params: OffsetParams, operationID: string) => Promise>; getGroupApplicationListAsApplicant: (params: OffsetParams, operationID: string) => Promise>; getUsersInGroup: (params: getGroupMembersInfoParams, operationID: string) => Promise>; + isJoinGroup: (params: string, operationID: string) => Promise>; }; export interface GroupApi { createGroup: (params: CreateGroupParams) => Promise>; @@ -44,4 +45,5 @@ export interface GroupApi { dismissGroup: (params: string) => Promise>; quitGroup: (params: string) => Promise>; getUsersInGroup: (params: getGroupMembersInfoParams) => Promise>; + isJoinGroup: (params: string) => Promise>; } diff --git a/node_modules/@openim/client-sdk/lib/core/api/index.d.ts b/node_modules/@openim/client-sdk/lib/core/api/index.d.ts index 8ad3168..7afc757 100644 --- a/node_modules/@openim/client-sdk/lib/core/api/index.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/api/index.d.ts @@ -3,3 +3,4 @@ export * from "./friend"; export * from "./group"; export * from "./message"; export * from "./conversation"; +export * from "./signaling"; diff --git a/node_modules/@openim/client-sdk/lib/core/api/message.d.ts b/node_modules/@openim/client-sdk/lib/core/api/message.d.ts index eef3e37..7e2de8a 100644 --- a/node_modules/@openim/client-sdk/lib/core/api/message.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/api/message.d.ts @@ -1,4 +1,4 @@ -import { AtMsgParams, CustomMsgParams, FaceMessageParams, FileMsgParams, GetAdvancedHistoryMsgParams, ImageMsgParams, LocationMsgParams, MergerMsgParams, OpreateMessageParams, QuoteMsgParams, SendMsgParams, SoundMsgParams, VideoMsgParams } from '../../types/params'; +import { AtMsgParams, CustomMsgParams, FaceMessageParams, FileMsgParams, GetAdvancedHistoryMsgParams, GetGroupMessageReaderParams, ImageMsgParams, LocationMsgParams, MergerMsgParams, OpreateMessageParams, QuoteMsgParams, SendGroupReadReceiptParams, SendMsgParams, SoundMsgParams, VideoMsgParams } from '../../types/params'; import type { MixinApiService } from '..'; import { AdvancedGetMessageResult, CardElem, MessageItem, ApiResponse } from '../../types/entity'; export declare function setupMessage(apiService: MixinApiService): { @@ -35,6 +35,9 @@ export declare function setupMessage(apiService: MixinApiService): { getAdvancedHistoryMessageListReverse: (params: GetAdvancedHistoryMsgParams, operationID: string) => Promise>; deleteMessage: (params: OpreateMessageParams, operationID: string) => Promise>; deleteAllMsgFromLocalAndSvr: (operationID: string) => Promise>; + sendGroupMessageReadReceipt: (params: SendGroupReadReceiptParams, operationID: string) => Promise>; + getGroupMessageReaderList: (params: GetGroupMessageReaderParams, operationID: string) => Promise>; + cancelMessageTasks: () => void; }; export interface MessageApi { createTextMessage: (params: string) => Promise>; @@ -69,4 +72,7 @@ export interface MessageApi { getAdvancedHistoryMessageList: (params: GetAdvancedHistoryMsgParams) => Promise>; deleteMessage: (params: OpreateMessageParams) => Promise>; deleteAllMsgFromLocalAndSvr: () => Promise>; + sendGroupMessageReadReceipt: (params: SendGroupReadReceiptParams) => Promise>; + getGroupMessageReaderList: (params: GetGroupMessageReaderParams) => Promise>; + cancelMessageTasks: () => void; } diff --git a/node_modules/@openim/client-sdk/lib/core/api/signaling.d.ts b/node_modules/@openim/client-sdk/lib/core/api/signaling.d.ts new file mode 100644 index 0000000..91ace8a --- /dev/null +++ b/node_modules/@openim/client-sdk/lib/core/api/signaling.d.ts @@ -0,0 +1,28 @@ +import { RtcProto } from '@openim/protocol'; +import { MixinApiService } from '..'; +import { ApiResponse } from '../../types/entity'; +import { CustomSignalParams, RtcActionParams, SignalingInviteParams } from '../../types/params'; +export declare function setupSignaling(apiService: MixinApiService): { + signalingInvite: (data: SignalingInviteParams, operationID: string) => Promise>; + signalingInviteInGroup: (data: SignalingInviteParams, operationID: string) => Promise>; + signalingAccept: (data: RtcActionParams, operationID: string) => Promise>; + signalingReject: (data: RtcActionParams, operationID: string) => Promise>; + signalingCancel: (data: RtcActionParams, operationID: string) => Promise>; + signalingHungUp: (data: RtcActionParams, operationID: string) => Promise>; + signalingGetRoomByGroupID: (groupID: string, operationID: string) => Promise>; + signalingGetTokenByRoomID: (roomID: string, operationID: string) => Promise>; + getSignalingInvitationInfoStartApp: (operationID: string) => Promise>; + signalingSendCustomSignal: (data: CustomSignalParams, operationID: string) => Promise>; +}; +export interface SignalingApi { + signalingInvite: (data: SignalingInviteParams, operationID?: string) => Promise>; + signalingInviteInGroup: (data: SignalingInviteParams, operationID?: string) => Promise>; + signalingAccept: (data: RtcActionParams, operationID?: string) => Promise>; + signalingReject: (data: RtcActionParams, operationID?: string) => Promise; + signalingCancel: (data: RtcActionParams, operationID?: string) => Promise; + signalingHungUp: (data: RtcActionParams, operationID?: string) => Promise; + signalingGetRoomByGroupID: (groupID: string, operationID?: string) => Promise>; + signalingGetTokenByRoomID: (roomID: string, operationID?: string) => Promise>; + getSignalingInvitationInfoStartApp: (operationID?: string) => Promise>; + signalingSendCustomSignal: (data: CustomSignalParams, operationID?: string) => Promise; +} diff --git a/node_modules/@openim/client-sdk/lib/core/index.d.ts b/node_modules/@openim/client-sdk/lib/core/index.d.ts index f42fbf3..b782058 100644 --- a/node_modules/@openim/client-sdk/lib/core/index.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/index.d.ts @@ -1,16 +1,20 @@ import type { ApiResponse, HttpRequest } from '../types/entity'; import Emitter from '../utils/emitter'; +import { CbEvents } from '../constant/callback'; +import { SdkWsProto } from '@openim/protocol'; import { LoginParams, SendWsReqParams, TriggerEventParams, UploadFileParams } from '../types/params'; -import { MessageTrigger, RelationTrigger, GroupTrigger, UserTrigger, BusinessTrigger } from './internal'; -import { ConversationApi, FriendApi, GroupApi, MessageApi, UserApi } from './api'; +import { MessageTrigger, RelationTrigger, GroupTrigger, UserTrigger, BusinessTrigger, SignalingTrigger } from './internal'; +import { ConversationApi, FriendApi, GroupApi, MessageApi, SignalingApi, UserApi } from './api'; import { LoginStatus, Platform } from '../types/enum'; -declare class OpenIMSDK extends Emitter implements FriendApi, GroupApi, UserApi, MessageApi, ConversationApi { +import type { CallbackEvent, DataOfEvent } from '../types/eventData'; +declare class OpenIMSDK extends Emitter implements FriendApi, GroupApi, UserApi, MessageApi, ConversationApi, SignalingApi { userID?: string; platform?: Platform; private token?; private apiAddr?; loginStatus: LoginStatus; isReconnected: boolean; + serverConfig: SdkWsProto.ServerConfig; private connectState; private wsManager?; messageTrigger: MessageTrigger; @@ -18,6 +22,7 @@ declare class OpenIMSDK extends Emitter implements FriendApi, GroupApi, UserApi, groupTrigger: GroupTrigger; relationTrigger: RelationTrigger; businessTrigger: BusinessTrigger; + signalingTrigger: SignalingTrigger; private requestMap; constructor(); private generateHttpHeader; @@ -32,8 +37,9 @@ declare class OpenIMSDK extends Emitter implements FriendApi, GroupApi, UserApi, triggerEvent: ({ event, data, errCode, errMsg, operationID, }: TriggerEventParams) => void; login: (params: LoginParams, operationID?: string) => Promise>; getLoginStatus: (operationID?: string) => Promise>; + forceReconnect: (operationID?: string) => Promise>; logout: (operationID?: string) => Promise>; - internalUploadFile: (file: File, operationID: string) => Promise<{ + internalUploadFile: (file: File, operationID: string, onProgress?: (percent: number) => void) => Promise<{ url?: string; error?: Error; }>; @@ -80,6 +86,7 @@ declare class OpenIMSDK extends Emitter implements FriendApi, GroupApi, UserApi, dismissGroup: GroupApi['dismissGroup']; quitGroup: GroupApi['quitGroup']; getUsersInGroup: GroupApi['getUsersInGroup']; + isJoinGroup: GroupApi['isJoinGroup']; createTextMessage: MessageApi['createTextMessage']; createTextAtMessage: MessageApi['createTextAtMessage']; createLocationMessage: MessageApi['createLocationMessage']; @@ -103,19 +110,34 @@ declare class OpenIMSDK extends Emitter implements FriendApi, GroupApi, UserApi, getAdvancedHistoryMessageList: MessageApi['getAdvancedHistoryMessageList']; deleteMessage: MessageApi['deleteMessage']; deleteAllMsgFromLocalAndSvr: MessageApi['deleteAllMsgFromLocalAndSvr']; + sendGroupMessageReadReceipt: MessageApi['sendGroupMessageReadReceipt']; + getGroupMessageReaderList: MessageApi['getGroupMessageReaderList']; + cancelMessageTasks: MessageApi['cancelMessageTasks']; getConversationListSplit: ConversationApi['getConversationListSplit']; getOneConversation: ConversationApi['getOneConversation']; setConversation: ConversationApi['setConversation']; getTotalUnreadMsgCount: ConversationApi['getTotalUnreadMsgCount']; markConversationMessageAsRead: ConversationApi['markConversationMessageAsRead']; - clearConversationAndDeleteAllMsg: ConversationApi['clearConversationAndDeleteAllMsg']; changeInputStates: ConversationApi['changeInputStates']; getInputStates: ConversationApi['getInputStates']; + signalingInvite: SignalingApi['signalingInvite']; + signalingInviteInGroup: SignalingApi['signalingInviteInGroup']; + signalingAccept: SignalingApi['signalingAccept']; + signalingReject: SignalingApi['signalingReject']; + signalingCancel: SignalingApi['signalingCancel']; + signalingHungUp: SignalingApi['signalingHungUp']; + signalingGetRoomByGroupID: SignalingApi['signalingGetRoomByGroupID']; + signalingGetTokenByRoomID: SignalingApi['signalingGetTokenByRoomID']; + getSignalingInvitationInfoStartApp: SignalingApi['getSignalingInvitationInfoStartApp']; + signalingSendCustomSignal: SignalingApi['signalingSendCustomSignal']; } export declare const getSDK: () => ApiService; export type ApiService = FriendApi & GroupApi & UserApi & MessageApi & ConversationApi & { + on: (event: E, fn: (data: CallbackEvent>) => void) => unknown; + off: (event: E, fn: (data: CallbackEvent>) => void) => unknown; login: (params: LoginParams) => Promise>; getLoginStatus: () => Promise>; + forceReconnect: () => Promise>; logout: () => Promise>; uploadFile: (params: UploadFileParams) => Promise Promise; + getGroupMembersMayNotInGroup: (params: { + groupID: string; + userIDList: string[]; + operationID: string; + }) => Promise; updateCachedGroups: (groups: SdkWsProto.GroupInfo[]) => void; updateCachedGroupMembers: (members: SdkWsProto.GroupMemberFullInfo[]) => void; clearCachedGroupMembers: (groupID: string) => void; diff --git a/node_modules/@openim/client-sdk/lib/core/internal/group/syncer.d.ts b/node_modules/@openim/client-sdk/lib/core/internal/group/syncer.d.ts index cd0e588..ec5d88f 100644 --- a/node_modules/@openim/client-sdk/lib/core/internal/group/syncer.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/internal/group/syncer.d.ts @@ -17,5 +17,6 @@ declare class GroupSyncer { private getJoinedGroupIDs; addGroupMemberVersion: (grouoID: string, memberVersion: GroupMemberVersion) => void; updateGroupMemberVersion: (groupID: string, memberVersion: GroupMemberVersion) => void; + checkIsJoinGroup: (groupID: string) => boolean; } export default GroupSyncer; diff --git a/node_modules/@openim/client-sdk/lib/core/internal/index.d.ts b/node_modules/@openim/client-sdk/lib/core/internal/index.d.ts index 5a8ec5b..8ed98c6 100644 --- a/node_modules/@openim/client-sdk/lib/core/internal/index.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/internal/index.d.ts @@ -3,4 +3,5 @@ import GroupTrigger from './group/trigger'; import RelationTrigger from './relation/trigger'; import BusinessTrigger from './businessTrigger'; import UserTrigger from './user/trigger'; -export { MessageTrigger, GroupTrigger, RelationTrigger, BusinessTrigger, UserTrigger, }; +import SignalingTrigger from './signaling/trigger'; +export { MessageTrigger, GroupTrigger, RelationTrigger, BusinessTrigger, UserTrigger, SignalingTrigger, }; diff --git a/node_modules/@openim/client-sdk/lib/core/internal/message/cache.d.ts b/node_modules/@openim/client-sdk/lib/core/internal/message/cache.d.ts index 010b3f7..ed6be54 100644 --- a/node_modules/@openim/client-sdk/lib/core/internal/message/cache.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/internal/message/cache.d.ts @@ -1,6 +1,6 @@ import { MsgProto } from '@openim/protocol'; import { MixinApiService } from '../..'; -import { SDKMessage, ConversationItem } from '../../../types/entity'; +import { SDKMessage, ConversationItem, MessageItem, ReadUser } from '../../../types/entity'; declare class MessageCache { private instance; private totalUnreadCount; @@ -8,6 +8,9 @@ declare class MessageCache { private cachedConversations; private cachedMessages; private cachedFilterMessageSeqs; + private cachedGroupMessageReadInfo; + private cachedGroupMessageClientMsgIDs; + private cachedGroupMessageReadUser; cachedHasReadAndMaxSeqs: Record; constructor(instance: MixinApiService); clear: () => void; @@ -20,6 +23,7 @@ declare class MessageCache { getCachedMaxReadSeq: (conversationID: string) => MsgProto.Seqs | undefined; addCachedMaxReadSeq: (conversationID: string, seqs: MsgProto.Seqs) => void; updateCachedMaxReadSeq: (convesationID: string, seqs: Partial) => void; + removeCachedMaxReadSeq: (conversationID: string) => void; getNotNotifyConversationIDs: (operationID: string) => Promise; isNotNotifyConversation: (conversationID: string) => boolean; addNotNotifyConversationID: (conversationID: string) => void; @@ -40,5 +44,13 @@ declare class MessageCache { tryUpdateQuotedMessage: (conversationID: string, clientMsgID: string) => void; addFilterSeqsToCache: (conversationID: string, seqs: number[]) => void; checkIsFilterSeq: (conversationID: string, seq: number) => boolean | undefined; + getGroupMessageHasReadInfo: ({ conversationID, messages, operationID, }: { + conversationID: string; + messages: MessageItem[]; + operationID: string; + }) => Promise; + chearGroupMessageClientMsgIDs: () => void; + addGroupMessageReadUser: (clientMsgID: string, readUsers: ReadUser[]) => void; + getGroupMessageReadUser: (clientMsgID: string) => ReadUser[]; } export default MessageCache; diff --git a/node_modules/@openim/client-sdk/lib/core/internal/message/encryptor.d.ts b/node_modules/@openim/client-sdk/lib/core/internal/message/encryptor.d.ts new file mode 100644 index 0000000..db5b838 --- /dev/null +++ b/node_modules/@openim/client-sdk/lib/core/internal/message/encryptor.d.ts @@ -0,0 +1,13 @@ +import { EncryptionProto, SdkWsProto } from '@openim/protocol'; +import { MixinApiService } from '../..'; +export default class Encryptor { + private ctx; + private aesEncryptor; + private cachedVersionKeys; + constructor(ctx: MixinApiService); + private getEncryptionKeyFromServer; + getMaxVersionKey: (conversationID: string, operationID: string) => Promise; + getKeyByMessageVersion: (req: EncryptionProto.GetEncryptionKeyReq, operationID: string) => Promise; + encryption: (conversationID: string, msgData: SdkWsProto.MsgData, operationID: string) => Promise; + decryption: (conversationID: string, msgData: SdkWsProto.MsgData | undefined, operationID: string) => Promise; +} diff --git a/node_modules/@openim/client-sdk/lib/core/internal/message/trigger.d.ts b/node_modules/@openim/client-sdk/lib/core/internal/message/trigger.d.ts index 0d6b012..0361cdb 100644 --- a/node_modules/@openim/client-sdk/lib/core/internal/message/trigger.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/internal/message/trigger.d.ts @@ -5,11 +5,13 @@ import { MixinApiService } from '../..'; import { TypingManager } from './typing'; import MessageCache from './cache'; import MessageSyncer from './syncer'; +import Encryptor from './encryptor'; declare class MessageTrigger { private instance; cache: MessageCache; syncer: MessageSyncer; triggeredConversationEvent: Map; + encryptor: Encryptor; typingManager: TypingManager; constructor(instance: MixinApiService); sync: (operationID: string) => Promise; @@ -32,6 +34,7 @@ declare class MessageTrigger { getMessageFromServerBySeqs: (conversations: MsgProto.ConversationSeqs[], operationID: string) => Promise; revokeMessage: (revokeMsgTips: SdkWsProto.RevokeMsgTips, operationID: string) => Promise; triggerTyping: (message: MessageItem) => void; + private handleGroupReadReceipt; triggerNotification: (messages: Record, operationID: string) => Promise; triggerConversationNotification: (message: SdkWsProto.MsgData, operationID: string) => Promise; triggerConversation: (messages: Record, operationID: string) => Promise; diff --git a/node_modules/@openim/client-sdk/lib/core/internal/signaling/trigger.d.ts b/node_modules/@openim/client-sdk/lib/core/internal/signaling/trigger.d.ts new file mode 100644 index 0000000..00333ca --- /dev/null +++ b/node_modules/@openim/client-sdk/lib/core/internal/signaling/trigger.d.ts @@ -0,0 +1,14 @@ +import { RtcProto, SdkWsProto } from '@openim/protocol'; +import { MixinApiService } from '../..'; +declare class SignalingTrigger { + private apiService; + private inviteTimers; + constructor(apiService: MixinApiService); + reset: () => void; + private signalingNotificationHandle; + private removeInviteTimer; + private addInviteTimer; + sendSignalingReqWaitResp: (req: RtcProto.SignalReq, operationID: string) => Promise; + parseMessageAndTrigger: (message: SdkWsProto.MsgData, operationID: string) => Promise; +} +export default SignalingTrigger; diff --git a/node_modules/@openim/client-sdk/lib/core/internal/user/cache.d.ts b/node_modules/@openim/client-sdk/lib/core/internal/user/cache.d.ts index 55ed1e9..684dba5 100644 --- a/node_modules/@openim/client-sdk/lib/core/internal/user/cache.d.ts +++ b/node_modules/@openim/client-sdk/lib/core/internal/user/cache.d.ts @@ -1,5 +1,5 @@ -import { MixinApiService } from "../.."; -import { SdkWsProto } from "@openim/protocol"; +import { MixinApiService } from '../..'; +import { SdkWsProto } from '@openim/protocol'; declare class UserCache { private instance; private cachedLoginUserInfo; diff --git a/node_modules/@openim/client-sdk/lib/index.es.js b/node_modules/@openim/client-sdk/lib/index.es.js index 4fbd43b..5c58ef7 100644 --- a/node_modules/@openim/client-sdk/lib/index.es.js +++ b/node_modules/@openim/client-sdk/lib/index.es.js @@ -1 +1 @@ -import e from"loglevel";import t from"spark-md5";import{decode as n,encode as r}from"base64-arraybuffer";import{PbCoder as o,SdkWsProto as i}from"@openim/protocol";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;tt.latestMsgSendTime?-1:e.latestMsgSendTime {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n "],{type:"application/javascript"});u.workerUrl=URL.createObjectURL(e),u.heartbeatWorker=new Worker(u.workerUrl),u.heartbeatWorker.onmessage=function(e){"ping"===e.data.type&&u.sendPing()},u.heartbeatWorker.postMessage({type:"start",interval:u.heartbeatInterval})}else u.legacyTimer=setInterval(function(){u.sendPing()},u.heartbeatInterval)},this.connect=function(){return"unknow"===u.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise(function(e,t){if(u.ws&&u.ws.readyState!==Z.CLOSED)u.ws.readyState===u.ws.OPEN?e():t(new Error("WebSocket is in an unknown state"));else{var n=function(){u.reconnectAttempts&&u.onReconnectSuccess(),u.reconnectAttempts=0,u.startHeartbeat(),e()},r=function(e){return t(e)};if("web"===u.platformNamespace)u.ws=new WebSocket(u.urlFormat()),u.ws.onopen=n,u.ws.onerror=r;else{var o={url:u.urlFormat(),complete:function(){}};"my"===u.platformNamespace&&(o.multiple=!0),"uni"===u.platformNamespace&&(u.ws=uni.connectSocket(o)),"wx"===u.platformNamespace&&(u.ws=wx.connectSocket(o)),"my"===u.platformNamespace&&(u.ws=my.connectSocket(o)),u.ws.onOpen(n),u.ws.onError(r)}u.setupEventListeners()}})},this.setupEventListeners=function(){if(u.ws){var e=function(e){return u.onBinaryMessage(e.data)},t=function(e){if(u.shouldReconnect&&u.reconnectAttempts0&&(this.cleanupTimer=setInterval(function(){t.deleteExpired()},this.options.cleanupInterval))}var t=e.prototype;return t.onExpiry=function(e){this.expiryListeners.push(e)},t.triggerExpiry=function(e,t){this.expiryListeners.forEach(function(n){return n(e,t)}),this.delete(e)},t.set=function(e,t){var n=this;this.delete(e);var r=Date.now(),o=null;this.options.ttl>0&&(o=setTimeout(function(){clearTimeout(o),n.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:o,created:r})},t.get=function(e){var t=this.store.get(e);if(t&&Date.now()-t.createdd&&n.set(c,[d+1,u.maxSeq,u.maxSeqTime]):n.set(c,[0,u.maxSeq,u.maxSeqTime])}return r.syncAndTriggerMsgs(n,t),Promise.resolve()}catch(e){return Promise.reject(e)}},this.isNotification=function(e){return e.startsWith("n_")},this.syncAndTriggerMsgs=function(t,n){try{return e.debug("Current sync seqMap",t,t.size),Promise.resolve(function(){if(t.size>0){var r=function(r){return Ne(function(){return Promise.resolve(s.pullMsgBySeqRange(o,n)).then(function(e){return Promise.resolve(s.instance.messageTrigger.triggerConversation(e.msgs,n)).then(function(){return Promise.resolve(s.instance.messageTrigger.triggerNotification(e.notificationMsgs,n)).then(function(){for(var e,n=a(t);!(e=n()).done;){var r=e.value,o=r[1];s.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:o[1],maxSeqTime:o[2]})}})})})},function(n){throw e.error("Sync message from server error",n,t),n})},o=new Map,i=0,c=function(e,t){if("function"==typeof e[Fe]){var n,r,o,i=function(e){try{for(;!(n=s.next()).done;)if((e=t(n.value))&&e.then){if(!we(e))return void e.then(i,o||(o=Ue.bind(null,r=new Oe,2)));e=e.v}r?Ue(r,1,e):r=e}catch(e){Ue(r||(r=new Oe),2,e)}},s=e[Fe]();if(i(),s.return){var a=function(e){try{n.done||s.return()}catch(e){}return e};if(r&&r.then)return r.then(a,function(e){throw a(e)});a()}return r}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],u=0;u=s.SplitPullMsgNum)return Ne(function(){return Promise.resolve(s.pullMsgBySeqRange(o,n)).then(function(e){return Promise.resolve(s.instance.messageTrigger.triggerConversation(e.msgs,n)).then(function(){return Promise.resolve(s.instance.messageTrigger.triggerNotification(e.notificationMsgs,n)).then(function(){for(var e,t=a(o);!(e=t()).done;){var n=e.value,r=n[1];s.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:r[1],maxSeqTime:r[2]})}o=new Map,i=0})})})},function(t){throw e.error("Sync message from server error",t,o),t})}()}var d=c[0],g=c[1],p=c[2],l=g-d+1,f=function(){if(l/s.SplitPullMsgNum>1&&s.isNotification(r)){var t=new Map,o=Math.floor(l/s.SplitPullMsgNum),i=d,c=0,u=0;return function(e,t,n){for(var r;;){var o=e();if(we(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!we(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!we(s)){r=2;break}}}var a=new Oe,c=Ue.bind(null,a,2);return(0===r?o.then(d):1===r?i.then(u):s.then(g)).then(void 0,c),a;function u(r){i=r;do{if(t&&(s=t())&&s.then&&!we(s))return void s.then(g).then(void 0,c);if(!(o=e())||we(o)&&!o.v)return void Ue(a,1,i);if(o.then)return void o.then(d).then(void 0,c);we(i=n())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,c)}function d(e){e?(i=n())&&i.then?i.then(u).then(void 0,c):u(i):Ue(a,1,i)}function g(){(o=e())?o.then?o.then(d).then(void 0,c):d(o):Ue(a,1,i)}}(function(){return u<=o},function(){return u++},function(){return u===o?t.set(r,[i,g,p]):((c=i+s.SplitPullMsgNum)>g&&(c=g,u=o),t.set(r,[i,c,p])),Ne(function(){return Promise.resolve(s.pullMsgBySeqRange(t,n)).then(function(e){return Promise.resolve(s.instance.messageTrigger.triggerConversation(e.msgs,n)).then(function(){return Promise.resolve(s.instance.messageTrigger.triggerNotification(e.notificationMsgs,n)).then(function(){for(var e,n=a(t);!(e=n()).done;){var r=e.value,o=r[1];s.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:o[1],maxSeqTime:o[2]})}i=c+1})})})},function(n){throw e.error("Sync message from server error",n,t),n})})}}();return f&&f.then?f.then(u):u()});return c&&c.then?c.then(r):r()}e.debug("Nothing to sync")}())}catch(e){return Promise.reject(e)}},this.pullMsgBySeqRange=function(t,n){try{var r=[].concat(t.entries()).map(function(e){var t=e[1];return{conversationID:e[0],begin:t[0],end:t[1],num:u.defaultPullNums}});e.debug("PullMsgBySeqRange with opid: ",n,"seqRanges: ",r);var s=o.PullMessageBySeqsReq.encode({userID:u.instance.userID,seqRanges:r,order:i.PullOrder.PullOrderAsc}).finish();return Promise.resolve(u.instance.sendReqWaitResp({operationID:n,data:s,reqIdentifier:C.PullMsgByRange}))}catch(e){return Promise.reject(e)}},this.instance=t};function Ue(e,t,n){if(!e.s){if(n instanceof Oe){if(!n.s)return void(n.o=Ue.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Ue.bind(null,e,t),Ue.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var Oe=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Ue(r,1,i(this.v))}catch(e){Ue(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ue(r,1,t?t(o):o):n?Ue(r,1,n(o)):Ue(r,2,o)}catch(e){Ue(r,2,e)}},r},e}();function we(e){return e instanceof Oe&&1&e.s}var Fe="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function qe(e,t,n){if(!e.s){if(n instanceof Ee){if(!n.s)return void(n.o=qe.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(qe.bind(null,e,t),qe.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var ke=[b.MsgStatusHasDeleted,b.MsgStatusFiltered],Ee=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{qe(r,1,i(this.v))}catch(e){qe(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?qe(r,1,t?t(o):o):n?qe(r,1,n(o)):qe(r,2,o)}catch(e){qe(r,2,e)}},r},e}(),Le=function(t){var n=this,r=this,i=this,s=this,a=this,u=this,d=this,g=this,p=this,l=this,f=this,v=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredConversationEvent=new Map,this.typingManager=void 0,this.sync=function(e){try{return Promise.resolve(r.cache.getMaxReadSeqs(e)).then(function(){var t=[r.syncer.syncConversationVersion(e),r.cache.getActiveConversationsFromServer(e),r.cache.getNotNotifyConversationIDs(e)];return Promise.resolve(Promise.all(t)).then(function(){})})}catch(e){return Promise.reject(e)}},this.reset=function(){n.cache.clear(),n.syncer.reset(),n.typingManager.reset(),n.triggeredConversationEvent.clear()},this.setTriggeredConversationEvent=function(e){n.triggeredConversationEvent.set(e,!0)},this.getMessageWithCacheBySeqs=function(t,n,r){try{var o=function(){return u.sort(function(e,t){return e.seq-t.seq}),{messages:u,filterCount:d}},s=i.cache.getCachedMessagesBySeqs(t,n),a=s.cachedMessages,c=s.unCachedSeqs,u=[].concat(a),d=0;e.debug("after getCachedMessagesBySeqs with opid: ",r,"seqs: ",n,"cachedMessages: ",a,"unCachedSeqs: ",c);var g=function(){if(c.length)return Promise.resolve(i.getMessageFromServerBySeqs([{conversationID:t,seqs:c}],r)).then(function(e){var n=[],r=[];e.msgs[t].Msgs.forEach(function(e){ke.includes(e.status)?(n.push(e.seq),d++):r.push(Me(e))}),e.msgs[t].Msgs.length||n.push.apply(n,c),i.cache.addMessagesToCache(t,r),i.cache.addFilterSeqsToCache(t,n),u.push.apply(u,r)})}();return Promise.resolve(g&&g.then?g.then(o):o())}catch(e){return Promise.reject(e)}},this.getPreviousSeqMessage=function(e){var t=e.conversationID,n=e.seq,r=e.operationID;try{if(n<1)return Promise.resolve(null);for(var o=[],i=n;o.length<10&&!(i<1);i--)s.cache.checkIsFilterSeq(t,i)||o.push(i);return Promise.resolve(s.getMessageWithCacheBySeqs(t,o,r)).then(function(e){var n,i=e.messages;function a(e){return n?e:i[i.length-1]}var c=function(){if(!i.length)return Promise.resolve(s.getPreviousSeqMessage({seq:o[o.length-1],operationID:r,conversationID:t})).then(function(e){return n=1,e})}();return c&&c.then?c.then(a):a(c)})}catch(e){return Promise.reject(e)}},this.initConversation=function(e){try{var t=function(e){return a.cache.setCachedConversations([n]),n},n={conversationID:re(c({},e,{userID:a.instance.userID})),userID:"",groupID:"",recvMsgOpt:w.Nomal,unreadCount:0,groupAtType:J.AtNormal,latestMsg:"",latestMsgSendTime:0,draftText:"",draftTextTime:0,burnDuration:0,msgDestructTime:0,isPinned:!1,isPrivateChat:!1,isMsgDestruct:!1,attachedInfo:"",ex:""},r=e.sessionType===H.Group?Promise.resolve(a.instance.groupTrigger.cache.getGroupInfosWithCache([e.sourceID],e.operationID)).then(function(t){if(!t[0])throw new Error("target group not exist");n.showName=t[0].groupName,n.faceURL=t[0].faceURL,n.conversationType=H.Group,n.groupID=e.sourceID}):(n.userID=e.sourceID,n.conversationType=H.Single,Promise.resolve(a.instance.getSpecifiedFriendsInfo([e.sourceID],e.operationID)).then(function(t){var r=t.data,o=function(){if(!r.length)return Promise.resolve(a.instance.getUsersInfo([e.sourceID],e.operationID)).then(function(e){var t=e.data;n.showName=t[0].nickname,n.faceURL=t[0].faceURL});n.showName=r[0].remark||r[0].nickname,n.faceURL=r[0].faceURL}();if(o&&o.then)return o.then(function(){})}));return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},this.getConversationsWithCacheByIDs=function(e,t){try{var n=function(){return[].concat(r,i)},r=[],i=[],s=[];e.forEach(function(e){var t=u.cache.getCachedConversation(e);t?r.push(t):s.push(e)});var a=function(){if(s.length)return Promise.resolve(u.instance.sendHttpRequest({reqFuncName:m.GetDesignatedConversation,data:o.GetConversationsReq.encode({ownerUserID:u.instance.userID,conversationIDs:s}).finish(),operationID:t})).then(function(e){var t=se(e,m.GetDesignatedConversation),n=i.push;return Promise.resolve(Promise.all(t.conversations.map(function(e){var t,n;return Se(e,u.getPreviousSeqMessage,null==(t=u.cache.getCachedMaxReadSeq(null==(n=e.conversation)?void 0:n.conversationID))?void 0:t.maxSeqTime)}))).then(function(e){n.call.apply(n,[i].concat(e)),u.cache.setCachedConversations(i)})})}();return Promise.resolve(a&&a.then?a.then(n):n())}catch(e){return Promise.reject(e)}},this.getOneConversationAndTryChange=function(e,t,n,r,i){try{var s,a=function(e){return s?e:(u&&n&&d.instance.triggerEvent({event:i?D.OnNewConversation:D.OnConversationChanged,data:[c({},u)],operationID:t}),u)},u=void 0;u=d.cache.getCachedConversation(e);var g=function(){if(!u)return function(){if(d.cache.getCachedMaxReadSeq(e))return Promise.resolve(d.instance.sendHttpRequest({reqFuncName:m.GetDesignatedConversation,data:o.GetConversationsReq.encode({ownerUserID:d.instance.userID,conversationIDs:[e]}).finish(),operationID:t})).then(function(t){var n,r=se(t,m.GetDesignatedConversation).conversations;if(r)return Promise.resolve(Se(r[0],d.getPreviousSeqMessage,null==(n=d.cache.getCachedMaxReadSeq(e))?void 0:n.maxSeqTime)).then(function(e){d.cache.setCachedConversations([u=e])});s=1})}();void 0!==(null==n?void 0:n.recvMsgOpt)&&(n.recvMsgOpt===w.Nomal?d.cache.deleteNotNotifyConversationID(e):d.cache.addNotNotifyConversationID(e)),n&&Object.assign(u,n),r&&(u.unreadCount+=1)}();return Promise.resolve(g&&g.then?g.then(a):a(g))}catch(e){return Promise.reject(e)}},this.getMessageFromServerBySeqs=function(e,t){try{var n=o.GetSeqMessageReq.encode({userID:g.instance.userID,conversations:e}).finish();return Promise.resolve(g.instance.sendReqWaitResp({operationID:t,data:n,reqIdentifier:C.PullMsgBySeqList}))}catch(e){return Promise.reject(e)}},this.revokeMessage=function(e,t){try{return Promise.resolve(p.getMessageWithCacheBySeqs(e.conversationID,[e.seq],t)).then(function(n){function r(){function n(){var n,o;p.instance.triggerEvent({event:D.OnNewRecvMessageRevoked,data:r,operationID:t});var i=null!=(n=null==(o=p.cache.getCachedMaxReadSeq(e.conversationID))?void 0:o.maxSeq)?n:0,s=function(){if(i<=e.seq)return p.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:e.revokeTime}),Promise.resolve(p.getOneConversationAndTryChange(e.conversationID,t,{latestMsg:JSON.stringify(De(a)),latestMsgSendTime:e.revokeTime})).then(function(){})}();if(s&&s.then)return s.then(function(){})}var r={revokerID:e.revokerUserID,revokerRole:i,clientMsgID:o.clientMsgID,revokerNickname:s,revokeTime:e.revokeTime,sourceMessageSendTime:o.sendTime,sourceMessageSendID:o.sendID,sourceMessageSenderNickname:o.senderNickname,sessionType:e.sesstionType,seq:e.seq,ex:"",isAdminRevoke:e.isAdminRevoke},a=p.cache.tryUpdateCachedMessages(e.conversationID,{clientMsgID:e.clientMsgID,seq:e.seq,content:JSON.stringify({detail:JSON.stringify(r)}),contentType:T.RevokeNotification});p.cache.tryUpdateQuotedMessage(e.conversationID,e.clientMsgID);var c=function(){if(!a)return Promise.resolve(p.getMessageFromServerBySeqs([{conversationID:e.conversationID,seqs:[e.seq]}],t)).then(function(t){a=Me(t.msgs[e.conversationID].Msgs[0])})}();return c&&c.then?c.then(n):n()}var o=n.messages[0],i=0,s="",a=function(){if(e.isAdminRevoke||e.sesstionType===H.Single)return Promise.resolve(p.instance.getUsersInfo([e.revokerUserID],t)).then(function(e){var t;s=null==(t=e.data[0])?void 0:t.nickname});var n=function(){if(e.sesstionType===H.Group)return Promise.resolve(p.getOneConversationAndTryChange(e.conversationID,t)).then(function(n){return Promise.resolve(p.instance.groupTrigger.cache.getGroupMembersWithCache({groupID:n.groupID,userIDList:[e.revokerUserID],operationID:t})).then(function(e){var t,n;s=null==(t=e[0])?void 0:t.nickname,i=null==(n=e[0])?void 0:n.roleLevel})})}();return n&&n.then?n.then(function(){}):void 0}();return a&&a.then?a.then(r):r()})}catch(e){return Promise.reject(e)}},this.triggerTyping=function(e){e.sendID!==n.instance.userID&&n.typingManager.onNewMessage(e)},this.triggerNotification=function(t,n){try{for(var r=0,o=Object.entries(t);rT.FriendNotificationBegin&&t.contentTypeT.UserNotificationBegin&&t.contentTypeT.GroupNotificationBegin&&t.contentTypeT.SignalingNotificationBegin&&t.contentTypeD&&(o=h||!v.cache.isNotNotifyConversation(a),v.cache.updateCachedMaxReadSeq(a,{maxSeq:D+1,maxSeqTime:M.sendTime}),m&&(v.cache.updateCachedMaxReadSeq(a,{hasReadSeq:y+1}),v.cache.tryUpdateCachedMessages(a,{clientMsgID:M.clientMsgID,seq:M.seq})))}}})},c=0,u=Object.entries(t);c0){if(!r)return s.map(function(e){v.cache.tryUpdateCachedMessages(ne(e),e)}),Promise.resolve();v.instance.triggerEvent({event:D.OnRecvNewMessages,data:s.map(De),operationID:n})}return Promise.resolve()}catch(e){return Promise.reject(e)}},this.instance=t,this.cache=new Ae(t),this.syncer=new Re(t),this.typingManager=new be(t)},xe=/*#__PURE__*/function(){function e(e){var t=this,n=this,r=this,o=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=function(e,t){try{return Promise.resolve(n.instance.sendHttpRequest({reqFuncName:m.GetFullGroupMemberUserIDs,data:{groupID:e,idHash:0},operationID:t})).then(function(t){n.cachedGroupMembersID.set(e,t.userIDs)})}catch(e){return Promise.reject(e)}},this.getGroupInfosWithCache=function(e,t){try{var n=[],o=[];return e.forEach(function(e){var t=r.cachedGroups.get(e);t?n.push(t):o.push(e)}),o.length?Promise.resolve(r.instance.sendHttpRequest({reqFuncName:h.GetSpecifiedGroupsInfo,data:{groupIDs:o},operationID:t})).then(function(e){var t=e.groupInfos;return t&&t.forEach(function(e){return r.cachedGroups.set(e.groupID,e)}),[].concat(n,null!=t?t:[])}):Promise.resolve(n)}catch(e){return Promise.reject(e)}},this.getGroupMembersWithCache=function(e){var t=e.groupID,n=e.userIDList,r=e.operationID;try{var i,s,a=null!=(i=o.cachedGroupMembers.get(t))?i:[],c=function(){if(null!=n&&n.length){var e=[],i=[];return n.forEach(function(t){var n=a.find(function(e){return e.userID===t});n?i.push(n):e.push(t)}),e.length?Promise.resolve(o.instance.sendHttpRequest({reqFuncName:h.GetSpecifiedGroupMembersInfo,data:{groupID:t,userIDs:e},operationID:r})).then(function(e){var n=e.members;n&&o.cachedGroupMembers.set(t,[].concat(a,n));var r=[].concat(i,null!=n?n:[]);return s=1,r}):(s=1,i)}}();return Promise.resolve(c&&c.then?c.then(function(e){return s?e:a}):s?c:a)}catch(e){return Promise.reject(e)}},this.updateCachedGroups=function(e){e.map(function(e){t.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=function(e){var n,r=e[0].groupID,o=null!=(n=t.cachedGroupMembers.get(r))?n:[];t.cachedGroupMembers.set(r,[].concat(o.filter(function(t){return!e.find(function(e){return e.userID===t.userID})}),e));var i=t.instance.messageTrigger.cache.getAllCachedConversations().find(function(t){return t.groupID===e[0].groupID}),s=JSON.parse((null==i?void 0:i.latestMsg)||"{}"),a=e.find(function(e){return e.userID===s.sendID&&e.nickname!==s.senderNickname});i&&a&&t.instance.messageTrigger.getOneConversationAndTryChange(i.conversationID,"",{latestMsg:c({},s,{senderNickname:a.nickname})})},this.clearCachedGroupMembers=function(e){t.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=function(e){return t.cachedGroupMembersID.has(e)},this.getCachedGroupMembersID=function(e){var n;return null!=(n=t.cachedGroupMembersID.get(e))?n:[]},this.tryAddCachedGroupMembersID=function(e,n){if(t.cachedGroupMembersID.has(e)){var r,o=null!=(r=t.cachedGroupMembersID.get(e))?r:[];t.cachedGroupMembersID.set(e,[].concat(o,n))}},this.tryDeleteCachedGroupMembersID=function(e,n){if(t.cachedGroupMembersID.has(e)){var r,o=null!=(r=t.cachedGroupMembersID.get(e))?r:[];t.cachedGroupMembersID.set(e,o.filter(function(e){return!n.includes(e)}))}},this.instance=e}return e.prototype.clear=function(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()},e}(),je=/*#__PURE__*/function(){function t(t){var n=this,r=this,o=this,i=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=function(e){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:m.GetGroupVersion,data:{userID:r.instance.userID,version:r.syncedGroupsVersion,versionID:r.syncedGroupsVersionID},operationID:e})).then(function(t){r.syncedGroupsVersionID&&r.compareGroupVersionAndTrigger(t,e),r.syncedGroupsVersion=t.version,r.syncedGroupsVersionID=t.versionID})}catch(e){return Promise.reject(e)}},this.syncGroupInfoAndMemberVersion=function(e){try{var t=function(){if(n.length)return Promise.resolve(o.instance.sendHttpRequest({reqFuncName:m.GetGroupMemberVersion,data:{userID:o.instance.userID,reqList:n},operationID:e})).then(function(t){var n=t.respList;Object.keys(o.syncedGroupMemberVersion).length>0&&o.compareGroupMemberVersionAndTrigger(n,e),o.syncedGroupMemberVersion=n;for(var r=0,i=Object.entries(n);r0},0,function(){var t=n.queue.shift(),r=function(e,n){try{var r=Promise.resolve(t()).then(function(){})}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(0,function(t){e.error("Error executing task:",t)});if(r&&r.then)return r.then(function(){})});return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},t}();function st(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var at=((ot={})[_.TextMessage]="textElem",ot[_.AtTextMessage]="atTextElem",ot[_.LocationMessage]="locationElem",ot[_.CustomMessage]="customElem",ot[_.MergeMessage]="mergeElem",ot[_.QuoteMessage]="quoteElem",ot[_.CardMessage]="cardElem",ot[_.FaceMessage]="faceElem",ot[_.PictureMessage]="pictureElem",ot[_.VoiceMessage]="soundElem",ot[_.VideoMessage]="videoElem",ot[_.FileMessage]="fileElem",ot);function ct(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var ut=[m.GetActiveConversations,m.GetDesignatedConversation];function dt(e,t,n){if(!e.s){if(n instanceof pt){if(!n.s)return void(n.o=dt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(dt.bind(null,e,t),dt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var gt=/*#__PURE__*/function(n){function i(){var i,s;return(i=n.call(this)||this).userID=void 0,i.platform=void 0,i.token=void 0,i.apiAddr=void 0,i.loginStatus=K.Logout,i.isReconnected=!1,i.connectState="disconnected",i.wsManager=void 0,i.messageTrigger=void 0,i.userTrigger=void 0,i.groupTrigger=void 0,i.relationTrigger=void 0,i.businessTrigger=void 0,i.requestMap=new Map,i.generateHttpHeader=function(e,t){var n={"Content-Type":"application/json",token:i.token,operationID:t,reqFuncName:e};return ut.includes(e)&&(n["Content-Type"]="application/x-protobuf"),n},i.sendHttpRequest=function(e){try{var t;return Promise.resolve(function(e){var t=e.url,n=e.data,r=e.headers,o=e.platform,i=e.method,s=void 0===i?"POST":i;return"web"===o?function(e){var t=e.url,n=e.data,r=e.headers,o=e.method,i=void 0===o?"POST":o;try{return Promise.resolve(fetch(t,{method:i,headers:c({},r),body:n instanceof Uint8Array?n:JSON.stringify(n)}).then(function(e){if(e.ok)return e.json();throw new Error(e.statusText)}).then(function(e){if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))}catch(e){return Promise.reject(e)}}(e):new Promise(function(e,i){var a=function(e){return"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null}(o);a?a({url:t,data:n instanceof Uint8Array?Uint8Array.from(n).buffer:n,method:s,header:c({"Content-Type":"application/json"},r),success:function(t){200===t.statusCode&&0===t.data.errCode?e(t.data.data):i(t.data||"Request failed")},fail:function(e){i(e)}}):i(new Error("Request is not supported"))})}({url:""+i.apiAddr+(e.replaceURL||O[e.reqFuncName]),data:e.data,headers:i.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(t=i.wsManager)?void 0:t.platformNamespace)||"web"}))}catch(e){return Promise.reject(e)}},i.handleWsConnected=function(t,n){try{var r=function(){if(0===t.errCode){i.connectState="connected",i.loginStatus=K.Logged,i.triggerEvent({event:D.OnConnectSuccess}),i.triggerEvent({event:D.OnSyncServerStart});var r=[i.messageTrigger.sync(n),i.relationTrigger.sync(n),i.groupTrigger.sync(n),i.userTrigger.sync(n)],o=ct(function(){return Promise.resolve(Promise.all(r)).then(function(){i.triggerEvent({event:D.OnSyncServerFinish})})},function(t){e.error(t),i.triggerEvent({event:D.OnSyncServerFailed,errCode:t.errCode||S.SdkInternalError,errMsg:t.message||"Internal Error"})});if(o&&o.then)return o.then(function(){})}else{i.triggerEvent({event:D.OnConnectFailed,errCode:t.errCode,errMsg:t.errMsg,operationID:n});var s=$[t.errCode];s&&i.triggerEvent({event:s,errCode:t.errCode,errMsg:t.errMsg,operationID:n}),i.connectState="disconnected",i.loginStatus=K.Logout}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},i.handleMessage=function(e,t){try{var n=function(){if("string"!=typeof e){var n=function(){var t=ge(e),n=JSON.parse(t);i.handleGeneralWsResp(n)},r=function(){if(!(e instanceof ArrayBuffer))return Promise.resolve(e.arrayBuffer()).then(function(t){e=t})}();return r&&r.then?r.then(n):n()}var o=JSON.parse(e);i.handleWsConnected(o,t)}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},i.handleGeneralWsResp=function(e){var t=se(e.data,e.reqIdentifier);if(e.reqIdentifier===C.PushMsg&&t)return i.messageTrigger.triggerConversation(t.msgs,e.operationID),void i.messageTrigger.triggerNotification(t.notificationMsgs,e.operationID);if(e.reqIdentifier!==C.WsSubUserOnlineStatus||e.msgIncr||i.userTrigger.onlineSub.userOnlineStateChange(t),e.reqIdentifier===C.KickOnlineMsg)return i.triggerEvent({event:D.OnKickedOffline,operationID:e.operationID}),void i.reset();var n=i.requestMap.get(e.msgIncr);n&&(0===e.errCode?n.resolve(t):n.reject(new ue(e.errCode,e.errMsg)),i.requestMap.delete(e.msgIncr))},i.handleReconnecting=function(){i.connectState="reconnecting",i.triggerEvent({event:D.OnConnecting})},i.handleReconnectFailed=function(){i.connectState="disconnected",i.triggerEvent({event:D.OnConnectFailed,errCode:S.NetworkError,errMsg:"network error"})},i.handleReconnectSuccess=function(){i.isReconnected=!0},i.sendReqWaitResp=function(e){var t=e.data,n=e.reqIdentifier,o=e.operationID;if("connected"!==i.connectState)throw new ue(S.NetworkError,"network error, ws not connected");var s=ee();return new Promise(function(e,a){var c;i.requestMap.set(s,{resolve:e,reject:a}),null==(c=i.wsManager)||c.sendMessage({reqIdentifier:n,msgIncr:s,sendID:i.userID,operationID:o,data:r(t.buffer)})})},i.triggerEvent=function(t){var n=t.event,r=t.data,o=void 0===r?null:r,s=t.errCode,a=void 0===s?0:s,c=t.errMsg,u=void 0===c?"":c,d=t.operationID,g=void 0===d?"":d;i.loginStatus!==K.Logout&&(e.debug("%cSDK =>%c [OperationID:"+g+"] (event) trigger "+n+" with data "+JSON.stringify(o)+" errCode "+a+" errMsg "+u,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),i.emit(n,{event:n,data:o,errCode:a,errMsg:u,operationID:g}))},i.login=function(t,n){try{return Promise.resolve(de(K.Logged,h.Login,n,function(){try{var r,o=t.userID,s=t.token,a=t.wsAddr,c=t.apiAddr,u=t.platformID;if(i.wsManager)throw new ue(S.LoginRepeatError,"login repeat");return e.setLevel(null!=(r=t.logLevel)?r:B.Debug),i.userID=o,i.token=s,i.apiAddr=c,i.platform=u,i.wsManager=new fe(a,{sendID:o,token:s,platformID:u,operationID:n,isBackground:!1,isMsgResp:!0,sdkType:"js"},i.handleMessage,i.handleReconnecting,i.handleReconnectFailed,i.handleReconnectSuccess),i.connectState="connecting",i.loginStatus=K.Logging,i.triggerEvent({event:D.OnConnecting,operationID:n}),Promise.resolve(ct(function(){return Promise.resolve(i.wsManager.connect()).then(function(){})},function(e){throw i.triggerEvent({event:D.OnConnectFailed,errCode:S.NetworkError,errMsg:e.message||"network error",operationID:n}),i.connectState="disconnected",i.loginStatus=K.Logout,i.wsManager.close(),new ue(S.NetworkError,e.message||"network error")}))}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},i.getLoginStatus=function(e){return de(K.Logged,h.GetLoginStatus,e,function(){try{var e;return null==(e=i.wsManager)||e.sendPing(),Promise.resolve(i.loginStatus)}catch(e){return Promise.reject(e)}})},i.logout=function(e){return de(i.loginStatus,h.Logout,e,function(){try{return i.reset(),Promise.resolve()}catch(e){return Promise.reject(e)}})},i.internalUploadFile=function(e,n){return Promise.resolve(ct(function(){var r=i.userID+"/"+e.name,o=function(e){var t,n,r=null!=(t=null==(n=e.split(".").pop())?void 0:n.toLowerCase())?t:"";return M[r]||"application/octet-stream"}(e.name),s={operationID:n,token:i.token};return Promise.resolve(function(e,t,n){return fetch(e+"/object/part_size",{method:"POST",headers:c({},n),body:JSON.stringify({size:t})}).then(I)}(i.apiAddr,e.size,s)).then(function(n){var a=n.size;function u(){var n=p.join(",");l.destroy();var u=new t;return u.append(n),Promise.resolve(function(e,t,n){return fetch(e+"/object/initiate_multipart_upload",{method:"POST",headers:c({},n),body:JSON.stringify(t)}).then(I)}(i.apiAddr,{hash:u.end(),size:e.size,partSize:a,maxParts:-1,cause:"",name:r,contentType:o},s)).then(function(t){var n=t.url,a=t.upload;if(u.destroy(),n)return{url:n};var d=a.sign.query,l=a.sign.header;return Promise.resolve(Promise.all(a.sign.parts.map(function(t,n){try{var r=new URL(t.url||a.sign.url);if(d){var i=new URLSearchParams(r.search);d.forEach(function(e){i.set(e.key,e.values[0])}),r.search=i.toString()}if(t.query){var s=new URLSearchParams(r.search);t.query.forEach(function(e){s.set(e.key,e.values[0])}),r.search=s.toString()}var c=r.toString(),u=new Headers;return l&&l.forEach(function(e){u.set(e.key,e.values[0])}),t.header&&t.header.forEach(function(e){u.set(e.key,e.values[0])}),u.set("Content-Length",(g[n].end-g[n].start).toString()),u.set("Content-Type",o),Promise.resolve(fetch(c,{method:"PUT",headers:u,body:e.slice(g[n].start,g[n].end)})).then(function(e){if(!e.ok)throw new Error("Failed to upload chunk "+(n+1))})}catch(e){return Promise.reject(e)}}))).then(function(){return Promise.resolve(function(e,t,n){return fetch(e+"/object/complete_multipart_upload",{method:"POST",headers:c({},n),body:JSON.stringify(t)}).then(I)}(i.apiAddr,{uploadID:a.uploadID,parts:p,cause:"",name:r,contentType:o},s)).then(function(e){return{url:e.url}})})})}var d=Math.ceil(e.size/a),g=[],p=[],l=new t.ArrayBuffer,f=0,v=function(e,t,n){for(var r;;){var o=e();if(lt(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!lt(i)){r=1;break}i=i.s}}var s=new pt,a=dt.bind(null,s,2);return(0===r?o.then(u):1===r?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(u).then(void 0,a):u(o):dt(s,1,i)})).then(void 0,a),s;function c(t){i=t;do{if(!(o=e())||lt(o)&&!o.v)return void dt(s,1,i);if(o.then)return void o.then(u).then(void 0,a);lt(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,a)}function u(e){e?(i=n())&&i.then?i.then(c).then(void 0,a):c(i):dt(s,1,i)}}(function(){return fp?g:p,count:r-t.length,conversationID:o,operationID:i,fetchedMessages:d})}return d}):Promise.resolve(a)}catch(e){return Promise.reject(e)}};return{createTextMessage:function(e,n){return de(t.loginStatus,h.CreateTextMessage,n,function(){try{var n=ae(t,P.UserMsgType,_.TextMessage);return n.textElem={content:e},Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createTextAtMessage:function(e,n){return de(t.loginStatus,h.CreateTextAtMessage,n,function(){try{var n;if(!e.text)throw new ue(S.ArgsError,"text cannot be empty");if(e.atUserIDList.length>10)throw new ue(S.ArgsError,"atUserIDList length must be less than 10");var r,o=ae(t,P.UserMsgType,_.AtTextMessage);return(null==(n=e.message)?void 0:n.contentType)===_.QuoteMessage&&(e.message.contentType=_.TextMessage,e.message.textElem={content:null==(r=e.message.quoteElem)?void 0:r.text}),o.atTextElem={text:e.text,atUserList:e.atUserIDList,atUsersInfo:e.atUsersInfo,quoteMessage:e.message},Promise.resolve(o)}catch(e){return Promise.reject(e)}})},createLocationMessage:function(e,n){return de(t.loginStatus,h.CreateLocationMessage,n,function(){try{var n=ae(t,P.UserMsgType,_.LocationMessage);return n.locationElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createCustomMessage:function(e,n){return de(t.loginStatus,h.CreateCustomMessage,n,function(){try{var n=ae(t,P.UserMsgType,_.CustomMessage);return n.customElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createQuoteMessage:function(e,n){return de(t.loginStatus,h.CreateQuoteMessage,n,function(){try{var n,r=ae(t,P.UserMsgType,_.QuoteMessage),o=JSON.parse(e.message);return o.contentType===_.QuoteMessage&&(o.contentType=_.TextMessage,o.textElem={content:null==(n=o.quoteElem)?void 0:n.text}),r.quoteElem={text:e.text,quoteMessage:o},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createCardMessage:function(e,n){return de(t.loginStatus,h.CreateCardMessage,n,function(){try{var n=ae(t,P.UserMsgType,_.CardMessage);return n.cardElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createImageMessageByURL:function(e,n){return de(t.loginStatus,h.CreateImageMessageByURL,n,function(){try{var n=ae(t,P.UserMsgType,_.PictureMessage);return n.pictureElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createImageMessageByFile:function(e,r){try{return Promise.resolve(de(t.loginStatus,h.CreateImageMessageByFile,r,function(){try{var r=ae(t,P.UserMsgType,_.PictureMessage);return r.pictureElem=c({},e),n.set(e.sourcePicture.uuid,e.file),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createSoundMessageByURL:function(e,n){return de(t.loginStatus,h.CreateSoundMessageByURL,n,function(){try{var n=ae(t,P.UserMsgType,_.VoiceMessage);return n.soundElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createSoundMessageByFile:function(e,r){try{return Promise.resolve(de(t.loginStatus,h.CreateSoundMessageByFile,r,function(){try{var r=ae(t,P.UserMsgType,_.VoiceMessage);return r.soundElem=c({},e),n.set(e.uuid,e.file),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createVideoMessageByURL:function(e,n){return de(t.loginStatus,h.CreateVideoMessageByURL,n,function(){try{var n=ae(t,P.UserMsgType,_.VideoMessage);return n.videoElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createVideoMessageByFile:function(e,r){try{return Promise.resolve(de(t.loginStatus,h.CreateVideoMessageByFile,r,function(){try{var r=ae(t,P.UserMsgType,_.VideoMessage);return r.videoElem=c({},e),n.set(e.videoUUID,e.videoFile),n.set(e.snapshotUUID,e.snapshotFile),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createFileMessageByURL:function(e,n){return de(t.loginStatus,h.CreateFileMessageByURL,n,function(){try{var n=ae(t,P.UserMsgType,_.FileMessage);return n.fileElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createFileMessageByFile:function(e,r){try{return Promise.resolve(de(t.loginStatus,h.CreateFileMessageByFile,r,function(){try{var r=ae(t,P.UserMsgType,_.FileMessage);return r.fileElem=c({},e),n.set(e.uuid,e.file),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createMergerMessage:function(e,n){return de(t.loginStatus,h.CreateMergerMessage,n,function(){try{var n=ae(t,P.UserMsgType,_.MergeMessage);return n.mergeElem={title:e.title,abstractList:e.summaryList,multiMessage:e.messageList,messageEntityList:[]},Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createFaceMessage:function(e,n){return de(t.loginStatus,h.CreateFaceMessage,n,function(){try{var n=ae(t,P.UserMsgType,_.FaceMessage);return n.faceElem=c({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createForwardMessage:function(e,n){return de(t.loginStatus,h.CreateForwardMessage,n,function(){try{if(e.status!==x.Succeed)throw new ue(S.ArgsError,"Only successfully sent messages can be forwarded");var n=ae(t,P.UserMsgType,e.contentType);return Promise.resolve(c({},e,n,{seq:0,status:x.Sending}))}catch(e){return Promise.reject(e)}})},sendMessage:function(e,i){try{return Promise.resolve(de(t.loginStatus,h.SendMessage,i,function(){return r.enqueue(function(){try{var r=c({},e,{message:c({},e.message)}),s=r.message,a=r.recvID,u=r.groupID,d=r.isOnlineOnly,g=r.offlinePushInfo,p=void 0===g?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:g;void 0===p.signalInfo&&(p.signalInfo="");var l=at[s.contentType];if(!l)throw new ue(S.MsgContentTypeNotSupportError,"Unknown message content type");s.recvID=a,s.groupID=u,s.sessionType=u?H.Group:H.Single;var f={};d&&Object.values(A).forEach(function(e){return f[e]=!1});var v=ne(s),h=!1;return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(v,i)).then(function(e){function r(){function r(r){function c(r){function c(r){function c(r){function c(n){var r,c,d=JSON.stringify(s[l]),g=o.MsgData.encode({sendID:t.userID,recvID:a||"",groupID:u||"",clientMsgID:s.clientMsgID,serverMsgID:s.serverMsgID||"",senderPlatformID:t.platform,senderNickname:s.senderNickname,senderFaceURL:s.senderFaceUrl,sessionType:s.sessionType,msgFrom:s.msgFrom,contentType:s.contentType,content:pe(d),seq:s.seq,sendTime:0,createTime:s.createTime,status:s.status,isRead:!1,options:f,offlinePushInfo:p,atUserIDList:null!=(r=null==(c=s.atTextElem)?void 0:c.atUserList)?r:[],attachedInfo:s.attachedInfoElem?JSON.stringify(s.attachedInfoElem):"",ex:s.ex||"",keyVersion:0,dstUserIDs:[]}).finish();return st(function(){return Promise.resolve(t.sendReqWaitResp({data:g,operationID:i,reqIdentifier:C.SendMsg})).then(function(n){var r=n.serverMsgID,o=n.sendTime;return s.sendTime=o,s.serverMsgID=r,s.status=x.Succeed,t.messageTrigger.setTriggeredConversationEvent(i),t.messageTrigger.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:o}),t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s),latestMsgSendTime:o}),s})},function(e){throw s.status=x.Failed,t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s)}),e})}var d=function(){if(s.contentType===_.FileMessage){var e,r=n.get(null==(e=s.fileElem)?void 0:e.uuid);if(!r)throw new ue(S.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(r,i)).then(function(e){var t,r=e.url,o=void 0===r?"":r,i=e.error;if(n.delete(null==(t=s.fileElem)?void 0:t.uuid),i)throw new ue(S.NetworkError,"Upload file failed");s.fileElem.sourceUrl=o})}}();return d&&d.then?d.then(c):c()}var d=function(){if(s.contentType===_.VideoMessage){var e,r,o=n.get(null==(e=s.videoElem)?void 0:e.videoUUID),a=n.get(null==(r=s.videoElem)?void 0:r.snapshotUUID);if(!o||!a)throw new ue(S.ArgsError,"Can not find target file");return Promise.resolve(Promise.all([t.internalUploadFile(o,i),t.internalUploadFile(a,i)])).then(function(e){var t,r;if(n.delete(null==(t=s.videoElem)?void 0:t.videoUUID),n.delete(null==(r=s.videoElem)?void 0:r.snapshotUUID),e[0].error||e[1].error)throw new ue(S.NetworkError,"Upload file failed");s.videoElem.videoUrl=e[0].url,s.videoElem.snapshotUrl=e[1].url})}}();return d&&d.then?d.then(c):c()}var d=function(){if(s.contentType===_.VoiceMessage){var e,r=n.get(null==(e=s.soundElem)?void 0:e.uuid);if(!r)throw new ue(S.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(r,i)).then(function(e){var t,r=e.url,o=void 0===r?"":r,i=e.error;if(n.delete(null==(t=s.soundElem)?void 0:t.uuid),i)throw new ue(S.NetworkError,"Upload file failed");s.soundElem.sourceUrl=o})}}();return d&&d.then?d.then(c):c()}e.latestMsgSendTime=s.createTime,t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s)},void 0,h);var d=function(){if(s.contentType===_.PictureMessage){var e,r=n.get(null==(e=s.pictureElem)?void 0:e.sourcePicture.uuid);if(!r)throw new ue(S.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(r,i)).then(function(e){var t,r=e.url,o=void 0===r?"":r,i=e.error;if(n.delete(null==(t=s.pictureElem)?void 0:t.sourcePicture.uuid),i)throw new ue(S.NetworkError,"Upload file failed");s.pictureElem.sourcePicture.url=o,s.pictureElem.bigPicture.url=o,s.pictureElem.snapshotPicture.width=640,s.pictureElem.snapshotPicture.height=640,s.pictureElem.snapshotPicture.url=o+"?type=image&width=640&height=640"})}}();return d&&d.then?d.then(c):c()}var c=function(){if(u)return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:u,userIDList:[t.userID],operationID:i})).then(function(e){if(null==e||!e.length)throw new ue(S.ArgsError,"user not join target group");e[0].nickname&&(s.senderNickname=e[0].nickname)})}();return c&&c.then?c.then(r):r()}var d=function(){if(!e)return h=!0,Promise.resolve(t.messageTrigger.initConversation({sourceID:u||a,sessionType:s.sessionType,operationID:i})).then(function(t){e=t});e.isPrivateChat&&(f[A.IsNotPrivate]=!1,s.attachedInfoElem=c({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:e.burnDuration}))}();return d&&d.then?d.then(r):r()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},sendMessageNotOss:function(e,n){try{return Promise.resolve(de(t.loginStatus,h.SendMessage,n,function(){return r.enqueue(function(){try{var r=c({},e,{message:c({},e.message)}),i=r.message,s=r.recvID,a=r.groupID,u=r.isOnlineOnly,d=r.offlinePushInfo,g=void 0===d?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:d;void 0===g.signalInfo&&(g.signalInfo="");var p=at[i.contentType];if(!p)throw new ue(S.MsgContentTypeNotSupportError,"Unknown message content type");i.recvID=s,i.groupID=a,i.sessionType=a?H.Group:H.Single;var l={};u&&Object.values(A).forEach(function(e){return l[e]=!1});var f=ne(i);return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(f,n)).then(function(e){function r(r){var c,u;e.latestMsgSendTime=i.createTime,t.messageTrigger.getOneConversationAndTryChange(f,n,{latestMsg:JSON.stringify(i)});var d=JSON.stringify(i[p]),v=o.MsgData.encode({sendID:t.userID,recvID:s||"",groupID:a||"",clientMsgID:i.clientMsgID,serverMsgID:i.serverMsgID||"",senderPlatformID:t.platform,senderNickname:i.senderNickname,senderFaceURL:i.senderFaceUrl,sessionType:i.sessionType,msgFrom:i.msgFrom,contentType:i.contentType,content:pe(d),seq:i.seq,sendTime:0,createTime:i.createTime,status:i.status,isRead:!1,options:l,offlinePushInfo:g,atUserIDList:null!=(c=null==(u=i.atTextElem)?void 0:u.atUserList)?c:[],attachedInfo:i.attachedInfoElem?JSON.stringify(i.attachedInfoElem):"",ex:i.ex||"",keyVersion:0,dstUserIDs:[]}).finish();return st(function(){return Promise.resolve(t.sendReqWaitResp({data:v,operationID:n,reqIdentifier:C.SendMsg})).then(function(r){var o=r.serverMsgID,s=r.sendTime;return i.sendTime=s,i.serverMsgID=o,i.status=x.Succeed,t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:s}),t.messageTrigger.getOneConversationAndTryChange(f,n,{latestMsg:JSON.stringify(i),latestMsgSendTime:s}),i})},function(e){throw i.status=x.Failed,t.messageTrigger.getOneConversationAndTryChange(f,n,{latestMsg:JSON.stringify(i)}),e})}var u=function(){if(!e)return Promise.resolve(t.messageTrigger.initConversation({sourceID:a||s,sessionType:i.sessionType,operationID:n})).then(function(r){return e=r,function(){if(a)return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:a,userIDList:[t.userID],operationID:n})).then(function(e){if(null==e||!e.length)throw new ue(S.ArgsError,"user not join target group");e[0].nickname&&(i.senderNickname=e[0].nickname)})}()});e.isPrivateChat&&(l[A.IsNotPrivate]=!1,i.attachedInfoElem=c({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:e.burnDuration}))}();return u&&u.then?u.then(r):r()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},revokeMessage:function(e,n){try{return Promise.resolve(de(t.loginStatus,h.RevokeMessage,n,function(){try{var r=function(r){return Promise.resolve(t.sendHttpRequest({reqFuncName:h.RevokeMessage,data:{conversationID:e.conversationID,seq:o.seq,userID:t.userID},operationID:n})).then(function(){t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.revokeMessage({revokerUserID:t.userID,clientMsgID:o.clientMsgID,revokeTime:Date.now(),sesstionType:o.sessionType,seq:o.seq,conversationID:e.conversationID,isAdminRevoke:!1},n)})},o=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(e.conversationID,[e.clientMsgID])[0];if(!o)throw new ue(S.ArgsError,"message not exist");var i=function(){if(o.sendID!==t.userID){if(!o.groupID)throw new ue(S.ArgsError,"message can not be revoked");return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:o.groupID,userIDList:[t.userID],operationID:n})).then(function(e){var t=e[0];if(!t||t.roleLevel===E.Nomal)throw new ue(S.ArgsError,"message can not be revoked")})}}();return Promise.resolve(i&&i.then?i.then(r):r())}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},getAdvancedHistoryMessageList:function(n,r){try{return Promise.resolve(de(t.loginStatus,h.GetAdvancedHistoryMessageList,r,function(){try{var o={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(s!==n.conversationID&&(i=null,s=n.conversationID),n.startClientMsgID){if(null===i){var u=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!u)return Promise.resolve(c({},o,{isEnd:!0}));i=u.seq}}else i=0;var d=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);return e.log("syncedSeqs",d),d?Promise.resolve(a({maxSeq:i?i-1:d.maxSeq,count:n.count,conversationID:n.conversationID,operationID:r})).then(function(s){function a(){function a(){var t,a;return o.messageList=s.map(De),e.debug("getAdvancedHistoryMessageList with opid: ",r,"messageList: ",o.messageList),i=null!=(t=null==(a=s[0])?void 0:a.seq)?t:0,c({},o,{isEnd:s.length%c [OperationID:"+n[n.length-1]+"] (invoked) run "+t+" with args "+JSON.stringify(n),"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")}(n,r),Promise.resolve(o.apply(t,r)).then(function(t){var r,o;return r=n,(o=t).errCode?e.debug("%cSDK =>%c [OperationID:"+o.operationID+"] (response) run "+r+" with error "+JSON.stringify(o),"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):e.debug("%cSDK =>%c [OperationID:"+o.operationID+"] (response) run "+r+" with response before processor "+JSON.stringify(o.data),"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),t.errCode?Promise.reject(t):t})}catch(e){return Promise.reject(e)}}:Reflect.get(t,n,r)}})};export{F as AllowType,V as ApplicationHandleResult,D as CbEvents,S as ErrorCode,J as GroupAtType,k as GroupJoinSource,W as GroupMemberFilter,E as GroupMemberRole,N as GroupStatus,q as GroupType,L as GroupVerificationType,G as InternalContentType,b as InternalMessageStatus,B as LogLevel,K as LoginStatus,A as MessageOptionsKey,w as MessageReceiveOptType,x as MessageStatus,_ as MessageType,P as MsgFrom,T as NotificationType,z as OnlineState,j as Platform,Q as Relationship,C as ReqIdentifier,h as RequestApi,H as SessionType,Y as ViewType,R as WorkMomentSdkNotificationType,U as WsErrorCode,$ as WsErrorEventMap,ft as getSDK}; +import e from"loglevel";import t from"spark-md5";import{decode as n,encode as r}from"base64-arraybuffer";import{PbCoder as i,SdkWsProto as o}from"@openim/protocol";import s from"crypto-js";function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;tt.latestMsgSendTime?-1:e.latestMsgSendTime>6*(r-1)),o=1;o>6*(r-(o+1))&191);return}}},Me=function(e,t,n,r){var i=t.getUint8(n);if(e.bytesRead=1,e.charVal=0,128&i){for(var o=0,s=i;128&s;)o++,s<<=1;if(1===o)return console.error("UTF-8 read - found continuation byte at beginning of character"),void(e.charVal=Ie);if(o>r)return console.error("UTF-8 read - attempted to read "+o+" byte character, "+(r-o)+" bytes past end of buffer"),void(e.charVal=Ie);e.charVal=i&255>>o+1;for(var a=1;a>8-(o+1)-1))return console.error("UTF-8 read - found overlong encoding"),e.charVal=Ie,void(e.bytesRead=1);e.bytesRead++}if(e.charVal>1114111)return console.error("UTF-8 read - found illegally high code point "+e.charVal),e.charVal=Ie,void(e.bytesRead=1)}else e.charVal=i},ye=function(e){for(var t=[],n=0;n255&&(r="?".charCodeAt(0)),t.push(r)}return t},Ce=function(e,t,n,r){var i=void 0===n,o=t||0;if(!i&&o+n>e.byteLength)throw new Error("Attempted to read "+(o+n-e.byteLength)+" bytes past end of buffer");for(var s=[],a={};oo-t)&&(Me(a,e,o,i?e.byteLength-(o+t):n-(o-t)),o+=a.bytesRead,!i||a.charVal!==r);)s.push(String.fromCharCode(a.charVal));return{str:s.join(""),byteLength:o-t}},Te=function(e,t,n,r){var i=[],o=0;t=t||0;var s=!1;void 0===n&&(s=!0,n=e.byteLength-e.byteOffset);for(var a=0;a=e.byteLength&&(i-=1),e.setUint8(t+i,0),i+1},e}()),we=function(e){return(new TextDecoder).decode(e)},Ue=function(e){return(new TextEncoder).encode(e)};!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(Ae||(Ae={}));var Oe,Ee=/*#__PURE__*/function(){function e(e,t,n,r,i,o,s,a,c,u){var d=this,g=this;void 0===a&&(a=5e3),void 0===c&&(c=Infinity),this.url=void 0,this.onMessage=void 0,this.onClose=void 0,this.onReconnecting=void 0,this.onReconnectFailed=void 0,this.onReconnectSuccess=void 0,this.reconnectInterval=void 0,this.maxReconnectAttempts=void 0,this.ws=void 0,this.connectParams=void 0,this.reconnectAttempts=void 0,this.shouldReconnect=void 0,this.isProcessingMessage=!1,this.consecutiveHeartbeatFailures=0,this.connectTimeoutId=null,this.platformNamespace=void 0,this.envListenersInstalled=!1,this.heartbeatConfig={interval:1e4,timeout:5e3,maxFailures:3},this.heartbeatWorker=null,this.legacyTimer=null,this.heartbeatTimeoutId=null,this.workerUrl=null,this.lastPongAt=0,this.forceImmediateReconnect=!1,this.checkPlatform=function(){if("undefined"!=typeof WebSocket)try{if("undefined"!=typeof window&&window.WebSocket)return"web";if("undefined"!=typeof global&&global.WebSocket)return"web"}catch(e){}return"undefined"!=typeof my&&"function"==typeof my.connectSocket?"my":"undefined"!=typeof uni&&"function"==typeof uni.connectSocket?"uni":"undefined"!=typeof wx&&"function"==typeof wx.connectSocket?"wx":"unknow"},this.urlFormat=function(){for(var e="?",t=0,n=Object.entries(g.connectParams);t {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n "],{type:"application/javascript"});g.workerUrl=URL.createObjectURL(e),g.heartbeatWorker=new Worker(g.workerUrl),g.heartbeatWorker.onmessage=function(e){"ping"===e.data.type&&g.sendPing()},g.heartbeatWorker.postMessage({type:"start",interval:g.heartbeatConfig.interval})}catch(e){g.heartbeatWorker=null,g.workerUrl&&(URL.revokeObjectURL(g.workerUrl),g.workerUrl=null),g.legacyTimer=setInterval(function(){g.sendPing()},g.heartbeatConfig.interval)}else g.legacyTimer=setInterval(function(){g.sendPing()},g.heartbeatConfig.interval)},this.connect=function(e){return void 0===e&&(e=1e4),"unknow"===g.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise(function(t,n){if(g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.connectTimeoutId=setTimeout(function(){g.ws&&(g.ws.close(),g.onClose()),n(new Error("Connection timeout after "+e+"ms"))},e),g.ws&&g.ws.readyState!==Ae.CLOSED)g.ws.readyState===g.ws.OPEN?(g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),t()):(g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),n(new Error("WebSocket is in an unknown state")));else{var r=function(){g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.reconnectAttempts&&g.onReconnectSuccess(),g.reconnectAttempts=0,g.consecutiveHeartbeatFailures=0,g.lastPongAt=Date.now(),g.startHeartbeat(),t()},i=function(e){g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),n(e)};if("web"===g.platformNamespace)g.ws=new WebSocket(g.urlFormat()),g.ws.onopen=r,g.ws.onerror=i;else{var o={url:g.urlFormat(),complete:function(){}};"my"===g.platformNamespace&&(o.multiple=!0),"uni"===g.platformNamespace&&(g.ws=uni.connectSocket(o)),"wx"===g.platformNamespace&&(g.ws=wx.connectSocket(o)),"my"===g.platformNamespace&&(g.ws=my.connectSocket(o)),g.ws.onOpen(r),g.ws.onError(i)}g.setupEventListeners(),g.installEnvListeners()}})},this.setupEventListeners=function(){if(g.ws){var e=function(e){return g.onBinaryMessage(e.data)},t=function(e){if(g.shouldReconnect&&g.reconnectAttempts=g.heartbeatConfig.maxFailures)return console.warn("Heartbeat failed "+g.consecutiveHeartbeatFailures+" times, closing connection"),g.ws.close(),g.onClose(),void g.stopHeartbeat();g.heartbeatTimeoutId&&clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=setTimeout(function(){var e;g.consecutiveHeartbeatFailures++,console.warn("Heartbeat timeout, consecutive failures: "+g.consecutiveHeartbeatFailures),g.consecutiveHeartbeatFailures>=g.heartbeatConfig.maxFailures&&(null==(e=g.ws)||e.close(),g.onClose(),g.stopHeartbeat())},g.heartbeatConfig.timeout);var t=JSON.stringify({type:"ping"});g.ws.send("web"===g.platformNamespace?t:{data:t})}else g.heartbeatTimeoutId&&(clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=null)},this.forceHealthCheck=function(e){void 0===e&&(e=!1),g.ws&&g.ws.readyState===Ae.OPEN&&(e&&(g.consecutiveHeartbeatFailures=Math.max(g.heartbeatConfig.maxFailures-1,0)),g.sendPing())},this.handleVisibilityChange=function(){try{"visible"===("undefined"!=typeof document?document.visibilityState:"visible")&&g.forceHealthCheck(!0)}catch(e){}},this.handleOnline=function(){if(!g.ws||g.ws.readyState!==Ae.OPEN)return g.reconnectAttempts=0,g.onReconnecting(),g.connectParams.operationID=ie(),void g.connect().catch(function(){g.onReconnectFailed()});var e=Date.now();g.lastPongAt&&e-g.lastPongAt>g.heartbeatConfig.interval+g.heartbeatConfig.timeout*g.heartbeatConfig.maxFailures&&g.forceHealthCheck(!0)},this.handleOffline=function(){g.stopHeartbeat()},this.installEnvListeners=function(){if(!g.envListenersInstalled&&"web"===g.platformNamespace)try{"undefined"!=typeof document&&document.addEventListener&&document.addEventListener("visibilitychange",g.handleVisibilityChange),"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("online",g.handleOnline),window.addEventListener("offline",g.handleOffline),window.addEventListener("pageshow",g.handleVisibilityChange),window.addEventListener("focus",g.handleVisibilityChange)),g.envListenersInstalled=!0}catch(e){}},this.removeEnvListeners=function(){if(g.envListenersInstalled&&"web"===g.platformNamespace){try{"undefined"!=typeof document&&document.removeEventListener&&document.removeEventListener("visibilitychange",g.handleVisibilityChange),"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("online",g.handleOnline),window.removeEventListener("offline",g.handleOffline),window.removeEventListener("pageshow",g.handleVisibilityChange),window.removeEventListener("focus",g.handleVisibilityChange))}catch(e){}g.envListenersInstalled=!1}},this.sendMessage=function(e){var t,n=Ue(JSON.stringify(e));(null==(t=g.ws)?void 0:t.readyState)===Ae.OPEN?g.ws.send("web"===g.platformNamespace?n:{data:Uint8Array.from(n).buffer}):console.error("WebSocket is not open. Message not sent.")},this.close=function(){var e;g.shouldReconnect=!1,g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.heartbeatTimeoutId&&(clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=null),(null==(e=g.ws)?void 0:e.readyState)===Ae.OPEN&&(g.ws.close(),g.onClose()),g.stopHeartbeat(),g.removeEnvListeners()},this.forceReconnect=function(e){if(void 0===e&&(e=!0),g.shouldReconnect=!0,g.reconnectAttempts=0,g.consecutiveHeartbeatFailures=0,e&&(g.forceImmediateReconnect=!0),!g.ws||g.ws.readyState===Ae.CLOSED)return g.onReconnecting(),g.connectParams.operationID=ie(),void g.connect().catch(function(){g.onReconnectFailed()});g.stopHeartbeat();try{g.ws.close()}catch(e){g.onReconnecting(),g.connectParams.operationID=ie(),g.connect().catch(function(){g.onReconnectFailed()})}},this.reset=function(){g.shouldReconnect=!0,g.reconnectAttempts=0,g.consecutiveHeartbeatFailures=0,g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.heartbeatTimeoutId&&(clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=null),g.stopHeartbeat(),g.removeEnvListeners()},this.url=e,this.onMessage=n,this.onClose=r,this.onReconnecting=i,this.onReconnectFailed=o,this.onReconnectSuccess=s,this.reconnectInterval=a,this.maxReconnectAttempts=c,this.connectParams=t,this.reconnectInterval=a,this.maxReconnectAttempts=c,this.reconnectAttempts=0,this.shouldReconnect=!0,this.platformNamespace=this.checkPlatform(),u&&(this.heartbeatConfig=l({},this.heartbeatConfig,u))}return e.prototype.stopHeartbeat=function(){this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.heartbeatWorker&&(this.heartbeatWorker.postMessage({type:"stop"}),this.heartbeatWorker.terminate(),this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.heartbeatWorker=null),this.legacyTimer&&(clearInterval(this.legacyTimer),this.legacyTimer=null)},e}(),Fe=/*#__PURE__*/function(){function e(){this.events=void 0,this.events={}}var t=e.prototype;return t.emit=function(e,t){return this.events[e]&&this.events[e].forEach(function(e){return e(t)}),this},t.on=function(e,t){return this.events[e]?this.events[e].push(t):this.events[e]=[t],this},t.off=function(e,t){if(e&&"function"==typeof t&&this.events[e]){var n=this.events[e];if(!n||0===n.length)return;var r=n.findIndex(function(e){return e===t});-1!==r&&n.splice(r,1)}return this},e}(),ke=["friendUser"],qe=["blackUserInfo"],Le=function(e){var t,n,r,i,o,s,a,c,u,d,g,l,p,f;return{createTime:null==(t=e.groupInfo)?void 0:t.createTime,creatorUserID:null==(n=e.groupInfo)?void 0:n.creatorUserID,ex:e.ex,groupFaceURL:null==(r=e.groupInfo)?void 0:r.faceURL,groupID:null==(i=e.groupInfo)?void 0:i.groupID,groupName:null==(o=e.groupInfo)?void 0:o.groupName,groupType:null==(s=e.groupInfo)?void 0:s.groupType,handleResult:e.handleResult,handleUserID:e.handleUserID,handledMsg:e.handleMsg,handledTime:e.handleTime,introduction:null==(a=e.groupInfo)?void 0:a.introduction,memberCount:null==(c=e.groupInfo)?void 0:c.memberCount,nickname:null==(u=e.userInfo)?void 0:u.nickname,notification:null==(d=e.groupInfo)?void 0:d.notification,ownerUserID:null==(g=e.groupInfo)?void 0:g.ownerUserID,reqMsg:e.reqMsg,reqTime:e.reqTime,joinSource:e.joinSource,status:null==(l=e.groupInfo)?void 0:l.status,userFaceURL:null==(p=e.userInfo)?void 0:p.faceURL,userID:null==(f=e.userInfo)?void 0:f.userID}},je=function(e){return{clientMsgID:e.clientMsgID,serverMsgID:e.serverMsgID,createTime:e.createTime,sendTime:e.sendTime,sessionType:e.sessionType,sendID:e.sendID,recvID:e.recvID,msgFrom:e.msgFrom,contentType:e.contentType,senderPlatformID:e.senderPlatformID,senderNickname:e.senderNickname,senderFaceUrl:e.senderFaceURL,groupID:e.groupID,content:e.content.length?we(e.content):"",seq:e.seq,isRead:e.isRead,status:w.MsgStatusSendSuccess,isExternalExtensions:!1,offlinePush:e.offlinePushInfo,attachedInfo:e.attachedInfo,ex:e.ex,localEx:""}},xe=function(t){var n=l({},t);try{switch(t.contentType){case R.Text:n.textElem=JSON.parse(n.content);break;case R.Picture:n.pictureElem=JSON.parse(n.content);break;case R.Sound:n.soundElem=JSON.parse(n.content);break;case R.Video:n.videoElem=JSON.parse(n.content);break;case R.File:n.fileElem=JSON.parse(n.content);break;case R.AtText:n.atTextElem=JSON.parse(n.content);break;case R.Location:n.locationElem=JSON.parse(n.content);break;case R.Custom:case R.CustomMsgNotTriggerConversation:case R.CustomMsgOnlineOnly:n.customElem=JSON.parse(n.content);break;case R.Typing:n.typingElem=JSON.parse(n.content);break;case R.Merger:n.mergeElem=JSON.parse(n.content);break;case R.Face:n.faceElem=JSON.parse(n.content);break;case R.Quote:n.quoteElem=JSON.parse(n.content);break;case R.Card:n.cardElem=JSON.parse(n.content);break;default:n.notificationElem=JSON.parse(n.content)}}catch(t){e.warn("messageElemFormater messageElem parse failed",n)}if(t.attachedInfo)try{n.attachedInfoElem=JSON.parse(n.attachedInfo),n.attachedInfo=""}catch(t){e.warn("messageElemFormater attachedInfoElem failed",n.attachedInfo)}return n.content="",n},Be=function(e){var t=we(e),n=JSON.parse(t);return JSON.parse(n.detail)},Ve=function(e,t,n){var r=e.conversation,i=e.group,o=e.friend,s=e.user,a=e.lastMsg,c=e.maxSeq,u=e.readSeq;try{var d,g,l,p,f=function(){var e,t;return{conversationID:r.conversationID,conversationType:r.conversationType,userID:r.userID,groupID:r.groupID,showName:d,faceURL:v,recvMsgOpt:r.recvMsgOpt,unreadCount:c-u,groupAtType:r.groupAtType,latestMsg:h,latestMsgSendTime:null!=(e=null!=(t=null==a?void 0:a.sendTime)?t:n)?e:0,draftText:"",draftTextTime:0,burnDuration:r.burnDuration,msgDestructTime:r.msgDestructTime,isPinned:r.isPinned,isPrivateChat:r.isPrivateChat,isMsgDestruct:r.isMsgDestruct,attachedInfo:r.attachedInfo,ex:r.ex}},v="",h=a?JSON.stringify(xe(je(a))):"";(null==r?void 0:r.conversationType)===Q.Group?(d=null!=(g=null==i?void 0:i.groupName)?g:"",v=null!=(l=null==i?void 0:i.faceURL)?l:""):(d=(null==o?void 0:o.remark)||(null==s?void 0:s.nickname)||"",v=null!=(p=null==s?void 0:s.faceURL)?p:"");var m=function(){if((null==a?void 0:a.status)===w.MsgStatusHasDeleted)return Promise.resolve(t({conversationID:null==r?void 0:r.conversationID,seq:a.seq,operationID:ie()})).then(function(e){e&&(h=JSON.stringify(xe(e)))})}();return Promise.resolve(m&&m.then?m.then(f):f())}catch(e){return Promise.reject(e)}},_e=function(e){var t=e.friendUser;return l({},h(e,ke),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL,attachedInfo:""})},He=function(e){var t=e.blackUserInfo;return l({},h(e,qe),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL})},Je=/*#__PURE__*/function(){function e(e){var t=this;this.store=void 0,this.options=void 0,this.expiryListeners=[],this.cleanupTimer=void 0,this.options=e,this.store=new Map,this.options.cleanupInterval>0&&(this.cleanupTimer=setInterval(function(){t.deleteExpired()},this.options.cleanupInterval))}var t=e.prototype;return t.onExpiry=function(e){this.expiryListeners.push(e)},t.triggerExpiry=function(e,t){this.expiryListeners.forEach(function(n){return n(e,t)}),this.delete(e)},t.set=function(e,t){var n=this;this.delete(e);var r=Date.now(),i=null;this.options.ttl>0&&(i=setTimeout(function(){clearTimeout(i),n.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:i,created:r})},t.get=function(e){var t=this.store.get(e);if(t&&Date.now()-t.createdA.NotificationBegin&&e.contentType(null!=(d=null==h?void 0:h.hasReadCount)?d:0)||v.unreadNum&&v.unreadNum<(null!=(p=null==h?void 0:h.unreadCount)?p:0)){var m,I=l({},f.attachedInfoElem,{groupHasReadInfo:{hasReadCount:v.readNum,unreadCount:v.unreadNum}});s.tryUpdateCachedMessages(t,{clientMsgID:f.clientMsgID,attachedInfo:JSON.stringify(I)});var D=s.getCachedConversation(t),M=JSON.parse(null!=(m=null==D?void 0:D.latestMsg)?m:"{}");M.clientMsgID===f.clientMsgID&&M.seq&&s.instance.messageTrigger.getOneConversationAndTryChange(t,r,{latestMsg:JSON.stringify(l({},M,{attachedInfoElem:I}))}),a.push({clientMsgID:f.clientMsgID,hasReadCount:v.readNum,unreadCount:v.unreadNum,readMembers:[],readUsers:[]}),s.cachedGroupMessageClientMsgIDs.add(f.clientMsgID)}}}a.length>0&&s.instance.triggerEvent({event:T.OnRecvGroupReadReceipt,data:{conversationID:t,groupMessageReadInfo:a},operationID:r})}):Promise.resolve()}catch(e){return Promise.reject(e)}},this.chearGroupMessageClientMsgIDs=function(){return a.cachedGroupMessageClientMsgIDs.clear()},this.addGroupMessageReadUser=function(e,t){var n=a.cachedGroupMessageReadUser.get(e)||[],r=t.filter(function(e){return!n.some(function(t){return t.userID===e.userID})});a.cachedGroupMessageReadUser.set(e,[].concat(n,r))},this.getGroupMessageReadUser=function(e){var t;return null!=(t=a.cachedGroupMessageReadUser.get(e))?t:[]},this.instance=t};function ze(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Ye=function(t){var n=this,r=this,s=this,a=this,c=this;this.instance=void 0,this.defaultPullNums=10,this.SplitPullMsgNum=100,this.syncedConversationVersion=0,this.syncedConversationVersionID="",this.reset=function(){c.syncedConversationVersion=0,c.syncedConversationVersionID=""},this.syncConversationVersion=function(e){try{return Promise.resolve(n.instance.sendHttpRequest({operationID:e,reqFuncName:y.GetConversationVersion,data:{userID:n.instance.userID,version:n.syncedConversationVersion,versionID:n.syncedConversationVersionID}})).then(function(e){n.syncedConversationVersionID&&n.compareVersionAndTrigger(e),n.syncedConversationVersion=e.version,n.syncedConversationVersionID=e.versionID})}catch(e){return Promise.reject(e)}},this.compareVersionAndTrigger=function(e){var t=e.insert,n=e.update;(null!=t?t:[]).map(function(e){return Promise.resolve()}),(null!=n?n:[]).map(function(e){try{return Promise.resolve(c.instance.messageTrigger.getOneConversationAndTryChange(e.conversationID,"",l({},e))).then(function(){})}catch(e){return Promise.reject(e)}})},this.compareSeqsAndBatchSync=function(e,t){try{for(var n=new Map,i=0,o=Object.entries(e);id&&n.set(c,[d+1,u.maxSeq,u.maxSeqTime]):n.set(c,[0,u.maxSeq,u.maxSeqTime])}return r.syncAndTriggerMsgs(n,t),Promise.resolve()}catch(e){return Promise.reject(e)}},this.isNotification=function(e){return e.startsWith("n_")},this.syncAndTriggerMsgs=function(t,n){try{return e.debug("Current sync seqMap",t,t.size),Promise.resolve(function(){if(t.size>0){var r=function(r){return ze(function(){return Promise.resolve(s.pullMsgBySeqRange(i,n)).then(function(e){return Promise.resolve(s.instance.messageTrigger.triggerConversation(e.msgs,n)).then(function(){return Promise.resolve(s.instance.messageTrigger.triggerNotification(e.notificationMsgs,n)).then(function(){for(var e,n=g(t);!(e=n()).done;){var r=e.value,i=r[1];s.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:i[1],maxSeqTime:i[2]})}})})})},function(n){throw e.error("Sync message from server error",n,t),n})},i=new Map,o=0,a=function(e,t){if("function"==typeof e[et]){var n,r,i,o=function(e){try{for(;!(n=s.next()).done;)if((e=t(n.value))&&e.then){if(!Ze(e))return void e.then(o,i||(i=Xe.bind(null,r=new $e,2)));e=e.v}r?Xe(r,1,e):r=e}catch(e){Xe(r||(r=new $e),2,e)}},s=e[et]();if(o(),s.return){var a=function(e){try{n.done||s.return()}catch(e){}return e};if(r&&r.then)return r.then(a,function(e){throw a(e)});a()}return r}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],u=0;u=s.SplitPullMsgNum)return ze(function(){return Promise.resolve(s.pullMsgBySeqRange(i,n)).then(function(e){return Promise.resolve(s.instance.messageTrigger.triggerConversation(e.msgs,n)).then(function(){return Promise.resolve(s.instance.messageTrigger.triggerNotification(e.notificationMsgs,n)).then(function(){for(var e,t=g(i);!(e=t()).done;){var n=e.value,r=n[1];s.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:r[1],maxSeqTime:r[2]})}i=new Map,o=0})})})},function(t){throw e.error("Sync message from server error",t,i),t})}()}var u=a[0],d=a[1],l=a[2],p=d-u+1,f=function(){if(p/s.SplitPullMsgNum>1&&s.isNotification(r)){var t=new Map,i=Math.floor(p/s.SplitPullMsgNum),o=u,a=0,c=0;return function(e,t,n){for(var r;;){var i=e();if(Ze(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!Ze(o)){r=1;break}o=o.s}if(t){var s=t();if(s&&s.then&&!Ze(s)){r=2;break}}}var a=new $e,c=Xe.bind(null,a,2);return(0===r?i.then(d):1===r?o.then(u):s.then(g)).then(void 0,c),a;function u(r){o=r;do{if(t&&(s=t())&&s.then&&!Ze(s))return void s.then(g).then(void 0,c);if(!(i=e())||Ze(i)&&!i.v)return void Xe(a,1,o);if(i.then)return void i.then(d).then(void 0,c);Ze(o=n())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,c)}function d(e){e?(o=n())&&o.then?o.then(u).then(void 0,c):u(o):Xe(a,1,o)}function g(){(i=e())?i.then?i.then(d).then(void 0,c):d(i):Xe(a,1,o)}}(function(){return c<=i},function(){return c++},function(){return c===i?t.set(r,[o,d,l]):((a=o+s.SplitPullMsgNum)>d&&(a=d,c=i),t.set(r,[o,a,l])),ze(function(){return Promise.resolve(s.pullMsgBySeqRange(t,n)).then(function(e){return Promise.resolve(s.instance.messageTrigger.triggerConversation(e.msgs,n)).then(function(){return Promise.resolve(s.instance.messageTrigger.triggerNotification(e.notificationMsgs,n)).then(function(){for(var e,n=g(t);!(e=n()).done;){var r=e.value,i=r[1];s.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:i[1],maxSeqTime:i[2]})}o=a+1})})})},function(n){throw e.error("Sync message from server error",n,t),n})})}}();return f&&f.then?f.then(c):c()});return a&&a.then?a.then(r):r()}e.debug("Nothing to sync")}())}catch(e){return Promise.reject(e)}},this.pullMsgBySeqRange=function(t,n){try{var r=[].concat(t.entries()).map(function(e){var t=e[1];return{conversationID:e[0],begin:t[0],end:t[1],num:a.defaultPullNums}});e.debug("PullMsgBySeqRange with opid: ",n,"seqRanges: ",r);var s=i.PullMessageBySeqsReq.encode({userID:a.instance.userID,seqRanges:r,order:o.PullOrder.PullOrderAsc}).finish();return Promise.resolve(a.instance.sendReqWaitResp({operationID:n,data:s,reqIdentifier:b.PullMsgByRange}))}catch(e){return Promise.reject(e)}},this.instance=t};function Xe(e,t,n){if(!e.s){if(n instanceof $e){if(!n.s)return void(n.o=Xe.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Xe.bind(null,e,t),Xe.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var $e=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{Xe(r,1,o(this.v))}catch(e){Xe(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?Xe(r,1,t?t(i):i):n?Xe(r,1,n(i)):Xe(r,2,i)}catch(e){Xe(r,2,e)}},r},e}();function Ze(e){return e instanceof $e&&1&e.s}var et="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator",tt=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.uint8ArrayToWordArray=function(e){for(var t=[],n=0,r=e.length;n>24&255,t>>16&255,t>>8&255,255&t],c=0;c<4&&ir.version&&(r=o),n.cachedVersionKeys.set(at(t.conversationID,o.version),o)}return n.cachedVersionKeys.set(ct(t.conversationID),r),[s,r]},s=null,a=0,c=function(e,t,n){for(var r;;){var i=e();if(st(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!st(o)){r=1;break}o=o.s}if(t){var s=t();if(s&&s.then&&!st(s)){r=2;break}}}var a=new ot,c=it.bind(null,a,2);return(0===r?i.then(d):1===r?o.then(u):s.then(g)).then(void 0,c),a;function u(r){o=r;do{if(t&&(s=t())&&s.then&&!st(s))return void s.then(g).then(void 0,c);if(!(i=e())||st(i)&&!i.v)return void it(a,1,o);if(i.then)return void i.then(d).then(void 0,c);st(o=n())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,c)}function d(e){e?(o=n())&&o.then?o.then(u).then(void 0,c):u(o):it(a,1,o)}function g(){(i=e())?i.then?i.then(d).then(void 0,c):d(i):it(a,1,o)}}(function(){return!i&&a<10},function(){return a++},function(){var o=nt(function(){return Promise.resolve(n.ctx.sendHttpRequest({reqFuncName:y.GetEncryptionKey,data:l({},t),operationID:r})).then(function(e){s=e.versionKeyList,i=1})},function(n){return e.error("getEncryptionKeyFromServer error",n,"conversationID: ",t.conversationID),Promise.resolve(new Promise(function(e){return setTimeout(e,1e3)})).then(function(){})});if(o&&o.then)return o.then(function(){})});return Promise.resolve(c&&c.then?c.then(o):o())}catch(e){return Promise.reject(e)}},this.getMaxVersionKey=function(e,t){try{var n=r.cachedVersionKeys.get(ct(e));return n?Promise.resolve(n):Promise.resolve(r.getEncryptionKeyFromServer({conversationID:e,keyVersion:0},t)).then(function(e){return e[1]})}catch(e){return Promise.reject(e)}},this.getKeyByMessageVersion=function(t,n){try{var r=i.cachedVersionKeys.get(at(t.conversationID,t.keyVersion));return r?Promise.resolve(r):Promise.resolve(i.getEncryptionKeyFromServer(t,n)).then(function(n){var r=n[0];if(!r.length)throw e.error("version key not found, verion: ",t.keyVersion," conversationID: ",t.conversationID),new Error("getKeyByMessageVersion failed");return r[0]})}catch(e){return Promise.reject(e)}},this.encryption=function(e,t,n){try{return o.ctx.serverConfig.isEncryption?Promise.resolve(o.getMaxVersionKey(e,n)).then(function(e){t.content=o.aesEncryptor.encryption(t.content,e.key),t.keyVersion=e.version}):Promise.resolve()}catch(e){return Promise.reject(e)}},this.decryption=function(t,n,r){try{if(!n||0===n.keyVersion)return Promise.resolve();if((n.sessionType===Q.Single||n.sessionType===Q.Notification)&&n.recvID!==s.ctx.userID&&n.sendID!==s.ctx.userID)return e.warn("maybe message come from app manager",n),Promise.resolve();if(n.contentType===K.RevokeMessage||n.status===w.MsgStatusHasDeleted)return e.debug("message is revoke notification or has deleted",n),Promise.resolve();var i=nt(function(){return Promise.resolve(s.getMaxVersionKey(t,r)).then(function(e){n.content=s.aesEncryptor.decryption(n.content,e.key)})},function(t){e.warn("decryption with error: ",t,"msgData: ",n)});return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this.ctx=t};function it(e,t,n){if(!e.s){if(n instanceof ot){if(!n.s)return void(n.o=it.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(it.bind(null,e,t),it.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var ot=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{it(r,1,o(this.v))}catch(e){it(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?it(r,1,t?t(i):i):n?it(r,1,n(i)):it(r,2,i)}catch(e){it(r,2,e)}},r},e}();function st(e){return e instanceof ot&&1&e.s}function at(e,t){return e+"_v_"+t}function ct(e){return e+"_v_max"}var ut="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function dt(e,t,n){if(!e.s){if(n instanceof gt){if(!n.s)return void(n.o=dt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(dt.bind(null,e,t),dt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var gt=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{dt(r,1,o(this.v))}catch(e){dt(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?dt(r,1,t?t(i):i):n?dt(r,1,n(i)):dt(r,2,i)}catch(e){dt(r,2,e)}},r},e}();function lt(e){return e instanceof gt&&1&e.s}var pt=[w.MsgStatusHasDeleted,w.MsgStatusFiltered];function ft(e,t,n){if("function"==typeof e[ut]){var r,i,o,s=function(e){try{for(;!((r=a.next()).done||n&&n());)if((e=t(r.value))&&e.then){if(!lt(e))return void e.then(s,o||(o=dt.bind(null,i=new gt,2)));e=e.v}i?dt(i,1,e):i=e}catch(e){dt(i||(i=new gt),2,e)}},a=e[ut]();if(s(),a.return){var c=function(e){try{r.done||a.return()}catch(e){}return e};if(i&&i.then)return i.then(c,function(e){throw c(e)});c()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],d=0;d0&&f.instance.triggerEvent({event:T.OnRecvGroupReadReceipt,data:{conversationID:n,groupMessageReadInfo:o},operationID:t})}var o=[],s=ft(e[1],function(e){var r;function s(){var r;if(c&&d){var i=(null==(r=a.readUsers)?void 0:r.map(function(e){return e.userID}))||[],s=JSON.parse(c.attachedInfo||"{}");return s.groupHasReadInfo={hasReadCount:a.hasReadCount,unreadCount:a.unreadCount},f.cache.tryUpdateCachedMessages(n,{clientMsgID:c.clientMsgID,attachedInfo:JSON.stringify(s),isRead:!!i.includes(f.instance.userID)||c.isRead}),u&&f.getOneConversationAndTryChange(n,t,{latestMsg:JSON.stringify(l({},g,{attachedInfoElem:s}))}),Promise.resolve(f.instance.groupTrigger.cache.getGroupMembersMayNotInGroup({groupID:d.groupID,userIDList:i,operationID:t})).then(function(t){o.push({clientMsgID:e,hasReadCount:a.hasReadCount,unreadCount:a.unreadCount,readMembers:t,readUsers:[]})})}}var a=i[e];if(a){var c,u=!1,d=f.cache.getCachedConversation(n),g=JSON.parse(null!=(r=null==d?void 0:d.latestMsg)?r:"{}"),p=function(){if(g.clientMsgID===e&&g.seq)return u=!0,Promise.resolve(f.getMessageWithCacheBySeqs(n,[g.seq],t)).then(function(e){c=e.messages[0]});c=f.cache.getCachedMessageByClientMsgIDs(n,[e])[0]}();return p&&p.then?p.then(s):s()}});return s&&s.then?s.then(r):r()});return Promise.resolve(c&&c.then?c.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this.triggerNotification=function(t,n){try{for(var r=0,i=Object.entries(t);rA.FriendNotificationBegin&&t.contentTypeA.UserNotificationBegin&&t.contentTypeA.GroupNotificationBegin&&t.contentTypeA.SignalingNotificationBegin&&t.contentType0){if(!i)return void a.map(function(e){m.cache.tryUpdateCachedMessages(se(e),e)});m.instance.triggerEvent({event:T.OnRecvNewMessages,data:a.map(xe),operationID:n})}};if(0===Object.keys(t).length)return Promise.resolve();e.debug("Trigger conversation",t);var i=!0;m.triggeredConversationEvent.has(n)&&(m.triggeredConversationEvent.delete(n),i=!1);var o=!1,s=m.cache.getTotalUnreadCount(),a=[],c=ft(Object.entries(t),function(t){var r=t[0],c=t[1].Msgs.map(function(t){var c,u,d,g,l=!m.cache.getCachedMaxReadSeq(r),p=t.sendID===m.instance.userID,f=ce(t.options,U.IsUnreadCount)&&!p,v=ce(t.options,U.IsConversationUpdate),h=ce(t.options,U.IsNotPrivate);if(t.clientMsgID&&r){var I=je(t),D=xe(I);if(D.attachedInfoElem=t.attachedInfo?JSON.parse(t.attachedInfo):{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},t.status!==w.MsgStatusHasDeleted){t.contentType===R.Typing&&m.triggerTyping(D),D.status=w.MsgStatusSendSuccess,I.status=w.MsgStatusSendSuccess,l&&m.cache.addCachedMaxReadSeq(r,{hasReadSeq:p?t.seq:t.seq-1,maxSeq:t.seq,maxSeqTime:t.sendTime}),h||(D.attachedInfoElem.isPrivateChat=!0),v&&(s+=f?1:0,m.cache.updateCachedMaxReadSeq(r,{maxSeqTime:D.sendTime}),i&&m.getOneConversationAndTryChange(r,n,{latestMsg:JSON.stringify(D),latestMsgSendTime:D.sendTime},f,l),a.push(I),m.cache.addMessagesToCache(r,[I]));var M=null!=(c=null==(u=m.cache.getCachedMaxReadSeq(r))?void 0:u.maxSeq)?c:0,y=null!=(d=null==(g=m.cache.getCachedMaxReadSeq(r))?void 0:g.hasReadSeq)?d:0;e.debug("currentMaxSeq",M,"currentHasReadSeq",y),D.seq>M&&(o=l||!m.cache.isNotNotifyConversation(r),m.cache.updateCachedMaxReadSeq(r,{maxSeq:M+1,maxSeqTime:D.sendTime}),p&&(m.cache.updateCachedMaxReadSeq(r,{hasReadSeq:y+1}),m.cache.tryUpdateCachedMessages(r,{clientMsgID:D.clientMsgID,seq:D.seq})))}}});return Promise.resolve(Promise.all(c)).then(function(){})});return Promise.resolve(c&&c.then?c.then(r):r())}catch(e){return Promise.reject(e)}},this.instance=t,this.cache=new Qe(t),this.encryptor=new rt(t),this.syncer=new Ye(t),this.typingManager=new Ke(t)},ht=/*#__PURE__*/function(){function e(e){var t=this,n=this,r=this,i=this,o=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=function(e,t){try{return Promise.resolve(n.instance.sendHttpRequest({reqFuncName:y.GetFullGroupMemberUserIDs,data:{groupID:e,idHash:0},operationID:t})).then(function(t){n.cachedGroupMembersID.set(e,t.userIDs)})}catch(e){return Promise.reject(e)}},this.getGroupInfosWithCache=function(e,t){try{var n=[],i=[];return e.forEach(function(e){var t=r.cachedGroups.get(e);t?n.push(t):i.push(e)}),i.length?Promise.resolve(r.instance.sendHttpRequest({reqFuncName:M.GetSpecifiedGroupsInfo,data:{groupIDs:i},operationID:t})).then(function(e){var t=e.groupInfos;return t&&t.forEach(function(e){return r.cachedGroups.set(e.groupID,e)}),[].concat(n,null!=t?t:[])}):Promise.resolve(n)}catch(e){return Promise.reject(e)}},this.getGroupMembersWithCache=function(e){var t=e.groupID,n=e.userIDList,r=e.operationID;try{var o,s,a=null!=(o=i.cachedGroupMembers.get(t))?o:[],c=function(){if(null!=n&&n.length){var e=[],o=[];return n.forEach(function(t){var n=a.find(function(e){return e.userID===t});n?o.push(n):e.push(t)}),e.length?Promise.resolve(i.instance.sendHttpRequest({reqFuncName:M.GetSpecifiedGroupMembersInfo,data:{groupID:t,userIDs:e},operationID:r})).then(function(e){var n=e.members;n&&i.cachedGroupMembers.set(t,[].concat(a,n));var r=[].concat(o,null!=n?n:[]);return s=1,r}):(s=1,o)}}();return Promise.resolve(c&&c.then?c.then(function(e){return s?e:a}):s?c:a)}catch(e){return Promise.reject(e)}},this.getGroupMembersMayNotInGroup=function(e){try{return Promise.resolve(o.getGroupMembersWithCache(e)).then(function(t){var n=e.userIDList.filter(function(e){return!t.find(function(t){return t.userID===e})}),r=function(){if(n.length)return Promise.resolve(o.instance.getUsersInfo(n,operationID)).then(function(e){t.push.apply(t,e.data.map(function(e){return{userID:e.userID,nickname:e.nickname,faceURL:e.faceURL}}))})}();return r&&r.then?r.then(function(){return t}):t})}catch(e){return Promise.reject(e)}},this.updateCachedGroups=function(e){e.map(function(e){t.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=function(e){var n,r=e[0].groupID,i=null!=(n=t.cachedGroupMembers.get(r))?n:[];t.cachedGroupMembers.set(r,[].concat(i.filter(function(t){return!e.find(function(e){return e.userID===t.userID})}),e));var o=t.instance.messageTrigger.cache.getAllCachedConversations().find(function(t){return t.groupID===e[0].groupID}),s=JSON.parse((null==o?void 0:o.latestMsg)||"{}"),a=e.find(function(e){return e.userID===s.sendID&&e.nickname!==s.senderNickname});o&&a&&t.instance.messageTrigger.getOneConversationAndTryChange(o.conversationID,"",{latestMsg:JSON.stringify(l({},s,{senderNickname:a.nickname}))})},this.clearCachedGroupMembers=function(e){t.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=function(e){return t.cachedGroupMembersID.has(e)},this.getCachedGroupMembersID=function(e){var n;return null!=(n=t.cachedGroupMembersID.get(e))?n:[]},this.tryAddCachedGroupMembersID=function(e,n){if(t.cachedGroupMembersID.has(e)){var r,i=null!=(r=t.cachedGroupMembersID.get(e))?r:[];t.cachedGroupMembersID.set(e,[].concat(i,n))}},this.tryDeleteCachedGroupMembersID=function(e,n){if(t.cachedGroupMembersID.has(e)){var r,i=null!=(r=t.cachedGroupMembersID.get(e))?r:[];t.cachedGroupMembersID.set(e,i.filter(function(e){return!n.includes(e)}))}},this.instance=e}return e.prototype.clear=function(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()},e}(),mt=/*#__PURE__*/function(){function t(t){var n=this,r=this,i=this,o=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=function(e){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:y.GetGroupVersion,data:{userID:r.instance.userID,version:r.syncedGroupsVersion,versionID:r.syncedGroupsVersionID},operationID:e})).then(function(t){r.syncedGroupsVersionID&&r.compareGroupVersionAndTrigger(t,e),r.syncedGroupsVersion=t.version,r.syncedGroupsVersionID=t.versionID})}catch(e){return Promise.reject(e)}},this.syncGroupInfoAndMemberVersion=function(e){try{var t=function(){if(n.length)return Promise.resolve(i.instance.sendHttpRequest({reqFuncName:y.GetGroupMemberVersion,data:{userID:i.instance.userID,reqList:n},operationID:e})).then(function(t){var n=t.respList;Object.keys(i.syncedGroupMemberVersion).length>0&&i.compareGroupMemberVersionAndTrigger(n,e),i.syncedGroupMemberVersion=n;for(var r=0,o=Object.entries(n);r0},0,function(){var t=n.queue.shift()[0],r=function(e,n){try{var r=Promise.resolve(t()).then(function(){})}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(0,function(t){e.error("Error executing task:",t)});if(r&&r.then)return r.then(function(){})});return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},t}();function Lt(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var jt=((kt={})[K.TextMessage]="textElem",kt[K.AtTextMessage]="atTextElem",kt[K.LocationMessage]="locationElem",kt[K.CustomMessage]="customElem",kt[K.MergeMessage]="mergeElem",kt[K.QuoteMessage]="quoteElem",kt[K.CardMessage]="cardElem",kt[K.FaceMessage]="faceElem",kt[K.PictureMessage]="pictureElem",kt[K.VoiceMessage]="soundElem",kt[K.VideoMessage]="videoElem",kt[K.FileMessage]="fileElem",kt),xt=[K.PictureMessage,K.VoiceMessage,K.VideoMessage,K.FileMessage],Bt=/*#__PURE__*/function(e){function t(t,n){var r;return(r=e.call(this,n)||this).status=void 0,r.name="HttpError",r.status=t,r}return f(t,e),t}(/*#__PURE__*/I(Error));function Vt(e,t,n){if(!e.s){if(n instanceof _t){if(!n.s)return void(n.o=Vt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Vt.bind(null,e,t),Vt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var _t=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{Vt(r,1,o(this.v))}catch(e){Vt(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?Vt(r,1,t?t(i):i):n?Vt(r,1,n(i)):Vt(r,2,i)}catch(e){Vt(r,2,e)}},r},e}();function Ht(e){return e instanceof _t&&1&e.s}function Jt(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Wt=[y.GetActiveConversations,y.GetDesignatedConversation];function Kt(e,t,n){if(!e.s){if(n instanceof zt){if(!n.s)return void(n.o=Kt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Kt.bind(null,e,t),Kt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Qt=/*#__PURE__*/function(n){function o(){var o,s;return(o=n.call(this)||this).userID=void 0,o.platform=void 0,o.token=void 0,o.apiAddr=void 0,o.loginStatus=$.Logout,o.isReconnected=!1,o.serverConfig={isEncryption:!1},o.connectState="disconnected",o.wsManager=void 0,o.messageTrigger=void 0,o.userTrigger=void 0,o.groupTrigger=void 0,o.relationTrigger=void 0,o.businessTrigger=void 0,o.signalingTrigger=void 0,o.requestMap=new Map,o.generateHttpHeader=function(e,t){var n={"Content-Type":"application/json",token:o.token,operationID:t,reqFuncName:e};return Wt.includes(e)&&(n["Content-Type"]="application/x-protobuf"),n},o.sendHttpRequest=function(e){try{var t;return Promise.resolve(function(e,t){void 0===t&&(t={});var n=e.url,r=e.data,i=e.headers,o=e.platform,s=e.method,a=void 0===s?"POST":s,c=t.retries,u=void 0===c?3:c,d=t.baseDelayMs,g=void 0===d?300:d,p=t.maxDelayMs,f=void 0===p?3e3:p;return function(t){try{var s=0;return Promise.resolve(function(e,t,n){for(var r;;){var i=e();if(Ht(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!Ht(o)){r=1;break}o=o.s}}var s=new _t,a=Vt.bind(null,s,2);return(0===r?i.then(u):1===r?o.then(c):(void 0).then(function(){(i=e())?i.then?i.then(u).then(void 0,a):u(i):Vt(s,1,o)})).then(void 0,a),s;function c(t){o=t;do{if(!(i=e())||Ht(i)&&!i.v)return void Vt(s,1,o);if(i.then)return void i.then(u).then(void 0,a);Ht(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,a)}function u(e){e?(o=n())&&o.then?o.then(c).then(void 0,a):c(o):Vt(s,1,o)}}(function(){return!t},0,function(){return function(s,c){try{var u=Promise.resolve("web"===o?function(e){var t=e.url,n=e.data,r=e.headers,i=e.method,o=void 0===i?"POST":i;try{return Promise.resolve(fetch(t,{method:o,headers:l({},r),body:n instanceof Uint8Array?n:JSON.stringify(n)}).then(function(e){if(e.ok)return e.json();throw new Bt(e.status,e.statusText||"HTTP_"+e.status)}).then(function(e){if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))}catch(e){return Promise.reject(e)}}(e):new Promise(function(e,t){var s=function(e){return"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null}(o);s?s({url:n,data:r instanceof Uint8Array?Uint8Array.from(r).buffer:r,method:a,header:l({"Content-Type":"application/json"},i),success:function(n){200===n.statusCode&&0===n.data.errCode?e(n.data.data):t({statusCode:n.statusCode,data:n.data})},fail:function(e){t(e)}}):t(new Error("Request is not supported"))})).then(function(e){return t=1,e})}catch(e){return c(e)}return u&&u.then?u.then(void 0,c):u}(0,function(e){if(++s>u||!function(e){if(!e)return!1;if(e instanceof Bt)return e.status>=500;if("object"==typeof e&&"number"==typeof e.statusCode)return e.statusCode>=500;var t=String((null==e?void 0:e.message)||e||"").toLowerCase();return!!(t.includes("network")||t.includes("timeout")||t.includes("failed to fetch")||t.includes("request:fail"))}(e))throw e;var t,n=Math.min(g*Math.pow(2,s-1),f),r=Math.floor(150*Math.random());return Promise.resolve((t=n+r,new Promise(function(e){return setTimeout(e,t)}))).then(function(){})})}))}catch(e){return Promise.reject(e)}}()}({url:""+o.apiAddr+(e.replaceURL||k[e.reqFuncName]),data:e.data,headers:o.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(t=o.wsManager)?void 0:t.platformNamespace)||"web"}))}catch(e){return Promise.reject(e)}},o.handleWsConnected=function(t,n){try{var r=function(){if(0===t.errCode){o.connectState="connected",o.loginStatus=$.Logged,o.triggerEvent({event:T.OnConnectSuccess}),o.triggerEvent({event:T.OnSyncServerStart});var r=[o.messageTrigger.sync(n),o.relationTrigger.sync(n),o.groupTrigger.sync(n),o.userTrigger.sync(n)],i=Jt(function(){return Promise.resolve(Promise.all(r)).then(function(){o.triggerEvent({event:T.OnSyncServerFinish})})},function(t){e.error(t),o.triggerEvent({event:T.OnSyncServerFailed,errCode:t.errCode||G.SdkInternalError,errMsg:t.message||"Internal Error"})});if(i&&i.then)return i.then(function(){})}else{o.triggerEvent({event:T.OnConnectFailed,errCode:t.errCode,errMsg:t.errMsg,operationID:n});var s=re[t.errCode];s&&o.triggerEvent({event:s,errCode:t.errCode,errMsg:t.errMsg,operationID:n}),o.connectState="disconnected",o.loginStatus=$.Logout}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},o.handleMessage=function(e,t){try{var n=function(){if("string"!=typeof e){var n=function(){var t,n,r=(t=e,n=new DataView(t),Ne.getString(n,0,t.byteLength,"UTF-8")),i=JSON.parse(r);o.handleGeneralWsResp(i)},r=function(){if(!(e instanceof ArrayBuffer))return Promise.resolve(e.arrayBuffer()).then(function(t){e=t})}();return r&&r.then?r.then(n):n()}var i=JSON.parse(e);o.handleWsConnected(i,t)}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},o.handleGeneralWsResp=function(e){var t=de(e.data,e.reqIdentifier);if(e.reqIdentifier===b.PushMsg&&t)return o.messageTrigger.triggerConversation(t.msgs,e.operationID),void o.messageTrigger.triggerNotification(t.notificationMsgs,e.operationID);if(e.reqIdentifier!==b.WsSubUserOnlineStatus||e.msgIncr||o.userTrigger.onlineSub.userOnlineStateChange(t),e.reqIdentifier===b.WSServerConfigMsg&&t&&(o.serverConfig=t),e.reqIdentifier===b.KickOnlineMsg)return o.triggerEvent({event:T.OnKickedOffline,operationID:e.operationID}),void o.reset();var n=o.requestMap.get(e.msgIncr);n&&(0===e.errCode?n.resolve(t):n.reject(new pe(e.errCode,e.errMsg)),o.requestMap.delete(e.msgIncr))},o.handleReconnecting=function(){o.connectState="reconnecting",o.triggerEvent({event:T.OnConnecting})},o.handleReconnectFailed=function(){o.connectState="disconnected",o.triggerEvent({event:T.OnConnectFailed,errCode:G.NetworkError,errMsg:"network error"}),o.cancelMessageTasks()},o.handleReconnectSuccess=function(){o.isReconnected=!0,o.messageTrigger.cache.chearGroupMessageClientMsgIDs()},o.sendReqWaitResp=function(e){var t=e.data,n=e.reqIdentifier,i=e.operationID;if("connected"!==o.connectState)throw new pe(G.NetworkError,"network error, ws not connected");var s=ie();return new Promise(function(e,a){var c;o.requestMap.set(s,{resolve:e,reject:a}),null==(c=o.wsManager)||c.sendMessage({reqIdentifier:n,msgIncr:s,sendID:o.userID,operationID:i,data:r(t.buffer)})})},o.triggerEvent=function(t){var n=t.event,r=t.data,i=void 0===r?null:r,s=t.errCode,a=void 0===s?0:s,c=t.errMsg,u=void 0===c?"":c,d=t.operationID,g=void 0===d?"":d;o.loginStatus!==$.Logout&&(e.debug("%cSDK =>%c [OperationID:"+g+"] (event) trigger "+n+" with data "+JSON.stringify(i)+" errCode "+a+" errMsg "+u,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),o.emit(n,{event:n,data:i,errCode:a,errMsg:u,operationID:g}))},o.login=function(t,n){try{return Promise.resolve(fe($.Logged,M.Login,n,function(){try{var r,i=t.userID,s=t.token,a=t.wsAddr,c=t.apiAddr,u=t.platformID;if(o.wsManager)throw new pe(G.LoginRepeatError,"login repeat");return e.setLevel(null!=(r=t.logLevel)?r:J.Debug),o.userID=i,o.token=s,o.apiAddr=c,o.platform=u,o.wsManager=new Ee(a,{sendID:i,token:s,platformID:u,operationID:n,isBackground:!1,isMsgResp:!0,sdkType:"js"},o.handleMessage,o.handleReconnectFailed,o.handleReconnecting,o.handleReconnectFailed,o.handleReconnectSuccess),o.connectState="connecting",o.loginStatus=$.Logging,o.triggerEvent({event:T.OnConnecting,operationID:n}),Promise.resolve(Jt(function(){return Promise.resolve(o.wsManager.connect()).then(function(){})},function(e){throw o.triggerEvent({event:T.OnConnectFailed,errCode:G.NetworkError,errMsg:e.message||"network error",operationID:n}),o.connectState="disconnected",o.loginStatus=$.Logout,o.wsManager.close(),new pe(G.NetworkError,e.message||"network error")}))}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},o.getLoginStatus=function(e){return fe($.Logged,M.GetLoginStatus,e,function(){try{var e;return null==(e=o.wsManager)||e.sendPing(),Promise.resolve(o.loginStatus)}catch(e){return Promise.reject(e)}})},o.forceReconnect=function(e){return fe(o.loginStatus,M.ForceReconnect,e,function(){try{var e;return null==(e=o.wsManager)||e.forceReconnect(!0),Promise.resolve()}catch(e){return Promise.reject(e)}})},o.logout=function(e){return fe(o.loginStatus,M.Logout,e,function(){try{return o.reset(),Promise.resolve()}catch(e){return Promise.reject(e)}})},o.internalUploadFile=function(e,n,r){return Promise.resolve(Jt(function(){var i=o.userID+"/"+e.name,s=function(e){var t,n,r=null!=(t=null==(n=e.split(".").pop())?void 0:n.toLowerCase())?t:"";return C[r]||"application/octet-stream"}(e.name),a={operationID:n,token:o.token};return Promise.resolve(function(e,t,n){return fetch(e+"/object/part_size",{method:"POST",headers:l({},n),body:JSON.stringify({size:t})}).then(S)}(o.apiAddr,e.size,a)).then(function(n){var c=n.size;function u(){var n=p.join(","),u=new t;return u.append(n),Promise.resolve(function(e,t,n){return fetch(e+"/object/initiate_multipart_upload",{method:"POST",headers:l({},n),body:JSON.stringify(t)}).then(S)}(o.apiAddr,{hash:u.end(),size:e.size,partSize:c,maxParts:-1,cause:"",name:i,contentType:s},a)).then(function(t){var n=t.url,c=t.upload;if(u.destroy(),n)return null==r||r(100),{url:n};var d=c.sign.parts,f=c.sign.query,v=c.sign.header,h=e.size,m=0;null==r||r(0);for(var I=0,D=[],M=function(){try{var t=Xt(function(){return I=3)throw new Error("Failed to upload chunk "+(t+1)+" after 3 attempts: "+e.message);var n,r=400*Math.pow(2,D-1),i=Math.floor(150*Math.random());return Promise.resolve((n=r+i,new Promise(function(e){return setTimeout(e,n)}))).then(function(){})})}))}catch(e){return Promise.reject(e)}}(t)).then(function(){})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},y=Math.min(4,d.length),C=0;Cl?g:l,count:r-t.length,conversationID:i,operationID:o,fetchedMessages:d})}return d}):Promise.resolve(a)}catch(e){return Promise.reject(e)}};return{createTextMessage:function(e,n){return fe(t.loginStatus,M.CreateTextMessage,n,function(){try{var n=ge(t,N.UserMsgType,K.TextMessage);return n.textElem={content:e},Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createTextAtMessage:function(e,n){return fe(t.loginStatus,M.CreateTextAtMessage,n,function(){try{var n;if(!e.text)throw new pe(G.ArgsError,"text cannot be empty");if(e.atUserIDList.length>10)throw new pe(G.ArgsError,"atUserIDList length must be less than 10");var r,i=ge(t,N.UserMsgType,K.AtTextMessage);return(null==(n=e.message)?void 0:n.contentType)===K.QuoteMessage&&(e.message.contentType=K.TextMessage,e.message.textElem={content:null==(r=e.message.quoteElem)?void 0:r.text}),i.atTextElem={text:e.text,atUserList:e.atUserIDList,atUsersInfo:e.atUsersInfo,quoteMessage:e.message},Promise.resolve(i)}catch(e){return Promise.reject(e)}})},createLocationMessage:function(e,n){return fe(t.loginStatus,M.CreateLocationMessage,n,function(){try{var n=ge(t,N.UserMsgType,K.LocationMessage);return n.locationElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createCustomMessage:function(e,n){return fe(t.loginStatus,M.CreateCustomMessage,n,function(){try{var n=ge(t,N.UserMsgType,K.CustomMessage);return n.customElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createQuoteMessage:function(e,n){return fe(t.loginStatus,M.CreateQuoteMessage,n,function(){try{var n,r=ge(t,N.UserMsgType,K.QuoteMessage),i=JSON.parse(e.message);return i.contentType===K.QuoteMessage&&(i.contentType=K.TextMessage,i.textElem={content:null==(n=i.quoteElem)?void 0:n.text}),r.quoteElem={text:e.text,quoteMessage:i},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createCardMessage:function(e,n){return fe(t.loginStatus,M.CreateCardMessage,n,function(){try{var n=ge(t,N.UserMsgType,K.CardMessage);return n.cardElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createImageMessageByURL:function(e,n){return fe(t.loginStatus,M.CreateImageMessageByURL,n,function(){try{var n=ge(t,N.UserMsgType,K.PictureMessage);return n.pictureElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createImageMessageByFile:function(e,r){try{return Promise.resolve(fe(t.loginStatus,M.CreateImageMessageByFile,r,function(){try{var r=ge(t,N.UserMsgType,K.PictureMessage);return n.set(e.sourcePicture.uuid,e.file),delete e.file,r.pictureElem=l({},e),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createSoundMessageByURL:function(e,n){return fe(t.loginStatus,M.CreateSoundMessageByURL,n,function(){try{var n=ge(t,N.UserMsgType,K.VoiceMessage);return n.soundElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createSoundMessageByFile:function(e,r){try{return Promise.resolve(fe(t.loginStatus,M.CreateSoundMessageByFile,r,function(){try{var r=ge(t,N.UserMsgType,K.VoiceMessage);return n.set(e.uuid,e.file),delete e.file,r.soundElem=l({},e),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createVideoMessageByURL:function(e,n){return fe(t.loginStatus,M.CreateVideoMessageByURL,n,function(){try{var n=ge(t,N.UserMsgType,K.VideoMessage);return n.videoElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createVideoMessageByFile:function(e,r){try{return Promise.resolve(fe(t.loginStatus,M.CreateVideoMessageByFile,r,function(){try{var r=ge(t,N.UserMsgType,K.VideoMessage);return n.set(e.videoUUID,e.videoFile),n.set(e.snapshotUUID,e.snapshotFile),delete e.videoFile,delete e.snapshotFile,r.videoElem=l({},e),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createFileMessageByURL:function(e,n){return fe(t.loginStatus,M.CreateFileMessageByURL,n,function(){try{var n=ge(t,N.UserMsgType,K.FileMessage);return n.fileElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createFileMessageByFile:function(e,r){try{return Promise.resolve(fe(t.loginStatus,M.CreateFileMessageByFile,r,function(){try{var r=ge(t,N.UserMsgType,K.FileMessage);return n.set(e.uuid,e.file),delete e.file,r.fileElem=l({},e),Promise.resolve(r)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createMergerMessage:function(e,n){return fe(t.loginStatus,M.CreateMergerMessage,n,function(){try{var n=ge(t,N.UserMsgType,K.MergeMessage);return n.mergeElem={title:e.title,abstractList:e.summaryList,multiMessage:e.messageList,messageEntityList:[]},Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createFaceMessage:function(e,n){return fe(t.loginStatus,M.CreateFaceMessage,n,function(){try{var n=ge(t,N.UserMsgType,K.FaceMessage);return n.faceElem=l({},e),Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createForwardMessage:function(e,n){return fe(t.loginStatus,M.CreateForwardMessage,n,function(){try{if(e.status!==_.Succeed)throw new pe(G.ArgsError,"Only successfully sent messages can be forwarded");var n=ge(t,N.UserMsgType,e.contentType);return Promise.resolve(l({},e,n,{seq:0,status:_.Sending}))}catch(e){return Promise.reject(e)}})},sendMessage:function(e,s){try{return Promise.resolve(fe(t.loginStatus,M.SendMessage,s,function(){var a=function(){try{var r=l({},e,{message:l({},e.message)}),o=r.message,a=r.recvID,c=r.groupID,u=r.isOnlineOnly,d=r.offlinePushInfo,g=void 0===d?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:d;void 0===g.signalInfo&&(g.signalInfo="");var p=jt[o.contentType];if(!p)throw new pe(G.MsgContentTypeNotSupportError,"Unknown message content type");o.recvID=a,o.groupID=c,o.sessionType=c?Q.Group:Q.Single;var f={};u&&Object.values(U).forEach(function(e){return f[e]=!1});var v=se(o),h=!1;return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(v,s)).then(function(e){function r(){function r(r){function u(r){function u(r){function u(r){function u(n){var r,u,d=JSON.stringify(o[p]),l={sendID:t.userID,recvID:a||"",groupID:c||"",clientMsgID:o.clientMsgID,serverMsgID:o.serverMsgID||"",senderPlatformID:t.platform,senderNickname:o.senderNickname,senderFaceURL:o.senderFaceUrl,sessionType:o.sessionType,msgFrom:o.msgFrom,contentType:o.contentType,content:Ue(d),seq:o.seq,sendTime:0,createTime:o.createTime,status:o.status,isRead:!1,options:f,offlinePushInfo:g,atUserIDList:null!=(r=null==(u=o.atTextElem)?void 0:u.atUserList)?r:[],attachedInfo:o.attachedInfoElem?JSON.stringify(o.attachedInfoElem):"",ex:o.ex||"",dstUserIDs:[],keyVersion:0};return Promise.resolve(t.messageTrigger.encryptor.encryption(v,l,s)).then(function(){var n=i.MsgData.encode(l).finish();return Lt(function(){return Promise.resolve(t.sendReqWaitResp({data:n,operationID:s,reqIdentifier:b.SendMsg})).then(function(n){var r=n.serverMsgID,i=n.sendTime;return o.sendTime=i,o.serverMsgID=r,o.status=_.Succeed,t.messageTrigger.setTriggeredConversationEvent(s),t.messageTrigger.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:i}),t.messageTrigger.getOneConversationAndTryChange(v,s,{latestMsg:JSON.stringify(o),latestMsgSendTime:i}),o})},function(e){throw o.status=_.Failed,t.messageTrigger.getOneConversationAndTryChange(v,s,{latestMsg:JSON.stringify(o)}),e})})}var d=function(){if(o.contentType===K.FileMessage){var e,r=n.get(null==(e=o.fileElem)?void 0:e.uuid);if(!r)throw new pe(G.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(r,s,function(e){return t.triggerEvent({event:T.OnProgress,data:{progress:e,clientMsgID:o.clientMsgID},operationID:s})})).then(function(e){var t,r=e.url,i=void 0===r?"":r,s=e.error;if(n.delete(null==(t=o.fileElem)?void 0:t.uuid),s)throw new pe(G.NetworkError,"Upload file failed");o.fileElem.sourceUrl=i})}}();return d&&d.then?d.then(u):u()}var d=function(){if(o.contentType===K.VideoMessage){var e,r,i=n.get(null==(e=o.videoElem)?void 0:e.videoUUID),a=n.get(null==(r=o.videoElem)?void 0:r.snapshotUUID);if(!i||!a)throw new pe(G.ArgsError,"Can not find target file");var c=0,u=0,d=i.size,g=a.size,l=d+g,p=function(){t.triggerEvent({event:T.OnProgress,data:{progress:(c*d+u*g)/l,clientMsgID:o.clientMsgID},operationID:s})};return Promise.resolve(Promise.all([t.internalUploadFile(i,s,function(e){c=e,p()}),t.internalUploadFile(a,s,function(e){u=e,p()})])).then(function(e){var t,r;if(n.delete(null==(t=o.videoElem)?void 0:t.videoUUID),n.delete(null==(r=o.videoElem)?void 0:r.snapshotUUID),e[0].error||e[1].error)throw new pe(G.NetworkError,"Upload file failed");o.videoElem.videoUrl=e[0].url,o.videoElem.snapshotUrl=e[1].url})}}();return d&&d.then?d.then(u):u()}var d=function(){if(o.contentType===K.VoiceMessage){var e,r=n.get(null==(e=o.soundElem)?void 0:e.uuid);if(!r)throw new pe(G.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(r,s,function(e){return t.triggerEvent({event:T.OnProgress,data:{progress:e,clientMsgID:o.clientMsgID},operationID:s})})).then(function(e){var t,r=e.url,i=void 0===r?"":r,s=e.error;if(n.delete(null==(t=o.soundElem)?void 0:t.uuid),s)throw new pe(G.NetworkError,"Upload file failed");o.soundElem.sourceUrl=i})}}();return d&&d.then?d.then(u):u()}e.latestMsgSendTime=o.createTime,t.messageTrigger.getOneConversationAndTryChange(v,s,{latestMsg:JSON.stringify(o)},void 0,h);var d=function(){if(o.contentType===K.PictureMessage){var e,r=n.get(null==(e=o.pictureElem)?void 0:e.sourcePicture.uuid);if(!r)throw new pe(G.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(r,s,function(e){return t.triggerEvent({event:T.OnProgress,data:{progress:e,clientMsgID:o.clientMsgID},operationID:s})})).then(function(e){var t,r=e.url,i=void 0===r?"":r,s=e.error;if(n.delete(null==(t=o.pictureElem)?void 0:t.sourcePicture.uuid),s)throw new pe(G.NetworkError,"Upload file failed");o.pictureElem.sourcePicture.url=i,o.pictureElem.bigPicture.url=i,o.pictureElem.snapshotPicture.width=640,o.pictureElem.snapshotPicture.height=640,o.pictureElem.snapshotPicture.url=i+"?type=image&width=640&height=640"})}}();return d&&d.then?d.then(u):u()}var u=function(){if(c)return Promise.resolve(t.groupTrigger.cache.getGroupInfosWithCache([c],s)).then(function(e){return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:c,userIDList:[t.userID],operationID:s})).then(function(t){if(null==t||!t.length)throw new pe(G.ArgsError,"user not join target group");t[0].nickname&&(o.senderNickname=t[0].nickname),o.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},o.attachedInfoElem.groupHasReadInfo.unreadCount=e[0].memberCount-1})})}();return u&&u.then?u.then(r):r()}var u=function(){if(!e)return h=!0,Promise.resolve(t.messageTrigger.initConversation({sourceID:c||a,sessionType:o.sessionType,operationID:s})).then(function(t){e=t});e.isPrivateChat&&(f[U.IsNotPrivate]=!1,o.attachedInfoElem=l({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:e.burnDuration}))}();return u&&u.then?u.then(r):r()})}catch(e){return Promise.reject(e)}};return xt.includes(e.message.contentType)?o.enqueue(a):r.enqueue(a)}))}catch(e){return Promise.reject(e)}},sendMessageNotOss:function(e,n){try{return Promise.resolve(fe(t.loginStatus,M.SendMessage,n,function(){return r.enqueue(function(){try{var r=l({},e,{message:l({},e.message)}),o=r.message,s=r.recvID,a=r.groupID,c=r.isOnlineOnly,u=r.offlinePushInfo,d=void 0===u?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:u;void 0===d.signalInfo&&(d.signalInfo="");var g=jt[o.contentType];if(!g)throw new pe(G.MsgContentTypeNotSupportError,"Unknown message content type");o.recvID=s,o.groupID=a,o.sessionType=a?Q.Group:Q.Single;var p={};c&&Object.values(U).forEach(function(e){return p[e]=!1});var f=se(o);return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(f,n)).then(function(e){function r(r){var c,u;e.latestMsgSendTime=o.createTime,t.messageTrigger.getOneConversationAndTryChange(f,n,{latestMsg:JSON.stringify(o)});var l=JSON.stringify(o[g]),v={sendID:t.userID,recvID:s||"",groupID:a||"",clientMsgID:o.clientMsgID,serverMsgID:o.serverMsgID||"",senderPlatformID:t.platform,senderNickname:o.senderNickname,senderFaceURL:o.senderFaceUrl,sessionType:o.sessionType,msgFrom:o.msgFrom,contentType:o.contentType,content:Ue(l),seq:o.seq,sendTime:0,createTime:o.createTime,status:o.status,isRead:!1,options:p,offlinePushInfo:d,atUserIDList:null!=(c=null==(u=o.atTextElem)?void 0:u.atUserList)?c:[],attachedInfo:o.attachedInfoElem?JSON.stringify(o.attachedInfoElem):"",ex:o.ex||"",dstUserIDs:[],keyVersion:0};return Promise.resolve(t.messageTrigger.encryptor.encryption(f,v,n)).then(function(){var r=i.MsgData.encode(v).finish();return Lt(function(){return Promise.resolve(t.sendReqWaitResp({data:r,operationID:n,reqIdentifier:b.SendMsg})).then(function(r){var i=r.serverMsgID,s=r.sendTime;return o.sendTime=s,o.serverMsgID=i,o.status=_.Succeed,t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:s}),t.messageTrigger.getOneConversationAndTryChange(f,n,{latestMsg:JSON.stringify(o),latestMsgSendTime:s}),o})},function(e){throw o.status=_.Failed,t.messageTrigger.getOneConversationAndTryChange(f,n,{latestMsg:JSON.stringify(o)}),e})})}var c=function(){if(!e)return Promise.resolve(t.messageTrigger.initConversation({sourceID:a||s,sessionType:o.sessionType,operationID:n})).then(function(r){return e=r,function(){if(a)return Promise.resolve(t.groupTrigger.cache.getGroupInfosWithCache([a],n)).then(function(e){return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:a,userIDList:[t.userID],operationID:n})).then(function(t){if(null==t||!t.length)throw new pe(G.ArgsError,"user not join target group");t[0].nickname&&(o.senderNickname=t[0].nickname),o.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},o.attachedInfoElem.groupHasReadInfo.unreadCount=e[0].memberCount-1})})}()});e.isPrivateChat&&(p[U.IsNotPrivate]=!1,o.attachedInfoElem=l({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:e.burnDuration}))}();return c&&c.then?c.then(r):r()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},revokeMessage:function(e,n){try{return Promise.resolve(fe(t.loginStatus,M.RevokeMessage,n,function(){try{var r=function(r){return Promise.resolve(t.sendHttpRequest({reqFuncName:M.RevokeMessage,data:{conversationID:e.conversationID,seq:i.seq,userID:t.userID},operationID:n})).then(function(){t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.revokeMessage({revokerUserID:t.userID,clientMsgID:i.clientMsgID,revokeTime:Date.now(),sesstionType:i.sessionType,seq:i.seq,conversationID:e.conversationID,isAdminRevoke:!1},n)})},i=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(e.conversationID,[e.clientMsgID])[0];if(!i)throw new pe(G.ArgsError,"message not exist");var o=function(){if(i.sendID!==t.userID){if(!i.groupID)throw new pe(G.ArgsError,"message can not be revoked");return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:i.groupID,userIDList:[t.userID],operationID:n})).then(function(e){var t=e[0];if(!t||t.roleLevel===B.Nomal)throw new pe(G.ArgsError,"message can not be revoked")})}}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},getAdvancedHistoryMessageList:function(n,r){try{return Promise.resolve(fe(t.loginStatus,M.GetAdvancedHistoryMessageList,r,function(){try{var i={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(a!==n.conversationID&&(s=null,a=n.conversationID),n.startClientMsgID){if(null===s){var o=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!o)return Promise.resolve(l({},i,{isEnd:!0}));s=o.seq}}else s=0;var u=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);return e.log("syncedSeqs",u),u?Promise.resolve(c({maxSeq:s?s-1:u.maxSeq,count:n.count,conversationID:n.conversationID,operationID:r})).then(function(o){function a(){function a(){var a,c;return i.messageList=o.map(xe),t.messageTrigger.cache.getGroupMessageHasReadInfo({conversationID:n.conversationID,messages:[].concat(i.messageList),operationID:r}),e.debug("getAdvancedHistoryMessageList with opid: ",r,"messageList: ",i.messageList),s=null!=(a=null==(c=o[0])?void 0:c.seq)?a:0,l({},i,{isEnd:o.lengthA.NotificationBegin&&u.contentTypeo.length&&a.groupHasReadInfo.hasReadCount>o.length)return Promise.resolve(t.sendHttpRequest({reqFuncName:y.GetGroupMessageHasRead,data:{clientMsgID:e.clientMsgID,conversationID:e.conversationID,type:ee.Read,pagination:{pageNumber:e.offset+1,showNumber:e.count}},operationID:n})).then(function(s){var a=s.reads;if(o.length<50&&e.offset<50){var c=50-o.length;t.messageTrigger.cache.addGroupMessageReadUser(e.clientMsgID,a.slice(0,c%c [OperationID:"+n[n.length-1]+"] (invoked) run "+t+" with args "+JSON.stringify(n),"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")}(n,r),Promise.resolve(i.apply(t,r)).then(function(t){var r,i;return r=n,(i=t).errCode?e.debug("%cSDK =>%c [OperationID:"+i.operationID+"] (response) run "+r+" with error "+JSON.stringify(i),"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):e.debug("%cSDK =>%c [OperationID:"+i.operationID+"] (response) run "+r+" with response before processor "+JSON.stringify(i.data),"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),t.errCode?Promise.reject(t):t})}catch(e){return Promise.reject(e)}}:Reflect.get(t,n,r)}})};export{L as AllowType,W as ApplicationHandleResult,T as CbEvents,G as ErrorCode,z as GroupAtType,x as GroupJoinSource,Y as GroupMemberFilter,B as GroupMemberRole,ee as GroupMessageReaderFilter,O as GroupStatus,j as GroupType,V as GroupVerificationType,R as InternalContentType,w as InternalMessageStatus,J as LogLevel,$ as LoginStatus,U as MessageOptionsKey,q as MessageReceiveOptType,_ as MessageStatus,K as MessageType,N as MsgFrom,A as NotificationType,Z as OnlineState,H as Platform,X as Relationship,b as ReqIdentifier,M as RequestApi,Q as SessionType,te as ViewType,E as WorkMomentSdkNotificationType,F as WsErrorCode,re as WsErrorEventMap,$t as getSDK}; diff --git a/node_modules/@openim/client-sdk/lib/index.js b/node_modules/@openim/client-sdk/lib/index.js index eb4038f..1e058ee 100644 --- a/node_modules/@openim/client-sdk/lib/index.js +++ b/node_modules/@openim/client-sdk/lib/index.js @@ -1 +1 @@ -var e=require("loglevel"),t=require("spark-md5"),r=require("base64-arraybuffer"),n=require("@openim/protocol");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/o(e),s=/*#__PURE__*/o(t);function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;tt.latestMsgSendTime?-1:e.latestMsgSendTime {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n "],{type:"application/javascript"});c.workerUrl=URL.createObjectURL(e),c.heartbeatWorker=new Worker(c.workerUrl),c.heartbeatWorker.onmessage=function(e){"ping"===e.data.type&&c.sendPing()},c.heartbeatWorker.postMessage({type:"start",interval:c.heartbeatInterval})}else c.legacyTimer=setInterval(function(){c.sendPing()},c.heartbeatInterval)},this.connect=function(){return"unknow"===c.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise(function(e,t){if(c.ws&&c.ws.readyState!==ee.CLOSED)c.ws.readyState===c.ws.OPEN?e():t(new Error("WebSocket is in an unknown state"));else{var r=function(){c.reconnectAttempts&&c.onReconnectSuccess(),c.reconnectAttempts=0,c.startHeartbeat(),e()},n=function(e){return t(e)};if("web"===c.platformNamespace)c.ws=new WebSocket(c.urlFormat()),c.ws.onopen=r,c.ws.onerror=n;else{var o={url:c.urlFormat(),complete:function(){}};"my"===c.platformNamespace&&(o.multiple=!0),"uni"===c.platformNamespace&&(c.ws=uni.connectSocket(o)),"wx"===c.platformNamespace&&(c.ws=wx.connectSocket(o)),"my"===c.platformNamespace&&(c.ws=my.connectSocket(o)),c.ws.onOpen(r),c.ws.onError(n)}c.setupEventListeners()}})},this.setupEventListeners=function(){if(c.ws){var e=function(e){return c.onBinaryMessage(e.data)},t=function(e){if(c.shouldReconnect&&c.reconnectAttempts0&&(this.cleanupTimer=setInterval(function(){t.deleteExpired()},this.options.cleanupInterval))}var t=e.prototype;return t.onExpiry=function(e){this.expiryListeners.push(e)},t.triggerExpiry=function(e,t){this.expiryListeners.forEach(function(r){return r(e,t)}),this.delete(e)},t.set=function(e,t){var r=this;this.delete(e);var n=Date.now(),o=null;this.options.ttl>0&&(o=setTimeout(function(){clearTimeout(o),r.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:o,created:n})},t.get=function(e){var t=this.store.get(e);if(t&&Date.now()-t.createdp&&n.set(u,[p+1,c.maxSeq,c.maxSeqTime]):n.set(u,[0,c.maxSeq,c.maxSeqTime])}return r.syncAndTriggerMsgs(n,t),Promise.resolve()}catch(e){return Promise.reject(e)}},this.isNotification=function(e){return e.startsWith("n_")},this.syncAndTriggerMsgs=function(e,t){try{return i.default.debug("Current sync seqMap",e,e.size),Promise.resolve(function(){if(e.size>0){var r=function(r){return Pe(function(){return Promise.resolve(o.pullMsgBySeqRange(n,t)).then(function(r){return Promise.resolve(o.instance.messageTrigger.triggerConversation(r.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(r.notificationMsgs,t)).then(function(){for(var t,r=u(e);!(t=r()).done;){var n=t.value,i=n[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:i[1],maxSeqTime:i[2]})}})})})},function(t){throw i.default.error("Sync message from server error",t,e),t})},n=new Map,s=0,a=function(e,t){if("function"==typeof e[Oe]){var r,n,o,i=function(e){try{for(;!(r=s.next()).done;)if((e=t(r.value))&&e.then){if(!Ue(e))return void e.then(i,o||(o=qe.bind(null,n=new Ee,2)));e=e.v}n?qe(n,1,e):n=e}catch(e){qe(n||(n=new Ee),2,e)}},s=e[Oe]();if(i(),s.return){var a=function(e){try{r.done||s.return()}catch(e){}return e};if(n&&n.then)return n.then(a,function(e){throw a(e)});a()}return n}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],c=0;c=o.SplitPullMsgNum)return Pe(function(){return Promise.resolve(o.pullMsgBySeqRange(n,t)).then(function(e){return Promise.resolve(o.instance.messageTrigger.triggerConversation(e.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(e.notificationMsgs,t)).then(function(){for(var e,t=u(n);!(e=t()).done;){var r=e.value,i=r[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:i[1],maxSeqTime:i[2]})}n=new Map,s=0})})})},function(e){throw i.default.error("Sync message from server error",e,n),e})}()}var p=a[0],d=a[1],g=a[2],l=d-p+1,f=function(){if(l/o.SplitPullMsgNum>1&&o.isNotification(r)){var e=new Map,n=Math.floor(l/o.SplitPullMsgNum),s=p,a=0,c=0;return function(e,t,r){for(var n;;){var o=e();if(Ue(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Ue(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Ue(s)){n=2;break}}}var a=new Ee,u=qe.bind(null,a,2);return(0===n?o.then(p):1===n?i.then(c):s.then(d)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!Ue(s))return void s.then(d).then(void 0,u);if(!(o=e())||Ue(o)&&!o.v)return void qe(a,1,i);if(o.then)return void o.then(p).then(void 0,u);Ue(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function p(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):qe(a,1,i)}function d(){(o=e())?o.then?o.then(p).then(void 0,u):p(o):qe(a,1,i)}}(function(){return c<=n},function(){return c++},function(){return c===n?e.set(r,[s,d,g]):((a=s+o.SplitPullMsgNum)>d&&(a=d,c=n),e.set(r,[s,a,g])),Pe(function(){return Promise.resolve(o.pullMsgBySeqRange(e,t)).then(function(r){return Promise.resolve(o.instance.messageTrigger.triggerConversation(r.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(r.notificationMsgs,t)).then(function(){for(var t,r=u(e);!(t=r()).done;){var n=t.value,i=n[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:i[1],maxSeqTime:i[2]})}s=a+1})})})},function(t){throw i.default.error("Sync message from server error",t,e),t})})}}();return f&&f.then?f.then(c):c()});return a&&a.then?a.then(r):r()}i.default.debug("Nothing to sync")}())}catch(e){return Promise.reject(e)}},this.pullMsgBySeqRange=function(e,t){try{var r=[].concat(e.entries()).map(function(e){var t=e[1];return{conversationID:e[0],begin:t[0],end:t[1],num:s.defaultPullNums}});i.default.debug("PullMsgBySeqRange with opid: ",t,"seqRanges: ",r);var o=n.PbCoder.PullMessageBySeqsReq.encode({userID:s.instance.userID,seqRanges:r,order:n.SdkWsProto.PullOrder.PullOrderAsc}).finish();return Promise.resolve(s.instance.sendReqWaitResp({operationID:t,data:o,reqIdentifier:exports.ReqIdentifier.PullMsgByRange}))}catch(e){return Promise.reject(e)}},this.instance=e};function qe(e,t,r){if(!e.s){if(r instanceof Ee){if(!r.s)return void(r.o=qe.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(qe.bind(null,e,t),qe.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var Ee=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{qe(n,1,i(this.v))}catch(e){qe(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?qe(n,1,t?t(o):o):r?qe(n,1,r(o)):qe(n,2,o)}catch(e){qe(n,2,e)}},n},e}();function Ue(e){return e instanceof Ee&&1&e.s}var Oe="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Fe(e,t,r){if(!e.s){if(r instanceof ke){if(!r.s)return void(r.o=Fe.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Fe.bind(null,e,t),Fe.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var we=[exports.InternalMessageStatus.MsgStatusHasDeleted,exports.InternalMessageStatus.MsgStatusFiltered],ke=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Fe(n,1,i(this.v))}catch(e){Fe(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Fe(n,1,t?t(o):o):r?Fe(n,1,r(o)):Fe(n,2,o)}catch(e){Fe(n,2,e)}},n},e}(),Le=function(e){var t=this,r=this,o=this,s=this,a=this,u=this,p=this,d=this,g=this,l=this,f=this,v=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredConversationEvent=new Map,this.typingManager=void 0,this.sync=function(e){try{return Promise.resolve(r.cache.getMaxReadSeqs(e)).then(function(){var t=[r.syncer.syncConversationVersion(e),r.cache.getActiveConversationsFromServer(e),r.cache.getNotNotifyConversationIDs(e)];return Promise.resolve(Promise.all(t)).then(function(){})})}catch(e){return Promise.reject(e)}},this.reset=function(){t.cache.clear(),t.syncer.reset(),t.typingManager.reset(),t.triggeredConversationEvent.clear()},this.setTriggeredConversationEvent=function(e){t.triggeredConversationEvent.set(e,!0)},this.getMessageWithCacheBySeqs=function(e,t,r){try{var n=function(){return c.sort(function(e,t){return e.seq-t.seq}),{messages:c,filterCount:p}},s=o.cache.getCachedMessagesBySeqs(e,t),a=s.cachedMessages,u=s.unCachedSeqs,c=[].concat(a),p=0;i.default.debug("after getCachedMessagesBySeqs with opid: ",r,"seqs: ",t,"cachedMessages: ",a,"unCachedSeqs: ",u);var d=function(){if(u.length)return Promise.resolve(o.getMessageFromServerBySeqs([{conversationID:e,seqs:u}],r)).then(function(t){var r=[],n=[];t.msgs[e].Msgs.forEach(function(e){we.includes(e.status)?(r.push(e.seq),p++):n.push(ye(e))}),t.msgs[e].Msgs.length||r.push.apply(r,u),o.cache.addMessagesToCache(e,n),o.cache.addFilterSeqsToCache(e,r),c.push.apply(c,n)})}();return Promise.resolve(d&&d.then?d.then(n):n())}catch(e){return Promise.reject(e)}},this.getPreviousSeqMessage=function(e){var t=e.conversationID,r=e.seq,n=e.operationID;try{if(r<1)return Promise.resolve(null);for(var o=[],i=r;o.length<10&&!(i<1);i--)s.cache.checkIsFilterSeq(t,i)||o.push(i);return Promise.resolve(s.getMessageWithCacheBySeqs(t,o,n)).then(function(e){var r,i=e.messages;function a(e){return r?e:i[i.length-1]}var u=function(){if(!i.length)return Promise.resolve(s.getPreviousSeqMessage({seq:o[o.length-1],operationID:n,conversationID:t})).then(function(e){return r=1,e})}();return u&&u.then?u.then(a):a(u)})}catch(e){return Promise.reject(e)}},this.initConversation=function(e){try{var t=function(e){return a.cache.setCachedConversations([r]),r},r={conversationID:oe(c({},e,{userID:a.instance.userID})),userID:"",groupID:"",recvMsgOpt:exports.MessageReceiveOptType.Nomal,unreadCount:0,groupAtType:exports.GroupAtType.AtNormal,latestMsg:"",latestMsgSendTime:0,draftText:"",draftTextTime:0,burnDuration:0,msgDestructTime:0,isPinned:!1,isPrivateChat:!1,isMsgDestruct:!1,attachedInfo:"",ex:""},n=e.sessionType===exports.SessionType.Group?Promise.resolve(a.instance.groupTrigger.cache.getGroupInfosWithCache([e.sourceID],e.operationID)).then(function(t){if(!t[0])throw new Error("target group not exist");r.showName=t[0].groupName,r.faceURL=t[0].faceURL,r.conversationType=exports.SessionType.Group,r.groupID=e.sourceID}):(r.userID=e.sourceID,r.conversationType=exports.SessionType.Single,Promise.resolve(a.instance.getSpecifiedFriendsInfo([e.sourceID],e.operationID)).then(function(t){var n=t.data,o=function(){if(!n.length)return Promise.resolve(a.instance.getUsersInfo([e.sourceID],e.operationID)).then(function(e){var t=e.data;r.showName=t[0].nickname,r.faceURL=t[0].faceURL});r.showName=n[0].remark||n[0].nickname,r.faceURL=n[0].faceURL}();if(o&&o.then)return o.then(function(){})}));return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},this.getConversationsWithCacheByIDs=function(e,t){try{var r=function(){return[].concat(o,i)},o=[],i=[],s=[];e.forEach(function(e){var t=u.cache.getCachedConversation(e);t?o.push(t):s.push(e)});var a=function(){if(s.length)return Promise.resolve(u.instance.sendHttpRequest({reqFuncName:I.GetDesignatedConversation,data:n.PbCoder.GetConversationsReq.encode({ownerUserID:u.instance.userID,conversationIDs:s}).finish(),operationID:t})).then(function(e){var t=ae(e,I.GetDesignatedConversation),r=i.push;return Promise.resolve(Promise.all(t.conversations.map(function(e){var t,r;return Se(e,u.getPreviousSeqMessage,null==(t=u.cache.getCachedMaxReadSeq(null==(r=e.conversation)?void 0:r.conversationID))?void 0:t.maxSeqTime)}))).then(function(e){r.call.apply(r,[i].concat(e)),u.cache.setCachedConversations(i)})})}();return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}},this.getOneConversationAndTryChange=function(e,t,r,o,i){try{var s,a=function(e){return s?e:(u&&r&&p.instance.triggerEvent({event:i?exports.CbEvents.OnNewConversation:exports.CbEvents.OnConversationChanged,data:[c({},u)],operationID:t}),u)},u=void 0;u=p.cache.getCachedConversation(e);var d=function(){if(!u)return function(){if(p.cache.getCachedMaxReadSeq(e))return Promise.resolve(p.instance.sendHttpRequest({reqFuncName:I.GetDesignatedConversation,data:n.PbCoder.GetConversationsReq.encode({ownerUserID:p.instance.userID,conversationIDs:[e]}).finish(),operationID:t})).then(function(t){var r,n=ae(t,I.GetDesignatedConversation).conversations;if(n)return Promise.resolve(Se(n[0],p.getPreviousSeqMessage,null==(r=p.cache.getCachedMaxReadSeq(e))?void 0:r.maxSeqTime)).then(function(e){p.cache.setCachedConversations([u=e])});s=1})}();void 0!==(null==r?void 0:r.recvMsgOpt)&&(r.recvMsgOpt===exports.MessageReceiveOptType.Nomal?p.cache.deleteNotNotifyConversationID(e):p.cache.addNotNotifyConversationID(e)),r&&Object.assign(u,r),o&&(u.unreadCount+=1)}();return Promise.resolve(d&&d.then?d.then(a):a(d))}catch(e){return Promise.reject(e)}},this.getMessageFromServerBySeqs=function(e,t){try{var r=n.PbCoder.GetSeqMessageReq.encode({userID:d.instance.userID,conversations:e}).finish();return Promise.resolve(d.instance.sendReqWaitResp({operationID:t,data:r,reqIdentifier:exports.ReqIdentifier.PullMsgBySeqList}))}catch(e){return Promise.reject(e)}},this.revokeMessage=function(e,t){try{return Promise.resolve(g.getMessageWithCacheBySeqs(e.conversationID,[e.seq],t)).then(function(r){function n(){function r(){var r,o;g.instance.triggerEvent({event:exports.CbEvents.OnNewRecvMessageRevoked,data:n,operationID:t});var i=null!=(r=null==(o=g.cache.getCachedMaxReadSeq(e.conversationID))?void 0:o.maxSeq)?r:0,s=function(){if(i<=e.seq)return g.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:e.revokeTime}),Promise.resolve(g.getOneConversationAndTryChange(e.conversationID,t,{latestMsg:JSON.stringify(De(a)),latestMsgSendTime:e.revokeTime})).then(function(){})}();if(s&&s.then)return s.then(function(){})}var n={revokerID:e.revokerUserID,revokerRole:i,clientMsgID:o.clientMsgID,revokerNickname:s,revokeTime:e.revokeTime,sourceMessageSendTime:o.sendTime,sourceMessageSendID:o.sendID,sourceMessageSenderNickname:o.senderNickname,sessionType:e.sesstionType,seq:e.seq,ex:"",isAdminRevoke:e.isAdminRevoke},a=g.cache.tryUpdateCachedMessages(e.conversationID,{clientMsgID:e.clientMsgID,seq:e.seq,content:JSON.stringify({detail:JSON.stringify(n)}),contentType:exports.NotificationType.RevokeNotification});g.cache.tryUpdateQuotedMessage(e.conversationID,e.clientMsgID);var u=function(){if(!a)return Promise.resolve(g.getMessageFromServerBySeqs([{conversationID:e.conversationID,seqs:[e.seq]}],t)).then(function(t){a=ye(t.msgs[e.conversationID].Msgs[0])})}();return u&&u.then?u.then(r):r()}var o=r.messages[0],i=0,s="",a=function(){if(e.isAdminRevoke||e.sesstionType===exports.SessionType.Single)return Promise.resolve(g.instance.getUsersInfo([e.revokerUserID],t)).then(function(e){var t;s=null==(t=e.data[0])?void 0:t.nickname});var r=function(){if(e.sesstionType===exports.SessionType.Group)return Promise.resolve(g.getOneConversationAndTryChange(e.conversationID,t)).then(function(r){return Promise.resolve(g.instance.groupTrigger.cache.getGroupMembersWithCache({groupID:r.groupID,userIDList:[e.revokerUserID],operationID:t})).then(function(e){var t,r;s=null==(t=e[0])?void 0:t.nickname,i=null==(r=e[0])?void 0:r.roleLevel})})}();return r&&r.then?r.then(function(){}):void 0}();return a&&a.then?a.then(n):n()})}catch(e){return Promise.reject(e)}},this.triggerTyping=function(e){e.sendID!==t.instance.userID&&t.typingManager.onNewMessage(e)},this.triggerNotification=function(e,t){try{for(var r=0,n=Object.entries(e);rexports.NotificationType.FriendNotificationBegin&&e.contentTypeexports.NotificationType.UserNotificationBegin&&e.contentTypeexports.NotificationType.GroupNotificationBegin&&e.contentTypeexports.NotificationType.SignalingNotificationBegin&&e.contentTypey&&(n=h||!v.cache.isNotNotifyConversation(a),v.cache.updateCachedMaxReadSeq(a,{maxSeq:y+1,maxSeqTime:M.sendTime}),m&&(v.cache.updateCachedMaxReadSeq(a,{hasReadSeq:D+1}),v.cache.tryUpdateCachedMessages(a,{clientMsgID:M.clientMsgID,seq:M.seq})))}}})},u=0,c=Object.entries(e);u0){if(!r)return s.map(function(e){v.cache.tryUpdateCachedMessages(ne(e),e)}),Promise.resolve();v.instance.triggerEvent({event:exports.CbEvents.OnRecvNewMessages,data:s.map(De),operationID:t})}return Promise.resolve()}catch(e){return Promise.reject(e)}},this.instance=e,this.cache=new Ge(e),this.syncer=new Ne(e),this.typingManager=new Re(e)},je=/*#__PURE__*/function(){function e(e){var t=this,r=this,n=this,o=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=function(e,t){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:I.GetFullGroupMemberUserIDs,data:{groupID:e,idHash:0},operationID:t})).then(function(t){r.cachedGroupMembersID.set(e,t.userIDs)})}catch(e){return Promise.reject(e)}},this.getGroupInfosWithCache=function(e,t){try{var r=[],o=[];return e.forEach(function(e){var t=n.cachedGroups.get(e);t?r.push(t):o.push(e)}),o.length?Promise.resolve(n.instance.sendHttpRequest({reqFuncName:exports.RequestApi.GetSpecifiedGroupsInfo,data:{groupIDs:o},operationID:t})).then(function(e){var t=e.groupInfos;return t&&t.forEach(function(e){return n.cachedGroups.set(e.groupID,e)}),[].concat(r,null!=t?t:[])}):Promise.resolve(r)}catch(e){return Promise.reject(e)}},this.getGroupMembersWithCache=function(e){var t=e.groupID,r=e.userIDList,n=e.operationID;try{var i,s,a=null!=(i=o.cachedGroupMembers.get(t))?i:[],u=function(){if(null!=r&&r.length){var e=[],i=[];return r.forEach(function(t){var r=a.find(function(e){return e.userID===t});r?i.push(r):e.push(t)}),e.length?Promise.resolve(o.instance.sendHttpRequest({reqFuncName:exports.RequestApi.GetSpecifiedGroupMembersInfo,data:{groupID:t,userIDs:e},operationID:n})).then(function(e){var r=e.members;r&&o.cachedGroupMembers.set(t,[].concat(a,r));var n=[].concat(i,null!=r?r:[]);return s=1,n}):(s=1,i)}}();return Promise.resolve(u&&u.then?u.then(function(e){return s?e:a}):s?u:a)}catch(e){return Promise.reject(e)}},this.updateCachedGroups=function(e){e.map(function(e){t.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=function(e){var r,n=e[0].groupID,o=null!=(r=t.cachedGroupMembers.get(n))?r:[];t.cachedGroupMembers.set(n,[].concat(o.filter(function(t){return!e.find(function(e){return e.userID===t.userID})}),e));var i=t.instance.messageTrigger.cache.getAllCachedConversations().find(function(t){return t.groupID===e[0].groupID}),s=JSON.parse((null==i?void 0:i.latestMsg)||"{}"),a=e.find(function(e){return e.userID===s.sendID&&e.nickname!==s.senderNickname});i&&a&&t.instance.messageTrigger.getOneConversationAndTryChange(i.conversationID,"",{latestMsg:c({},s,{senderNickname:a.nickname})})},this.clearCachedGroupMembers=function(e){t.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=function(e){return t.cachedGroupMembersID.has(e)},this.getCachedGroupMembersID=function(e){var r;return null!=(r=t.cachedGroupMembersID.get(e))?r:[]},this.tryAddCachedGroupMembersID=function(e,r){if(t.cachedGroupMembersID.has(e)){var n,o=null!=(n=t.cachedGroupMembersID.get(e))?n:[];t.cachedGroupMembersID.set(e,[].concat(o,r))}},this.tryDeleteCachedGroupMembersID=function(e,r){if(t.cachedGroupMembersID.has(e)){var n,o=null!=(n=t.cachedGroupMembersID.get(e))?n:[];t.cachedGroupMembersID.set(e,o.filter(function(e){return!r.includes(e)}))}},this.instance=e}return e.prototype.clear=function(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()},e}(),Be=/*#__PURE__*/function(){function e(e){var t=this,r=this,n=this,o=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=function(e){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:I.GetGroupVersion,data:{userID:r.instance.userID,version:r.syncedGroupsVersion,versionID:r.syncedGroupsVersionID},operationID:e})).then(function(t){r.syncedGroupsVersionID&&r.compareGroupVersionAndTrigger(t,e),r.syncedGroupsVersion=t.version,r.syncedGroupsVersionID=t.versionID})}catch(e){return Promise.reject(e)}},this.syncGroupInfoAndMemberVersion=function(e){try{var t=function(){if(r.length)return Promise.resolve(n.instance.sendHttpRequest({reqFuncName:I.GetGroupMemberVersion,data:{userID:n.instance.userID,reqList:r},operationID:e})).then(function(t){var r=t.respList;Object.keys(n.syncedGroupMemberVersion).length>0&&n.compareGroupMemberVersionAndTrigger(r,e),n.syncedGroupMemberVersion=r;for(var o=0,i=Object.entries(r);o0},0,function(){var e=t.queue.shift(),r=function(t,r){try{var n=Promise.resolve(e()).then(function(){})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){i.default.error("Error executing task:",e)});if(r&&r.then)return r.then(function(){})});return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},e}();function at(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var ut=((it={})[exports.MessageType.TextMessage]="textElem",it[exports.MessageType.AtTextMessage]="atTextElem",it[exports.MessageType.LocationMessage]="locationElem",it[exports.MessageType.CustomMessage]="customElem",it[exports.MessageType.MergeMessage]="mergeElem",it[exports.MessageType.QuoteMessage]="quoteElem",it[exports.MessageType.CardMessage]="cardElem",it[exports.MessageType.FaceMessage]="faceElem",it[exports.MessageType.PictureMessage]="pictureElem",it[exports.MessageType.VoiceMessage]="soundElem",it[exports.MessageType.VideoMessage]="videoElem",it[exports.MessageType.FileMessage]="fileElem",it);function ct(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var pt=[I.GetActiveConversations,I.GetDesignatedConversation];function dt(e,t,r){if(!e.s){if(r instanceof lt){if(!r.s)return void(r.o=dt.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(dt.bind(null,e,t),dt.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var gt=/*#__PURE__*/function(e){function t(){var t,o;return(t=e.call(this)||this).userID=void 0,t.platform=void 0,t.token=void 0,t.apiAddr=void 0,t.loginStatus=exports.LoginStatus.Logout,t.isReconnected=!1,t.connectState="disconnected",t.wsManager=void 0,t.messageTrigger=void 0,t.userTrigger=void 0,t.groupTrigger=void 0,t.relationTrigger=void 0,t.businessTrigger=void 0,t.requestMap=new Map,t.generateHttpHeader=function(e,r){var n={"Content-Type":"application/json",token:t.token,operationID:r,reqFuncName:e};return pt.includes(e)&&(n["Content-Type"]="application/x-protobuf"),n},t.sendHttpRequest=function(e){try{var r;return Promise.resolve(function(e){var t=e.url,r=e.data,n=e.headers,o=e.platform,i=e.method,s=void 0===i?"POST":i;return"web"===o?function(e){var t=e.url,r=e.data,n=e.headers,o=e.method,i=void 0===o?"POST":o;try{return Promise.resolve(fetch(t,{method:i,headers:c({},n),body:r instanceof Uint8Array?r:JSON.stringify(r)}).then(function(e){if(e.ok)return e.json();throw new Error(e.statusText)}).then(function(e){if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))}catch(e){return Promise.reject(e)}}(e):new Promise(function(e,i){var a=function(e){return"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null}(o);a?a({url:t,data:r instanceof Uint8Array?Uint8Array.from(r).buffer:r,method:s,header:c({"Content-Type":"application/json"},n),success:function(t){200===t.statusCode&&0===t.data.errCode?e(t.data.data):i(t.data||"Request failed")},fail:function(e){i(e)}}):i(new Error("Request is not supported"))})}({url:""+t.apiAddr+(e.replaceURL||E[e.reqFuncName]),data:e.data,headers:t.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(r=t.wsManager)?void 0:r.platformNamespace)||"web"}))}catch(e){return Promise.reject(e)}},t.handleWsConnected=function(e,r){try{var n=function(){if(0===e.errCode){t.connectState="connected",t.loginStatus=exports.LoginStatus.Logged,t.triggerEvent({event:exports.CbEvents.OnConnectSuccess}),t.triggerEvent({event:exports.CbEvents.OnSyncServerStart});var n=[t.messageTrigger.sync(r),t.relationTrigger.sync(r),t.groupTrigger.sync(r),t.userTrigger.sync(r)],o=ct(function(){return Promise.resolve(Promise.all(n)).then(function(){t.triggerEvent({event:exports.CbEvents.OnSyncServerFinish})})},function(e){i.default.error(e),t.triggerEvent({event:exports.CbEvents.OnSyncServerFailed,errCode:e.errCode||exports.ErrorCode.SdkInternalError,errMsg:e.message||"Internal Error"})});if(o&&o.then)return o.then(function(){})}else{t.triggerEvent({event:exports.CbEvents.OnConnectFailed,errCode:e.errCode,errMsg:e.errMsg,operationID:r});var s=Z[e.errCode];s&&t.triggerEvent({event:s,errCode:e.errCode,errMsg:e.errMsg,operationID:r}),t.connectState="disconnected",t.loginStatus=exports.LoginStatus.Logout}}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},t.handleMessage=function(e,r){try{var n=function(){if("string"!=typeof e){var n=function(){var r=ge(e),n=JSON.parse(r);t.handleGeneralWsResp(n)},o=function(){if(!(e instanceof ArrayBuffer))return Promise.resolve(e.arrayBuffer()).then(function(t){e=t})}();return o&&o.then?o.then(n):n()}var i=JSON.parse(e);t.handleWsConnected(i,r)}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},t.handleGeneralWsResp=function(e){var r=ae(e.data,e.reqIdentifier);if(e.reqIdentifier===exports.ReqIdentifier.PushMsg&&r)return t.messageTrigger.triggerConversation(r.msgs,e.operationID),void t.messageTrigger.triggerNotification(r.notificationMsgs,e.operationID);if(e.reqIdentifier!==exports.ReqIdentifier.WsSubUserOnlineStatus||e.msgIncr||t.userTrigger.onlineSub.userOnlineStateChange(r),e.reqIdentifier===exports.ReqIdentifier.KickOnlineMsg)return t.triggerEvent({event:exports.CbEvents.OnKickedOffline,operationID:e.operationID}),void t.reset();var n=t.requestMap.get(e.msgIncr);n&&(0===e.errCode?n.resolve(r):n.reject(new pe(e.errCode,e.errMsg)),t.requestMap.delete(e.msgIncr))},t.handleReconnecting=function(){t.connectState="reconnecting",t.triggerEvent({event:exports.CbEvents.OnConnecting})},t.handleReconnectFailed=function(){t.connectState="disconnected",t.triggerEvent({event:exports.CbEvents.OnConnectFailed,errCode:exports.ErrorCode.NetworkError,errMsg:"network error"})},t.handleReconnectSuccess=function(){t.isReconnected=!0},t.sendReqWaitResp=function(e){var n=e.data,o=e.reqIdentifier,i=e.operationID;if("connected"!==t.connectState)throw new pe(exports.ErrorCode.NetworkError,"network error, ws not connected");var s=te();return new Promise(function(e,a){var u;t.requestMap.set(s,{resolve:e,reject:a}),null==(u=t.wsManager)||u.sendMessage({reqIdentifier:o,msgIncr:s,sendID:t.userID,operationID:i,data:r.encode(n.buffer)})})},t.triggerEvent=function(e){var r=e.event,n=e.data,o=void 0===n?null:n,s=e.errCode,a=void 0===s?0:s,u=e.errMsg,c=void 0===u?"":u,p=e.operationID,d=void 0===p?"":p;t.loginStatus!==exports.LoginStatus.Logout&&(i.default.debug("%cSDK =>%c [OperationID:"+d+"] (event) trigger "+r+" with data "+JSON.stringify(o)+" errCode "+a+" errMsg "+c,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),t.emit(r,{event:r,data:o,errCode:a,errMsg:c,operationID:d}))},t.login=function(e,r){try{return Promise.resolve(de(exports.LoginStatus.Logged,exports.RequestApi.Login,r,function(){try{var n,o=e.userID,s=e.token,a=e.wsAddr,u=e.apiAddr,c=e.platformID;if(t.wsManager)throw new pe(exports.ErrorCode.LoginRepeatError,"login repeat");return i.default.setLevel(null!=(n=e.logLevel)?n:exports.LogLevel.Debug),t.userID=o,t.token=s,t.apiAddr=u,t.platform=c,t.wsManager=new ve(a,{sendID:o,token:s,platformID:c,operationID:r,isBackground:!1,isMsgResp:!0,sdkType:"js"},t.handleMessage,t.handleReconnecting,t.handleReconnectFailed,t.handleReconnectSuccess),t.connectState="connecting",t.loginStatus=exports.LoginStatus.Logging,t.triggerEvent({event:exports.CbEvents.OnConnecting,operationID:r}),Promise.resolve(ct(function(){return Promise.resolve(t.wsManager.connect()).then(function(){})},function(e){throw t.triggerEvent({event:exports.CbEvents.OnConnectFailed,errCode:exports.ErrorCode.NetworkError,errMsg:e.message||"network error",operationID:r}),t.connectState="disconnected",t.loginStatus=exports.LoginStatus.Logout,t.wsManager.close(),new pe(exports.ErrorCode.NetworkError,e.message||"network error")}))}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},t.getLoginStatus=function(e){return de(exports.LoginStatus.Logged,exports.RequestApi.GetLoginStatus,e,function(){try{var e;return null==(e=t.wsManager)||e.sendPing(),Promise.resolve(t.loginStatus)}catch(e){return Promise.reject(e)}})},t.logout=function(e){return de(t.loginStatus,exports.RequestApi.Logout,e,function(){try{return t.reset(),Promise.resolve()}catch(e){return Promise.reject(e)}})},t.internalUploadFile=function(e,r){return Promise.resolve(ct(function(){var n=t.userID+"/"+e.name,o=function(e){var t,r,n=null!=(t=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?t:"";return y[n]||"application/octet-stream"}(e.name),i={operationID:r,token:t.token};return Promise.resolve(function(e,t,r){return fetch(e+"/object/part_size",{method:"POST",headers:c({},r),body:JSON.stringify({size:t})}).then(M)}(t.apiAddr,e.size,i)).then(function(r){var a=r.size;function u(){var r=g.join(",");l.destroy();var u=new s.default;return u.append(r),Promise.resolve(function(e,t,r){return fetch(e+"/object/initiate_multipart_upload",{method:"POST",headers:c({},r),body:JSON.stringify(t)}).then(M)}(t.apiAddr,{hash:u.end(),size:e.size,partSize:a,maxParts:-1,cause:"",name:n,contentType:o},i)).then(function(r){var s=r.url,a=r.upload;if(u.destroy(),s)return{url:s};var p=a.sign.query,l=a.sign.header;return Promise.resolve(Promise.all(a.sign.parts.map(function(t,r){try{var n=new URL(t.url||a.sign.url);if(p){var i=new URLSearchParams(n.search);p.forEach(function(e){i.set(e.key,e.values[0])}),n.search=i.toString()}if(t.query){var s=new URLSearchParams(n.search);t.query.forEach(function(e){s.set(e.key,e.values[0])}),n.search=s.toString()}var u=n.toString(),c=new Headers;return l&&l.forEach(function(e){c.set(e.key,e.values[0])}),t.header&&t.header.forEach(function(e){c.set(e.key,e.values[0])}),c.set("Content-Length",(d[r].end-d[r].start).toString()),c.set("Content-Type",o),Promise.resolve(fetch(u,{method:"PUT",headers:c,body:e.slice(d[r].start,d[r].end)})).then(function(e){if(!e.ok)throw new Error("Failed to upload chunk "+(r+1))})}catch(e){return Promise.reject(e)}}))).then(function(){return Promise.resolve(function(e,t,r){return fetch(e+"/object/complete_multipart_upload",{method:"POST",headers:c({},r),body:JSON.stringify(t)}).then(M)}(t.apiAddr,{uploadID:a.uploadID,parts:g,cause:"",name:n,contentType:o},i)).then(function(e){return{url:e.url}})})})}var p=Math.ceil(e.size/a),d=[],g=[],l=new s.default.ArrayBuffer,f=0,v=function(e,t,r){for(var n;;){var o=e();if(ft(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!ft(i)){n=1;break}i=i.s}}var s=new lt,a=dt.bind(null,s,2);return(0===n?o.then(c):1===n?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):dt(s,1,i)})).then(void 0,a),s;function u(t){i=t;do{if(!(o=e())||ft(o)&&!o.v)return void dt(s,1,i);if(o.then)return void o.then(c).then(void 0,a);ft(i=r())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(u).then(void 0,a):u(i):dt(s,1,i)}}(function(){return fg?d:g,count:n-t.length,conversationID:o,operationID:i,fetchedMessages:p})}return p}):Promise.resolve(a)}catch(e){return Promise.reject(e)}};return{createTextMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateTextMessage,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.TextMessage);return r.textElem={content:t},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createTextAtMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateTextAtMessage,r,function(){try{var r;if(!t.text)throw new pe(exports.ErrorCode.ArgsError,"text cannot be empty");if(t.atUserIDList.length>10)throw new pe(exports.ErrorCode.ArgsError,"atUserIDList length must be less than 10");var n,o=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.AtTextMessage);return(null==(r=t.message)?void 0:r.contentType)===exports.MessageType.QuoteMessage&&(t.message.contentType=exports.MessageType.TextMessage,t.message.textElem={content:null==(n=t.message.quoteElem)?void 0:n.text}),o.atTextElem={text:t.text,atUserList:t.atUserIDList,atUsersInfo:t.atUsersInfo,quoteMessage:t.message},Promise.resolve(o)}catch(e){return Promise.reject(e)}})},createLocationMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateLocationMessage,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.LocationMessage);return r.locationElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createCustomMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateCustomMessage,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.CustomMessage);return r.customElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createQuoteMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateQuoteMessage,r,function(){try{var r,n=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.QuoteMessage),o=JSON.parse(t.message);return o.contentType===exports.MessageType.QuoteMessage&&(o.contentType=exports.MessageType.TextMessage,o.textElem={content:null==(r=o.quoteElem)?void 0:r.text}),n.quoteElem={text:t.text,quoteMessage:o},Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createCardMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateCardMessage,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.CardMessage);return r.cardElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByURL:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateImageMessageByURL,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.PictureMessage);return r.pictureElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByFile:function(r,n){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.CreateImageMessageByFile,n,function(){try{var n=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.PictureMessage);return n.pictureElem=c({},r),t.set(r.sourcePicture.uuid,r.file),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createSoundMessageByURL:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateSoundMessageByURL,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.VoiceMessage);return r.soundElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createSoundMessageByFile:function(r,n){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.CreateSoundMessageByFile,n,function(){try{var n=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.VoiceMessage);return n.soundElem=c({},r),t.set(r.uuid,r.file),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createVideoMessageByURL:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateVideoMessageByURL,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.VideoMessage);return r.videoElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createVideoMessageByFile:function(r,n){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.CreateVideoMessageByFile,n,function(){try{var n=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.VideoMessage);return n.videoElem=c({},r),t.set(r.videoUUID,r.videoFile),t.set(r.snapshotUUID,r.snapshotFile),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createFileMessageByURL:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateFileMessageByURL,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.FileMessage);return r.fileElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFileMessageByFile:function(r,n){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.CreateFileMessageByFile,n,function(){try{var n=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.FileMessage);return n.fileElem=c({},r),t.set(r.uuid,r.file),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createMergerMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateMergerMessage,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.MergeMessage);return r.mergeElem={title:t.title,abstractList:t.summaryList,multiMessage:t.messageList,messageEntityList:[]},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFaceMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateFaceMessage,r,function(){try{var r=ue(e,exports.MsgFrom.UserMsgType,exports.MessageType.FaceMessage);return r.faceElem=c({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createForwardMessage:function(t,r){return de(e.loginStatus,exports.RequestApi.CreateForwardMessage,r,function(){try{if(t.status!==exports.MessageStatus.Succeed)throw new pe(exports.ErrorCode.ArgsError,"Only successfully sent messages can be forwarded");var r=ue(e,exports.MsgFrom.UserMsgType,t.contentType);return Promise.resolve(c({},t,r,{seq:0,status:exports.MessageStatus.Sending}))}catch(e){return Promise.reject(e)}})},sendMessage:function(o,i){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.SendMessage,i,function(){return r.enqueue(function(){try{var r=c({},o,{message:c({},o.message)}),s=r.message,a=r.recvID,u=r.groupID,p=r.isOnlineOnly,d=r.offlinePushInfo,g=void 0===d?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:d;void 0===g.signalInfo&&(g.signalInfo="");var l=ut[s.contentType];if(!l)throw new pe(exports.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");s.recvID=a,s.groupID=u,s.sessionType=u?exports.SessionType.Group:exports.SessionType.Single;var f={};p&&Object.values(exports.MessageOptionsKey).forEach(function(e){return f[e]=!1});var v=ne(s),h=!1;return Promise.resolve(e.messageTrigger.getOneConversationAndTryChange(v,i)).then(function(r){function o(){function o(o){function c(o){function c(o){function c(o){function c(t){var o,c,p=JSON.stringify(s[l]),d=n.PbCoder.MsgData.encode({sendID:e.userID,recvID:a||"",groupID:u||"",clientMsgID:s.clientMsgID,serverMsgID:s.serverMsgID||"",senderPlatformID:e.platform,senderNickname:s.senderNickname,senderFaceURL:s.senderFaceUrl,sessionType:s.sessionType,msgFrom:s.msgFrom,contentType:s.contentType,content:le(p),seq:s.seq,sendTime:0,createTime:s.createTime,status:s.status,isRead:!1,options:f,offlinePushInfo:g,atUserIDList:null!=(o=null==(c=s.atTextElem)?void 0:c.atUserList)?o:[],attachedInfo:s.attachedInfoElem?JSON.stringify(s.attachedInfoElem):"",ex:s.ex||"",keyVersion:0,dstUserIDs:[]}).finish();return at(function(){return Promise.resolve(e.sendReqWaitResp({data:d,operationID:i,reqIdentifier:exports.ReqIdentifier.SendMsg})).then(function(t){var n=t.serverMsgID,o=t.sendTime;return s.sendTime=o,s.serverMsgID=n,s.status=exports.MessageStatus.Succeed,e.messageTrigger.setTriggeredConversationEvent(i),e.messageTrigger.cache.updateCachedMaxReadSeq(r.conversationID,{maxSeqTime:o}),e.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s),latestMsgSendTime:o}),s})},function(t){throw s.status=exports.MessageStatus.Failed,e.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s)}),t})}var p=function(){if(s.contentType===exports.MessageType.FileMessage){var r,n=t.get(null==(r=s.fileElem)?void 0:r.uuid);if(!n)throw new pe(exports.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(e.internalUploadFile(n,i)).then(function(e){var r,n=e.url,o=void 0===n?"":n,i=e.error;if(t.delete(null==(r=s.fileElem)?void 0:r.uuid),i)throw new pe(exports.ErrorCode.NetworkError,"Upload file failed");s.fileElem.sourceUrl=o})}}();return p&&p.then?p.then(c):c()}var p=function(){if(s.contentType===exports.MessageType.VideoMessage){var r,n,o=t.get(null==(r=s.videoElem)?void 0:r.videoUUID),a=t.get(null==(n=s.videoElem)?void 0:n.snapshotUUID);if(!o||!a)throw new pe(exports.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(Promise.all([e.internalUploadFile(o,i),e.internalUploadFile(a,i)])).then(function(e){var r,n;if(t.delete(null==(r=s.videoElem)?void 0:r.videoUUID),t.delete(null==(n=s.videoElem)?void 0:n.snapshotUUID),e[0].error||e[1].error)throw new pe(exports.ErrorCode.NetworkError,"Upload file failed");s.videoElem.videoUrl=e[0].url,s.videoElem.snapshotUrl=e[1].url})}}();return p&&p.then?p.then(c):c()}var p=function(){if(s.contentType===exports.MessageType.VoiceMessage){var r,n=t.get(null==(r=s.soundElem)?void 0:r.uuid);if(!n)throw new pe(exports.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(e.internalUploadFile(n,i)).then(function(e){var r,n=e.url,o=void 0===n?"":n,i=e.error;if(t.delete(null==(r=s.soundElem)?void 0:r.uuid),i)throw new pe(exports.ErrorCode.NetworkError,"Upload file failed");s.soundElem.sourceUrl=o})}}();return p&&p.then?p.then(c):c()}r.latestMsgSendTime=s.createTime,e.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s)},void 0,h);var p=function(){if(s.contentType===exports.MessageType.PictureMessage){var r,n=t.get(null==(r=s.pictureElem)?void 0:r.sourcePicture.uuid);if(!n)throw new pe(exports.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(e.internalUploadFile(n,i)).then(function(e){var r,n=e.url,o=void 0===n?"":n,i=e.error;if(t.delete(null==(r=s.pictureElem)?void 0:r.sourcePicture.uuid),i)throw new pe(exports.ErrorCode.NetworkError,"Upload file failed");s.pictureElem.sourcePicture.url=o,s.pictureElem.bigPicture.url=o,s.pictureElem.snapshotPicture.width=640,s.pictureElem.snapshotPicture.height=640,s.pictureElem.snapshotPicture.url=o+"?type=image&width=640&height=640"})}}();return p&&p.then?p.then(c):c()}var c=function(){if(u)return Promise.resolve(e.groupTrigger.cache.getGroupMembersWithCache({groupID:u,userIDList:[e.userID],operationID:i})).then(function(e){if(null==e||!e.length)throw new pe(exports.ErrorCode.ArgsError,"user not join target group");e[0].nickname&&(s.senderNickname=e[0].nickname)})}();return c&&c.then?c.then(o):o()}var p=function(){if(!r)return h=!0,Promise.resolve(e.messageTrigger.initConversation({sourceID:u||a,sessionType:s.sessionType,operationID:i})).then(function(e){r=e});r.isPrivateChat&&(f[exports.MessageOptionsKey.IsNotPrivate]=!1,s.attachedInfoElem=c({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:r.burnDuration}))}();return p&&p.then?p.then(o):o()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},sendMessageNotOss:function(t,o){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.SendMessage,o,function(){return r.enqueue(function(){try{var r=c({},t,{message:c({},t.message)}),i=r.message,s=r.recvID,a=r.groupID,u=r.isOnlineOnly,p=r.offlinePushInfo,d=void 0===p?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:p;void 0===d.signalInfo&&(d.signalInfo="");var g=ut[i.contentType];if(!g)throw new pe(exports.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");i.recvID=s,i.groupID=a,i.sessionType=a?exports.SessionType.Group:exports.SessionType.Single;var l={};u&&Object.values(exports.MessageOptionsKey).forEach(function(e){return l[e]=!1});var f=ne(i);return Promise.resolve(e.messageTrigger.getOneConversationAndTryChange(f,o)).then(function(t){function r(r){var u,c;t.latestMsgSendTime=i.createTime,e.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(i)});var p=JSON.stringify(i[g]),v=n.PbCoder.MsgData.encode({sendID:e.userID,recvID:s||"",groupID:a||"",clientMsgID:i.clientMsgID,serverMsgID:i.serverMsgID||"",senderPlatformID:e.platform,senderNickname:i.senderNickname,senderFaceURL:i.senderFaceUrl,sessionType:i.sessionType,msgFrom:i.msgFrom,contentType:i.contentType,content:le(p),seq:i.seq,sendTime:0,createTime:i.createTime,status:i.status,isRead:!1,options:l,offlinePushInfo:d,atUserIDList:null!=(u=null==(c=i.atTextElem)?void 0:c.atUserList)?u:[],attachedInfo:i.attachedInfoElem?JSON.stringify(i.attachedInfoElem):"",ex:i.ex||"",keyVersion:0,dstUserIDs:[]}).finish();return at(function(){return Promise.resolve(e.sendReqWaitResp({data:v,operationID:o,reqIdentifier:exports.ReqIdentifier.SendMsg})).then(function(r){var n=r.serverMsgID,s=r.sendTime;return i.sendTime=s,i.serverMsgID=n,i.status=exports.MessageStatus.Succeed,e.messageTrigger.setTriggeredConversationEvent(o),e.messageTrigger.cache.updateCachedMaxReadSeq(t.conversationID,{maxSeqTime:s}),e.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(i),latestMsgSendTime:s}),i})},function(t){throw i.status=exports.MessageStatus.Failed,e.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(i)}),t})}var u=function(){if(!t)return Promise.resolve(e.messageTrigger.initConversation({sourceID:a||s,sessionType:i.sessionType,operationID:o})).then(function(r){return t=r,function(){if(a)return Promise.resolve(e.groupTrigger.cache.getGroupMembersWithCache({groupID:a,userIDList:[e.userID],operationID:o})).then(function(e){if(null==e||!e.length)throw new pe(exports.ErrorCode.ArgsError,"user not join target group");e[0].nickname&&(i.senderNickname=e[0].nickname)})}()});t.isPrivateChat&&(l[exports.MessageOptionsKey.IsNotPrivate]=!1,i.attachedInfoElem=c({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:t.burnDuration}))}();return u&&u.then?u.then(r):r()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},revokeMessage:function(t,r){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.RevokeMessage,r,function(){try{var n=function(n){return Promise.resolve(e.sendHttpRequest({reqFuncName:exports.RequestApi.RevokeMessage,data:{conversationID:t.conversationID,seq:o.seq,userID:e.userID},operationID:r})).then(function(){e.messageTrigger.setTriggeredConversationEvent(r),e.messageTrigger.revokeMessage({revokerUserID:e.userID,clientMsgID:o.clientMsgID,revokeTime:Date.now(),sesstionType:o.sessionType,seq:o.seq,conversationID:t.conversationID,isAdminRevoke:!1},r)})},o=e.messageTrigger.cache.getCachedMessageByClientMsgIDs(t.conversationID,[t.clientMsgID])[0];if(!o)throw new pe(exports.ErrorCode.ArgsError,"message not exist");var i=function(){if(o.sendID!==e.userID){if(!o.groupID)throw new pe(exports.ErrorCode.ArgsError,"message can not be revoked");return Promise.resolve(e.groupTrigger.cache.getGroupMembersWithCache({groupID:o.groupID,userIDList:[e.userID],operationID:r})).then(function(e){var t=e[0];if(!t||t.roleLevel===exports.GroupMemberRole.Nomal)throw new pe(exports.ErrorCode.ArgsError,"message can not be revoked")})}}();return Promise.resolve(i&&i.then?i.then(n):n())}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},getAdvancedHistoryMessageList:function(t,r){try{return Promise.resolve(de(e.loginStatus,exports.RequestApi.GetAdvancedHistoryMessageList,r,function(){try{var n={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(s!==t.conversationID&&(o=null,s=t.conversationID),t.startClientMsgID){if(null===o){var u=e.messageTrigger.cache.getCachedMessageByClientMsgIDs(t.conversationID,[t.startClientMsgID])[0];if(!u)return Promise.resolve(c({},n,{isEnd:!0}));o=u.seq}}else o=0;var p=e.messageTrigger.cache.getCachedMaxReadSeq(t.conversationID);return i.default.log("syncedSeqs",p),p?Promise.resolve(a({maxSeq:o?o-1:p.maxSeq,count:t.count,conversationID:t.conversationID,operationID:r})).then(function(s){function a(){function a(){var e,a;return n.messageList=s.map(De),i.default.debug("getAdvancedHistoryMessageList with opid: ",r,"messageList: ",n.messageList),o=null!=(e=null==(a=s[0])?void 0:a.seq)?e:0,c({},n,{isEnd:s.length%c [OperationID:"+t[t.length-1]+"] (invoked) run "+e+" with args "+JSON.stringify(t),"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")}(t,r),Promise.resolve(n.apply(e,r)).then(function(e){var r,n;return r=t,(n=e).errCode?i.default.debug("%cSDK =>%c [OperationID:"+n.operationID+"] (response) run "+r+" with error "+JSON.stringify(n),"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):i.default.debug("%cSDK =>%c [OperationID:"+n.operationID+"] (response) run "+r+" with response before processor "+JSON.stringify(n.data),"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),e.errCode?Promise.reject(e):e})}catch(e){return Promise.reject(e)}}:Reflect.get(e,t,r)}})}; +var e=require("loglevel"),t=require("spark-md5"),r=require("base64-arraybuffer"),n=require("@openim/protocol"),o=require("crypto-js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=/*#__PURE__*/i(e),a=/*#__PURE__*/i(t),u=/*#__PURE__*/i(o);function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;tt.latestMsgSendTime?-1:e.latestMsgSendTime>6*(n-1)),i=1;i>6*(n-(i+1))&191);return}}},Se=function(e,t,r,n){var o=t.getUint8(r);if(e.bytesRead=1,e.charVal=0,128&o){for(var i=0,s=o;128&s;)i++,s<<=1;if(1===i)return console.error("UTF-8 read - found continuation byte at beginning of character"),void(e.charVal=Me);if(i>n)return console.error("UTF-8 read - attempted to read "+i+" byte character, "+(n-i)+" bytes past end of buffer"),void(e.charVal=Me);e.charVal=o&255>>i+1;for(var a=1;a>8-(i+1)-1))return console.error("UTF-8 read - found overlong encoding"),e.charVal=Me,void(e.bytesRead=1);e.bytesRead++}if(e.charVal>1114111)return console.error("UTF-8 read - found illegally high code point "+e.charVal),e.charVal=Me,void(e.bytesRead=1)}else e.charVal=o},Ce=function(e){for(var t=[],r=0;r255&&(n="?".charCodeAt(0)),t.push(n)}return t},xe=function(e,t,r,n){var o=void 0===r,i=t||0;if(!o&&i+r>e.byteLength)throw new Error("Attempted to read "+(i+r-e.byteLength)+" bytes past end of buffer");for(var s=[],a={};ii-t)&&(Se(a,e,i,o?e.byteLength-(i+t):r-(i-t)),i+=a.bytesRead,!o||a.charVal!==n);)s.push(String.fromCharCode(a.charVal));return{str:s.join(""),byteLength:i-t}},Re=function(e,t,r,n){var o=[],i=0;t=t||0;var s=!1;void 0===r&&(s=!0,r=e.byteLength-e.byteOffset);for(var a=0;a=e.byteLength&&(o-=1),e.setUint8(t+o,0),o+1},e}()),Ee=function(e){return(new TextDecoder).decode(e)},we=function(e){return(new TextEncoder).encode(e)};!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(Ne||(Ne={}));var Ue,Oe=/*#__PURE__*/function(){function e(e,t,r,n,o,i,s,a,u,c){var p=this,d=this;void 0===a&&(a=5e3),void 0===u&&(u=Infinity),this.url=void 0,this.onMessage=void 0,this.onClose=void 0,this.onReconnecting=void 0,this.onReconnectFailed=void 0,this.onReconnectSuccess=void 0,this.reconnectInterval=void 0,this.maxReconnectAttempts=void 0,this.ws=void 0,this.connectParams=void 0,this.reconnectAttempts=void 0,this.shouldReconnect=void 0,this.isProcessingMessage=!1,this.consecutiveHeartbeatFailures=0,this.connectTimeoutId=null,this.platformNamespace=void 0,this.envListenersInstalled=!1,this.heartbeatConfig={interval:1e4,timeout:5e3,maxFailures:3},this.heartbeatWorker=null,this.legacyTimer=null,this.heartbeatTimeoutId=null,this.workerUrl=null,this.lastPongAt=0,this.forceImmediateReconnect=!1,this.checkPlatform=function(){if("undefined"!=typeof WebSocket)try{if("undefined"!=typeof window&&window.WebSocket)return"web";if("undefined"!=typeof global&&global.WebSocket)return"web"}catch(e){}return"undefined"!=typeof my&&"function"==typeof my.connectSocket?"my":"undefined"!=typeof uni&&"function"==typeof uni.connectSocket?"uni":"undefined"!=typeof wx&&"function"==typeof wx.connectSocket?"wx":"unknow"},this.urlFormat=function(){for(var e="?",t=0,r=Object.entries(d.connectParams);t {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n "],{type:"application/javascript"});d.workerUrl=URL.createObjectURL(e),d.heartbeatWorker=new Worker(d.workerUrl),d.heartbeatWorker.onmessage=function(e){"ping"===e.data.type&&d.sendPing()},d.heartbeatWorker.postMessage({type:"start",interval:d.heartbeatConfig.interval})}catch(e){d.heartbeatWorker=null,d.workerUrl&&(URL.revokeObjectURL(d.workerUrl),d.workerUrl=null),d.legacyTimer=setInterval(function(){d.sendPing()},d.heartbeatConfig.interval)}else d.legacyTimer=setInterval(function(){d.sendPing()},d.heartbeatConfig.interval)},this.connect=function(e){return void 0===e&&(e=1e4),"unknow"===d.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise(function(t,r){if(d.connectTimeoutId&&(clearTimeout(d.connectTimeoutId),d.connectTimeoutId=null),d.connectTimeoutId=setTimeout(function(){d.ws&&(d.ws.close(),d.onClose()),r(new Error("Connection timeout after "+e+"ms"))},e),d.ws&&d.ws.readyState!==Ne.CLOSED)d.ws.readyState===d.ws.OPEN?(d.connectTimeoutId&&(clearTimeout(d.connectTimeoutId),d.connectTimeoutId=null),t()):(d.connectTimeoutId&&(clearTimeout(d.connectTimeoutId),d.connectTimeoutId=null),r(new Error("WebSocket is in an unknown state")));else{var n=function(){d.connectTimeoutId&&(clearTimeout(d.connectTimeoutId),d.connectTimeoutId=null),d.reconnectAttempts&&d.onReconnectSuccess(),d.reconnectAttempts=0,d.consecutiveHeartbeatFailures=0,d.lastPongAt=Date.now(),d.startHeartbeat(),t()},o=function(e){d.connectTimeoutId&&(clearTimeout(d.connectTimeoutId),d.connectTimeoutId=null),r(e)};if("web"===d.platformNamespace)d.ws=new WebSocket(d.urlFormat()),d.ws.onopen=n,d.ws.onerror=o;else{var i={url:d.urlFormat(),complete:function(){}};"my"===d.platformNamespace&&(i.multiple=!0),"uni"===d.platformNamespace&&(d.ws=uni.connectSocket(i)),"wx"===d.platformNamespace&&(d.ws=wx.connectSocket(i)),"my"===d.platformNamespace&&(d.ws=my.connectSocket(i)),d.ws.onOpen(n),d.ws.onError(o)}d.setupEventListeners(),d.installEnvListeners()}})},this.setupEventListeners=function(){if(d.ws){var e=function(e){return d.onBinaryMessage(e.data)},t=function(e){if(d.shouldReconnect&&d.reconnectAttempts=d.heartbeatConfig.maxFailures)return console.warn("Heartbeat failed "+d.consecutiveHeartbeatFailures+" times, closing connection"),d.ws.close(),d.onClose(),void d.stopHeartbeat();d.heartbeatTimeoutId&&clearTimeout(d.heartbeatTimeoutId),d.heartbeatTimeoutId=setTimeout(function(){var e;d.consecutiveHeartbeatFailures++,console.warn("Heartbeat timeout, consecutive failures: "+d.consecutiveHeartbeatFailures),d.consecutiveHeartbeatFailures>=d.heartbeatConfig.maxFailures&&(null==(e=d.ws)||e.close(),d.onClose(),d.stopHeartbeat())},d.heartbeatConfig.timeout);var t=JSON.stringify({type:"ping"});d.ws.send("web"===d.platformNamespace?t:{data:t})}else d.heartbeatTimeoutId&&(clearTimeout(d.heartbeatTimeoutId),d.heartbeatTimeoutId=null)},this.forceHealthCheck=function(e){void 0===e&&(e=!1),d.ws&&d.ws.readyState===Ne.OPEN&&(e&&(d.consecutiveHeartbeatFailures=Math.max(d.heartbeatConfig.maxFailures-1,0)),d.sendPing())},this.handleVisibilityChange=function(){try{"visible"===("undefined"!=typeof document?document.visibilityState:"visible")&&d.forceHealthCheck(!0)}catch(e){}},this.handleOnline=function(){if(!d.ws||d.ws.readyState!==Ne.OPEN)return d.reconnectAttempts=0,d.onReconnecting(),d.connectParams.operationID=se(),void d.connect().catch(function(){d.onReconnectFailed()});var e=Date.now();d.lastPongAt&&e-d.lastPongAt>d.heartbeatConfig.interval+d.heartbeatConfig.timeout*d.heartbeatConfig.maxFailures&&d.forceHealthCheck(!0)},this.handleOffline=function(){d.stopHeartbeat()},this.installEnvListeners=function(){if(!d.envListenersInstalled&&"web"===d.platformNamespace)try{"undefined"!=typeof document&&document.addEventListener&&document.addEventListener("visibilitychange",d.handleVisibilityChange),"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("online",d.handleOnline),window.addEventListener("offline",d.handleOffline),window.addEventListener("pageshow",d.handleVisibilityChange),window.addEventListener("focus",d.handleVisibilityChange)),d.envListenersInstalled=!0}catch(e){}},this.removeEnvListeners=function(){if(d.envListenersInstalled&&"web"===d.platformNamespace){try{"undefined"!=typeof document&&document.removeEventListener&&document.removeEventListener("visibilitychange",d.handleVisibilityChange),"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("online",d.handleOnline),window.removeEventListener("offline",d.handleOffline),window.removeEventListener("pageshow",d.handleVisibilityChange),window.removeEventListener("focus",d.handleVisibilityChange))}catch(e){}d.envListenersInstalled=!1}},this.sendMessage=function(e){var t,r=we(JSON.stringify(e));(null==(t=d.ws)?void 0:t.readyState)===Ne.OPEN?d.ws.send("web"===d.platformNamespace?r:{data:Uint8Array.from(r).buffer}):console.error("WebSocket is not open. Message not sent.")},this.close=function(){var e;d.shouldReconnect=!1,d.connectTimeoutId&&(clearTimeout(d.connectTimeoutId),d.connectTimeoutId=null),d.heartbeatTimeoutId&&(clearTimeout(d.heartbeatTimeoutId),d.heartbeatTimeoutId=null),(null==(e=d.ws)?void 0:e.readyState)===Ne.OPEN&&(d.ws.close(),d.onClose()),d.stopHeartbeat(),d.removeEnvListeners()},this.forceReconnect=function(e){if(void 0===e&&(e=!0),d.shouldReconnect=!0,d.reconnectAttempts=0,d.consecutiveHeartbeatFailures=0,e&&(d.forceImmediateReconnect=!0),!d.ws||d.ws.readyState===Ne.CLOSED)return d.onReconnecting(),d.connectParams.operationID=se(),void d.connect().catch(function(){d.onReconnectFailed()});d.stopHeartbeat();try{d.ws.close()}catch(e){d.onReconnecting(),d.connectParams.operationID=se(),d.connect().catch(function(){d.onReconnectFailed()})}},this.reset=function(){d.shouldReconnect=!0,d.reconnectAttempts=0,d.consecutiveHeartbeatFailures=0,d.connectTimeoutId&&(clearTimeout(d.connectTimeoutId),d.connectTimeoutId=null),d.heartbeatTimeoutId&&(clearTimeout(d.heartbeatTimeoutId),d.heartbeatTimeoutId=null),d.stopHeartbeat(),d.removeEnvListeners()},this.url=e,this.onMessage=r,this.onClose=n,this.onReconnecting=o,this.onReconnectFailed=i,this.onReconnectSuccess=s,this.reconnectInterval=a,this.maxReconnectAttempts=u,this.connectParams=t,this.reconnectInterval=a,this.maxReconnectAttempts=u,this.reconnectAttempts=0,this.shouldReconnect=!0,this.platformNamespace=this.checkPlatform(),c&&(this.heartbeatConfig=f({},this.heartbeatConfig,c))}return e.prototype.stopHeartbeat=function(){this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.heartbeatWorker&&(this.heartbeatWorker.postMessage({type:"stop"}),this.heartbeatWorker.terminate(),this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.heartbeatWorker=null),this.legacyTimer&&(clearInterval(this.legacyTimer),this.legacyTimer=null)},e}(),Fe=/*#__PURE__*/function(){function e(){this.events=void 0,this.events={}}var t=e.prototype;return t.emit=function(e,t){return this.events[e]&&this.events[e].forEach(function(e){return e(t)}),this},t.on=function(e,t){return this.events[e]?this.events[e].push(t):this.events[e]=[t],this},t.off=function(e,t){if(e&&"function"==typeof t&&this.events[e]){var r=this.events[e];if(!r||0===r.length)return;var n=r.findIndex(function(e){return e===t});-1!==n&&r.splice(n,1)}return this},e}(),ke=["friendUser"],Le=["blackUserInfo"],je=function(e){var t,r,n,o,i,s,a,u,c,p,d,g,l,f;return{createTime:null==(t=e.groupInfo)?void 0:t.createTime,creatorUserID:null==(r=e.groupInfo)?void 0:r.creatorUserID,ex:e.ex,groupFaceURL:null==(n=e.groupInfo)?void 0:n.faceURL,groupID:null==(o=e.groupInfo)?void 0:o.groupID,groupName:null==(i=e.groupInfo)?void 0:i.groupName,groupType:null==(s=e.groupInfo)?void 0:s.groupType,handleResult:e.handleResult,handleUserID:e.handleUserID,handledMsg:e.handleMsg,handledTime:e.handleTime,introduction:null==(a=e.groupInfo)?void 0:a.introduction,memberCount:null==(u=e.groupInfo)?void 0:u.memberCount,nickname:null==(c=e.userInfo)?void 0:c.nickname,notification:null==(p=e.groupInfo)?void 0:p.notification,ownerUserID:null==(d=e.groupInfo)?void 0:d.ownerUserID,reqMsg:e.reqMsg,reqTime:e.reqTime,joinSource:e.joinSource,status:null==(g=e.groupInfo)?void 0:g.status,userFaceURL:null==(l=e.userInfo)?void 0:l.faceURL,userID:null==(f=e.userInfo)?void 0:f.userID}},Be=function(e){return{clientMsgID:e.clientMsgID,serverMsgID:e.serverMsgID,createTime:e.createTime,sendTime:e.sendTime,sessionType:e.sessionType,sendID:e.sendID,recvID:e.recvID,msgFrom:e.msgFrom,contentType:e.contentType,senderPlatformID:e.senderPlatformID,senderNickname:e.senderNickname,senderFaceUrl:e.senderFaceURL,groupID:e.groupID,content:e.content.length?Ee(e.content):"",seq:e.seq,isRead:e.isRead,status:exports.InternalMessageStatus.MsgStatusSendSuccess,isExternalExtensions:!1,offlinePush:e.offlinePushInfo,attachedInfo:e.attachedInfo,ex:e.ex,localEx:""}},Ve=function(e){var t=f({},e);try{switch(e.contentType){case exports.InternalContentType.Text:t.textElem=JSON.parse(t.content);break;case exports.InternalContentType.Picture:t.pictureElem=JSON.parse(t.content);break;case exports.InternalContentType.Sound:t.soundElem=JSON.parse(t.content);break;case exports.InternalContentType.Video:t.videoElem=JSON.parse(t.content);break;case exports.InternalContentType.File:t.fileElem=JSON.parse(t.content);break;case exports.InternalContentType.AtText:t.atTextElem=JSON.parse(t.content);break;case exports.InternalContentType.Location:t.locationElem=JSON.parse(t.content);break;case exports.InternalContentType.Custom:case exports.InternalContentType.CustomMsgNotTriggerConversation:case exports.InternalContentType.CustomMsgOnlineOnly:t.customElem=JSON.parse(t.content);break;case exports.InternalContentType.Typing:t.typingElem=JSON.parse(t.content);break;case exports.InternalContentType.Merger:t.mergeElem=JSON.parse(t.content);break;case exports.InternalContentType.Face:t.faceElem=JSON.parse(t.content);break;case exports.InternalContentType.Quote:t.quoteElem=JSON.parse(t.content);break;case exports.InternalContentType.Card:t.cardElem=JSON.parse(t.content);break;default:t.notificationElem=JSON.parse(t.content)}}catch(e){s.default.warn("messageElemFormater messageElem parse failed",t)}if(e.attachedInfo)try{t.attachedInfoElem=JSON.parse(t.attachedInfo),t.attachedInfo=""}catch(e){s.default.warn("messageElemFormater attachedInfoElem failed",t.attachedInfo)}return t.content="",t},_e=function(e){var t=Ee(e),r=JSON.parse(t);return JSON.parse(r.detail)},He=function(e,t,r){var n=e.conversation,o=e.group,i=e.friend,s=e.user,a=e.lastMsg,u=e.maxSeq,c=e.readSeq;try{var p,d,g,l,f=function(){var e,t;return{conversationID:n.conversationID,conversationType:n.conversationType,userID:n.userID,groupID:n.groupID,showName:p,faceURL:v,recvMsgOpt:n.recvMsgOpt,unreadCount:u-c,groupAtType:n.groupAtType,latestMsg:h,latestMsgSendTime:null!=(e=null!=(t=null==a?void 0:a.sendTime)?t:r)?e:0,draftText:"",draftTextTime:0,burnDuration:n.burnDuration,msgDestructTime:n.msgDestructTime,isPinned:n.isPinned,isPrivateChat:n.isPrivateChat,isMsgDestruct:n.isMsgDestruct,attachedInfo:n.attachedInfo,ex:n.ex}},v="",h=a?JSON.stringify(Ve(Be(a))):"";(null==n?void 0:n.conversationType)===exports.SessionType.Group?(p=null!=(d=null==o?void 0:o.groupName)?d:"",v=null!=(g=null==o?void 0:o.faceURL)?g:""):(p=(null==i?void 0:i.remark)||(null==s?void 0:s.nickname)||"",v=null!=(l=null==s?void 0:s.faceURL)?l:"");var m=function(){if((null==a?void 0:a.status)===exports.InternalMessageStatus.MsgStatusHasDeleted)return Promise.resolve(t({conversationID:null==n?void 0:n.conversationID,seq:a.seq,operationID:se()})).then(function(e){e&&(h=JSON.stringify(Ve(e)))})}();return Promise.resolve(m&&m.then?m.then(f):f())}catch(e){return Promise.reject(e)}},We=function(e){var t=e.friendUser;return f({},I(e,ke),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL,attachedInfo:""})},Je=function(e){var t=e.blackUserInfo;return f({},I(e,Le),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL})},Ke=/*#__PURE__*/function(){function e(e){var t=this;this.store=void 0,this.options=void 0,this.expiryListeners=[],this.cleanupTimer=void 0,this.options=e,this.store=new Map,this.options.cleanupInterval>0&&(this.cleanupTimer=setInterval(function(){t.deleteExpired()},this.options.cleanupInterval))}var t=e.prototype;return t.onExpiry=function(e){this.expiryListeners.push(e)},t.triggerExpiry=function(e,t){this.expiryListeners.forEach(function(r){return r(e,t)}),this.delete(e)},t.set=function(e,t){var r=this;this.delete(e);var n=Date.now(),o=null;this.options.ttl>0&&(o=setTimeout(function(){clearTimeout(o),r.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:o,created:n})},t.get=function(e){var t=this.store.get(e);if(t&&Date.now()-t.createdexports.NotificationType.NotificationBegin&&e.contentType(null!=(p=null==h?void 0:h.hasReadCount)?p:0)||v.unreadNum&&v.unreadNum<(null!=(d=null==h?void 0:h.unreadCount)?d:0)){var m,I=f({},g.attachedInfoElem,{groupHasReadInfo:{hasReadCount:v.readNum,unreadCount:v.unreadNum}});i.tryUpdateCachedMessages(t,{clientMsgID:g.clientMsgID,attachedInfo:JSON.stringify(I)});var y=i.getCachedConversation(t),M=JSON.parse(null!=(m=null==y?void 0:y.latestMsg)?m:"{}");M.clientMsgID===g.clientMsgID&&M.seq&&i.instance.messageTrigger.getOneConversationAndTryChange(t,n,{latestMsg:JSON.stringify(f({},M,{attachedInfoElem:I}))}),a.push({clientMsgID:g.clientMsgID,hasReadCount:v.readNum,unreadCount:v.unreadNum,readMembers:[],readUsers:[]}),i.cachedGroupMessageClientMsgIDs.add(g.clientMsgID)}}}a.length>0&&i.instance.triggerEvent({event:exports.CbEvents.OnRecvGroupReadReceipt,data:{conversationID:t,groupMessageReadInfo:a},operationID:n})}):Promise.resolve()}catch(e){return Promise.reject(e)}},this.chearGroupMessageClientMsgIDs=function(){return a.cachedGroupMessageClientMsgIDs.clear()},this.addGroupMessageReadUser=function(e,t){var r=a.cachedGroupMessageReadUser.get(e)||[],n=t.filter(function(e){return!r.some(function(t){return t.userID===e.userID})});a.cachedGroupMessageReadUser.set(e,[].concat(r,n))},this.getGroupMessageReadUser=function(e){var t;return null!=(t=a.cachedGroupMessageReadUser.get(e))?t:[]},this.instance=e};function Xe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var $e=function(e){var t=this,r=this,o=this,i=this,a=this;this.instance=void 0,this.defaultPullNums=10,this.SplitPullMsgNum=100,this.syncedConversationVersion=0,this.syncedConversationVersionID="",this.reset=function(){a.syncedConversationVersion=0,a.syncedConversationVersionID=""},this.syncConversationVersion=function(e){try{return Promise.resolve(t.instance.sendHttpRequest({operationID:e,reqFuncName:C.GetConversationVersion,data:{userID:t.instance.userID,version:t.syncedConversationVersion,versionID:t.syncedConversationVersionID}})).then(function(e){t.syncedConversationVersionID&&t.compareVersionAndTrigger(e),t.syncedConversationVersion=e.version,t.syncedConversationVersionID=e.versionID})}catch(e){return Promise.reject(e)}},this.compareVersionAndTrigger=function(e){var t=e.insert,r=e.update;(null!=t?t:[]).map(function(e){return Promise.resolve()}),(null!=r?r:[]).map(function(e){try{return Promise.resolve(a.instance.messageTrigger.getOneConversationAndTryChange(e.conversationID,"",f({},e))).then(function(){})}catch(e){return Promise.reject(e)}})},this.compareSeqsAndBatchSync=function(e,t){try{for(var n=new Map,o=0,i=Object.entries(e);op&&n.set(u,[p+1,c.maxSeq,c.maxSeqTime]):n.set(u,[0,c.maxSeq,c.maxSeqTime])}return r.syncAndTriggerMsgs(n,t),Promise.resolve()}catch(e){return Promise.reject(e)}},this.isNotification=function(e){return e.startsWith("n_")},this.syncAndTriggerMsgs=function(e,t){try{return s.default.debug("Current sync seqMap",e,e.size),Promise.resolve(function(){if(e.size>0){var r=function(r){return Xe(function(){return Promise.resolve(o.pullMsgBySeqRange(n,t)).then(function(r){return Promise.resolve(o.instance.messageTrigger.triggerConversation(r.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(r.notificationMsgs,t)).then(function(){for(var t,r=l(e);!(t=r()).done;){var n=t.value,i=n[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:i[1],maxSeqTime:i[2]})}})})})},function(t){throw s.default.error("Sync message from server error",t,e),t})},n=new Map,i=0,a=function(e,t){if("function"==typeof e[rt]){var r,n,o,i=function(e){try{for(;!(r=s.next()).done;)if((e=t(r.value))&&e.then){if(!tt(e))return void e.then(i,o||(o=Ze.bind(null,n=new et,2)));e=e.v}n?Ze(n,1,e):n=e}catch(e){Ze(n||(n=new et),2,e)}},s=e[rt]();if(i(),s.return){var a=function(e){try{r.done||s.return()}catch(e){}return e};if(n&&n.then)return n.then(a,function(e){throw a(e)});a()}return n}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],c=0;c=o.SplitPullMsgNum)return Xe(function(){return Promise.resolve(o.pullMsgBySeqRange(n,t)).then(function(e){return Promise.resolve(o.instance.messageTrigger.triggerConversation(e.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(e.notificationMsgs,t)).then(function(){for(var e,t=l(n);!(e=t()).done;){var r=e.value,s=r[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:s[1],maxSeqTime:s[2]})}n=new Map,i=0})})})},function(e){throw s.default.error("Sync message from server error",e,n),e})}()}var c=a[0],p=a[1],d=a[2],g=p-c+1,f=function(){if(g/o.SplitPullMsgNum>1&&o.isNotification(r)){var e=new Map,n=Math.floor(g/o.SplitPullMsgNum),i=c,a=0,u=0;return function(e,t,r){for(var n;;){var o=e();if(tt(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!tt(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!tt(s)){n=2;break}}}var a=new et,u=Ze.bind(null,a,2);return(0===n?o.then(p):1===n?i.then(c):s.then(d)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!tt(s))return void s.then(d).then(void 0,u);if(!(o=e())||tt(o)&&!o.v)return void Ze(a,1,i);if(o.then)return void o.then(p).then(void 0,u);tt(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function p(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):Ze(a,1,i)}function d(){(o=e())?o.then?o.then(p).then(void 0,u):p(o):Ze(a,1,i)}}(function(){return u<=n},function(){return u++},function(){return u===n?e.set(r,[i,p,d]):((a=i+o.SplitPullMsgNum)>p&&(a=p,u=n),e.set(r,[i,a,d])),Xe(function(){return Promise.resolve(o.pullMsgBySeqRange(e,t)).then(function(r){return Promise.resolve(o.instance.messageTrigger.triggerConversation(r.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(r.notificationMsgs,t)).then(function(){for(var t,r=l(e);!(t=r()).done;){var n=t.value,s=n[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:s[1],maxSeqTime:s[2]})}i=a+1})})})},function(t){throw s.default.error("Sync message from server error",t,e),t})})}}();return f&&f.then?f.then(u):u()});return a&&a.then?a.then(r):r()}s.default.debug("Nothing to sync")}())}catch(e){return Promise.reject(e)}},this.pullMsgBySeqRange=function(e,t){try{var r=[].concat(e.entries()).map(function(e){var t=e[1];return{conversationID:e[0],begin:t[0],end:t[1],num:i.defaultPullNums}});s.default.debug("PullMsgBySeqRange with opid: ",t,"seqRanges: ",r);var o=n.PbCoder.PullMessageBySeqsReq.encode({userID:i.instance.userID,seqRanges:r,order:n.SdkWsProto.PullOrder.PullOrderAsc}).finish();return Promise.resolve(i.instance.sendReqWaitResp({operationID:t,data:o,reqIdentifier:exports.ReqIdentifier.PullMsgByRange}))}catch(e){return Promise.reject(e)}},this.instance=e};function Ze(e,t,r){if(!e.s){if(r instanceof et){if(!r.s)return void(r.o=Ze.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Ze.bind(null,e,t),Ze.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var et=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Ze(n,1,i(this.v))}catch(e){Ze(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ze(n,1,t?t(o):o):r?Ze(n,1,r(o)):Ze(n,2,o)}catch(e){Ze(n,2,e)}},n},e}();function tt(e){return e instanceof et&&1&e.s}var rt="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator",nt=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.uint8ArrayToWordArray=function(e){for(var t=[],r=0,n=e.length;r>24&255,t>>16&255,t>>8&255,255&t],u=0;u<4&&on.version&&(n=s),t.cachedVersionKeys.set(ct(e.conversationID,s.version),s)}return t.cachedVersionKeys.set(pt(e.conversationID),n),[i,n]},i=null,a=0,u=function(e,t,r){for(var n;;){var o=e();if(ut(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!ut(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!ut(s)){n=2;break}}}var a=new at,u=st.bind(null,a,2);return(0===n?o.then(p):1===n?i.then(c):s.then(d)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!ut(s))return void s.then(d).then(void 0,u);if(!(o=e())||ut(o)&&!o.v)return void st(a,1,i);if(o.then)return void o.then(p).then(void 0,u);ut(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function p(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):st(a,1,i)}function d(){(o=e())?o.then?o.then(p).then(void 0,u):p(o):st(a,1,i)}}(function(){return!n&&a<10},function(){return a++},function(){var o=ot(function(){return Promise.resolve(t.ctx.sendHttpRequest({reqFuncName:C.GetEncryptionKey,data:f({},e),operationID:r})).then(function(e){i=e.versionKeyList,n=1})},function(t){return s.default.error("getEncryptionKeyFromServer error",t,"conversationID: ",e.conversationID),Promise.resolve(new Promise(function(e){return setTimeout(e,1e3)})).then(function(){})});if(o&&o.then)return o.then(function(){})});return Promise.resolve(u&&u.then?u.then(o):o())}catch(e){return Promise.reject(e)}},this.getMaxVersionKey=function(e,t){try{var n=r.cachedVersionKeys.get(pt(e));return n?Promise.resolve(n):Promise.resolve(r.getEncryptionKeyFromServer({conversationID:e,keyVersion:0},t)).then(function(e){return e[1]})}catch(e){return Promise.reject(e)}},this.getKeyByMessageVersion=function(e,t){try{var r=n.cachedVersionKeys.get(ct(e.conversationID,e.keyVersion));return r?Promise.resolve(r):Promise.resolve(n.getEncryptionKeyFromServer(e,t)).then(function(t){var r=t[0];if(!r.length)throw s.default.error("version key not found, verion: ",e.keyVersion," conversationID: ",e.conversationID),new Error("getKeyByMessageVersion failed");return r[0]})}catch(e){return Promise.reject(e)}},this.encryption=function(e,t,r){try{return o.ctx.serverConfig.isEncryption?Promise.resolve(o.getMaxVersionKey(e,r)).then(function(e){t.content=o.aesEncryptor.encryption(t.content,e.key),t.keyVersion=e.version}):Promise.resolve()}catch(e){return Promise.reject(e)}},this.decryption=function(e,t,r){try{if(!t||0===t.keyVersion)return Promise.resolve();if((t.sessionType===exports.SessionType.Single||t.sessionType===exports.SessionType.Notification)&&t.recvID!==i.ctx.userID&&t.sendID!==i.ctx.userID)return s.default.warn("maybe message come from app manager",t),Promise.resolve();if(t.contentType===exports.MessageType.RevokeMessage||t.status===exports.InternalMessageStatus.MsgStatusHasDeleted)return s.default.debug("message is revoke notification or has deleted",t),Promise.resolve();var n=ot(function(){return Promise.resolve(i.getMaxVersionKey(e,r)).then(function(e){t.content=i.aesEncryptor.decryption(t.content,e.key)})},function(e){s.default.warn("decryption with error: ",e,"msgData: ",t)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this.ctx=e};function st(e,t,r){if(!e.s){if(r instanceof at){if(!r.s)return void(r.o=st.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(st.bind(null,e,t),st.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var at=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{st(n,1,i(this.v))}catch(e){st(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?st(n,1,t?t(o):o):r?st(n,1,r(o)):st(n,2,o)}catch(e){st(n,2,e)}},n},e}();function ut(e){return e instanceof at&&1&e.s}function ct(e,t){return e+"_v_"+t}function pt(e){return e+"_v_max"}var dt="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function gt(e,t,r){if(!e.s){if(r instanceof lt){if(!r.s)return void(r.o=gt.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(gt.bind(null,e,t),gt.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var lt=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{gt(n,1,i(this.v))}catch(e){gt(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?gt(n,1,t?t(o):o):r?gt(n,1,r(o)):gt(n,2,o)}catch(e){gt(n,2,e)}},n},e}();function ft(e){return e instanceof lt&&1&e.s}var vt=[exports.InternalMessageStatus.MsgStatusHasDeleted,exports.InternalMessageStatus.MsgStatusFiltered];function ht(e,t,r){if("function"==typeof e[dt]){var n,o,i,s=function(e){try{for(;!((n=a.next()).done||r&&r());)if((e=t(n.value))&&e.then){if(!ft(e))return void e.then(s,i||(i=gt.bind(null,o=new lt,2)));e=e.v}o?gt(o,1,e):o=e}catch(e){gt(o||(o=new lt),2,e)}},a=e[dt]();if(s(),a.return){var u=function(e){try{n.done||a.return()}catch(e){}return e};if(o&&o.then)return o.then(u,function(e){throw u(e)});u()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],p=0;p0&&g.instance.triggerEvent({event:exports.CbEvents.OnRecvGroupReadReceipt,data:{conversationID:r,groupMessageReadInfo:i},operationID:t})}var i=[],s=ht(e[1],function(e){var n;function s(){var n;if(u&&p){var o=(null==(n=a.readUsers)?void 0:n.map(function(e){return e.userID}))||[],s=JSON.parse(u.attachedInfo||"{}");return s.groupHasReadInfo={hasReadCount:a.hasReadCount,unreadCount:a.unreadCount},g.cache.tryUpdateCachedMessages(r,{clientMsgID:u.clientMsgID,attachedInfo:JSON.stringify(s),isRead:!!o.includes(g.instance.userID)||u.isRead}),c&&g.getOneConversationAndTryChange(r,t,{latestMsg:JSON.stringify(f({},d,{attachedInfoElem:s}))}),Promise.resolve(g.instance.groupTrigger.cache.getGroupMembersMayNotInGroup({groupID:p.groupID,userIDList:o,operationID:t})).then(function(t){i.push({clientMsgID:e,hasReadCount:a.hasReadCount,unreadCount:a.unreadCount,readMembers:t,readUsers:[]})})}}var a=o[e];if(a){var u,c=!1,p=g.cache.getCachedConversation(r),d=JSON.parse(null!=(n=null==p?void 0:p.latestMsg)?n:"{}"),l=function(){if(d.clientMsgID===e&&d.seq)return c=!0,Promise.resolve(g.getMessageWithCacheBySeqs(r,[d.seq],t)).then(function(e){u=e.messages[0]});u=g.cache.getCachedMessageByClientMsgIDs(r,[e])[0]}();return l&&l.then?l.then(s):s()}});return s&&s.then?s.then(n):n()});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this.triggerNotification=function(e,t){try{for(var r=0,n=Object.entries(e);rexports.NotificationType.FriendNotificationBegin&&e.contentTypeexports.NotificationType.UserNotificationBegin&&e.contentTypeexports.NotificationType.GroupNotificationBegin&&e.contentTypeexports.NotificationType.SignalingNotificationBegin&&e.contentType0){if(!n)return void a.map(function(e){m.cache.tryUpdateCachedMessages(ue(e),e)});m.instance.triggerEvent({event:exports.CbEvents.OnRecvNewMessages,data:a.map(Ve),operationID:t})}};if(0===Object.keys(e).length)return Promise.resolve();s.default.debug("Trigger conversation",e);var n=!0;m.triggeredConversationEvent.has(t)&&(m.triggeredConversationEvent.delete(t),n=!1);var o=!1,i=m.cache.getTotalUnreadCount(),a=[],u=ht(Object.entries(e),function(e){var r=e[0],u=e[1].Msgs.map(function(e){var u,c,p,d,g=!m.cache.getCachedMaxReadSeq(r),l=e.sendID===m.instance.userID,f=pe(e.options,exports.MessageOptionsKey.IsUnreadCount)&&!l,v=pe(e.options,exports.MessageOptionsKey.IsConversationUpdate),h=pe(e.options,exports.MessageOptionsKey.IsNotPrivate);if(e.clientMsgID&&r){var I=Be(e),y=Ve(I);if(y.attachedInfoElem=e.attachedInfo?JSON.parse(e.attachedInfo):{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},e.status!==exports.InternalMessageStatus.MsgStatusHasDeleted){e.contentType===exports.InternalContentType.Typing&&m.triggerTyping(y),y.status=exports.InternalMessageStatus.MsgStatusSendSuccess,I.status=exports.InternalMessageStatus.MsgStatusSendSuccess,g&&m.cache.addCachedMaxReadSeq(r,{hasReadSeq:l?e.seq:e.seq-1,maxSeq:e.seq,maxSeqTime:e.sendTime}),h||(y.attachedInfoElem.isPrivateChat=!0),v&&(i+=f?1:0,m.cache.updateCachedMaxReadSeq(r,{maxSeqTime:y.sendTime}),n&&m.getOneConversationAndTryChange(r,t,{latestMsg:JSON.stringify(y),latestMsgSendTime:y.sendTime},f,g),a.push(I),m.cache.addMessagesToCache(r,[I]));var M=null!=(u=null==(c=m.cache.getCachedMaxReadSeq(r))?void 0:c.maxSeq)?u:0,D=null!=(p=null==(d=m.cache.getCachedMaxReadSeq(r))?void 0:d.hasReadSeq)?p:0;s.default.debug("currentMaxSeq",M,"currentHasReadSeq",D),y.seq>M&&(o=g||!m.cache.isNotNotifyConversation(r),m.cache.updateCachedMaxReadSeq(r,{maxSeq:M+1,maxSeqTime:y.sendTime}),l&&(m.cache.updateCachedMaxReadSeq(r,{hasReadSeq:D+1}),m.cache.tryUpdateCachedMessages(r,{clientMsgID:y.clientMsgID,seq:y.seq})))}}});return Promise.resolve(Promise.all(u)).then(function(){})});return Promise.resolve(u&&u.then?u.then(r):r())}catch(e){return Promise.reject(e)}},this.instance=e,this.cache=new Ye(e),this.encryptor=new it(e),this.syncer=new $e(e),this.typingManager=new ze(e)},It=/*#__PURE__*/function(){function e(e){var t=this,r=this,n=this,o=this,i=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=function(e,t){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:C.GetFullGroupMemberUserIDs,data:{groupID:e,idHash:0},operationID:t})).then(function(t){r.cachedGroupMembersID.set(e,t.userIDs)})}catch(e){return Promise.reject(e)}},this.getGroupInfosWithCache=function(e,t){try{var r=[],o=[];return e.forEach(function(e){var t=n.cachedGroups.get(e);t?r.push(t):o.push(e)}),o.length?Promise.resolve(n.instance.sendHttpRequest({reqFuncName:exports.RequestApi.GetSpecifiedGroupsInfo,data:{groupIDs:o},operationID:t})).then(function(e){var t=e.groupInfos;return t&&t.forEach(function(e){return n.cachedGroups.set(e.groupID,e)}),[].concat(r,null!=t?t:[])}):Promise.resolve(r)}catch(e){return Promise.reject(e)}},this.getGroupMembersWithCache=function(e){var t=e.groupID,r=e.userIDList,n=e.operationID;try{var i,s,a=null!=(i=o.cachedGroupMembers.get(t))?i:[],u=function(){if(null!=r&&r.length){var e=[],i=[];return r.forEach(function(t){var r=a.find(function(e){return e.userID===t});r?i.push(r):e.push(t)}),e.length?Promise.resolve(o.instance.sendHttpRequest({reqFuncName:exports.RequestApi.GetSpecifiedGroupMembersInfo,data:{groupID:t,userIDs:e},operationID:n})).then(function(e){var r=e.members;r&&o.cachedGroupMembers.set(t,[].concat(a,r));var n=[].concat(i,null!=r?r:[]);return s=1,n}):(s=1,i)}}();return Promise.resolve(u&&u.then?u.then(function(e){return s?e:a}):s?u:a)}catch(e){return Promise.reject(e)}},this.getGroupMembersMayNotInGroup=function(e){try{return Promise.resolve(i.getGroupMembersWithCache(e)).then(function(t){var r=e.userIDList.filter(function(e){return!t.find(function(t){return t.userID===e})}),n=function(){if(r.length)return Promise.resolve(i.instance.getUsersInfo(r,operationID)).then(function(e){t.push.apply(t,e.data.map(function(e){return{userID:e.userID,nickname:e.nickname,faceURL:e.faceURL}}))})}();return n&&n.then?n.then(function(){return t}):t})}catch(e){return Promise.reject(e)}},this.updateCachedGroups=function(e){e.map(function(e){t.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=function(e){var r,n=e[0].groupID,o=null!=(r=t.cachedGroupMembers.get(n))?r:[];t.cachedGroupMembers.set(n,[].concat(o.filter(function(t){return!e.find(function(e){return e.userID===t.userID})}),e));var i=t.instance.messageTrigger.cache.getAllCachedConversations().find(function(t){return t.groupID===e[0].groupID}),s=JSON.parse((null==i?void 0:i.latestMsg)||"{}"),a=e.find(function(e){return e.userID===s.sendID&&e.nickname!==s.senderNickname});i&&a&&t.instance.messageTrigger.getOneConversationAndTryChange(i.conversationID,"",{latestMsg:JSON.stringify(f({},s,{senderNickname:a.nickname}))})},this.clearCachedGroupMembers=function(e){t.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=function(e){return t.cachedGroupMembersID.has(e)},this.getCachedGroupMembersID=function(e){var r;return null!=(r=t.cachedGroupMembersID.get(e))?r:[]},this.tryAddCachedGroupMembersID=function(e,r){if(t.cachedGroupMembersID.has(e)){var n,o=null!=(n=t.cachedGroupMembersID.get(e))?n:[];t.cachedGroupMembersID.set(e,[].concat(o,r))}},this.tryDeleteCachedGroupMembersID=function(e,r){if(t.cachedGroupMembersID.has(e)){var n,o=null!=(n=t.cachedGroupMembersID.get(e))?n:[];t.cachedGroupMembersID.set(e,o.filter(function(e){return!r.includes(e)}))}},this.instance=e}return e.prototype.clear=function(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()},e}(),yt=/*#__PURE__*/function(){function e(e){var t=this,r=this,n=this,o=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=function(e){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:C.GetGroupVersion,data:{userID:r.instance.userID,version:r.syncedGroupsVersion,versionID:r.syncedGroupsVersionID},operationID:e})).then(function(t){r.syncedGroupsVersionID&&r.compareGroupVersionAndTrigger(t,e),r.syncedGroupsVersion=t.version,r.syncedGroupsVersionID=t.versionID})}catch(e){return Promise.reject(e)}},this.syncGroupInfoAndMemberVersion=function(e){try{var t=function(){if(r.length)return Promise.resolve(n.instance.sendHttpRequest({reqFuncName:C.GetGroupMemberVersion,data:{userID:n.instance.userID,reqList:r},operationID:e})).then(function(t){var r=t.respList;Object.keys(n.syncedGroupMemberVersion).length>0&&n.compareGroupMemberVersionAndTrigger(r,e),n.syncedGroupMemberVersion=r;for(var o=0,i=Object.entries(r);o0},0,function(){var e=t.queue.shift()[0],r=function(t,r){try{var n=Promise.resolve(e()).then(function(){})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){s.default.error("Error executing task:",e)});if(r&&r.then)return r.then(function(){})});return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},e}();function jt(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Bt=((kt={})[exports.MessageType.TextMessage]="textElem",kt[exports.MessageType.AtTextMessage]="atTextElem",kt[exports.MessageType.LocationMessage]="locationElem",kt[exports.MessageType.CustomMessage]="customElem",kt[exports.MessageType.MergeMessage]="mergeElem",kt[exports.MessageType.QuoteMessage]="quoteElem",kt[exports.MessageType.CardMessage]="cardElem",kt[exports.MessageType.FaceMessage]="faceElem",kt[exports.MessageType.PictureMessage]="pictureElem",kt[exports.MessageType.VoiceMessage]="soundElem",kt[exports.MessageType.VideoMessage]="videoElem",kt[exports.MessageType.FileMessage]="fileElem",kt),Vt=[exports.MessageType.PictureMessage,exports.MessageType.VoiceMessage,exports.MessageType.VideoMessage,exports.MessageType.FileMessage],_t=/*#__PURE__*/function(e){function t(t,r){var n;return(n=e.call(this,r)||this).status=void 0,n.name="HttpError",n.status=t,n}return h(t,e),t}(/*#__PURE__*/M(Error));function Ht(e,t,r){if(!e.s){if(r instanceof Wt){if(!r.s)return void(r.o=Ht.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Ht.bind(null,e,t),Ht.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Wt=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Ht(n,1,i(this.v))}catch(e){Ht(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ht(n,1,t?t(o):o):r?Ht(n,1,r(o)):Ht(n,2,o)}catch(e){Ht(n,2,e)}},n},e}();function Jt(e){return e instanceof Wt&&1&e.s}function Kt(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Qt=[C.GetActiveConversations,C.GetDesignatedConversation];function zt(e,t,r){if(!e.s){if(r instanceof Xt){if(!r.s)return void(r.o=zt.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(zt.bind(null,e,t),zt.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Yt=/*#__PURE__*/function(e){function t(){var t,o;return(t=e.call(this)||this).userID=void 0,t.platform=void 0,t.token=void 0,t.apiAddr=void 0,t.loginStatus=exports.LoginStatus.Logout,t.isReconnected=!1,t.serverConfig={isEncryption:!1},t.connectState="disconnected",t.wsManager=void 0,t.messageTrigger=void 0,t.userTrigger=void 0,t.groupTrigger=void 0,t.relationTrigger=void 0,t.businessTrigger=void 0,t.signalingTrigger=void 0,t.requestMap=new Map,t.generateHttpHeader=function(e,r){var n={"Content-Type":"application/json",token:t.token,operationID:r,reqFuncName:e};return Qt.includes(e)&&(n["Content-Type"]="application/x-protobuf"),n},t.sendHttpRequest=function(e){try{var r;return Promise.resolve(function(e,t){void 0===t&&(t={});var r=e.url,n=e.data,o=e.headers,i=e.platform,s=e.method,a=void 0===s?"POST":s,u=t.retries,c=void 0===u?3:u,p=t.baseDelayMs,d=void 0===p?300:p,g=t.maxDelayMs,l=void 0===g?3e3:g;return function(t){try{var s=0;return Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(Jt(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Jt(i)){n=1;break}i=i.s}}var s=new Wt,a=Ht.bind(null,s,2);return(0===n?o.then(c):1===n?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):Ht(s,1,i)})).then(void 0,a),s;function u(t){i=t;do{if(!(o=e())||Jt(o)&&!o.v)return void Ht(s,1,i);if(o.then)return void o.then(c).then(void 0,a);Jt(i=r())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(u).then(void 0,a):u(i):Ht(s,1,i)}}(function(){return!t},0,function(){return function(s,u){try{var c=Promise.resolve("web"===i?function(e){var t=e.url,r=e.data,n=e.headers,o=e.method,i=void 0===o?"POST":o;try{return Promise.resolve(fetch(t,{method:i,headers:f({},n),body:r instanceof Uint8Array?r:JSON.stringify(r)}).then(function(e){if(e.ok)return e.json();throw new _t(e.status,e.statusText||"HTTP_"+e.status)}).then(function(e){if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))}catch(e){return Promise.reject(e)}}(e):new Promise(function(e,t){var s=function(e){return"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null}(i);s?s({url:r,data:n instanceof Uint8Array?Uint8Array.from(n).buffer:n,method:a,header:f({"Content-Type":"application/json"},o),success:function(r){200===r.statusCode&&0===r.data.errCode?e(r.data.data):t({statusCode:r.statusCode,data:r.data})},fail:function(e){t(e)}}):t(new Error("Request is not supported"))})).then(function(e){return t=1,e})}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(++s>c||!function(e){if(!e)return!1;if(e instanceof _t)return e.status>=500;if("object"==typeof e&&"number"==typeof e.statusCode)return e.statusCode>=500;var t=String((null==e?void 0:e.message)||e||"").toLowerCase();return!!(t.includes("network")||t.includes("timeout")||t.includes("failed to fetch")||t.includes("request:fail"))}(e))throw e;var t,r=Math.min(d*Math.pow(2,s-1),l),n=Math.floor(150*Math.random());return Promise.resolve((t=r+n,new Promise(function(e){return setTimeout(e,t)}))).then(function(){})})}))}catch(e){return Promise.reject(e)}}()}({url:""+t.apiAddr+(e.replaceURL||k[e.reqFuncName]),data:e.data,headers:t.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(r=t.wsManager)?void 0:r.platformNamespace)||"web"}))}catch(e){return Promise.reject(e)}},t.handleWsConnected=function(e,r){try{var n=function(){if(0===e.errCode){t.connectState="connected",t.loginStatus=exports.LoginStatus.Logged,t.triggerEvent({event:exports.CbEvents.OnConnectSuccess}),t.triggerEvent({event:exports.CbEvents.OnSyncServerStart});var n=[t.messageTrigger.sync(r),t.relationTrigger.sync(r),t.groupTrigger.sync(r),t.userTrigger.sync(r)],o=Kt(function(){return Promise.resolve(Promise.all(n)).then(function(){t.triggerEvent({event:exports.CbEvents.OnSyncServerFinish})})},function(e){s.default.error(e),t.triggerEvent({event:exports.CbEvents.OnSyncServerFailed,errCode:e.errCode||exports.ErrorCode.SdkInternalError,errMsg:e.message||"Internal Error"})});if(o&&o.then)return o.then(function(){})}else{t.triggerEvent({event:exports.CbEvents.OnConnectFailed,errCode:e.errCode,errMsg:e.errMsg,operationID:r});var i=ie[e.errCode];i&&t.triggerEvent({event:i,errCode:e.errCode,errMsg:e.errMsg,operationID:r}),t.connectState="disconnected",t.loginStatus=exports.LoginStatus.Logout}}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},t.handleMessage=function(e,r){try{var n=function(){if("string"!=typeof e){var n=function(){var r,n,o=(r=e,n=new DataView(r),qe.getString(n,0,r.byteLength,"UTF-8")),i=JSON.parse(o);t.handleGeneralWsResp(i)},o=function(){if(!(e instanceof ArrayBuffer))return Promise.resolve(e.arrayBuffer()).then(function(t){e=t})}();return o&&o.then?o.then(n):n()}var i=JSON.parse(e);t.handleWsConnected(i,r)}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},t.handleGeneralWsResp=function(e){var r=ge(e.data,e.reqIdentifier);if(e.reqIdentifier===exports.ReqIdentifier.PushMsg&&r)return t.messageTrigger.triggerConversation(r.msgs,e.operationID),void t.messageTrigger.triggerNotification(r.notificationMsgs,e.operationID);if(e.reqIdentifier!==exports.ReqIdentifier.WsSubUserOnlineStatus||e.msgIncr||t.userTrigger.onlineSub.userOnlineStateChange(r),e.reqIdentifier===exports.ReqIdentifier.WSServerConfigMsg&&r&&(t.serverConfig=r),e.reqIdentifier===exports.ReqIdentifier.KickOnlineMsg)return t.triggerEvent({event:exports.CbEvents.OnKickedOffline,operationID:e.operationID}),void t.reset();var n=t.requestMap.get(e.msgIncr);n&&(0===e.errCode?n.resolve(r):n.reject(new ve(e.errCode,e.errMsg)),t.requestMap.delete(e.msgIncr))},t.handleReconnecting=function(){t.connectState="reconnecting",t.triggerEvent({event:exports.CbEvents.OnConnecting})},t.handleReconnectFailed=function(){t.connectState="disconnected",t.triggerEvent({event:exports.CbEvents.OnConnectFailed,errCode:exports.ErrorCode.NetworkError,errMsg:"network error"}),t.cancelMessageTasks()},t.handleReconnectSuccess=function(){t.isReconnected=!0,t.messageTrigger.cache.chearGroupMessageClientMsgIDs()},t.sendReqWaitResp=function(e){var n=e.data,o=e.reqIdentifier,i=e.operationID;if("connected"!==t.connectState)throw new ve(exports.ErrorCode.NetworkError,"network error, ws not connected");var s=se();return new Promise(function(e,a){var u;t.requestMap.set(s,{resolve:e,reject:a}),null==(u=t.wsManager)||u.sendMessage({reqIdentifier:o,msgIncr:s,sendID:t.userID,operationID:i,data:r.encode(n.buffer)})})},t.triggerEvent=function(e){var r=e.event,n=e.data,o=void 0===n?null:n,i=e.errCode,a=void 0===i?0:i,u=e.errMsg,c=void 0===u?"":u,p=e.operationID,d=void 0===p?"":p;t.loginStatus!==exports.LoginStatus.Logout&&(s.default.debug("%cSDK =>%c [OperationID:"+d+"] (event) trigger "+r+" with data "+JSON.stringify(o)+" errCode "+a+" errMsg "+c,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),t.emit(r,{event:r,data:o,errCode:a,errMsg:c,operationID:d}))},t.login=function(e,r){try{return Promise.resolve(he(exports.LoginStatus.Logged,exports.RequestApi.Login,r,function(){try{var n,o=e.userID,i=e.token,a=e.wsAddr,u=e.apiAddr,c=e.platformID;if(t.wsManager)throw new ve(exports.ErrorCode.LoginRepeatError,"login repeat");return s.default.setLevel(null!=(n=e.logLevel)?n:exports.LogLevel.Debug),t.userID=o,t.token=i,t.apiAddr=u,t.platform=c,t.wsManager=new Oe(a,{sendID:o,token:i,platformID:c,operationID:r,isBackground:!1,isMsgResp:!0,sdkType:"js"},t.handleMessage,t.handleReconnectFailed,t.handleReconnecting,t.handleReconnectFailed,t.handleReconnectSuccess),t.connectState="connecting",t.loginStatus=exports.LoginStatus.Logging,t.triggerEvent({event:exports.CbEvents.OnConnecting,operationID:r}),Promise.resolve(Kt(function(){return Promise.resolve(t.wsManager.connect()).then(function(){})},function(e){throw t.triggerEvent({event:exports.CbEvents.OnConnectFailed,errCode:exports.ErrorCode.NetworkError,errMsg:e.message||"network error",operationID:r}),t.connectState="disconnected",t.loginStatus=exports.LoginStatus.Logout,t.wsManager.close(),new ve(exports.ErrorCode.NetworkError,e.message||"network error")}))}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},t.getLoginStatus=function(e){return he(exports.LoginStatus.Logged,exports.RequestApi.GetLoginStatus,e,function(){try{var e;return null==(e=t.wsManager)||e.sendPing(),Promise.resolve(t.loginStatus)}catch(e){return Promise.reject(e)}})},t.forceReconnect=function(e){return he(t.loginStatus,exports.RequestApi.ForceReconnect,e,function(){try{var e;return null==(e=t.wsManager)||e.forceReconnect(!0),Promise.resolve()}catch(e){return Promise.reject(e)}})},t.logout=function(e){return he(t.loginStatus,exports.RequestApi.Logout,e,function(){try{return t.reset(),Promise.resolve()}catch(e){return Promise.reject(e)}})},t.internalUploadFile=function(e,r,n){return Promise.resolve(Kt(function(){var o=t.userID+"/"+e.name,i=function(e){var t,r,n=null!=(t=null==(r=e.split(".").pop())?void 0:r.toLowerCase())?t:"";return x[n]||"application/octet-stream"}(e.name),s={operationID:r,token:t.token};return Promise.resolve(function(e,t,r){return fetch(e+"/object/part_size",{method:"POST",headers:f({},r),body:JSON.stringify({size:t})}).then(T)}(t.apiAddr,e.size,s)).then(function(r){var u=r.size;function c(){var r=g.join(","),c=new a.default;return c.append(r),Promise.resolve(function(e,t,r){return fetch(e+"/object/initiate_multipart_upload",{method:"POST",headers:f({},r),body:JSON.stringify(t)}).then(T)}(t.apiAddr,{hash:c.end(),size:e.size,partSize:u,maxParts:-1,cause:"",name:o,contentType:i},s)).then(function(r){var a=r.url,u=r.upload;if(c.destroy(),a)return null==n||n(100),{url:a};var p=u.sign.parts,l=u.sign.query,v=u.sign.header,h=e.size,m=0;null==n||n(0);for(var I=0,y=[],M=function(){try{var t=Zt(function(){return I=3)throw new Error("Failed to upload chunk "+(t+1)+" after 3 attempts: "+e.message);var r,n=400*Math.pow(2,y-1),o=Math.floor(150*Math.random());return Promise.resolve((r=n+o,new Promise(function(e){return setTimeout(e,r)}))).then(function(){})})}))}catch(e){return Promise.reject(e)}}(t)).then(function(){})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},D=Math.min(4,p.length),S=0;Sg?d:g,count:n-t.length,conversationID:o,operationID:i,fetchedMessages:p})}return p}):Promise.resolve(a)}catch(e){return Promise.reject(e)}};return{createTextMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateTextMessage,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.TextMessage);return r.textElem={content:t},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createTextAtMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateTextAtMessage,r,function(){try{var r;if(!t.text)throw new ve(exports.ErrorCode.ArgsError,"text cannot be empty");if(t.atUserIDList.length>10)throw new ve(exports.ErrorCode.ArgsError,"atUserIDList length must be less than 10");var n,o=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.AtTextMessage);return(null==(r=t.message)?void 0:r.contentType)===exports.MessageType.QuoteMessage&&(t.message.contentType=exports.MessageType.TextMessage,t.message.textElem={content:null==(n=t.message.quoteElem)?void 0:n.text}),o.atTextElem={text:t.text,atUserList:t.atUserIDList,atUsersInfo:t.atUsersInfo,quoteMessage:t.message},Promise.resolve(o)}catch(e){return Promise.reject(e)}})},createLocationMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateLocationMessage,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.LocationMessage);return r.locationElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createCustomMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateCustomMessage,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.CustomMessage);return r.customElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createQuoteMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateQuoteMessage,r,function(){try{var r,n=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.QuoteMessage),o=JSON.parse(t.message);return o.contentType===exports.MessageType.QuoteMessage&&(o.contentType=exports.MessageType.TextMessage,o.textElem={content:null==(r=o.quoteElem)?void 0:r.text}),n.quoteElem={text:t.text,quoteMessage:o},Promise.resolve(n)}catch(e){return Promise.reject(e)}})},createCardMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateCardMessage,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.CardMessage);return r.cardElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByURL:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateImageMessageByURL,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.PictureMessage);return r.pictureElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByFile:function(r,n){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.CreateImageMessageByFile,n,function(){try{var n=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.PictureMessage);return t.set(r.sourcePicture.uuid,r.file),delete r.file,n.pictureElem=f({},r),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createSoundMessageByURL:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateSoundMessageByURL,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.VoiceMessage);return r.soundElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createSoundMessageByFile:function(r,n){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.CreateSoundMessageByFile,n,function(){try{var n=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.VoiceMessage);return t.set(r.uuid,r.file),delete r.file,n.soundElem=f({},r),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createVideoMessageByURL:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateVideoMessageByURL,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.VideoMessage);return r.videoElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createVideoMessageByFile:function(r,n){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.CreateVideoMessageByFile,n,function(){try{var n=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.VideoMessage);return t.set(r.videoUUID,r.videoFile),t.set(r.snapshotUUID,r.snapshotFile),delete r.videoFile,delete r.snapshotFile,n.videoElem=f({},r),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createFileMessageByURL:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateFileMessageByURL,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.FileMessage);return r.fileElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFileMessageByFile:function(r,n){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.CreateFileMessageByFile,n,function(){try{var n=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.FileMessage);return t.set(r.uuid,r.file),delete r.file,n.fileElem=f({},r),Promise.resolve(n)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createMergerMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateMergerMessage,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.MergeMessage);return r.mergeElem={title:t.title,abstractList:t.summaryList,multiMessage:t.messageList,messageEntityList:[]},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFaceMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateFaceMessage,r,function(){try{var r=le(e,exports.MsgFrom.UserMsgType,exports.MessageType.FaceMessage);return r.faceElem=f({},t),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createForwardMessage:function(t,r){return he(e.loginStatus,exports.RequestApi.CreateForwardMessage,r,function(){try{if(t.status!==exports.MessageStatus.Succeed)throw new ve(exports.ErrorCode.ArgsError,"Only successfully sent messages can be forwarded");var r=le(e,exports.MsgFrom.UserMsgType,t.contentType);return Promise.resolve(f({},t,r,{seq:0,status:exports.MessageStatus.Sending}))}catch(e){return Promise.reject(e)}})},sendMessage:function(i,s){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.SendMessage,s,function(){var a=function(){try{var r=f({},i,{message:f({},i.message)}),o=r.message,a=r.recvID,u=r.groupID,c=r.isOnlineOnly,p=r.offlinePushInfo,d=void 0===p?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:p;void 0===d.signalInfo&&(d.signalInfo="");var g=Bt[o.contentType];if(!g)throw new ve(exports.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");o.recvID=a,o.groupID=u,o.sessionType=u?exports.SessionType.Group:exports.SessionType.Single;var l={};c&&Object.values(exports.MessageOptionsKey).forEach(function(e){return l[e]=!1});var v=ue(o),h=!1;return Promise.resolve(e.messageTrigger.getOneConversationAndTryChange(v,s)).then(function(r){function i(){function i(i){function c(i){function c(i){function c(i){function c(t){var i,c,p=JSON.stringify(o[g]),f={sendID:e.userID,recvID:a||"",groupID:u||"",clientMsgID:o.clientMsgID,serverMsgID:o.serverMsgID||"",senderPlatformID:e.platform,senderNickname:o.senderNickname,senderFaceURL:o.senderFaceUrl,sessionType:o.sessionType,msgFrom:o.msgFrom,contentType:o.contentType,content:we(p),seq:o.seq,sendTime:0,createTime:o.createTime,status:o.status,isRead:!1,options:l,offlinePushInfo:d,atUserIDList:null!=(i=null==(c=o.atTextElem)?void 0:c.atUserList)?i:[],attachedInfo:o.attachedInfoElem?JSON.stringify(o.attachedInfoElem):"",ex:o.ex||"",dstUserIDs:[],keyVersion:0};return Promise.resolve(e.messageTrigger.encryptor.encryption(v,f,s)).then(function(){var t=n.PbCoder.MsgData.encode(f).finish();return jt(function(){return Promise.resolve(e.sendReqWaitResp({data:t,operationID:s,reqIdentifier:exports.ReqIdentifier.SendMsg})).then(function(t){var n=t.serverMsgID,i=t.sendTime;return o.sendTime=i,o.serverMsgID=n,o.status=exports.MessageStatus.Succeed,e.messageTrigger.setTriggeredConversationEvent(s),e.messageTrigger.cache.updateCachedMaxReadSeq(r.conversationID,{maxSeqTime:i}),e.messageTrigger.getOneConversationAndTryChange(v,s,{latestMsg:JSON.stringify(o),latestMsgSendTime:i}),o})},function(t){throw o.status=exports.MessageStatus.Failed,e.messageTrigger.getOneConversationAndTryChange(v,s,{latestMsg:JSON.stringify(o)}),t})})}var p=function(){if(o.contentType===exports.MessageType.FileMessage){var r,n=t.get(null==(r=o.fileElem)?void 0:r.uuid);if(!n)throw new ve(exports.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(e.internalUploadFile(n,s,function(t){return e.triggerEvent({event:exports.CbEvents.OnProgress,data:{progress:t,clientMsgID:o.clientMsgID},operationID:s})})).then(function(e){var r,n=e.url,i=void 0===n?"":n,s=e.error;if(t.delete(null==(r=o.fileElem)?void 0:r.uuid),s)throw new ve(exports.ErrorCode.NetworkError,"Upload file failed");o.fileElem.sourceUrl=i})}}();return p&&p.then?p.then(c):c()}var p=function(){if(o.contentType===exports.MessageType.VideoMessage){var r,n,i=t.get(null==(r=o.videoElem)?void 0:r.videoUUID),a=t.get(null==(n=o.videoElem)?void 0:n.snapshotUUID);if(!i||!a)throw new ve(exports.ErrorCode.ArgsError,"Can not find target file");var u=0,c=0,p=i.size,d=a.size,g=p+d,l=function(){e.triggerEvent({event:exports.CbEvents.OnProgress,data:{progress:(u*p+c*d)/g,clientMsgID:o.clientMsgID},operationID:s})};return Promise.resolve(Promise.all([e.internalUploadFile(i,s,function(e){u=e,l()}),e.internalUploadFile(a,s,function(e){c=e,l()})])).then(function(e){var r,n;if(t.delete(null==(r=o.videoElem)?void 0:r.videoUUID),t.delete(null==(n=o.videoElem)?void 0:n.snapshotUUID),e[0].error||e[1].error)throw new ve(exports.ErrorCode.NetworkError,"Upload file failed");o.videoElem.videoUrl=e[0].url,o.videoElem.snapshotUrl=e[1].url})}}();return p&&p.then?p.then(c):c()}var p=function(){if(o.contentType===exports.MessageType.VoiceMessage){var r,n=t.get(null==(r=o.soundElem)?void 0:r.uuid);if(!n)throw new ve(exports.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(e.internalUploadFile(n,s,function(t){return e.triggerEvent({event:exports.CbEvents.OnProgress,data:{progress:t,clientMsgID:o.clientMsgID},operationID:s})})).then(function(e){var r,n=e.url,i=void 0===n?"":n,s=e.error;if(t.delete(null==(r=o.soundElem)?void 0:r.uuid),s)throw new ve(exports.ErrorCode.NetworkError,"Upload file failed");o.soundElem.sourceUrl=i})}}();return p&&p.then?p.then(c):c()}r.latestMsgSendTime=o.createTime,e.messageTrigger.getOneConversationAndTryChange(v,s,{latestMsg:JSON.stringify(o)},void 0,h);var p=function(){if(o.contentType===exports.MessageType.PictureMessage){var r,n=t.get(null==(r=o.pictureElem)?void 0:r.sourcePicture.uuid);if(!n)throw new ve(exports.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(e.internalUploadFile(n,s,function(t){return e.triggerEvent({event:exports.CbEvents.OnProgress,data:{progress:t,clientMsgID:o.clientMsgID},operationID:s})})).then(function(e){var r,n=e.url,i=void 0===n?"":n,s=e.error;if(t.delete(null==(r=o.pictureElem)?void 0:r.sourcePicture.uuid),s)throw new ve(exports.ErrorCode.NetworkError,"Upload file failed");o.pictureElem.sourcePicture.url=i,o.pictureElem.bigPicture.url=i,o.pictureElem.snapshotPicture.width=640,o.pictureElem.snapshotPicture.height=640,o.pictureElem.snapshotPicture.url=i+"?type=image&width=640&height=640"})}}();return p&&p.then?p.then(c):c()}var c=function(){if(u)return Promise.resolve(e.groupTrigger.cache.getGroupInfosWithCache([u],s)).then(function(t){return Promise.resolve(e.groupTrigger.cache.getGroupMembersWithCache({groupID:u,userIDList:[e.userID],operationID:s})).then(function(e){if(null==e||!e.length)throw new ve(exports.ErrorCode.ArgsError,"user not join target group");e[0].nickname&&(o.senderNickname=e[0].nickname),o.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},o.attachedInfoElem.groupHasReadInfo.unreadCount=t[0].memberCount-1})})}();return c&&c.then?c.then(i):i()}var c=function(){if(!r)return h=!0,Promise.resolve(e.messageTrigger.initConversation({sourceID:u||a,sessionType:o.sessionType,operationID:s})).then(function(e){r=e});r.isPrivateChat&&(l[exports.MessageOptionsKey.IsNotPrivate]=!1,o.attachedInfoElem=f({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:r.burnDuration}))}();return c&&c.then?c.then(i):i()})}catch(e){return Promise.reject(e)}};return Vt.includes(i.message.contentType)?o.enqueue(a):r.enqueue(a)}))}catch(e){return Promise.reject(e)}},sendMessageNotOss:function(t,o){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.SendMessage,o,function(){return r.enqueue(function(){try{var r=f({},t,{message:f({},t.message)}),i=r.message,s=r.recvID,a=r.groupID,u=r.isOnlineOnly,c=r.offlinePushInfo,p=void 0===c?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:c;void 0===p.signalInfo&&(p.signalInfo="");var d=Bt[i.contentType];if(!d)throw new ve(exports.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");i.recvID=s,i.groupID=a,i.sessionType=a?exports.SessionType.Group:exports.SessionType.Single;var g={};u&&Object.values(exports.MessageOptionsKey).forEach(function(e){return g[e]=!1});var l=ue(i);return Promise.resolve(e.messageTrigger.getOneConversationAndTryChange(l,o)).then(function(t){function r(r){var u,c;t.latestMsgSendTime=i.createTime,e.messageTrigger.getOneConversationAndTryChange(l,o,{latestMsg:JSON.stringify(i)});var f=JSON.stringify(i[d]),v={sendID:e.userID,recvID:s||"",groupID:a||"",clientMsgID:i.clientMsgID,serverMsgID:i.serverMsgID||"",senderPlatformID:e.platform,senderNickname:i.senderNickname,senderFaceURL:i.senderFaceUrl,sessionType:i.sessionType,msgFrom:i.msgFrom,contentType:i.contentType,content:we(f),seq:i.seq,sendTime:0,createTime:i.createTime,status:i.status,isRead:!1,options:g,offlinePushInfo:p,atUserIDList:null!=(u=null==(c=i.atTextElem)?void 0:c.atUserList)?u:[],attachedInfo:i.attachedInfoElem?JSON.stringify(i.attachedInfoElem):"",ex:i.ex||"",dstUserIDs:[],keyVersion:0};return Promise.resolve(e.messageTrigger.encryptor.encryption(l,v,o)).then(function(){var r=n.PbCoder.MsgData.encode(v).finish();return jt(function(){return Promise.resolve(e.sendReqWaitResp({data:r,operationID:o,reqIdentifier:exports.ReqIdentifier.SendMsg})).then(function(r){var n=r.serverMsgID,s=r.sendTime;return i.sendTime=s,i.serverMsgID=n,i.status=exports.MessageStatus.Succeed,e.messageTrigger.setTriggeredConversationEvent(o),e.messageTrigger.cache.updateCachedMaxReadSeq(t.conversationID,{maxSeqTime:s}),e.messageTrigger.getOneConversationAndTryChange(l,o,{latestMsg:JSON.stringify(i),latestMsgSendTime:s}),i})},function(t){throw i.status=exports.MessageStatus.Failed,e.messageTrigger.getOneConversationAndTryChange(l,o,{latestMsg:JSON.stringify(i)}),t})})}var u=function(){if(!t)return Promise.resolve(e.messageTrigger.initConversation({sourceID:a||s,sessionType:i.sessionType,operationID:o})).then(function(r){return t=r,function(){if(a)return Promise.resolve(e.groupTrigger.cache.getGroupInfosWithCache([a],o)).then(function(t){return Promise.resolve(e.groupTrigger.cache.getGroupMembersWithCache({groupID:a,userIDList:[e.userID],operationID:o})).then(function(e){if(null==e||!e.length)throw new ve(exports.ErrorCode.ArgsError,"user not join target group");e[0].nickname&&(i.senderNickname=e[0].nickname),i.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},i.attachedInfoElem.groupHasReadInfo.unreadCount=t[0].memberCount-1})})}()});t.isPrivateChat&&(g[exports.MessageOptionsKey.IsNotPrivate]=!1,i.attachedInfoElem=f({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:t.burnDuration}))}();return u&&u.then?u.then(r):r()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},revokeMessage:function(t,r){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.RevokeMessage,r,function(){try{var n=function(n){return Promise.resolve(e.sendHttpRequest({reqFuncName:exports.RequestApi.RevokeMessage,data:{conversationID:t.conversationID,seq:o.seq,userID:e.userID},operationID:r})).then(function(){e.messageTrigger.setTriggeredConversationEvent(r),e.messageTrigger.revokeMessage({revokerUserID:e.userID,clientMsgID:o.clientMsgID,revokeTime:Date.now(),sesstionType:o.sessionType,seq:o.seq,conversationID:t.conversationID,isAdminRevoke:!1},r)})},o=e.messageTrigger.cache.getCachedMessageByClientMsgIDs(t.conversationID,[t.clientMsgID])[0];if(!o)throw new ve(exports.ErrorCode.ArgsError,"message not exist");var i=function(){if(o.sendID!==e.userID){if(!o.groupID)throw new ve(exports.ErrorCode.ArgsError,"message can not be revoked");return Promise.resolve(e.groupTrigger.cache.getGroupMembersWithCache({groupID:o.groupID,userIDList:[e.userID],operationID:r})).then(function(e){var t=e[0];if(!t||t.roleLevel===exports.GroupMemberRole.Nomal)throw new ve(exports.ErrorCode.ArgsError,"message can not be revoked")})}}();return Promise.resolve(i&&i.then?i.then(n):n())}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},getAdvancedHistoryMessageList:function(t,r){try{return Promise.resolve(he(e.loginStatus,exports.RequestApi.GetAdvancedHistoryMessageList,r,function(){try{var n={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(a!==t.conversationID&&(i=null,a=t.conversationID),t.startClientMsgID){if(null===i){var o=e.messageTrigger.cache.getCachedMessageByClientMsgIDs(t.conversationID,[t.startClientMsgID])[0];if(!o)return Promise.resolve(f({},n,{isEnd:!0}));i=o.seq}}else i=0;var c=e.messageTrigger.cache.getCachedMaxReadSeq(t.conversationID);return s.default.log("syncedSeqs",c),c?Promise.resolve(u({maxSeq:i?i-1:c.maxSeq,count:t.count,conversationID:t.conversationID,operationID:r})).then(function(o){function a(){function a(){var a,u;return n.messageList=o.map(Ve),e.messageTrigger.cache.getGroupMessageHasReadInfo({conversationID:t.conversationID,messages:[].concat(n.messageList),operationID:r}),s.default.debug("getAdvancedHistoryMessageList with opid: ",r,"messageList: ",n.messageList),i=null!=(a=null==(u=o[0])?void 0:u.seq)?a:0,f({},n,{isEnd:o.lengthexports.NotificationType.NotificationBegin&&c.contentTypei.length&&a.groupHasReadInfo.hasReadCount>i.length){var s={clientMsgID:t.clientMsgID,conversationID:t.conversationID,type:exports.GroupMessageReaderFilter.Read,pagination:{pageNumber:t.offset+1,showNumber:t.count}};return Promise.resolve(e.sendHttpRequest({reqFuncName:C.GetGroupMessageHasRead,data:s,operationID:r})).then(function(s){var a=s.reads;if(i.length<50&&t.offset<50){var u=50-i.length;e.messageTrigger.cache.addGroupMessageReadUser(t.clientMsgID,a.slice(0,u%c [OperationID:"+t[t.length-1]+"] (invoked) run "+e+" with args "+JSON.stringify(t),"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")}(t,r),Promise.resolve(n.apply(e,r)).then(function(e){var r,n;return r=t,(n=e).errCode?s.default.debug("%cSDK =>%c [OperationID:"+n.operationID+"] (response) run "+r+" with error "+JSON.stringify(n),"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):s.default.debug("%cSDK =>%c [OperationID:"+n.operationID+"] (response) run "+r+" with response before processor "+JSON.stringify(n.data),"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),e.errCode?Promise.reject(e):e})}catch(e){return Promise.reject(e)}}:Reflect.get(e,t,r)}})}; diff --git a/node_modules/@openim/client-sdk/lib/index.modern.mjs b/node_modules/@openim/client-sdk/lib/index.modern.mjs index 3510b06..63f6725 100644 --- a/node_modules/@openim/client-sdk/lib/index.modern.mjs +++ b/node_modules/@openim/client-sdk/lib/index.modern.mjs @@ -1 +1 @@ -import e from"loglevel";import t from"spark-md5";import{decode as n,encode as s}from"base64-arraybuffer";import{PbCoder as r,SdkWsProto as i}from"@openim/protocol";function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t{if(!e.ok)throw new Error(e.statusText);const t=await e.json();if(0!==t.errCode)throw new Error(t.errMsg);return t.data},d={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",csv:"text/csv",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",bmp:"image/bmp",svg:"image/svg+xml",mp3:"audio/mpeg",mp4:"video/mp4",wav:"audio/wav",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",xml:"application/xml",zip:"application/zip",tar:"application/x-tar","7z":"application/x-7z-compressed",rar:"application/vnd.rar",ogg:"audio/ogg",midi:"audio/midi",webm:"audio/webm",avi:"video/x-msvideo",mpeg:"video/mpeg",ts:"video/mp2t",mov:"video/quicktime",wmv:"video/x-ms-wmv",flv:"video/x-flv",mkv:"video/x-matroska",webp:"image/webp",heic:"image/heic",psd:"image/vnd.adobe.photoshop",ai:"application/postscript",eps:"application/postscript",ttf:"font/ttf",otf:"font/otf",woff:"font/woff",woff2:"font/woff2",jsonld:"application/ld+json",ics:"text/calendar",sh:"application/x-sh",php:"application/x-httpd-php",jar:"application/java-archive"};var g,u;!function(e){e.InitSDK="InitSDK",e.Login="Login",e.Logout="Logout",e.GetLoginStatus="GetLoginStatus",e.GetLoginUserID="GetLoginUserID",e.GetSelfUserInfo="GetSelfUserInfo",e.SetSelfInfo="SetSelfInfo",e.GetUsersInfo="GetUsersInfo",e.SubscribeUsersStatus="SubscribeUsersStatus",e.UnsubscribeUsersStatus="UnsubscribeUsersStatus",e.GetSubscribeUsersStatus="GetSubscribeUsersStatus",e.SetAppBackgroundStatus="SetAppBackgroundStatus",e.NetworkStatusChanged="NetworkStatusChanged",e.SetGlobalRecvMessageOpt="SetGlobalRecvMessageOpt",e.AcceptFriendApplication="AcceptFriendApplication",e.AddBlack="AddBlack",e.AddFriend="AddFriend",e.CheckFriend="CheckFriend",e.DeleteFriend="DeleteFriend",e.GetBlackList="GetBlackList",e.GetFriendApplicationListAsApplicant="GetFriendApplicationListAsApplicant",e.GetFriendApplicationListAsRecipient="GetFriendApplicationListAsRecipient",e.GetFriendList="GetFriendList",e.GetFriendListPage="GetFriendListPage",e.GetSpecifiedFriendsInfo="GetSpecifiedFriendsInfo",e.RefuseFriendApplication="RefuseFriendApplication",e.RemoveBlack="RemoveBlack",e.SearchFriends="SearchFriends",e.UpdateFriends="UpdateFriends",e.CreateGroup="CreateGroup",e.JoinGroup="JoinGroup",e.InviteUserToGroup="InviteUserToGroup",e.GetJoinedGroupList="GetJoinedGroupList",e.GetJoinedGroupListPage="GetJoinedGroupListPage",e.SearchGroups="SearchGroups",e.GetSpecifiedGroupsInfo="GetSpecifiedGroupsInfo",e.SetGroupInfo="SetGroupInfo",e.GetGroupApplicationListAsRecipient="GetGroupApplicationListAsRecipient",e.GetGroupApplicationListAsApplicant="GetGroupApplicationListAsApplicant",e.AcceptGroupApplication="AcceptGroupApplication",e.RefuseGroupApplication="RefuseGroupApplication",e.GetGroupMemberList="GetGroupMemberList",e.GetSpecifiedGroupMembersInfo="GetSpecifiedGroupMembersInfo",e.SearchGroupMembers="SearchGroupMembers",e.SetGroupMemberInfo="SetGroupMemberInfo",e.GetGroupMemberOwnerAndAdmin="GetGroupMemberOwnerAndAdmin",e.GetGroupMemberListByJoinTimeFilter="GetGroupMemberListByJoinTimeFilter",e.KickGroupMember="KickGroupMember",e.ChangeGroupMemberMute="ChangeGroupMemberMute",e.ChangeGroupMute="ChangeGroupMute",e.TransferGroupOwner="TransferGroupOwner",e.DismissGroup="DismissGroup",e.QuitGroup="QuitGroup",e.GetUsersInGroup="GetUsersInGroup",e.GetAllConversationList="GetAllConversationList",e.GetConversationListSplit="GetConversationListSplit",e.GetOneConversation="GetOneConversation",e.GetMultipleConversation="GetMultipleConversation",e.GetConversationIDBySessionType="GetConversationIDBySessionType",e.GetTotalUnreadMsgCount="GetTotalUnreadMsgCount",e.MarkConversationMessageAsRead="MarkConversationMessageAsRead",e.SetConversationDraft="SetConversationDraft",e.PinConversation="PinConversation",e.SetConversationRecvMessageOpt="SetConversationRecvMessageOpt",e.SetConversationPrivateChat="SetConversationPrivateChat",e.SetConversationBurnDuration="SetConversationBurnDuration",e.ResetConversationGroupAtType="ResetConversationGroupAtType",e.HideConversation="HideConversation",e.HideAllConversation="HideAllConversation",e.ClearConversationAndDeleteAllMsg="ClearConversationAndDeleteAllMsg",e.DeleteConversationAndDeleteAllMsg="DeleteConversationAndDeleteAllMsg",e.ChangeInputStates="ChangeInputStates",e.GetInputStates="GetInputStates",e.CreateTextMessage="CreateTextMessage",e.CreateTextAtMessage="CreateTextAtMessage",e.CreateImageMessageByFile="CreateImageMessageByFile",e.CreateImageMessageByURL="CreateImageMessageByURL",e.CreateSoundMessageByFile="CreateSoundMessageByFile",e.CreateSoundMessageByURL="CreateSoundMessageByURL",e.CreateVideoMessageByFile="CreateVideoMessageByFile",e.CreateVideoMessageByURL="CreateVideoMessageByURL",e.CreateFileMessageByFile="CreateFileMessageByFile",e.CreateFileMessageByURL="CreateFileMessageByURL",e.CreateMergerMessage="CreateMergerMessage",e.CreateForwardMessage="CreateForwardMessage",e.CreateLocationMessage="CreateLocationMessage",e.CreateQuoteMessage="CreateQuoteMessage",e.CreateCardMessage="CreateCardMessage",e.CreateCustomMessage="CreateCustomMessage",e.CreateFaceMessage="CreateFaceMessage",e.SendMessage="SendMessage",e.SendMessageNotOss="SendMessageNotOss",e.UploadFile="UploadFile",e.TypingStatusUpdate="TypingStatusUpdate",e.RevokeMessage="RevokeMessage",e.DeleteMessage="DeleteMessage",e.DeleteMessageFromLocalStorage="DeleteMessageFromLocalStorage",e.DeleteAllMsgFromLocal="DeleteAllMsgFromLocal",e.DeleteAllMsgFromLocalAndSvr="DeleteAllMsgFromLocalAndSvr",e.SearchLocalMessages="SearchLocalMessages",e.GetAdvancedHistoryMessageList="GetAdvancedHistoryMessageList",e.GetAdvancedHistoryMessageListReverse="GetAdvancedHistoryMessageListReverse",e.FindMessageList="FindMessageList",e.InsertGroupMessageToLocalStorage="InsertGroupMessageToLocalStorage",e.InsertSingleMessageToLocalStorage="InsertSingleMessageToLocalStorage",e.SetMessageLocalEx="SetMessageLocalEx",e.SetConversation="SetConversation"}(g||(g={})),function(e){e.GetFriendVersion="GetFriendVersion",e.GetGroupVersion="GetGroupVersion",e.GetJoinedGroupIDList="GetJoinedGroupIDList",e.GetGroupMemberVersion="GetGroupMemberVersion",e.GetConversationVersion="GetConversationVersion",e.GetConversationsHasReadAndMaxSeq="GetConversationsHasReadAndMaxSeq",e.GetDesignatedFriendsApplication="GetDesignatedFriendsApplication",e.GetDesignatedGroupApplication="GetDesignatedGroupApplication",e.GetDesignatedBlackUser="GetDesignatedBlackUser",e.GetActiveConversations="GetActiveConversations",e.GetDesignatedConversation="GetDesignatedConversation",e.GetNotNotifyConversationIDs="GetNotNotifyConversationIDs",e.GetFullFriendUserIDs="GetFullFriendUserIDs",e.GetFullGroupMemberUserIDs="GetFullGroupMemberUserIDs"}(u||(u={}));const p={[g.AddFriend]:"/friend/add_friend",[g.CheckFriend]:"/friend/is_friend",[g.DeleteFriend]:"/friend/delete_friend",[g.AcceptFriendApplication]:"/friend/add_friend_response",[g.RefuseFriendApplication]:"/friend/add_friend_response",[g.GetFriendListPage]:"/friend/get_friend_list",[g.GetSpecifiedFriendsInfo]:"/friend/get_designated_friends",[g.GetFriendApplicationListAsApplicant]:"/friend/get_self_friend_apply_list",[g.GetFriendApplicationListAsRecipient]:"/friend/get_friend_apply_list",[g.UpdateFriends]:"/friend/update_friends",[g.AddBlack]:"/friend/add_black",[g.RemoveBlack]:"/friend/remove_black",[g.GetBlackList]:"/friend/get_black_list",[g.CreateGroup]:"/group/create_group",[g.JoinGroup]:"/group/join_group",[g.InviteUserToGroup]:"/group/invite_user_to_group",[g.GetJoinedGroupListPage]:"/group/get_joined_group_list",[g.GetSpecifiedGroupsInfo]:"/group/get_groups_info",[g.SetGroupInfo]:"/group/set_group_info_ex",[g.GetGroupApplicationListAsApplicant]:"/group/get_user_req_group_applicationList",[g.GetGroupApplicationListAsRecipient]:"/group/get_recv_group_applicationList",[g.AcceptGroupApplication]:"/group/group_application_response",[g.RefuseGroupApplication]:"/group/group_application_response",[g.GetGroupMemberList]:"/group/get_group_member_list",[g.GetSpecifiedGroupMembersInfo]:"/group/get_group_members_info",[g.SetGroupMemberInfo]:"/group/set_group_member_info",[g.KickGroupMember]:"/group/kick_group",[g.TransferGroupOwner]:"/group/transfer_group",[g.DismissGroup]:"/group/dismiss_group",[g.QuitGroup]:"/group/quit_group",[g.GetSelfUserInfo]:"/user/get_users_info",[g.SetSelfInfo]:"/user/update_user_info_ex",[g.GetUsersInfo]:"/user/get_users_info",[g.SubscribeUsersStatus]:"/user/subscribe_users_status",[g.UnsubscribeUsersStatus]:"/user/subscribe_users_status",[g.GetSubscribeUsersStatus]:"/user/get_subscribe_users_status",[g.SetGlobalRecvMessageOpt]:"/user/set_global_msg_recv_opt",[g.RevokeMessage]:"/msg/revoke_msg",[g.DeleteMessage]:"/msg/delete_msgs",[g.ClearConversationAndDeleteAllMsg]:"/msg/clear_conversation_msg",[g.DeleteAllMsgFromLocalAndSvr]:"/msg/user_clear_all_msg",[g.MarkConversationMessageAsRead]:"/msg/mark_conversation_as_read",[g.SetConversation]:"/conversation/set_conversations",[u.GetFriendVersion]:"/friend/get_incremental_friends",[u.GetGroupVersion]:"/group/get_incremental_join_groups",[u.GetJoinedGroupIDList]:"/group/get_full_join_group_ids",[u.GetGroupMemberVersion]:"/group/get_incremental_group_members_batch",[u.GetConversationVersion]:"/conversation/get_incremental_conversations",[u.GetConversationsHasReadAndMaxSeq]:"/conversation/get_conversations_has_read_and_max_seq",[u.GetDesignatedFriendsApplication]:"/friend/get_designated_friend_apply",[u.GetDesignatedGroupApplication]:"/group/get_specified_user_group_request_info",[u.GetDesignatedBlackUser]:"/friend/get_specified_blacks",[u.GetActiveConversations]:"/jssdk/get_active_conversations",[u.GetDesignatedConversation]:"/jssdk/get_conversations",[u.GetNotNotifyConversationIDs]:"/conversation/get_not_notify_conversation_ids",[u.GetFullFriendUserIDs]:"/friend/get_full_friend_user_ids",[u.GetFullGroupMemberUserIDs]:"/group/get_full_group_member_user_ids"};var l,h,f,m,v,I,D,M,S,y,C;!function(e){e.OnConnectFailed="OnConnectFailed",e.OnConnectSuccess="OnConnectSuccess",e.OnConnecting="OnConnecting",e.OnKickedOffline="OnKickedOffline",e.OnSelfInfoUpdated="OnSelfInfoUpdated",e.OnUserTokenExpired="OnUserTokenExpired",e.OnUserTokenInvalid="OnUserTokenInvalid",e.OnProgress="OnProgress",e.OnRecvNewMessage="OnRecvNewMessage",e.OnRecvNewMessages="OnRecvNewMessages",e.OnRecvOfflineNewMessage="onRecvOfflineNewMessage",e.OnRecvOfflineNewMessages="onRecvOfflineNewMessages",e.OnNewRecvMessageRevoked="OnNewRecvMessageRevoked",e.OnRecvC2CReadReceipt="OnRecvC2CReadReceipt",e.OnRecvGroupReadReceipt="OnRecvGroupReadReceipt",e.OnConversationChanged="OnConversationChanged",e.OnNewConversation="OnNewConversation",e.OnConversationUserInputStatusChanged="OnConversationUserInputStatusChanged",e.OnSyncServerFailed="OnSyncServerFailed",e.OnSyncServerFinish="OnSyncServerFinish",e.OnSyncServerProgress="OnSyncServerProgress",e.OnSyncServerStart="OnSyncServerStart",e.OnTotalUnreadMessageCountChanged="OnTotalUnreadMessageCountChanged",e.OnBlackAdded="OnBlackAdded",e.OnBlackDeleted="OnBlackDeleted",e.OnFriendApplicationAccepted="OnFriendApplicationAccepted",e.OnFriendApplicationAdded="OnFriendApplicationAdded",e.OnFriendApplicationDeleted="OnFriendApplicationDeleted",e.OnFriendApplicationRejected="OnFriendApplicationRejected",e.OnFriendInfoChanged="OnFriendInfoChanged",e.OnFriendAdded="OnFriendAdded",e.OnFriendDeleted="OnFriendDeleted",e.OnJoinedGroupAdded="OnJoinedGroupAdded",e.OnJoinedGroupDeleted="OnJoinedGroupDeleted",e.OnGroupDismissed="OnGroupDismissed",e.OnGroupMemberAdded="OnGroupMemberAdded",e.OnGroupMemberDeleted="OnGroupMemberDeleted",e.OnGroupApplicationAdded="OnGroupApplicationAdded",e.OnGroupApplicationDeleted="OnGroupApplicationDeleted",e.OnGroupInfoChanged="OnGroupInfoChanged",e.OnGroupMemberInfoChanged="OnGroupMemberInfoChanged",e.OnGroupApplicationAccepted="OnGroupApplicationAccepted",e.OnGroupApplicationRejected="OnGroupApplicationRejected",e.UploadComplete="UploadComplete",e.OnRecvCustomBusinessMessage="OnRecvCustomBusinessMessage",e.OnUserStatusChanged="OnUserStatusChanged",e.OnUploadLogsProgress="OnUploadLogsProgress",e.OnReceiveNewInvitation="OnReceiveNewInvitation",e.OnInviteeAccepted="OnInviteeAccepted",e.OnInviteeRejected="OnInviteeRejected",e.OnInvitationCancelled="OnInvitationCancelled",e.OnHangUp="OnHangUp",e.OnInvitationTimeout="OnInvitationTimeout",e.OnInviteeAcceptedByOtherDevice="OnInviteeAcceptedByOtherDevice",e.OnInviteeRejectedByOtherDevice="OnInviteeRejectedByOtherDevice",e.OnStreamChange="OnStreamChange",e.OnRoomParticipantConnected="OnRoomParticipantConnected",e.OnRoomParticipantDisconnected="OnRoomParticipantDisconnected",e.OnReceiveCustomSignal="OnReceiveCustomSignal",e.UnUsedEvent="UnUsedEvent"}(l||(l={})),function(e){e[e.NetworkError=1e4]="NetworkError",e[e.NetworkTimeoutError=10001]="NetworkTimeoutError",e[e.ArgsError=10002]="ArgsError",e[e.CtxDeadlineExceededError=10003]="CtxDeadlineExceededError",e[e.ResourceLoadNotCompleteError=10004]="ResourceLoadNotCompleteError",e[e.UnknownCode=10005]="UnknownCode",e[e.SdkInternalError=10006]="SdkInternalError",e[e.NoUpdateError=10007]="NoUpdateError",e[e.UserIDNotFoundError=10100]="UserIDNotFoundError",e[e.LoginOutError=10101]="LoginOutError",e[e.LoginRepeatError=10102]="LoginRepeatError",e[e.FileNotFoundError=10200]="FileNotFoundError",e[e.MsgDeCompressionError=10201]="MsgDeCompressionError",e[e.MsgDecodeBinaryWsError=10202]="MsgDecodeBinaryWsError",e[e.MsgBinaryTypeNotSupportError=10203]="MsgBinaryTypeNotSupportError",e[e.MsgRepeatError=10204]="MsgRepeatError",e[e.MsgContentTypeNotSupportError=10205]="MsgContentTypeNotSupportError",e[e.MsgHasNoSeqError=10206]="MsgHasNoSeqError",e[e.NotSupportOptError=10301]="NotSupportOptError",e[e.NotSupportTypeError=10302]="NotSupportTypeError",e[e.UnreadCountError=10303]="UnreadCountError",e[e.GroupIDNotFoundError=10400]="GroupIDNotFoundError",e[e.GroupTypeErr=10401]="GroupTypeErr"}(h||(h={})),function(e){e[e.GetNewestSeq=1001]="GetNewestSeq",e[e.PullMsgByRange=1002]="PullMsgByRange",e[e.SendMsg=1003]="SendMsg",e[e.SendSignalMsg=1004]="SendSignalMsg",e[e.PullMsgBySeqList=1005]="PullMsgBySeqList",e[e.GetConvMaxReadSeq=1006]="GetConvMaxReadSeq",e[e.PushMsg=2001]="PushMsg",e[e.KickOnlineMsg=2002]="KickOnlineMsg",e[e.LogoutMsg=2003]="LogoutMsg",e[e.SetBackgroundStatus=2004]="SetBackgroundStatus",e[e.WsSubUserOnlineStatus=2005]="WsSubUserOnlineStatus",e[e.WSServerConfigMsg=2100]="WSServerConfigMsg",e[e.WSDataError=3001]="WSDataError"}(f||(f={})),function(e){e[e.Text=101]="Text",e[e.Picture=102]="Picture",e[e.Sound=103]="Sound",e[e.Video=104]="Video",e[e.File=105]="File",e[e.AtText=106]="AtText",e[e.Merger=107]="Merger",e[e.Card=108]="Card",e[e.Location=109]="Location",e[e.Custom=110]="Custom",e[e.Typing=113]="Typing",e[e.Quote=114]="Quote",e[e.Face=115]="Face",e[e.AdvancedText=117]="AdvancedText",e[e.CustomMsgNotTriggerConversation=119]="CustomMsgNotTriggerConversation",e[e.CustomMsgOnlineOnly=120]="CustomMsgOnlineOnly",e[e.ReactionMessageModifier=121]="ReactionMessageModifier",e[e.ReactionMessageDeleter=122]="ReactionMessageDeleter"}(m||(m={})),function(e){e[e.NotificationBegin=1e3]="NotificationBegin",e[e.FriendNotificationBegin=1200]="FriendNotificationBegin",e[e.FriendApplicationApprovedNotification=1201]="FriendApplicationApprovedNotification",e[e.FriendApplicationRejectedNotification=1202]="FriendApplicationRejectedNotification",e[e.FriendApplicationNotification=1203]="FriendApplicationNotification",e[e.FriendAddedNotification=1204]="FriendAddedNotification",e[e.FriendDeletedNotification=1205]="FriendDeletedNotification",e[e.FriendRemarkSetNotification=1206]="FriendRemarkSetNotification",e[e.BlackAddedNotification=1207]="BlackAddedNotification",e[e.BlackDeletedNotification=1208]="BlackDeletedNotification",e[e.FriendInfoUpdatedNotification=1209]="FriendInfoUpdatedNotification",e[e.FriendsInfoUpdateNotification=1210]="FriendsInfoUpdateNotification",e[e.FriendNotificationEnd=1299]="FriendNotificationEnd",e[e.ConversationChangeNotification=1300]="ConversationChangeNotification",e[e.UserNotificationBegin=1301]="UserNotificationBegin",e[e.UserInfoUpdatedNotification=1303]="UserInfoUpdatedNotification",e[e.UserStatusChangeNotification=1304]="UserStatusChangeNotification",e[e.UserCommandAddNotification=1305]="UserCommandAddNotification",e[e.UserCommandDeleteNotification=1306]="UserCommandDeleteNotification",e[e.UserCommandUpdateNotification=1307]="UserCommandUpdateNotification",e[e.UserNotificationEnd=1399]="UserNotificationEnd",e[e.OANotification=1400]="OANotification",e[e.GroupNotificationBegin=1500]="GroupNotificationBegin",e[e.GroupCreatedNotification=1501]="GroupCreatedNotification",e[e.GroupInfoSetNotification=1502]="GroupInfoSetNotification",e[e.JoinGroupApplicationNotification=1503]="JoinGroupApplicationNotification",e[e.MemberQuitNotification=1504]="MemberQuitNotification",e[e.GroupApplicationAcceptedNotification=1505]="GroupApplicationAcceptedNotification",e[e.GroupApplicationRejectedNotification=1506]="GroupApplicationRejectedNotification",e[e.GroupOwnerTransferredNotification=1507]="GroupOwnerTransferredNotification",e[e.MemberKickedNotification=1508]="MemberKickedNotification",e[e.MemberInvitedNotification=1509]="MemberInvitedNotification",e[e.MemberEnterNotification=1510]="MemberEnterNotification",e[e.GroupDismissedNotification=1511]="GroupDismissedNotification",e[e.GroupMemberMutedNotification=1512]="GroupMemberMutedNotification",e[e.GroupMemberCancelMutedNotification=1513]="GroupMemberCancelMutedNotification",e[e.GroupMutedNotification=1514]="GroupMutedNotification",e[e.GroupCancelMutedNotification=1515]="GroupCancelMutedNotification",e[e.GroupMemberInfoSetNotification=1516]="GroupMemberInfoSetNotification",e[e.GroupMemberSetToAdminNotification=1517]="GroupMemberSetToAdminNotification",e[e.GroupMemberSetToOrdinaryUserNotification=1518]="GroupMemberSetToOrdinaryUserNotification",e[e.GroupInfoSetAnnouncementNotification=1519]="GroupInfoSetAnnouncementNotification",e[e.GroupInfoSetNameNotification=1520]="GroupInfoSetNameNotification",e[e.GroupNotificationEnd=1599]="GroupNotificationEnd",e[e.SignalingNotificationBegin=1600]="SignalingNotificationBegin",e[e.SignalingNotification=1601]="SignalingNotification",e[e.RoomParticipantsConnectedNotification=1602]="RoomParticipantsConnectedNotification",e[e.RoomParticipantsDisconnectedNotification=1603]="RoomParticipantsDisconnectedNotification",e[e.StreamChangedNotification=1604]="StreamChangedNotification",e[e.CustomSignalNotification=1605]="CustomSignalNotification",e[e.SignalingNotificationEnd=1649]="SignalingNotificationEnd",e[e.SuperGroupNotificationBegin=1650]="SuperGroupNotificationBegin",e[e.SuperGroupUpdateNotification=1651]="SuperGroupUpdateNotification",e[e.MsgDeleteNotification=1652]="MsgDeleteNotification",e[e.ReactionMessageModifierNotification=1653]="ReactionMessageModifierNotification",e[e.ReactionMessageDeleteNotification=1654]="ReactionMessageDeleteNotification",e[e.SuperGroupNotificationEnd=1699]="SuperGroupNotificationEnd",e[e.ConversationPrivateChatNotification=1701]="ConversationPrivateChatNotification",e[e.ConversationUnreadNotification=1702]="ConversationUnreadNotification",e[e.ClearConversationNotification=1703]="ClearConversationNotification",e[e.WorkMomentNotificationBegin=1900]="WorkMomentNotificationBegin",e[e.WorkMomentNotification=1901]="WorkMomentNotification",e[e.BusinessNotificationBegin=2e3]="BusinessNotificationBegin",e[e.BusinessNotification=2001]="BusinessNotification",e[e.BusinessNotificationEnd=2099]="BusinessNotificationEnd",e[e.RevokeNotification=2101]="RevokeNotification",e[e.HasReadReceiptNotification=2150]="HasReadReceiptNotification",e[e.GroupHasReadReceiptNotification=2155]="GroupHasReadReceiptNotification",e[e.DeleteMsgsNotification=2102]="DeleteMsgsNotification",e[e.HasReadReceipt=2200]="HasReadReceipt",e[e.HasGroupReadReceipt=2300]="HasGroupReadReceipt",e[e.NotificationEnd=5e3]="NotificationEnd"}(v||(v={})),function(e){e[e.UserMsgType=100]="UserMsgType",e[e.SysMsgType=200]="SysMsgType"}(I||(I={})),function(e){e[e.MsgStatusDefault=0]="MsgStatusDefault",e[e.MsgStatusSending=1]="MsgStatusSending",e[e.MsgStatusSendSuccess=2]="MsgStatusSendSuccess",e[e.MsgStatusSendFailed=3]="MsgStatusSendFailed",e[e.MsgStatusHasDeleted=4]="MsgStatusHasDeleted",e[e.MsgStatusFiltered=5]="MsgStatusFiltered"}(D||(D={})),function(e){e.IsHistory="history",e.IsPersistent="persistent",e.IsUnreadCount="unreadCount",e.IsConversationUpdate="conversationUpdate",e.IsOfflinePush="offlinePush",e.IsSenderSync="senderSync",e.IsNotPrivate="notPrivate",e.IsSenderConversationUpdate="senderConversationUpdate"}(M||(M={})),function(e){e[e.GroupOk=0]="GroupOk",e[e.GroupBanChat=1]="GroupBanChat",e[e.GroupStatusDismissed=2]="GroupStatusDismissed",e[e.GroupStatusMuted=3]="GroupStatusMuted"}(S||(S={})),function(e){e[e.WorkMomentCommentNotification=0]="WorkMomentCommentNotification",e[e.WorkMomentLikeNotification=1]="WorkMomentLikeNotification",e[e.WorkMomentAtUserNotification=2]="WorkMomentAtUserNotification"}(y||(y={})),function(e){e[e.TokenExpiredError=1501]="TokenExpiredError",e[e.TokenInvalidError=1502]="TokenInvalidError",e[e.TokenMalformedError=1503]="TokenMalformedError",e[e.TokenNotValidYetError=1504]="TokenNotValidYetError",e[e.TokenUnknownError=1505]="TokenUnknownError",e[e.TokenKickedError=1506]="TokenKickedError",e[e.TokenNotExistError=1507]="TokenNotExistError"}(C||(C={}));const G={[C.TokenExpiredError]:l.OnUserTokenExpired,[C.TokenInvalidError]:l.OnUserTokenInvalid,[C.TokenMalformedError]:l.OnUserTokenInvalid,[C.TokenNotValidYetError]:l.OnUserTokenInvalid,[C.TokenUnknownError]:l.OnUserTokenInvalid,[C.TokenKickedError]:l.OnKickedOffline,[C.TokenNotExistError]:l.OnUserTokenInvalid};var T,A,N,w,b,R,U,O,F,q,k,E,L,x,B,P,V,_;!function(e){e[e.Nomal=0]="Nomal",e[e.NotReceive=1]="NotReceive",e[e.NotNotify=2]="NotNotify"}(T||(T={})),function(e){e[e.Allowed=0]="Allowed",e[e.NotAllowed=1]="NotAllowed"}(A||(A={})),function(e){e[e.Group=2]="Group",e[e.WorkingGroup=2]="WorkingGroup"}(N||(N={})),function(e){e[e.Invitation=2]="Invitation",e[e.Search=3]="Search",e[e.QrCode=4]="QrCode"}(w||(w={})),function(e){e[e.Nomal=20]="Nomal",e[e.Admin=60]="Admin",e[e.Owner=100]="Owner"}(b||(b={})),function(e){e[e.ApplyNeedInviteNot=0]="ApplyNeedInviteNot",e[e.AllNeed=1]="AllNeed",e[e.AllNot=2]="AllNot"}(R||(R={})),function(e){e[e.Sending=1]="Sending",e[e.Succeed=2]="Succeed",e[e.Failed=3]="Failed"}(U||(U={})),function(e){e[e.iOS=1]="iOS",e[e.Android=2]="Android",e[e.Windows=3]="Windows",e[e.MacOSX=4]="MacOSX",e[e.Web=5]="Web",e[e.Linux=7]="Linux",e[e.AndroidPad=8]="AndroidPad",e[e.iPad=9]="iPad"}(O||(O={})),function(e){e[e.Silent=5]="Silent",e[e.Error=4]="Error",e[e.Warn=3]="Warn",e[e.Info=2]="Info",e[e.Debug=1]="Debug",e[e.Trace=0]="Trace"}(F||(F={})),function(e){e[e.Unprocessed=0]="Unprocessed",e[e.Agree=1]="Agree",e[e.Reject=-1]="Reject"}(q||(q={})),function(e){e[e.TextMessage=101]="TextMessage",e[e.PictureMessage=102]="PictureMessage",e[e.VoiceMessage=103]="VoiceMessage",e[e.VideoMessage=104]="VideoMessage",e[e.FileMessage=105]="FileMessage",e[e.AtTextMessage=106]="AtTextMessage",e[e.MergeMessage=107]="MergeMessage",e[e.CardMessage=108]="CardMessage",e[e.LocationMessage=109]="LocationMessage",e[e.CustomMessage=110]="CustomMessage",e[e.TypingMessage=113]="TypingMessage",e[e.QuoteMessage=114]="QuoteMessage",e[e.FaceMessage=115]="FaceMessage",e[e.FriendAdded=1201]="FriendAdded",e[e.OANotification=1400]="OANotification",e[e.GroupCreated=1501]="GroupCreated",e[e.MemberQuit=1504]="MemberQuit",e[e.GroupOwnerTransferred=1507]="GroupOwnerTransferred",e[e.MemberKicked=1508]="MemberKicked",e[e.MemberInvited=1509]="MemberInvited",e[e.MemberEnter=1510]="MemberEnter",e[e.GroupDismissed=1511]="GroupDismissed",e[e.GroupMemberMuted=1512]="GroupMemberMuted",e[e.GroupMemberCancelMuted=1513]="GroupMemberCancelMuted",e[e.GroupMuted=1514]="GroupMuted",e[e.GroupCancelMuted=1515]="GroupCancelMuted",e[e.GroupAnnouncementUpdated=1519]="GroupAnnouncementUpdated",e[e.GroupNameUpdated=1520]="GroupNameUpdated",e[e.BurnMessageChange=1701]="BurnMessageChange",e[e.RevokeMessage=2101]="RevokeMessage"}(k||(k={})),function(e){e[e.Single=1]="Single",e[e.Group=3]="Group",e[e.Notification=4]="Notification"}(E||(E={})),function(e){e[e.Nomal=0]="Nomal",e[e.Baned=1]="Baned",e[e.Dismissed=2]="Dismissed",e[e.Muted=3]="Muted"}(S||(S={})),function(e){e[e.AtNormal=0]="AtNormal",e[e.AtMe=1]="AtMe",e[e.AtAll=2]="AtAll",e[e.AtAllAtMe=3]="AtAllAtMe",e[e.AtGroupNotice=4]="AtGroupNotice"}(L||(L={})),function(e){e[e.All=0]="All",e[e.Owner=1]="Owner",e[e.Admin=2]="Admin",e[e.Nomal=3]="Nomal",e[e.AdminAndNomal=4]="AdminAndNomal",e[e.AdminAndOwner=5]="AdminAndOwner"}(x||(x={})),function(e){e[e.isBlack=0]="isBlack",e[e.isFriend=1]="isFriend"}(B||(B={})),function(e){e[e.Logout=1]="Logout",e[e.Logging=2]="Logging",e[e.Logged=3]="Logged"}(P||(P={})),function(e){e[e.Online=1]="Online",e[e.Offline=0]="Offline"}(V||(V={})),function(e){e[e.ViewHistory=0]="ViewHistory",e[e.ViewSearch=1]="ViewSearch"}(_||(_={}));const H=()=>(36*Math.random()).toString(36).slice(2)+(new Date).getTime().toString(),j=e=>{const n=(new Date).getTime().toString(),s=Math.floor(Math.random()*(new Date).getTime());return t.hash(n+e+s)},J=e=>{if(e.sessionType===E.Single){const t=[e.sendID,e.recvID].sort();return`si_${t[0]}_${t[1]}`}return e.sessionType===E.Group?`sg_${e.groupID}`:e.sessionType===E.Notification?`sn_${e.sendID}_${e.recvID}`:""},W=e=>{if(e.sessionType===E.Single){const t=[e.sourceID,e.userID].sort();return`si_${t[0]}_${t[1]}`}return e.sessionType===E.Group?`sg_${e.sourceID}`:e.sessionType===E.Notification?`sn_${e.sourceID}_${e.userID}`:""},$=(e,t)=>!(t in e&&!e[t]),Q={[f.GetNewestSeq]:r.GetMaxSeqResp.decode,[f.PullMsgByRange]:r.PullMessageBySeqsResp.decode,[f.SendMsg]:r.UserSendMsgResp.decode,[f.PullMsgBySeqList]:r.GetSeqMessageResp.decode,[f.PushMsg]:r.PushMessages.decode,[f.SetBackgroundStatus]:r.SetAppBackgroundStatusResp.decode,[f.WsSubUserOnlineStatus]:r.SubUserOnlineStatusTips.decode,[f.GetConvMaxReadSeq]:r.GetConversationsHasReadAndMaxSeqResp.decode,[u.GetActiveConversations]:r.GetActiveConversationsResp.decode,[u.GetDesignatedConversation]:r.GetConversationsResp.decode},K=(e,t)=>{if(!e)return null;const s=n(e),r=Q[t];return r?r(new Uint8Array(s)):null},z=(e,t,n)=>{const s=(new Date).getTime(),r=e.userTrigger.cache.getSelfUserInfo();return{clientMsgID:j(e.userID),createTime:s,sendTime:s,sessionType:0,sendID:e.userID,msgFrom:t,contentType:n,senderPlatformID:e.platform,senderNickname:null==r?void 0:r.nickname,senderFaceUrl:null==r?void 0:r.faceURL,seq:0,isRead:!1,status:U.Sending}};class Y extends Error{constructor(e,t){super(t),this.errCode=void 0,this.name=this.constructor.name,this.errCode=e,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const X=(e,t,n,s)=>{const r={event:t,operationID:n,data:null,errMsg:"",errCode:0};return e===P.Logout?Promise.reject(o({},r,{errCode:h.ResourceLoadNotCompleteError,errMsg:"Resource load not complete"})):s().then((e=null)=>o({},r,{data:e})).catch(e=>o({},r,{errCode:e.errCode||h.SdkInternalError,errMsg:e.message||"Internal Error"}))},Z=e=>(new TextDecoder).decode(e),ee=e=>(new TextEncoder).encode(e);var te;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(te||(te={}));class ne{constructor(e,t,n,s,r,i,o=5e3,a=Infinity){var c=this;this.url=void 0,this.onMessage=void 0,this.onReconnecting=void 0,this.onReconnectFailed=void 0,this.onReconnectSuccess=void 0,this.reconnectInterval=void 0,this.maxReconnectAttempts=void 0,this.ws=void 0,this.connectParams=void 0,this.reconnectAttempts=void 0,this.shouldReconnect=void 0,this.isProcessingMessage=!1,this.hasPong=!1,this.platformNamespace=void 0,this.heartbeatInterval=1e4,this.heartbeatWorker=null,this.legacyTimer=null,this.workerUrl=null,this.checkPlatform=()=>"undefined"!=typeof WebSocket?"web":"undefined"!=typeof my?"my":"undefined"!=typeof uni?"uni":"undefined"!=typeof wx?"wx":"unknow",this.urlFormat=()=>{let e="?";for(const[t,n]of Object.entries(this.connectParams))e+=`${t}=${n}&`;return this.url+e.slice(0,-1)},this.startHeartbeat=()=>{if(this.heartbeatWorker&&this.stopHeartbeat(),this.hasPong=!0,"undefined"!=typeof Worker){const e=new Blob(["\n let timerId = null;\n let heartbeatInterval;\n\n self.onmessage = (e) => {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n "],{type:"application/javascript"});this.workerUrl=URL.createObjectURL(e),this.heartbeatWorker=new Worker(this.workerUrl),this.heartbeatWorker.onmessage=e=>{"ping"===e.data.type&&this.sendPing()},this.heartbeatWorker.postMessage({type:"start",interval:this.heartbeatInterval})}else this.legacyTimer=setInterval(()=>{this.sendPing()},this.heartbeatInterval)},this.connect=()=>"unknow"===this.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise((e,t)=>{if(this.ws&&this.ws.readyState!==te.CLOSED)this.ws.readyState===this.ws.OPEN?e():t(new Error("WebSocket is in an unknown state"));else{const n=()=>{this.reconnectAttempts&&this.onReconnectSuccess(),this.reconnectAttempts=0,this.startHeartbeat(),e()},s=e=>t(e);if("web"===this.platformNamespace)this.ws=new WebSocket(this.urlFormat()),this.ws.onopen=n,this.ws.onerror=s;else{const e={url:this.urlFormat(),complete:()=>{}};"my"===this.platformNamespace&&(e.multiple=!0),"uni"===this.platformNamespace&&(this.ws=uni.connectSocket(e)),"wx"===this.platformNamespace&&(this.ws=wx.connectSocket(e)),"my"===this.platformNamespace&&(this.ws=my.connectSocket(e)),this.ws.onOpen(n),this.ws.onError(s)}this.setupEventListeners()}}),this.setupEventListeners=()=>{if(!this.ws)return;const e=e=>this.onBinaryMessage(e.data),t=e=>{if(this.shouldReconnect&&this.reconnectAttemptst(),100);setTimeout(()=>{this.onReconnecting(),this.connectParams.operationID=H(),this.connect().catch(()=>{this.onReconnectFailed()})},this.reconnectInterval),this.reconnectAttempts++}this.stopHeartbeat()};"web"===this.platformNamespace?(this.ws.onmessage=e,this.ws.onclose=t):(this.ws.onMessage(e),this.ws.onClose(t))},this.onBinaryMessage=async function(e){"string"!=typeof e&&"my"===c.platformNamespace&&(e=e.data),"string"!=typeof e||"pong"!==JSON.parse(e).type?(c.isProcessingMessage=!0,await c.onMessage(e,c.connectParams.operationID),c.isProcessingMessage=!1):c.hasPong=!0},this.sendPing=()=>{var e;if((null==(e=this.ws)?void 0:e.readyState)===te.OPEN){if(!this.hasPong)return this.ws.close(),void this.stopHeartbeat();const e=JSON.stringify({type:"ping"});this.ws.send("web"===this.platformNamespace?e:{data:e}),this.hasPong=!1}},this.sendMessage=e=>{var t;const n=ee(JSON.stringify(e));(null==(t=this.ws)?void 0:t.readyState)===te.OPEN?this.ws.send("web"===this.platformNamespace?n:{data:Uint8Array.from(n).buffer}):console.error("WebSocket is not open. Message not sent.")},this.close=()=>{var e;this.shouldReconnect=!1,(null==(e=this.ws)?void 0:e.readyState)===te.OPEN&&this.ws.close()},this.url=e,this.onMessage=n,this.onReconnecting=s,this.onReconnectFailed=r,this.onReconnectSuccess=i,this.reconnectInterval=o,this.maxReconnectAttempts=a,this.connectParams=t,this.reconnectInterval=o,this.maxReconnectAttempts=a,this.reconnectAttempts=0,this.shouldReconnect=!0,this.platformNamespace=this.checkPlatform()}stopHeartbeat(){this.heartbeatWorker&&(this.heartbeatWorker.postMessage({type:"stop"}),this.heartbeatWorker.terminate(),this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.heartbeatWorker=null),this.legacyTimer&&(clearInterval(this.legacyTimer),this.legacyTimer=null)}}class se{constructor(){this.events=void 0,this.events={}}emit(e,t){return this.events[e]&&this.events[e].forEach(e=>e(t)),this}on(e,t){return this.events[e]?this.events[e].push(t):this.events[e]=[t],this}off(e,t){if(e&&"function"==typeof t&&this.events[e]){const n=this.events[e];if(!n||0===n.length)return;const s=n.findIndex(e=>e===t);-1!==s&&n.splice(s,1)}return this}}const re=["friendUser"],ie=["blackUserInfo"],oe=e=>{var t,n,s,r,i,o,a,c,d,g,u,p,l,h;return{createTime:null==(t=e.groupInfo)?void 0:t.createTime,creatorUserID:null==(n=e.groupInfo)?void 0:n.creatorUserID,ex:e.ex,groupFaceURL:null==(s=e.groupInfo)?void 0:s.faceURL,groupID:null==(r=e.groupInfo)?void 0:r.groupID,groupName:null==(i=e.groupInfo)?void 0:i.groupName,groupType:null==(o=e.groupInfo)?void 0:o.groupType,handleResult:e.handleResult,handleUserID:e.handleUserID,handledMsg:e.handleMsg,handledTime:e.handleTime,introduction:null==(a=e.groupInfo)?void 0:a.introduction,memberCount:null==(c=e.groupInfo)?void 0:c.memberCount,nickname:null==(d=e.userInfo)?void 0:d.nickname,notification:null==(g=e.groupInfo)?void 0:g.notification,ownerUserID:null==(u=e.groupInfo)?void 0:u.ownerUserID,reqMsg:e.reqMsg,reqTime:e.reqTime,joinSource:e.joinSource,status:null==(p=e.groupInfo)?void 0:p.status,userFaceURL:null==(l=e.userInfo)?void 0:l.faceURL,userID:null==(h=e.userInfo)?void 0:h.userID}},ae=e=>({clientMsgID:e.clientMsgID,serverMsgID:e.serverMsgID,createTime:e.createTime,sendTime:e.sendTime,sessionType:e.sessionType,sendID:e.sendID,recvID:e.recvID,msgFrom:e.msgFrom,contentType:e.contentType,senderPlatformID:e.senderPlatformID,senderNickname:e.senderNickname,senderFaceUrl:e.senderFaceURL,groupID:e.groupID,content:e.content.length?Z(e.content):"",seq:e.seq,isRead:e.isRead,status:D.MsgStatusSendSuccess,isExternalExtensions:!1,offlinePush:e.offlinePushInfo,attachedInfo:e.attachedInfo,ex:e.ex,localEx:""}),ce=t=>{const n=o({},t);try{switch(t.contentType){case m.Text:n.textElem=JSON.parse(n.content);break;case m.Picture:n.pictureElem=JSON.parse(n.content);break;case m.Sound:n.soundElem=JSON.parse(n.content);break;case m.Video:n.videoElem=JSON.parse(n.content);break;case m.File:n.fileElem=JSON.parse(n.content);break;case m.AtText:n.atTextElem=JSON.parse(n.content);break;case m.Location:n.locationElem=JSON.parse(n.content);break;case m.Custom:case m.CustomMsgNotTriggerConversation:case m.CustomMsgOnlineOnly:n.customElem=JSON.parse(n.content);break;case m.Typing:n.typingElem=JSON.parse(n.content);break;case m.Merger:n.mergeElem=JSON.parse(n.content);break;case m.Face:n.faceElem=JSON.parse(n.content);break;case m.Quote:n.quoteElem=JSON.parse(n.content);break;case m.Card:n.cardElem=JSON.parse(n.content);break;default:n.notificationElem=JSON.parse(n.content)}}catch(t){e.warn("messageElemFormater messageElem parse failed",n)}if(t.attachedInfo)try{n.attachedInfoElem=JSON.parse(n.attachedInfo),n.attachedInfo=""}catch(t){e.warn("messageElemFormater attachedInfoElem failed",n.attachedInfo)}return n.content="",n},de=e=>{const t=Z(e),n=JSON.parse(t);return JSON.parse(n.detail)},ge=async({conversation:e,group:t,friend:n,user:s,lastMsg:r,maxSeq:i,readSeq:o},a,c)=>{var d,g;let u,p="",l=r?JSON.stringify(ce(ae(r))):"";var h,f,m;if((null==e?void 0:e.conversationType)===E.Group?(u=null!=(h=null==t?void 0:t.groupName)?h:"",p=null!=(f=null==t?void 0:t.faceURL)?f:""):(u=(null==n?void 0:n.remark)||(null==s?void 0:s.nickname)||"",p=null!=(m=null==s?void 0:s.faceURL)?m:""),(null==r?void 0:r.status)===D.MsgStatusHasDeleted){const t=await a({conversationID:null==e?void 0:e.conversationID,seq:r.seq,operationID:H()});t&&(l=JSON.stringify(ce(t)))}return{conversationID:e.conversationID,conversationType:e.conversationType,userID:e.userID,groupID:e.groupID,showName:u,faceURL:p,recvMsgOpt:e.recvMsgOpt,unreadCount:i-o,groupAtType:e.groupAtType,latestMsg:l,latestMsgSendTime:null!=(d=null!=(g=null==r?void 0:r.sendTime)?g:c)?d:0,draftText:"",draftTextTime:0,burnDuration:e.burnDuration,msgDestructTime:e.msgDestructTime,isPinned:e.isPinned,isPrivateChat:e.isPrivateChat,isMsgDestruct:e.isMsgDestruct,attachedInfo:e.attachedInfo,ex:e.ex}},ue=e=>{let{friendUser:t}=e;return o({},a(e,re),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL,attachedInfo:""})},pe=e=>{let{blackUserInfo:t}=e;return o({},a(e,ie),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL})};class le{constructor(e){this.store=void 0,this.options=void 0,this.expiryListeners=[],this.cleanupTimer=void 0,this.options=e,this.store=new Map,this.options.cleanupInterval>0&&(this.cleanupTimer=setInterval(()=>{this.deleteExpired()},this.options.cleanupInterval))}onExpiry(e){this.expiryListeners.push(e)}triggerExpiry(e,t){this.expiryListeners.forEach(n=>n(e,t)),this.delete(e)}set(e,t){this.delete(e);const n=Date.now();let s=null;this.options.ttl>0&&(s=setTimeout(()=>{clearTimeout(s),this.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:s,created:n})}get(e){const t=this.store.get(e);if(t&&Date.now()-t.created{e.timer&&clearTimeout(e.timer)}),this.store.clear()}deleteExpired(){const e=Date.now();this.store.forEach((t,n)=>{t.created+this.options.ttl<=e&&this.triggerExpiry(n,t.value)})}dispose(){this.cleanupTimer&&clearInterval(this.cleanupTimer),this.clear()}}const he=15e3;var fe;!function(e){e.Success="stateCodeSuccess",e.End="stateCodeEnd"}(fe||(fe={}));class me{constructor(e){var t=this;this.ctx=void 0,this.send=void 0,this.state=void 0,this.platformIDs=[],this.platformIDSet=new Map,this.reset=()=>{this.send.clear(),this.state.clear()},this.changeInputStates=async function({conversationID:e,focus:n,operationID:s}){const i=await t.ctx.messageTrigger.getOneConversationAndTryChange(e,s);if(!i)throw new Error("conversation not exist");if(n){if(t.send.get(e)===fe.Success)return;t.send.set(e,fe.Success)}else{if(!t.send.get(e))return;if(t.send.get(e)===fe.End)return;t.send.set(e,fe.End)}const a=z(t.ctx,I.UserMsgType,k.TypingMessage);a.recvID=i.userID,a.groupID=i.groupID,a.sessionType=i.conversationType,a.content=JSON.stringify({msgTips:n?"yes":"no"});const c={};Object.values(M).forEach(e=>c[e]=!1);const d=r.MsgData.encode(o({},a,{content:ee(a.content),senderFaceURL:a.senderFaceUrl,options:c,offlinePushInfo:void 0,atUserIDList:[],keyVersion:0,dstUserIDs:[]})).finish();await t.ctx.sendReqWaitResp({data:d,operationID:s,reqIdentifier:f.SendMsg})},this.onNewMessage=async function(e){const n=e.typingElem;if(e.sendID===t.ctx.userID)return;if(!t.platformIDSet.has(e.senderPlatformID))return;const s=Date.now()+10,r=W({sourceID:e.groupID||e.sendID,sessionType:e.sessionType,userID:t.ctx.userID}),i=JSON.stringify({conversationID:r,platformID:e.senderPlatformID,userID:e.sendID});"yes"===(null==n?void 0:n.msgTips)?(t.state.get(i)||setTimeout(()=>t.triggerChange(r,e.sendID)),t.state.set(i,s)):t.triggerChange(r,e.sendID)},this.triggerChange=(e,t)=>{this.ctx.triggerEvent({event:l.OnConversationUserInputStatusChanged,data:{conversationID:e,userID:t,platformIDs:this.getInputStates(e,t)}})},this.getInputStates=(e,t)=>{const n=[];return this.platformIDs.forEach(s=>{const r=JSON.stringify({conversationID:e,platformID:s,userID:t});this.state.get(r)&&n.push(s)}),n},this.ctx=e,this.send=new le({ttl:1e4,cleanupInterval:he}),this.state=new le({ttl:he,cleanupInterval:he}),[1,2,3,4,5,7,8,9].forEach(e=>{this.platformIDSet.set(e),this.platformIDs.push(e)}),this.platformIDs.sort((e,t)=>e-t),this.state.onExpiry(e=>{const{conversationID:t,userID:n}=JSON.parse(e);this.triggerChange(t,n)})}}class ve{constructor(t){var n=this;this.instance=void 0,this.totalUnreadCount=0,this.cachedNotNotifyConversationIDs=new Set,this.cachedConversations=new Map,this.cachedMessages=new Map,this.cachedFilterMessageSeqs=new Map,this.cachedHasReadAndMaxSeqs={},this.clear=()=>{this.totalUnreadCount=0,this.cachedHasReadAndMaxSeqs={},this.cachedNotNotifyConversationIDs.clear(),this.cachedMessages.clear(),this.cachedConversations.clear(),this.cachedFilterMessageSeqs.clear()},this.getActiveConversationsFromServer=async function(e){const t=await n.instance.sendHttpRequest({reqFuncName:u.GetActiveConversations,data:r.GetActiveConversationsReq.encode({ownerUserID:n.instance.userID,count:20}).finish(),operationID:e}),s=K(t,u.GetActiveConversations);if(!s)return;const{conversations:i,unreadCount:o}=s;n.totalUnreadCount=o,n.instance.messageTrigger.cache.setCachedConversations(await Promise.all(i.map(e=>{var t,s;return ge(e,n.instance.messageTrigger.getPreviousSeqMessage,null==(t=n.instance.messageTrigger.cache.getCachedMaxReadSeq(null==(s=e.conversation)?void 0:s.conversationID))?void 0:t.maxSeqTime)})))},this.getTotalUnreadCount=()=>this.totalUnreadCount,this.setTotalUnreadCount=(e,t)=>{e!==this.totalUnreadCount&&(e<0&&(e=0),this.totalUnreadCount=e,this.instance.triggerEvent({event:l.OnTotalUnreadMessageCountChanged,data:e,operationID:t}))},this.decreaseTotalUnreadCount=(e,t)=>{this.setTotalUnreadCount(this.totalUnreadCount-e,t)},this.getMaxReadSeqs=async function(e,t=[]){const s=r.GetConversationsHasReadAndMaxSeqReq.encode({userID:n.instance.userID,conversationIDs:t}).finish(),i=await n.instance.sendReqWaitResp({operationID:e,data:s,reqIdentifier:f.GetConvMaxReadSeq});i&&(n.instance.isReconnected&&await n.instance.messageTrigger.syncer.compareSeqsAndBatchSync(i.seqs,e),n.cachedHasReadAndMaxSeqs=i.seqs)},this.getSortedConversationIDs=(e,t)=>Object.keys(this.cachedHasReadAndMaxSeqs).sort((e,t)=>this.cachedHasReadAndMaxSeqs[t].maxSeqTime-this.cachedHasReadAndMaxSeqs[e].maxSeqTime).slice(e,e+t),this.getCachedMaxReadSeq=e=>this.cachedHasReadAndMaxSeqs[e],this.addCachedMaxReadSeq=(e,t)=>{this.cachedHasReadAndMaxSeqs[e]=t},this.updateCachedMaxReadSeq=(t,n)=>{this.cachedHasReadAndMaxSeqs[t]?this.cachedHasReadAndMaxSeqs[t]=o({},this.cachedHasReadAndMaxSeqs[t],n):e.warn("updateCachedMaxReadSeq: conversationID not found",t,"seqs",n)},this.getNotNotifyConversationIDs=async function(e){const t={userID:n.instance.userID},{conversationIDs:s}=await n.instance.sendHttpRequest({reqFuncName:u.GetNotNotifyConversationIDs,data:t,operationID:e});n.cachedNotNotifyConversationIDs=new Set(null!=s?s:[])},this.isNotNotifyConversation=e=>this.cachedNotNotifyConversationIDs.has(e),this.addNotNotifyConversationID=e=>{this.cachedNotNotifyConversationIDs.has(e)||this.cachedNotNotifyConversationIDs.add(e)},this.deleteNotNotifyConversationID=e=>{this.cachedNotNotifyConversationIDs.has(e)&&this.cachedNotNotifyConversationIDs.delete(e)},this.getCachedConversation=e=>this.cachedConversations.get(e),this.getAllCachedConversations=()=>Array.from(this.cachedConversations.values()),this.setCachedConversations=e=>{e.map(e=>{this.cachedConversations.set(e.conversationID,e)})},this.getCachedMessagesBySeqs=(e,t)=>{const n=this.cachedMessages.get(e)||[],s=[],r=[];return t.forEach(e=>{const t=n.find(t=>t.seq===e);t?r.push(t):s.push(e)}),{cachedMessages:r,unCachedSeqs:s}},this.getCachedMessageByClientMsgIDs=(e,t)=>(this.cachedMessages.get(e)||[]).filter(e=>t.includes(e.clientMsgID)),this.addMessagesToCache=(e,t)=>{const n=this.cachedMessages.get(e)||[];this.cachedMessages.set(e,[...n,...t])},this.deleteMessageFromCache=(e,t)=>{const n=this.cachedMessages.get(e)||[];this.cachedMessages.set(e,n.filter(e=>e.seq!==t)),this.addFilterSeqsToCache(e,[t])},this.clearCachedConversationMessages=e=>{this.cachedMessages.delete(e)},this.markCachedMessagesAsRead=(e,t)=>{(this.cachedMessages.get(e)||[]).forEach(e=>{(!t&&e.sendID!==this.instance.userID||null!=t&&t.includes(e.seq))&&(e.isRead=!0)})},this.tryUpdateCachedMessages=(e,t)=>{const n=this.cachedMessages.get(e)||[],s=n.findIndex(e=>e.clientMsgID===t.clientMsgID);if(-1!==s)return Object.assign(n[s],t),n[s]},this.tryUpdateQuotedMessage=(e,t)=>{const n=this.cachedMessages.get(e)||[],s=n.findIndex(e=>{var n;if(e.contentType===m.Quote)return(null==(n=ce(e).quoteElem)?void 0:n.quoteMessage.clientMsgID)===t});if(-1!==s){const e=JSON.parse(n[s].content);e.quoteMessage.contentType=v.RevokeNotification,Object.assign(n[s],{content:JSON.stringify(e)})}},this.addFilterSeqsToCache=(e,t)=>{const n=this.cachedFilterMessageSeqs.get(e)||[];this.cachedFilterMessageSeqs.set(e,[...n,...t])},this.checkIsFilterSeq=(e,t)=>{var n;return null==(n=this.cachedFilterMessageSeqs.get(e))?void 0:n.includes(t)},this.instance=t}}class Ie{constructor(t){var n=this;this.instance=void 0,this.defaultPullNums=10,this.SplitPullMsgNum=100,this.syncedConversationVersion=0,this.syncedConversationVersionID="",this.reset=()=>{this.syncedConversationVersion=0,this.syncedConversationVersionID=""},this.syncConversationVersion=async function(e){const t={userID:n.instance.userID,version:n.syncedConversationVersion,versionID:n.syncedConversationVersionID},s=await n.instance.sendHttpRequest({operationID:e,reqFuncName:u.GetConversationVersion,data:t});n.syncedConversationVersionID&&n.compareVersionAndTrigger(s),n.syncedConversationVersion=s.version,n.syncedConversationVersionID=s.versionID},this.compareVersionAndTrigger=e=>{const{insert:t,update:s}=e;(null!=t?t:[]).map(async function(e){}),(null!=s?s:[]).map(async function(e){await n.instance.messageTrigger.getOneConversationAndTryChange(e.conversationID,"",o({},e))})},this.compareSeqsAndBatchSync=async function(e,t){const s=new Map;for(const[t,i]of Object.entries(e)){var r;const e=null==(r=n.instance.messageTrigger.cache.getCachedMaxReadSeq(t))?void 0:r.maxSeq;e?i.maxSeq>e&&s.set(t,[e+1,i.maxSeq,i.maxSeqTime]):s.set(t,[0,i.maxSeq,i.maxSeqTime])}n.syncAndTriggerMsgs(s,t)},this.isNotification=e=>e.startsWith("n_"),this.syncAndTriggerMsgs=async function(t,s){if(e.debug("Current sync seqMap",t,t.size),t.size>0){let r=new Map,i=0;for(let[o,a]of t.entries()){const[t,c,d]=a,g=c-t+1;if(g/n.SplitPullMsgNum>1&&n.isNotification(o)){const r=new Map,i=Math.floor(g/n.SplitPullMsgNum);let a=t,u=0;for(let t=0;t<=i;t++){t===i?r.set(o,[a,c,d]):(u=a+n.SplitPullMsgNum,u>c&&(u=c,t=i),r.set(o,[a,u,d]));try{const e=await n.pullMsgBySeqRange(r,s);await n.instance.messageTrigger.triggerConversation(e.msgs,s),await n.instance.messageTrigger.triggerNotification(e.notificationMsgs,s);for(let[e,t]of r)n.instance.messageTrigger.cache.updateCachedMaxReadSeq(e,{maxSeq:t[1],maxSeqTime:t[2]});a=u+1}catch(t){throw e.error("Sync message from server error",t,r),t}}}else if(r.set(o,a),i+=g,i>=n.SplitPullMsgNum)try{const e=await n.pullMsgBySeqRange(r,s);await n.instance.messageTrigger.triggerConversation(e.msgs,s),await n.instance.messageTrigger.triggerNotification(e.notificationMsgs,s);for(let[e,t]of r)n.instance.messageTrigger.cache.updateCachedMaxReadSeq(e,{maxSeq:t[1],maxSeqTime:t[2]});r=new Map,i=0}catch(t){throw e.error("Sync message from server error",t,r),t}}try{const e=await n.pullMsgBySeqRange(r,s);await n.instance.messageTrigger.triggerConversation(e.msgs,s),await n.instance.messageTrigger.triggerNotification(e.notificationMsgs,s);for(let[e,s]of t)n.instance.messageTrigger.cache.updateCachedMaxReadSeq(e,{maxSeq:s[1],maxSeqTime:s[2]})}catch(n){throw e.error("Sync message from server error",n,t),n}}else e.debug("Nothing to sync")},this.pullMsgBySeqRange=async function(t,s){const o=[...t.entries()].map(([e,t])=>({conversationID:e,begin:t[0],end:t[1],num:n.defaultPullNums}));e.debug("PullMsgBySeqRange with opid: ",s,"seqRanges: ",o);const a=r.PullMessageBySeqsReq.encode({userID:n.instance.userID,seqRanges:o,order:i.PullOrder.PullOrderAsc}).finish();return await n.instance.sendReqWaitResp({operationID:s,data:a,reqIdentifier:f.PullMsgByRange})},this.instance=t}}const De=[D.MsgStatusHasDeleted,D.MsgStatusFiltered];class Me{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredConversationEvent=new Map,this.typingManager=void 0,this.sync=async function(e){await n.cache.getMaxReadSeqs(e);const t=[n.syncer.syncConversationVersion(e),n.cache.getActiveConversationsFromServer(e),n.cache.getNotNotifyConversationIDs(e)];await Promise.all(t)},this.reset=()=>{this.cache.clear(),this.syncer.reset(),this.typingManager.reset(),this.triggeredConversationEvent.clear()},this.setTriggeredConversationEvent=e=>{this.triggeredConversationEvent.set(e,!0)},this.getMessageWithCacheBySeqs=async function(t,s,r){const{cachedMessages:i,unCachedSeqs:o}=n.cache.getCachedMessagesBySeqs(t,s),a=[...i];let c=0;if(e.debug("after getCachedMessagesBySeqs with opid: ",r,"seqs: ",s,"cachedMessages: ",i,"unCachedSeqs: ",o),o.length){const e=await n.getMessageFromServerBySeqs([{conversationID:t,seqs:o}],r),s=[],i=[];e.msgs[t].Msgs.forEach(e=>{De.includes(e.status)?(s.push(e.seq),c++):i.push(ae(e))}),e.msgs[t].Msgs.length||s.push(...o),n.cache.addMessagesToCache(t,i),n.cache.addFilterSeqsToCache(t,s),a.push(...i)}return a.sort((e,t)=>e.seq-t.seq),{messages:a,filterCount:c}},this.getPreviousSeqMessage=async function({conversationID:e,seq:t,operationID:s}){if(t<1)return null;const r=[];for(let s=t;r.length<10&&!(s<1);s--)n.cache.checkIsFilterSeq(e,s)||r.push(s);const{messages:i}=await n.getMessageWithCacheBySeqs(e,r,s);return i.length?i[i.length-1]:await n.getPreviousSeqMessage({seq:r[r.length-1],operationID:s,conversationID:e})},this.initConversation=async function(e){let t={conversationID:W(o({},e,{userID:n.instance.userID})),userID:"",groupID:"",recvMsgOpt:T.Nomal,unreadCount:0,groupAtType:L.AtNormal,latestMsg:"",latestMsgSendTime:0,draftText:"",draftTextTime:0,burnDuration:0,msgDestructTime:0,isPinned:!1,isPrivateChat:!1,isMsgDestruct:!1,attachedInfo:"",ex:""};if(e.sessionType===E.Group){const s=await n.instance.groupTrigger.cache.getGroupInfosWithCache([e.sourceID],e.operationID);if(!s[0])throw new Error("target group not exist");t.showName=s[0].groupName,t.faceURL=s[0].faceURL,t.conversationType=E.Group,t.groupID=e.sourceID}else{t.userID=e.sourceID,t.conversationType=E.Single;const{data:s}=await n.instance.getSpecifiedFriendsInfo([e.sourceID],e.operationID);if(s.length)t.showName=s[0].remark||s[0].nickname,t.faceURL=s[0].faceURL;else{const{data:s}=await n.instance.getUsersInfo([e.sourceID],e.operationID);t.showName=s[0].nickname,t.faceURL=s[0].faceURL}}return n.cache.setCachedConversations([t]),t},this.getConversationsWithCacheByIDs=async function(e,t){const s=[],i=[],o=[];if(e.forEach(e=>{const t=n.cache.getCachedConversation(e);t?s.push(t):o.push(e)}),o.length){const e=await n.instance.sendHttpRequest({reqFuncName:u.GetDesignatedConversation,data:r.GetConversationsReq.encode({ownerUserID:n.instance.userID,conversationIDs:o}).finish(),operationID:t}),{conversations:s}=K(e,u.GetDesignatedConversation);i.push(...await Promise.all(s.map(e=>{var t,s;return ge(e,n.getPreviousSeqMessage,null==(t=n.cache.getCachedMaxReadSeq(null==(s=e.conversation)?void 0:s.conversationID))?void 0:t.maxSeqTime)}))),n.cache.setCachedConversations(i)}return[...s,...i]},this.getOneConversationAndTryChange=async function(e,t,s,i,a){let c;if(c=n.cache.getCachedConversation(e),c)void 0!==(null==s?void 0:s.recvMsgOpt)&&(s.recvMsgOpt===T.Nomal?n.cache.deleteNotNotifyConversationID(e):n.cache.addNotNotifyConversationID(e)),s&&Object.assign(c,s),i&&(c.unreadCount+=1);else if(n.cache.getCachedMaxReadSeq(e)){var d;const s=await n.instance.sendHttpRequest({reqFuncName:u.GetDesignatedConversation,data:r.GetConversationsReq.encode({ownerUserID:n.instance.userID,conversationIDs:[e]}).finish(),operationID:t}),{conversations:i}=K(s,u.GetDesignatedConversation);if(!i)return;c=await ge(i[0],n.getPreviousSeqMessage,null==(d=n.cache.getCachedMaxReadSeq(e))?void 0:d.maxSeqTime),n.cache.setCachedConversations([c])}return c&&s&&n.instance.triggerEvent({event:a?l.OnNewConversation:l.OnConversationChanged,data:[o({},c)],operationID:t}),c},this.getMessageFromServerBySeqs=async function(e,t){const s=r.GetSeqMessageReq.encode({userID:n.instance.userID,conversations:e}).finish();return await n.instance.sendReqWaitResp({operationID:t,data:s,reqIdentifier:f.PullMsgBySeqList})},this.revokeMessage=async function(e,t){var s,r;const{messages:i}=await n.getMessageWithCacheBySeqs(e.conversationID,[e.seq],t),o=i[0];let a=0,c="";if(e.isAdminRevoke||e.sesstionType===E.Single){var d;const{data:s}=await n.instance.getUsersInfo([e.revokerUserID],t);c=null==(d=s[0])?void 0:d.nickname}else if(e.sesstionType===E.Group){var g,u;const s=await n.getOneConversationAndTryChange(e.conversationID,t),r=await n.instance.groupTrigger.cache.getGroupMembersWithCache({groupID:s.groupID,userIDList:[e.revokerUserID],operationID:t});c=null==(g=r[0])?void 0:g.nickname,a=null==(u=r[0])?void 0:u.roleLevel}const p={revokerID:e.revokerUserID,revokerRole:a,clientMsgID:o.clientMsgID,revokerNickname:c,revokeTime:e.revokeTime,sourceMessageSendTime:o.sendTime,sourceMessageSendID:o.sendID,sourceMessageSenderNickname:o.senderNickname,sessionType:e.sesstionType,seq:e.seq,ex:"",isAdminRevoke:e.isAdminRevoke};let h=n.cache.tryUpdateCachedMessages(e.conversationID,{clientMsgID:e.clientMsgID,seq:e.seq,content:JSON.stringify({detail:JSON.stringify(p)}),contentType:v.RevokeNotification});if(n.cache.tryUpdateQuotedMessage(e.conversationID,e.clientMsgID),!h){const s=await n.getMessageFromServerBySeqs([{conversationID:e.conversationID,seqs:[e.seq]}],t);h=ae(s.msgs[e.conversationID].Msgs[0])}n.instance.triggerEvent({event:l.OnNewRecvMessageRevoked,data:p,operationID:t}),(null!=(s=null==(r=n.cache.getCachedMaxReadSeq(e.conversationID))?void 0:r.maxSeq)?s:0)<=e.seq&&(n.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:e.revokeTime}),await n.getOneConversationAndTryChange(e.conversationID,t,{latestMsg:JSON.stringify(ce(h)),latestMsgSendTime:e.revokeTime}))},this.triggerTyping=e=>{e.sendID!==this.instance.userID&&this.typingManager.onNewMessage(e)},this.triggerNotification=async function(t,s){for(let[r,i]of Object.entries(t))i.Msgs.map(t=>{t.contentType>v.FriendNotificationBegin&&t.contentTypev.UserNotificationBegin&&t.contentTypev.GroupNotificationBegin&&t.contentTypev.SignalingNotificationBegin&&t.contentType{var s;return t===(null==(s=n.cache.getCachedMaxReadSeq(e.conversationID))?void 0:s.hasReadSeq)});if(r){const{messages:i}=await n.getMessageWithCacheBySeqs(e.conversationID,[r-1],s),o=i[0];o&&(n.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:t.sendTime}),await n.getOneConversationAndTryChange(e.conversationID,s,{latestMsg:JSON.stringify(ce(o)),latestMsgSendTime:o.sendTime}))}break}case v.HasReadReceipt:{const r=de(t.content);if(r.markAsReadUserID===n.instance.userID||!r.seqs.length)return;const{messages:i}=await n.getMessageWithCacheBySeqs(r.conversationID,r.seqs,s),o={userID:r.markAsReadUserID,groupID:"",msgIDList:i.map(e=>e.clientMsgID),readTime:t.sendTime,msgFrom:0,contentType:0,sessionType:i[0].sessionType};e.debug("receipt",o),n.instance.triggerEvent({event:l.OnRecvC2CReadReceipt,data:[o],operationID:s});const a=i.find(e=>e.seq===r.hasReadSeq);if(a){a.isRead=!0;const e=JSON.stringify(ce(a));await n.getOneConversationAndTryChange(r.conversationID,s,{unreadCount:0,latestMsg:e})}n.cache.decreaseTotalUnreadCount(r.seqs.length,s),n.cache.updateCachedMaxReadSeq(r.conversationID,{hasReadSeq:r.hasReadSeq});break}}},this.triggerConversation=async function(t,s){if(0===Object.keys(t).length)return;e.debug("Trigger conversation",t);let r=!0;n.triggeredConversationEvent.has(s)&&(n.triggeredConversationEvent.delete(s),r=!1);let i=!1,o=n.cache.getTotalUnreadCount();const a=[];for(const[c,d]of Object.entries(t))d.Msgs.map(t=>{var d,g,u,p;const l=$(t.options,M.IsUnreadCount),h=$(t.options,M.IsConversationUpdate),f=$(t.options,M.IsNotPrivate),v=!n.cache.getCachedMaxReadSeq(c),I=t.sendID===n.instance.userID;if(!t.clientMsgID||!c)return;const S=ae(t),y=ce(S);if(y.attachedInfoElem=t.attachedInfo?JSON.parse(t.attachedInfo):{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},t.status===D.MsgStatusHasDeleted)return;t.contentType===m.Typing&&n.triggerTyping(y),y.status=D.MsgStatusSendSuccess,S.status=D.MsgStatusSendSuccess,v&&n.cache.addCachedMaxReadSeq(c,{hasReadSeq:I?t.seq:t.seq-1,maxSeq:t.seq,maxSeqTime:t.sendTime}),f||(y.attachedInfoElem.isPrivateChat=!0),h&&(o+=l?1:0,n.cache.updateCachedMaxReadSeq(c,{maxSeqTime:y.sendTime}),r&&n.getOneConversationAndTryChange(c,s,{latestMsg:JSON.stringify(y),latestMsgSendTime:y.sendTime},l,v),a.push(S),n.cache.addMessagesToCache(c,[S]));const C=null!=(d=null==(g=n.cache.getCachedMaxReadSeq(c))?void 0:g.maxSeq)?d:0,G=null!=(u=null==(p=n.cache.getCachedMaxReadSeq(c))?void 0:p.hasReadSeq)?u:0;e.debug("currentMaxSeq",C,"currentHasReadSeq",G),y.seq>C&&(i=v||!n.cache.isNotNotifyConversation(c),n.cache.updateCachedMaxReadSeq(c,{maxSeq:C+1,maxSeqTime:y.sendTime}),I&&(n.cache.updateCachedMaxReadSeq(c,{hasReadSeq:G+1}),n.cache.tryUpdateCachedMessages(c,{clientMsgID:y.clientMsgID,seq:y.seq})))});if(r&&i&&n.cache.setTotalUnreadCount(o,s),a.length>0){if(!r)return void a.map(e=>{n.cache.tryUpdateCachedMessages(J(e),e)});n.instance.triggerEvent({event:l.OnRecvNewMessages,data:a.map(ce),operationID:s})}},this.instance=t,this.cache=new ve(t),this.syncer=new Ie(t),this.typingManager=new me(t)}}class Se{constructor(e){var t=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=async function(e,n){const s={groupID:e,idHash:0},{userIDs:r}=await t.instance.sendHttpRequest({reqFuncName:u.GetFullGroupMemberUserIDs,data:s,operationID:n});t.cachedGroupMembersID.set(e,r)},this.getGroupInfosWithCache=async function(e,n){const s=[],r=[];if(e.forEach(e=>{const n=t.cachedGroups.get(e);n?s.push(n):r.push(e)}),!r.length)return s;const i={groupIDs:r},{groupInfos:o}=await t.instance.sendHttpRequest({reqFuncName:g.GetSpecifiedGroupsInfo,data:i,operationID:n});return o&&o.forEach(e=>t.cachedGroups.set(e.groupID,e)),[...s,...null!=o?o:[]]},this.getGroupMembersWithCache=async function({groupID:e,userIDList:n,operationID:s}){var r;const i=null!=(r=t.cachedGroupMembers.get(e))?r:[];if(null!=n&&n.length){const r=[],o=[];if(n.forEach(e=>{const t=i.find(t=>t.userID===e);t?o.push(t):r.push(e)}),!r.length)return o;const a={groupID:e,userIDs:r},{members:c}=await t.instance.sendHttpRequest({reqFuncName:g.GetSpecifiedGroupMembersInfo,data:a,operationID:s});return c&&t.cachedGroupMembers.set(e,[...i,...c]),[...o,...null!=c?c:[]]}return i},this.updateCachedGroups=e=>{e.map(e=>{this.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=e=>{var t;const n=e[0].groupID,s=null!=(t=this.cachedGroupMembers.get(n))?t:[];this.cachedGroupMembers.set(n,[...s.filter(t=>!e.find(e=>e.userID===t.userID)),...e]);const r=this.instance.messageTrigger.cache.getAllCachedConversations().find(t=>t.groupID===e[0].groupID),i=JSON.parse((null==r?void 0:r.latestMsg)||"{}"),a=e.find(e=>e.userID===i.sendID&&e.nickname!==i.senderNickname);r&&a&&this.instance.messageTrigger.getOneConversationAndTryChange(r.conversationID,"",{latestMsg:o({},i,{senderNickname:a.nickname})})},this.clearCachedGroupMembers=e=>{this.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=e=>this.cachedGroupMembersID.has(e),this.getCachedGroupMembersID=e=>{var t;return null!=(t=this.cachedGroupMembersID.get(e))?t:[]},this.tryAddCachedGroupMembersID=(e,t)=>{if(this.cachedGroupMembersID.has(e)){var n;const s=null!=(n=this.cachedGroupMembersID.get(e))?n:[];this.cachedGroupMembersID.set(e,[...s,...t])}},this.tryDeleteCachedGroupMembersID=(e,t)=>{if(this.cachedGroupMembersID.has(e)){var n;const s=null!=(n=this.cachedGroupMembersID.get(e))?n:[];this.cachedGroupMembersID.set(e,s.filter(e=>!t.includes(e)))}},this.instance=e}clear(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()}}class ye{constructor(t){var n=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=async function(e){const t={userID:n.instance.userID,version:n.syncedGroupsVersion,versionID:n.syncedGroupsVersionID},s=await n.instance.sendHttpRequest({reqFuncName:u.GetGroupVersion,data:t,operationID:e});n.syncedGroupsVersionID&&n.compareGroupVersionAndTrigger(s,e),n.syncedGroupsVersion=s.version,n.syncedGroupsVersionID=s.versionID},this.syncGroupInfoAndMemberVersion=async function(e){let t=[];const s=Object.keys(n.syncedGroupMemberVersion);if(t=s.length?s.map(e=>{var t,s;const r=n.syncedGroupMemberVersion[e];return{groupID:e,version:null!=(t=null==r?void 0:r.version)?t:0,versionID:null!=(s=null==r?void 0:r.versionID)?s:""}}):(await n.getJoinedGroupIDs(e)).map(e=>({groupID:e,version:0,versionID:""})),!t.length)return;const r={userID:n.instance.userID,reqList:t},{respList:i}=await n.instance.sendHttpRequest({reqFuncName:u.GetGroupMemberVersion,data:r,operationID:e});Object.keys(n.syncedGroupMemberVersion).length>0&&n.compareGroupMemberVersionAndTrigger(i,e),n.syncedGroupMemberVersion=i;for(let[e,t]of Object.entries(i))t.group&&n.instance.groupTrigger.cache.updateCachedGroups([t.group]),(t.insert||t.update)&&n.instance.groupTrigger.cache.updateCachedGroupMembers(t.insert||t.update)},this.compareGroupVersionAndTrigger=(e,t)=>{const{insert:n,delete:s}=e;(null!=n?n:[]).map(e=>{this.instance.triggerEvent({event:l.OnJoinedGroupAdded,data:e,operationID:t})}),(null!=s?s:[]).map(e=>{this.instance.triggerEvent({event:l.OnJoinedGroupDeleted,data:{groupID:e},operationID:t}),this.instance.groupTrigger.cache.clearCachedGroupMembers(e)})},this.compareGroupMemberVersionAndTrigger=(e,t)=>{for(let[n,s]of Object.entries(e)){const{group:e,insert:r,update:i,delete:o}=s;e&&(this.instance.groupTrigger.updateCachedGroupInfoAndTrigger(e,t),this.instance.groupTrigger.checkConversationUpdate(e)),(null!=r?r:[]).map(e=>{this.instance.triggerEvent({event:l.OnGroupMemberAdded,data:e,operationID:t})}),(null!=i?i:[]).map(e=>this.instance.groupTrigger.updateCachedGroupMemberInfoAndTrigger(e,t)),(null!=o?o:[]).map(e=>{this.instance.triggerEvent({event:l.OnGroupMemberDeleted,data:{groupID:n,userID:e},operationID:t})})}},this.getJoinedGroupIDs=async function(e){const t={idHash:0,userID:n.instance.userID},{groupIDs:s}=await n.instance.sendHttpRequest({reqFuncName:u.GetJoinedGroupIDList,data:t,operationID:e});return null!=s?s:[]},this.addGroupMemberVersion=(e,t)=>{this.syncedGroupMemberVersion[e]=o({},t)},this.updateGroupMemberVersion=(t,n)=>{this.syncedGroupMemberVersion[t]?this.syncedGroupMemberVersion[t]=o({},n):e.warn("updateGroupMemberVersion: group member version not found",t,"new version",n)},this.instance=t}reset(){this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={}}}class Ce{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredEventMap={[l.OnGroupApplicationAdded]:new Map,[l.OnGroupApplicationAccepted]:new Map,[l.OnGroupApplicationRejected]:new Map},this.sync=e=>{const t=[this.syncer.syncGroupVersion(e),this.syncer.syncGroupInfoAndMemberVersion(e)];return Promise.all(t)},this.setTriggeredEventMap=(e,t)=>{this.triggeredEventMap[e].set(t,!0)},this.checkConversationUpdate=e=>{const t=`sg_${e.groupID}`,n=this.instance.messageTrigger.cache.getCachedConversation(t);!n||n.showName===e.groupName&&n.faceURL===e.faceURL||this.instance.messageTrigger.getOneConversationAndTryChange(t,"",{showName:e.groupName,faceURL:e.faceURL})},this.getDesignatedGroupApplicationAndTrigger=async function({event:e,userID:t,groupID:s,operationID:r,activeTrigger:i=!1}){if(!i&&n.triggeredEventMap[e].has(r))return void n.triggeredEventMap[e].delete(r);const o={groupID:s,userID:null!=t?t:n.instance.userID},{groupRequests:a}=await n.instance.sendHttpRequest({reqFuncName:u.GetDesignatedGroupApplication,data:o,operationID:r});a&&n.instance.triggerEvent({event:e,operationID:r,data:a.map(oe)[0]})},this.updateCachedGroupInfoAndTrigger=(e,t)=>{this.cache.updateCachedGroups([e]),this.instance.triggerEvent({event:l.OnGroupInfoChanged,data:e,operationID:t})},this.updateCachedGroupMemberInfoAndTrigger=(e,t)=>{this.cache.updateCachedGroupMembers([e]),this.instance.triggerEvent({event:l.OnGroupMemberInfoChanged,data:e,operationID:t})},this.parseMessageAndTrigger=async function(t,s){switch(t.contentType){case v.JoinGroupApplicationNotification:{var r,i;const o=de(t.content);e.debug("Recv JoinGroupApplicationNotification with opid: ",s,"tips: ",o),await n.getDesignatedGroupApplicationAndTrigger({event:l.OnGroupApplicationAdded,userID:null==(r=o.applicant)?void 0:r.userID,groupID:null==(i=o.group)?void 0:i.groupID,operationID:s});break}case v.GroupApplicationAcceptedNotification:{var o,a;const r=de(t.content);e.debug("Recv GroupApplicationAcceptedNotification with opid: ",s,"tips: ",r),await n.getDesignatedGroupApplicationAndTrigger({event:l.OnGroupApplicationAccepted,userID:r.receiverAs?null==(o=r.opUser)?void 0:o.userID:void 0,groupID:null==(a=r.group)?void 0:a.groupID,operationID:s});break}case v.GroupApplicationRejectedNotification:{var c,d;const r=de(t.content);e.debug("Recv GroupApplicationRejectedNotification with opid: ",s,"tips: ",r),await n.getDesignatedGroupApplicationAndTrigger({event:l.OnGroupApplicationRejected,userID:r.receiverAs?null==(c=r.opUser)?void 0:c.userID:void 0,groupID:null==(d=r.group)?void 0:d.groupID,operationID:s});break}case v.GroupCreatedNotification:{const r=de(t.content);e.debug("Recv GroupCreatedNotification with opid: ",s,"tips: ",r),n.cache.updateCachedGroups([r.group]),await n.syncer.syncGroupVersion(s),n.syncer.addGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID});break}case v.GroupInfoSetNotification:{const r=de(t.content);e.debug("Recv GroupInfoSetNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.checkConversationUpdate(r.group),n.updateCachedGroupInfoAndTrigger(r.group,s);break}case v.MemberQuitNotification:{var g,u,p;const r=de(t.content);e.debug("Recv MemberQuitNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s),n.cache.tryDeleteCachedGroupMembersID(null==(g=r.group)?void 0:g.groupID,[null==(u=r.quitUser)?void 0:u.userID]);const i=(null==(p=r.quitUser)?void 0:p.userID)===n.instance.userID;i&&await n.syncer.syncGroupVersion(s),i||n.instance.triggerEvent({event:l.OnGroupMemberDeleted,data:r.quitUser,operationID:s});break}case v.GroupOwnerTransferredNotification:{const r=de(t.content);e.debug("Recv GroupOwnerTransferredNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s),n.updateCachedGroupMemberInfoAndTrigger(r.oldGroupOwnerInfo,s),n.updateCachedGroupMemberInfoAndTrigger(r.newGroupOwner,s);break}case v.MemberKickedNotification:{var h;const r=de(t.content);e.debug("Recv MemberKickedNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s),n.cache.tryDeleteCachedGroupMembersID(null==(h=r.group)?void 0:h.groupID,r.kickedUserList.map(e=>e.userID));const i=r.kickedUserList.find(e=>e.userID===n.instance.userID);i&&await n.syncer.syncGroupVersion(s),i||r.kickedUserList.map(e=>n.instance.triggerEvent({event:l.OnGroupMemberDeleted,data:e,operationID:s}));break}case v.MemberInvitedNotification:{var f;const r=de(t.content);e.debug("Recv MemberInvitedNotification with opid: ",s,"tips: ",r);const i=r.invitedUserList.find(e=>e.userID===n.instance.userID);i&&(await n.syncer.syncGroupVersion(s),n.syncer.addGroupMemberVersion(r.group.groupID,{})),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s),n.checkConversationUpdate(r.group),n.cache.tryAddCachedGroupMembersID(null==(f=r.group)?void 0:f.groupID,r.invitedUserList.map(e=>e.userID)),i||r.invitedUserList.map(e=>n.instance.triggerEvent({event:l.OnGroupMemberAdded,data:e,operationID:s}));break}case v.MemberEnterNotification:{var m,I,D;const r=de(t.content);e.debug("Recv MemberEnterNotification with opid: ",s,"tips: ",r);const i=(null==(m=r.entrantUser)?void 0:m.userID)===n.instance.userID;i&&(await n.syncer.syncGroupVersion(s),n.syncer.addGroupMemberVersion(r.group.groupID,{})),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s),n.checkConversationUpdate(r.group),n.cache.tryAddCachedGroupMembersID(null==(I=r.group)?void 0:I.groupID,[null==(D=r.entrantUser)?void 0:D.userID]),i||n.instance.triggerEvent({event:l.OnGroupMemberAdded,data:r.entrantUser,operationID:s});break}case v.GroupDismissedNotification:{const r=de(t.content);e.debug("Recv GroupDismissedNotification with opid: ",s,"tips: ",r),await n.syncer.syncGroupVersion(s),n.updateCachedGroupInfoAndTrigger(r.group,s),n.instance.triggerEvent({event:l.OnGroupDismissed,data:r.group,operationID:s});break}case v.GroupMemberMutedNotification:{const r=de(t.content);e.debug("Recv GroupMemberMutedNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(r.mutedUser,s);break}case v.GroupMemberCancelMutedNotification:{const r=de(t.content);e.debug("Recv GroupMemberCancelMutedNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(r.mutedUser,s);break}case v.GroupMutedNotification:{const r=de(t.content);e.debug("Recv GroupMutedNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s);break}case v.GroupCancelMutedNotification:{const r=de(t.content);e.debug("Recv GroupCancelMutedNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s);break}case v.GroupMemberInfoSetNotification:{const r=de(t.content);e.debug("Recv GroupMemberInfoSetNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(r.changedUser,s);break}case v.GroupMemberSetToAdminNotification:{const r=de(t.content);e.debug("Recv GroupMemberSetToAdminNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(r.changedUser,s);break}case v.GroupMemberSetToOrdinaryUserNotification:{const r=de(t.content);e.debug("Recv GroupMemberSetToOrdinaryUserNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(r.changedUser,s);break}case v.GroupInfoSetAnnouncementNotification:{const r=de(t.content);e.debug("Recv GroupInfoSetAnnouncementNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(r.group,s);break}case v.GroupInfoSetNameNotification:{const r=de(t.content);e.debug("Recv GroupInfoSetNameNotification with opid: ",s,"tips: ",r),n.syncer.updateGroupMemberVersion(r.group.groupID,{version:r.groupMemberVersion,versionID:r.groupMemberVersionID}),n.checkConversationUpdate(r.group),n.updateCachedGroupInfoAndTrigger(r.group,s);break}}},this.instance=t,this.cache=new Se(t),this.syncer=new ye(t)}reset(){this.cache.clear(),this.syncer.reset(),Object.keys(this.triggeredEventMap).forEach(e=>{this.triggeredEventMap[e].clear()})}}class Ge{constructor(e){var t=this;this.instance=void 0,this.cachedFriendIDs=[],this.clear=()=>{this.cachedFriendIDs=[]},this.getFullFriendsIDs=async function(e){const n={idHash:0,userID:t.instance.userID},{userIDs:s}=await t.instance.sendHttpRequest({reqFuncName:u.GetFullFriendUserIDs,data:n,operationID:e});return t.cachedFriendIDs=null!=s?s:[],null!=s?s:[]},this.isFriend=e=>this.cachedFriendIDs.includes(e),this.addNewFriend=e=>{this.cachedFriendIDs.push(e)},this.deleteFriend=e=>{this.cachedFriendIDs=this.cachedFriendIDs.filter(t=>t!==e)},this.instance=e}}class Te{constructor(e){var t=this;this.instance=void 0,this.syncedFriendsVersion=0,this.syncedFriendsVersionID="",this.reset=()=>{this.syncedFriendsVersion=0,this.syncedFriendsVersionID=""},this.syncFriendVersion=async function(e){const n={userID:t.instance.userID,version:t.syncedFriendsVersion,versionID:t.syncedFriendsVersionID},s=await t.instance.sendHttpRequest({reqFuncName:u.GetFriendVersion,data:n,operationID:e});t.syncedFriendsVersionID&&t.compareVersionAndTrigger(s,e),t.syncedFriendsVersion=s.version,t.syncedFriendsVersionID=s.versionID},this.compareVersionAndTrigger=(e,t)=>{const{insert:n,update:s,delete:r}=e;(null!=n?n:[]).map(e=>{this.instance.triggerEvent({operationID:t,event:l.OnFriendAdded,data:ue(e)})}),(null!=s?s:[]).map(e=>{const n=ue(e);this.instance.triggerEvent({operationID:t,event:l.OnFriendInfoChanged,data:n});const s=[this.instance.userID,null==n?void 0:n.userID].sort(),r=`si_${s[0]}_${s[1]}`,i=this.instance.messageTrigger.cache.getCachedConversation(r);!i||i.showName===(n.remark||n.nickname)&&i.faceURL===n.faceURL||this.instance.messageTrigger.getOneConversationAndTryChange(r,t,{showName:n.remark||n.nickname,faceURL:n.faceURL})}),(null!=r?r:[]).map(e=>{this.instance.triggerEvent({operationID:t,event:l.OnFriendDeleted,data:{userID:e}})})},this.instance=e}}class Ae{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredEventMap={[l.OnFriendApplicationAdded]:new Map,[l.OnFriendApplicationAccepted]:new Map,[l.OnFriendApplicationRejected]:new Map,[l.OnFriendAdded]:new Map,[l.OnFriendDeleted]:new Map,[l.OnFriendInfoChanged]:new Map,[l.OnBlackAdded]:new Map,[l.OnBlackDeleted]:new Map},this.sync=e=>{const t=[this.syncer.syncFriendVersion(e),this.cache.getFullFriendsIDs(e)];return Promise.all(t)},this.reset=()=>{this.cache.clear(),this.syncer.reset(),Object.keys(this.triggeredEventMap).forEach(e=>{this.triggeredEventMap[e].clear()})},this.setTriggeredEventMap=(e,t)=>{this.triggeredEventMap[e].set(t,!0)},this.checkShouldTrigger=(e,t)=>!e||!this.triggeredEventMap[e].has(t)||(this.triggeredEventMap[e].delete(t),!1),this.getDesignatedFriendApplicationAndTrigger=async function(e,t,s,r=!1){if(!r&&n.triggeredEventMap[e].has(s))return void n.triggeredEventMap[e].delete(s);const i={fromUserID:t.fromUserID,toUserID:t.toUserID},{friendRequests:o}=await n.instance.sendHttpRequest({reqFuncName:u.GetDesignatedFriendsApplication,data:i,operationID:s});o&&n.instance.triggerEvent({event:e,operationID:s,data:o[0]})},this.getDesignatedBlackUserAndTrigger=async function(e,t,s,r=!1){if(!r&&n.triggeredEventMap[e].has(s))return void n.triggeredEventMap[e].delete(s);const i={ownerUserID:n.instance.userID,userIDList:[t]},{blacks:o}=await n.instance.sendHttpRequest({reqFuncName:u.GetDesignatedBlackUser,data:i,operationID:s});o&&n.instance.triggerEvent({event:e,data:o.map(pe)[0],operationID:s})},this.parseMessageAndTrigger=async function(t,s){switch(t.contentType){case v.FriendApplicationNotification:{const r=de(t.content);e.debug("Recv FriendApplicationNotification with opid: ",s,"tips: ",r),await n.getDesignatedFriendApplicationAndTrigger(l.OnFriendApplicationAdded,r.fromToUserID,s);break}case v.FriendApplicationApprovedNotification:{const r=de(t.content);e.debug("Recv FriendApplicationApprovedNotification with opid: ",s,"tips: ",r),await Promise.all([await n.getDesignatedFriendApplicationAndTrigger(l.OnFriendApplicationAccepted,r.fromToUserID,s),async function(){n.checkShouldTrigger(l.OnFriendAdded,s)&&await n.syncer.syncFriendVersion(s)}]);break}case v.FriendApplicationRejectedNotification:{const r=de(t.content);e.debug("Recv FriendApplicationRejectedNotification with opid: ",s,"tips: ",r),await n.getDesignatedFriendApplicationAndTrigger(l.OnFriendApplicationRejected,r.fromToUserID,s);break}case v.FriendAddedNotification:{var r;const i=de(t.content);if(e.debug("Recv FriendAddedNotification with opid: ",s,"tips: ",i),!n.checkShouldTrigger(l.OnFriendAdded,s))return;await n.syncer.syncFriendVersion(s),n.cache.addNewFriend(null==(r=i.friend)||null==(r=r.friendUser)?void 0:r.userID);break}case v.FriendDeletedNotification:{var i;const r=de(t.content);if(e.debug("Recv FriendDeletedNotification with opid: ",s,"tips: ",r),!n.checkShouldTrigger(l.OnFriendDeleted,s))return;await n.syncer.syncFriendVersion(s),n.cache.deleteFriend(null==(i=r.fromToUserID)?void 0:i.toUserID);break}case v.FriendRemarkSetNotification:{const r=de(t.content);if(e.debug("Recv FriendRemarkSetNotification with opid: ",s,"tips: ",r),!n.checkShouldTrigger(l.OnFriendInfoChanged,s))return;await n.syncer.syncFriendVersion(s);break}case v.FriendInfoUpdatedNotification:{const r=de(t.content);if(e.debug("Recv FriendInfoUpdatedNotification with opid: ",s,"tips: ",r),!n.checkShouldTrigger(l.OnFriendInfoChanged,s))return;await n.syncer.syncFriendVersion(s);break}case v.BlackAddedNotification:{var o;const r=de(t.content);e.debug("Recv BlackAddedNotification with opid: ",s,"tips: ",r),n.getDesignatedBlackUserAndTrigger(l.OnBlackAdded,null==(o=r.fromToUserID)?void 0:o.toUserID,s);break}case v.BlackDeletedNotification:{var a;const r=de(t.content);e.debug("Recv BlackDeletedNotification with opid: ",s,"tips: ",r),n.instance.triggerEvent({event:l.OnBlackDeleted,data:{userID:null==(a=r.fromToUserID)?void 0:a.toUserID},operationID:s});break}case v.FriendsInfoUpdateNotification:{const r=de(t.content);if(e.debug("Recv FriendsInfoUpdateNotification with opid: ",s,"tips: ",r),!n.checkShouldTrigger(l.OnFriendInfoChanged,s))return;await n.syncer.syncFriendVersion(s);break}}},this.instance=t,this.cache=new Ge(t),this.syncer=new Te(t)}}class Ne{constructor(t){var n=this;this.instance=void 0,this.parseMessageAndTrigger=async function(t,s){const r=de(t.content);e.debug("Recv BussinessMessage with opid: ",s,"tips: ",r),n.instance.triggerEvent({event:l.OnRecvCustomBusinessMessage,data:r,operationID:s})},this.instance=t}}class we{constructor(e){var t=this;this.instance=void 0,this.cachedLoginUserInfo=null,this.clear=()=>{this.cachedLoginUserInfo=null},this.getSelfUserInfo=()=>this.cachedLoginUserInfo,this.syncLoginUserInfoAndTrigger=async function(e){const n={userIDs:[t.instance.userID]},{usersInfo:s}=await t.instance.sendHttpRequest({reqFuncName:g.GetSelfUserInfo,data:n,operationID:e});t.cachedLoginUserInfo&&JSON.stringify(t.cachedLoginUserInfo)!==JSON.stringify(s[0])&&t.instance.triggerEvent({event:l.OnSelfInfoUpdated,data:s[0]}),t.cachedLoginUserInfo=s[0]},this.udpateCachedLoginUserInfoAndTrigger=async function(e,n){t.cachedLoginUserInfo&&(t.cachedLoginUserInfo=o({},t.cachedLoginUserInfo,e),t.instance.triggerEvent({event:l.OnSelfInfoUpdated,data:t.cachedLoginUserInfo,operationID:n}))},this.instance=e}}class be{constructor(e){var t=this;this.ctx=void 0,this.state=new Map,this.updateSubs=async function({sub:e,unSub:n,operationID:s}){if(0===t.state.size&&!e)return;const i=await t.ctx.sendReqWaitResp({reqIdentifier:f.WsSubUserOnlineStatus,operationID:s,data:r.SubUserOnlineStatus.encode({subscribeUserID:null!=e?e:Array.from(t.state.keys()),unsubscribeUserID:null!=n?n:[]}).finish()});null==i||i.subscribers.forEach(e=>t.state.set(e.userID,e.onlinePlatformIDs)),null!=n&&n.length&&n.forEach(e=>t.state.delete(e))},this.getUserOnlineState=async function(e,n){const s=e.filter(e=>!t.state.has(e));return s.length&&await t.updateSubs({operationID:n,sub:s}),e.map(e=>{var n,s;return{userID:e,status:null!=(n=t.state.get(e))&&n.length?1:0,platformIDs:null!=(s=t.state.get(e))?s:[]}})},this.getAllSubUsersOnlineState=()=>Array.from(this.state.keys()).map(e=>{var t,n;return{userID:e,status:null!=(t=this.state.get(e))&&t.length?1:0,platformIDs:null!=(n=this.state.get(e))?n:[]}}),this.userOnlineStateChange=({subscribers:e})=>{e.forEach(e=>{var t;e.onlinePlatformIDs.length?this.state.set(e.userID,e.onlinePlatformIDs):this.state.delete(e.userID),this.ctx.triggerEvent({event:l.OnUserStatusChanged,data:{userID:e.userID,status:e.onlinePlatformIDs.length?1:0,platformIDs:null!=(t=e.onlinePlatformIDs)?t:[]}})})},this.ctx=e}}class Re{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.onlineSub=void 0,this.triggeredEventMap=new Map,this.sync=e=>Promise.all([this.cache.syncLoginUserInfoAndTrigger(e),this.onlineSub.updateSubs({operationID:e})]),this.reset=()=>{this.cache.clear(),this.triggeredEventMap.clear()},this.setTriggeredEventMap=e=>{this.triggeredEventMap.set(e,!0)},this.checkConversationUpdate=e=>{const t=[this.instance.userID,e.userID].sort(),n=`si_${t[0]}_${t[1]}`,s=this.instance.messageTrigger.cache.getCachedConversation(n);!s||s.showName===e.nickname&&s.faceURL===e.faceURL||this.instance.messageTrigger.getOneConversationAndTryChange(n,"",{showName:e.nickname,faceURL:e.faceURL})},this.parseMessageAndTrigger=async function(t,s){if(t.contentType===v.UserInfoUpdatedNotification){const r=de(t.content);if(e.debug("Recv UserInfoUpdatedNotification with opid: ",s,"tips: ",r),n.triggeredEventMap.get(s))return void n.triggeredEventMap.delete(s);r.userID===n.instance.userID&&await n.cache.syncLoginUserInfoAndTrigger(s)}},this.instance=t,this.cache=new we(t),this.onlineSub=new be(t)}}class Ue{constructor(){this.queue=[],this.pending=!1}async enqueue(e){return new Promise((t,n)=>{this.queue.push(()=>e().then(t).catch(n)),this.pending||(this.pending=!0,this.dequeue())})}async dequeue(){for(;this.queue.length>0;){const t=this.queue.shift();try{await t()}catch(t){e.error("Error executing task:",t)}}this.pending=!1}}const Oe={[k.TextMessage]:"textElem",[k.AtTextMessage]:"atTextElem",[k.LocationMessage]:"locationElem",[k.CustomMessage]:"customElem",[k.MergeMessage]:"mergeElem",[k.QuoteMessage]:"quoteElem",[k.CardMessage]:"cardElem",[k.FaceMessage]:"faceElem",[k.PictureMessage]:"pictureElem",[k.VoiceMessage]:"soundElem",[k.VideoMessage]:"videoElem",[k.FileMessage]:"fileElem"},Fe=[u.GetActiveConversations,u.GetDesignatedConversation];class qe extends se{constructor(){var n,i;super(),n=this,this.userID=void 0,this.platform=void 0,this.token=void 0,this.apiAddr=void 0,this.loginStatus=P.Logout,this.isReconnected=!1,this.connectState="disconnected",this.wsManager=void 0,this.messageTrigger=void 0,this.userTrigger=void 0,this.groupTrigger=void 0,this.relationTrigger=void 0,this.businessTrigger=void 0,this.requestMap=new Map,this.generateHttpHeader=(e,t)=>{const n={"Content-Type":"application/json",token:this.token,operationID:t,reqFuncName:e};return Fe.includes(e)&&(n["Content-Type"]="application/x-protobuf"),n},this.sendHttpRequest=async function(e){var t;return await(e=>{const{url:t,data:n,headers:s,platform:r,method:i="POST"}=e;return"web"===r?(async({url:e,data:t,headers:n,method:s="POST"})=>fetch(e,{method:s,headers:o({},n),body:t instanceof Uint8Array?t:JSON.stringify(t)}).then(e=>{if(e.ok)return e.json();throw new Error(e.statusText)}).then(e=>{if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))(e):new Promise((e,a)=>{const c=(e=>"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null)(r);c?c({url:t,data:n instanceof Uint8Array?Uint8Array.from(n).buffer:n,method:i,header:o({"Content-Type":"application/json"},s),success:t=>{200===t.statusCode&&0===t.data.errCode?e(t.data.data):a(t.data||"Request failed")},fail:e=>{a(e)}}):a(new Error("Request is not supported"))})})({url:`${n.apiAddr}${e.replaceURL||p[e.reqFuncName]}`,data:e.data,headers:n.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(t=n.wsManager)?void 0:t.platformNamespace)||"web"})},this.handleWsConnected=async function(t,s){if(0===t.errCode){n.connectState="connected",n.loginStatus=P.Logged,n.triggerEvent({event:l.OnConnectSuccess}),n.triggerEvent({event:l.OnSyncServerStart});const t=[n.messageTrigger.sync(s),n.relationTrigger.sync(s),n.groupTrigger.sync(s),n.userTrigger.sync(s)];try{await Promise.all(t),n.triggerEvent({event:l.OnSyncServerFinish})}catch(t){e.error(t),n.triggerEvent({event:l.OnSyncServerFailed,errCode:t.errCode||h.SdkInternalError,errMsg:t.message||"Internal Error"})}}else{n.triggerEvent({event:l.OnConnectFailed,errCode:t.errCode,errMsg:t.errMsg,operationID:s});const e=G[t.errCode];e&&n.triggerEvent({event:e,errCode:t.errCode,errMsg:t.errMsg,operationID:s}),n.connectState="disconnected",n.loginStatus=P.Logout}},this.handleMessage=async function(e,t){if("string"==typeof e){const s=JSON.parse(e);n.handleWsConnected(s,t)}else{e instanceof ArrayBuffer||(e=await e.arrayBuffer());const t=Z(e),s=JSON.parse(t);n.handleGeneralWsResp(s)}},this.handleGeneralWsResp=e=>{const t=K(e.data,e.reqIdentifier);if(e.reqIdentifier===f.PushMsg&&t)return this.messageTrigger.triggerConversation(t.msgs,e.operationID),void this.messageTrigger.triggerNotification(t.notificationMsgs,e.operationID);if(e.reqIdentifier!==f.WsSubUserOnlineStatus||e.msgIncr||this.userTrigger.onlineSub.userOnlineStateChange(t),e.reqIdentifier===f.KickOnlineMsg)return this.triggerEvent({event:l.OnKickedOffline,operationID:e.operationID}),void this.reset();const n=this.requestMap.get(e.msgIncr);n&&(0===e.errCode?n.resolve(t):n.reject(new Y(e.errCode,e.errMsg)),this.requestMap.delete(e.msgIncr))},this.handleReconnecting=()=>{this.connectState="reconnecting",this.triggerEvent({event:l.OnConnecting})},this.handleReconnectFailed=()=>{this.connectState="disconnected",this.triggerEvent({event:l.OnConnectFailed,errCode:h.NetworkError,errMsg:"network error"})},this.handleReconnectSuccess=()=>{this.isReconnected=!0},this.sendReqWaitResp=({data:e,reqIdentifier:t,operationID:n})=>{if("connected"!==this.connectState)throw new Y(h.NetworkError,"network error, ws not connected");const r=H();return new Promise((i,o)=>{var a;this.requestMap.set(r,{resolve:i,reject:o}),null==(a=this.wsManager)||a.sendMessage({reqIdentifier:t,msgIncr:r,sendID:this.userID,operationID:n,data:s(e.buffer)})})},this.triggerEvent=({event:t,data:n=null,errCode:s=0,errMsg:r="",operationID:i=""})=>{this.loginStatus!==P.Logout&&(e.debug(`%cSDK =>%c [OperationID:${i}] (event) trigger ${t} with data ${JSON.stringify(n)} errCode ${s} errMsg ${r}`,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),this.emit(t,{event:t,data:n,errCode:s,errMsg:r,operationID:i}))},this.login=async function(t,s){return X(P.Logged,g.Login,s,async function(){var r;const{userID:i,token:o,wsAddr:a,apiAddr:c,platformID:d}=t;if(n.wsManager)throw new Y(h.LoginRepeatError,"login repeat");e.setLevel(null!=(r=t.logLevel)?r:F.Debug),n.userID=i,n.token=o,n.apiAddr=c,n.platform=d,n.wsManager=new ne(a,{sendID:i,token:o,platformID:d,operationID:s,isBackground:!1,isMsgResp:!0,sdkType:"js"},n.handleMessage,n.handleReconnecting,n.handleReconnectFailed,n.handleReconnectSuccess),n.connectState="connecting",n.loginStatus=P.Logging,n.triggerEvent({event:l.OnConnecting,operationID:s});try{await n.wsManager.connect()}catch(e){throw n.triggerEvent({event:l.OnConnectFailed,errCode:h.NetworkError,errMsg:e.message||"network error",operationID:s}),n.connectState="disconnected",n.loginStatus=P.Logout,n.wsManager.close(),new Y(h.NetworkError,e.message||"network error")}})},this.getLoginStatus=e=>X(P.Logged,g.GetLoginStatus,e,async function(){var e;return null==(e=n.wsManager)||e.sendPing(),n.loginStatus}),this.logout=e=>X(this.loginStatus,g.Logout,e,async function(){n.reset()}),this.internalUploadFile=async function(e,s){try{const r=`${n.userID}/${e.name}`,i=(e=>{var t,n;const s=null!=(t=null==(n=e.split(".").pop())?void 0:n.toLowerCase())?t:"";return d[s]||"application/octet-stream"})(e.name),a={operationID:s,token:n.token},{size:g}=await((e,t,n)=>fetch(`${e}/object/part_size`,{method:"POST",headers:o({},n),body:JSON.stringify({size:t})}).then(c))(n.apiAddr,e.size,a),u=Math.ceil(e.size/g),p=[],l=[],h=new t.ArrayBuffer;let f=0;for(;f{const n=new FileReader;n.readAsArrayBuffer(s),n.onload=t=>{t.target&&(h.append(t.target.result),e(h.end()))},n.onerror=e=>t(e)});l.push(r),f++}const m=l.join(",");h.destroy();const v=new t;v.append(m);const{url:I,upload:D}=await((e,t,n)=>fetch(`${e}/object/initiate_multipart_upload`,{method:"POST",headers:o({},n),body:JSON.stringify(t)}).then(c))(n.apiAddr,{hash:v.end(),size:e.size,partSize:g,maxParts:-1,cause:"",name:r,contentType:i},a);if(v.destroy(),I)return{url:I};let M=D.sign.parts;const S=D.sign.query,y=D.sign.header;await Promise.all(M.map(async function(t,n){const s=new URL(t.url||D.sign.url);if(S){const e=new URLSearchParams(s.search);S.forEach(t=>{e.set(t.key,t.values[0])}),s.search=e.toString()}if(t.query){const e=new URLSearchParams(s.search);t.query.forEach(t=>{e.set(t.key,t.values[0])}),s.search=e.toString()}const r=s.toString(),o=new Headers;if(y&&y.forEach(e=>{o.set(e.key,e.values[0])}),t.header&&t.header.forEach(e=>{o.set(e.key,e.values[0])}),o.set("Content-Length",(p[n].end-p[n].start).toString()),o.set("Content-Type",i),!(await fetch(r,{method:"PUT",headers:o,body:e.slice(p[n].start,p[n].end)})).ok)throw new Error(`Failed to upload chunk ${n+1}`)}));const{url:C}=await((e,t,n)=>fetch(`${e}/object/complete_multipart_upload`,{method:"POST",headers:o({},n),body:JSON.stringify(t)}).then(c))(n.apiAddr,{uploadID:D.uploadID,parts:l,cause:"",name:r,contentType:i},a);return{url:C}}catch(e){return{error:e}}},this.uploadFile=async function(e,t){return X(n.loginStatus,g.UploadFile,t,async function(){const{url:s="",error:r}=await n.internalUploadFile(e.file,t);if(r)throw new Y(h.SdkInternalError,r.message);return{url:s}})},this.reset=()=>{var e;null==(e=this.wsManager)||e.close(),this.wsManager=void 0,this.userID=void 0,this.token=void 0,this.apiAddr=void 0,this.isReconnected=!1,this.loginStatus=P.Logout,this.connectState="disconnected",this.messageTrigger.reset(),this.userTrigger.reset(),this.groupTrigger.reset(),this.relationTrigger.reset()},this.getSelfUserInfo=void 0,this.setSelfInfo=void 0,this.getUsersInfo=void 0,this.subscribeUsersStatus=void 0,this.unsubscribeUsersStatus=void 0,this.getSubscribeUsersStatus=void 0,this.acceptFriendApplication=void 0,this.addBlack=void 0,this.addFriend=void 0,this.updateFriends=void 0,this.checkFriend=void 0,this.deleteFriend=void 0,this.getBlackList=void 0,this.getFriendApplicationListAsApplicant=void 0,this.getFriendApplicationListAsRecipient=void 0,this.getFriendListPage=void 0,this.getSpecifiedFriendsInfo=void 0,this.refuseFriendApplication=void 0,this.removeBlack=void 0,this.createGroup=void 0,this.joinGroup=void 0,this.inviteUserToGroup=void 0,this.getJoinedGroupListPage=void 0,this.getSpecifiedGroupsInfo=void 0,this.setGroupInfo=void 0,this.getGroupApplicationListAsRecipient=void 0,this.getGroupApplicationListAsApplicant=void 0,this.acceptGroupApplication=void 0,this.refuseGroupApplication=void 0,this.getGroupMemberList=void 0,this.getSpecifiedGroupMembersInfo=void 0,this.setGroupMemberInfo=void 0,this.kickGroupMember=void 0,this.changeGroupMemberMute=void 0,this.changeGroupMute=void 0,this.transferGroupOwner=void 0,this.dismissGroup=void 0,this.quitGroup=void 0,this.getUsersInGroup=void 0,this.createTextMessage=void 0,this.createTextAtMessage=void 0,this.createLocationMessage=void 0,this.createCustomMessage=void 0,this.createQuoteMessage=void 0,this.createCardMessage=void 0,this.createImageMessageByURL=void 0,this.createImageMessageByFile=void 0,this.createSoundMessageByURL=void 0,this.createSoundMessageByFile=void 0,this.createVideoMessageByURL=void 0,this.createVideoMessageByFile=void 0,this.createFileMessageByURL=void 0,this.createFileMessageByFile=void 0,this.createMergerMessage=void 0,this.createFaceMessage=void 0,this.createForwardMessage=void 0,this.sendMessage=void 0,this.sendMessageNotOss=void 0,this.revokeMessage=void 0,this.getAdvancedHistoryMessageList=void 0,this.deleteMessage=void 0,this.deleteAllMsgFromLocalAndSvr=void 0,this.getConversationListSplit=void 0,this.getOneConversation=void 0,this.setConversation=void 0,this.getTotalUnreadMsgCount=void 0,this.markConversationMessageAsRead=void 0,this.clearConversationAndDeleteAllMsg=void 0,this.changeInputStates=void 0,this.getInputStates=void 0,this.userTrigger=new Re(this),this.groupTrigger=new Ce(this),this.relationTrigger=new Ae(this),this.businessTrigger=new Ne(this),this.messageTrigger=new Me(this),Object.assign(this,(i=this,{addFriend:async(e,t)=>X(i.loginStatus,g.AddFriend,t,async()=>{const n={fromUserID:i.userID,toUserID:e.toUserID,reqMsg:e.reqMsg,ex:e.ex||""};await i.sendHttpRequest({reqFuncName:g.AddFriend,data:n,operationID:t}),i.relationTrigger.setTriggeredEventMap(l.OnFriendApplicationAdded,t),i.relationTrigger.getDesignatedFriendApplicationAndTrigger(l.OnFriendApplicationAdded,{fromUserID:i.userID,toUserID:e.toUserID},t,!0)}),checkFriend:async(e,t)=>X(i.loginStatus,g.CheckFriend,t,async()=>{const n=e.map(e=>i.sendHttpRequest({reqFuncName:g.CheckFriend,data:{userID1:i.userID,userID2:e},operationID:t}));return(await Promise.all(n)).map((t,n)=>({result:Number(t.inUser1Friends),userID:e[n]}))}),deleteFriend:async(e,t)=>X(i.loginStatus,g.DeleteFriend,t,async()=>{const n={ownerUserID:i.userID,friendUserID:e};await i.sendHttpRequest({reqFuncName:g.DeleteFriend,data:n,operationID:t}),i.relationTrigger.setTriggeredEventMap(l.OnFriendDeleted,t),i.relationTrigger.syncer.syncFriendVersion(t)}),acceptFriendApplication:async(e,t)=>X(i.loginStatus,g.AcceptFriendApplication,t,async()=>{const n={fromUserID:e.toUserID,toUserID:i.userID,handleResult:q.Agree,handleMsg:e.handleMsg};await i.sendHttpRequest({reqFuncName:g.AcceptFriendApplication,data:n,operationID:t}),i.relationTrigger.setTriggeredEventMap(l.OnFriendApplicationAccepted,t),i.relationTrigger.setTriggeredEventMap(l.OnFriendAdded,t),i.relationTrigger.getDesignatedFriendApplicationAndTrigger(l.OnFriendApplicationAccepted,{fromUserID:i.userID,toUserID:e.toUserID},t,!0),i.relationTrigger.syncer.syncFriendVersion(t)}),refuseFriendApplication:async(e,t)=>X(i.loginStatus,g.RefuseFriendApplication,t,async()=>{const n={fromUserID:e.toUserID,toUserID:i.userID,handleResult:q.Reject,handleMsg:e.handleMsg};await i.sendHttpRequest({reqFuncName:g.RefuseFriendApplication,data:n,operationID:t}),i.relationTrigger.setTriggeredEventMap(l.OnFriendApplicationRejected,t),i.relationTrigger.getDesignatedFriendApplicationAndTrigger(l.OnFriendApplicationRejected,{fromUserID:i.userID,toUserID:e.toUserID},t,!0)}),getFriendListPage:async(e,t)=>X(i.loginStatus,g.GetFriendListPage,t,async()=>{const n={userID:i.userID,pagination:{pageNumber:Math.round(e.offset/e.count)+1,showNumber:e.count}},{friendsInfo:s}=await i.sendHttpRequest({reqFuncName:g.GetFriendListPage,data:n,operationID:t});return(null!=s?s:[]).map(ue)}),getSpecifiedFriendsInfo:async(e,t)=>X(i.loginStatus,g.GetSpecifiedFriendsInfo,t,async()=>{const n={ownerUserID:i.userID,friendUserIDs:e},{friendsInfo:s}=await i.sendHttpRequest({reqFuncName:g.GetSpecifiedFriendsInfo,data:n,operationID:t});return(null!=s?s:[]).map(ue)}),getFriendApplicationListAsApplicant:async(e,t)=>X(i.loginStatus,g.GetFriendApplicationListAsApplicant,t,async()=>{const{offset:n,count:s}=e,r={userID:i.userID,pagination:{pageNumber:Math.round(n/s)+1,showNumber:s}},{friendRequests:o}=await i.sendHttpRequest({reqFuncName:g.GetFriendApplicationListAsApplicant,data:r,operationID:t});return null!=o?o:[]}),getFriendApplicationListAsRecipient:async(e,t)=>X(i.loginStatus,g.GetFriendApplicationListAsRecipient,t,async()=>{const{offset:n,count:s}=e,r={userID:i.userID,pagination:{pageNumber:Math.round(n/s)+1,showNumber:s}},{FriendRequests:o}=await i.sendHttpRequest({reqFuncName:g.GetFriendApplicationListAsRecipient,data:r,operationID:t});return null!=o?o:[]}),updateFriends:async(e,t)=>X(i.loginStatus,g.UpdateFriends,t,async()=>{await i.sendHttpRequest({reqFuncName:g.UpdateFriends,data:{ownerUserID:i.userID,friendUserIDs:e.friendUserIDs,remark:e.remark,isPinned:e.isPinned,ex:e.ex},operationID:t}),i.relationTrigger.setTriggeredEventMap(l.OnFriendInfoChanged,t),i.relationTrigger.syncer.syncFriendVersion(t)}),addBlack:async(e,t)=>X(i.loginStatus,g.AddBlack,t,async()=>{const n={ownerUserID:i.userID,blackUserID:e.toUserID,ex:e.ex};await i.sendHttpRequest({reqFuncName:g.AddBlack,data:n,operationID:t}),i.relationTrigger.setTriggeredEventMap(l.OnBlackAdded,t),i.relationTrigger.getDesignatedBlackUserAndTrigger(l.OnBlackAdded,e.toUserID,t,!0)}),removeBlack:async(e,t)=>X(i.loginStatus,g.RemoveBlack,t,async()=>{const n={ownerUserID:i.userID,blackUserID:e};await i.sendHttpRequest({reqFuncName:g.RemoveBlack,data:n,operationID:t}),i.relationTrigger.setTriggeredEventMap(l.OnBlackDeleted,t),i.relationTrigger.getDesignatedBlackUserAndTrigger(l.OnBlackDeleted,e,t,!0)}),getBlackList:async(e,t)=>X(i.loginStatus,g.GetBlackList,t,async()=>{const{offset:n,count:s}=e,r={userID:i.userID,pagination:{pageNumber:Math.round(n/s)+1,showNumber:s}},{blacks:o}=await i.sendHttpRequest({reqFuncName:g.GetBlackList,data:r,operationID:t});return(null!=o?o:[]).map(pe)})})),Object.assign(this,function(e){return{createGroup:async(t,n)=>X(e.loginStatus,g.CreateGroup,n,async()=>{var s;const r={ownerUserID:e.userID,memberUserIDs:t.memberUserIDs,adminUserIDs:null!=(s=t.adminUserIDs)?s:[],groupInfo:o({},t.groupInfo,{groupType:2,creatorUserID:e.userID})},{groupInfo:i}=await e.sendHttpRequest({reqFuncName:g.CreateGroup,data:r,operationID:n});return i}),joinGroup:async(t,n)=>X(e.loginStatus,g.JoinGroup,n,async()=>{var s;const r={groupID:t.groupID,reqMessage:t.reqMsg,joinSource:t.joinSource,inviterUserID:e.userID,ex:null!=(s=t.ex)?s:""};return await e.sendHttpRequest({reqFuncName:g.JoinGroup,data:r,operationID:n}),e.groupTrigger.setTriggeredEventMap(l.OnGroupApplicationAdded,n),e.groupTrigger.getDesignatedGroupApplicationAndTrigger({event:l.OnGroupApplicationAdded,groupID:t.groupID,operationID:n,activeTrigger:!0}),null}),inviteUserToGroup:async(t,n)=>X(e.loginStatus,g.InviteUserToGroup,n,async()=>{const s={groupID:t.groupID,reason:t.reason,invitedUserIDs:t.userIDList};return await e.sendHttpRequest({reqFuncName:g.InviteUserToGroup,data:s,operationID:n}),null}),getJoinedGroupListPage:async(t,n)=>X(e.loginStatus,g.GetJoinedGroupListPage,n,async()=>{const s={fromUserID:e.userID,pagination:{pageNumber:Math.round(t.offset/t.count)+1,showNumber:t.count}},{groups:r}=await e.sendHttpRequest({reqFuncName:g.GetJoinedGroupListPage,data:s,operationID:n});return r&&e.groupTrigger.cache.updateCachedGroups(r),null!=r?r:[]}),getSpecifiedGroupsInfo:async(t,n)=>X(e.loginStatus,g.GetSpecifiedGroupsInfo,n,()=>e.groupTrigger.cache.getGroupInfosWithCache(t,n)),setGroupInfo:async(t,n)=>X(e.loginStatus,g.SetGroupInfo,n,async()=>(await e.sendHttpRequest({reqFuncName:g.SetGroupInfo,data:t,operationID:n}),null)),acceptGroupApplication:async(t,n)=>X(e.loginStatus,g.AcceptGroupApplication,n,async()=>{const s={groupID:t.groupID,fromUserID:t.fromUserID,handledMsg:t.handleMsg,handleResult:q.Agree};return await e.sendHttpRequest({reqFuncName:g.AcceptGroupApplication,data:s,operationID:n}),e.groupTrigger.setTriggeredEventMap(l.OnGroupApplicationAccepted,n),e.groupTrigger.getDesignatedGroupApplicationAndTrigger({event:l.OnGroupApplicationAccepted,groupID:t.groupID,operationID:n,activeTrigger:!0}),null}),refuseGroupApplication:async(t,n)=>X(e.loginStatus,g.RefuseGroupApplication,n,async()=>{const s={groupID:t.groupID,fromUserID:t.fromUserID,handledMsg:t.handleMsg,handleResult:q.Reject};return await e.sendHttpRequest({reqFuncName:g.RefuseGroupApplication,data:s,operationID:n}),e.groupTrigger.setTriggeredEventMap(l.OnGroupApplicationRejected,n),e.groupTrigger.getDesignatedGroupApplicationAndTrigger({event:l.OnGroupApplicationRejected,groupID:t.groupID,operationID:n,activeTrigger:!0}),null}),getGroupMemberList:async(t,n)=>X(e.loginStatus,g.GetGroupMemberList,n,async()=>{const s={filter:0,keyword:"",groupID:t.groupID,pagination:{pageNumber:Math.round(t.offset/t.count)+1,showNumber:t.count}},{members:r}=await e.sendHttpRequest({reqFuncName:g.GetGroupMemberList,data:s,operationID:n});return r&&e.groupTrigger.cache.updateCachedGroupMembers(r),null!=r?r:[]}),getSpecifiedGroupMembersInfo:async(t,n)=>X(e.loginStatus,g.GetSpecifiedGroupMembersInfo,n,()=>e.groupTrigger.cache.getGroupMembersWithCache(o({},t,{operationID:n}))),setGroupMemberInfo:async(t,n)=>X(e.loginStatus,g.SetGroupMemberInfo,n,async()=>(await e.sendHttpRequest({reqFuncName:g.SetGroupMemberInfo,data:{members:[o({},t)]},operationID:n}),null)),kickGroupMember:async(t,n)=>X(e.loginStatus,g.KickGroupMember,n,async()=>{const s={reason:t.reason,groupID:t.groupID,kickedUserIDs:t.userIDList};return await e.sendHttpRequest({reqFuncName:g.KickGroupMember,data:s,operationID:n}),null}),changeGroupMemberMute:async(t,n)=>X(e.loginStatus,g.ChangeGroupMemberMute,n,async()=>{const s={groupID:t.groupID,userID:t.userID,mutedSeconds:t.mutedSeconds};return await e.sendHttpRequest({replaceURL:t.mutedSeconds?"/group/mute_group_member":"/group/cancel_mute_group_member",reqFuncName:g.ChangeGroupMemberMute,data:s,operationID:n}),null}),changeGroupMute:async(t,n)=>X(e.loginStatus,g.ChangeGroupMute,n,async()=>{const s={groupID:t.groupID};return await e.sendHttpRequest({replaceURL:t.isMute?"/group/mute_group":"/group/cancel_mute_group",reqFuncName:g.ChangeGroupMute,data:s,operationID:n}),null}),transferGroupOwner:async(t,n)=>X(e.loginStatus,g.TransferGroupOwner,n,async()=>{const s={groupID:t.groupID,oldOwnerUserID:e.userID,newOwnerUserID:t.newOwnerUserID};return await e.sendHttpRequest({reqFuncName:g.TransferGroupOwner,data:s,operationID:n}),null}),dismissGroup:async(t,n)=>X(e.loginStatus,g.DismissGroup,n,async()=>{const s={groupID:t,deleteMember:!1};return await e.sendHttpRequest({reqFuncName:g.DismissGroup,data:s,operationID:n}),null}),quitGroup:async(t,n)=>X(e.loginStatus,g.QuitGroup,n,async()=>{const s={groupID:t,userID:e.userID};return await e.sendHttpRequest({reqFuncName:g.QuitGroup,data:s,operationID:n}),null}),getGroupApplicationListAsRecipient:async(t,n)=>X(e.loginStatus,g.GetGroupApplicationListAsRecipient,n,async()=>{const{offset:s,count:r}=t,i={fromUserID:e.userID,pagination:{pageNumber:Math.round(s/r)+1,showNumber:r}},{groupRequests:o}=await e.sendHttpRequest({reqFuncName:g.GetGroupApplicationListAsRecipient,data:i,operationID:n});return(null!=o?o:[]).map(oe)}),getGroupApplicationListAsApplicant:async(t,n)=>X(e.loginStatus,g.GetGroupApplicationListAsApplicant,n,async()=>{const{offset:s,count:r}=t,i={userID:e.userID,pagination:{pageNumber:Math.round(s/r)+1,showNumber:r}},{groupRequests:o}=await e.sendHttpRequest({reqFuncName:g.GetGroupApplicationListAsApplicant,data:i,operationID:n});return(null!=o?o:[]).map(oe)}),getUsersInGroup:async(t,n)=>X(e.loginStatus,g.GetUsersInGroup,n,async()=>{var s;e.groupTrigger.cache.hasCachedGroupMembersID(t.groupID)||await e.groupTrigger.cache.getGroupMembersID(t.groupID,n);const r=e.groupTrigger.cache.getCachedGroupMembersID(t.groupID);return null==(s=t.userIDList)?void 0:s.filter(e=>r.includes(e))})}}(this)),Object.assign(this,function(e){return{getSelfUserInfo:async t=>X(e.loginStatus,g.GetSelfUserInfo,t,async()=>{const n=e.userTrigger.cache.getSelfUserInfo();if(n)return n;const s={userIDs:[e.userID]},{usersInfo:r}=await e.sendHttpRequest({reqFuncName:g.GetSelfUserInfo,data:s,operationID:t});return(null!=r?r:[])[0]}),setSelfInfo:async(t,n)=>X(e.loginStatus,g.SetSelfInfo,n,async()=>{const s={userInfo:o({userID:e.userID},t)};return await e.sendHttpRequest({reqFuncName:g.SetSelfInfo,data:s,operationID:n}),e.userTrigger.setTriggeredEventMap(n),e.userTrigger.cache.udpateCachedLoginUserInfoAndTrigger(o({},t),n),null}),getUsersInfo:async(t,n)=>X(e.loginStatus,g.GetUsersInfo,n,async()=>{const s={userIDs:t},{usersInfo:r}=await e.sendHttpRequest({reqFuncName:g.GetUsersInfo,data:s,operationID:n}),i=null!=r?r:[];return i.filter(t=>!e.relationTrigger.cache.isFriend(t.userID)).map(e.userTrigger.checkConversationUpdate),i}),subscribeUsersStatus:async(t,n)=>X(e.loginStatus,g.SubscribeUsersStatus,n,()=>{if(!t.length)throw new Y(h.ArgsError,"sub users is empty");return e.userTrigger.onlineSub.getUserOnlineState(t,n)}),unsubscribeUsersStatus:async(t,n)=>X(e.loginStatus,g.UnsubscribeUsersStatus,n,async()=>{if(!t.length)throw new Y(h.ArgsError,"unSub users is empty");return await e.userTrigger.onlineSub.updateSubs({sub:[],unSub:t,operationID:n}),null}),getSubscribeUsersStatus:async t=>X(e.loginStatus,g.GetSubscribeUsersStatus,t,async()=>e.userTrigger.onlineSub.getAllSubUsersOnlineState())}}(this)),Object.assign(this,function(t){const n=new Map,s=new Ue;let i=null,a="";const c=async({maxSeq:e,count:n,conversationID:s,operationID:r,fetchedMessages:i=[]})=>{const o=[];for(let r=e;o.length{const o=[];for(let r=e;o.lengthi?t:i,count:n-a.length,conversationID:s,operationID:r,fetchedMessages:g})}return g};return{createTextMessage:(e,n)=>X(t.loginStatus,g.CreateTextMessage,n,async()=>{const n=z(t,I.UserMsgType,k.TextMessage);return n.textElem={content:e},n}),createTextAtMessage:(e,n)=>X(t.loginStatus,g.CreateTextAtMessage,n,async()=>{var n;if(!e.text)throw new Y(h.ArgsError,"text cannot be empty");if(e.atUserIDList.length>10)throw new Y(h.ArgsError,"atUserIDList length must be less than 10");const s=z(t,I.UserMsgType,k.AtTextMessage);var r;return(null==(n=e.message)?void 0:n.contentType)===k.QuoteMessage&&(e.message.contentType=k.TextMessage,e.message.textElem={content:null==(r=e.message.quoteElem)?void 0:r.text}),s.atTextElem={text:e.text,atUserList:e.atUserIDList,atUsersInfo:e.atUsersInfo,quoteMessage:e.message},s}),createLocationMessage:(e,n)=>X(t.loginStatus,g.CreateLocationMessage,n,async()=>{const n=z(t,I.UserMsgType,k.LocationMessage);return n.locationElem=o({},e),n}),createCustomMessage:(e,n)=>X(t.loginStatus,g.CreateCustomMessage,n,async()=>{const n=z(t,I.UserMsgType,k.CustomMessage);return n.customElem=o({},e),n}),createQuoteMessage:(e,n)=>X(t.loginStatus,g.CreateQuoteMessage,n,async()=>{const n=z(t,I.UserMsgType,k.QuoteMessage),s=JSON.parse(e.message);var r;return s.contentType===k.QuoteMessage&&(s.contentType=k.TextMessage,s.textElem={content:null==(r=s.quoteElem)?void 0:r.text}),n.quoteElem={text:e.text,quoteMessage:s},n}),createCardMessage:(e,n)=>X(t.loginStatus,g.CreateCardMessage,n,async()=>{const n=z(t,I.UserMsgType,k.CardMessage);return n.cardElem=o({},e),n}),createImageMessageByURL:(e,n)=>X(t.loginStatus,g.CreateImageMessageByURL,n,async()=>{const n=z(t,I.UserMsgType,k.PictureMessage);return n.pictureElem=o({},e),n}),createImageMessageByFile:async(e,s)=>X(t.loginStatus,g.CreateImageMessageByFile,s,async()=>{const s=z(t,I.UserMsgType,k.PictureMessage);return s.pictureElem=o({},e),n.set(e.sourcePicture.uuid,e.file),s}),createSoundMessageByURL:(e,n)=>X(t.loginStatus,g.CreateSoundMessageByURL,n,async()=>{const n=z(t,I.UserMsgType,k.VoiceMessage);return n.soundElem=o({},e),n}),createSoundMessageByFile:async(e,s)=>X(t.loginStatus,g.CreateSoundMessageByFile,s,async()=>{const s=z(t,I.UserMsgType,k.VoiceMessage);return s.soundElem=o({},e),n.set(e.uuid,e.file),s}),createVideoMessageByURL:(e,n)=>X(t.loginStatus,g.CreateVideoMessageByURL,n,async()=>{const n=z(t,I.UserMsgType,k.VideoMessage);return n.videoElem=o({},e),n}),createVideoMessageByFile:async(e,s)=>X(t.loginStatus,g.CreateVideoMessageByFile,s,async()=>{const s=z(t,I.UserMsgType,k.VideoMessage);return s.videoElem=o({},e),n.set(e.videoUUID,e.videoFile),n.set(e.snapshotUUID,e.snapshotFile),s}),createFileMessageByURL:(e,n)=>X(t.loginStatus,g.CreateFileMessageByURL,n,async()=>{const n=z(t,I.UserMsgType,k.FileMessage);return n.fileElem=o({},e),n}),createFileMessageByFile:async(e,s)=>X(t.loginStatus,g.CreateFileMessageByFile,s,async()=>{const s=z(t,I.UserMsgType,k.FileMessage);return s.fileElem=o({},e),n.set(e.uuid,e.file),s}),createMergerMessage:(e,n)=>X(t.loginStatus,g.CreateMergerMessage,n,async()=>{const n=z(t,I.UserMsgType,k.MergeMessage);return n.mergeElem={title:e.title,abstractList:e.summaryList,multiMessage:e.messageList,messageEntityList:[]},n}),createFaceMessage:(e,n)=>X(t.loginStatus,g.CreateFaceMessage,n,async()=>{const n=z(t,I.UserMsgType,k.FaceMessage);return n.faceElem=o({},e),n}),createForwardMessage:(e,n)=>X(t.loginStatus,g.CreateForwardMessage,n,async()=>{if(e.status!==U.Succeed)throw new Y(h.ArgsError,"Only successfully sent messages can be forwarded");const n=z(t,I.UserMsgType,e.contentType);return o({},e,n,{seq:0,status:U.Sending})}),sendMessage:async(e,i)=>X(t.loginStatus,g.SendMessage,i,()=>s.enqueue(async()=>{var s,a;const{message:c,recvID:d,groupID:g,isOnlineOnly:u,offlinePushInfo:p={title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}}=o({},e,{message:o({},e.message)});void 0===p.signalInfo&&(p.signalInfo="");const l=Oe[c.contentType];if(!l)throw new Y(h.MsgContentTypeNotSupportError,"Unknown message content type");c.recvID=d,c.groupID=g,c.sessionType=g?E.Group:E.Single;const m={};u&&Object.values(M).forEach(e=>m[e]=!1);const v=J(c);let I=!1,D=await t.messageTrigger.getOneConversationAndTryChange(v,i);if(D?D.isPrivateChat&&(m[M.IsNotPrivate]=!1,c.attachedInfoElem=o({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:D.burnDuration})):(I=!0,D=await t.messageTrigger.initConversation({sourceID:g||d,sessionType:c.sessionType,operationID:i})),g){const e=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:g,userIDList:[t.userID],operationID:i});if(null==e||!e.length)throw new Y(h.ArgsError,"user not join target group");e[0].nickname&&(c.senderNickname=e[0].nickname)}if(D.latestMsgSendTime=c.createTime,t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(c)},void 0,I),c.contentType===k.PictureMessage){var S,y;const e=n.get(null==(S=c.pictureElem)?void 0:S.sourcePicture.uuid);if(!e)throw new Y(h.ArgsError,"Can not find target file");const{url:s="",error:r}=await t.internalUploadFile(e,i);if(n.delete(null==(y=c.pictureElem)?void 0:y.sourcePicture.uuid),r)throw new Y(h.NetworkError,"Upload file failed");c.pictureElem.sourcePicture.url=s,c.pictureElem.bigPicture.url=s,c.pictureElem.snapshotPicture.width=640,c.pictureElem.snapshotPicture.height=640,c.pictureElem.snapshotPicture.url=`${s}?type=image&width=640&height=640`}if(c.contentType===k.VoiceMessage){var C,G;const e=n.get(null==(C=c.soundElem)?void 0:C.uuid);if(!e)throw new Y(h.ArgsError,"Can not find target file");const{url:s="",error:r}=await t.internalUploadFile(e,i);if(n.delete(null==(G=c.soundElem)?void 0:G.uuid),r)throw new Y(h.NetworkError,"Upload file failed");c.soundElem.sourceUrl=s}if(c.contentType===k.VideoMessage){var T,A,N,w;const e=n.get(null==(T=c.videoElem)?void 0:T.videoUUID),s=n.get(null==(A=c.videoElem)?void 0:A.snapshotUUID);if(!e||!s)throw new Y(h.ArgsError,"Can not find target file");const r=await Promise.all([t.internalUploadFile(e,i),t.internalUploadFile(s,i)]);if(n.delete(null==(N=c.videoElem)?void 0:N.videoUUID),n.delete(null==(w=c.videoElem)?void 0:w.snapshotUUID),r[0].error||r[1].error)throw new Y(h.NetworkError,"Upload file failed");c.videoElem.videoUrl=r[0].url,c.videoElem.snapshotUrl=r[1].url}if(c.contentType===k.FileMessage){var b,R;const e=n.get(null==(b=c.fileElem)?void 0:b.uuid);if(!e)throw new Y(h.ArgsError,"Can not find target file");const{url:s="",error:r}=await t.internalUploadFile(e,i);if(n.delete(null==(R=c.fileElem)?void 0:R.uuid),r)throw new Y(h.NetworkError,"Upload file failed");c.fileElem.sourceUrl=s}const O=JSON.stringify(c[l]),F=r.MsgData.encode({sendID:t.userID,recvID:d||"",groupID:g||"",clientMsgID:c.clientMsgID,serverMsgID:c.serverMsgID||"",senderPlatformID:t.platform,senderNickname:c.senderNickname,senderFaceURL:c.senderFaceUrl,sessionType:c.sessionType,msgFrom:c.msgFrom,contentType:c.contentType,content:ee(O),seq:c.seq,sendTime:0,createTime:c.createTime,status:c.status,isRead:!1,options:m,offlinePushInfo:p,atUserIDList:null!=(s=null==(a=c.atTextElem)?void 0:a.atUserList)?s:[],attachedInfo:c.attachedInfoElem?JSON.stringify(c.attachedInfoElem):"",ex:c.ex||"",keyVersion:0,dstUserIDs:[]}).finish();try{const{serverMsgID:e,sendTime:n}=await t.sendReqWaitResp({data:F,operationID:i,reqIdentifier:f.SendMsg});return c.sendTime=n,c.serverMsgID=e,c.status=U.Succeed,t.messageTrigger.setTriggeredConversationEvent(i),t.messageTrigger.cache.updateCachedMaxReadSeq(D.conversationID,{maxSeqTime:n}),t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(c),latestMsgSendTime:n}),c}catch(e){throw c.status=U.Failed,t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(c)}),e}})),sendMessageNotOss:async(e,n)=>X(t.loginStatus,g.SendMessage,n,()=>s.enqueue(async()=>{var s,i;const{message:a,recvID:c,groupID:d,isOnlineOnly:g,offlinePushInfo:u={title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}}=o({},e,{message:o({},e.message)});void 0===u.signalInfo&&(u.signalInfo="");const p=Oe[a.contentType];if(!p)throw new Y(h.MsgContentTypeNotSupportError,"Unknown message content type");a.recvID=c,a.groupID=d,a.sessionType=d?E.Group:E.Single;const l={};g&&Object.values(M).forEach(e=>l[e]=!1);const m=J(a);let v=await t.messageTrigger.getOneConversationAndTryChange(m,n);if(v)v.isPrivateChat&&(l[M.IsNotPrivate]=!1,a.attachedInfoElem=o({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:v.burnDuration}));else if(v=await t.messageTrigger.initConversation({sourceID:d||c,sessionType:a.sessionType,operationID:n}),d){const e=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:d,userIDList:[t.userID],operationID:n});if(null==e||!e.length)throw new Y(h.ArgsError,"user not join target group");e[0].nickname&&(a.senderNickname=e[0].nickname)}v.latestMsgSendTime=a.createTime,t.messageTrigger.getOneConversationAndTryChange(m,n,{latestMsg:JSON.stringify(a)});const I=JSON.stringify(a[p]),D=r.MsgData.encode({sendID:t.userID,recvID:c||"",groupID:d||"",clientMsgID:a.clientMsgID,serverMsgID:a.serverMsgID||"",senderPlatformID:t.platform,senderNickname:a.senderNickname,senderFaceURL:a.senderFaceUrl,sessionType:a.sessionType,msgFrom:a.msgFrom,contentType:a.contentType,content:ee(I),seq:a.seq,sendTime:0,createTime:a.createTime,status:a.status,isRead:!1,options:l,offlinePushInfo:u,atUserIDList:null!=(s=null==(i=a.atTextElem)?void 0:i.atUserList)?s:[],attachedInfo:a.attachedInfoElem?JSON.stringify(a.attachedInfoElem):"",ex:a.ex||"",keyVersion:0,dstUserIDs:[]}).finish();try{const{serverMsgID:e,sendTime:s}=await t.sendReqWaitResp({data:D,operationID:n,reqIdentifier:f.SendMsg});return a.sendTime=s,a.serverMsgID=e,a.status=U.Succeed,t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.cache.updateCachedMaxReadSeq(v.conversationID,{maxSeqTime:s}),t.messageTrigger.getOneConversationAndTryChange(m,n,{latestMsg:JSON.stringify(a),latestMsgSendTime:s}),a}catch(e){throw a.status=U.Failed,t.messageTrigger.getOneConversationAndTryChange(m,n,{latestMsg:JSON.stringify(a)}),e}})),revokeMessage:async(e,n)=>X(t.loginStatus,g.RevokeMessage,n,async()=>{const s=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(e.conversationID,[e.clientMsgID])[0];if(!s)throw new Y(h.ArgsError,"message not exist");if(s.sendID!==t.userID){if(!s.groupID)throw new Y(h.ArgsError,"message can not be revoked");const e=(await t.groupTrigger.cache.getGroupMembersWithCache({groupID:s.groupID,userIDList:[t.userID],operationID:n}))[0];if(!e||e.roleLevel===b.Nomal)throw new Y(h.ArgsError,"message can not be revoked")}const r={conversationID:e.conversationID,seq:s.seq,userID:t.userID};await t.sendHttpRequest({reqFuncName:g.RevokeMessage,data:r,operationID:n}),t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.revokeMessage({revokerUserID:t.userID,clientMsgID:s.clientMsgID,revokeTime:Date.now(),sesstionType:s.sessionType,seq:s.seq,conversationID:e.conversationID,isAdminRevoke:!1},n)}),getAdvancedHistoryMessageList:async(n,s)=>X(t.loginStatus,g.GetAdvancedHistoryMessageList,s,async()=>{var r,d,g,u;const p={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(a!==n.conversationID&&(i=null,a=n.conversationID),n.startClientMsgID){if(null===i){const e=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!e)return o({},p,{isEnd:!0});i=e.seq}}else i=0;const l=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);if(e.log("syncedSeqs",l),!l)return o({},p,{isEnd:!0});const h=i?i-1:l.maxSeq,f=await c({maxSeq:h,count:n.count,conversationID:n.conversationID,operationID:s});if((null==(r=f[0])?void 0:r.sessionType)===E.Single){const e=await t.messageTrigger.getOneConversationAndTryChange(n.conversationID,s),r=t.userTrigger.cache.getSelfUserInfo();f.forEach(n=>{const s=n.sendID===t.userID;n.senderNickname=s?null==r?void 0:r.nickname:null==e?void 0:e.showName,n.senderFaceUrl=s?null==r?void 0:r.faceURL:null==e?void 0:e.faceURL})}if((null==(d=f[0])?void 0:d.sessionType)===E.Group){const e=new Set(f.map(e=>e.sendID)),n=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:f[0].groupID,userIDList:Array.from(e),operationID:s});f.forEach(e=>{const t=n.find(t=>t.userID===e.sendID);t&&(e.senderNickname=null==t?void 0:t.nickname,e.senderFaceUrl=null==t?void 0:t.faceURL)})}return p.messageList=f.map(ce),e.debug("getAdvancedHistoryMessageList with opid: ",s,"messageList: ",p.messageList),i=null!=(g=null==(u=f[0])?void 0:u.seq)?g:0,o({},p,{isEnd:f.lengthX(t.loginStatus,g.GetAdvancedHistoryMessageListReverse,s,async()=>{var r,i;const a={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(!n.startClientMsgID)return o({},a,{isEnd:!0});const c=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!c)return o({},a,{isEnd:!0});const g=c.seq,u=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);if(e.log("syncedSeqs",u),!u||u.maxSeq===g)return o({},a,{isEnd:!0});const p=await d({minSeq:g,count:n.count,conversationID:n.conversationID,operationID:s});if((null==(r=p[0])?void 0:r.sessionType)===E.Single){const e=await t.messageTrigger.getOneConversationAndTryChange(n.conversationID,s),r=t.userTrigger.cache.getSelfUserInfo();p.forEach(n=>{const s=n.sendID===t.userID;n.senderNickname=s?null==r?void 0:r.nickname:null==e?void 0:e.showName,n.senderFaceUrl=s?null==r?void 0:r.faceURL:null==e?void 0:e.faceURL})}if((null==(i=p[0])?void 0:i.sessionType)===E.Group){const e=new Set(p.map(e=>e.sendID)),n=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:p[0].groupID,userIDList:Array.from(e),operationID:s});p.forEach(e=>{const t=n.find(t=>t.userID===e.sendID);t&&(e.senderNickname=null==t?void 0:t.nickname,e.senderFaceUrl=null==t?void 0:t.faceURL)})}return a.messageList=p.map(ce),e.debug("getAdvancedHistoryMessageListReverse with opid: ",s,"messageList: ",a.messageList),o({},a,{isEnd:p.lengthX(t.loginStatus,g.DeleteMessage,s,async()=>{var r;const i=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.clientMsgID])[0];if(!i)throw new Y(h.ArgsError,"message not exist");const o={conversationID:n.conversationID,seqs:[i.seq],userID:t.userID,deleteSyncOpt:void 0};await t.sendHttpRequest({reqFuncName:g.DeleteMessage,data:o,operationID:s});const a=null==(r=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID))?void 0:r.maxSeq;if(e.debug("delete message with opid: ",s,"conversationMaxSeq: ",a,"deleteMessage seq: ",i.seq),t.messageTrigger.cache.deleteMessageFromCache(n.conversationID,i.seq),i.seq===a){const e=await t.messageTrigger.getPreviousSeqMessage({conversationID:n.conversationID,seq:i.seq,operationID:s});t.messageTrigger.getOneConversationAndTryChange(n.conversationID,s,{latestMsg:e?JSON.stringify(ce(e)):""})}}),deleteAllMsgFromLocalAndSvr:async e=>X(t.loginStatus,g.DeleteAllMsgFromLocalAndSvr,e,async()=>{const n={userID:t.userID,deleteSyncOpt:void 0};await t.sendHttpRequest({reqFuncName:g.DeleteAllMsgFromLocalAndSvr,data:n,operationID:e}),t.messageTrigger.cache.getAllCachedConversations().forEach(({conversationID:n})=>{t.messageTrigger.getOneConversationAndTryChange(n,e,{latestMsg:""})})})}}(this)),Object.assign(this,function(t){return{getConversationListSplit:async(e,n)=>X(t.loginStatus,g.GetConversationListSplit,n,async()=>{const s=t.messageTrigger.cache.getSortedConversationIDs(e.offset,e.count);return(await t.messageTrigger.getConversationsWithCacheByIDs(s,n)).sort((e,t)=>e.isPinned===t.isPinned?e.latestMsgSendTime>t.latestMsgSendTime?-1:e.latestMsgSendTimeX(t.loginStatus,g.GetOneConversation,n,async()=>{let s=await t.messageTrigger.getOneConversationAndTryChange(W(o({},e,{userID:t.userID})),n);return s||(s=await t.messageTrigger.initConversation(o({},e,{operationID:n}))),o({},s)}),getTotalUnreadMsgCount:async e=>X(t.loginStatus,g.GetTotalUnreadMsgCount,e,()=>Promise.resolve(t.messageTrigger.cache.getTotalUnreadCount())),markConversationMessageAsRead:async(n,s)=>X(t.loginStatus,g.MarkConversationMessageAsRead,s,async()=>{const r=t.messageTrigger.cache.getCachedMaxReadSeq(n);if(!r)throw new Y(h.ArgsError,"conversation not exist");if(r.hasReadSeq===r.maxSeq)throw new Y(h.ArgsError,"hasReadSeq equal max");const i=[];for(let e=r.hasReadSeq;e<=r.maxSeq;e++)i.push(e);const{messages:o}=await t.messageTrigger.getMessageWithCacheBySeqs(n,i,s),a=o.filter(e=>e.sendID!==t.userID&&!e.isRead).map(e=>e.seq);a.length||e.warn("seqs is empty ",n);const c={conversationID:n,seqs:a,hasReadSeq:r.maxSeq,userID:t.userID};if(await t.sendHttpRequest({reqFuncName:g.MarkConversationMessageAsRead,data:c,operationID:s}),t.messageTrigger.cache.updateCachedMaxReadSeq(n,{hasReadSeq:r.maxSeq}),t.messageTrigger.cache.markCachedMessagesAsRead(n),e.debug("markConversationMessageAsRead with opid: ",s,"conversationID: ",n,"asReadSeqs: ",a,"syncedMaxSeq",r.maxSeq),a.sort()[a.length-1]===r.maxSeq){const e=o.find(e=>e.seq===r.maxSeq);e.isRead=!0,t.messageTrigger.getOneConversationAndTryChange(n,s,{latestMsg:JSON.stringify(ce(e))})}t.messageTrigger.getOneConversationAndTryChange(n,s).then(e=>{t.messageTrigger.cache.decreaseTotalUnreadCount(e.unreadCount,s),t.messageTrigger.getOneConversationAndTryChange(n,s,{unreadCount:0})})}),clearConversationAndDeleteAllMsg:async(e,n)=>X(t.loginStatus,g.ClearConversationAndDeleteAllMsg,n,async()=>{const s={conversationIDs:[e],userID:t.userID,deleteSyncOpt:void 0};await t.sendHttpRequest({reqFuncName:g.ClearConversationAndDeleteAllMsg,data:s,operationID:n}),t.messageTrigger.cache.clearCachedConversationMessages(e),await t.messageTrigger.getOneConversationAndTryChange(e,n,{latestMsg:""})}),setConversation:async(e,n)=>X(t.loginStatus,g.SetConversation,n,async()=>{const s=await t.messageTrigger.getOneConversationAndTryChange(e.conversationID,n);if(!s)throw new Y(h.ArgsError,"conversation not exist");await t.sendHttpRequest({reqFuncName:g.SetConversation,data:{conversation:o({},e,{conversationID:s.conversationID,conversationType:s.conversationType,userID:s.userID,groupID:s.groupID,attachedInfo:void 0,minSeq:void 0}),userIDs:[t.userID]},operationID:n})}),changeInputStates:async(e,n)=>X(t.loginStatus,g.ChangeInputStates,n,async()=>{await t.messageTrigger.typingManager.changeInputStates(o({},e,{operationID:n}))}),getInputStates:async(e,n)=>X(t.loginStatus,g.ChangeInputStates,n,()=>Promise.resolve(t.messageTrigger.typingManager.getInputStates(e.conversationID,e.userID)))}}(this))}}const ke=()=>(console.info("%cOpenIMSDK v0.0.13","background: #004085; color: #ffffff; padding: 2px 5px; border-radius: 4px;"),new Proxy(new qe,{get(t,n,s){if("on"===n||"off"===n)return Reflect.get(t,n,s);let r=t[n];return"function"==typeof r?async function(...s){s.push(H()),((t,n)=>{e.debug(`%cSDK =>%c [OperationID:${n[n.length-1]}] (invoked) run ${t} with args ${JSON.stringify(n)}`,"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")})(n,s);const i=await r.apply(t,s);var o,a;return o=n,(a=i).errCode?e.debug(`%cSDK =>%c [OperationID:${a.operationID}] (response) run ${o} with error ${JSON.stringify(a)}`,"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):e.debug(`%cSDK =>%c [OperationID:${a.operationID}] (response) run ${o} with response before processor ${JSON.stringify(a.data)}`,"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),i.errCode?Promise.reject(i):i}:Reflect.get(t,n,s)}}));export{A as AllowType,q as ApplicationHandleResult,l as CbEvents,h as ErrorCode,L as GroupAtType,w as GroupJoinSource,x as GroupMemberFilter,b as GroupMemberRole,S as GroupStatus,N as GroupType,R as GroupVerificationType,m as InternalContentType,D as InternalMessageStatus,F as LogLevel,P as LoginStatus,M as MessageOptionsKey,T as MessageReceiveOptType,U as MessageStatus,k as MessageType,I as MsgFrom,v as NotificationType,V as OnlineState,O as Platform,B as Relationship,f as ReqIdentifier,g as RequestApi,E as SessionType,_ as ViewType,y as WorkMomentSdkNotificationType,C as WsErrorCode,G as WsErrorEventMap,ke as getSDK}; +import e from"loglevel";import t from"spark-md5";import{decode as n,encode as s}from"base64-arraybuffer";import{PbCoder as i,SdkWsProto as r}from"@openim/protocol";import o from"crypto-js";function a(e,t){if(!{}.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var c=0;function d(e){return"__private_"+c+++"_"+e}function g(){return g=Object.assign?Object.assign.bind():function(e){for(var t=1;t{if(!e.ok)throw new Error(e.statusText);const t=await e.json();if(0!==t.errCode)throw new Error(t.errMsg);return t.data},l={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",csv:"text/csv",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",bmp:"image/bmp",svg:"image/svg+xml",mp3:"audio/mpeg",mp4:"video/mp4",wav:"audio/wav",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",xml:"application/xml",zip:"application/zip",tar:"application/x-tar","7z":"application/x-7z-compressed",rar:"application/vnd.rar",ogg:"audio/ogg",midi:"audio/midi",webm:"audio/webm",avi:"video/x-msvideo",mpeg:"video/mpeg",ts:"video/mp2t",mov:"video/quicktime",wmv:"video/x-ms-wmv",flv:"video/x-flv",mkv:"video/x-matroska",webp:"image/webp",heic:"image/heic",psd:"image/vnd.adobe.photoshop",ai:"application/postscript",eps:"application/postscript",ttf:"font/ttf",otf:"font/otf",woff:"font/woff",woff2:"font/woff2",jsonld:"application/ld+json",ics:"text/calendar",sh:"application/x-sh",php:"application/x-httpd-php",jar:"application/java-archive"};var h,f;!function(e){e.InitSDK="InitSDK",e.Login="Login",e.Logout="Logout",e.GetLoginStatus="GetLoginStatus",e.GetLoginUserID="GetLoginUserID",e.ForceReconnect="ForceReconnect",e.GetSelfUserInfo="GetSelfUserInfo",e.SetSelfInfo="SetSelfInfo",e.GetUsersInfo="GetUsersInfo",e.SubscribeUsersStatus="SubscribeUsersStatus",e.UnsubscribeUsersStatus="UnsubscribeUsersStatus",e.GetSubscribeUsersStatus="GetSubscribeUsersStatus",e.SetAppBackgroundStatus="SetAppBackgroundStatus",e.NetworkStatusChanged="NetworkStatusChanged",e.SetGlobalRecvMessageOpt="SetGlobalRecvMessageOpt",e.AcceptFriendApplication="AcceptFriendApplication",e.AddBlack="AddBlack",e.AddFriend="AddFriend",e.CheckFriend="CheckFriend",e.DeleteFriend="DeleteFriend",e.GetBlackList="GetBlackList",e.GetFriendApplicationListAsApplicant="GetFriendApplicationListAsApplicant",e.GetFriendApplicationListAsRecipient="GetFriendApplicationListAsRecipient",e.GetFriendList="GetFriendList",e.GetFriendListPage="GetFriendListPage",e.GetSpecifiedFriendsInfo="GetSpecifiedFriendsInfo",e.RefuseFriendApplication="RefuseFriendApplication",e.RemoveBlack="RemoveBlack",e.SearchFriends="SearchFriends",e.UpdateFriends="UpdateFriends",e.CreateGroup="CreateGroup",e.JoinGroup="JoinGroup",e.InviteUserToGroup="InviteUserToGroup",e.GetJoinedGroupList="GetJoinedGroupList",e.GetJoinedGroupListPage="GetJoinedGroupListPage",e.SearchGroups="SearchGroups",e.GetSpecifiedGroupsInfo="GetSpecifiedGroupsInfo",e.SetGroupInfo="SetGroupInfo",e.GetGroupApplicationListAsRecipient="GetGroupApplicationListAsRecipient",e.GetGroupApplicationListAsApplicant="GetGroupApplicationListAsApplicant",e.AcceptGroupApplication="AcceptGroupApplication",e.RefuseGroupApplication="RefuseGroupApplication",e.GetGroupMemberList="GetGroupMemberList",e.GetSpecifiedGroupMembersInfo="GetSpecifiedGroupMembersInfo",e.SearchGroupMembers="SearchGroupMembers",e.SetGroupMemberInfo="SetGroupMemberInfo",e.GetGroupMemberOwnerAndAdmin="GetGroupMemberOwnerAndAdmin",e.GetGroupMemberListByJoinTimeFilter="GetGroupMemberListByJoinTimeFilter",e.KickGroupMember="KickGroupMember",e.ChangeGroupMemberMute="ChangeGroupMemberMute",e.ChangeGroupMute="ChangeGroupMute",e.TransferGroupOwner="TransferGroupOwner",e.DismissGroup="DismissGroup",e.QuitGroup="QuitGroup",e.GetUsersInGroup="GetUsersInGroup",e.SendGroupMessageReadReceipt="SendGroupMessageReadReceipt",e.GetGroupMessageReaderList="GetGroupMessageReaderList",e.IsJoinGroup="IsJoinGroup",e.GetAllConversationList="GetAllConversationList",e.GetConversationListSplit="GetConversationListSplit",e.GetOneConversation="GetOneConversation",e.GetMultipleConversation="GetMultipleConversation",e.GetConversationIDBySessionType="GetConversationIDBySessionType",e.GetTotalUnreadMsgCount="GetTotalUnreadMsgCount",e.MarkConversationMessageAsRead="MarkConversationMessageAsRead",e.SetConversationDraft="SetConversationDraft",e.PinConversation="PinConversation",e.SetConversationRecvMessageOpt="SetConversationRecvMessageOpt",e.SetConversationPrivateChat="SetConversationPrivateChat",e.SetConversationBurnDuration="SetConversationBurnDuration",e.ResetConversationGroupAtType="ResetConversationGroupAtType",e.HideConversation="HideConversation",e.HideAllConversation="HideAllConversation",e.ClearConversationAndDeleteAllMsg="ClearConversationAndDeleteAllMsg",e.DeleteConversationAndDeleteAllMsg="DeleteConversationAndDeleteAllMsg",e.ChangeInputStates="ChangeInputStates",e.GetInputStates="GetInputStates",e.CreateTextMessage="CreateTextMessage",e.CreateTextAtMessage="CreateTextAtMessage",e.CreateImageMessageByFile="CreateImageMessageByFile",e.CreateImageMessageByURL="CreateImageMessageByURL",e.CreateSoundMessageByFile="CreateSoundMessageByFile",e.CreateSoundMessageByURL="CreateSoundMessageByURL",e.CreateVideoMessageByFile="CreateVideoMessageByFile",e.CreateVideoMessageByURL="CreateVideoMessageByURL",e.CreateFileMessageByFile="CreateFileMessageByFile",e.CreateFileMessageByURL="CreateFileMessageByURL",e.CreateMergerMessage="CreateMergerMessage",e.CreateForwardMessage="CreateForwardMessage",e.CreateLocationMessage="CreateLocationMessage",e.CreateQuoteMessage="CreateQuoteMessage",e.CreateCardMessage="CreateCardMessage",e.CreateCustomMessage="CreateCustomMessage",e.CreateFaceMessage="CreateFaceMessage",e.SendMessage="SendMessage",e.SendMessageNotOss="SendMessageNotOss",e.UploadFile="UploadFile",e.TypingStatusUpdate="TypingStatusUpdate",e.RevokeMessage="RevokeMessage",e.DeleteMessage="DeleteMessage",e.DeleteMessageFromLocalStorage="DeleteMessageFromLocalStorage",e.DeleteAllMsgFromLocal="DeleteAllMsgFromLocal",e.DeleteAllMsgFromLocalAndSvr="DeleteAllMsgFromLocalAndSvr",e.SearchLocalMessages="SearchLocalMessages",e.GetAdvancedHistoryMessageList="GetAdvancedHistoryMessageList",e.GetAdvancedHistoryMessageListReverse="GetAdvancedHistoryMessageListReverse",e.FindMessageList="FindMessageList",e.InsertGroupMessageToLocalStorage="InsertGroupMessageToLocalStorage",e.InsertSingleMessageToLocalStorage="InsertSingleMessageToLocalStorage",e.SetMessageLocalEx="SetMessageLocalEx",e.SetConversation="SetConversation",e.SignalingInvite="SignalingInvite",e.SignalingInviteInGroup="SignalingInviteInGroup",e.SignalingAccept="SignalingAccept",e.SignalingReject="SignalingReject",e.SignalingCancel="SignalingCancel",e.SignalingHungUp="SignalingHungUp",e.SignalingGetRoomByGroupID="SignalingGetRoomByGroupID",e.SignalingGetTokenByRoomID="SignalingGetTokenByRoomID",e.GetSignalingInvitationInfoStartApp="GetSignalingInvitationInfoStartApp",e.SignalingSendCustomSignal="SignalingSendCustomSignal"}(h||(h={})),function(e){e.GetFriendVersion="GetFriendVersion",e.GetGroupVersion="GetGroupVersion",e.GetJoinedGroupIDList="GetJoinedGroupIDList",e.GetGroupMemberVersion="GetGroupMemberVersion",e.GetConversationVersion="GetConversationVersion",e.GetConversationsHasReadAndMaxSeq="GetConversationsHasReadAndMaxSeq",e.GetDesignatedFriendsApplication="GetDesignatedFriendsApplication",e.GetDesignatedGroupApplication="GetDesignatedGroupApplication",e.GetDesignatedBlackUser="GetDesignatedBlackUser",e.GetActiveConversations="GetActiveConversations",e.GetDesignatedConversation="GetDesignatedConversation",e.GetNotNotifyConversationIDs="GetNotNotifyConversationIDs",e.GetFullFriendUserIDs="GetFullFriendUserIDs",e.GetFullGroupMemberUserIDs="GetFullGroupMemberUserIDs",e.SignalGetRoomByGroupID="SignalGetRoomByGroupID",e.SignalSendCustomSignal="SignalSendCustomSignal",e.GetSignalInvitationInfoStartApp="GetSignalInvitationInfoStartApp",e.GetEncryptionKey="GetEncryptionKey",e.MarkGroupMessageRead="MarkGroupMessageRead",e.GetGroupMessageHasRead="GetGroupMessageHasRead",e.GetGroupMessageReadNum="GetGroupMessageReadNum"}(f||(f={}));const m={[h.AddFriend]:"/friend/add_friend",[h.CheckFriend]:"/friend/is_friend",[h.DeleteFriend]:"/friend/delete_friend",[h.AcceptFriendApplication]:"/friend/add_friend_response",[h.RefuseFriendApplication]:"/friend/add_friend_response",[h.GetFriendListPage]:"/friend/get_friend_list",[h.GetSpecifiedFriendsInfo]:"/friend/get_designated_friends",[h.GetFriendApplicationListAsApplicant]:"/friend/get_self_friend_apply_list",[h.GetFriendApplicationListAsRecipient]:"/friend/get_friend_apply_list",[h.UpdateFriends]:"/friend/update_friends",[h.AddBlack]:"/friend/add_black",[h.RemoveBlack]:"/friend/remove_black",[h.GetBlackList]:"/friend/get_black_list",[h.CreateGroup]:"/group/create_group",[h.JoinGroup]:"/group/join_group",[h.InviteUserToGroup]:"/group/invite_user_to_group",[h.GetJoinedGroupListPage]:"/group/get_joined_group_list",[h.GetSpecifiedGroupsInfo]:"/group/get_groups_info",[h.SetGroupInfo]:"/group/set_group_info_ex",[h.GetGroupApplicationListAsApplicant]:"/group/get_user_req_group_applicationList",[h.GetGroupApplicationListAsRecipient]:"/group/get_recv_group_applicationList",[h.AcceptGroupApplication]:"/group/group_application_response",[h.RefuseGroupApplication]:"/group/group_application_response",[h.GetGroupMemberList]:"/group/get_group_member_list",[h.GetSpecifiedGroupMembersInfo]:"/group/get_group_members_info",[h.SetGroupMemberInfo]:"/group/set_group_member_info",[h.KickGroupMember]:"/group/kick_group",[h.TransferGroupOwner]:"/group/transfer_group",[h.DismissGroup]:"/group/dismiss_group",[h.QuitGroup]:"/group/quit_group",[h.GetSelfUserInfo]:"/user/get_users_info",[h.SetSelfInfo]:"/user/update_user_info_ex",[h.GetUsersInfo]:"/user/get_users_info",[h.SubscribeUsersStatus]:"/user/subscribe_users_status",[h.UnsubscribeUsersStatus]:"/user/subscribe_users_status",[h.GetSubscribeUsersStatus]:"/user/get_subscribe_users_status",[h.SetGlobalRecvMessageOpt]:"/user/set_global_msg_recv_opt",[h.RevokeMessage]:"/msg/revoke_msg",[h.DeleteMessage]:"/msg/delete_msgs",[h.DeleteConversationAndDeleteAllMsg]:"/msg/clear_conversation_msg",[h.DeleteAllMsgFromLocalAndSvr]:"/msg/user_clear_all_msg",[h.MarkConversationMessageAsRead]:"/msg/mark_conversation_as_read",[h.SetConversation]:"/conversation/set_conversations",[f.GetFriendVersion]:"/friend/get_incremental_friends",[f.GetGroupVersion]:"/group/get_incremental_join_groups",[f.GetJoinedGroupIDList]:"/group/get_full_join_group_ids",[f.GetGroupMemberVersion]:"/group/get_incremental_group_members_batch",[f.GetConversationVersion]:"/conversation/get_incremental_conversations",[f.GetConversationsHasReadAndMaxSeq]:"/conversation/get_conversations_has_read_and_max_seq",[f.GetDesignatedFriendsApplication]:"/friend/get_designated_friend_apply",[f.GetDesignatedGroupApplication]:"/group/get_specified_user_group_request_info",[f.GetDesignatedBlackUser]:"/friend/get_specified_blacks",[f.GetActiveConversations]:"/jssdk/get_active_conversations",[f.GetDesignatedConversation]:"/jssdk/get_conversations",[f.GetNotNotifyConversationIDs]:"/conversation/get_not_notify_conversation_ids",[f.GetFullFriendUserIDs]:"/friend/get_full_friend_user_ids",[f.GetFullGroupMemberUserIDs]:"/group/get_full_group_member_user_ids",[f.SignalGetRoomByGroupID]:"/rtc-meeting/signal_get_room_by_group_id",[f.SignalSendCustomSignal]:"/rtc-meeting/signal_send_custom_signal",[f.GetSignalInvitationInfoStartApp]:"/rtc-meeting/get_signal_invitation_info_start_app",[f.GetEncryptionKey]:"/encryption/get_encryption_key",[f.GetGroupMessageHasRead]:"/msg/get_group_message_has_read",[f.GetGroupMessageReadNum]:"/msg/get_group_message_read_num",[f.MarkGroupMessageRead]:"/msg/mark_group_message_read"};var v,I,D,M,y,S,C,T,G,w,b;!function(e){e.OnConnectFailed="OnConnectFailed",e.OnConnectSuccess="OnConnectSuccess",e.OnConnecting="OnConnecting",e.OnKickedOffline="OnKickedOffline",e.OnSelfInfoUpdated="OnSelfInfoUpdated",e.OnUserTokenExpired="OnUserTokenExpired",e.OnUserTokenInvalid="OnUserTokenInvalid",e.OnProgress="OnProgress",e.OnRecvNewMessage="OnRecvNewMessage",e.OnRecvNewMessages="OnRecvNewMessages",e.OnRecvOfflineNewMessage="onRecvOfflineNewMessage",e.OnRecvOfflineNewMessages="onRecvOfflineNewMessages",e.OnNewRecvMessageRevoked="OnNewRecvMessageRevoked",e.OnRecvC2CReadReceipt="OnRecvC2CReadReceipt",e.OnRecvGroupReadReceipt="OnRecvGroupReadReceipt",e.OnConversationChanged="OnConversationChanged",e.OnNewConversation="OnNewConversation",e.OnConversationUserInputStatusChanged="OnConversationUserInputStatusChanged",e.OnSyncServerFailed="OnSyncServerFailed",e.OnSyncServerFinish="OnSyncServerFinish",e.OnSyncServerProgress="OnSyncServerProgress",e.OnSyncServerStart="OnSyncServerStart",e.OnTotalUnreadMessageCountChanged="OnTotalUnreadMessageCountChanged",e.OnBlackAdded="OnBlackAdded",e.OnBlackDeleted="OnBlackDeleted",e.OnFriendApplicationAccepted="OnFriendApplicationAccepted",e.OnFriendApplicationAdded="OnFriendApplicationAdded",e.OnFriendApplicationDeleted="OnFriendApplicationDeleted",e.OnFriendApplicationRejected="OnFriendApplicationRejected",e.OnFriendInfoChanged="OnFriendInfoChanged",e.OnFriendAdded="OnFriendAdded",e.OnFriendDeleted="OnFriendDeleted",e.OnJoinedGroupAdded="OnJoinedGroupAdded",e.OnJoinedGroupDeleted="OnJoinedGroupDeleted",e.OnGroupDismissed="OnGroupDismissed",e.OnGroupMemberAdded="OnGroupMemberAdded",e.OnGroupMemberDeleted="OnGroupMemberDeleted",e.OnGroupApplicationAdded="OnGroupApplicationAdded",e.OnGroupApplicationDeleted="OnGroupApplicationDeleted",e.OnGroupInfoChanged="OnGroupInfoChanged",e.OnGroupMemberInfoChanged="OnGroupMemberInfoChanged",e.OnGroupApplicationAccepted="OnGroupApplicationAccepted",e.OnGroupApplicationRejected="OnGroupApplicationRejected",e.UploadComplete="UploadComplete",e.OnRecvCustomBusinessMessage="OnRecvCustomBusinessMessage",e.OnUserStatusChanged="OnUserStatusChanged",e.OnUploadLogsProgress="OnUploadLogsProgress",e.OnReceiveNewInvitation="OnReceiveNewInvitation",e.OnInviteeAccepted="OnInviteeAccepted",e.OnInviteeRejected="OnInviteeRejected",e.OnInvitationCancelled="OnInvitationCancelled",e.OnHangUp="OnHangUp",e.OnInvitationTimeout="OnInvitationTimeout",e.OnInviteeAcceptedByOtherDevice="OnInviteeAcceptedByOtherDevice",e.OnInviteeRejectedByOtherDevice="OnInviteeRejectedByOtherDevice",e.OnStreamChange="OnStreamChange",e.OnRoomParticipantConnected="OnRoomParticipantConnected",e.OnRoomParticipantDisconnected="OnRoomParticipantDisconnected",e.OnReceiveCustomSignal="OnReceiveCustomSignal",e.UnUsedEvent="UnUsedEvent"}(v||(v={})),function(e){e[e.NetworkError=1e4]="NetworkError",e[e.NetworkTimeoutError=10001]="NetworkTimeoutError",e[e.ArgsError=10002]="ArgsError",e[e.CtxDeadlineExceededError=10003]="CtxDeadlineExceededError",e[e.ResourceLoadNotCompleteError=10004]="ResourceLoadNotCompleteError",e[e.UnknownCode=10005]="UnknownCode",e[e.SdkInternalError=10006]="SdkInternalError",e[e.NoUpdateError=10007]="NoUpdateError",e[e.UserIDNotFoundError=10100]="UserIDNotFoundError",e[e.LoginOutError=10101]="LoginOutError",e[e.LoginRepeatError=10102]="LoginRepeatError",e[e.FileNotFoundError=10200]="FileNotFoundError",e[e.MsgDeCompressionError=10201]="MsgDeCompressionError",e[e.MsgDecodeBinaryWsError=10202]="MsgDecodeBinaryWsError",e[e.MsgBinaryTypeNotSupportError=10203]="MsgBinaryTypeNotSupportError",e[e.MsgRepeatError=10204]="MsgRepeatError",e[e.MsgContentTypeNotSupportError=10205]="MsgContentTypeNotSupportError",e[e.MsgHasNoSeqError=10206]="MsgHasNoSeqError",e[e.NotSupportOptError=10301]="NotSupportOptError",e[e.NotSupportTypeError=10302]="NotSupportTypeError",e[e.UnreadCountError=10303]="UnreadCountError",e[e.GroupIDNotFoundError=10400]="GroupIDNotFoundError",e[e.GroupTypeErr=10401]="GroupTypeErr"}(I||(I={})),function(e){e[e.GetNewestSeq=1001]="GetNewestSeq",e[e.PullMsgByRange=1002]="PullMsgByRange",e[e.SendMsg=1003]="SendMsg",e[e.SendSignalMsg=1004]="SendSignalMsg",e[e.PullMsgBySeqList=1005]="PullMsgBySeqList",e[e.GetConvMaxReadSeq=1006]="GetConvMaxReadSeq",e[e.PushMsg=2001]="PushMsg",e[e.KickOnlineMsg=2002]="KickOnlineMsg",e[e.LogoutMsg=2003]="LogoutMsg",e[e.SetBackgroundStatus=2004]="SetBackgroundStatus",e[e.WsSubUserOnlineStatus=2005]="WsSubUserOnlineStatus",e[e.WSServerConfigMsg=2100]="WSServerConfigMsg",e[e.WSDataError=3001]="WSDataError"}(D||(D={})),function(e){e[e.Text=101]="Text",e[e.Picture=102]="Picture",e[e.Sound=103]="Sound",e[e.Video=104]="Video",e[e.File=105]="File",e[e.AtText=106]="AtText",e[e.Merger=107]="Merger",e[e.Card=108]="Card",e[e.Location=109]="Location",e[e.Custom=110]="Custom",e[e.Typing=113]="Typing",e[e.Quote=114]="Quote",e[e.Face=115]="Face",e[e.AdvancedText=117]="AdvancedText",e[e.CustomMsgNotTriggerConversation=119]="CustomMsgNotTriggerConversation",e[e.CustomMsgOnlineOnly=120]="CustomMsgOnlineOnly",e[e.ReactionMessageModifier=121]="ReactionMessageModifier",e[e.ReactionMessageDeleter=122]="ReactionMessageDeleter"}(M||(M={})),function(e){e[e.NotificationBegin=1e3]="NotificationBegin",e[e.FriendNotificationBegin=1200]="FriendNotificationBegin",e[e.FriendApplicationApprovedNotification=1201]="FriendApplicationApprovedNotification",e[e.FriendApplicationRejectedNotification=1202]="FriendApplicationRejectedNotification",e[e.FriendApplicationNotification=1203]="FriendApplicationNotification",e[e.FriendAddedNotification=1204]="FriendAddedNotification",e[e.FriendDeletedNotification=1205]="FriendDeletedNotification",e[e.FriendRemarkSetNotification=1206]="FriendRemarkSetNotification",e[e.BlackAddedNotification=1207]="BlackAddedNotification",e[e.BlackDeletedNotification=1208]="BlackDeletedNotification",e[e.FriendInfoUpdatedNotification=1209]="FriendInfoUpdatedNotification",e[e.FriendsInfoUpdateNotification=1210]="FriendsInfoUpdateNotification",e[e.FriendNotificationEnd=1299]="FriendNotificationEnd",e[e.ConversationChangeNotification=1300]="ConversationChangeNotification",e[e.UserNotificationBegin=1301]="UserNotificationBegin",e[e.UserInfoUpdatedNotification=1303]="UserInfoUpdatedNotification",e[e.UserStatusChangeNotification=1304]="UserStatusChangeNotification",e[e.UserCommandAddNotification=1305]="UserCommandAddNotification",e[e.UserCommandDeleteNotification=1306]="UserCommandDeleteNotification",e[e.UserCommandUpdateNotification=1307]="UserCommandUpdateNotification",e[e.UserNotificationEnd=1399]="UserNotificationEnd",e[e.OANotification=1400]="OANotification",e[e.GroupNotificationBegin=1500]="GroupNotificationBegin",e[e.GroupCreatedNotification=1501]="GroupCreatedNotification",e[e.GroupInfoSetNotification=1502]="GroupInfoSetNotification",e[e.JoinGroupApplicationNotification=1503]="JoinGroupApplicationNotification",e[e.MemberQuitNotification=1504]="MemberQuitNotification",e[e.GroupApplicationAcceptedNotification=1505]="GroupApplicationAcceptedNotification",e[e.GroupApplicationRejectedNotification=1506]="GroupApplicationRejectedNotification",e[e.GroupOwnerTransferredNotification=1507]="GroupOwnerTransferredNotification",e[e.MemberKickedNotification=1508]="MemberKickedNotification",e[e.MemberInvitedNotification=1509]="MemberInvitedNotification",e[e.MemberEnterNotification=1510]="MemberEnterNotification",e[e.GroupDismissedNotification=1511]="GroupDismissedNotification",e[e.GroupMemberMutedNotification=1512]="GroupMemberMutedNotification",e[e.GroupMemberCancelMutedNotification=1513]="GroupMemberCancelMutedNotification",e[e.GroupMutedNotification=1514]="GroupMutedNotification",e[e.GroupCancelMutedNotification=1515]="GroupCancelMutedNotification",e[e.GroupMemberInfoSetNotification=1516]="GroupMemberInfoSetNotification",e[e.GroupMemberSetToAdminNotification=1517]="GroupMemberSetToAdminNotification",e[e.GroupMemberSetToOrdinaryUserNotification=1518]="GroupMemberSetToOrdinaryUserNotification",e[e.GroupInfoSetAnnouncementNotification=1519]="GroupInfoSetAnnouncementNotification",e[e.GroupInfoSetNameNotification=1520]="GroupInfoSetNameNotification",e[e.GroupNotificationEnd=1599]="GroupNotificationEnd",e[e.SignalingNotificationBegin=1600]="SignalingNotificationBegin",e[e.SignalingNotification=1601]="SignalingNotification",e[e.RoomParticipantsConnectedNotification=1602]="RoomParticipantsConnectedNotification",e[e.RoomParticipantsDisconnectedNotification=1603]="RoomParticipantsDisconnectedNotification",e[e.StreamChangedNotification=1604]="StreamChangedNotification",e[e.CustomSignalNotification=1605]="CustomSignalNotification",e[e.SignalingNotificationEnd=1649]="SignalingNotificationEnd",e[e.SuperGroupNotificationBegin=1650]="SuperGroupNotificationBegin",e[e.SuperGroupUpdateNotification=1651]="SuperGroupUpdateNotification",e[e.MsgDeleteNotification=1652]="MsgDeleteNotification",e[e.ReactionMessageModifierNotification=1653]="ReactionMessageModifierNotification",e[e.ReactionMessageDeleteNotification=1654]="ReactionMessageDeleteNotification",e[e.SuperGroupNotificationEnd=1699]="SuperGroupNotificationEnd",e[e.ConversationPrivateChatNotification=1701]="ConversationPrivateChatNotification",e[e.ConversationUnreadNotification=1702]="ConversationUnreadNotification",e[e.ClearConversationNotification=1703]="ClearConversationNotification",e[e.WorkMomentNotificationBegin=1900]="WorkMomentNotificationBegin",e[e.WorkMomentNotification=1901]="WorkMomentNotification",e[e.BusinessNotificationBegin=2e3]="BusinessNotificationBegin",e[e.BusinessNotification=2001]="BusinessNotification",e[e.BusinessNotificationEnd=2099]="BusinessNotificationEnd",e[e.RevokeNotification=2101]="RevokeNotification",e[e.HasReadReceiptNotification=2150]="HasReadReceiptNotification",e[e.GroupHasReadReceiptNotification=2155]="GroupHasReadReceiptNotification",e[e.DeleteMsgsNotification=2102]="DeleteMsgsNotification",e[e.HasReadReceipt=2200]="HasReadReceipt",e[e.HasGroupReadReceipt=2300]="HasGroupReadReceipt",e[e.NotificationEnd=5e3]="NotificationEnd"}(y||(y={})),function(e){e[e.UserMsgType=100]="UserMsgType",e[e.SysMsgType=200]="SysMsgType"}(S||(S={})),function(e){e[e.MsgStatusDefault=0]="MsgStatusDefault",e[e.MsgStatusSending=1]="MsgStatusSending",e[e.MsgStatusSendSuccess=2]="MsgStatusSendSuccess",e[e.MsgStatusSendFailed=3]="MsgStatusSendFailed",e[e.MsgStatusHasDeleted=4]="MsgStatusHasDeleted",e[e.MsgStatusFiltered=5]="MsgStatusFiltered"}(C||(C={})),function(e){e.IsHistory="history",e.IsPersistent="persistent",e.IsUnreadCount="unreadCount",e.IsConversationUpdate="conversationUpdate",e.IsOfflinePush="offlinePush",e.IsSenderSync="senderSync",e.IsNotPrivate="notPrivate",e.IsSenderConversationUpdate="senderConversationUpdate"}(T||(T={})),function(e){e[e.GroupOk=0]="GroupOk",e[e.GroupBanChat=1]="GroupBanChat",e[e.GroupStatusDismissed=2]="GroupStatusDismissed",e[e.GroupStatusMuted=3]="GroupStatusMuted"}(G||(G={})),function(e){e[e.WorkMomentCommentNotification=0]="WorkMomentCommentNotification",e[e.WorkMomentLikeNotification=1]="WorkMomentLikeNotification",e[e.WorkMomentAtUserNotification=2]="WorkMomentAtUserNotification"}(w||(w={})),function(e){e[e.TokenExpiredError=1501]="TokenExpiredError",e[e.TokenInvalidError=1502]="TokenInvalidError",e[e.TokenMalformedError=1503]="TokenMalformedError",e[e.TokenNotValidYetError=1504]="TokenNotValidYetError",e[e.TokenUnknownError=1505]="TokenUnknownError",e[e.TokenKickedError=1506]="TokenKickedError",e[e.TokenNotExistError=1507]="TokenNotExistError"}(b||(b={}));const R={[b.TokenExpiredError]:v.OnUserTokenExpired,[b.TokenInvalidError]:v.OnUserTokenInvalid,[b.TokenMalformedError]:v.OnUserTokenInvalid,[b.TokenNotValidYetError]:v.OnUserTokenInvalid,[b.TokenUnknownError]:v.OnUserTokenInvalid,[b.TokenKickedError]:v.OnKickedOffline,[b.TokenNotExistError]:v.OnUserTokenInvalid};var A,N,U,O,E,k,F,q,L,x,P,B,V,_,H,j,J,W,$;!function(e){e[e.Nomal=0]="Nomal",e[e.NotReceive=1]="NotReceive",e[e.NotNotify=2]="NotNotify"}(A||(A={})),function(e){e[e.Allowed=0]="Allowed",e[e.NotAllowed=1]="NotAllowed"}(N||(N={})),function(e){e[e.Group=2]="Group",e[e.WorkingGroup=2]="WorkingGroup"}(U||(U={})),function(e){e[e.Invitation=2]="Invitation",e[e.Search=3]="Search",e[e.QrCode=4]="QrCode"}(O||(O={})),function(e){e[e.Nomal=20]="Nomal",e[e.Admin=60]="Admin",e[e.Owner=100]="Owner"}(E||(E={})),function(e){e[e.ApplyNeedInviteNot=0]="ApplyNeedInviteNot",e[e.AllNeed=1]="AllNeed",e[e.AllNot=2]="AllNot"}(k||(k={})),function(e){e[e.Sending=1]="Sending",e[e.Succeed=2]="Succeed",e[e.Failed=3]="Failed"}(F||(F={})),function(e){e[e.iOS=1]="iOS",e[e.Android=2]="Android",e[e.Windows=3]="Windows",e[e.MacOSX=4]="MacOSX",e[e.Web=5]="Web",e[e.Linux=7]="Linux",e[e.AndroidPad=8]="AndroidPad",e[e.iPad=9]="iPad"}(q||(q={})),function(e){e[e.Silent=5]="Silent",e[e.Error=4]="Error",e[e.Warn=3]="Warn",e[e.Info=2]="Info",e[e.Debug=1]="Debug",e[e.Trace=0]="Trace"}(L||(L={})),function(e){e[e.Unprocessed=0]="Unprocessed",e[e.Agree=1]="Agree",e[e.Reject=-1]="Reject"}(x||(x={})),function(e){e[e.TextMessage=101]="TextMessage",e[e.PictureMessage=102]="PictureMessage",e[e.VoiceMessage=103]="VoiceMessage",e[e.VideoMessage=104]="VideoMessage",e[e.FileMessage=105]="FileMessage",e[e.AtTextMessage=106]="AtTextMessage",e[e.MergeMessage=107]="MergeMessage",e[e.CardMessage=108]="CardMessage",e[e.LocationMessage=109]="LocationMessage",e[e.CustomMessage=110]="CustomMessage",e[e.TypingMessage=113]="TypingMessage",e[e.QuoteMessage=114]="QuoteMessage",e[e.FaceMessage=115]="FaceMessage",e[e.FriendAdded=1201]="FriendAdded",e[e.OANotification=1400]="OANotification",e[e.GroupCreated=1501]="GroupCreated",e[e.MemberQuit=1504]="MemberQuit",e[e.GroupOwnerTransferred=1507]="GroupOwnerTransferred",e[e.MemberKicked=1508]="MemberKicked",e[e.MemberInvited=1509]="MemberInvited",e[e.MemberEnter=1510]="MemberEnter",e[e.GroupDismissed=1511]="GroupDismissed",e[e.GroupMemberMuted=1512]="GroupMemberMuted",e[e.GroupMemberCancelMuted=1513]="GroupMemberCancelMuted",e[e.GroupMuted=1514]="GroupMuted",e[e.GroupCancelMuted=1515]="GroupCancelMuted",e[e.GroupAnnouncementUpdated=1519]="GroupAnnouncementUpdated",e[e.GroupNameUpdated=1520]="GroupNameUpdated",e[e.BurnMessageChange=1701]="BurnMessageChange",e[e.RevokeMessage=2101]="RevokeMessage"}(P||(P={})),function(e){e[e.Single=1]="Single",e[e.Group=3]="Group",e[e.Notification=4]="Notification"}(B||(B={})),function(e){e[e.Nomal=0]="Nomal",e[e.Baned=1]="Baned",e[e.Dismissed=2]="Dismissed",e[e.Muted=3]="Muted"}(G||(G={})),function(e){e[e.AtNormal=0]="AtNormal",e[e.AtMe=1]="AtMe",e[e.AtAll=2]="AtAll",e[e.AtAllAtMe=3]="AtAllAtMe",e[e.AtGroupNotice=4]="AtGroupNotice"}(V||(V={})),function(e){e[e.All=0]="All",e[e.Owner=1]="Owner",e[e.Admin=2]="Admin",e[e.Nomal=3]="Nomal",e[e.AdminAndNomal=4]="AdminAndNomal",e[e.AdminAndOwner=5]="AdminAndOwner",e[e.NotSelf=6]="NotSelf"}(_||(_={})),function(e){e[e.isBlack=0]="isBlack",e[e.isFriend=1]="isFriend"}(H||(H={})),function(e){e[e.Logout=1]="Logout",e[e.Logging=2]="Logging",e[e.Logged=3]="Logged"}(j||(j={})),function(e){e[e.Online=1]="Online",e[e.Offline=0]="Offline"}(J||(J={})),function(e){e[e.Read=0]="Read",e[e.UnRead=1]="UnRead"}(W||(W={})),function(e){e[e.ViewHistory=0]="ViewHistory",e[e.ViewSearch=1]="ViewSearch"}($||($={}));const K=()=>(36*Math.random()).toString(36).slice(2)+(new Date).getTime().toString(),Q=e=>{const n=(new Date).getTime().toString(),s=Math.floor(Math.random()*(new Date).getTime());return t.hash(n+e+s)},z=e=>{if(e.sessionType===B.Single){const t=[e.sendID,e.recvID].sort();return`si_${t[0]}_${t[1]}`}return e.sessionType===B.Group?`sg_${e.groupID}`:e.sessionType===B.Notification?`sn_${e.sendID}_${e.recvID}`:""},Y=e=>{if(e.sessionType===B.Single){const t=[e.sourceID,e.userID].sort();return`si_${t[0]}_${t[1]}`}return e.sessionType===B.Group?`sg_${e.sourceID}`:e.sessionType===B.Notification?`sn_${e.sourceID}_${e.userID}`:""},X=(e,t)=>!(t in e&&!e[t]),Z={[D.GetNewestSeq]:i.GetMaxSeqResp.decode,[D.PullMsgByRange]:i.PullMessageBySeqsResp.decode,[D.SendMsg]:i.UserSendMsgResp.decode,[D.SendSignalMsg]:i.SignalMessageAssembleResp.decode,[D.PullMsgBySeqList]:i.GetSeqMessageResp.decode,[D.PushMsg]:i.PushMessages.decode,[D.SetBackgroundStatus]:i.SetAppBackgroundStatusResp.decode,[D.WsSubUserOnlineStatus]:i.SubUserOnlineStatusTips.decode,[D.GetConvMaxReadSeq]:i.GetConversationsHasReadAndMaxSeqResp.decode,[D.WSServerConfigMsg]:i.ServerConfig.decode,[f.GetActiveConversations]:i.GetActiveConversationsResp.decode,[f.GetDesignatedConversation]:i.GetConversationsResp.decode},ee=(e,t)=>{if(!e)return null;const s=n(e),i=Z[t];return i?i(new Uint8Array(s)):null},te=(e,t,n)=>{const s=(new Date).getTime(),i=e.userTrigger.cache.getSelfUserInfo();return{clientMsgID:Q(e.userID),createTime:s,sendTime:s,sessionType:0,sendID:e.userID,msgFrom:t,contentType:n,senderPlatformID:e.platform,senderNickname:null==i?void 0:i.nickname,senderFaceUrl:null==i?void 0:i.faceURL,seq:0,isRead:!1,status:F.Sending}};class ne extends Error{constructor(e,t){super(t),this.errCode=void 0,this.name=this.constructor.name,this.errCode=e,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}const se=(e,t,n,s)=>{const i={event:t,operationID:n,data:null,errMsg:"",errCode:0};return e===j.Logout?Promise.reject(g({},i,{errCode:I.ResourceLoadNotCompleteError,errMsg:"Resource load not complete"})):s().then((e=null)=>g({},i,{data:e})).catch(e=>(console.log(e),g({},i,{errCode:e.errCode||I.SdkInternalError,errMsg:e.message||"Internal Error"})))},ie="UTF-8",re="ASCII",oe=ie,ae=65533,ce=function e(t,n){if(t<128)n.push(t);else{const s=[127,2047,65535,2097151];let i=0;for(;;){if(i++,i===s.length)return console.error("UTF-8 Write - attempted to encode illegally high code point - "+t),void e(ae,n);if(t<=s[i]){i+=1;let e,s=0;for(e=0;e>6*(i-1),n.push(s),e=1;e>6*(i-(e+1))&191,n.push(s);return}}}},de=function(e,t,n,s){const i=t.getUint8(n);if(e.bytesRead=1,e.charVal=0,128&i){let r=0,o=i;for(;128&o;)r++,o<<=1;if(1===r)return console.error("UTF-8 read - found continuation byte at beginning of character"),void(e.charVal=ae);if(r>s)return console.error("UTF-8 read - attempted to read "+r+" byte character, "+(s-r)+" bytes past end of buffer"),void(e.charVal=ae);e.charVal=i&255>>r+1;for(let s=1;s>8-(r+1)-1))return console.error("UTF-8 read - found overlong encoding"),e.charVal=ae,void(e.bytesRead=1);e.bytesRead++}if(e.charVal>1114111)return console.error("UTF-8 read - found illegally high code point "+e.charVal),e.charVal=ae,void(e.bytesRead=1)}else e.charVal=i},ge=function(e){const t=[];for(let n=0;n255&&(s="?".charCodeAt(0)),t.push(s)}return t},pe=function(e,t,n,s){const i=void 0===n;let r=t||0;if(!i&&r+n>e.byteLength)throw new Error("Attempted to read "+(r+n-e.byteLength)+" bytes past end of buffer");const o=[],a={};for(;rr-t)&&(de(a,e,r,i?e.byteLength-(r+t):n-(r-t)),r+=a.bytesRead,!i||a.charVal!==s);)o.push(String.fromCharCode(a.charVal));return{str:o.join(""),byteLength:r-t}},le=function(e,t,n,s){const i=[];let r=0;t=t||0;let o=!1;void 0===n&&(o=!0,n=e.byteLength-e.byteOffset);for(let a=0;a=e.byteLength&&(i-=1),e.setUint8(t+i,0),i+1}};const De=e=>(new TextDecoder).decode(e),Me=e=>(new TextEncoder).encode(e);var ye;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(ye||(ye={}));class Se{constructor(e,t,n,s,i,r,o,a=5e3,c=Infinity,d){var u=this;this.url=void 0,this.onMessage=void 0,this.onClose=void 0,this.onReconnecting=void 0,this.onReconnectFailed=void 0,this.onReconnectSuccess=void 0,this.reconnectInterval=void 0,this.maxReconnectAttempts=void 0,this.ws=void 0,this.connectParams=void 0,this.reconnectAttempts=void 0,this.shouldReconnect=void 0,this.isProcessingMessage=!1,this.consecutiveHeartbeatFailures=0,this.connectTimeoutId=null,this.platformNamespace=void 0,this.envListenersInstalled=!1,this.heartbeatConfig={interval:1e4,timeout:5e3,maxFailures:3},this.heartbeatWorker=null,this.legacyTimer=null,this.heartbeatTimeoutId=null,this.workerUrl=null,this.lastPongAt=0,this.forceImmediateReconnect=!1,this.checkPlatform=()=>{if("undefined"!=typeof WebSocket)try{if("undefined"!=typeof window&&window.WebSocket)return"web";if("undefined"!=typeof global&&global.WebSocket)return"web"}catch(e){}return"undefined"!=typeof my&&"function"==typeof my.connectSocket?"my":"undefined"!=typeof uni&&"function"==typeof uni.connectSocket?"uni":"undefined"!=typeof wx&&"function"==typeof wx.connectSocket?"wx":"unknow"},this.urlFormat=()=>{let e="?";for(const[t,n]of Object.entries(this.connectParams))e+=`${t}=${n}&`;return this.url+e.slice(0,-1)},this.startHeartbeat=()=>{if(this.heartbeatWorker&&this.stopHeartbeat(),this.consecutiveHeartbeatFailures=0,"undefined"!=typeof Worker){const e="\n let timerId = null;\n let heartbeatInterval;\n\n self.onmessage = (e) => {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n ";try{const t=new Blob([e],{type:"application/javascript"});this.workerUrl=URL.createObjectURL(t),this.heartbeatWorker=new Worker(this.workerUrl),this.heartbeatWorker.onmessage=e=>{"ping"===e.data.type&&this.sendPing()},this.heartbeatWorker.postMessage({type:"start",interval:this.heartbeatConfig.interval})}catch(e){this.heartbeatWorker=null,this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.legacyTimer=setInterval(()=>{this.sendPing()},this.heartbeatConfig.interval)}}else this.legacyTimer=setInterval(()=>{this.sendPing()},this.heartbeatConfig.interval)},this.connect=(e=1e4)=>"unknow"===this.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise((t,n)=>{if(this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.connectTimeoutId=setTimeout(()=>{this.ws&&(this.ws.close(),this.onClose()),n(new Error(`Connection timeout after ${e}ms`))},e),this.ws&&this.ws.readyState!==ye.CLOSED)this.ws.readyState===this.ws.OPEN?(this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),t()):(this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),n(new Error("WebSocket is in an unknown state")));else{const e=()=>{this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.reconnectAttempts&&this.onReconnectSuccess(),this.reconnectAttempts=0,this.consecutiveHeartbeatFailures=0,this.lastPongAt=Date.now(),this.startHeartbeat(),t()},s=e=>{this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),n(e)};if("web"===this.platformNamespace)this.ws=new WebSocket(this.urlFormat()),this.ws.onopen=e,this.ws.onerror=s;else{const t={url:this.urlFormat(),complete:()=>{}};"my"===this.platformNamespace&&(t.multiple=!0),"uni"===this.platformNamespace&&(this.ws=uni.connectSocket(t)),"wx"===this.platformNamespace&&(this.ws=wx.connectSocket(t)),"my"===this.platformNamespace&&(this.ws=my.connectSocket(t)),this.ws.onOpen(e),this.ws.onError(s)}this.setupEventListeners(),this.installEnvListeners()}}),this.setupEventListeners=()=>{if(!this.ws)return;const e=e=>this.onBinaryMessage(e.data),t=e=>{if(this.shouldReconnect&&this.reconnectAttemptst(),100);const e=()=>{this.onReconnecting(),this.connectParams.operationID=K(),this.connect().catch(()=>{this.onReconnectFailed()}),this.reconnectAttempts++};if(this.forceImmediateReconnect)this.forceImmediateReconnect=!1,e();else{const t=Math.min(this.reconnectInterval*Math.pow(1.5,this.reconnectAttempts),6e4),n=.25*t*(2*Math.random()-1),s=Math.max(t+n,1e3);setTimeout(()=>{e()},s)}}this.stopHeartbeat(),this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null)};"web"===this.platformNamespace?(this.ws.onmessage=e,this.ws.onclose=t):(this.ws.onMessage(e),this.ws.onClose(t))},this.onBinaryMessage=async function(e){if("string"!=typeof e&&"my"===u.platformNamespace&&(e=e.data),"string"==typeof e&&"pong"===JSON.parse(e).type)return u.heartbeatTimeoutId&&(clearTimeout(u.heartbeatTimeoutId),u.heartbeatTimeoutId=null),u.consecutiveHeartbeatFailures=0,void(u.lastPongAt=Date.now());u.isProcessingMessage=!0,await u.onMessage(e,u.connectParams.operationID),u.isProcessingMessage=!1},this.sendPing=()=>{var e;if((null==(e=this.ws)?void 0:e.readyState)===ye.OPEN){if(this.consecutiveHeartbeatFailures>=this.heartbeatConfig.maxFailures)return console.warn(`Heartbeat failed ${this.consecutiveHeartbeatFailures} times, closing connection`),this.ws.close(),this.onClose(),void this.stopHeartbeat();this.heartbeatTimeoutId&&clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=setTimeout(()=>{var e;this.consecutiveHeartbeatFailures++,console.warn(`Heartbeat timeout, consecutive failures: ${this.consecutiveHeartbeatFailures}`),this.consecutiveHeartbeatFailures>=this.heartbeatConfig.maxFailures&&(null==(e=this.ws)||e.close(),this.onClose(),this.stopHeartbeat())},this.heartbeatConfig.timeout);const e=JSON.stringify({type:"ping"});this.ws.send("web"===this.platformNamespace?e:{data:e})}else this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null)},this.forceHealthCheck=(e=!1)=>{this.ws&&this.ws.readyState===ye.OPEN&&(e&&(this.consecutiveHeartbeatFailures=Math.max(this.heartbeatConfig.maxFailures-1,0)),this.sendPing())},this.handleVisibilityChange=()=>{try{"visible"===("undefined"!=typeof document?document.visibilityState:"visible")&&this.forceHealthCheck(!0)}catch(e){}},this.handleOnline=()=>{if(!this.ws||this.ws.readyState!==ye.OPEN)return this.reconnectAttempts=0,this.onReconnecting(),this.connectParams.operationID=K(),void this.connect().catch(()=>{this.onReconnectFailed()});const e=Date.now();this.lastPongAt&&e-this.lastPongAt>this.heartbeatConfig.interval+this.heartbeatConfig.timeout*this.heartbeatConfig.maxFailures&&this.forceHealthCheck(!0)},this.handleOffline=()=>{this.stopHeartbeat()},this.installEnvListeners=()=>{if(!this.envListenersInstalled&&"web"===this.platformNamespace)try{"undefined"!=typeof document&&document.addEventListener&&document.addEventListener("visibilitychange",this.handleVisibilityChange),"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline),window.addEventListener("pageshow",this.handleVisibilityChange),window.addEventListener("focus",this.handleVisibilityChange)),this.envListenersInstalled=!0}catch(e){}},this.removeEnvListeners=()=>{if(this.envListenersInstalled&&"web"===this.platformNamespace){try{"undefined"!=typeof document&&document.removeEventListener&&document.removeEventListener("visibilitychange",this.handleVisibilityChange),"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline),window.removeEventListener("pageshow",this.handleVisibilityChange),window.removeEventListener("focus",this.handleVisibilityChange))}catch(e){}this.envListenersInstalled=!1}},this.sendMessage=e=>{var t;const n=Me(JSON.stringify(e));(null==(t=this.ws)?void 0:t.readyState)===ye.OPEN?this.ws.send("web"===this.platformNamespace?n:{data:Uint8Array.from(n).buffer}):console.error("WebSocket is not open. Message not sent.")},this.close=()=>{var e;this.shouldReconnect=!1,this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),(null==(e=this.ws)?void 0:e.readyState)===ye.OPEN&&(this.ws.close(),this.onClose()),this.stopHeartbeat(),this.removeEnvListeners()},this.forceReconnect=(e=!0)=>{if(this.shouldReconnect=!0,this.reconnectAttempts=0,this.consecutiveHeartbeatFailures=0,e&&(this.forceImmediateReconnect=!0),!this.ws||this.ws.readyState===ye.CLOSED)return this.onReconnecting(),this.connectParams.operationID=K(),void this.connect().catch(()=>{this.onReconnectFailed()});this.stopHeartbeat();try{this.ws.close()}catch(e){this.onReconnecting(),this.connectParams.operationID=K(),this.connect().catch(()=>{this.onReconnectFailed()})}},this.reset=()=>{this.shouldReconnect=!0,this.reconnectAttempts=0,this.consecutiveHeartbeatFailures=0,this.connectTimeoutId&&(clearTimeout(this.connectTimeoutId),this.connectTimeoutId=null),this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.stopHeartbeat(),this.removeEnvListeners()},this.url=e,this.onMessage=n,this.onClose=s,this.onReconnecting=i,this.onReconnectFailed=r,this.onReconnectSuccess=o,this.reconnectInterval=a,this.maxReconnectAttempts=c,this.connectParams=t,this.reconnectInterval=a,this.maxReconnectAttempts=c,this.reconnectAttempts=0,this.shouldReconnect=!0,this.platformNamespace=this.checkPlatform(),d&&(this.heartbeatConfig=g({},this.heartbeatConfig,d))}stopHeartbeat(){this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.heartbeatWorker&&(this.heartbeatWorker.postMessage({type:"stop"}),this.heartbeatWorker.terminate(),this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.heartbeatWorker=null),this.legacyTimer&&(clearInterval(this.legacyTimer),this.legacyTimer=null)}}class Ce{constructor(){this.events=void 0,this.events={}}emit(e,t){return this.events[e]&&this.events[e].forEach(e=>e(t)),this}on(e,t){return this.events[e]?this.events[e].push(t):this.events[e]=[t],this}off(e,t){if(e&&"function"==typeof t&&this.events[e]){const n=this.events[e];if(!n||0===n.length)return;const s=n.findIndex(e=>e===t);-1!==s&&n.splice(s,1)}return this}}const Te=["friendUser"],Ge=["blackUserInfo"],we=e=>{var t,n,s,i,r,o,a,c,d,g,u,p,l,h;return{createTime:null==(t=e.groupInfo)?void 0:t.createTime,creatorUserID:null==(n=e.groupInfo)?void 0:n.creatorUserID,ex:e.ex,groupFaceURL:null==(s=e.groupInfo)?void 0:s.faceURL,groupID:null==(i=e.groupInfo)?void 0:i.groupID,groupName:null==(r=e.groupInfo)?void 0:r.groupName,groupType:null==(o=e.groupInfo)?void 0:o.groupType,handleResult:e.handleResult,handleUserID:e.handleUserID,handledMsg:e.handleMsg,handledTime:e.handleTime,introduction:null==(a=e.groupInfo)?void 0:a.introduction,memberCount:null==(c=e.groupInfo)?void 0:c.memberCount,nickname:null==(d=e.userInfo)?void 0:d.nickname,notification:null==(g=e.groupInfo)?void 0:g.notification,ownerUserID:null==(u=e.groupInfo)?void 0:u.ownerUserID,reqMsg:e.reqMsg,reqTime:e.reqTime,joinSource:e.joinSource,status:null==(p=e.groupInfo)?void 0:p.status,userFaceURL:null==(l=e.userInfo)?void 0:l.faceURL,userID:null==(h=e.userInfo)?void 0:h.userID}},be=e=>({clientMsgID:e.clientMsgID,serverMsgID:e.serverMsgID,createTime:e.createTime,sendTime:e.sendTime,sessionType:e.sessionType,sendID:e.sendID,recvID:e.recvID,msgFrom:e.msgFrom,contentType:e.contentType,senderPlatformID:e.senderPlatformID,senderNickname:e.senderNickname,senderFaceUrl:e.senderFaceURL,groupID:e.groupID,content:e.content.length?De(e.content):"",seq:e.seq,isRead:e.isRead,status:C.MsgStatusSendSuccess,isExternalExtensions:!1,offlinePush:e.offlinePushInfo,attachedInfo:e.attachedInfo,ex:e.ex,localEx:""}),Re=t=>{const n=g({},t);try{switch(t.contentType){case M.Text:n.textElem=JSON.parse(n.content);break;case M.Picture:n.pictureElem=JSON.parse(n.content);break;case M.Sound:n.soundElem=JSON.parse(n.content);break;case M.Video:n.videoElem=JSON.parse(n.content);break;case M.File:n.fileElem=JSON.parse(n.content);break;case M.AtText:n.atTextElem=JSON.parse(n.content);break;case M.Location:n.locationElem=JSON.parse(n.content);break;case M.Custom:case M.CustomMsgNotTriggerConversation:case M.CustomMsgOnlineOnly:n.customElem=JSON.parse(n.content);break;case M.Typing:n.typingElem=JSON.parse(n.content);break;case M.Merger:n.mergeElem=JSON.parse(n.content);break;case M.Face:n.faceElem=JSON.parse(n.content);break;case M.Quote:n.quoteElem=JSON.parse(n.content);break;case M.Card:n.cardElem=JSON.parse(n.content);break;default:n.notificationElem=JSON.parse(n.content)}}catch(t){e.warn("messageElemFormater messageElem parse failed",n)}if(t.attachedInfo)try{n.attachedInfoElem=JSON.parse(n.attachedInfo),n.attachedInfo=""}catch(t){e.warn("messageElemFormater attachedInfoElem failed",n.attachedInfo)}return n.content="",n},Ae=e=>{const t=De(e),n=JSON.parse(t);return JSON.parse(n.detail)},Ne=async({conversation:e,group:t,friend:n,user:s,lastMsg:i,maxSeq:r,readSeq:o},a,c)=>{var d,g;let u,p="",l=i?JSON.stringify(Re(be(i))):"";var h,f,m;if((null==e?void 0:e.conversationType)===B.Group?(u=null!=(h=null==t?void 0:t.groupName)?h:"",p=null!=(f=null==t?void 0:t.faceURL)?f:""):(u=(null==n?void 0:n.remark)||(null==s?void 0:s.nickname)||"",p=null!=(m=null==s?void 0:s.faceURL)?m:""),(null==i?void 0:i.status)===C.MsgStatusHasDeleted){const t=await a({conversationID:null==e?void 0:e.conversationID,seq:i.seq,operationID:K()});t&&(l=JSON.stringify(Re(t)))}return{conversationID:e.conversationID,conversationType:e.conversationType,userID:e.userID,groupID:e.groupID,showName:u,faceURL:p,recvMsgOpt:e.recvMsgOpt,unreadCount:r-o,groupAtType:e.groupAtType,latestMsg:l,latestMsgSendTime:null!=(d=null!=(g=null==i?void 0:i.sendTime)?g:c)?d:0,draftText:"",draftTextTime:0,burnDuration:e.burnDuration,msgDestructTime:e.msgDestructTime,isPinned:e.isPinned,isPrivateChat:e.isPrivateChat,isMsgDestruct:e.isMsgDestruct,attachedInfo:e.attachedInfo,ex:e.ex}},Ue=e=>{let{friendUser:t}=e;return g({},u(e,Te),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL,attachedInfo:""})},Oe=e=>{let{blackUserInfo:t}=e;return g({},u(e,Ge),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL})};class Ee{constructor(e){this.store=void 0,this.options=void 0,this.expiryListeners=[],this.cleanupTimer=void 0,this.options=e,this.store=new Map,this.options.cleanupInterval>0&&(this.cleanupTimer=setInterval(()=>{this.deleteExpired()},this.options.cleanupInterval))}onExpiry(e){this.expiryListeners.push(e)}triggerExpiry(e,t){this.expiryListeners.forEach(n=>n(e,t)),this.delete(e)}set(e,t){this.delete(e);const n=Date.now();let s=null;this.options.ttl>0&&(s=setTimeout(()=>{clearTimeout(s),this.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:s,created:n})}get(e){const t=this.store.get(e);if(t&&Date.now()-t.created{e.timer&&clearTimeout(e.timer)}),this.store.clear()}deleteExpired(){const e=Date.now();this.store.forEach((t,n)=>{t.created+this.options.ttl<=e&&this.triggerExpiry(n,t.value)})}dispose(){this.cleanupTimer&&clearInterval(this.cleanupTimer),this.clear()}}const ke=15e3;var Fe;!function(e){e.Success="stateCodeSuccess",e.End="stateCodeEnd"}(Fe||(Fe={}));class qe{constructor(e){var t=this;this.ctx=void 0,this.send=void 0,this.state=void 0,this.platformIDs=[],this.platformIDSet=new Map,this.reset=()=>{this.send.clear(),this.state.clear()},this.changeInputStates=async function({conversationID:e,focus:n,operationID:s}){const r=await t.ctx.messageTrigger.getOneConversationAndTryChange(e,s);if(!r)throw new Error("conversation not exist");if(n){if(t.send.get(e)===Fe.Success)return;t.send.set(e,Fe.Success)}else{if(!t.send.get(e))return;if(t.send.get(e)===Fe.End)return;t.send.set(e,Fe.End)}const o=te(t.ctx,S.UserMsgType,P.TypingMessage);o.recvID=r.userID,o.groupID=r.groupID,o.sessionType=r.conversationType,o.content=JSON.stringify({msgTips:n?"yes":"no"});const a={};Object.values(T).forEach(e=>a[e]=!1);const c=i.MsgData.encode(g({},o,{content:Me(o.content),senderFaceURL:o.senderFaceUrl,options:a,offlinePushInfo:void 0,atUserIDList:[],keyVersion:0,dstUserIDs:[]})).finish();await t.ctx.sendReqWaitResp({data:c,operationID:s,reqIdentifier:D.SendMsg})},this.onNewMessage=async function(e){const n=e.typingElem;if(e.sendID===t.ctx.userID)return;if(!t.platformIDSet.has(e.senderPlatformID))return;const s=Date.now()+10,i=Y({sourceID:e.groupID||e.sendID,sessionType:e.sessionType,userID:t.ctx.userID}),r=JSON.stringify({conversationID:i,platformID:e.senderPlatformID,userID:e.sendID});"yes"===(null==n?void 0:n.msgTips)?(t.state.get(r)||setTimeout(()=>t.triggerChange(i,e.sendID)),t.state.set(r,s)):t.triggerChange(i,e.sendID)},this.triggerChange=(e,t)=>{this.ctx.triggerEvent({event:v.OnConversationUserInputStatusChanged,data:{conversationID:e,userID:t,platformIDs:this.getInputStates(e,t)}})},this.getInputStates=(e,t)=>{const n=[];return this.platformIDs.forEach(s=>{const i=JSON.stringify({conversationID:e,platformID:s,userID:t});this.state.get(i)&&n.push(s)}),n},this.ctx=e,this.send=new Ee({ttl:1e4,cleanupInterval:ke}),this.state=new Ee({ttl:ke,cleanupInterval:ke}),[1,2,3,4,5,7,8,9].forEach(e=>{this.platformIDSet.set(e),this.platformIDs.push(e)}),this.platformIDs.sort((e,t)=>e-t),this.state.onExpiry(e=>{const{conversationID:t,userID:n}=JSON.parse(e);this.triggerChange(t,n)})}}class Le{constructor(t){var n=this;this.instance=void 0,this.totalUnreadCount=0,this.cachedNotNotifyConversationIDs=new Set,this.cachedConversations=new Map,this.cachedMessages=new Map,this.cachedFilterMessageSeqs=new Map,this.cachedGroupMessageReadInfo=new Map,this.cachedGroupMessageClientMsgIDs=new Set,this.cachedGroupMessageReadUser=new Map,this.cachedHasReadAndMaxSeqs={},this.clear=()=>{this.totalUnreadCount=0,this.cachedHasReadAndMaxSeqs={},this.cachedNotNotifyConversationIDs.clear(),this.cachedMessages.clear(),this.cachedConversations.clear(),this.cachedFilterMessageSeqs.clear(),this.cachedGroupMessageReadInfo.clear(),this.cachedGroupMessageClientMsgIDs.clear()},this.getActiveConversationsFromServer=async function(e){const t=await n.instance.sendHttpRequest({reqFuncName:f.GetActiveConversations,data:i.GetActiveConversationsReq.encode({ownerUserID:n.instance.userID,count:20}).finish(),operationID:e}),s=ee(t,f.GetActiveConversations);if(!s)return;console.warn(s);const{conversations:r,unreadCount:o}=s;n.totalUnreadCount=o,n.instance.messageTrigger.cache.setCachedConversations(await Promise.all(r.map(async function(t){var s,i,r;return await n.instance.messageTrigger.encryptor.decryption(null==(s=t.conversation)?void 0:s.conversationID,t.lastMsg,e),Ne(t,n.instance.messageTrigger.getPreviousSeqMessage,null==(i=n.instance.messageTrigger.cache.getCachedMaxReadSeq(null==(r=t.conversation)?void 0:r.conversationID))?void 0:i.maxSeqTime)})))},this.getTotalUnreadCount=()=>this.totalUnreadCount,this.setTotalUnreadCount=(e,t)=>{e!==this.totalUnreadCount&&(e<0&&(e=0),this.totalUnreadCount=e,this.instance.triggerEvent({event:v.OnTotalUnreadMessageCountChanged,data:e,operationID:t}))},this.decreaseTotalUnreadCount=(e,t)=>{this.setTotalUnreadCount(this.totalUnreadCount-e,t)},this.getMaxReadSeqs=async function(e,t=[]){const s=i.GetConversationsHasReadAndMaxSeqReq.encode({userID:n.instance.userID,conversationIDs:t}).finish(),r=await n.instance.sendReqWaitResp({operationID:e,data:s,reqIdentifier:D.GetConvMaxReadSeq});r&&(n.instance.isReconnected&&await n.instance.messageTrigger.syncer.compareSeqsAndBatchSync(r.seqs,e),n.cachedHasReadAndMaxSeqs=r.seqs)},this.getSortedConversationIDs=(e,t)=>Object.keys(this.cachedHasReadAndMaxSeqs).sort((e,t)=>this.cachedHasReadAndMaxSeqs[t].maxSeqTime-this.cachedHasReadAndMaxSeqs[e].maxSeqTime).slice(e,e+t),this.getCachedMaxReadSeq=e=>this.cachedHasReadAndMaxSeqs[e],this.addCachedMaxReadSeq=(e,t)=>{this.cachedHasReadAndMaxSeqs[e]=t},this.updateCachedMaxReadSeq=(t,n)=>{this.cachedHasReadAndMaxSeqs[t]?this.cachedHasReadAndMaxSeqs[t]=g({},this.cachedHasReadAndMaxSeqs[t],n):e.warn("updateCachedMaxReadSeq: conversationID not found",t,"seqs",n)},this.removeCachedMaxReadSeq=e=>{delete this.cachedHasReadAndMaxSeqs[e]},this.getNotNotifyConversationIDs=async function(e){const t={userID:n.instance.userID},{conversationIDs:s}=await n.instance.sendHttpRequest({reqFuncName:f.GetNotNotifyConversationIDs,data:t,operationID:e});n.cachedNotNotifyConversationIDs=new Set(null!=s?s:[])},this.isNotNotifyConversation=e=>this.cachedNotNotifyConversationIDs.has(e),this.addNotNotifyConversationID=e=>{this.cachedNotNotifyConversationIDs.has(e)||this.cachedNotNotifyConversationIDs.add(e)},this.deleteNotNotifyConversationID=e=>{this.cachedNotNotifyConversationIDs.has(e)&&this.cachedNotNotifyConversationIDs.delete(e)},this.getCachedConversation=e=>this.cachedConversations.get(e),this.getAllCachedConversations=()=>Array.from(this.cachedConversations.values()),this.setCachedConversations=e=>{e.map(e=>{this.cachedConversations.set(e.conversationID,e)})},this.getCachedMessagesBySeqs=(e,t)=>{const n=this.cachedMessages.get(e)||[],s=[],i=[];return t.forEach(e=>{const t=n.find(t=>t.seq===e);t?i.push(t):s.push(e)}),{cachedMessages:i,unCachedSeqs:s}},this.getCachedMessageByClientMsgIDs=(e,t)=>(this.cachedMessages.get(e)||[]).filter(e=>t.includes(e.clientMsgID)),this.addMessagesToCache=(e,t)=>{const n=this.cachedMessages.get(e)||[];this.cachedMessages.set(e,[...n,...t])},this.deleteMessageFromCache=(e,t)=>{const n=this.cachedMessages.get(e)||[];this.cachedMessages.set(e,n.filter(e=>e.seq!==t)),this.addFilterSeqsToCache(e,[t])},this.clearCachedConversationMessages=e=>{this.cachedMessages.delete(e)},this.markCachedMessagesAsRead=(e,t)=>{(this.cachedMessages.get(e)||[]).forEach(e=>{(!t&&e.sendID!==this.instance.userID||null!=t&&t.includes(e.seq))&&(e.isRead=!0)})},this.tryUpdateCachedMessages=(e,t)=>{const n=this.cachedMessages.get(e)||[],s=n.findIndex(e=>e.clientMsgID===t.clientMsgID);if(-1!==s)return Object.assign(n[s],t),n[s]},this.tryUpdateQuotedMessage=(e,t)=>{const n=this.cachedMessages.get(e)||[],s=n.findIndex(e=>{var n;if(e.contentType===M.Quote)return(null==(n=Re(e).quoteElem)?void 0:n.quoteMessage.clientMsgID)===t});if(-1!==s){const e=JSON.parse(n[s].content);e.quoteMessage.contentType=y.RevokeNotification,Object.assign(n[s],{content:JSON.stringify(e)})}},this.addFilterSeqsToCache=(e,t)=>{const n=this.cachedFilterMessageSeqs.get(e)||[];this.cachedFilterMessageSeqs.set(e,[...n,...t])},this.checkIsFilterSeq=(e,t)=>{var n;return null==(n=this.cachedFilterMessageSeqs.get(e))?void 0:n.includes(t)},this.getGroupMessageHasReadInfo=async function({conversationID:e,messages:t,operationID:s}){if(t[0].sessionType!==B.Group)return;const i=t.filter(e=>!(e.contentType>y.NotificationBegin&&e.contentTypee.clientMsgID);if(!i.length)return;const r={clientMsgIDs:i,conversationID:e,userID:n.instance.userID},{num:o}=await n.instance.sendHttpRequest({reqFuncName:f.GetGroupMessageReadNum,data:r,operationID:s}),a=[];for(const i of t){var c,d,u;const t=o[i.clientMsgID];if(!t)continue;const r=null==(c=i.attachedInfoElem)?void 0:c.groupHasReadInfo;if(t.readNum>(null!=(d=null==r?void 0:r.hasReadCount)?d:0)||t.unreadNum&&t.unreadNum<(null!=(u=null==r?void 0:r.unreadCount)?u:0)){var p;const r=g({},i.attachedInfoElem,{groupHasReadInfo:{hasReadCount:t.readNum,unreadCount:t.unreadNum}});n.tryUpdateCachedMessages(e,{clientMsgID:i.clientMsgID,attachedInfo:JSON.stringify(r)});const o=n.getCachedConversation(e),c=JSON.parse(null!=(p=null==o?void 0:o.latestMsg)?p:"{}");c.clientMsgID===i.clientMsgID&&c.seq&&n.instance.messageTrigger.getOneConversationAndTryChange(e,s,{latestMsg:JSON.stringify(g({},c,{attachedInfoElem:r}))}),a.push({clientMsgID:i.clientMsgID,hasReadCount:t.readNum,unreadCount:t.unreadNum,readMembers:[],readUsers:[]}),n.cachedGroupMessageClientMsgIDs.add(i.clientMsgID)}}a.length>0&&n.instance.triggerEvent({event:v.OnRecvGroupReadReceipt,data:{conversationID:e,groupMessageReadInfo:a},operationID:s})},this.chearGroupMessageClientMsgIDs=()=>this.cachedGroupMessageClientMsgIDs.clear(),this.addGroupMessageReadUser=(e,t)=>{const n=this.cachedGroupMessageReadUser.get(e)||[],s=t.filter(e=>!n.some(t=>t.userID===e.userID));this.cachedGroupMessageReadUser.set(e,[...n,...s])},this.getGroupMessageReadUser=e=>{var t;return null!=(t=this.cachedGroupMessageReadUser.get(e))?t:[]},this.instance=t}}class xe{constructor(t){var n=this;this.instance=void 0,this.defaultPullNums=10,this.SplitPullMsgNum=100,this.syncedConversationVersion=0,this.syncedConversationVersionID="",this.reset=()=>{this.syncedConversationVersion=0,this.syncedConversationVersionID=""},this.syncConversationVersion=async function(e){const t={userID:n.instance.userID,version:n.syncedConversationVersion,versionID:n.syncedConversationVersionID},s=await n.instance.sendHttpRequest({operationID:e,reqFuncName:f.GetConversationVersion,data:t});n.syncedConversationVersionID&&n.compareVersionAndTrigger(s),n.syncedConversationVersion=s.version,n.syncedConversationVersionID=s.versionID},this.compareVersionAndTrigger=e=>{const{insert:t,update:s}=e;(null!=t?t:[]).map(async function(e){}),(null!=s?s:[]).map(async function(e){await n.instance.messageTrigger.getOneConversationAndTryChange(e.conversationID,"",g({},e))})},this.compareSeqsAndBatchSync=async function(e,t){const s=new Map;for(const[t,r]of Object.entries(e)){var i;const e=null==(i=n.instance.messageTrigger.cache.getCachedMaxReadSeq(t))?void 0:i.maxSeq;e?r.maxSeq>e&&s.set(t,[e+1,r.maxSeq,r.maxSeqTime]):s.set(t,[0,r.maxSeq,r.maxSeqTime])}n.syncAndTriggerMsgs(s,t)},this.isNotification=e=>e.startsWith("n_"),this.syncAndTriggerMsgs=async function(t,s){if(e.debug("Current sync seqMap",t,t.size),t.size>0){let i=new Map,r=0;for(let[o,a]of t.entries()){const[t,c,d]=a,g=c-t+1;if(g/n.SplitPullMsgNum>1&&n.isNotification(o)){const i=new Map,r=Math.floor(g/n.SplitPullMsgNum);let a=t,u=0;for(let t=0;t<=r;t++){t===r?i.set(o,[a,c,d]):(u=a+n.SplitPullMsgNum,u>c&&(u=c,t=r),i.set(o,[a,u,d]));try{const e=await n.pullMsgBySeqRange(i,s);await n.instance.messageTrigger.triggerConversation(e.msgs,s),await n.instance.messageTrigger.triggerNotification(e.notificationMsgs,s);for(let[e,t]of i)n.instance.messageTrigger.cache.updateCachedMaxReadSeq(e,{maxSeq:t[1],maxSeqTime:t[2]});a=u+1}catch(t){throw e.error("Sync message from server error",t,i),t}}}else if(i.set(o,a),r+=g,r>=n.SplitPullMsgNum)try{const e=await n.pullMsgBySeqRange(i,s);await n.instance.messageTrigger.triggerConversation(e.msgs,s),await n.instance.messageTrigger.triggerNotification(e.notificationMsgs,s);for(let[e,t]of i)n.instance.messageTrigger.cache.updateCachedMaxReadSeq(e,{maxSeq:t[1],maxSeqTime:t[2]});i=new Map,r=0}catch(t){throw e.error("Sync message from server error",t,i),t}}try{const e=await n.pullMsgBySeqRange(i,s);await n.instance.messageTrigger.triggerConversation(e.msgs,s),await n.instance.messageTrigger.triggerNotification(e.notificationMsgs,s);for(let[e,s]of t)n.instance.messageTrigger.cache.updateCachedMaxReadSeq(e,{maxSeq:s[1],maxSeqTime:s[2]})}catch(n){throw e.error("Sync message from server error",n,t),n}}else e.debug("Nothing to sync")},this.pullMsgBySeqRange=async function(t,s){const o=[...t.entries()].map(([e,t])=>({conversationID:e,begin:t[0],end:t[1],num:n.defaultPullNums}));e.debug("PullMsgBySeqRange with opid: ",s,"seqRanges: ",o);const a=i.PullMessageBySeqsReq.encode({userID:n.instance.userID,seqRanges:o,order:r.PullOrder.PullOrderAsc}).finish();return await n.instance.sendReqWaitResp({operationID:s,data:a,reqIdentifier:D.PullMsgByRange})},this.instance=t}}class Pe{uint8ArrayToWordArray(e){const t=[];let n=0;const s=e.length;for(;n>24&255,s>>16&255,s>>8&255,255&s];for(let e=0;e<4&&isetTimeout(e,1e3))}if(!i)throw new Error("getEncryptionKeyFromServer failed");let r={version:0,key:""};for(const e of i)e.version>r.version&&(r=e),n.cachedVersionKeys.set(Ve(t.conversationID,e.version),e);return n.cachedVersionKeys.set(_e(t.conversationID),r),[i,r]},this.getMaxVersionKey=async function(e,t){const s=n.cachedVersionKeys.get(_e(e));if(s)return s;const[,i]=await n.getEncryptionKeyFromServer({conversationID:e,keyVersion:0},t);return i},this.getKeyByMessageVersion=async function(t,s){const i=n.cachedVersionKeys.get(Ve(t.conversationID,t.keyVersion));if(i)return i;const[r]=await n.getEncryptionKeyFromServer(t,s);if(!r.length)throw e.error("version key not found, verion: ",t.keyVersion," conversationID: ",t.conversationID),new Error("getKeyByMessageVersion failed");return r[0]},this.encryption=async function(e,t,s){if(!n.ctx.serverConfig.isEncryption)return;const i=await n.getMaxVersionKey(e,s);t.content=n.aesEncryptor.encryption(t.content,i.key),t.keyVersion=i.version},this.decryption=async function(t,s,i){if(s&&0!==s.keyVersion)if(s.sessionType!==B.Single&&s.sessionType!==B.Notification||s.recvID===n.ctx.userID||s.sendID===n.ctx.userID)if(s.contentType!==P.RevokeMessage&&s.status!==C.MsgStatusHasDeleted)try{const e=await n.getMaxVersionKey(t,i);s.content=n.aesEncryptor.decryption(s.content,e.key)}catch(t){e.warn("decryption with error: ",t,"msgData: ",s)}else e.debug("message is revoke notification or has deleted",s);else e.warn("maybe message come from app manager",s)},this.ctx=t}}function Ve(e,t){return`${e}_v_${t}`}function _e(e){return`${e}_v_max`}const He=[C.MsgStatusHasDeleted,C.MsgStatusFiltered];class je{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredConversationEvent=new Map,this.encryptor=void 0,this.typingManager=void 0,this.sync=async function(e){await n.cache.getMaxReadSeqs(e);const t=[n.syncer.syncConversationVersion(e),n.cache.getActiveConversationsFromServer(e),n.cache.getNotNotifyConversationIDs(e)];await Promise.all(t)},this.reset=()=>{this.cache.clear(),this.syncer.reset(),this.typingManager.reset(),this.triggeredConversationEvent.clear()},this.setTriggeredConversationEvent=e=>{this.triggeredConversationEvent.set(e,!0)},this.getMessageWithCacheBySeqs=async function(t,s,i){const{cachedMessages:r,unCachedSeqs:o}=n.cache.getCachedMessagesBySeqs(t,s),a=[...r];let c=0;if(e.debug("after getCachedMessagesBySeqs with opid: ",i,"seqs: ",s,"cachedMessages: ",r,"unCachedSeqs: ",o),o.length){const e=await n.getMessageFromServerBySeqs([{conversationID:t,seqs:o}],i),s=[],r=[],d=e.msgs[t].Msgs.map(async function(e){He.includes(e.status)?(s.push(e.seq),c++):(await n.encryptor.decryption(t,e,i),r.push(be(e)))});await Promise.all(d),e.msgs[t].Msgs.length||s.push(...o),n.cache.addMessagesToCache(t,r),n.cache.addFilterSeqsToCache(t,s),a.push(...r)}return a.sort((e,t)=>e.seq-t.seq),{messages:a,filterCount:c}},this.getPreviousSeqMessage=async function({conversationID:e,seq:t,operationID:s}){if(!t||t<1)return null;const i=[];for(let s=t;i.length<10&&!(s<1);s--)n.cache.checkIsFilterSeq(e,s)||i.push(s);const{messages:r}=await n.getMessageWithCacheBySeqs(e,i,s);return r.length?r[r.length-1]:await n.getPreviousSeqMessage({seq:i[i.length-1],operationID:s,conversationID:e})},this.initConversation=async function(e){let t={conversationID:Y(g({},e,{userID:n.instance.userID})),userID:"",groupID:"",recvMsgOpt:A.Nomal,unreadCount:0,groupAtType:V.AtNormal,latestMsg:"",latestMsgSendTime:0,draftText:"",draftTextTime:0,burnDuration:0,msgDestructTime:0,isPinned:!1,isPrivateChat:!1,isMsgDestruct:!1,attachedInfo:"",ex:""};if(e.sessionType===B.Group){const s=await n.instance.groupTrigger.cache.getGroupInfosWithCache([e.sourceID],e.operationID);if(!s[0])throw new Error("target group not exist");t.showName=s[0].groupName,t.faceURL=s[0].faceURL,t.conversationType=B.Group,t.groupID=e.sourceID}else{t.userID=e.sourceID,t.conversationType=B.Single;const{data:s}=await n.instance.getSpecifiedFriendsInfo([e.sourceID],e.operationID);if(s.length)t.showName=s[0].remark||s[0].nickname,t.faceURL=s[0].faceURL;else{const{data:s}=await n.instance.getUsersInfo([e.sourceID],e.operationID);t.showName=s[0].nickname,t.faceURL=s[0].faceURL}}return n.cache.setCachedConversations([t]),t},this.getConversationsWithCacheByIDs=async function(e,t){const s=[],r=[],o=[];if(e.forEach(e=>{const t=n.cache.getCachedConversation(e);t?s.push(t):o.push(e)}),o.length){const e=await n.instance.sendHttpRequest({reqFuncName:f.GetDesignatedConversation,data:i.GetConversationsReq.encode({ownerUserID:n.instance.userID,conversationIDs:o}).finish(),operationID:t}),{conversations:s}=ee(e,f.GetDesignatedConversation);r.push(...await Promise.all(s.map(async function(e){var s,i,r;return await n.instance.messageTrigger.encryptor.decryption(null==(s=e.conversation)?void 0:s.conversationID,e.lastMsg,t),Ne(e,n.getPreviousSeqMessage,null==(i=n.cache.getCachedMaxReadSeq(null==(r=e.conversation)?void 0:r.conversationID))?void 0:i.maxSeqTime)}))),n.cache.setCachedConversations(r)}return[...s,...r]},this.getOneConversationAndTryChange=async function(e,t,s,r,o){let a;if(a=n.cache.getCachedConversation(e),a)void 0!==(null==s?void 0:s.recvMsgOpt)&&(s.recvMsgOpt===A.Nomal?n.cache.deleteNotNotifyConversationID(e):n.cache.addNotNotifyConversationID(e)),s&&Object.assign(a,s),r&&(a.unreadCount+=1);else if(n.cache.getCachedMaxReadSeq(e)){var c;const s=await n.instance.sendHttpRequest({reqFuncName:f.GetDesignatedConversation,data:i.GetConversationsReq.encode({ownerUserID:n.instance.userID,conversationIDs:[e]}).finish(),operationID:t}),{conversations:r}=ee(s,f.GetDesignatedConversation);if(!r)return;a=await Ne(r[0],n.getPreviousSeqMessage,null==(c=n.cache.getCachedMaxReadSeq(e))?void 0:c.maxSeqTime),n.cache.setCachedConversations([a])}return a&&s&&n.instance.triggerEvent({event:o?v.OnNewConversation:v.OnConversationChanged,data:[g({},a)],operationID:t}),a},this.getMessageFromServerBySeqs=async function(e,t){const s=i.GetSeqMessageReq.encode({userID:n.instance.userID,conversations:e}).finish();return await n.instance.sendReqWaitResp({operationID:t,data:s,reqIdentifier:D.PullMsgBySeqList})},this.revokeMessage=async function(e,t){var s,i;const{messages:r}=await n.getMessageWithCacheBySeqs(e.conversationID,[e.seq],t),o=r[0];let a=0,c="";if(e.isAdminRevoke||e.sesstionType===B.Single){var d;const{data:s}=await n.instance.getUsersInfo([e.revokerUserID],t);c=null==(d=s[0])?void 0:d.nickname}else if(e.sesstionType===B.Group){var g,u;const s=await n.getOneConversationAndTryChange(e.conversationID,t),i=await n.instance.groupTrigger.cache.getGroupMembersWithCache({groupID:s.groupID,userIDList:[e.revokerUserID],operationID:t});c=null==(g=i[0])?void 0:g.nickname,a=null==(u=i[0])?void 0:u.roleLevel}const p={revokerID:e.revokerUserID,revokerRole:a,clientMsgID:o.clientMsgID,revokerNickname:c,revokeTime:e.revokeTime,sourceMessageSendTime:o.sendTime,sourceMessageSendID:o.sendID,sourceMessageSenderNickname:o.senderNickname,sessionType:e.sesstionType,seq:e.seq,ex:"",isAdminRevoke:e.isAdminRevoke};let l=n.cache.tryUpdateCachedMessages(e.conversationID,{clientMsgID:e.clientMsgID,seq:e.seq,content:JSON.stringify({detail:JSON.stringify(p)}),contentType:y.RevokeNotification});if(n.cache.tryUpdateQuotedMessage(e.conversationID,e.clientMsgID),!l){const s=await n.getMessageFromServerBySeqs([{conversationID:e.conversationID,seqs:[e.seq]}],t);l=be(s.msgs[e.conversationID].Msgs[0])}n.instance.triggerEvent({event:v.OnNewRecvMessageRevoked,data:p,operationID:t}),(null!=(s=null==(i=n.cache.getCachedMaxReadSeq(e.conversationID))?void 0:i.maxSeq)?s:0)<=e.seq&&(n.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:e.revokeTime}),await n.getOneConversationAndTryChange(e.conversationID,t,{latestMsg:JSON.stringify(Re(l)),latestMsgSendTime:e.revokeTime}))},this.triggerTyping=e=>{e.sendID!==this.instance.userID&&this.typingManager.onNewMessage(e)},this.handleGroupReadReceipt=async function(e,t){const s={},i={};for(const t of e.reads){s[t.conversationID]?s[t.conversationID].push(t.clientMsgID):s[t.conversationID]=[t.clientMsgID];const e=t.users.map(e=>({userID:e.userID,readTime:e.readTime}));i[t.clientMsgID]={clientMsgID:t.clientMsgID,hasReadCount:t.readNum,unreadCount:t.unreadNum,readUsers:e,readMembers:[]}}for(const[e,a]of Object.entries(s)){const s=[];for(const c of a){var r,o;const a=i[c];if(!a)continue;let d,u=!1;const p=n.cache.getCachedConversation(e),l=JSON.parse(null!=(r=null==p?void 0:p.latestMsg)?r:"{}");if(l.clientMsgID===c&&l.seq){u=!0;const{messages:s}=await n.getMessageWithCacheBySeqs(e,[l.seq],t);d=s[0]}else d=n.cache.getCachedMessageByClientMsgIDs(e,[c])[0];if(!d||!p)continue;const h=(null==(o=a.readUsers)?void 0:o.map(e=>e.userID))||[];let f=JSON.parse(d.attachedInfo||"{}");f.groupHasReadInfo={hasReadCount:a.hasReadCount,unreadCount:a.unreadCount},n.cache.tryUpdateCachedMessages(e,{clientMsgID:d.clientMsgID,attachedInfo:JSON.stringify(f),isRead:!!h.includes(n.instance.userID)||d.isRead}),u&&n.getOneConversationAndTryChange(e,t,{latestMsg:JSON.stringify(g({},l,{attachedInfoElem:f}))});const m=await n.instance.groupTrigger.cache.getGroupMembersMayNotInGroup({groupID:p.groupID,userIDList:h,operationID:t});s.push({clientMsgID:c,hasReadCount:a.hasReadCount,unreadCount:a.unreadCount,readMembers:m,readUsers:[]})}s.length>0&&n.instance.triggerEvent({event:v.OnRecvGroupReadReceipt,data:{conversationID:e,groupMessageReadInfo:s},operationID:t})}},this.triggerNotification=async function(t,s){for(let[i,r]of Object.entries(t))r.Msgs.map(t=>{t.contentType>y.FriendNotificationBegin&&t.contentTypey.UserNotificationBegin&&t.contentTypey.GroupNotificationBegin&&t.contentTypey.SignalingNotificationBegin&&t.contentType{var s;return t===(null==(s=n.cache.getCachedMaxReadSeq(e.conversationID))?void 0:s.hasReadSeq)});if(i){const{messages:r}=await n.getMessageWithCacheBySeqs(e.conversationID,[i-1],s),o=r[0];o&&(n.cache.updateCachedMaxReadSeq(e.conversationID,{maxSeqTime:t.sendTime}),await n.getOneConversationAndTryChange(e.conversationID,s,{latestMsg:JSON.stringify(Re(o)),latestMsgSendTime:o.sendTime}))}break}case y.HasReadReceipt:{const i=Ae(t.content);if(i.markAsReadUserID===n.instance.userID||!i.seqs.length)return;const{messages:r}=await n.getMessageWithCacheBySeqs(i.conversationID,i.seqs,s),o={userID:i.markAsReadUserID,groupID:"",msgIDList:r.map(e=>e.clientMsgID),readTime:t.sendTime,msgFrom:0,contentType:0,sessionType:r[0].sessionType};e.debug("receipt",o),n.cache.markCachedMessagesAsRead(i.conversationID,i.seqs),n.instance.triggerEvent({event:v.OnRecvC2CReadReceipt,data:[o],operationID:s});const a=r.find(e=>e.seq===i.hasReadSeq);if(a){a.isRead=!0;const e=JSON.stringify(Re(a));await n.getOneConversationAndTryChange(i.conversationID,s,{unreadCount:0,latestMsg:e})}n.cache.decreaseTotalUnreadCount(i.seqs.length,s),n.cache.updateCachedMaxReadSeq(i.conversationID,{hasReadSeq:i.hasReadSeq});break}case y.HasGroupReadReceipt:{const i=Ae(t.content);e.debug("Recv HasGroupReadReceipt",i),n.handleGroupReadReceipt(i,s);break}}},this.triggerConversation=async function(t,s){if(0===Object.keys(t).length)return;e.debug("Trigger conversation",t);let i=!0;n.triggeredConversationEvent.has(s)&&(n.triggeredConversationEvent.delete(s),i=!1);let r=!1,o=n.cache.getTotalUnreadCount();const a=[];for(const[c,d]of Object.entries(t)){const t=d.Msgs.map(t=>{var d,g,u,p;const l=!n.cache.getCachedMaxReadSeq(c),h=t.sendID===n.instance.userID,f=X(t.options,T.IsUnreadCount)&&!h,m=X(t.options,T.IsConversationUpdate),v=X(t.options,T.IsNotPrivate);if(!t.clientMsgID||!c)return;const I=be(t),D=Re(I);if(D.attachedInfoElem=t.attachedInfo?JSON.parse(t.attachedInfo):{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},t.status===C.MsgStatusHasDeleted)return;t.contentType===M.Typing&&n.triggerTyping(D),D.status=C.MsgStatusSendSuccess,I.status=C.MsgStatusSendSuccess,l&&n.cache.addCachedMaxReadSeq(c,{hasReadSeq:h?t.seq:t.seq-1,maxSeq:t.seq,maxSeqTime:t.sendTime}),v||(D.attachedInfoElem.isPrivateChat=!0),m&&(o+=f?1:0,n.cache.updateCachedMaxReadSeq(c,{maxSeqTime:D.sendTime}),i&&n.getOneConversationAndTryChange(c,s,{latestMsg:JSON.stringify(D),latestMsgSendTime:D.sendTime},f,l),a.push(I),n.cache.addMessagesToCache(c,[I]));const y=null!=(d=null==(g=n.cache.getCachedMaxReadSeq(c))?void 0:g.maxSeq)?d:0,S=null!=(u=null==(p=n.cache.getCachedMaxReadSeq(c))?void 0:p.hasReadSeq)?u:0;e.debug("currentMaxSeq",y,"currentHasReadSeq",S),D.seq>y&&(r=l||!n.cache.isNotNotifyConversation(c),n.cache.updateCachedMaxReadSeq(c,{maxSeq:y+1,maxSeqTime:D.sendTime}),h&&(n.cache.updateCachedMaxReadSeq(c,{hasReadSeq:S+1}),n.cache.tryUpdateCachedMessages(c,{clientMsgID:D.clientMsgID,seq:D.seq})))});await Promise.all(t)}if(i&&r&&n.cache.setTotalUnreadCount(o,s),a.length>0){if(!i)return void a.map(e=>{n.cache.tryUpdateCachedMessages(z(e),e)});n.instance.triggerEvent({event:v.OnRecvNewMessages,data:a.map(Re),operationID:s})}},this.instance=t,this.cache=new Le(t),this.encryptor=new Be(t),this.syncer=new xe(t),this.typingManager=new qe(t)}}class Je{constructor(e){var t=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=async function(e,n){const s={groupID:e,idHash:0},{userIDs:i}=await t.instance.sendHttpRequest({reqFuncName:f.GetFullGroupMemberUserIDs,data:s,operationID:n});t.cachedGroupMembersID.set(e,i)},this.getGroupInfosWithCache=async function(e,n){const s=[],i=[];if(e.forEach(e=>{const n=t.cachedGroups.get(e);n?s.push(n):i.push(e)}),!i.length)return s;const r={groupIDs:i},{groupInfos:o}=await t.instance.sendHttpRequest({reqFuncName:h.GetSpecifiedGroupsInfo,data:r,operationID:n});return o&&o.forEach(e=>t.cachedGroups.set(e.groupID,e)),[...s,...null!=o?o:[]]},this.getGroupMembersWithCache=async function({groupID:e,userIDList:n,operationID:s}){var i;const r=null!=(i=t.cachedGroupMembers.get(e))?i:[];if(null!=n&&n.length){const i=[],o=[];if(n.forEach(e=>{const t=r.find(t=>t.userID===e);t?o.push(t):i.push(e)}),!i.length)return o;const a={groupID:e,userIDs:i},{members:c}=await t.instance.sendHttpRequest({reqFuncName:h.GetSpecifiedGroupMembersInfo,data:a,operationID:s});return c&&t.cachedGroupMembers.set(e,[...r,...c]),[...o,...null!=c?c:[]]}return r},this.getGroupMembersMayNotInGroup=async function(e){const n=await t.getGroupMembersWithCache(e),s=e.userIDList.filter(e=>!n.find(t=>t.userID===e));if(s.length){const{data:e}=await t.instance.getUsersInfo(s,operationID);n.push(...e.map(e=>({userID:e.userID,nickname:e.nickname,faceURL:e.faceURL})))}return n},this.updateCachedGroups=e=>{e.map(e=>{this.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=e=>{var t;const n=e[0].groupID,s=null!=(t=this.cachedGroupMembers.get(n))?t:[];this.cachedGroupMembers.set(n,[...s.filter(t=>!e.find(e=>e.userID===t.userID)),...e]);const i=this.instance.messageTrigger.cache.getAllCachedConversations().find(t=>t.groupID===e[0].groupID),r=JSON.parse((null==i?void 0:i.latestMsg)||"{}"),o=e.find(e=>e.userID===r.sendID&&e.nickname!==r.senderNickname);i&&o&&this.instance.messageTrigger.getOneConversationAndTryChange(i.conversationID,"",{latestMsg:JSON.stringify(g({},r,{senderNickname:o.nickname}))})},this.clearCachedGroupMembers=e=>{this.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=e=>this.cachedGroupMembersID.has(e),this.getCachedGroupMembersID=e=>{var t;return null!=(t=this.cachedGroupMembersID.get(e))?t:[]},this.tryAddCachedGroupMembersID=(e,t)=>{if(this.cachedGroupMembersID.has(e)){var n;const s=null!=(n=this.cachedGroupMembersID.get(e))?n:[];this.cachedGroupMembersID.set(e,[...s,...t])}},this.tryDeleteCachedGroupMembersID=(e,t)=>{if(this.cachedGroupMembersID.has(e)){var n;const s=null!=(n=this.cachedGroupMembersID.get(e))?n:[];this.cachedGroupMembersID.set(e,s.filter(e=>!t.includes(e)))}},this.instance=e}clear(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()}}class We{constructor(t){var n=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=async function(e){const t={userID:n.instance.userID,version:n.syncedGroupsVersion,versionID:n.syncedGroupsVersionID},s=await n.instance.sendHttpRequest({reqFuncName:f.GetGroupVersion,data:t,operationID:e});n.syncedGroupsVersionID&&n.compareGroupVersionAndTrigger(s,e),n.syncedGroupsVersion=s.version,n.syncedGroupsVersionID=s.versionID},this.syncGroupInfoAndMemberVersion=async function(e){let t=[];const s=Object.keys(n.syncedGroupMemberVersion);if(t=s.length?s.map(e=>{var t,s;const i=n.syncedGroupMemberVersion[e];return{groupID:e,version:null!=(t=null==i?void 0:i.version)?t:0,versionID:null!=(s=null==i?void 0:i.versionID)?s:""}}):(await n.getJoinedGroupIDs(e)).map(e=>({groupID:e,version:0,versionID:""})),!t.length)return;const i={userID:n.instance.userID,reqList:t},{respList:r}=await n.instance.sendHttpRequest({reqFuncName:f.GetGroupMemberVersion,data:i,operationID:e});Object.keys(n.syncedGroupMemberVersion).length>0&&n.compareGroupMemberVersionAndTrigger(r,e),n.syncedGroupMemberVersion=r;for(let[e,t]of Object.entries(r))t.group&&n.instance.groupTrigger.cache.updateCachedGroups([t.group]),(t.insert||t.update)&&n.instance.groupTrigger.cache.updateCachedGroupMembers(t.insert||t.update)},this.compareGroupVersionAndTrigger=(e,t)=>{const{insert:n,delete:s}=e;(null!=n?n:[]).map(e=>{this.instance.triggerEvent({event:v.OnJoinedGroupAdded,data:e,operationID:t})}),(null!=s?s:[]).map(e=>{this.instance.triggerEvent({event:v.OnJoinedGroupDeleted,data:{groupID:e},operationID:t}),this.instance.groupTrigger.cache.clearCachedGroupMembers(e)})},this.compareGroupMemberVersionAndTrigger=(e,t)=>{for(let[n,s]of Object.entries(e)){const{group:e,insert:i,update:r,delete:o}=s;e&&(this.instance.groupTrigger.updateCachedGroupInfoAndTrigger(e,t),this.instance.groupTrigger.checkConversationUpdate(e)),(null!=i?i:[]).map(e=>{this.instance.triggerEvent({event:v.OnGroupMemberAdded,data:e,operationID:t})}),(null!=r?r:[]).map(e=>this.instance.groupTrigger.updateCachedGroupMemberInfoAndTrigger(e,t)),(null!=o?o:[]).map(e=>{this.instance.triggerEvent({event:v.OnGroupMemberDeleted,data:{groupID:n,userID:e},operationID:t})})}},this.getJoinedGroupIDs=async function(e){const t={idHash:0,userID:n.instance.userID},{groupIDs:s}=await n.instance.sendHttpRequest({reqFuncName:f.GetJoinedGroupIDList,data:t,operationID:e});return null!=s?s:[]},this.addGroupMemberVersion=(e,t)=>{this.syncedGroupMemberVersion[e]=g({},t)},this.updateGroupMemberVersion=(t,n)=>{this.syncedGroupMemberVersion[t]?this.syncedGroupMemberVersion[t]=g({},n):e.warn("updateGroupMemberVersion: group member version not found",t,"new version",n)},this.checkIsJoinGroup=e=>!!this.syncedGroupMemberVersion[e],this.instance=t}reset(){this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={}}}class $e{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredEventMap={[v.OnGroupApplicationAdded]:new Map,[v.OnGroupApplicationAccepted]:new Map,[v.OnGroupApplicationRejected]:new Map},this.sync=e=>{const t=[this.syncer.syncGroupVersion(e),this.syncer.syncGroupInfoAndMemberVersion(e)];return Promise.all(t)},this.setTriggeredEventMap=(e,t)=>{this.triggeredEventMap[e].set(t,!0)},this.checkConversationUpdate=e=>{const t=`sg_${e.groupID}`,n=this.instance.messageTrigger.cache.getCachedConversation(t);!n||n.showName===e.groupName&&n.faceURL===e.faceURL||this.instance.messageTrigger.getOneConversationAndTryChange(t,"",{showName:e.groupName,faceURL:e.faceURL})},this.getDesignatedGroupApplicationAndTrigger=async function({event:e,userID:t,groupID:s,operationID:i,activeTrigger:r=!1}){if(!r&&n.triggeredEventMap[e].has(i))return void n.triggeredEventMap[e].delete(i);const o={groupID:s,userID:null!=t?t:n.instance.userID},{groupRequests:a}=await n.instance.sendHttpRequest({reqFuncName:f.GetDesignatedGroupApplication,data:o,operationID:i});a&&n.instance.triggerEvent({event:e,operationID:i,data:a.map(we)[0]})},this.updateCachedGroupInfoAndTrigger=(e,t)=>{this.cache.updateCachedGroups([e]),this.instance.triggerEvent({event:v.OnGroupInfoChanged,data:e,operationID:t})},this.updateCachedGroupMemberInfoAndTrigger=(e,t)=>{this.cache.updateCachedGroupMembers([e]),this.instance.triggerEvent({event:v.OnGroupMemberInfoChanged,data:e,operationID:t})},this.parseMessageAndTrigger=async function(t,s){switch(t.contentType){case y.JoinGroupApplicationNotification:{var i,r;const o=Ae(t.content);e.debug("Recv JoinGroupApplicationNotification with opid: ",s,"tips: ",o),await n.getDesignatedGroupApplicationAndTrigger({event:v.OnGroupApplicationAdded,userID:null==(i=o.applicant)?void 0:i.userID,groupID:null==(r=o.group)?void 0:r.groupID,operationID:s});break}case y.GroupApplicationAcceptedNotification:{var o,a;const i=Ae(t.content);e.debug("Recv GroupApplicationAcceptedNotification with opid: ",s,"tips: ",i),await n.getDesignatedGroupApplicationAndTrigger({event:v.OnGroupApplicationAccepted,userID:i.receiverAs?null==(o=i.opUser)?void 0:o.userID:void 0,groupID:null==(a=i.group)?void 0:a.groupID,operationID:s});break}case y.GroupApplicationRejectedNotification:{var c,d;const i=Ae(t.content);e.debug("Recv GroupApplicationRejectedNotification with opid: ",s,"tips: ",i),await n.getDesignatedGroupApplicationAndTrigger({event:v.OnGroupApplicationRejected,userID:i.receiverAs?null==(c=i.opUser)?void 0:c.userID:void 0,groupID:null==(d=i.group)?void 0:d.groupID,operationID:s});break}case y.GroupCreatedNotification:{const i=Ae(t.content);e.debug("Recv GroupCreatedNotification with opid: ",s,"tips: ",i),n.cache.updateCachedGroups([i.group]),await n.syncer.syncGroupVersion(s),n.syncer.addGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID});break}case y.GroupInfoSetNotification:{const i=Ae(t.content);e.debug("Recv GroupInfoSetNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.checkConversationUpdate(i.group),n.updateCachedGroupInfoAndTrigger(i.group,s);break}case y.MemberQuitNotification:{var g,u,p;const i=Ae(t.content);e.debug("Recv MemberQuitNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s),n.cache.tryDeleteCachedGroupMembersID(null==(g=i.group)?void 0:g.groupID,[null==(u=i.quitUser)?void 0:u.userID]);const r=(null==(p=i.quitUser)?void 0:p.userID)===n.instance.userID;r&&await n.syncer.syncGroupVersion(s),r||n.instance.triggerEvent({event:v.OnGroupMemberDeleted,data:i.quitUser,operationID:s});break}case y.GroupOwnerTransferredNotification:{const i=Ae(t.content);e.debug("Recv GroupOwnerTransferredNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s),n.updateCachedGroupMemberInfoAndTrigger(i.oldGroupOwnerInfo,s),n.updateCachedGroupMemberInfoAndTrigger(i.newGroupOwner,s);break}case y.MemberKickedNotification:{var l;const i=Ae(t.content);e.debug("Recv MemberKickedNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s),n.cache.tryDeleteCachedGroupMembersID(null==(l=i.group)?void 0:l.groupID,i.kickedUserList.map(e=>e.userID));const r=i.kickedUserList.find(e=>e.userID===n.instance.userID);r&&await n.syncer.syncGroupVersion(s),r||i.kickedUserList.map(e=>n.instance.triggerEvent({event:v.OnGroupMemberDeleted,data:e,operationID:s}));break}case y.MemberInvitedNotification:{var h;const i=Ae(t.content);e.debug("Recv MemberInvitedNotification with opid: ",s,"tips: ",i);const r=i.invitedUserList.find(e=>e.userID===n.instance.userID);r&&(await n.syncer.syncGroupVersion(s),n.syncer.addGroupMemberVersion(i.group.groupID,{})),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s),n.checkConversationUpdate(i.group),n.cache.tryAddCachedGroupMembersID(null==(h=i.group)?void 0:h.groupID,i.invitedUserList.map(e=>e.userID)),r||i.invitedUserList.map(e=>n.instance.triggerEvent({event:v.OnGroupMemberAdded,data:e,operationID:s}));break}case y.MemberEnterNotification:{var f,m,I;const i=Ae(t.content);e.debug("Recv MemberEnterNotification with opid: ",s,"tips: ",i);const r=(null==(f=i.entrantUser)?void 0:f.userID)===n.instance.userID;r&&(await n.syncer.syncGroupVersion(s),n.syncer.addGroupMemberVersion(i.group.groupID,{})),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s),n.checkConversationUpdate(i.group),n.cache.tryAddCachedGroupMembersID(null==(m=i.group)?void 0:m.groupID,[null==(I=i.entrantUser)?void 0:I.userID]),r||n.instance.triggerEvent({event:v.OnGroupMemberAdded,data:i.entrantUser,operationID:s});break}case y.GroupDismissedNotification:{const i=Ae(t.content);e.debug("Recv GroupDismissedNotification with opid: ",s,"tips: ",i),await n.syncer.syncGroupVersion(s),n.updateCachedGroupInfoAndTrigger(i.group,s),n.instance.triggerEvent({event:v.OnGroupDismissed,data:i.group,operationID:s});break}case y.GroupMemberMutedNotification:{const i=Ae(t.content);e.debug("Recv GroupMemberMutedNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(i.mutedUser,s);break}case y.GroupMemberCancelMutedNotification:{const i=Ae(t.content);e.debug("Recv GroupMemberCancelMutedNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(i.mutedUser,s);break}case y.GroupMutedNotification:{const i=Ae(t.content);e.debug("Recv GroupMutedNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s);break}case y.GroupCancelMutedNotification:{const i=Ae(t.content);e.debug("Recv GroupCancelMutedNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s);break}case y.GroupMemberInfoSetNotification:{const i=Ae(t.content);e.debug("Recv GroupMemberInfoSetNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(i.changedUser,s);break}case y.GroupMemberSetToAdminNotification:{const i=Ae(t.content);e.debug("Recv GroupMemberSetToAdminNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(i.changedUser,s);break}case y.GroupMemberSetToOrdinaryUserNotification:{const i=Ae(t.content);e.debug("Recv GroupMemberSetToOrdinaryUserNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupMemberInfoAndTrigger(i.changedUser,s);break}case y.GroupInfoSetAnnouncementNotification:{const i=Ae(t.content);e.debug("Recv GroupInfoSetAnnouncementNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.updateCachedGroupInfoAndTrigger(i.group,s);break}case y.GroupInfoSetNameNotification:{const i=Ae(t.content);e.debug("Recv GroupInfoSetNameNotification with opid: ",s,"tips: ",i),n.syncer.updateGroupMemberVersion(i.group.groupID,{version:i.groupMemberVersion,versionID:i.groupMemberVersionID}),n.checkConversationUpdate(i.group),n.updateCachedGroupInfoAndTrigger(i.group,s);break}}},this.instance=t,this.cache=new Je(t),this.syncer=new We(t)}reset(){this.cache.clear(),this.syncer.reset(),Object.keys(this.triggeredEventMap).forEach(e=>{this.triggeredEventMap[e].clear()})}}class Ke{constructor(e){var t=this;this.instance=void 0,this.cachedFriendIDs=[],this.clear=()=>{this.cachedFriendIDs=[]},this.getFullFriendsIDs=async function(e){const n={idHash:0,userID:t.instance.userID},{userIDs:s}=await t.instance.sendHttpRequest({reqFuncName:f.GetFullFriendUserIDs,data:n,operationID:e});return t.cachedFriendIDs=null!=s?s:[],null!=s?s:[]},this.isFriend=e=>this.cachedFriendIDs.includes(e),this.addNewFriend=e=>{this.cachedFriendIDs.push(e)},this.deleteFriend=e=>{this.cachedFriendIDs=this.cachedFriendIDs.filter(t=>t!==e)},this.instance=e}}class Qe{constructor(e){var t=this;this.instance=void 0,this.syncedFriendsVersion=0,this.syncedFriendsVersionID="",this.reset=()=>{this.syncedFriendsVersion=0,this.syncedFriendsVersionID=""},this.syncFriendVersion=async function(e){const n={userID:t.instance.userID,version:t.syncedFriendsVersion,versionID:t.syncedFriendsVersionID},s=await t.instance.sendHttpRequest({reqFuncName:f.GetFriendVersion,data:n,operationID:e});t.syncedFriendsVersionID&&t.compareVersionAndTrigger(s,e),t.syncedFriendsVersion=s.version,t.syncedFriendsVersionID=s.versionID},this.compareVersionAndTrigger=(e,t)=>{const{insert:n,update:s,delete:i}=e;(null!=n?n:[]).map(e=>{this.instance.triggerEvent({operationID:t,event:v.OnFriendAdded,data:Ue(e)})}),(null!=s?s:[]).map(e=>{const n=Ue(e);this.instance.triggerEvent({operationID:t,event:v.OnFriendInfoChanged,data:n});const s=[this.instance.userID,null==n?void 0:n.userID].sort(),i=`si_${s[0]}_${s[1]}`,r=this.instance.messageTrigger.cache.getCachedConversation(i);!r||r.showName===(n.remark||n.nickname)&&r.faceURL===n.faceURL||this.instance.messageTrigger.getOneConversationAndTryChange(i,t,{showName:n.remark||n.nickname,faceURL:n.faceURL})}),(null!=i?i:[]).map(e=>{this.instance.triggerEvent({operationID:t,event:v.OnFriendDeleted,data:{userID:e}})})},this.instance=e}}class ze{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredEventMap={[v.OnFriendApplicationAdded]:new Map,[v.OnFriendApplicationAccepted]:new Map,[v.OnFriendApplicationRejected]:new Map,[v.OnFriendAdded]:new Map,[v.OnFriendDeleted]:new Map,[v.OnFriendInfoChanged]:new Map,[v.OnBlackAdded]:new Map,[v.OnBlackDeleted]:new Map},this.sync=e=>{const t=[this.syncer.syncFriendVersion(e),this.cache.getFullFriendsIDs(e)];return Promise.all(t)},this.reset=()=>{this.cache.clear(),this.syncer.reset(),Object.keys(this.triggeredEventMap).forEach(e=>{this.triggeredEventMap[e].clear()})},this.setTriggeredEventMap=(e,t)=>{this.triggeredEventMap[e].set(t,!0)},this.checkShouldTrigger=(e,t)=>!e||!this.triggeredEventMap[e].has(t)||(this.triggeredEventMap[e].delete(t),!1),this.getDesignatedFriendApplicationAndTrigger=async function(e,t,s,i=!1){if(!i&&n.triggeredEventMap[e].has(s))return void n.triggeredEventMap[e].delete(s);const r={fromUserID:t.fromUserID,toUserID:t.toUserID},{friendRequests:o}=await n.instance.sendHttpRequest({reqFuncName:f.GetDesignatedFriendsApplication,data:r,operationID:s});o&&n.instance.triggerEvent({event:e,operationID:s,data:o[0]})},this.getDesignatedBlackUserAndTrigger=async function(e,t,s,i=!1){if(!i&&n.triggeredEventMap[e].has(s))return void n.triggeredEventMap[e].delete(s);const r={ownerUserID:n.instance.userID,userIDList:[t]},{blacks:o}=await n.instance.sendHttpRequest({reqFuncName:f.GetDesignatedBlackUser,data:r,operationID:s});o&&n.instance.triggerEvent({event:e,data:o.map(Oe)[0],operationID:s})},this.parseMessageAndTrigger=async function(t,s){switch(t.contentType){case y.FriendApplicationNotification:{const i=Ae(t.content);e.debug("Recv FriendApplicationNotification with opid: ",s,"tips: ",i),await n.getDesignatedFriendApplicationAndTrigger(v.OnFriendApplicationAdded,i.fromToUserID,s);break}case y.FriendApplicationApprovedNotification:{const i=Ae(t.content);e.debug("Recv FriendApplicationApprovedNotification with opid: ",s,"tips: ",i),await Promise.all([await n.getDesignatedFriendApplicationAndTrigger(v.OnFriendApplicationAccepted,i.fromToUserID,s),async function(){n.checkShouldTrigger(v.OnFriendAdded,s)&&await n.syncer.syncFriendVersion(s)}]);break}case y.FriendApplicationRejectedNotification:{const i=Ae(t.content);e.debug("Recv FriendApplicationRejectedNotification with opid: ",s,"tips: ",i),await n.getDesignatedFriendApplicationAndTrigger(v.OnFriendApplicationRejected,i.fromToUserID,s);break}case y.FriendAddedNotification:{var i;const r=Ae(t.content);if(e.debug("Recv FriendAddedNotification with opid: ",s,"tips: ",r),!n.checkShouldTrigger(v.OnFriendAdded,s))return;await n.syncer.syncFriendVersion(s),n.cache.addNewFriend(null==(i=r.friend)||null==(i=i.friendUser)?void 0:i.userID);break}case y.FriendDeletedNotification:{var r;const i=Ae(t.content);if(e.debug("Recv FriendDeletedNotification with opid: ",s,"tips: ",i),!n.checkShouldTrigger(v.OnFriendDeleted,s))return;await n.syncer.syncFriendVersion(s),n.cache.deleteFriend(null==(r=i.fromToUserID)?void 0:r.toUserID);break}case y.FriendRemarkSetNotification:{const i=Ae(t.content);if(e.debug("Recv FriendRemarkSetNotification with opid: ",s,"tips: ",i),!n.checkShouldTrigger(v.OnFriendInfoChanged,s))return;await n.syncer.syncFriendVersion(s);break}case y.FriendInfoUpdatedNotification:{const i=Ae(t.content);if(e.debug("Recv FriendInfoUpdatedNotification with opid: ",s,"tips: ",i),!n.checkShouldTrigger(v.OnFriendInfoChanged,s))return;await n.syncer.syncFriendVersion(s);break}case y.BlackAddedNotification:{var o;const i=Ae(t.content);e.debug("Recv BlackAddedNotification with opid: ",s,"tips: ",i),n.getDesignatedBlackUserAndTrigger(v.OnBlackAdded,null==(o=i.fromToUserID)?void 0:o.toUserID,s);break}case y.BlackDeletedNotification:{var a;const i=Ae(t.content);e.debug("Recv BlackDeletedNotification with opid: ",s,"tips: ",i),n.instance.triggerEvent({event:v.OnBlackDeleted,data:{userID:null==(a=i.fromToUserID)?void 0:a.toUserID},operationID:s});break}case y.FriendsInfoUpdateNotification:{const i=Ae(t.content);if(e.debug("Recv FriendsInfoUpdateNotification with opid: ",s,"tips: ",i),!n.checkShouldTrigger(v.OnFriendInfoChanged,s))return;await n.syncer.syncFriendVersion(s);break}}},this.instance=t,this.cache=new Ke(t),this.syncer=new Qe(t)}}class Ye{constructor(t){var n=this;this.instance=void 0,this.parseMessageAndTrigger=async function(t,s){const i=Ae(t.content);e.debug("Recv BussinessMessage with opid: ",s,"tips: ",i),n.instance.triggerEvent({event:v.OnRecvCustomBusinessMessage,data:i,operationID:s})},this.instance=t}}class Xe{constructor(e){var t=this;this.instance=void 0,this.cachedLoginUserInfo=null,this.clear=()=>{this.cachedLoginUserInfo=null},this.getSelfUserInfo=()=>this.cachedLoginUserInfo,this.syncLoginUserInfoAndTrigger=async function(e){const n={userIDs:[t.instance.userID]},{usersInfo:s}=await t.instance.sendHttpRequest({reqFuncName:h.GetSelfUserInfo,data:n,operationID:e});t.cachedLoginUserInfo&&JSON.stringify(t.cachedLoginUserInfo)!==JSON.stringify(s[0])&&t.instance.triggerEvent({event:v.OnSelfInfoUpdated,data:s[0]}),t.cachedLoginUserInfo=s[0]},this.udpateCachedLoginUserInfoAndTrigger=async function(e,n){t.cachedLoginUserInfo&&(t.cachedLoginUserInfo=g({},t.cachedLoginUserInfo,e),t.instance.triggerEvent({event:v.OnSelfInfoUpdated,data:t.cachedLoginUserInfo,operationID:n}))},this.instance=e}}class Ze{constructor(e){var t=this;this.ctx=void 0,this.state=new Map,this.updateSubs=async function({sub:e,unSub:n,operationID:s}){var r;if(0===t.state.size&&!e)return;const{subscribers:o}=null!=(r=await t.ctx.sendReqWaitResp({reqIdentifier:D.WsSubUserOnlineStatus,operationID:s,data:i.SubUserOnlineStatus.encode({subscribeUserID:null!=e?e:Array.from(t.state.keys()),unsubscribeUserID:null!=n?n:[]}).finish()}))?r:{subscribers:[]};o.forEach(e=>t.state.set(e.userID,e.onlinePlatformIDs)),null!=n&&n.length&&n.forEach(e=>t.state.delete(e))},this.getUserOnlineState=async function(e,n){const s=e.filter(e=>!t.state.has(e));return s.length&&await t.updateSubs({operationID:n,sub:s}),e.map(e=>{var n,s;return{userID:e,status:null!=(n=t.state.get(e))&&n.length?1:0,platformIDs:null!=(s=t.state.get(e))?s:[]}})},this.getAllSubUsersOnlineState=()=>Array.from(this.state.keys()).map(e=>{var t,n;return{userID:e,status:null!=(t=this.state.get(e))&&t.length?1:0,platformIDs:null!=(n=this.state.get(e))?n:[]}}),this.userOnlineStateChange=({subscribers:e})=>{e.forEach(e=>{var t;e.onlinePlatformIDs.length?this.state.set(e.userID,e.onlinePlatformIDs):this.state.delete(e.userID),this.ctx.triggerEvent({event:v.OnUserStatusChanged,data:{userID:e.userID,status:e.onlinePlatformIDs.length?1:0,platformIDs:null!=(t=e.onlinePlatformIDs)?t:[]}})})},this.ctx=e}}class et{constructor(t){var n=this;this.instance=void 0,this.cache=void 0,this.onlineSub=void 0,this.triggeredEventMap=new Map,this.sync=e=>Promise.all([this.cache.syncLoginUserInfoAndTrigger(e),this.onlineSub.updateSubs({operationID:e})]),this.reset=()=>{this.cache.clear(),this.triggeredEventMap.clear()},this.setTriggeredEventMap=e=>{this.triggeredEventMap.set(e,!0)},this.checkConversationUpdate=e=>{const t=[this.instance.userID,e.userID].sort(),n=`si_${t[0]}_${t[1]}`,s=this.instance.messageTrigger.cache.getCachedConversation(n);!s||s.showName===e.nickname&&s.faceURL===e.faceURL||this.instance.messageTrigger.getOneConversationAndTryChange(n,"",{showName:e.nickname,faceURL:e.faceURL})},this.parseMessageAndTrigger=async function(t,s){if(t.contentType===y.UserInfoUpdatedNotification){const i=Ae(t.content);if(e.debug("Recv UserInfoUpdatedNotification with opid: ",s,"tips: ",i),n.triggeredEventMap.get(s))return void n.triggeredEventMap.delete(s);i.userID===n.instance.userID&&await n.cache.syncLoginUserInfoAndTrigger(s)}},this.instance=t,this.cache=new Xe(t),this.onlineSub=new Ze(t)}}class tt{constructor(t){var n=this;this.apiService=void 0,this.inviteTimers=new Map,this.reset=()=>{this.inviteTimers.forEach(e=>clearTimeout(e))},this.signalingNotificationHandle=(t,n)=>{var s,i,r;if(t.accept)(null==(s=t.accept.invitation)?void 0:s.inviterUserID)===this.apiService.userID&&(null==(i=t.accept.invitation)?void 0:i.platformID)===this.apiService.platform&&(null==(r=t.accept.invitation)||r.inviteeUserIDList.forEach(e=>{var n;return this.removeInviteTimer(`${null==(n=t.accept)||null==(n=n.invitation)?void 0:n.roomID}_${e}`)}),this.apiService.triggerEvent({event:v.OnInviteeAccepted,data:t.accept,operationID:n})),t.accept.opUserPlatformID!==this.apiService.platform&&t.accept.userID===this.apiService.userID&&this.apiService.triggerEvent({event:v.OnInviteeAcceptedByOtherDevice,data:t.accept,operationID:n});else if(t.reject){var o,a,c;(null==(o=t.reject.invitation)?void 0:o.inviterUserID)===this.apiService.userID&&(null==(a=t.reject.invitation)?void 0:a.platformID)===this.apiService.platform&&(null==(c=t.reject.invitation)||c.inviteeUserIDList.forEach(e=>{var n;return this.removeInviteTimer(`${null==(n=t.reject)||null==(n=n.invitation)?void 0:n.roomID}_${e}`)}),this.apiService.triggerEvent({event:v.OnInviteeRejected,data:t.reject,operationID:n})),t.reject.opUserPlatformID!==this.apiService.platform&&t.reject.userID===this.apiService.userID&&this.apiService.triggerEvent({event:v.OnInviteeRejectedByOtherDevice,data:t.reject,operationID:n})}else if(t.hungUp)this.apiService.userID!==t.hungUp.userID&&this.apiService.triggerEvent({event:v.OnHangUp,data:t.hungUp,operationID:n});else if(t.cancel){var d;null!=(d=t.cancel.invitation)&&d.inviteeUserIDList.includes(this.apiService.userID)&&this.apiService.triggerEvent({event:v.OnInvitationCancelled,data:t.cancel,operationID:n})}else if(t.invite){var g;null!=(g=t.invite.invitation)&&g.inviteeUserIDList.includes(this.apiService.userID)&&this.apiService.triggerEvent({event:v.OnReceiveNewInvitation,data:t.invite,operationID:n})}else if(t.inviteInGroup){var u;null!=(u=t.inviteInGroup.invitation)&&u.inviteeUserIDList.includes(this.apiService.userID)&&this.apiService.triggerEvent({event:v.OnReceiveNewInvitation,data:t.inviteInGroup,operationID:n})}else e.warn("Unknown signaling notification: ",t)},this.removeInviteTimer=e=>{this.inviteTimers.has(e)&&clearTimeout(this.inviteTimers.get(e))},this.addInviteTimer=(e,t,n)=>{var s,i;this.removeInviteTimer(e),this.inviteTimers.set(e,setTimeout(()=>{this.apiService.triggerEvent({event:v.OnInvitationTimeout,data:t,operationID:n})},1e3*(null!=(s=null==(i=t.invitation)?void 0:i.timeout)?s:60)))},this.sendSignalingReqWaitResp=(e,t)=>{if(e.invite||e.inviteInGroup){var n;const s=e.invite||e.inviteInGroup,i=null==s||null==(n=s.invitation)?void 0:n.inviteeUserIDList;null==i||i.forEach(e=>{var n;const i=`${null==s||null==(n=s.invitation)?void 0:n.roomID}_${e}`;this.addInviteTimer(i,s,t)})}if(e.cancel){var s;const t=null==(s=e.cancel)||null==(s=s.invitation)?void 0:s.inviteeUserIDList;null==t||t.forEach(t=>{var n;const s=`${null==(n=e.cancel)||null==(n=n.invitation)?void 0:n.roomID}_${t}`;this.inviteTimers.delete(s)})}return this.apiService.sendReqWaitResp({reqIdentifier:D.SendSignalMsg,data:i.SignalReq.encode(e).finish(),operationID:t})},this.parseMessageAndTrigger=async function(t,s){switch(t.contentType){case y.SignalingNotification:{const r=i.SignalReq.decode(t.content);e.debug("Recv SignalingNotification with opid: ",s,"tips: ",r),n.signalingNotificationHandle(r,s);break}case y.RoomParticipantsConnectedNotification:{const r=i.SignalOnRoomParticipantConnectedReq.decode(t.content);e.debug("Recv RoomParticipantsConnectedNotification with opid: ",s,"tips: ",r),n.apiService.triggerEvent({event:v.OnRoomParticipantConnected,data:r,operationID:s});break}case y.RoomParticipantsDisconnectedNotification:{const r=i.SignalOnRoomParticipantDisconnectedReq.decode(t.content);e.debug("Recv RoomParticipantsDisconnectedNotification with opid: ",s,"tips: ",r),n.apiService.triggerEvent({event:v.OnRoomParticipantDisconnected,data:r,operationID:s});break}case y.StreamChangedNotification:{const r=i.SignalOnStreamChangeReq.decode(t.content);e.debug("Recv StreamChangedNotification with opid: ",s,"tips: ",r),n.apiService.triggerEvent({event:v.OnStreamChange,data:r,operationID:s});break}case y.CustomSignalNotification:{const r=i.SignalSendCustomSignalReq.decode(t.content);e.debug("Recv CustomSignalNotification with opid: ",s,"tips: ",r),n.apiService.triggerEvent({event:v.OnReceiveCustomSignal,data:r,operationID:s});break}}},this.apiService=t}}class nt{constructor(){this.queue=[],this.pending=!1}async enqueue(e){return new Promise((t,n)=>{this.queue.push([()=>e().then(t).catch(n),n]),this.pending||(this.pending=!0,this.dequeue())})}cancelTasks(){this.queue.forEach(([,e])=>e(new ne(I.NetworkError,"network error, ws not connected"))),this.queue=[],this.pending=!1}async dequeue(){for(;this.queue.length>0;){const[t]=this.queue.shift();try{await t()}catch(t){e.error("Error executing task:",t)}}this.pending=!1}}const st={[P.TextMessage]:"textElem",[P.AtTextMessage]:"atTextElem",[P.LocationMessage]:"locationElem",[P.CustomMessage]:"customElem",[P.MergeMessage]:"mergeElem",[P.QuoteMessage]:"quoteElem",[P.CardMessage]:"cardElem",[P.FaceMessage]:"faceElem",[P.PictureMessage]:"pictureElem",[P.VoiceMessage]:"soundElem",[P.VideoMessage]:"videoElem",[P.FileMessage]:"fileElem"},it=[P.PictureMessage,P.VoiceMessage,P.VideoMessage,P.FileMessage];class rt extends Error{constructor(e,t){super(t),this.status=void 0,this.name="HttpError",this.status=e}}const ot=[f.GetActiveConversations,f.GetDesignatedConversation];class at extends Ce{constructor(){var n,r;super(),n=this,this.userID=void 0,this.platform=void 0,this.token=void 0,this.apiAddr=void 0,this.loginStatus=j.Logout,this.isReconnected=!1,this.serverConfig={isEncryption:!1},this.connectState="disconnected",this.wsManager=void 0,this.messageTrigger=void 0,this.userTrigger=void 0,this.groupTrigger=void 0,this.relationTrigger=void 0,this.businessTrigger=void 0,this.signalingTrigger=void 0,this.requestMap=new Map,this.generateHttpHeader=(e,t)=>{const n={"Content-Type":"application/json",token:this.token,operationID:t,reqFuncName:e};return ot.includes(e)&&(n["Content-Type"]="application/x-protobuf"),n},this.sendHttpRequest=async function(e){var t;return await((e,t={})=>{const{url:n,data:s,headers:i,platform:r,method:o="POST"}=e,{retries:a=3,baseDelayMs:c=300,maxDelayMs:d=3e3}=t,u=e=>new Promise(t=>setTimeout(t,e)),p=e=>{if(!e)return!1;if(e instanceof rt)return e.status>=500;if("object"==typeof e&&"number"==typeof e.statusCode)return e.statusCode>=500;const t=String((null==e?void 0:e.message)||e||"").toLowerCase();return!!(t.includes("network")||t.includes("timeout")||t.includes("failed to fetch")||t.includes("request:fail"))};return(async()=>{let t=0;for(;;)try{return await("web"===r?(async({url:e,data:t,headers:n,method:s="POST"})=>fetch(e,{method:s,headers:g({},n),body:t instanceof Uint8Array?t:JSON.stringify(t)}).then(e=>{if(e.ok)return e.json();throw new rt(e.status,e.statusText||`HTTP_${e.status}`)}).then(e=>{if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))(e):new Promise((e,t)=>{const a=(e=>"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null)(r);a?a({url:n,data:s instanceof Uint8Array?Uint8Array.from(s).buffer:s,method:o,header:g({"Content-Type":"application/json"},i),success:n=>{200===n.statusCode&&0===n.data.errCode?e(n.data.data):t({statusCode:n.statusCode,data:n.data})},fail:e=>{t(e)}}):t(new Error("Request is not supported"))}))}catch(e){if(t++,t>a||!p(e))throw e;const n=Math.min(c*Math.pow(2,t-1),d),s=Math.floor(150*Math.random());await u(n+s)}})()})({url:`${n.apiAddr}${e.replaceURL||m[e.reqFuncName]}`,data:e.data,headers:n.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(t=n.wsManager)?void 0:t.platformNamespace)||"web"})},this.handleWsConnected=async function(t,s){if(0===t.errCode){n.connectState="connected",n.loginStatus=j.Logged,n.triggerEvent({event:v.OnConnectSuccess}),n.triggerEvent({event:v.OnSyncServerStart});const t=[n.messageTrigger.sync(s),n.relationTrigger.sync(s),n.groupTrigger.sync(s),n.userTrigger.sync(s)];try{await Promise.all(t),n.triggerEvent({event:v.OnSyncServerFinish})}catch(t){e.error(t),n.triggerEvent({event:v.OnSyncServerFailed,errCode:t.errCode||I.SdkInternalError,errMsg:t.message||"Internal Error"})}}else{n.triggerEvent({event:v.OnConnectFailed,errCode:t.errCode,errMsg:t.errMsg,operationID:s});const e=R[t.errCode];e&&n.triggerEvent({event:e,errCode:t.errCode,errMsg:t.errMsg,operationID:s}),n.connectState="disconnected",n.loginStatus=j.Logout}},this.handleMessage=async function(e,t){if("string"==typeof e){const s=JSON.parse(e);n.handleWsConnected(s,t)}else{e instanceof ArrayBuffer||(e=await e.arrayBuffer());const t=(e=>{const t=new DataView(e);return Ie.getString(t,0,e.byteLength,"UTF-8")})(e),s=JSON.parse(t);n.handleGeneralWsResp(s)}},this.handleGeneralWsResp=e=>{const t=ee(e.data,e.reqIdentifier);if(e.reqIdentifier===D.PushMsg&&t)return this.messageTrigger.triggerConversation(t.msgs,e.operationID),void this.messageTrigger.triggerNotification(t.notificationMsgs,e.operationID);if(e.reqIdentifier!==D.WsSubUserOnlineStatus||e.msgIncr||this.userTrigger.onlineSub.userOnlineStateChange(t),e.reqIdentifier===D.WSServerConfigMsg&&t&&(this.serverConfig=t),e.reqIdentifier===D.KickOnlineMsg)return this.triggerEvent({event:v.OnKickedOffline,operationID:e.operationID}),void this.reset();const n=this.requestMap.get(e.msgIncr);n&&(0===e.errCode?n.resolve(t):n.reject(new ne(e.errCode,e.errMsg)),this.requestMap.delete(e.msgIncr))},this.handleReconnecting=()=>{this.connectState="reconnecting",this.triggerEvent({event:v.OnConnecting})},this.handleReconnectFailed=()=>{this.connectState="disconnected",this.triggerEvent({event:v.OnConnectFailed,errCode:I.NetworkError,errMsg:"network error"}),this.cancelMessageTasks()},this.handleReconnectSuccess=()=>{this.isReconnected=!0,this.messageTrigger.cache.chearGroupMessageClientMsgIDs()},this.sendReqWaitResp=({data:e,reqIdentifier:t,operationID:n})=>{if("connected"!==this.connectState)throw new ne(I.NetworkError,"network error, ws not connected");const i=K();return new Promise((r,o)=>{var a;this.requestMap.set(i,{resolve:r,reject:o}),null==(a=this.wsManager)||a.sendMessage({reqIdentifier:t,msgIncr:i,sendID:this.userID,operationID:n,data:s(e.buffer)})})},this.triggerEvent=({event:t,data:n=null,errCode:s=0,errMsg:i="",operationID:r=""})=>{this.loginStatus!==j.Logout&&(e.debug(`%cSDK =>%c [OperationID:${r}] (event) trigger ${t} with data ${JSON.stringify(n)} errCode ${s} errMsg ${i}`,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),this.emit(t,{event:t,data:n,errCode:s,errMsg:i,operationID:r}))},this.login=async function(t,s){return se(j.Logged,h.Login,s,async function(){var i;const{userID:r,token:o,wsAddr:a,apiAddr:c,platformID:d}=t;if(n.wsManager)throw new ne(I.LoginRepeatError,"login repeat");e.setLevel(null!=(i=t.logLevel)?i:L.Debug),n.userID=r,n.token=o,n.apiAddr=c,n.platform=d,n.wsManager=new Se(a,{sendID:r,token:o,platformID:d,operationID:s,isBackground:!1,isMsgResp:!0,sdkType:"js"},n.handleMessage,n.handleReconnectFailed,n.handleReconnecting,n.handleReconnectFailed,n.handleReconnectSuccess),n.connectState="connecting",n.loginStatus=j.Logging,n.triggerEvent({event:v.OnConnecting,operationID:s});try{await n.wsManager.connect()}catch(e){throw n.triggerEvent({event:v.OnConnectFailed,errCode:I.NetworkError,errMsg:e.message||"network error",operationID:s}),n.connectState="disconnected",n.loginStatus=j.Logout,n.wsManager.close(),new ne(I.NetworkError,e.message||"network error")}})},this.getLoginStatus=e=>se(j.Logged,h.GetLoginStatus,e,async function(){var e;return null==(e=n.wsManager)||e.sendPing(),n.loginStatus}),this.forceReconnect=e=>se(this.loginStatus,h.ForceReconnect,e,async function(){var e;null==(e=n.wsManager)||e.forceReconnect(!0)}),this.logout=e=>se(this.loginStatus,h.Logout,e,async function(){n.reset()}),this.internalUploadFile=async function(e,s,i){try{const r=`${n.userID}/${e.name}`,o=(e=>{var t,n;const s=null!=(t=null==(n=e.split(".").pop())?void 0:n.toLowerCase())?t:"";return l[s]||"application/octet-stream"})(e.name),a={operationID:s,token:n.token},{size:c}=await((e,t,n)=>fetch(`${e}/object/part_size`,{method:"POST",headers:g({},n),body:JSON.stringify({size:t})}).then(p))(n.apiAddr,e.size,a),d=Math.ceil(e.size/c),u=[],h=[];let f=0;for(;f{const s=new FileReader;s.readAsArrayBuffer(i),s.onload=s=>{try{var i;const n=(null==(i=s.target)?void 0:i.result)||new ArrayBuffer(0),r=t.ArrayBuffer.hash(n);e(r)}catch(e){n(e)}},s.onerror=e=>n(e)});h.push(r),f++}const m=h.join(","),v=new t;v.append(m);const{url:I,upload:D}=await((e,t,n)=>fetch(`${e}/object/initiate_multipart_upload`,{method:"POST",headers:g({},n),body:JSON.stringify(t)}).then(p))(n.apiAddr,{hash:v.end(),size:e.size,partSize:c,maxParts:-1,cause:"",name:r,contentType:o},a);if(v.destroy(),I)return null==i||i(100),{url:I};let M=D.sign.parts;const y=D.sign.query,S=D.sign.header,C=4,T=3,G=e=>new Promise(t=>setTimeout(t,e)),w=e.size;let b=0,R=0;null==i||i(0);const A=async function(t){const n=M[t],s=new URL(n.url||D.sign.url);if(y){const e=new URLSearchParams(s.search);y.forEach(t=>{e.set(t.key,t.values[0])}),s.search=e.toString()}if(n.query){const e=new URLSearchParams(s.search);n.query.forEach(t=>{e.set(t.key,t.values[0])}),s.search=e.toString()}const r=s.toString(),a=new Headers;S&&S.forEach(e=>{a.set(e.key,e.values[0])}),n.header&&n.header.forEach(e=>{a.set(e.key,e.values[0])}),a.has("Content-Type")||a.set("Content-Type",o);const c=e.slice(u[t].start,u[t].end);let d=0;for(;;)try{const e=await fetch(r,{method:"PUT",headers:a,body:c});if(!e.ok)throw new Error(`HTTP ${e.status}`);R+=1,b+=u[t].end-u[t].start;const n=Math.min(100,Math.floor(b/w*100));return void(null==i||i(n))}catch(e){if(d++,d>=T)throw new Error(`Failed to upload chunk ${t+1} after ${T} attempts: ${e.message}`);const n=400*Math.pow(2,d-1),s=Math.floor(150*Math.random());await G(n+s)}};let N=0;const U=[],O=async function(){for(;Nfetch(`${e}/object/complete_multipart_upload`,{method:"POST",headers:g({},n),body:JSON.stringify(t)}).then(p))(n.apiAddr,{uploadID:D.uploadID,parts:h,cause:"",name:r,contentType:o},a);return null==i||i(100),{url:k}}catch(e){return{error:e}}},this.uploadFile=async function(e,t){return se(n.loginStatus,h.UploadFile,t,async function(){const{url:s="",error:i}=await n.internalUploadFile(e.file,t);if(i)throw new ne(I.SdkInternalError,i.message);return{url:s}})},this.reset=()=>{var e;null==(e=this.wsManager)||e.close(),this.wsManager=void 0,this.userID=void 0,this.token=void 0,this.apiAddr=void 0,this.isReconnected=!1,this.loginStatus=j.Logout,this.connectState="disconnected",this.messageTrigger.reset(),this.userTrigger.reset(),this.groupTrigger.reset(),this.relationTrigger.reset(),this.signalingTrigger.reset()},this.getSelfUserInfo=void 0,this.setSelfInfo=void 0,this.getUsersInfo=void 0,this.subscribeUsersStatus=void 0,this.unsubscribeUsersStatus=void 0,this.getSubscribeUsersStatus=void 0,this.acceptFriendApplication=void 0,this.addBlack=void 0,this.addFriend=void 0,this.updateFriends=void 0,this.checkFriend=void 0,this.deleteFriend=void 0,this.getBlackList=void 0,this.getFriendApplicationListAsApplicant=void 0,this.getFriendApplicationListAsRecipient=void 0,this.getFriendListPage=void 0,this.getSpecifiedFriendsInfo=void 0,this.refuseFriendApplication=void 0,this.removeBlack=void 0,this.createGroup=void 0,this.joinGroup=void 0,this.inviteUserToGroup=void 0,this.getJoinedGroupListPage=void 0,this.getSpecifiedGroupsInfo=void 0,this.setGroupInfo=void 0,this.getGroupApplicationListAsRecipient=void 0,this.getGroupApplicationListAsApplicant=void 0,this.acceptGroupApplication=void 0,this.refuseGroupApplication=void 0,this.getGroupMemberList=void 0,this.getSpecifiedGroupMembersInfo=void 0,this.setGroupMemberInfo=void 0,this.kickGroupMember=void 0,this.changeGroupMemberMute=void 0,this.changeGroupMute=void 0,this.transferGroupOwner=void 0,this.dismissGroup=void 0,this.quitGroup=void 0,this.getUsersInGroup=void 0,this.isJoinGroup=void 0,this.createTextMessage=void 0,this.createTextAtMessage=void 0,this.createLocationMessage=void 0,this.createCustomMessage=void 0,this.createQuoteMessage=void 0,this.createCardMessage=void 0,this.createImageMessageByURL=void 0,this.createImageMessageByFile=void 0,this.createSoundMessageByURL=void 0,this.createSoundMessageByFile=void 0,this.createVideoMessageByURL=void 0,this.createVideoMessageByFile=void 0,this.createFileMessageByURL=void 0,this.createFileMessageByFile=void 0,this.createMergerMessage=void 0,this.createFaceMessage=void 0,this.createForwardMessage=void 0,this.sendMessage=void 0,this.sendMessageNotOss=void 0,this.revokeMessage=void 0,this.getAdvancedHistoryMessageList=void 0,this.deleteMessage=void 0,this.deleteAllMsgFromLocalAndSvr=void 0,this.sendGroupMessageReadReceipt=void 0,this.getGroupMessageReaderList=void 0,this.cancelMessageTasks=void 0,this.getConversationListSplit=void 0,this.getOneConversation=void 0,this.setConversation=void 0,this.getTotalUnreadMsgCount=void 0,this.markConversationMessageAsRead=void 0,this.changeInputStates=void 0,this.getInputStates=void 0,this.signalingInvite=void 0,this.signalingInviteInGroup=void 0,this.signalingAccept=void 0,this.signalingReject=void 0,this.signalingCancel=void 0,this.signalingHungUp=void 0,this.signalingGetRoomByGroupID=void 0,this.signalingGetTokenByRoomID=void 0,this.getSignalingInvitationInfoStartApp=void 0,this.signalingSendCustomSignal=void 0,this.userTrigger=new et(this),this.groupTrigger=new $e(this),this.relationTrigger=new ze(this),this.businessTrigger=new Ye(this),this.messageTrigger=new je(this),this.signalingTrigger=new tt(this),Object.assign(this,(r=this,{addFriend:async(e,t)=>se(r.loginStatus,h.AddFriend,t,async()=>{const n={fromUserID:r.userID,toUserID:e.toUserID,reqMsg:e.reqMsg,ex:e.ex||""};await r.sendHttpRequest({reqFuncName:h.AddFriend,data:n,operationID:t}),r.relationTrigger.setTriggeredEventMap(v.OnFriendApplicationAdded,t),r.relationTrigger.getDesignatedFriendApplicationAndTrigger(v.OnFriendApplicationAdded,{fromUserID:r.userID,toUserID:e.toUserID},t,!0)}),checkFriend:async(e,t)=>se(r.loginStatus,h.CheckFriend,t,async()=>{const n=e.map(e=>r.sendHttpRequest({reqFuncName:h.CheckFriend,data:{userID1:r.userID,userID2:e},operationID:t}));return(await Promise.all(n)).map((t,n)=>({result:Number(t.inUser1Friends),userID:e[n]}))}),deleteFriend:async(e,t)=>se(r.loginStatus,h.DeleteFriend,t,async()=>{const n={ownerUserID:r.userID,friendUserID:e};await r.sendHttpRequest({reqFuncName:h.DeleteFriend,data:n,operationID:t}),r.relationTrigger.setTriggeredEventMap(v.OnFriendDeleted,t),r.relationTrigger.syncer.syncFriendVersion(t)}),acceptFriendApplication:async(e,t)=>se(r.loginStatus,h.AcceptFriendApplication,t,async()=>{const n={fromUserID:e.toUserID,toUserID:r.userID,handleResult:x.Agree,handleMsg:e.handleMsg};await r.sendHttpRequest({reqFuncName:h.AcceptFriendApplication,data:n,operationID:t}),r.relationTrigger.setTriggeredEventMap(v.OnFriendApplicationAccepted,t),r.relationTrigger.setTriggeredEventMap(v.OnFriendAdded,t),r.relationTrigger.getDesignatedFriendApplicationAndTrigger(v.OnFriendApplicationAccepted,{fromUserID:r.userID,toUserID:e.toUserID},t,!0),r.relationTrigger.syncer.syncFriendVersion(t)}),refuseFriendApplication:async(e,t)=>se(r.loginStatus,h.RefuseFriendApplication,t,async()=>{const n={fromUserID:e.toUserID,toUserID:r.userID,handleResult:x.Reject,handleMsg:e.handleMsg};await r.sendHttpRequest({reqFuncName:h.RefuseFriendApplication,data:n,operationID:t}),r.relationTrigger.setTriggeredEventMap(v.OnFriendApplicationRejected,t),r.relationTrigger.getDesignatedFriendApplicationAndTrigger(v.OnFriendApplicationRejected,{fromUserID:r.userID,toUserID:e.toUserID},t,!0)}),getFriendListPage:async(e,t)=>se(r.loginStatus,h.GetFriendListPage,t,async()=>{const n={userID:r.userID,pagination:{pageNumber:Math.round(e.offset/e.count)+1,showNumber:e.count}},{friendsInfo:s}=await r.sendHttpRequest({reqFuncName:h.GetFriendListPage,data:n,operationID:t});return(null!=s?s:[]).map(Ue)}),getSpecifiedFriendsInfo:async(e,t)=>se(r.loginStatus,h.GetSpecifiedFriendsInfo,t,async()=>{const n={ownerUserID:r.userID,friendUserIDs:e},{friendsInfo:s}=await r.sendHttpRequest({reqFuncName:h.GetSpecifiedFriendsInfo,data:n,operationID:t});return(null!=s?s:[]).map(Ue)}),getFriendApplicationListAsApplicant:async(e,t)=>se(r.loginStatus,h.GetFriendApplicationListAsApplicant,t,async()=>{const{offset:n,count:s}=e,i={userID:r.userID,pagination:{pageNumber:Math.round(n/s)+1,showNumber:s}},{friendRequests:o}=await r.sendHttpRequest({reqFuncName:h.GetFriendApplicationListAsApplicant,data:i,operationID:t});return null!=o?o:[]}),getFriendApplicationListAsRecipient:async(e,t)=>se(r.loginStatus,h.GetFriendApplicationListAsRecipient,t,async()=>{const{offset:n,count:s}=e,i={userID:r.userID,pagination:{pageNumber:Math.round(n/s)+1,showNumber:s}},{FriendRequests:o}=await r.sendHttpRequest({reqFuncName:h.GetFriendApplicationListAsRecipient,data:i,operationID:t});return null!=o?o:[]}),updateFriends:async(e,t)=>se(r.loginStatus,h.UpdateFriends,t,async()=>{await r.sendHttpRequest({reqFuncName:h.UpdateFriends,data:{ownerUserID:r.userID,friendUserIDs:e.friendUserIDs,remark:e.remark,isPinned:e.isPinned,ex:e.ex},operationID:t}),r.relationTrigger.setTriggeredEventMap(v.OnFriendInfoChanged,t),r.relationTrigger.syncer.syncFriendVersion(t)}),addBlack:async(e,t)=>se(r.loginStatus,h.AddBlack,t,async()=>{const n={ownerUserID:r.userID,blackUserID:e.toUserID,ex:e.ex};await r.sendHttpRequest({reqFuncName:h.AddBlack,data:n,operationID:t}),r.relationTrigger.setTriggeredEventMap(v.OnBlackAdded,t),r.relationTrigger.getDesignatedBlackUserAndTrigger(v.OnBlackAdded,e.toUserID,t,!0)}),removeBlack:async(e,t)=>se(r.loginStatus,h.RemoveBlack,t,async()=>{const n={ownerUserID:r.userID,blackUserID:e};await r.sendHttpRequest({reqFuncName:h.RemoveBlack,data:n,operationID:t}),r.relationTrigger.setTriggeredEventMap(v.OnBlackDeleted,t),r.relationTrigger.getDesignatedBlackUserAndTrigger(v.OnBlackDeleted,e,t,!0)}),getBlackList:async(e,t)=>se(r.loginStatus,h.GetBlackList,t,async()=>{const{offset:n,count:s}=e,i={userID:r.userID,pagination:{pageNumber:Math.round(n/s)+1,showNumber:s}},{blacks:o}=await r.sendHttpRequest({reqFuncName:h.GetBlackList,data:i,operationID:t});return(null!=o?o:[]).map(Oe)})})),Object.assign(this,function(e){return{createGroup:async(t,n)=>se(e.loginStatus,h.CreateGroup,n,async()=>{var s;const i={ownerUserID:e.userID,memberUserIDs:t.memberUserIDs,adminUserIDs:null!=(s=t.adminUserIDs)?s:[],groupInfo:g({},t.groupInfo,{groupType:2,creatorUserID:e.userID})},{groupInfo:r}=await e.sendHttpRequest({reqFuncName:h.CreateGroup,data:i,operationID:n});return r}),joinGroup:async(t,n)=>se(e.loginStatus,h.JoinGroup,n,async()=>{var s;const i={groupID:t.groupID,reqMessage:t.reqMsg,joinSource:t.joinSource,inviterUserID:e.userID,ex:null!=(s=t.ex)?s:""};return await e.sendHttpRequest({reqFuncName:h.JoinGroup,data:i,operationID:n}),e.groupTrigger.setTriggeredEventMap(v.OnGroupApplicationAdded,n),e.groupTrigger.getDesignatedGroupApplicationAndTrigger({event:v.OnGroupApplicationAdded,groupID:t.groupID,operationID:n,activeTrigger:!0}),null}),inviteUserToGroup:async(t,n)=>se(e.loginStatus,h.InviteUserToGroup,n,async()=>{const s={groupID:t.groupID,reason:t.reason,invitedUserIDs:t.userIDList};return await e.sendHttpRequest({reqFuncName:h.InviteUserToGroup,data:s,operationID:n}),null}),getJoinedGroupListPage:async(t,n)=>se(e.loginStatus,h.GetJoinedGroupListPage,n,async()=>{const s={fromUserID:e.userID,pagination:{pageNumber:Math.round(t.offset/t.count)+1,showNumber:t.count}},{groups:i}=await e.sendHttpRequest({reqFuncName:h.GetJoinedGroupListPage,data:s,operationID:n});return i&&e.groupTrigger.cache.updateCachedGroups(i),null!=i?i:[]}),getSpecifiedGroupsInfo:async(t,n)=>se(e.loginStatus,h.GetSpecifiedGroupsInfo,n,()=>e.groupTrigger.cache.getGroupInfosWithCache(t,n)),setGroupInfo:async(t,n)=>se(e.loginStatus,h.SetGroupInfo,n,async()=>(await e.sendHttpRequest({reqFuncName:h.SetGroupInfo,data:t,operationID:n}),null)),acceptGroupApplication:async(t,n)=>se(e.loginStatus,h.AcceptGroupApplication,n,async()=>{const s={groupID:t.groupID,fromUserID:t.fromUserID,handledMsg:t.handleMsg,handleResult:x.Agree};return await e.sendHttpRequest({reqFuncName:h.AcceptGroupApplication,data:s,operationID:n}),e.groupTrigger.setTriggeredEventMap(v.OnGroupApplicationAccepted,n),e.groupTrigger.getDesignatedGroupApplicationAndTrigger({event:v.OnGroupApplicationAccepted,groupID:t.groupID,operationID:n,activeTrigger:!0}),null}),refuseGroupApplication:async(t,n)=>se(e.loginStatus,h.RefuseGroupApplication,n,async()=>{const s={groupID:t.groupID,fromUserID:t.fromUserID,handledMsg:t.handleMsg,handleResult:x.Reject};return await e.sendHttpRequest({reqFuncName:h.RefuseGroupApplication,data:s,operationID:n}),e.groupTrigger.setTriggeredEventMap(v.OnGroupApplicationRejected,n),e.groupTrigger.getDesignatedGroupApplicationAndTrigger({event:v.OnGroupApplicationRejected,groupID:t.groupID,operationID:n,activeTrigger:!0}),null}),getGroupMemberList:async(t,n)=>se(e.loginStatus,h.GetGroupMemberList,n,async()=>{const s={filter:0,keyword:"",groupID:t.groupID,pagination:{pageNumber:Math.round(t.offset/t.count)+1,showNumber:t.count}},{members:i}=await e.sendHttpRequest({reqFuncName:h.GetGroupMemberList,data:s,operationID:n});return i&&e.groupTrigger.cache.updateCachedGroupMembers(i),null!=i?i:[]}),getSpecifiedGroupMembersInfo:async(t,n)=>se(e.loginStatus,h.GetSpecifiedGroupMembersInfo,n,()=>e.groupTrigger.cache.getGroupMembersWithCache(g({},t,{operationID:n}))),setGroupMemberInfo:async(t,n)=>se(e.loginStatus,h.SetGroupMemberInfo,n,async()=>(await e.sendHttpRequest({reqFuncName:h.SetGroupMemberInfo,data:{members:[g({},t)]},operationID:n}),null)),kickGroupMember:async(t,n)=>se(e.loginStatus,h.KickGroupMember,n,async()=>{const s={reason:t.reason,groupID:t.groupID,kickedUserIDs:t.userIDList};return await e.sendHttpRequest({reqFuncName:h.KickGroupMember,data:s,operationID:n}),null}),changeGroupMemberMute:async(t,n)=>se(e.loginStatus,h.ChangeGroupMemberMute,n,async()=>{const s={groupID:t.groupID,userID:t.userID,mutedSeconds:t.mutedSeconds};return await e.sendHttpRequest({replaceURL:t.mutedSeconds?"/group/mute_group_member":"/group/cancel_mute_group_member",reqFuncName:h.ChangeGroupMemberMute,data:s,operationID:n}),null}),changeGroupMute:async(t,n)=>se(e.loginStatus,h.ChangeGroupMute,n,async()=>{const s={groupID:t.groupID};return await e.sendHttpRequest({replaceURL:t.isMute?"/group/mute_group":"/group/cancel_mute_group",reqFuncName:h.ChangeGroupMute,data:s,operationID:n}),null}),transferGroupOwner:async(t,n)=>se(e.loginStatus,h.TransferGroupOwner,n,async()=>{const s={groupID:t.groupID,oldOwnerUserID:e.userID,newOwnerUserID:t.newOwnerUserID};return await e.sendHttpRequest({reqFuncName:h.TransferGroupOwner,data:s,operationID:n}),null}),dismissGroup:async(t,n)=>se(e.loginStatus,h.DismissGroup,n,async()=>{const s={groupID:t,deleteMember:!1};return await e.sendHttpRequest({reqFuncName:h.DismissGroup,data:s,operationID:n}),null}),quitGroup:async(t,n)=>se(e.loginStatus,h.QuitGroup,n,async()=>{const s={groupID:t,userID:e.userID};return await e.sendHttpRequest({reqFuncName:h.QuitGroup,data:s,operationID:n}),null}),getGroupApplicationListAsRecipient:async(t,n)=>se(e.loginStatus,h.GetGroupApplicationListAsRecipient,n,async()=>{const{offset:s,count:i}=t,r={fromUserID:e.userID,pagination:{pageNumber:Math.round(s/i)+1,showNumber:i}},{groupRequests:o}=await e.sendHttpRequest({reqFuncName:h.GetGroupApplicationListAsRecipient,data:r,operationID:n});return(null!=o?o:[]).map(we)}),getGroupApplicationListAsApplicant:async(t,n)=>se(e.loginStatus,h.GetGroupApplicationListAsApplicant,n,async()=>{const{offset:s,count:i}=t,r={userID:e.userID,pagination:{pageNumber:Math.round(s/i)+1,showNumber:i}},{groupRequests:o}=await e.sendHttpRequest({reqFuncName:h.GetGroupApplicationListAsApplicant,data:r,operationID:n});return(null!=o?o:[]).map(we)}),getUsersInGroup:async(t,n)=>se(e.loginStatus,h.GetUsersInGroup,n,async()=>{var s;e.groupTrigger.cache.hasCachedGroupMembersID(t.groupID)||await e.groupTrigger.cache.getGroupMembersID(t.groupID,n);const i=e.groupTrigger.cache.getCachedGroupMembersID(t.groupID);return null==(s=t.userIDList)?void 0:s.filter(e=>i.includes(e))}),isJoinGroup:async(t,n)=>se(e.loginStatus,h.IsJoinGroup,n,async()=>e.groupTrigger.syncer.checkIsJoinGroup(t))}}(this)),Object.assign(this,function(e){return{getSelfUserInfo:async t=>se(e.loginStatus,h.GetSelfUserInfo,t,async()=>{const n=e.userTrigger.cache.getSelfUserInfo();if(n)return n;const s={userIDs:[e.userID]},{usersInfo:i}=await e.sendHttpRequest({reqFuncName:h.GetSelfUserInfo,data:s,operationID:t});return(null!=i?i:[])[0]}),setSelfInfo:async(t,n)=>se(e.loginStatus,h.SetSelfInfo,n,async()=>{const s={userInfo:g({userID:e.userID},t)};return await e.sendHttpRequest({reqFuncName:h.SetSelfInfo,data:s,operationID:n}),e.userTrigger.setTriggeredEventMap(n),e.userTrigger.cache.udpateCachedLoginUserInfoAndTrigger(g({},t),n),null}),getUsersInfo:async(t,n)=>se(e.loginStatus,h.GetUsersInfo,n,async()=>{const s={userIDs:t},{usersInfo:i}=await e.sendHttpRequest({reqFuncName:h.GetUsersInfo,data:s,operationID:n}),r=null!=i?i:[];return r.filter(t=>!e.relationTrigger.cache.isFriend(t.userID)).map(e.userTrigger.checkConversationUpdate),r}),subscribeUsersStatus:async(t,n)=>se(e.loginStatus,h.SubscribeUsersStatus,n,()=>{if(!t.length)throw new ne(I.ArgsError,"sub users is empty");return e.userTrigger.onlineSub.getUserOnlineState(t,n)}),unsubscribeUsersStatus:async(t,n)=>se(e.loginStatus,h.UnsubscribeUsersStatus,n,async()=>{if(!t.length)throw new ne(I.ArgsError,"unSub users is empty");return await e.userTrigger.onlineSub.updateSubs({sub:[],unSub:t,operationID:n}),null}),getSubscribeUsersStatus:async t=>se(e.loginStatus,h.GetSubscribeUsersStatus,t,async()=>e.userTrigger.onlineSub.getAllSubUsersOnlineState())}}(this)),Object.assign(this,function(t){const n=new Map,s=new nt,r=new nt;let o=null,a="";const c=async({maxSeq:e,count:n,conversationID:s,operationID:i,fetchedMessages:r=[]})=>{const o=[];for(let i=e;o.length{const o=[];for(let i=e;o.lengthr?t:r,count:n-a.length,conversationID:s,operationID:i,fetchedMessages:g})}return g};return{createTextMessage:(e,n)=>se(t.loginStatus,h.CreateTextMessage,n,async()=>{const n=te(t,S.UserMsgType,P.TextMessage);return n.textElem={content:e},n}),createTextAtMessage:(e,n)=>se(t.loginStatus,h.CreateTextAtMessage,n,async()=>{var n;if(!e.text)throw new ne(I.ArgsError,"text cannot be empty");if(e.atUserIDList.length>10)throw new ne(I.ArgsError,"atUserIDList length must be less than 10");const s=te(t,S.UserMsgType,P.AtTextMessage);var i;return(null==(n=e.message)?void 0:n.contentType)===P.QuoteMessage&&(e.message.contentType=P.TextMessage,e.message.textElem={content:null==(i=e.message.quoteElem)?void 0:i.text}),s.atTextElem={text:e.text,atUserList:e.atUserIDList,atUsersInfo:e.atUsersInfo,quoteMessage:e.message},s}),createLocationMessage:(e,n)=>se(t.loginStatus,h.CreateLocationMessage,n,async()=>{const n=te(t,S.UserMsgType,P.LocationMessage);return n.locationElem=g({},e),n}),createCustomMessage:(e,n)=>se(t.loginStatus,h.CreateCustomMessage,n,async()=>{const n=te(t,S.UserMsgType,P.CustomMessage);return n.customElem=g({},e),n}),createQuoteMessage:(e,n)=>se(t.loginStatus,h.CreateQuoteMessage,n,async()=>{const n=te(t,S.UserMsgType,P.QuoteMessage),s=JSON.parse(e.message);var i;return s.contentType===P.QuoteMessage&&(s.contentType=P.TextMessage,s.textElem={content:null==(i=s.quoteElem)?void 0:i.text}),n.quoteElem={text:e.text,quoteMessage:s},n}),createCardMessage:(e,n)=>se(t.loginStatus,h.CreateCardMessage,n,async()=>{const n=te(t,S.UserMsgType,P.CardMessage);return n.cardElem=g({},e),n}),createImageMessageByURL:(e,n)=>se(t.loginStatus,h.CreateImageMessageByURL,n,async()=>{const n=te(t,S.UserMsgType,P.PictureMessage);return n.pictureElem=g({},e),n}),createImageMessageByFile:async(e,s)=>se(t.loginStatus,h.CreateImageMessageByFile,s,async()=>{const s=te(t,S.UserMsgType,P.PictureMessage);return n.set(e.sourcePicture.uuid,e.file),delete e.file,s.pictureElem=g({},e),s}),createSoundMessageByURL:(e,n)=>se(t.loginStatus,h.CreateSoundMessageByURL,n,async()=>{const n=te(t,S.UserMsgType,P.VoiceMessage);return n.soundElem=g({},e),n}),createSoundMessageByFile:async(e,s)=>se(t.loginStatus,h.CreateSoundMessageByFile,s,async()=>{const s=te(t,S.UserMsgType,P.VoiceMessage);return n.set(e.uuid,e.file),delete e.file,s.soundElem=g({},e),s}),createVideoMessageByURL:(e,n)=>se(t.loginStatus,h.CreateVideoMessageByURL,n,async()=>{const n=te(t,S.UserMsgType,P.VideoMessage);return n.videoElem=g({},e),n}),createVideoMessageByFile:async(e,s)=>se(t.loginStatus,h.CreateVideoMessageByFile,s,async()=>{const s=te(t,S.UserMsgType,P.VideoMessage);return n.set(e.videoUUID,e.videoFile),n.set(e.snapshotUUID,e.snapshotFile),delete e.videoFile,delete e.snapshotFile,s.videoElem=g({},e),s}),createFileMessageByURL:(e,n)=>se(t.loginStatus,h.CreateFileMessageByURL,n,async()=>{const n=te(t,S.UserMsgType,P.FileMessage);return n.fileElem=g({},e),n}),createFileMessageByFile:async(e,s)=>se(t.loginStatus,h.CreateFileMessageByFile,s,async()=>{const s=te(t,S.UserMsgType,P.FileMessage);return n.set(e.uuid,e.file),delete e.file,s.fileElem=g({},e),s}),createMergerMessage:(e,n)=>se(t.loginStatus,h.CreateMergerMessage,n,async()=>{const n=te(t,S.UserMsgType,P.MergeMessage);return n.mergeElem={title:e.title,abstractList:e.summaryList,multiMessage:e.messageList,messageEntityList:[]},n}),createFaceMessage:(e,n)=>se(t.loginStatus,h.CreateFaceMessage,n,async()=>{const n=te(t,S.UserMsgType,P.FaceMessage);return n.faceElem=g({},e),n}),createForwardMessage:(e,n)=>se(t.loginStatus,h.CreateForwardMessage,n,async()=>{if(e.status!==F.Succeed)throw new ne(I.ArgsError,"Only successfully sent messages can be forwarded");const n=te(t,S.UserMsgType,e.contentType);return g({},e,n,{seq:0,status:F.Sending})}),sendMessage:async(e,o)=>se(t.loginStatus,h.SendMessage,o,()=>{const a=async()=>{var s,r;const{message:a,recvID:c,groupID:d,isOnlineOnly:u,offlinePushInfo:p={title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}}=g({},e,{message:g({},e.message)});void 0===p.signalInfo&&(p.signalInfo="");const l=st[a.contentType];if(!l)throw new ne(I.MsgContentTypeNotSupportError,"Unknown message content type");a.recvID=c,a.groupID=d,a.sessionType=d?B.Group:B.Single;const h={};u&&Object.values(T).forEach(e=>h[e]=!1);const f=z(a);let m=!1,M=await t.messageTrigger.getOneConversationAndTryChange(f,o);if(M?M.isPrivateChat&&(h[T.IsNotPrivate]=!1,a.attachedInfoElem=g({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:M.burnDuration})):(m=!0,M=await t.messageTrigger.initConversation({sourceID:d||c,sessionType:a.sessionType,operationID:o})),d){const e=await t.groupTrigger.cache.getGroupInfosWithCache([d],o),n=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:d,userIDList:[t.userID],operationID:o});if(null==n||!n.length)throw new ne(I.ArgsError,"user not join target group");n[0].nickname&&(a.senderNickname=n[0].nickname),a.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},a.attachedInfoElem.groupHasReadInfo.unreadCount=e[0].memberCount-1}if(M.latestMsgSendTime=a.createTime,t.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(a)},void 0,m),a.contentType===P.PictureMessage){var y,S;const e=n.get(null==(y=a.pictureElem)?void 0:y.sourcePicture.uuid);if(!e)throw new ne(I.ArgsError,"Can not find target file");const{url:s="",error:i}=await t.internalUploadFile(e,o,e=>t.triggerEvent({event:v.OnProgress,data:{progress:e,clientMsgID:a.clientMsgID},operationID:o}));if(n.delete(null==(S=a.pictureElem)?void 0:S.sourcePicture.uuid),i)throw new ne(I.NetworkError,"Upload file failed");a.pictureElem.sourcePicture.url=s,a.pictureElem.bigPicture.url=s,a.pictureElem.snapshotPicture.width=640,a.pictureElem.snapshotPicture.height=640,a.pictureElem.snapshotPicture.url=`${s}?type=image&width=640&height=640`}if(a.contentType===P.VoiceMessage){var C,G;const e=n.get(null==(C=a.soundElem)?void 0:C.uuid);if(!e)throw new ne(I.ArgsError,"Can not find target file");const{url:s="",error:i}=await t.internalUploadFile(e,o,e=>t.triggerEvent({event:v.OnProgress,data:{progress:e,clientMsgID:a.clientMsgID},operationID:o}));if(n.delete(null==(G=a.soundElem)?void 0:G.uuid),i)throw new ne(I.NetworkError,"Upload file failed");a.soundElem.sourceUrl=s}if(a.contentType===P.VideoMessage){var w,b,R,A;const e=n.get(null==(w=a.videoElem)?void 0:w.videoUUID),s=n.get(null==(b=a.videoElem)?void 0:b.snapshotUUID);if(!e||!s)throw new ne(I.ArgsError,"Can not find target file");let i=0,r=0;const c=e.size,d=s.size,g=c+d,u=()=>{t.triggerEvent({event:v.OnProgress,data:{progress:(i*c+r*d)/g,clientMsgID:a.clientMsgID},operationID:o})},p=await Promise.all([t.internalUploadFile(e,o,e=>{i=e,u()}),t.internalUploadFile(s,o,e=>{r=e,u()})]);if(n.delete(null==(R=a.videoElem)?void 0:R.videoUUID),n.delete(null==(A=a.videoElem)?void 0:A.snapshotUUID),p[0].error||p[1].error)throw new ne(I.NetworkError,"Upload file failed");a.videoElem.videoUrl=p[0].url,a.videoElem.snapshotUrl=p[1].url}if(a.contentType===P.FileMessage){var N,U;const e=n.get(null==(N=a.fileElem)?void 0:N.uuid);if(!e)throw new ne(I.ArgsError,"Can not find target file");const{url:s="",error:i}=await t.internalUploadFile(e,o,e=>t.triggerEvent({event:v.OnProgress,data:{progress:e,clientMsgID:a.clientMsgID},operationID:o}));if(n.delete(null==(U=a.fileElem)?void 0:U.uuid),i)throw new ne(I.NetworkError,"Upload file failed");a.fileElem.sourceUrl=s}const O=JSON.stringify(a[l]),E={sendID:t.userID,recvID:c||"",groupID:d||"",clientMsgID:a.clientMsgID,serverMsgID:a.serverMsgID||"",senderPlatformID:t.platform,senderNickname:a.senderNickname,senderFaceURL:a.senderFaceUrl,sessionType:a.sessionType,msgFrom:a.msgFrom,contentType:a.contentType,content:Me(O),seq:a.seq,sendTime:0,createTime:a.createTime,status:a.status,isRead:!1,options:h,offlinePushInfo:p,atUserIDList:null!=(s=null==(r=a.atTextElem)?void 0:r.atUserList)?s:[],attachedInfo:a.attachedInfoElem?JSON.stringify(a.attachedInfoElem):"",ex:a.ex||"",dstUserIDs:[],keyVersion:0};await t.messageTrigger.encryptor.encryption(f,E,o);const k=i.MsgData.encode(E).finish();try{const{serverMsgID:e,sendTime:n}=await t.sendReqWaitResp({data:k,operationID:o,reqIdentifier:D.SendMsg});return a.sendTime=n,a.serverMsgID=e,a.status=F.Succeed,t.messageTrigger.setTriggeredConversationEvent(o),t.messageTrigger.cache.updateCachedMaxReadSeq(M.conversationID,{maxSeqTime:n}),t.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(a),latestMsgSendTime:n}),a}catch(e){throw a.status=F.Failed,t.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(a)}),e}};return it.includes(e.message.contentType)?r.enqueue(a):s.enqueue(a)}),sendMessageNotOss:async(e,n)=>se(t.loginStatus,h.SendMessage,n,()=>s.enqueue(async()=>{var s,r;const{message:o,recvID:a,groupID:c,isOnlineOnly:d,offlinePushInfo:u={title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}}=g({},e,{message:g({},e.message)});void 0===u.signalInfo&&(u.signalInfo="");const p=st[o.contentType];if(!p)throw new ne(I.MsgContentTypeNotSupportError,"Unknown message content type");o.recvID=a,o.groupID=c,o.sessionType=c?B.Group:B.Single;const l={};d&&Object.values(T).forEach(e=>l[e]=!1);const h=z(o);let f=await t.messageTrigger.getOneConversationAndTryChange(h,n);if(f)f.isPrivateChat&&(l[T.IsNotPrivate]=!1,o.attachedInfoElem=g({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:f.burnDuration}));else if(f=await t.messageTrigger.initConversation({sourceID:c||a,sessionType:o.sessionType,operationID:n}),c){const e=await t.groupTrigger.cache.getGroupInfosWithCache([c],n),s=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:c,userIDList:[t.userID],operationID:n});if(null==s||!s.length)throw new ne(I.ArgsError,"user not join target group");s[0].nickname&&(o.senderNickname=s[0].nickname),o.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},o.attachedInfoElem.groupHasReadInfo.unreadCount=e[0].memberCount-1}f.latestMsgSendTime=o.createTime,t.messageTrigger.getOneConversationAndTryChange(h,n,{latestMsg:JSON.stringify(o)});const m=JSON.stringify(o[p]),v={sendID:t.userID,recvID:a||"",groupID:c||"",clientMsgID:o.clientMsgID,serverMsgID:o.serverMsgID||"",senderPlatformID:t.platform,senderNickname:o.senderNickname,senderFaceURL:o.senderFaceUrl,sessionType:o.sessionType,msgFrom:o.msgFrom,contentType:o.contentType,content:Me(m),seq:o.seq,sendTime:0,createTime:o.createTime,status:o.status,isRead:!1,options:l,offlinePushInfo:u,atUserIDList:null!=(s=null==(r=o.atTextElem)?void 0:r.atUserList)?s:[],attachedInfo:o.attachedInfoElem?JSON.stringify(o.attachedInfoElem):"",ex:o.ex||"",dstUserIDs:[],keyVersion:0};await t.messageTrigger.encryptor.encryption(h,v,n);const M=i.MsgData.encode(v).finish();try{const{serverMsgID:e,sendTime:s}=await t.sendReqWaitResp({data:M,operationID:n,reqIdentifier:D.SendMsg});return o.sendTime=s,o.serverMsgID=e,o.status=F.Succeed,t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.cache.updateCachedMaxReadSeq(f.conversationID,{maxSeqTime:s}),t.messageTrigger.getOneConversationAndTryChange(h,n,{latestMsg:JSON.stringify(o),latestMsgSendTime:s}),o}catch(e){throw o.status=F.Failed,t.messageTrigger.getOneConversationAndTryChange(h,n,{latestMsg:JSON.stringify(o)}),e}})),revokeMessage:async(e,n)=>se(t.loginStatus,h.RevokeMessage,n,async()=>{const s=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(e.conversationID,[e.clientMsgID])[0];if(!s)throw new ne(I.ArgsError,"message not exist");if(s.sendID!==t.userID){if(!s.groupID)throw new ne(I.ArgsError,"message can not be revoked");const e=(await t.groupTrigger.cache.getGroupMembersWithCache({groupID:s.groupID,userIDList:[t.userID],operationID:n}))[0];if(!e||e.roleLevel===E.Nomal)throw new ne(I.ArgsError,"message can not be revoked")}const i={conversationID:e.conversationID,seq:s.seq,userID:t.userID};await t.sendHttpRequest({reqFuncName:h.RevokeMessage,data:i,operationID:n}),t.messageTrigger.setTriggeredConversationEvent(n),t.messageTrigger.revokeMessage({revokerUserID:t.userID,clientMsgID:s.clientMsgID,revokeTime:Date.now(),sesstionType:s.sessionType,seq:s.seq,conversationID:e.conversationID,isAdminRevoke:!1},n)}),getAdvancedHistoryMessageList:async(n,s)=>se(t.loginStatus,h.GetAdvancedHistoryMessageList,s,async()=>{var i,r,d,u;const p={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(a!==n.conversationID&&(o=null,a=n.conversationID),n.startClientMsgID){if(null===o){const e=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!e)return g({},p,{isEnd:!0});o=e.seq}}else o=0;const l=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);if(e.log("syncedSeqs",l),!l)return g({},p,{isEnd:!0});const h=o?o-1:l.maxSeq,f=await c({maxSeq:h,count:n.count,conversationID:n.conversationID,operationID:s});if((null==(i=f[0])?void 0:i.sessionType)===B.Single){const e=await t.messageTrigger.getOneConversationAndTryChange(n.conversationID,s),i=t.userTrigger.cache.getSelfUserInfo();f.forEach(n=>{const s=n.sendID===t.userID;n.senderNickname=s?null==i?void 0:i.nickname:null==e?void 0:e.showName,n.senderFaceUrl=s?null==i?void 0:i.faceURL:null==e?void 0:e.faceURL})}if((null==(r=f[0])?void 0:r.sessionType)===B.Group){const e=new Set(f.map(e=>e.sendID)),n=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:f[0].groupID,userIDList:Array.from(e),operationID:s});f.forEach(e=>{const t=n.find(t=>t.userID===e.sendID);t&&(e.senderNickname=null==t?void 0:t.nickname,e.senderFaceUrl=null==t?void 0:t.faceURL)})}return p.messageList=f.map(Re),t.messageTrigger.cache.getGroupMessageHasReadInfo({conversationID:n.conversationID,messages:[...p.messageList],operationID:s}),e.debug("getAdvancedHistoryMessageList with opid: ",s,"messageList: ",p.messageList),o=null!=(d=null==(u=f[0])?void 0:u.seq)?d:0,g({},p,{isEnd:f.lengthse(t.loginStatus,h.GetAdvancedHistoryMessageListReverse,s,async()=>{var i,r;const o={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(!n.startClientMsgID)return g({},o,{isEnd:!0});const a=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!a)return g({},o,{isEnd:!0});const c=a.seq,u=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);if(e.log("syncedSeqs",u),!u||u.maxSeq===c)return g({},o,{isEnd:!0});const p=await d({minSeq:c,count:n.count,conversationID:n.conversationID,operationID:s});if((null==(i=p[0])?void 0:i.sessionType)===B.Single){const e=await t.messageTrigger.getOneConversationAndTryChange(n.conversationID,s),i=t.userTrigger.cache.getSelfUserInfo();p.forEach(n=>{const s=n.sendID===t.userID;n.senderNickname=s?null==i?void 0:i.nickname:null==e?void 0:e.showName,n.senderFaceUrl=s?null==i?void 0:i.faceURL:null==e?void 0:e.faceURL})}if((null==(r=p[0])?void 0:r.sessionType)===B.Group){const e=new Set(p.map(e=>e.sendID)),n=await t.groupTrigger.cache.getGroupMembersWithCache({groupID:p[0].groupID,userIDList:Array.from(e),operationID:s});p.forEach(e=>{const t=n.find(t=>t.userID===e.sendID);t&&(e.senderNickname=null==t?void 0:t.nickname,e.senderFaceUrl=null==t?void 0:t.faceURL)})}return o.messageList=p.map(Re),e.debug("getAdvancedHistoryMessageListReverse with opid: ",s,"messageList: ",o.messageList),g({},o,{isEnd:p.lengthse(t.loginStatus,h.DeleteMessage,s,async()=>{var i;const r=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.clientMsgID])[0];if(!r)throw new ne(I.ArgsError,"message not exist");const o={conversationID:n.conversationID,seqs:[r.seq],userID:t.userID,deleteSyncOpt:void 0};await t.sendHttpRequest({reqFuncName:h.DeleteMessage,data:o,operationID:s});const a=null==(i=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID))?void 0:i.maxSeq;if(e.debug("delete message with opid: ",s,"conversationMaxSeq: ",a,"deleteMessage seq: ",r.seq),t.messageTrigger.cache.deleteMessageFromCache(n.conversationID,r.seq),r.seq===a){const e=await t.messageTrigger.getPreviousSeqMessage({conversationID:n.conversationID,seq:r.seq,operationID:s});t.messageTrigger.getOneConversationAndTryChange(n.conversationID,s,{latestMsg:e?JSON.stringify(Re(e)):""})}}),deleteAllMsgFromLocalAndSvr:async e=>se(t.loginStatus,h.DeleteAllMsgFromLocalAndSvr,e,async()=>{const n={userID:t.userID,deleteSyncOpt:void 0};await t.sendHttpRequest({reqFuncName:h.DeleteAllMsgFromLocalAndSvr,data:n,operationID:e}),t.messageTrigger.cache.getAllCachedConversations().forEach(({conversationID:n})=>{t.messageTrigger.getOneConversationAndTryChange(n,e,{latestMsg:""})})}),sendGroupMessageReadReceipt:async(e,n)=>se(t.loginStatus,h.SendGroupMessageReadReceipt,n,async()=>{const s=await t.messageTrigger.getOneConversationAndTryChange(e.conversationID,n);if(!s)throw new ne(I.ArgsError,"conversation not exist");if(s.conversationType!==B.Group)throw new ne(I.ArgsError,"conversation is not group");const i=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(e.conversationID,e.clientMsgIDList);if(!i.length)throw new ne(I.ArgsError,"message not exist");let r=[],o={};for(const e of i)e.contentType>y.NotificationBegin&&e.contentTypese(t.loginStatus,h.GetGroupMessageReaderList,n,async()=>{const s=await t.messageTrigger.getOneConversationAndTryChange(e.conversationID,n);if(!s)throw new ne(I.ArgsError,"conversation not exist");if(s.conversationType!==B.Group)throw new ne(I.ArgsError,"conversation is not group");const i=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(e.conversationID,[e.clientMsgID])[0];if(!i)throw new ne(I.ArgsError,"message not exist");const r=JSON.parse(i.attachedInfo||"{}");if(e.filter===W.Read){if(0===r.groupHasReadInfo.hasReadCount)return[];const i=t.messageTrigger.cache.getGroupMessageReadUser(e.clientMsgID);if(e.offset+e.count>i.length&&r.groupHasReadInfo.hasReadCount>i.length){const r={clientMsgID:e.clientMsgID,conversationID:e.conversationID,type:W.Read,pagination:{pageNumber:e.offset+1,showNumber:e.count}},{reads:o}=await t.sendHttpRequest({reqFuncName:f.GetGroupMessageHasRead,data:r,operationID:n});if(i.length<50&&e.offset<50){const n=50-i.length;t.messageTrigger.cache.addGroupMessageReadUser(e.clientMsgID,o.slice(0,ne.userID),operationID:n})}return t.groupTrigger.cache.getGroupMembersMayNotInGroup({groupID:s.groupID,userIDList:i.slice(e.offset,e.offset+e.count).map(e=>e.userID),operationID:n})}if(e.filter===W.UnRead){if(0===r.groupHasReadInfo.hasReadCount)return(await t.getGroupMemberList({groupID:s.groupID,offset:e.offset,count:e.count},n)).data.filter(e=>e.userID!==t.userID);const i={clientMsgID:e.clientMsgID,conversationID:e.conversationID,type:W.UnRead,pagination:{pageNumber:e.offset+1,showNumber:e.count}},{reads:o}=await t.sendHttpRequest({reqFuncName:f.GetGroupMessageHasRead,data:i,operationID:n});return o?t.groupTrigger.cache.getGroupMembersMayNotInGroup({groupID:s.groupID,userIDList:o.map(e=>e.userID),operationID:n}):[]}return[]}),cancelMessageTasks:()=>{s.cancelTasks(),r.cancelTasks(),n.clear()}}}(this)),Object.assign(this,function(t){return{getConversationListSplit:async(e,n)=>se(t.loginStatus,h.GetConversationListSplit,n,async()=>{const s=t.messageTrigger.cache.getSortedConversationIDs(e.offset,e.count);return(await t.messageTrigger.getConversationsWithCacheByIDs(s,n)).sort((e,t)=>e.isPinned===t.isPinned?e.latestMsgSendTime>t.latestMsgSendTime?-1:e.latestMsgSendTimese(t.loginStatus,h.GetOneConversation,n,async()=>{let s=await t.messageTrigger.getOneConversationAndTryChange(Y(g({},e,{userID:t.userID})),n);return s||(s=await t.messageTrigger.initConversation(g({},e,{operationID:n}))),g({},s)}),getTotalUnreadMsgCount:async e=>se(t.loginStatus,h.GetTotalUnreadMsgCount,e,()=>Promise.resolve(t.messageTrigger.cache.getTotalUnreadCount())),markConversationMessageAsRead:async(n,s)=>se(t.loginStatus,h.MarkConversationMessageAsRead,s,async()=>{const i=t.messageTrigger.cache.getCachedMaxReadSeq(n);if(!i)throw new ne(I.ArgsError,"conversation not exist");if(i.hasReadSeq===i.maxSeq)throw new ne(I.ArgsError,"hasReadSeq equal max");const r=[];for(let e=i.hasReadSeq;e<=i.maxSeq;e++)r.push(e);const{messages:o}=await t.messageTrigger.getMessageWithCacheBySeqs(n,r,s),a=o.filter(e=>e.sendID!==t.userID&&!e.isRead).map(e=>e.seq);a.length||e.warn("seqs is empty ",n);const c={conversationID:n,seqs:a,hasReadSeq:i.maxSeq,userID:t.userID};if(await t.sendHttpRequest({reqFuncName:h.MarkConversationMessageAsRead,data:c,operationID:s}),t.messageTrigger.cache.updateCachedMaxReadSeq(n,{hasReadSeq:i.maxSeq}),t.messageTrigger.cache.markCachedMessagesAsRead(n),e.debug("markConversationMessageAsRead with opid: ",s,"conversationID: ",n,"asReadSeqs: ",a,"syncedMaxSeq",i.maxSeq),a.sort()[a.length-1]===i.maxSeq){const e=o.find(e=>e.seq===i.maxSeq);e.isRead=!0,t.messageTrigger.getOneConversationAndTryChange(n,s,{latestMsg:JSON.stringify(Re(e))})}t.messageTrigger.getOneConversationAndTryChange(n,s).then(e=>{t.messageTrigger.cache.decreaseTotalUnreadCount(e.unreadCount,s),t.messageTrigger.getOneConversationAndTryChange(n,s,{unreadCount:0})})}),deleteConversationAndDeleteAllMsg:async(e,n)=>se(t.loginStatus,h.DeleteConversationAndDeleteAllMsg,n,async()=>{await t.sendHttpRequest({reqFuncName:h.DeleteConversationAndDeleteAllMsg,data:{conversationIDs:[e],userID:t.userID,deleteSyncOpt:void 0},operationID:n}),t.messageTrigger.cache.clearCachedConversationMessages(e)}),setConversation:async(e,n)=>se(t.loginStatus,h.SetConversation,n,async()=>{const s=await t.messageTrigger.getOneConversationAndTryChange(e.conversationID,n);if(!s)throw new ne(I.ArgsError,"conversation not exist");await t.sendHttpRequest({reqFuncName:h.SetConversation,data:{conversation:g({},e,{conversationID:s.conversationID,conversationType:s.conversationType,userID:s.userID,groupID:s.groupID,attachedInfo:void 0,minSeq:void 0}),userIDs:[t.userID]},operationID:n})}),changeInputStates:async(e,n)=>se(t.loginStatus,h.ChangeInputStates,n,async()=>{await t.messageTrigger.typingManager.changeInputStates(g({},e,{operationID:n}))}),getInputStates:async(e,n)=>se(t.loginStatus,h.ChangeInputStates,n,()=>Promise.resolve(t.messageTrigger.typingManager.getInputStates(e.conversationID,e.userID)))}}(this)),Object.assign(this,function(e){const t=e=>{e.roomID||(e.roomID=K()),e.timeout||(e.timeout=60),e.customData||(e.customData=""),e.busyLineUserIDList||(e.busyLineUserIDList=[])},n=async(t,n)=>{const s={userInfo:void 0,groupInfo:void 0,groupMemberInfo:void 0},i=e.userTrigger.cache.getSelfUserInfo();if(s.userInfo={userID:i.userID,nickname:i.nickname,faceURL:i.faceURL,ex:i.ex},t){const r=await e.groupTrigger.cache.getGroupInfosWithCache([t],n);if(r[0]){s.groupInfo=g({},r[0]);const o=await e.groupTrigger.cache.getGroupMembersWithCache({groupID:t,userIDList:[i.userID],operationID:n});o[0]&&(s.groupMemberInfo=g({},o[0]))}}return s};return{signalingInvite:async(s,i)=>se(e.loginStatus,h.SignalingInvite,i,async()=>{var r,o,a;const c=g({},s);if(!c.invitation)throw new ne(I.ArgsError,"invitation is required");t(c.invitation);const d=await n(c.invitation.groupID,i);return c.invitation.inviterUserID=null==(r=d.userInfo)?void 0:r.userID,c.userID=null==(o=d.userInfo)?void 0:o.userID,c.invitation.initiateTime=Math.floor(Date.now()/1e3),c.participant=d,null==(a=(await e.signalingTrigger.sendSignalingReqWaitResp({invite:c},i)).signalResp)?void 0:a.invite}),signalingInviteInGroup:async(s,i)=>se(e.loginStatus,h.SignalingInviteInGroup,i,async()=>{var r,o,a;const c=g({},s);if(!c.invitation)throw new ne(I.ArgsError,"invitation is required");t(c.invitation);const d=await n(c.invitation.groupID,i);return c.invitation.inviterUserID=null==(r=d.userInfo)?void 0:r.userID,c.userID=null==(o=d.userInfo)?void 0:o.userID,c.invitation.initiateTime=Math.floor(Date.now()/1e3),c.participant=d,null==(a=(await e.signalingTrigger.sendSignalingReqWaitResp({inviteInGroup:c},i)).signalResp)?void 0:a.inviteInGroup}),signalingAccept:async(s,i)=>se(e.loginStatus,h.SignalingAccept,i,async()=>{var r;if(!s.invitation)throw new ne(I.ArgsError,"invitation is required");const o={invitation:g({},s.invitation),offlinePushInfo:void 0,participant:void 0,opUserPlatformID:e.platform,userID:e.userID};t(o.invitation);const a=await n(o.invitation.groupID,i);return o.invitation.initiateTime=Math.floor(Date.now()/1e3),o.participant=a,null==(r=(await e.signalingTrigger.sendSignalingReqWaitResp({accept:o},i)).signalResp)?void 0:r.accept}),signalingReject:async(s,i)=>se(e.loginStatus,h.SignalingReject,i,async()=>{var r;if(!s.invitation)throw new ne(I.ArgsError,"invitation is required");const o={invitation:g({},s.invitation),offlinePushInfo:void 0,participant:void 0,opUserPlatformID:e.platform,userID:e.userID};t(o.invitation);const a=await n(o.invitation.groupID,i);return o.invitation.initiateTime=Math.floor(Date.now()/1e3),o.participant=a,null==(r=(await e.signalingTrigger.sendSignalingReqWaitResp({reject:o},i)).signalResp)?void 0:r.reject}),signalingCancel:async(s,i)=>se(e.loginStatus,h.SignalingCancel,i,async()=>{var r;if(!s.invitation)throw new ne(I.ArgsError,"invitation is required");const o={invitation:g({},s.invitation),offlinePushInfo:void 0,participant:void 0,userID:s.opUserID};t(o.invitation);const a=await n(o.invitation.groupID,i);return o.invitation.initiateTime=Math.floor(Date.now()/1e3),o.participant=a,null==(r=(await e.signalingTrigger.sendSignalingReqWaitResp({cancel:o},i)).signalResp)?void 0:r.cancel}),signalingHungUp:async(n,s)=>se(e.loginStatus,h.SignalingHungUp,s,async()=>{var i;if(!n.invitation)throw new ne(I.ArgsError,"invitation is required");const r={invitation:g({},n.invitation),offlinePushInfo:void 0,userID:n.opUserID};return t(r.invitation),r.invitation.initiateTime=Math.floor(Date.now()/1e3),null==(i=(await e.signalingTrigger.sendSignalingReqWaitResp({hungUp:r},s)).signalResp)?void 0:i.hungUp}),signalingGetRoomByGroupID:async(t,n)=>se(e.loginStatus,h.SignalingGetRoomByGroupID,n,()=>e.sendHttpRequest({reqFuncName:f.SignalGetRoomByGroupID,data:{groupID:t},operationID:n})),signalingGetTokenByRoomID:async(t,s)=>se(e.loginStatus,h.SignalingGetTokenByRoomID,s,async()=>{var i;const r={roomID:t,userID:e.userID,participant:await n(t,s)};return null==(i=(await e.signalingTrigger.sendSignalingReqWaitResp({getTokenByRoomID:r},s)).signalResp)?void 0:i.getTokenByRoomID}),getSignalingInvitationInfoStartApp:async t=>se(e.loginStatus,h.GetSignalingInvitationInfoStartApp,t,()=>e.sendHttpRequest({reqFuncName:f.GetSignalInvitationInfoStartApp,data:{userID:e.userID},operationID:t})),signalingSendCustomSignal:async(t,n)=>se(e.loginStatus,h.SignalingSendCustomSignal,n,async()=>(await e.sendHttpRequest({reqFuncName:f.SignalSendCustomSignal,data:g({},t),operationID:n}),null))}}(this))}}const ct=()=>(console.info("%cOpenIMSDK-Enterprise v0.0.21","background: #004085; color: #ffffff; padding: 2px 5px; border-radius: 4px;"),new Proxy(new at,{get(t,n,s){if("on"===n||"off"===n)return Reflect.get(t,n,s);let i=t[n];return"function"==typeof i?async function(...s){s.push(K()),((t,n)=>{e.debug(`%cSDK =>%c [OperationID:${n[n.length-1]}] (invoked) run ${t} with args ${JSON.stringify(n)}`,"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")})(n,s);const r=await i.apply(t,s);var o,a;return o=n,(a=r).errCode?e.debug(`%cSDK =>%c [OperationID:${a.operationID}] (response) run ${o} with error ${JSON.stringify(a)}`,"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):e.debug(`%cSDK =>%c [OperationID:${a.operationID}] (response) run ${o} with response before processor ${JSON.stringify(a.data)}`,"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),r.errCode?Promise.reject(r):r}:Reflect.get(t,n,s)}}));export{N as AllowType,x as ApplicationHandleResult,v as CbEvents,I as ErrorCode,V as GroupAtType,O as GroupJoinSource,_ as GroupMemberFilter,E as GroupMemberRole,W as GroupMessageReaderFilter,G as GroupStatus,U as GroupType,k as GroupVerificationType,M as InternalContentType,C as InternalMessageStatus,L as LogLevel,j as LoginStatus,T as MessageOptionsKey,A as MessageReceiveOptType,F as MessageStatus,P as MessageType,S as MsgFrom,y as NotificationType,J as OnlineState,q as Platform,H as Relationship,D as ReqIdentifier,h as RequestApi,B as SessionType,$ as ViewType,w as WorkMomentSdkNotificationType,b as WsErrorCode,R as WsErrorEventMap,ct as getSDK}; diff --git a/node_modules/@openim/client-sdk/lib/index.umd.js b/node_modules/@openim/client-sdk/lib/index.umd.js index ef21f1d..56fa629 100644 --- a/node_modules/@openim/client-sdk/lib/index.umd.js +++ b/node_modules/@openim/client-sdk/lib/index.umd.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("loglevel"),require("spark-md5"),require("base64-arraybuffer"),require("@openim/protocol")):"function"==typeof define&&define.amd?define(["exports","loglevel","spark-md5","base64-arraybuffer","@openim/protocol"],t):t((e||self).clientSdk={},e.loglevel,e.sparkMd5,e.base64Arraybuffer,e.protocol)}(this,function(e,t,n,r,o){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=/*#__PURE__*/i(t),a=/*#__PURE__*/i(n);function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;tt.latestMsgSendTime?-1:e.latestMsgSendTime {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n "],{type:"application/javascript"});c.workerUrl=URL.createObjectURL(e),c.heartbeatWorker=new Worker(c.workerUrl),c.heartbeatWorker.onmessage=function(e){"ping"===e.data.type&&c.sendPing()},c.heartbeatWorker.postMessage({type:"start",interval:c.heartbeatInterval})}else c.legacyTimer=setInterval(function(){c.sendPing()},c.heartbeatInterval)},this.connect=function(){return"unknow"===c.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise(function(e,t){if(c.ws&&c.ws.readyState!==te.CLOSED)c.ws.readyState===c.ws.OPEN?e():t(new Error("WebSocket is in an unknown state"));else{var n=function(){c.reconnectAttempts&&c.onReconnectSuccess(),c.reconnectAttempts=0,c.startHeartbeat(),e()},r=function(e){return t(e)};if("web"===c.platformNamespace)c.ws=new WebSocket(c.urlFormat()),c.ws.onopen=n,c.ws.onerror=r;else{var o={url:c.urlFormat(),complete:function(){}};"my"===c.platformNamespace&&(o.multiple=!0),"uni"===c.platformNamespace&&(c.ws=uni.connectSocket(o)),"wx"===c.platformNamespace&&(c.ws=wx.connectSocket(o)),"my"===c.platformNamespace&&(c.ws=my.connectSocket(o)),c.ws.onOpen(n),c.ws.onError(r)}c.setupEventListeners()}})},this.setupEventListeners=function(){if(c.ws){var e=function(e){return c.onBinaryMessage(e.data)},t=function(e){if(c.shouldReconnect&&c.reconnectAttempts0&&(this.cleanupTimer=setInterval(function(){t.deleteExpired()},this.options.cleanupInterval))}var t=e.prototype;return t.onExpiry=function(e){this.expiryListeners.push(e)},t.triggerExpiry=function(e,t){this.expiryListeners.forEach(function(n){return n(e,t)}),this.delete(e)},t.set=function(e,t){var n=this;this.delete(e);var r=Date.now(),o=null;this.options.ttl>0&&(o=setTimeout(function(){clearTimeout(o),n.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:o,created:r})},t.get=function(e){var t=this.store.get(e);if(t&&Date.now()-t.createdd&&n.set(u,[d+1,c.maxSeq,c.maxSeqTime]):n.set(u,[0,c.maxSeq,c.maxSeqTime])}return r.syncAndTriggerMsgs(n,t),Promise.resolve()}catch(e){return Promise.reject(e)}},this.isNotification=function(e){return e.startsWith("n_")},this.syncAndTriggerMsgs=function(e,t){try{return s.default.debug("Current sync seqMap",e,e.size),Promise.resolve(function(){if(e.size>0){var n=function(n){return qe(function(){return Promise.resolve(i.pullMsgBySeqRange(r,t)).then(function(n){return Promise.resolve(i.instance.messageTrigger.triggerConversation(n.msgs,t)).then(function(){return Promise.resolve(i.instance.messageTrigger.triggerNotification(n.notificationMsgs,t)).then(function(){for(var t,n=c(e);!(t=n()).done;){var r=t.value,o=r[1];i.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:o[1],maxSeqTime:o[2]})}})})})},function(t){throw s.default.error("Sync message from server error",t,e),t})},r=new Map,o=0,a=function(e,t){if("function"==typeof e[we]){var n,r,o,i=function(e){try{for(;!(n=s.next()).done;)if((e=t(n.value))&&e.then){if(!Fe(e))return void e.then(i,o||(o=Ue.bind(null,r=new Oe,2)));e=e.v}r?Ue(r,1,e):r=e}catch(e){Ue(r||(r=new Oe),2,e)}},s=e[we]();if(i(),s.return){var a=function(e){try{n.done||s.return()}catch(e){}return e};if(r&&r.then)return r.then(a,function(e){throw a(e)});a()}return r}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],c=0;c=i.SplitPullMsgNum)return qe(function(){return Promise.resolve(i.pullMsgBySeqRange(r,t)).then(function(e){return Promise.resolve(i.instance.messageTrigger.triggerConversation(e.msgs,t)).then(function(){return Promise.resolve(i.instance.messageTrigger.triggerNotification(e.notificationMsgs,t)).then(function(){for(var e,t=c(r);!(e=t()).done;){var n=e.value,s=n[1];i.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:s[1],maxSeqTime:s[2]})}r=new Map,o=0})})})},function(e){throw s.default.error("Sync message from server error",e,r),e})}()}var d=a[0],g=a[1],p=a[2],l=g-d+1,f=function(){if(l/i.SplitPullMsgNum>1&&i.isNotification(n)){var e=new Map,r=Math.floor(l/i.SplitPullMsgNum),o=d,a=0,u=0;return function(e,t,n){for(var r;;){var o=e();if(Fe(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Fe(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Fe(s)){r=2;break}}}var a=new Oe,u=Ue.bind(null,a,2);return(0===r?o.then(d):1===r?i.then(c):s.then(g)).then(void 0,u),a;function c(r){i=r;do{if(t&&(s=t())&&s.then&&!Fe(s))return void s.then(g).then(void 0,u);if(!(o=e())||Fe(o)&&!o.v)return void Ue(a,1,i);if(o.then)return void o.then(d).then(void 0,u);Fe(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function d(e){e?(i=n())&&i.then?i.then(c).then(void 0,u):c(i):Ue(a,1,i)}function g(){(o=e())?o.then?o.then(d).then(void 0,u):d(o):Ue(a,1,i)}}(function(){return u<=r},function(){return u++},function(){return u===r?e.set(n,[o,g,p]):((a=o+i.SplitPullMsgNum)>g&&(a=g,u=r),e.set(n,[o,a,p])),qe(function(){return Promise.resolve(i.pullMsgBySeqRange(e,t)).then(function(n){return Promise.resolve(i.instance.messageTrigger.triggerConversation(n.msgs,t)).then(function(){return Promise.resolve(i.instance.messageTrigger.triggerNotification(n.notificationMsgs,t)).then(function(){for(var t,n=c(e);!(t=n()).done;){var r=t.value,s=r[1];i.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:s[1],maxSeqTime:s[2]})}o=a+1})})})},function(t){throw s.default.error("Sync message from server error",t,e),t})})}}();return f&&f.then?f.then(u):u()});return a&&a.then?a.then(n):n()}s.default.debug("Nothing to sync")}())}catch(e){return Promise.reject(e)}},this.pullMsgBySeqRange=function(t,n){try{var r=[].concat(t.entries()).map(function(e){var t=e[1];return{conversationID:e[0],begin:t[0],end:t[1],num:a.defaultPullNums}});s.default.debug("PullMsgBySeqRange with opid: ",n,"seqRanges: ",r);var i=o.PbCoder.PullMessageBySeqsReq.encode({userID:a.instance.userID,seqRanges:r,order:o.SdkWsProto.PullOrder.PullOrderAsc}).finish();return Promise.resolve(a.instance.sendReqWaitResp({operationID:n,data:i,reqIdentifier:e.ReqIdentifier.PullMsgByRange}))}catch(e){return Promise.reject(e)}},this.instance=t};function Ue(e,t,n){if(!e.s){if(n instanceof Oe){if(!n.s)return void(n.o=Ue.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Ue.bind(null,e,t),Ue.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var Oe=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Ue(r,1,i(this.v))}catch(e){Ue(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ue(r,1,t?t(o):o):n?Ue(r,1,n(o)):Ue(r,2,o)}catch(e){Ue(r,2,e)}},r},e}();function Fe(e){return e instanceof Oe&&1&e.s}var we="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ke(e,t,n){if(!e.s){if(n instanceof xe){if(!n.s)return void(n.o=ke.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(ke.bind(null,e,t),ke.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Le=[e.InternalMessageStatus.MsgStatusHasDeleted,e.InternalMessageStatus.MsgStatusFiltered],xe=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{ke(r,1,i(this.v))}catch(e){ke(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?ke(r,1,t?t(o):o):n?ke(r,1,n(o)):ke(r,2,o)}catch(e){ke(r,2,e)}},r},e}(),je=function(t){var n=this,r=this,i=this,a=this,u=this,c=this,g=this,p=this,l=this,f=this,v=this,h=this;this.instance=void 0,this.cache=void 0,this.syncer=void 0,this.triggeredConversationEvent=new Map,this.typingManager=void 0,this.sync=function(e){try{return Promise.resolve(r.cache.getMaxReadSeqs(e)).then(function(){var t=[r.syncer.syncConversationVersion(e),r.cache.getActiveConversationsFromServer(e),r.cache.getNotNotifyConversationIDs(e)];return Promise.resolve(Promise.all(t)).then(function(){})})}catch(e){return Promise.reject(e)}},this.reset=function(){n.cache.clear(),n.syncer.reset(),n.typingManager.reset(),n.triggeredConversationEvent.clear()},this.setTriggeredConversationEvent=function(e){n.triggeredConversationEvent.set(e,!0)},this.getMessageWithCacheBySeqs=function(e,t,n){try{var r=function(){return c.sort(function(e,t){return e.seq-t.seq}),{messages:c,filterCount:d}},o=i.cache.getCachedMessagesBySeqs(e,t),a=o.cachedMessages,u=o.unCachedSeqs,c=[].concat(a),d=0;s.default.debug("after getCachedMessagesBySeqs with opid: ",n,"seqs: ",t,"cachedMessages: ",a,"unCachedSeqs: ",u);var g=function(){if(u.length)return Promise.resolve(i.getMessageFromServerBySeqs([{conversationID:e,seqs:u}],n)).then(function(t){var n=[],r=[];t.msgs[e].Msgs.forEach(function(e){Le.includes(e.status)?(n.push(e.seq),d++):r.push(De(e))}),t.msgs[e].Msgs.length||n.push.apply(n,u),i.cache.addMessagesToCache(e,r),i.cache.addFilterSeqsToCache(e,n),c.push.apply(c,r)})}();return Promise.resolve(g&&g.then?g.then(r):r())}catch(e){return Promise.reject(e)}},this.getPreviousSeqMessage=function(e){var t=e.conversationID,n=e.seq,r=e.operationID;try{if(n<1)return Promise.resolve(null);for(var o=[],i=n;o.length<10&&!(i<1);i--)a.cache.checkIsFilterSeq(t,i)||o.push(i);return Promise.resolve(a.getMessageWithCacheBySeqs(t,o,r)).then(function(e){var n,i=e.messages;function s(e){return n?e:i[i.length-1]}var u=function(){if(!i.length)return Promise.resolve(a.getPreviousSeqMessage({seq:o[o.length-1],operationID:r,conversationID:t})).then(function(e){return n=1,e})}();return u&&u.then?u.then(s):s(u)})}catch(e){return Promise.reject(e)}},this.initConversation=function(t){try{var n=function(e){return u.cache.setCachedConversations([r]),r},r={conversationID:ie(d({},t,{userID:u.instance.userID})),userID:"",groupID:"",recvMsgOpt:e.MessageReceiveOptType.Nomal,unreadCount:0,groupAtType:e.GroupAtType.AtNormal,latestMsg:"",latestMsgSendTime:0,draftText:"",draftTextTime:0,burnDuration:0,msgDestructTime:0,isPinned:!1,isPrivateChat:!1,isMsgDestruct:!1,attachedInfo:"",ex:""},o=t.sessionType===e.SessionType.Group?Promise.resolve(u.instance.groupTrigger.cache.getGroupInfosWithCache([t.sourceID],t.operationID)).then(function(n){if(!n[0])throw new Error("target group not exist");r.showName=n[0].groupName,r.faceURL=n[0].faceURL,r.conversationType=e.SessionType.Group,r.groupID=t.sourceID}):(r.userID=t.sourceID,r.conversationType=e.SessionType.Single,Promise.resolve(u.instance.getSpecifiedFriendsInfo([t.sourceID],t.operationID)).then(function(e){var n=e.data,o=function(){if(!n.length)return Promise.resolve(u.instance.getUsersInfo([t.sourceID],t.operationID)).then(function(e){var t=e.data;r.showName=t[0].nickname,r.faceURL=t[0].faceURL});r.showName=n[0].remark||n[0].nickname,r.faceURL=n[0].faceURL}();if(o&&o.then)return o.then(function(){})}));return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}},this.getConversationsWithCacheByIDs=function(e,t){try{var n=function(){return[].concat(r,i)},r=[],i=[],s=[];e.forEach(function(e){var t=c.cache.getCachedConversation(e);t?r.push(t):s.push(e)});var a=function(){if(s.length)return Promise.resolve(c.instance.sendHttpRequest({reqFuncName:M.GetDesignatedConversation,data:o.PbCoder.GetConversationsReq.encode({ownerUserID:c.instance.userID,conversationIDs:s}).finish(),operationID:t})).then(function(e){var t=ue(e,M.GetDesignatedConversation),n=i.push;return Promise.resolve(Promise.all(t.conversations.map(function(e){var t,n;return Te(e,c.getPreviousSeqMessage,null==(t=c.cache.getCachedMaxReadSeq(null==(n=e.conversation)?void 0:n.conversationID))?void 0:t.maxSeqTime)}))).then(function(e){n.call.apply(n,[i].concat(e)),c.cache.setCachedConversations(i)})})}();return Promise.resolve(a&&a.then?a.then(n):n())}catch(e){return Promise.reject(e)}},this.getOneConversationAndTryChange=function(t,n,r,i,s){try{var a,u=function(t){return a?t:(c&&r&&g.instance.triggerEvent({event:s?e.CbEvents.OnNewConversation:e.CbEvents.OnConversationChanged,data:[d({},c)],operationID:n}),c)},c=void 0;c=g.cache.getCachedConversation(t);var p=function(){if(!c)return function(){if(g.cache.getCachedMaxReadSeq(t))return Promise.resolve(g.instance.sendHttpRequest({reqFuncName:M.GetDesignatedConversation,data:o.PbCoder.GetConversationsReq.encode({ownerUserID:g.instance.userID,conversationIDs:[t]}).finish(),operationID:n})).then(function(e){var n,r=ue(e,M.GetDesignatedConversation).conversations;if(r)return Promise.resolve(Te(r[0],g.getPreviousSeqMessage,null==(n=g.cache.getCachedMaxReadSeq(t))?void 0:n.maxSeqTime)).then(function(e){g.cache.setCachedConversations([c=e])});a=1})}();void 0!==(null==r?void 0:r.recvMsgOpt)&&(r.recvMsgOpt===e.MessageReceiveOptType.Nomal?g.cache.deleteNotNotifyConversationID(t):g.cache.addNotNotifyConversationID(t)),r&&Object.assign(c,r),i&&(c.unreadCount+=1)}();return Promise.resolve(p&&p.then?p.then(u):u(p))}catch(e){return Promise.reject(e)}},this.getMessageFromServerBySeqs=function(t,n){try{var r=o.PbCoder.GetSeqMessageReq.encode({userID:p.instance.userID,conversations:t}).finish();return Promise.resolve(p.instance.sendReqWaitResp({operationID:n,data:r,reqIdentifier:e.ReqIdentifier.PullMsgBySeqList}))}catch(e){return Promise.reject(e)}},this.revokeMessage=function(t,n){try{return Promise.resolve(l.getMessageWithCacheBySeqs(t.conversationID,[t.seq],n)).then(function(r){function o(){function r(){var r,i;l.instance.triggerEvent({event:e.CbEvents.OnNewRecvMessageRevoked,data:o,operationID:n});var s=null!=(r=null==(i=l.cache.getCachedMaxReadSeq(t.conversationID))?void 0:i.maxSeq)?r:0,a=function(){if(s<=t.seq)return l.cache.updateCachedMaxReadSeq(t.conversationID,{maxSeqTime:t.revokeTime}),Promise.resolve(l.getOneConversationAndTryChange(t.conversationID,n,{latestMsg:JSON.stringify(Ce(u)),latestMsgSendTime:t.revokeTime})).then(function(){})}();if(a&&a.then)return a.then(function(){})}var o={revokerID:t.revokerUserID,revokerRole:s,clientMsgID:i.clientMsgID,revokerNickname:a,revokeTime:t.revokeTime,sourceMessageSendTime:i.sendTime,sourceMessageSendID:i.sendID,sourceMessageSenderNickname:i.senderNickname,sessionType:t.sesstionType,seq:t.seq,ex:"",isAdminRevoke:t.isAdminRevoke},u=l.cache.tryUpdateCachedMessages(t.conversationID,{clientMsgID:t.clientMsgID,seq:t.seq,content:JSON.stringify({detail:JSON.stringify(o)}),contentType:e.NotificationType.RevokeNotification});l.cache.tryUpdateQuotedMessage(t.conversationID,t.clientMsgID);var c=function(){if(!u)return Promise.resolve(l.getMessageFromServerBySeqs([{conversationID:t.conversationID,seqs:[t.seq]}],n)).then(function(e){u=De(e.msgs[t.conversationID].Msgs[0])})}();return c&&c.then?c.then(r):r()}var i=r.messages[0],s=0,a="",u=function(){if(t.isAdminRevoke||t.sesstionType===e.SessionType.Single)return Promise.resolve(l.instance.getUsersInfo([t.revokerUserID],n)).then(function(e){var t;a=null==(t=e.data[0])?void 0:t.nickname});var r=function(){if(t.sesstionType===e.SessionType.Group)return Promise.resolve(l.getOneConversationAndTryChange(t.conversationID,n)).then(function(e){return Promise.resolve(l.instance.groupTrigger.cache.getGroupMembersWithCache({groupID:e.groupID,userIDList:[t.revokerUserID],operationID:n})).then(function(e){var t,n;a=null==(t=e[0])?void 0:t.nickname,s=null==(n=e[0])?void 0:n.roleLevel})})}();return r&&r.then?r.then(function(){}):void 0}();return u&&u.then?u.then(o):o()})}catch(e){return Promise.reject(e)}},this.triggerTyping=function(e){e.sendID!==n.instance.userID&&n.typingManager.onNewMessage(e)},this.triggerNotification=function(t,n){try{for(var r=0,o=Object.entries(t);re.NotificationType.FriendNotificationBegin&&t.contentTypee.NotificationType.UserNotificationBegin&&t.contentTypee.NotificationType.GroupNotificationBegin&&t.contentTypee.NotificationType.SignalingNotificationBegin&&t.contentTypeD&&(o=m||!h.cache.isNotNotifyConversation(u),h.cache.updateCachedMaxReadSeq(u,{maxSeq:D+1,maxSeqTime:y.sendTime}),I&&(h.cache.updateCachedMaxReadSeq(u,{hasReadSeq:C+1}),h.cache.tryUpdateCachedMessages(u,{clientMsgID:y.clientMsgID,seq:y.seq})))}}})},c=0,d=Object.entries(t);c0){if(!r)return a.map(function(e){h.cache.tryUpdateCachedMessages(oe(e),e)}),Promise.resolve();h.instance.triggerEvent({event:e.CbEvents.OnRecvNewMessages,data:a.map(Ce),operationID:n})}return Promise.resolve()}catch(e){return Promise.reject(e)}},this.instance=t,this.cache=new Ne(t),this.syncer=new Ee(t),this.typingManager=new Pe(t)},Be=/*#__PURE__*/function(){function t(t){var n=this,r=this,o=this,i=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=function(e,t){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:M.GetFullGroupMemberUserIDs,data:{groupID:e,idHash:0},operationID:t})).then(function(t){r.cachedGroupMembersID.set(e,t.userIDs)})}catch(e){return Promise.reject(e)}},this.getGroupInfosWithCache=function(t,n){try{var r=[],i=[];return t.forEach(function(e){var t=o.cachedGroups.get(e);t?r.push(t):i.push(e)}),i.length?Promise.resolve(o.instance.sendHttpRequest({reqFuncName:e.RequestApi.GetSpecifiedGroupsInfo,data:{groupIDs:i},operationID:n})).then(function(e){var t=e.groupInfos;return t&&t.forEach(function(e){return o.cachedGroups.set(e.groupID,e)}),[].concat(r,null!=t?t:[])}):Promise.resolve(r)}catch(e){return Promise.reject(e)}},this.getGroupMembersWithCache=function(t){var n=t.groupID,r=t.userIDList,o=t.operationID;try{var s,a,u=null!=(s=i.cachedGroupMembers.get(n))?s:[],c=function(){if(null!=r&&r.length){var t=[],s=[];return r.forEach(function(e){var n=u.find(function(t){return t.userID===e});n?s.push(n):t.push(e)}),t.length?Promise.resolve(i.instance.sendHttpRequest({reqFuncName:e.RequestApi.GetSpecifiedGroupMembersInfo,data:{groupID:n,userIDs:t},operationID:o})).then(function(e){var t=e.members;t&&i.cachedGroupMembers.set(n,[].concat(u,t));var r=[].concat(s,null!=t?t:[]);return a=1,r}):(a=1,s)}}();return Promise.resolve(c&&c.then?c.then(function(e){return a?e:u}):a?c:u)}catch(e){return Promise.reject(e)}},this.updateCachedGroups=function(e){e.map(function(e){n.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=function(e){var t,r=e[0].groupID,o=null!=(t=n.cachedGroupMembers.get(r))?t:[];n.cachedGroupMembers.set(r,[].concat(o.filter(function(t){return!e.find(function(e){return e.userID===t.userID})}),e));var i=n.instance.messageTrigger.cache.getAllCachedConversations().find(function(t){return t.groupID===e[0].groupID}),s=JSON.parse((null==i?void 0:i.latestMsg)||"{}"),a=e.find(function(e){return e.userID===s.sendID&&e.nickname!==s.senderNickname});i&&a&&n.instance.messageTrigger.getOneConversationAndTryChange(i.conversationID,"",{latestMsg:d({},s,{senderNickname:a.nickname})})},this.clearCachedGroupMembers=function(e){n.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=function(e){return n.cachedGroupMembersID.has(e)},this.getCachedGroupMembersID=function(e){var t;return null!=(t=n.cachedGroupMembersID.get(e))?t:[]},this.tryAddCachedGroupMembersID=function(e,t){if(n.cachedGroupMembersID.has(e)){var r,o=null!=(r=n.cachedGroupMembersID.get(e))?r:[];n.cachedGroupMembersID.set(e,[].concat(o,t))}},this.tryDeleteCachedGroupMembersID=function(e,t){if(n.cachedGroupMembersID.has(e)){var r,o=null!=(r=n.cachedGroupMembersID.get(e))?r:[];n.cachedGroupMembersID.set(e,o.filter(function(e){return!t.includes(e)}))}},this.instance=t}return t.prototype.clear=function(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()},t}(),Ve=/*#__PURE__*/function(){function t(t){var n=this,r=this,o=this,i=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=function(e){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:M.GetGroupVersion,data:{userID:r.instance.userID,version:r.syncedGroupsVersion,versionID:r.syncedGroupsVersionID},operationID:e})).then(function(t){r.syncedGroupsVersionID&&r.compareGroupVersionAndTrigger(t,e),r.syncedGroupsVersion=t.version,r.syncedGroupsVersionID=t.versionID})}catch(e){return Promise.reject(e)}},this.syncGroupInfoAndMemberVersion=function(e){try{var t=function(){if(n.length)return Promise.resolve(o.instance.sendHttpRequest({reqFuncName:M.GetGroupMemberVersion,data:{userID:o.instance.userID,reqList:n},operationID:e})).then(function(t){var n=t.respList;Object.keys(o.syncedGroupMemberVersion).length>0&&o.compareGroupMemberVersionAndTrigger(n,e),o.syncedGroupMemberVersion=n;for(var r=0,i=Object.entries(n);r0},0,function(){var e=t.queue.shift(),n=function(t,n){try{var r=Promise.resolve(e()).then(function(){})}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(0,function(e){s.default.error("Error executing task:",e)});if(n&&n.then)return n.then(function(){})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(e){return Promise.reject(e)}},e}();function ut(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var ct=((st={})[e.MessageType.TextMessage]="textElem",st[e.MessageType.AtTextMessage]="atTextElem",st[e.MessageType.LocationMessage]="locationElem",st[e.MessageType.CustomMessage]="customElem",st[e.MessageType.MergeMessage]="mergeElem",st[e.MessageType.QuoteMessage]="quoteElem",st[e.MessageType.CardMessage]="cardElem",st[e.MessageType.FaceMessage]="faceElem",st[e.MessageType.PictureMessage]="pictureElem",st[e.MessageType.VoiceMessage]="soundElem",st[e.MessageType.VideoMessage]="videoElem",st[e.MessageType.FileMessage]="fileElem",st);function dt(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var gt=[M.GetActiveConversations,M.GetDesignatedConversation];function pt(e,t,n){if(!e.s){if(n instanceof ft){if(!n.s)return void(n.o=pt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(pt.bind(null,e,t),pt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var lt=/*#__PURE__*/function(t){function n(){var n,i;return(n=t.call(this)||this).userID=void 0,n.platform=void 0,n.token=void 0,n.apiAddr=void 0,n.loginStatus=e.LoginStatus.Logout,n.isReconnected=!1,n.connectState="disconnected",n.wsManager=void 0,n.messageTrigger=void 0,n.userTrigger=void 0,n.groupTrigger=void 0,n.relationTrigger=void 0,n.businessTrigger=void 0,n.requestMap=new Map,n.generateHttpHeader=function(e,t){var r={"Content-Type":"application/json",token:n.token,operationID:t,reqFuncName:e};return gt.includes(e)&&(r["Content-Type"]="application/x-protobuf"),r},n.sendHttpRequest=function(e){try{var t;return Promise.resolve(function(e){var t=e.url,n=e.data,r=e.headers,o=e.platform,i=e.method,s=void 0===i?"POST":i;return"web"===o?function(e){var t=e.url,n=e.data,r=e.headers,o=e.method,i=void 0===o?"POST":o;try{return Promise.resolve(fetch(t,{method:i,headers:d({},r),body:n instanceof Uint8Array?n:JSON.stringify(n)}).then(function(e){if(e.ok)return e.json();throw new Error(e.statusText)}).then(function(e){if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))}catch(e){return Promise.reject(e)}}(e):new Promise(function(e,i){var a=function(e){return"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null}(o);a?a({url:t,data:n instanceof Uint8Array?Uint8Array.from(n).buffer:n,method:s,header:d({"Content-Type":"application/json"},r),success:function(t){200===t.statusCode&&0===t.data.errCode?e(t.data.data):i(t.data||"Request failed")},fail:function(e){i(e)}}):i(new Error("Request is not supported"))})}({url:""+n.apiAddr+(e.replaceURL||O[e.reqFuncName]),data:e.data,headers:n.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(t=n.wsManager)?void 0:t.platformNamespace)||"web"}))}catch(e){return Promise.reject(e)}},n.handleWsConnected=function(t,r){try{var o=function(){if(0===t.errCode){n.connectState="connected",n.loginStatus=e.LoginStatus.Logged,n.triggerEvent({event:e.CbEvents.OnConnectSuccess}),n.triggerEvent({event:e.CbEvents.OnSyncServerStart});var o=[n.messageTrigger.sync(r),n.relationTrigger.sync(r),n.groupTrigger.sync(r),n.userTrigger.sync(r)],i=dt(function(){return Promise.resolve(Promise.all(o)).then(function(){n.triggerEvent({event:e.CbEvents.OnSyncServerFinish})})},function(t){s.default.error(t),n.triggerEvent({event:e.CbEvents.OnSyncServerFailed,errCode:t.errCode||e.ErrorCode.SdkInternalError,errMsg:t.message||"Internal Error"})});if(i&&i.then)return i.then(function(){})}else{n.triggerEvent({event:e.CbEvents.OnConnectFailed,errCode:t.errCode,errMsg:t.errMsg,operationID:r});var a=ee[t.errCode];a&&n.triggerEvent({event:a,errCode:t.errCode,errMsg:t.errMsg,operationID:r}),n.connectState="disconnected",n.loginStatus=e.LoginStatus.Logout}}();return Promise.resolve(o&&o.then?o.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},n.handleMessage=function(e,t){try{var r=function(){if("string"!=typeof e){var r=function(){var t=le(e),r=JSON.parse(t);n.handleGeneralWsResp(r)},o=function(){if(!(e instanceof ArrayBuffer))return Promise.resolve(e.arrayBuffer()).then(function(t){e=t})}();return o&&o.then?o.then(r):r()}var i=JSON.parse(e);n.handleWsConnected(i,t)}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},n.handleGeneralWsResp=function(t){var r=ue(t.data,t.reqIdentifier);if(t.reqIdentifier===e.ReqIdentifier.PushMsg&&r)return n.messageTrigger.triggerConversation(r.msgs,t.operationID),void n.messageTrigger.triggerNotification(r.notificationMsgs,t.operationID);if(t.reqIdentifier!==e.ReqIdentifier.WsSubUserOnlineStatus||t.msgIncr||n.userTrigger.onlineSub.userOnlineStateChange(r),t.reqIdentifier===e.ReqIdentifier.KickOnlineMsg)return n.triggerEvent({event:e.CbEvents.OnKickedOffline,operationID:t.operationID}),void n.reset();var o=n.requestMap.get(t.msgIncr);o&&(0===t.errCode?o.resolve(r):o.reject(new ge(t.errCode,t.errMsg)),n.requestMap.delete(t.msgIncr))},n.handleReconnecting=function(){n.connectState="reconnecting",n.triggerEvent({event:e.CbEvents.OnConnecting})},n.handleReconnectFailed=function(){n.connectState="disconnected",n.triggerEvent({event:e.CbEvents.OnConnectFailed,errCode:e.ErrorCode.NetworkError,errMsg:"network error"})},n.handleReconnectSuccess=function(){n.isReconnected=!0},n.sendReqWaitResp=function(t){var o=t.data,i=t.reqIdentifier,s=t.operationID;if("connected"!==n.connectState)throw new ge(e.ErrorCode.NetworkError,"network error, ws not connected");var a=ne();return new Promise(function(e,t){var u;n.requestMap.set(a,{resolve:e,reject:t}),null==(u=n.wsManager)||u.sendMessage({reqIdentifier:i,msgIncr:a,sendID:n.userID,operationID:s,data:r.encode(o.buffer)})})},n.triggerEvent=function(t){var r=t.event,o=t.data,i=void 0===o?null:o,a=t.errCode,u=void 0===a?0:a,c=t.errMsg,d=void 0===c?"":c,g=t.operationID,p=void 0===g?"":g;n.loginStatus!==e.LoginStatus.Logout&&(s.default.debug("%cSDK =>%c [OperationID:"+p+"] (event) trigger "+r+" with data "+JSON.stringify(i)+" errCode "+u+" errMsg "+d,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),n.emit(r,{event:r,data:i,errCode:u,errMsg:d,operationID:p}))},n.login=function(t,r){try{return Promise.resolve(pe(e.LoginStatus.Logged,e.RequestApi.Login,r,function(){try{var o,i=t.userID,a=t.token,u=t.wsAddr,c=t.apiAddr,d=t.platformID;if(n.wsManager)throw new ge(e.ErrorCode.LoginRepeatError,"login repeat");return s.default.setLevel(null!=(o=t.logLevel)?o:e.LogLevel.Debug),n.userID=i,n.token=a,n.apiAddr=c,n.platform=d,n.wsManager=new he(u,{sendID:i,token:a,platformID:d,operationID:r,isBackground:!1,isMsgResp:!0,sdkType:"js"},n.handleMessage,n.handleReconnecting,n.handleReconnectFailed,n.handleReconnectSuccess),n.connectState="connecting",n.loginStatus=e.LoginStatus.Logging,n.triggerEvent({event:e.CbEvents.OnConnecting,operationID:r}),Promise.resolve(dt(function(){return Promise.resolve(n.wsManager.connect()).then(function(){})},function(t){throw n.triggerEvent({event:e.CbEvents.OnConnectFailed,errCode:e.ErrorCode.NetworkError,errMsg:t.message||"network error",operationID:r}),n.connectState="disconnected",n.loginStatus=e.LoginStatus.Logout,n.wsManager.close(),new ge(e.ErrorCode.NetworkError,t.message||"network error")}))}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},n.getLoginStatus=function(t){return pe(e.LoginStatus.Logged,e.RequestApi.GetLoginStatus,t,function(){try{var e;return null==(e=n.wsManager)||e.sendPing(),Promise.resolve(n.loginStatus)}catch(e){return Promise.reject(e)}})},n.logout=function(t){return pe(n.loginStatus,e.RequestApi.Logout,t,function(){try{return n.reset(),Promise.resolve()}catch(e){return Promise.reject(e)}})},n.internalUploadFile=function(e,t){return Promise.resolve(dt(function(){var r=n.userID+"/"+e.name,o=function(e){var t,n,r=null!=(t=null==(n=e.split(".").pop())?void 0:n.toLowerCase())?t:"";return D[r]||"application/octet-stream"}(e.name),i={operationID:t,token:n.token};return Promise.resolve(function(e,t,n){return fetch(e+"/object/part_size",{method:"POST",headers:d({},n),body:JSON.stringify({size:t})}).then(y)}(n.apiAddr,e.size,i)).then(function(t){var s=t.size;function u(){var t=p.join(",");l.destroy();var u=new a.default;return u.append(t),Promise.resolve(function(e,t,n){return fetch(e+"/object/initiate_multipart_upload",{method:"POST",headers:d({},n),body:JSON.stringify(t)}).then(y)}(n.apiAddr,{hash:u.end(),size:e.size,partSize:s,maxParts:-1,cause:"",name:r,contentType:o},i)).then(function(t){var s=t.url,a=t.upload;if(u.destroy(),s)return{url:s};var c=a.sign.query,l=a.sign.header;return Promise.resolve(Promise.all(a.sign.parts.map(function(t,n){try{var r=new URL(t.url||a.sign.url);if(c){var i=new URLSearchParams(r.search);c.forEach(function(e){i.set(e.key,e.values[0])}),r.search=i.toString()}if(t.query){var s=new URLSearchParams(r.search);t.query.forEach(function(e){s.set(e.key,e.values[0])}),r.search=s.toString()}var u=r.toString(),d=new Headers;return l&&l.forEach(function(e){d.set(e.key,e.values[0])}),t.header&&t.header.forEach(function(e){d.set(e.key,e.values[0])}),d.set("Content-Length",(g[n].end-g[n].start).toString()),d.set("Content-Type",o),Promise.resolve(fetch(u,{method:"PUT",headers:d,body:e.slice(g[n].start,g[n].end)})).then(function(e){if(!e.ok)throw new Error("Failed to upload chunk "+(n+1))})}catch(e){return Promise.reject(e)}}))).then(function(){return Promise.resolve(function(e,t,n){return fetch(e+"/object/complete_multipart_upload",{method:"POST",headers:d({},n),body:JSON.stringify(t)}).then(y)}(n.apiAddr,{uploadID:a.uploadID,parts:p,cause:"",name:r,contentType:o},i)).then(function(e){return{url:e.url}})})})}var c=Math.ceil(e.size/s),g=[],p=[],l=new a.default.ArrayBuffer,f=0,v=function(e,t,n){for(var r;;){var o=e();if(vt(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!vt(i)){r=1;break}i=i.s}}var s=new ft,a=pt.bind(null,s,2);return(0===r?o.then(c):1===r?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):pt(s,1,i)})).then(void 0,a),s;function u(t){i=t;do{if(!(o=e())||vt(o)&&!o.v)return void pt(s,1,i);if(o.then)return void o.then(c).then(void 0,a);vt(i=n())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,a)}function c(e){e?(i=n())&&i.then?i.then(u).then(void 0,a):u(i):pt(s,1,i)}}(function(){return fp?g:p,count:r-t.length,conversationID:o,operationID:i,fetchedMessages:d})}return d}):Promise.resolve(a)}catch(e){return Promise.reject(e)}};return{createTextMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateTextMessage,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.TextMessage);return r.textElem={content:n},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createTextAtMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateTextAtMessage,r,function(){try{var r;if(!n.text)throw new ge(e.ErrorCode.ArgsError,"text cannot be empty");if(n.atUserIDList.length>10)throw new ge(e.ErrorCode.ArgsError,"atUserIDList length must be less than 10");var o,i=ce(t,e.MsgFrom.UserMsgType,e.MessageType.AtTextMessage);return(null==(r=n.message)?void 0:r.contentType)===e.MessageType.QuoteMessage&&(n.message.contentType=e.MessageType.TextMessage,n.message.textElem={content:null==(o=n.message.quoteElem)?void 0:o.text}),i.atTextElem={text:n.text,atUserList:n.atUserIDList,atUsersInfo:n.atUsersInfo,quoteMessage:n.message},Promise.resolve(i)}catch(e){return Promise.reject(e)}})},createLocationMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateLocationMessage,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.LocationMessage);return r.locationElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createCustomMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateCustomMessage,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.CustomMessage);return r.customElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createQuoteMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateQuoteMessage,r,function(){try{var r,o=ce(t,e.MsgFrom.UserMsgType,e.MessageType.QuoteMessage),i=JSON.parse(n.message);return i.contentType===e.MessageType.QuoteMessage&&(i.contentType=e.MessageType.TextMessage,i.textElem={content:null==(r=i.quoteElem)?void 0:r.text}),o.quoteElem={text:n.text,quoteMessage:i},Promise.resolve(o)}catch(e){return Promise.reject(e)}})},createCardMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateCardMessage,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.CardMessage);return r.cardElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByURL:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateImageMessageByURL,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.PictureMessage);return r.pictureElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByFile:function(r,o){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.CreateImageMessageByFile,o,function(){try{var o=ce(t,e.MsgFrom.UserMsgType,e.MessageType.PictureMessage);return o.pictureElem=d({},r),n.set(r.sourcePicture.uuid,r.file),Promise.resolve(o)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createSoundMessageByURL:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateSoundMessageByURL,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.VoiceMessage);return r.soundElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createSoundMessageByFile:function(r,o){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.CreateSoundMessageByFile,o,function(){try{var o=ce(t,e.MsgFrom.UserMsgType,e.MessageType.VoiceMessage);return o.soundElem=d({},r),n.set(r.uuid,r.file),Promise.resolve(o)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createVideoMessageByURL:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateVideoMessageByURL,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.VideoMessage);return r.videoElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createVideoMessageByFile:function(r,o){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.CreateVideoMessageByFile,o,function(){try{var o=ce(t,e.MsgFrom.UserMsgType,e.MessageType.VideoMessage);return o.videoElem=d({},r),n.set(r.videoUUID,r.videoFile),n.set(r.snapshotUUID,r.snapshotFile),Promise.resolve(o)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createFileMessageByURL:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateFileMessageByURL,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.FileMessage);return r.fileElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFileMessageByFile:function(r,o){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.CreateFileMessageByFile,o,function(){try{var o=ce(t,e.MsgFrom.UserMsgType,e.MessageType.FileMessage);return o.fileElem=d({},r),n.set(r.uuid,r.file),Promise.resolve(o)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createMergerMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateMergerMessage,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.MergeMessage);return r.mergeElem={title:n.title,abstractList:n.summaryList,multiMessage:n.messageList,messageEntityList:[]},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFaceMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateFaceMessage,r,function(){try{var r=ce(t,e.MsgFrom.UserMsgType,e.MessageType.FaceMessage);return r.faceElem=d({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createForwardMessage:function(n,r){return pe(t.loginStatus,e.RequestApi.CreateForwardMessage,r,function(){try{if(n.status!==e.MessageStatus.Succeed)throw new ge(e.ErrorCode.ArgsError,"Only successfully sent messages can be forwarded");var r=ce(t,e.MsgFrom.UserMsgType,n.contentType);return Promise.resolve(d({},n,r,{seq:0,status:e.MessageStatus.Sending}))}catch(e){return Promise.reject(e)}})},sendMessage:function(i,s){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.SendMessage,s,function(){return r.enqueue(function(){try{var r=d({},i,{message:d({},i.message)}),a=r.message,u=r.recvID,c=r.groupID,g=r.isOnlineOnly,p=r.offlinePushInfo,l=void 0===p?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:p;void 0===l.signalInfo&&(l.signalInfo="");var f=ct[a.contentType];if(!f)throw new ge(e.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");a.recvID=u,a.groupID=c,a.sessionType=c?e.SessionType.Group:e.SessionType.Single;var v={};g&&Object.values(e.MessageOptionsKey).forEach(function(e){return v[e]=!1});var h=oe(a),m=!1;return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(h,s)).then(function(r){function i(){function i(i){function d(i){function d(i){function d(i){function d(n){var i,d,g=JSON.stringify(a[f]),p=o.PbCoder.MsgData.encode({sendID:t.userID,recvID:u||"",groupID:c||"",clientMsgID:a.clientMsgID,serverMsgID:a.serverMsgID||"",senderPlatformID:t.platform,senderNickname:a.senderNickname,senderFaceURL:a.senderFaceUrl,sessionType:a.sessionType,msgFrom:a.msgFrom,contentType:a.contentType,content:fe(g),seq:a.seq,sendTime:0,createTime:a.createTime,status:a.status,isRead:!1,options:v,offlinePushInfo:l,atUserIDList:null!=(i=null==(d=a.atTextElem)?void 0:d.atUserList)?i:[],attachedInfo:a.attachedInfoElem?JSON.stringify(a.attachedInfoElem):"",ex:a.ex||"",keyVersion:0,dstUserIDs:[]}).finish();return ut(function(){return Promise.resolve(t.sendReqWaitResp({data:p,operationID:s,reqIdentifier:e.ReqIdentifier.SendMsg})).then(function(n){var o=n.serverMsgID,i=n.sendTime;return a.sendTime=i,a.serverMsgID=o,a.status=e.MessageStatus.Succeed,t.messageTrigger.setTriggeredConversationEvent(s),t.messageTrigger.cache.updateCachedMaxReadSeq(r.conversationID,{maxSeqTime:i}),t.messageTrigger.getOneConversationAndTryChange(h,s,{latestMsg:JSON.stringify(a),latestMsgSendTime:i}),a})},function(n){throw a.status=e.MessageStatus.Failed,t.messageTrigger.getOneConversationAndTryChange(h,s,{latestMsg:JSON.stringify(a)}),n})}var g=function(){if(a.contentType===e.MessageType.FileMessage){var r,o=n.get(null==(r=a.fileElem)?void 0:r.uuid);if(!o)throw new ge(e.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(o,s)).then(function(t){var r,o=t.url,i=void 0===o?"":o,s=t.error;if(n.delete(null==(r=a.fileElem)?void 0:r.uuid),s)throw new ge(e.ErrorCode.NetworkError,"Upload file failed");a.fileElem.sourceUrl=i})}}();return g&&g.then?g.then(d):d()}var g=function(){if(a.contentType===e.MessageType.VideoMessage){var r,o,i=n.get(null==(r=a.videoElem)?void 0:r.videoUUID),u=n.get(null==(o=a.videoElem)?void 0:o.snapshotUUID);if(!i||!u)throw new ge(e.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(Promise.all([t.internalUploadFile(i,s),t.internalUploadFile(u,s)])).then(function(t){var r,o;if(n.delete(null==(r=a.videoElem)?void 0:r.videoUUID),n.delete(null==(o=a.videoElem)?void 0:o.snapshotUUID),t[0].error||t[1].error)throw new ge(e.ErrorCode.NetworkError,"Upload file failed");a.videoElem.videoUrl=t[0].url,a.videoElem.snapshotUrl=t[1].url})}}();return g&&g.then?g.then(d):d()}var g=function(){if(a.contentType===e.MessageType.VoiceMessage){var r,o=n.get(null==(r=a.soundElem)?void 0:r.uuid);if(!o)throw new ge(e.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(o,s)).then(function(t){var r,o=t.url,i=void 0===o?"":o,s=t.error;if(n.delete(null==(r=a.soundElem)?void 0:r.uuid),s)throw new ge(e.ErrorCode.NetworkError,"Upload file failed");a.soundElem.sourceUrl=i})}}();return g&&g.then?g.then(d):d()}r.latestMsgSendTime=a.createTime,t.messageTrigger.getOneConversationAndTryChange(h,s,{latestMsg:JSON.stringify(a)},void 0,m);var g=function(){if(a.contentType===e.MessageType.PictureMessage){var r,o=n.get(null==(r=a.pictureElem)?void 0:r.sourcePicture.uuid);if(!o)throw new ge(e.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(o,s)).then(function(t){var r,o=t.url,i=void 0===o?"":o,s=t.error;if(n.delete(null==(r=a.pictureElem)?void 0:r.sourcePicture.uuid),s)throw new ge(e.ErrorCode.NetworkError,"Upload file failed");a.pictureElem.sourcePicture.url=i,a.pictureElem.bigPicture.url=i,a.pictureElem.snapshotPicture.width=640,a.pictureElem.snapshotPicture.height=640,a.pictureElem.snapshotPicture.url=i+"?type=image&width=640&height=640"})}}();return g&&g.then?g.then(d):d()}var d=function(){if(c)return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:c,userIDList:[t.userID],operationID:s})).then(function(t){if(null==t||!t.length)throw new ge(e.ErrorCode.ArgsError,"user not join target group");t[0].nickname&&(a.senderNickname=t[0].nickname)})}();return d&&d.then?d.then(i):i()}var g=function(){if(!r)return m=!0,Promise.resolve(t.messageTrigger.initConversation({sourceID:c||u,sessionType:a.sessionType,operationID:s})).then(function(e){r=e});r.isPrivateChat&&(v[e.MessageOptionsKey.IsNotPrivate]=!1,a.attachedInfoElem=d({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:r.burnDuration}))}();return g&&g.then?g.then(i):i()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},sendMessageNotOss:function(n,i){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.SendMessage,i,function(){return r.enqueue(function(){try{var r=d({},n,{message:d({},n.message)}),s=r.message,a=r.recvID,u=r.groupID,c=r.isOnlineOnly,g=r.offlinePushInfo,p=void 0===g?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:g;void 0===p.signalInfo&&(p.signalInfo="");var l=ct[s.contentType];if(!l)throw new ge(e.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");s.recvID=a,s.groupID=u,s.sessionType=u?e.SessionType.Group:e.SessionType.Single;var f={};c&&Object.values(e.MessageOptionsKey).forEach(function(e){return f[e]=!1});var v=oe(s);return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(v,i)).then(function(n){function r(r){var c,d;n.latestMsgSendTime=s.createTime,t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s)});var g=JSON.stringify(s[l]),h=o.PbCoder.MsgData.encode({sendID:t.userID,recvID:a||"",groupID:u||"",clientMsgID:s.clientMsgID,serverMsgID:s.serverMsgID||"",senderPlatformID:t.platform,senderNickname:s.senderNickname,senderFaceURL:s.senderFaceUrl,sessionType:s.sessionType,msgFrom:s.msgFrom,contentType:s.contentType,content:fe(g),seq:s.seq,sendTime:0,createTime:s.createTime,status:s.status,isRead:!1,options:f,offlinePushInfo:p,atUserIDList:null!=(c=null==(d=s.atTextElem)?void 0:d.atUserList)?c:[],attachedInfo:s.attachedInfoElem?JSON.stringify(s.attachedInfoElem):"",ex:s.ex||"",keyVersion:0,dstUserIDs:[]}).finish();return ut(function(){return Promise.resolve(t.sendReqWaitResp({data:h,operationID:i,reqIdentifier:e.ReqIdentifier.SendMsg})).then(function(r){var o=r.serverMsgID,a=r.sendTime;return s.sendTime=a,s.serverMsgID=o,s.status=e.MessageStatus.Succeed,t.messageTrigger.setTriggeredConversationEvent(i),t.messageTrigger.cache.updateCachedMaxReadSeq(n.conversationID,{maxSeqTime:a}),t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s),latestMsgSendTime:a}),s})},function(n){throw s.status=e.MessageStatus.Failed,t.messageTrigger.getOneConversationAndTryChange(v,i,{latestMsg:JSON.stringify(s)}),n})}var c=function(){if(!n)return Promise.resolve(t.messageTrigger.initConversation({sourceID:u||a,sessionType:s.sessionType,operationID:i})).then(function(r){return n=r,function(){if(u)return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:u,userIDList:[t.userID],operationID:i})).then(function(t){if(null==t||!t.length)throw new ge(e.ErrorCode.ArgsError,"user not join target group");t[0].nickname&&(s.senderNickname=t[0].nickname)})}()});n.isPrivateChat&&(f[e.MessageOptionsKey.IsNotPrivate]=!1,s.attachedInfoElem=d({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:n.burnDuration}))}();return c&&c.then?c.then(r):r()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},revokeMessage:function(n,r){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.RevokeMessage,r,function(){try{var o=function(o){return Promise.resolve(t.sendHttpRequest({reqFuncName:e.RequestApi.RevokeMessage,data:{conversationID:n.conversationID,seq:i.seq,userID:t.userID},operationID:r})).then(function(){t.messageTrigger.setTriggeredConversationEvent(r),t.messageTrigger.revokeMessage({revokerUserID:t.userID,clientMsgID:i.clientMsgID,revokeTime:Date.now(),sesstionType:i.sessionType,seq:i.seq,conversationID:n.conversationID,isAdminRevoke:!1},r)})},i=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.clientMsgID])[0];if(!i)throw new ge(e.ErrorCode.ArgsError,"message not exist");var s=function(){if(i.sendID!==t.userID){if(!i.groupID)throw new ge(e.ErrorCode.ArgsError,"message can not be revoked");return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:i.groupID,userIDList:[t.userID],operationID:r})).then(function(t){var n=t[0];if(!n||n.roleLevel===e.GroupMemberRole.Nomal)throw new ge(e.ErrorCode.ArgsError,"message can not be revoked")})}}();return Promise.resolve(s&&s.then?s.then(o):o())}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},getAdvancedHistoryMessageList:function(n,r){try{return Promise.resolve(pe(t.loginStatus,e.RequestApi.GetAdvancedHistoryMessageList,r,function(){try{var o={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(a!==n.conversationID&&(i=null,a=n.conversationID),n.startClientMsgID){if(null===i){var c=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!c)return Promise.resolve(d({},o,{isEnd:!0}));i=c.seq}}else i=0;var g=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);return s.default.log("syncedSeqs",g),g?Promise.resolve(u({maxSeq:i?i-1:g.maxSeq,count:n.count,conversationID:n.conversationID,operationID:r})).then(function(a){function u(){function u(){var e,t;return o.messageList=a.map(Ce),s.default.debug("getAdvancedHistoryMessageList with opid: ",r,"messageList: ",o.messageList),i=null!=(e=null==(t=a[0])?void 0:t.seq)?e:0,d({},o,{isEnd:a.length%c [OperationID:"+t[t.length-1]+"] (invoked) run "+e+" with args "+JSON.stringify(t),"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")}(t,n),Promise.resolve(r.apply(e,n)).then(function(e){var n,r;return n=t,(r=e).errCode?s.default.debug("%cSDK =>%c [OperationID:"+r.operationID+"] (response) run "+n+" with error "+JSON.stringify(r),"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):s.default.debug("%cSDK =>%c [OperationID:"+r.operationID+"] (response) run "+n+" with response before processor "+JSON.stringify(r.data),"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),e.errCode?Promise.reject(e):e})}catch(e){return Promise.reject(e)}}:Reflect.get(e,t,n)}})}}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("loglevel"),require("spark-md5"),require("base64-arraybuffer"),require("@openim/protocol"),require("crypto-js")):"function"==typeof define&&define.amd?define(["exports","loglevel","spark-md5","base64-arraybuffer","@openim/protocol","crypto-js"],t):t((e||self).clientSdkEnterprise={},e.loglevel,e.sparkMd5,e.base64Arraybuffer,e.protocol,e.cryptoJs)}(this,function(e,t,n,r,i,o){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/s(t),u=/*#__PURE__*/s(n),c=/*#__PURE__*/s(o);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function v(){return v=Object.assign?Object.assign.bind():function(e){for(var t=1;tt.latestMsgSendTime?-1:e.latestMsgSendTime>6*(r-1)),o=1;o>6*(r-(o+1))&191);return}}},Ce=function(e,t,n,r){var i=t.getUint8(n);if(e.bytesRead=1,e.charVal=0,128&i){for(var o=0,s=i;128&s;)o++,s<<=1;if(1===o)return console.error("UTF-8 read - found continuation byte at beginning of character"),void(e.charVal=De);if(o>r)return console.error("UTF-8 read - attempted to read "+o+" byte character, "+(r-o)+" bytes past end of buffer"),void(e.charVal=De);e.charVal=i&255>>o+1;for(var a=1;a>8-(o+1)-1))return console.error("UTF-8 read - found overlong encoding"),e.charVal=De,void(e.bytesRead=1);e.bytesRead++}if(e.charVal>1114111)return console.error("UTF-8 read - found illegally high code point "+e.charVal),e.charVal=De,void(e.bytesRead=1)}else e.charVal=i},Te=function(e){for(var t=[],n=0;n255&&(r="?".charCodeAt(0)),t.push(r)}return t},Re=function(e,t,n,r){var i=void 0===n,o=t||0;if(!i&&o+n>e.byteLength)throw new Error("Attempted to read "+(o+n-e.byteLength)+" bytes past end of buffer");for(var s=[],a={};oo-t)&&(Ce(a,e,o,i?e.byteLength-(o+t):n-(o-t)),o+=a.bytesRead,!i||a.charVal!==r);)s.push(String.fromCharCode(a.charVal));return{str:s.join(""),byteLength:o-t}},Ae=function(e,t,n,r){var i=[],o=0;t=t||0;var s=!1;void 0===n&&(s=!0,n=e.byteLength-e.byteOffset);for(var a=0;a=e.byteLength&&(i-=1),e.setUint8(t+i,0),i+1},e}()),Ue=function(e){return(new TextDecoder).decode(e)},Oe=function(e){return(new TextEncoder).encode(e)};!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(Ee||(Ee={}));var Fe,ke=/*#__PURE__*/function(){function e(e,t,n,r,i,o,s,a,u,c){var d=this,g=this;void 0===a&&(a=5e3),void 0===u&&(u=Infinity),this.url=void 0,this.onMessage=void 0,this.onClose=void 0,this.onReconnecting=void 0,this.onReconnectFailed=void 0,this.onReconnectSuccess=void 0,this.reconnectInterval=void 0,this.maxReconnectAttempts=void 0,this.ws=void 0,this.connectParams=void 0,this.reconnectAttempts=void 0,this.shouldReconnect=void 0,this.isProcessingMessage=!1,this.consecutiveHeartbeatFailures=0,this.connectTimeoutId=null,this.platformNamespace=void 0,this.envListenersInstalled=!1,this.heartbeatConfig={interval:1e4,timeout:5e3,maxFailures:3},this.heartbeatWorker=null,this.legacyTimer=null,this.heartbeatTimeoutId=null,this.workerUrl=null,this.lastPongAt=0,this.forceImmediateReconnect=!1,this.checkPlatform=function(){if("undefined"!=typeof WebSocket)try{if("undefined"!=typeof window&&window.WebSocket)return"web";if("undefined"!=typeof global&&global.WebSocket)return"web"}catch(e){}return"undefined"!=typeof my&&"function"==typeof my.connectSocket?"my":"undefined"!=typeof uni&&"function"==typeof uni.connectSocket?"uni":"undefined"!=typeof wx&&"function"==typeof wx.connectSocket?"wx":"unknow"},this.urlFormat=function(){for(var e="?",t=0,n=Object.entries(g.connectParams);t {\n if (e.data.type === 'start') {\n heartbeatInterval = e.data.interval;\n if (timerId) return;\n \n timerId = self.setInterval(() => {\n self.postMessage({ type: 'ping' });\n }, heartbeatInterval);\n } else if (e.data.type === 'stop') {\n if (timerId) {\n self.clearInterval(timerId);\n timerId = null;\n }\n }\n };\n "],{type:"application/javascript"});g.workerUrl=URL.createObjectURL(e),g.heartbeatWorker=new Worker(g.workerUrl),g.heartbeatWorker.onmessage=function(e){"ping"===e.data.type&&g.sendPing()},g.heartbeatWorker.postMessage({type:"start",interval:g.heartbeatConfig.interval})}catch(e){g.heartbeatWorker=null,g.workerUrl&&(URL.revokeObjectURL(g.workerUrl),g.workerUrl=null),g.legacyTimer=setInterval(function(){g.sendPing()},g.heartbeatConfig.interval)}else g.legacyTimer=setInterval(function(){g.sendPing()},g.heartbeatConfig.interval)},this.connect=function(e){return void 0===e&&(e=1e4),"unknow"===g.platformNamespace?Promise.reject(new Error("WebSocket is not supported")):new Promise(function(t,n){if(g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.connectTimeoutId=setTimeout(function(){g.ws&&(g.ws.close(),g.onClose()),n(new Error("Connection timeout after "+e+"ms"))},e),g.ws&&g.ws.readyState!==Ee.CLOSED)g.ws.readyState===g.ws.OPEN?(g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),t()):(g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),n(new Error("WebSocket is in an unknown state")));else{var r=function(){g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.reconnectAttempts&&g.onReconnectSuccess(),g.reconnectAttempts=0,g.consecutiveHeartbeatFailures=0,g.lastPongAt=Date.now(),g.startHeartbeat(),t()},i=function(e){g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),n(e)};if("web"===g.platformNamespace)g.ws=new WebSocket(g.urlFormat()),g.ws.onopen=r,g.ws.onerror=i;else{var o={url:g.urlFormat(),complete:function(){}};"my"===g.platformNamespace&&(o.multiple=!0),"uni"===g.platformNamespace&&(g.ws=uni.connectSocket(o)),"wx"===g.platformNamespace&&(g.ws=wx.connectSocket(o)),"my"===g.platformNamespace&&(g.ws=my.connectSocket(o)),g.ws.onOpen(r),g.ws.onError(i)}g.setupEventListeners(),g.installEnvListeners()}})},this.setupEventListeners=function(){if(g.ws){var e=function(e){return g.onBinaryMessage(e.data)},t=function(e){if(g.shouldReconnect&&g.reconnectAttempts=g.heartbeatConfig.maxFailures)return console.warn("Heartbeat failed "+g.consecutiveHeartbeatFailures+" times, closing connection"),g.ws.close(),g.onClose(),void g.stopHeartbeat();g.heartbeatTimeoutId&&clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=setTimeout(function(){var e;g.consecutiveHeartbeatFailures++,console.warn("Heartbeat timeout, consecutive failures: "+g.consecutiveHeartbeatFailures),g.consecutiveHeartbeatFailures>=g.heartbeatConfig.maxFailures&&(null==(e=g.ws)||e.close(),g.onClose(),g.stopHeartbeat())},g.heartbeatConfig.timeout);var t=JSON.stringify({type:"ping"});g.ws.send("web"===g.platformNamespace?t:{data:t})}else g.heartbeatTimeoutId&&(clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=null)},this.forceHealthCheck=function(e){void 0===e&&(e=!1),g.ws&&g.ws.readyState===Ee.OPEN&&(e&&(g.consecutiveHeartbeatFailures=Math.max(g.heartbeatConfig.maxFailures-1,0)),g.sendPing())},this.handleVisibilityChange=function(){try{"visible"===("undefined"!=typeof document?document.visibilityState:"visible")&&g.forceHealthCheck(!0)}catch(e){}},this.handleOnline=function(){if(!g.ws||g.ws.readyState!==Ee.OPEN)return g.reconnectAttempts=0,g.onReconnecting(),g.connectParams.operationID=ae(),void g.connect().catch(function(){g.onReconnectFailed()});var e=Date.now();g.lastPongAt&&e-g.lastPongAt>g.heartbeatConfig.interval+g.heartbeatConfig.timeout*g.heartbeatConfig.maxFailures&&g.forceHealthCheck(!0)},this.handleOffline=function(){g.stopHeartbeat()},this.installEnvListeners=function(){if(!g.envListenersInstalled&&"web"===g.platformNamespace)try{"undefined"!=typeof document&&document.addEventListener&&document.addEventListener("visibilitychange",g.handleVisibilityChange),"undefined"!=typeof window&&window.addEventListener&&(window.addEventListener("online",g.handleOnline),window.addEventListener("offline",g.handleOffline),window.addEventListener("pageshow",g.handleVisibilityChange),window.addEventListener("focus",g.handleVisibilityChange)),g.envListenersInstalled=!0}catch(e){}},this.removeEnvListeners=function(){if(g.envListenersInstalled&&"web"===g.platformNamespace){try{"undefined"!=typeof document&&document.removeEventListener&&document.removeEventListener("visibilitychange",g.handleVisibilityChange),"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener("online",g.handleOnline),window.removeEventListener("offline",g.handleOffline),window.removeEventListener("pageshow",g.handleVisibilityChange),window.removeEventListener("focus",g.handleVisibilityChange))}catch(e){}g.envListenersInstalled=!1}},this.sendMessage=function(e){var t,n=Oe(JSON.stringify(e));(null==(t=g.ws)?void 0:t.readyState)===Ee.OPEN?g.ws.send("web"===g.platformNamespace?n:{data:Uint8Array.from(n).buffer}):console.error("WebSocket is not open. Message not sent.")},this.close=function(){var e;g.shouldReconnect=!1,g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.heartbeatTimeoutId&&(clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=null),(null==(e=g.ws)?void 0:e.readyState)===Ee.OPEN&&(g.ws.close(),g.onClose()),g.stopHeartbeat(),g.removeEnvListeners()},this.forceReconnect=function(e){if(void 0===e&&(e=!0),g.shouldReconnect=!0,g.reconnectAttempts=0,g.consecutiveHeartbeatFailures=0,e&&(g.forceImmediateReconnect=!0),!g.ws||g.ws.readyState===Ee.CLOSED)return g.onReconnecting(),g.connectParams.operationID=ae(),void g.connect().catch(function(){g.onReconnectFailed()});g.stopHeartbeat();try{g.ws.close()}catch(e){g.onReconnecting(),g.connectParams.operationID=ae(),g.connect().catch(function(){g.onReconnectFailed()})}},this.reset=function(){g.shouldReconnect=!0,g.reconnectAttempts=0,g.consecutiveHeartbeatFailures=0,g.connectTimeoutId&&(clearTimeout(g.connectTimeoutId),g.connectTimeoutId=null),g.heartbeatTimeoutId&&(clearTimeout(g.heartbeatTimeoutId),g.heartbeatTimeoutId=null),g.stopHeartbeat(),g.removeEnvListeners()},this.url=e,this.onMessage=n,this.onClose=r,this.onReconnecting=i,this.onReconnectFailed=o,this.onReconnectSuccess=s,this.reconnectInterval=a,this.maxReconnectAttempts=u,this.connectParams=t,this.reconnectInterval=a,this.maxReconnectAttempts=u,this.reconnectAttempts=0,this.shouldReconnect=!0,this.platformNamespace=this.checkPlatform(),c&&(this.heartbeatConfig=v({},this.heartbeatConfig,c))}return e.prototype.stopHeartbeat=function(){this.heartbeatTimeoutId&&(clearTimeout(this.heartbeatTimeoutId),this.heartbeatTimeoutId=null),this.heartbeatWorker&&(this.heartbeatWorker.postMessage({type:"stop"}),this.heartbeatWorker.terminate(),this.workerUrl&&(URL.revokeObjectURL(this.workerUrl),this.workerUrl=null),this.heartbeatWorker=null),this.legacyTimer&&(clearInterval(this.legacyTimer),this.legacyTimer=null)},e}(),Le=/*#__PURE__*/function(){function e(){this.events=void 0,this.events={}}var t=e.prototype;return t.emit=function(e,t){return this.events[e]&&this.events[e].forEach(function(e){return e(t)}),this},t.on=function(e,t){return this.events[e]?this.events[e].push(t):this.events[e]=[t],this},t.off=function(e,t){if(e&&"function"==typeof t&&this.events[e]){var n=this.events[e];if(!n||0===n.length)return;var r=n.findIndex(function(e){return e===t});-1!==r&&n.splice(r,1)}return this},e}(),je=["friendUser"],xe=["blackUserInfo"],Be=function(e){var t,n,r,i,o,s,a,u,c,d,g,p,l,f;return{createTime:null==(t=e.groupInfo)?void 0:t.createTime,creatorUserID:null==(n=e.groupInfo)?void 0:n.creatorUserID,ex:e.ex,groupFaceURL:null==(r=e.groupInfo)?void 0:r.faceURL,groupID:null==(i=e.groupInfo)?void 0:i.groupID,groupName:null==(o=e.groupInfo)?void 0:o.groupName,groupType:null==(s=e.groupInfo)?void 0:s.groupType,handleResult:e.handleResult,handleUserID:e.handleUserID,handledMsg:e.handleMsg,handledTime:e.handleTime,introduction:null==(a=e.groupInfo)?void 0:a.introduction,memberCount:null==(u=e.groupInfo)?void 0:u.memberCount,nickname:null==(c=e.userInfo)?void 0:c.nickname,notification:null==(d=e.groupInfo)?void 0:d.notification,ownerUserID:null==(g=e.groupInfo)?void 0:g.ownerUserID,reqMsg:e.reqMsg,reqTime:e.reqTime,joinSource:e.joinSource,status:null==(p=e.groupInfo)?void 0:p.status,userFaceURL:null==(l=e.userInfo)?void 0:l.faceURL,userID:null==(f=e.userInfo)?void 0:f.userID}},Ve=function(t){return{clientMsgID:t.clientMsgID,serverMsgID:t.serverMsgID,createTime:t.createTime,sendTime:t.sendTime,sessionType:t.sessionType,sendID:t.sendID,recvID:t.recvID,msgFrom:t.msgFrom,contentType:t.contentType,senderPlatformID:t.senderPlatformID,senderNickname:t.senderNickname,senderFaceUrl:t.senderFaceURL,groupID:t.groupID,content:t.content.length?Ue(t.content):"",seq:t.seq,isRead:t.isRead,status:e.InternalMessageStatus.MsgStatusSendSuccess,isExternalExtensions:!1,offlinePush:t.offlinePushInfo,attachedInfo:t.attachedInfo,ex:t.ex,localEx:""}},_e=function(t){var n=v({},t);try{switch(t.contentType){case e.InternalContentType.Text:n.textElem=JSON.parse(n.content);break;case e.InternalContentType.Picture:n.pictureElem=JSON.parse(n.content);break;case e.InternalContentType.Sound:n.soundElem=JSON.parse(n.content);break;case e.InternalContentType.Video:n.videoElem=JSON.parse(n.content);break;case e.InternalContentType.File:n.fileElem=JSON.parse(n.content);break;case e.InternalContentType.AtText:n.atTextElem=JSON.parse(n.content);break;case e.InternalContentType.Location:n.locationElem=JSON.parse(n.content);break;case e.InternalContentType.Custom:case e.InternalContentType.CustomMsgNotTriggerConversation:case e.InternalContentType.CustomMsgOnlineOnly:n.customElem=JSON.parse(n.content);break;case e.InternalContentType.Typing:n.typingElem=JSON.parse(n.content);break;case e.InternalContentType.Merger:n.mergeElem=JSON.parse(n.content);break;case e.InternalContentType.Face:n.faceElem=JSON.parse(n.content);break;case e.InternalContentType.Quote:n.quoteElem=JSON.parse(n.content);break;case e.InternalContentType.Card:n.cardElem=JSON.parse(n.content);break;default:n.notificationElem=JSON.parse(n.content)}}catch(e){a.default.warn("messageElemFormater messageElem parse failed",n)}if(t.attachedInfo)try{n.attachedInfoElem=JSON.parse(n.attachedInfo),n.attachedInfo=""}catch(e){a.default.warn("messageElemFormater attachedInfoElem failed",n.attachedInfo)}return n.content="",n},He=function(e){var t=Ue(e),n=JSON.parse(t);return JSON.parse(n.detail)},We=function(t,n,r){var i=t.conversation,o=t.group,s=t.friend,a=t.user,u=t.lastMsg,c=t.maxSeq,d=t.readSeq;try{var g,p,l,f,v=function(){var e,t;return{conversationID:i.conversationID,conversationType:i.conversationType,userID:i.userID,groupID:i.groupID,showName:g,faceURL:h,recvMsgOpt:i.recvMsgOpt,unreadCount:c-d,groupAtType:i.groupAtType,latestMsg:m,latestMsgSendTime:null!=(e=null!=(t=null==u?void 0:u.sendTime)?t:r)?e:0,draftText:"",draftTextTime:0,burnDuration:i.burnDuration,msgDestructTime:i.msgDestructTime,isPinned:i.isPinned,isPrivateChat:i.isPrivateChat,isMsgDestruct:i.isMsgDestruct,attachedInfo:i.attachedInfo,ex:i.ex}},h="",m=u?JSON.stringify(_e(Ve(u))):"";(null==i?void 0:i.conversationType)===e.SessionType.Group?(g=null!=(p=null==o?void 0:o.groupName)?p:"",h=null!=(l=null==o?void 0:o.faceURL)?l:""):(g=(null==s?void 0:s.remark)||(null==a?void 0:a.nickname)||"",h=null!=(f=null==a?void 0:a.faceURL)?f:"");var I=function(){if((null==u?void 0:u.status)===e.InternalMessageStatus.MsgStatusHasDeleted)return Promise.resolve(n({conversationID:null==i?void 0:i.conversationID,seq:u.seq,operationID:ae()})).then(function(e){e&&(m=JSON.stringify(_e(e)))})}();return Promise.resolve(I&&I.then?I.then(v):v())}catch(e){return Promise.reject(e)}},Je=function(e){var t=e.friendUser;return v({},y(e,je),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL,attachedInfo:""})},Ke=function(e){var t=e.blackUserInfo;return v({},y(e,xe),{userID:t.userID,nickname:t.nickname,faceURL:t.faceURL})},Qe=/*#__PURE__*/function(){function e(e){var t=this;this.store=void 0,this.options=void 0,this.expiryListeners=[],this.cleanupTimer=void 0,this.options=e,this.store=new Map,this.options.cleanupInterval>0&&(this.cleanupTimer=setInterval(function(){t.deleteExpired()},this.options.cleanupInterval))}var t=e.prototype;return t.onExpiry=function(e){this.expiryListeners.push(e)},t.triggerExpiry=function(e,t){this.expiryListeners.forEach(function(n){return n(e,t)}),this.delete(e)},t.set=function(e,t){var n=this;this.delete(e);var r=Date.now(),i=null;this.options.ttl>0&&(i=setTimeout(function(){clearTimeout(i),n.triggerExpiry(e,t)},this.options.ttl)),this.store.set(e,{value:t,timer:i,created:r})},t.get=function(e){var t=this.store.get(e);if(t&&Date.now()-t.createde.NotificationType.NotificationBegin&&t.contentType(null!=(g=null==m?void 0:m.hasReadCount)?g:0)||h.unreadNum&&h.unreadNum<(null!=(p=null==m?void 0:m.unreadCount)?p:0)){var I,y=v({},l.attachedInfoElem,{groupHasReadInfo:{hasReadCount:h.readNum,unreadCount:h.unreadNum}});s.tryUpdateCachedMessages(n,{clientMsgID:l.clientMsgID,attachedInfo:JSON.stringify(y)});var M=s.getCachedConversation(n),D=JSON.parse(null!=(I=null==M?void 0:M.latestMsg)?I:"{}");D.clientMsgID===l.clientMsgID&&D.seq&&s.instance.messageTrigger.getOneConversationAndTryChange(n,i,{latestMsg:JSON.stringify(v({},D,{attachedInfoElem:y}))}),u.push({clientMsgID:l.clientMsgID,hasReadCount:h.readNum,unreadCount:h.unreadNum,readMembers:[],readUsers:[]}),s.cachedGroupMessageClientMsgIDs.add(l.clientMsgID)}}}u.length>0&&s.instance.triggerEvent({event:e.CbEvents.OnRecvGroupReadReceipt,data:{conversationID:n,groupMessageReadInfo:u},operationID:i})}):Promise.resolve()}catch(e){return Promise.reject(e)}},this.chearGroupMessageClientMsgIDs=function(){return u.cachedGroupMessageClientMsgIDs.clear()},this.addGroupMessageReadUser=function(e,t){var n=u.cachedGroupMessageReadUser.get(e)||[],r=t.filter(function(e){return!n.some(function(t){return t.userID===e.userID})});u.cachedGroupMessageReadUser.set(e,[].concat(n,r))},this.getGroupMessageReadUser=function(e){var t;return null!=(t=u.cachedGroupMessageReadUser.get(e))?t:[]},this.instance=t};function $e(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Ze=function(t){var n=this,r=this,o=this,s=this,u=this;this.instance=void 0,this.defaultPullNums=10,this.SplitPullMsgNum=100,this.syncedConversationVersion=0,this.syncedConversationVersionID="",this.reset=function(){u.syncedConversationVersion=0,u.syncedConversationVersionID=""},this.syncConversationVersion=function(e){try{return Promise.resolve(n.instance.sendHttpRequest({operationID:e,reqFuncName:T.GetConversationVersion,data:{userID:n.instance.userID,version:n.syncedConversationVersion,versionID:n.syncedConversationVersionID}})).then(function(e){n.syncedConversationVersionID&&n.compareVersionAndTrigger(e),n.syncedConversationVersion=e.version,n.syncedConversationVersionID=e.versionID})}catch(e){return Promise.reject(e)}},this.compareVersionAndTrigger=function(e){var t=e.insert,n=e.update;(null!=t?t:[]).map(function(e){return Promise.resolve()}),(null!=n?n:[]).map(function(e){try{return Promise.resolve(u.instance.messageTrigger.getOneConversationAndTryChange(e.conversationID,"",v({},e))).then(function(){})}catch(e){return Promise.reject(e)}})},this.compareSeqsAndBatchSync=function(e,t){try{for(var n=new Map,i=0,o=Object.entries(e);id&&n.set(u,[d+1,c.maxSeq,c.maxSeqTime]):n.set(u,[0,c.maxSeq,c.maxSeqTime])}return r.syncAndTriggerMsgs(n,t),Promise.resolve()}catch(e){return Promise.reject(e)}},this.isNotification=function(e){return e.startsWith("n_")},this.syncAndTriggerMsgs=function(e,t){try{return a.default.debug("Current sync seqMap",e,e.size),Promise.resolve(function(){if(e.size>0){var n=function(n){return $e(function(){return Promise.resolve(o.pullMsgBySeqRange(r,t)).then(function(n){return Promise.resolve(o.instance.messageTrigger.triggerConversation(n.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(n.notificationMsgs,t)).then(function(){for(var t,n=f(e);!(t=n()).done;){var r=t.value,i=r[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:i[1],maxSeqTime:i[2]})}})})})},function(t){throw a.default.error("Sync message from server error",t,e),t})},r=new Map,i=0,s=function(e,t){if("function"==typeof e[rt]){var n,r,i,o=function(e){try{for(;!(n=s.next()).done;)if((e=t(n.value))&&e.then){if(!nt(e))return void e.then(o,i||(i=et.bind(null,r=new tt,2)));e=e.v}r?et(r,1,e):r=e}catch(e){et(r||(r=new tt),2,e)}},s=e[rt]();if(o(),s.return){var a=function(e){try{n.done||s.return()}catch(e){}return e};if(r&&r.then)return r.then(a,function(e){throw a(e)});a()}return r}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],c=0;c=o.SplitPullMsgNum)return $e(function(){return Promise.resolve(o.pullMsgBySeqRange(r,t)).then(function(e){return Promise.resolve(o.instance.messageTrigger.triggerConversation(e.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(e.notificationMsgs,t)).then(function(){for(var e,t=f(r);!(e=t()).done;){var n=e.value,s=n[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(n[0],{maxSeq:s[1],maxSeqTime:s[2]})}r=new Map,i=0})})})},function(e){throw a.default.error("Sync message from server error",e,r),e})}()}var c=s[0],d=s[1],g=s[2],p=d-c+1,l=function(){if(p/o.SplitPullMsgNum>1&&o.isNotification(n)){var e=new Map,r=Math.floor(p/o.SplitPullMsgNum),i=c,s=0,u=0;return function(e,t,n){for(var r;;){var i=e();if(nt(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!nt(o)){r=1;break}o=o.s}if(t){var s=t();if(s&&s.then&&!nt(s)){r=2;break}}}var a=new tt,u=et.bind(null,a,2);return(0===r?i.then(d):1===r?o.then(c):s.then(g)).then(void 0,u),a;function c(r){o=r;do{if(t&&(s=t())&&s.then&&!nt(s))return void s.then(g).then(void 0,u);if(!(i=e())||nt(i)&&!i.v)return void et(a,1,o);if(i.then)return void i.then(d).then(void 0,u);nt(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,u)}function d(e){e?(o=n())&&o.then?o.then(c).then(void 0,u):c(o):et(a,1,o)}function g(){(i=e())?i.then?i.then(d).then(void 0,u):d(i):et(a,1,o)}}(function(){return u<=r},function(){return u++},function(){return u===r?e.set(n,[i,d,g]):((s=i+o.SplitPullMsgNum)>d&&(s=d,u=r),e.set(n,[i,s,g])),$e(function(){return Promise.resolve(o.pullMsgBySeqRange(e,t)).then(function(n){return Promise.resolve(o.instance.messageTrigger.triggerConversation(n.msgs,t)).then(function(){return Promise.resolve(o.instance.messageTrigger.triggerNotification(n.notificationMsgs,t)).then(function(){for(var t,n=f(e);!(t=n()).done;){var r=t.value,a=r[1];o.instance.messageTrigger.cache.updateCachedMaxReadSeq(r[0],{maxSeq:a[1],maxSeqTime:a[2]})}i=s+1})})})},function(t){throw a.default.error("Sync message from server error",t,e),t})})}}();return l&&l.then?l.then(u):u()});return s&&s.then?s.then(n):n()}a.default.debug("Nothing to sync")}())}catch(e){return Promise.reject(e)}},this.pullMsgBySeqRange=function(t,n){try{var r=[].concat(t.entries()).map(function(e){var t=e[1];return{conversationID:e[0],begin:t[0],end:t[1],num:s.defaultPullNums}});a.default.debug("PullMsgBySeqRange with opid: ",n,"seqRanges: ",r);var o=i.PbCoder.PullMessageBySeqsReq.encode({userID:s.instance.userID,seqRanges:r,order:i.SdkWsProto.PullOrder.PullOrderAsc}).finish();return Promise.resolve(s.instance.sendReqWaitResp({operationID:n,data:o,reqIdentifier:e.ReqIdentifier.PullMsgByRange}))}catch(e){return Promise.reject(e)}},this.instance=t};function et(e,t,n){if(!e.s){if(n instanceof tt){if(!n.s)return void(n.o=et.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(et.bind(null,e,t),et.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var tt=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{et(r,1,o(this.v))}catch(e){et(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?et(r,1,t?t(i):i):n?et(r,1,n(i)):et(r,2,i)}catch(e){et(r,2,e)}},r},e}();function nt(e){return e instanceof tt&&1&e.s}var rt="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator",it=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.uint8ArrayToWordArray=function(e){for(var t=[],n=0,r=e.length;n>24&255,t>>16&255,t>>8&255,255&t],u=0;u<4&&ir.version&&(r=s),n.cachedVersionKeys.set(dt(e.conversationID,s.version),s)}return n.cachedVersionKeys.set(gt(e.conversationID),r),[o,r]},o=null,s=0,u=function(e,t,n){for(var r;;){var i=e();if(ct(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!ct(o)){r=1;break}o=o.s}if(t){var s=t();if(s&&s.then&&!ct(s)){r=2;break}}}var a=new ut,u=at.bind(null,a,2);return(0===r?i.then(d):1===r?o.then(c):s.then(g)).then(void 0,u),a;function c(r){o=r;do{if(t&&(s=t())&&s.then&&!ct(s))return void s.then(g).then(void 0,u);if(!(i=e())||ct(i)&&!i.v)return void at(a,1,o);if(i.then)return void i.then(d).then(void 0,u);ct(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,u)}function d(e){e?(o=n())&&o.then?o.then(c).then(void 0,u):c(o):at(a,1,o)}function g(){(i=e())?i.then?i.then(d).then(void 0,u):d(i):at(a,1,o)}}(function(){return!r&&s<10},function(){return s++},function(){var i=ot(function(){return Promise.resolve(n.ctx.sendHttpRequest({reqFuncName:T.GetEncryptionKey,data:v({},e),operationID:t})).then(function(e){o=e.versionKeyList,r=1})},function(t){return a.default.error("getEncryptionKeyFromServer error",t,"conversationID: ",e.conversationID),Promise.resolve(new Promise(function(e){return setTimeout(e,1e3)})).then(function(){})});if(i&&i.then)return i.then(function(){})});return Promise.resolve(u&&u.then?u.then(i):i())}catch(e){return Promise.reject(e)}},this.getMaxVersionKey=function(e,t){try{var n=r.cachedVersionKeys.get(gt(e));return n?Promise.resolve(n):Promise.resolve(r.getEncryptionKeyFromServer({conversationID:e,keyVersion:0},t)).then(function(e){return e[1]})}catch(e){return Promise.reject(e)}},this.getKeyByMessageVersion=function(e,t){try{var n=i.cachedVersionKeys.get(dt(e.conversationID,e.keyVersion));return n?Promise.resolve(n):Promise.resolve(i.getEncryptionKeyFromServer(e,t)).then(function(t){var n=t[0];if(!n.length)throw a.default.error("version key not found, verion: ",e.keyVersion," conversationID: ",e.conversationID),new Error("getKeyByMessageVersion failed");return n[0]})}catch(e){return Promise.reject(e)}},this.encryption=function(e,t,n){try{return o.ctx.serverConfig.isEncryption?Promise.resolve(o.getMaxVersionKey(e,n)).then(function(e){t.content=o.aesEncryptor.encryption(t.content,e.key),t.keyVersion=e.version}):Promise.resolve()}catch(e){return Promise.reject(e)}},this.decryption=function(t,n,r){try{if(!n||0===n.keyVersion)return Promise.resolve();if((n.sessionType===e.SessionType.Single||n.sessionType===e.SessionType.Notification)&&n.recvID!==s.ctx.userID&&n.sendID!==s.ctx.userID)return a.default.warn("maybe message come from app manager",n),Promise.resolve();if(n.contentType===e.MessageType.RevokeMessage||n.status===e.InternalMessageStatus.MsgStatusHasDeleted)return a.default.debug("message is revoke notification or has deleted",n),Promise.resolve();var i=ot(function(){return Promise.resolve(s.getMaxVersionKey(t,r)).then(function(e){n.content=s.aesEncryptor.decryption(n.content,e.key)})},function(e){a.default.warn("decryption with error: ",e,"msgData: ",n)});return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this.ctx=t};function at(e,t,n){if(!e.s){if(n instanceof ut){if(!n.s)return void(n.o=at.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(at.bind(null,e,t),at.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var ut=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{at(r,1,o(this.v))}catch(e){at(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?at(r,1,t?t(i):i):n?at(r,1,n(i)):at(r,2,i)}catch(e){at(r,2,e)}},r},e}();function ct(e){return e instanceof ut&&1&e.s}function dt(e,t){return e+"_v_"+t}function gt(e){return e+"_v_max"}var pt="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function lt(e,t,n){if(!e.s){if(n instanceof ft){if(!n.s)return void(n.o=lt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(lt.bind(null,e,t),lt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var ft=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{lt(r,1,o(this.v))}catch(e){lt(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?lt(r,1,t?t(i):i):n?lt(r,1,n(i)):lt(r,2,i)}catch(e){lt(r,2,e)}},r},e}();function vt(e){return e instanceof ft&&1&e.s}var ht=[e.InternalMessageStatus.MsgStatusHasDeleted,e.InternalMessageStatus.MsgStatusFiltered];function mt(e,t,n){if("function"==typeof e[pt]){var r,i,o,s=function(e){try{for(;!((r=a.next()).done||n&&n());)if((e=t(r.value))&&e.then){if(!vt(e))return void e.then(s,o||(o=lt.bind(null,i=new ft,2)));e=e.v}i?lt(i,1,e):i=e}catch(e){lt(i||(i=new ft),2,e)}},a=e[pt]();if(s(),a.return){var u=function(e){try{r.done||a.return()}catch(e){}return e};if(i&&i.then)return i.then(u,function(e){throw u(e)});u()}return i}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],d=0;d0&&l.instance.triggerEvent({event:e.CbEvents.OnRecvGroupReadReceipt,data:{conversationID:r,groupMessageReadInfo:s},operationID:n})}var s=[],a=mt(t[1],function(e){var t;function i(){var t;if(u&&d){var i=(null==(t=a.readUsers)?void 0:t.map(function(e){return e.userID}))||[],o=JSON.parse(u.attachedInfo||"{}");return o.groupHasReadInfo={hasReadCount:a.hasReadCount,unreadCount:a.unreadCount},l.cache.tryUpdateCachedMessages(r,{clientMsgID:u.clientMsgID,attachedInfo:JSON.stringify(o),isRead:!!i.includes(l.instance.userID)||u.isRead}),c&&l.getOneConversationAndTryChange(r,n,{latestMsg:JSON.stringify(v({},g,{attachedInfoElem:o}))}),Promise.resolve(l.instance.groupTrigger.cache.getGroupMembersMayNotInGroup({groupID:d.groupID,userIDList:i,operationID:n})).then(function(t){s.push({clientMsgID:e,hasReadCount:a.hasReadCount,unreadCount:a.unreadCount,readMembers:t,readUsers:[]})})}}var a=o[e];if(a){var u,c=!1,d=l.cache.getCachedConversation(r),g=JSON.parse(null!=(t=null==d?void 0:d.latestMsg)?t:"{}"),p=function(){if(g.clientMsgID===e&&g.seq)return c=!0,Promise.resolve(l.getMessageWithCacheBySeqs(r,[g.seq],n)).then(function(e){u=e.messages[0]});u=l.cache.getCachedMessageByClientMsgIDs(r,[e])[0]}();return p&&p.then?p.then(i):i()}});return a&&a.then?a.then(i):i()});return Promise.resolve(c&&c.then?c.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},this.triggerNotification=function(t,n){try{for(var r=0,i=Object.entries(t);re.NotificationType.FriendNotificationBegin&&t.contentTypee.NotificationType.UserNotificationBegin&&t.contentTypee.NotificationType.GroupNotificationBegin&&t.contentTypee.NotificationType.SignalingNotificationBegin&&t.contentType0){if(!i)return void u.map(function(e){I.cache.tryUpdateCachedMessages(ce(e),e)});I.instance.triggerEvent({event:e.CbEvents.OnRecvNewMessages,data:u.map(_e),operationID:n})}};if(0===Object.keys(t).length)return Promise.resolve();a.default.debug("Trigger conversation",t);var i=!0;I.triggeredConversationEvent.has(n)&&(I.triggeredConversationEvent.delete(n),i=!1);var o=!1,s=I.cache.getTotalUnreadCount(),u=[],c=mt(Object.entries(t),function(t){var r=t[0],c=t[1].Msgs.map(function(t){var c,d,g,p,l=!I.cache.getCachedMaxReadSeq(r),f=t.sendID===I.instance.userID,v=ge(t.options,e.MessageOptionsKey.IsUnreadCount)&&!f,h=ge(t.options,e.MessageOptionsKey.IsConversationUpdate),m=ge(t.options,e.MessageOptionsKey.IsNotPrivate);if(t.clientMsgID&&r){var y=Ve(t),M=_e(y);if(M.attachedInfoElem=t.attachedInfo?JSON.parse(t.attachedInfo):{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},t.status!==e.InternalMessageStatus.MsgStatusHasDeleted){t.contentType===e.InternalContentType.Typing&&I.triggerTyping(M),M.status=e.InternalMessageStatus.MsgStatusSendSuccess,y.status=e.InternalMessageStatus.MsgStatusSendSuccess,l&&I.cache.addCachedMaxReadSeq(r,{hasReadSeq:f?t.seq:t.seq-1,maxSeq:t.seq,maxSeqTime:t.sendTime}),m||(M.attachedInfoElem.isPrivateChat=!0),h&&(s+=v?1:0,I.cache.updateCachedMaxReadSeq(r,{maxSeqTime:M.sendTime}),i&&I.getOneConversationAndTryChange(r,n,{latestMsg:JSON.stringify(M),latestMsgSendTime:M.sendTime},v,l),u.push(y),I.cache.addMessagesToCache(r,[y]));var D=null!=(c=null==(d=I.cache.getCachedMaxReadSeq(r))?void 0:d.maxSeq)?c:0,S=null!=(g=null==(p=I.cache.getCachedMaxReadSeq(r))?void 0:p.hasReadSeq)?g:0;a.default.debug("currentMaxSeq",D,"currentHasReadSeq",S),M.seq>D&&(o=l||!I.cache.isNotNotifyConversation(r),I.cache.updateCachedMaxReadSeq(r,{maxSeq:D+1,maxSeqTime:M.sendTime}),f&&(I.cache.updateCachedMaxReadSeq(r,{hasReadSeq:S+1}),I.cache.tryUpdateCachedMessages(r,{clientMsgID:M.clientMsgID,seq:M.seq})))}}});return Promise.resolve(Promise.all(c)).then(function(){})});return Promise.resolve(c&&c.then?c.then(r):r())}catch(e){return Promise.reject(e)}},this.instance=t,this.cache=new Xe(t),this.encryptor=new st(t),this.syncer=new Ze(t),this.typingManager=new Ye(t)},yt=/*#__PURE__*/function(){function t(t){var n=this,r=this,i=this,o=this,s=this;this.instance=void 0,this.cachedGroups=new Map,this.cachedGroupMembers=new Map,this.cachedGroupMembersID=new Map,this.getGroupMembersID=function(e,t){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:T.GetFullGroupMemberUserIDs,data:{groupID:e,idHash:0},operationID:t})).then(function(t){r.cachedGroupMembersID.set(e,t.userIDs)})}catch(e){return Promise.reject(e)}},this.getGroupInfosWithCache=function(t,n){try{var r=[],o=[];return t.forEach(function(e){var t=i.cachedGroups.get(e);t?r.push(t):o.push(e)}),o.length?Promise.resolve(i.instance.sendHttpRequest({reqFuncName:e.RequestApi.GetSpecifiedGroupsInfo,data:{groupIDs:o},operationID:n})).then(function(e){var t=e.groupInfos;return t&&t.forEach(function(e){return i.cachedGroups.set(e.groupID,e)}),[].concat(r,null!=t?t:[])}):Promise.resolve(r)}catch(e){return Promise.reject(e)}},this.getGroupMembersWithCache=function(t){var n=t.groupID,r=t.userIDList,i=t.operationID;try{var s,a,u=null!=(s=o.cachedGroupMembers.get(n))?s:[],c=function(){if(null!=r&&r.length){var t=[],s=[];return r.forEach(function(e){var n=u.find(function(t){return t.userID===e});n?s.push(n):t.push(e)}),t.length?Promise.resolve(o.instance.sendHttpRequest({reqFuncName:e.RequestApi.GetSpecifiedGroupMembersInfo,data:{groupID:n,userIDs:t},operationID:i})).then(function(e){var t=e.members;t&&o.cachedGroupMembers.set(n,[].concat(u,t));var r=[].concat(s,null!=t?t:[]);return a=1,r}):(a=1,s)}}();return Promise.resolve(c&&c.then?c.then(function(e){return a?e:u}):a?c:u)}catch(e){return Promise.reject(e)}},this.getGroupMembersMayNotInGroup=function(e){try{return Promise.resolve(s.getGroupMembersWithCache(e)).then(function(t){var n=e.userIDList.filter(function(e){return!t.find(function(t){return t.userID===e})}),r=function(){if(n.length)return Promise.resolve(s.instance.getUsersInfo(n,operationID)).then(function(e){t.push.apply(t,e.data.map(function(e){return{userID:e.userID,nickname:e.nickname,faceURL:e.faceURL}}))})}();return r&&r.then?r.then(function(){return t}):t})}catch(e){return Promise.reject(e)}},this.updateCachedGroups=function(e){e.map(function(e){n.cachedGroups.set(e.groupID,e)})},this.updateCachedGroupMembers=function(e){var t,r=e[0].groupID,i=null!=(t=n.cachedGroupMembers.get(r))?t:[];n.cachedGroupMembers.set(r,[].concat(i.filter(function(t){return!e.find(function(e){return e.userID===t.userID})}),e));var o=n.instance.messageTrigger.cache.getAllCachedConversations().find(function(t){return t.groupID===e[0].groupID}),s=JSON.parse((null==o?void 0:o.latestMsg)||"{}"),a=e.find(function(e){return e.userID===s.sendID&&e.nickname!==s.senderNickname});o&&a&&n.instance.messageTrigger.getOneConversationAndTryChange(o.conversationID,"",{latestMsg:JSON.stringify(v({},s,{senderNickname:a.nickname}))})},this.clearCachedGroupMembers=function(e){n.cachedGroupMembers.delete(e)},this.hasCachedGroupMembersID=function(e){return n.cachedGroupMembersID.has(e)},this.getCachedGroupMembersID=function(e){var t;return null!=(t=n.cachedGroupMembersID.get(e))?t:[]},this.tryAddCachedGroupMembersID=function(e,t){if(n.cachedGroupMembersID.has(e)){var r,i=null!=(r=n.cachedGroupMembersID.get(e))?r:[];n.cachedGroupMembersID.set(e,[].concat(i,t))}},this.tryDeleteCachedGroupMembersID=function(e,t){if(n.cachedGroupMembersID.has(e)){var r,i=null!=(r=n.cachedGroupMembersID.get(e))?r:[];n.cachedGroupMembersID.set(e,i.filter(function(e){return!t.includes(e)}))}},this.instance=t}return t.prototype.clear=function(){this.cachedGroups.clear(),this.cachedGroupMembers.clear(),this.cachedGroupMembersID.clear()},t}(),Mt=/*#__PURE__*/function(){function t(t){var n=this,r=this,i=this,o=this;this.instance=void 0,this.syncedGroupsVersion=0,this.syncedGroupsVersionID="",this.syncedGroupMemberVersion={},this.syncGroupVersion=function(e){try{return Promise.resolve(r.instance.sendHttpRequest({reqFuncName:T.GetGroupVersion,data:{userID:r.instance.userID,version:r.syncedGroupsVersion,versionID:r.syncedGroupsVersionID},operationID:e})).then(function(t){r.syncedGroupsVersionID&&r.compareGroupVersionAndTrigger(t,e),r.syncedGroupsVersion=t.version,r.syncedGroupsVersionID=t.versionID})}catch(e){return Promise.reject(e)}},this.syncGroupInfoAndMemberVersion=function(e){try{var t=function(){if(n.length)return Promise.resolve(i.instance.sendHttpRequest({reqFuncName:T.GetGroupMemberVersion,data:{userID:i.instance.userID,reqList:n},operationID:e})).then(function(t){var n=t.respList;Object.keys(i.syncedGroupMemberVersion).length>0&&i.compareGroupMemberVersionAndTrigger(n,e),i.syncedGroupMemberVersion=n;for(var r=0,o=Object.entries(n);r0},0,function(){var e=t.queue.shift()[0],n=function(t,n){try{var r=Promise.resolve(e()).then(function(){})}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(0,function(e){a.default.error("Error executing task:",e)});if(n&&n.then)return n.then(function(){})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(e){return Promise.reject(e)}},t}();function Bt(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Vt=((jt={})[e.MessageType.TextMessage]="textElem",jt[e.MessageType.AtTextMessage]="atTextElem",jt[e.MessageType.LocationMessage]="locationElem",jt[e.MessageType.CustomMessage]="customElem",jt[e.MessageType.MergeMessage]="mergeElem",jt[e.MessageType.QuoteMessage]="quoteElem",jt[e.MessageType.CardMessage]="cardElem",jt[e.MessageType.FaceMessage]="faceElem",jt[e.MessageType.PictureMessage]="pictureElem",jt[e.MessageType.VoiceMessage]="soundElem",jt[e.MessageType.VideoMessage]="videoElem",jt[e.MessageType.FileMessage]="fileElem",jt),_t=[e.MessageType.PictureMessage,e.MessageType.VoiceMessage,e.MessageType.VideoMessage,e.MessageType.FileMessage],Ht=/*#__PURE__*/function(e){function t(t,n){var r;return(r=e.call(this,n)||this).status=void 0,r.name="HttpError",r.status=t,r}return m(t,e),t}(/*#__PURE__*/D(Error));function Wt(e,t,n){if(!e.s){if(n instanceof Jt){if(!n.s)return void(n.o=Wt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Wt.bind(null,e,t),Wt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Jt=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{Wt(r,1,o(this.v))}catch(e){Wt(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?Wt(r,1,t?t(i):i):n?Wt(r,1,n(i)):Wt(r,2,i)}catch(e){Wt(r,2,e)}},r},e}();function Kt(e){return e instanceof Jt&&1&e.s}function Qt(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var zt=[T.GetActiveConversations,T.GetDesignatedConversation];function Yt(e,t,n){if(!e.s){if(n instanceof $t){if(!n.s)return void(n.o=Yt.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Yt.bind(null,e,t),Yt.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Xt=/*#__PURE__*/function(t){function n(){var n,o;return(n=t.call(this)||this).userID=void 0,n.platform=void 0,n.token=void 0,n.apiAddr=void 0,n.loginStatus=e.LoginStatus.Logout,n.isReconnected=!1,n.serverConfig={isEncryption:!1},n.connectState="disconnected",n.wsManager=void 0,n.messageTrigger=void 0,n.userTrigger=void 0,n.groupTrigger=void 0,n.relationTrigger=void 0,n.businessTrigger=void 0,n.signalingTrigger=void 0,n.requestMap=new Map,n.generateHttpHeader=function(e,t){var r={"Content-Type":"application/json",token:n.token,operationID:t,reqFuncName:e};return zt.includes(e)&&(r["Content-Type"]="application/x-protobuf"),r},n.sendHttpRequest=function(e){try{var t;return Promise.resolve(function(e,t){void 0===t&&(t={});var n=e.url,r=e.data,i=e.headers,o=e.platform,s=e.method,a=void 0===s?"POST":s,u=t.retries,c=void 0===u?3:u,d=t.baseDelayMs,g=void 0===d?300:d,p=t.maxDelayMs,l=void 0===p?3e3:p;return function(t){try{var s=0;return Promise.resolve(function(e,t,n){for(var r;;){var i=e();if(Kt(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!Kt(o)){r=1;break}o=o.s}}var s=new Jt,a=Wt.bind(null,s,2);return(0===r?i.then(c):1===r?o.then(u):(void 0).then(function(){(i=e())?i.then?i.then(c).then(void 0,a):c(i):Wt(s,1,o)})).then(void 0,a),s;function u(t){o=t;do{if(!(i=e())||Kt(i)&&!i.v)return void Wt(s,1,o);if(i.then)return void i.then(c).then(void 0,a);Kt(o=n())&&(o=o.v)}while(!o||!o.then);o.then(u).then(void 0,a)}function c(e){e?(o=n())&&o.then?o.then(u).then(void 0,a):u(o):Wt(s,1,o)}}(function(){return!t},0,function(){return function(s,u){try{var c=Promise.resolve("web"===o?function(e){var t=e.url,n=e.data,r=e.headers,i=e.method,o=void 0===i?"POST":i;try{return Promise.resolve(fetch(t,{method:o,headers:v({},r),body:n instanceof Uint8Array?n:JSON.stringify(n)}).then(function(e){if(e.ok)return e.json();throw new Ht(e.status,e.statusText||"HTTP_"+e.status)}).then(function(e){if(0!==e.errCode)throw new Error(e.errMsg);return e.data}))}catch(e){return Promise.reject(e)}}(e):new Promise(function(e,t){var s=function(e){return"uni"===e?uni.request.bind(uni):"wx"===e?wx.request.bind(wx):"my"===e?(my.request||my.httpRequest).bind(my):null}(o);s?s({url:n,data:r instanceof Uint8Array?Uint8Array.from(r).buffer:r,method:a,header:v({"Content-Type":"application/json"},i),success:function(n){200===n.statusCode&&0===n.data.errCode?e(n.data.data):t({statusCode:n.statusCode,data:n.data})},fail:function(e){t(e)}}):t(new Error("Request is not supported"))})).then(function(e){return t=1,e})}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(++s>c||!function(e){if(!e)return!1;if(e instanceof Ht)return e.status>=500;if("object"==typeof e&&"number"==typeof e.statusCode)return e.statusCode>=500;var t=String((null==e?void 0:e.message)||e||"").toLowerCase();return!!(t.includes("network")||t.includes("timeout")||t.includes("failed to fetch")||t.includes("request:fail"))}(e))throw e;var t,n=Math.min(g*Math.pow(2,s-1),l),r=Math.floor(150*Math.random());return Promise.resolve((t=n+r,new Promise(function(e){return setTimeout(e,t)}))).then(function(){})})}))}catch(e){return Promise.reject(e)}}()}({url:""+n.apiAddr+(e.replaceURL||j[e.reqFuncName]),data:e.data,headers:n.generateHttpHeader(e.reqFuncName,e.operationID),platform:(null==(t=n.wsManager)?void 0:t.platformNamespace)||"web"}))}catch(e){return Promise.reject(e)}},n.handleWsConnected=function(t,r){try{var i=function(){if(0===t.errCode){n.connectState="connected",n.loginStatus=e.LoginStatus.Logged,n.triggerEvent({event:e.CbEvents.OnConnectSuccess}),n.triggerEvent({event:e.CbEvents.OnSyncServerStart});var i=[n.messageTrigger.sync(r),n.relationTrigger.sync(r),n.groupTrigger.sync(r),n.userTrigger.sync(r)],o=Qt(function(){return Promise.resolve(Promise.all(i)).then(function(){n.triggerEvent({event:e.CbEvents.OnSyncServerFinish})})},function(t){a.default.error(t),n.triggerEvent({event:e.CbEvents.OnSyncServerFailed,errCode:t.errCode||e.ErrorCode.SdkInternalError,errMsg:t.message||"Internal Error"})});if(o&&o.then)return o.then(function(){})}else{n.triggerEvent({event:e.CbEvents.OnConnectFailed,errCode:t.errCode,errMsg:t.errMsg,operationID:r});var s=se[t.errCode];s&&n.triggerEvent({event:s,errCode:t.errCode,errMsg:t.errMsg,operationID:r}),n.connectState="disconnected",n.loginStatus=e.LoginStatus.Logout}}();return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},n.handleMessage=function(e,t){try{var r=function(){if("string"!=typeof e){var r=function(){var t,r,i=(t=e,r=new DataView(t),we.getString(r,0,t.byteLength,"UTF-8")),o=JSON.parse(i);n.handleGeneralWsResp(o)},i=function(){if(!(e instanceof ArrayBuffer))return Promise.resolve(e.arrayBuffer()).then(function(t){e=t})}();return i&&i.then?i.then(r):r()}var o=JSON.parse(e);n.handleWsConnected(o,t)}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},n.handleGeneralWsResp=function(t){var r=le(t.data,t.reqIdentifier);if(t.reqIdentifier===e.ReqIdentifier.PushMsg&&r)return n.messageTrigger.triggerConversation(r.msgs,t.operationID),void n.messageTrigger.triggerNotification(r.notificationMsgs,t.operationID);if(t.reqIdentifier!==e.ReqIdentifier.WsSubUserOnlineStatus||t.msgIncr||n.userTrigger.onlineSub.userOnlineStateChange(r),t.reqIdentifier===e.ReqIdentifier.WSServerConfigMsg&&r&&(n.serverConfig=r),t.reqIdentifier===e.ReqIdentifier.KickOnlineMsg)return n.triggerEvent({event:e.CbEvents.OnKickedOffline,operationID:t.operationID}),void n.reset();var i=n.requestMap.get(t.msgIncr);i&&(0===t.errCode?i.resolve(r):i.reject(new he(t.errCode,t.errMsg)),n.requestMap.delete(t.msgIncr))},n.handleReconnecting=function(){n.connectState="reconnecting",n.triggerEvent({event:e.CbEvents.OnConnecting})},n.handleReconnectFailed=function(){n.connectState="disconnected",n.triggerEvent({event:e.CbEvents.OnConnectFailed,errCode:e.ErrorCode.NetworkError,errMsg:"network error"}),n.cancelMessageTasks()},n.handleReconnectSuccess=function(){n.isReconnected=!0,n.messageTrigger.cache.chearGroupMessageClientMsgIDs()},n.sendReqWaitResp=function(t){var i=t.data,o=t.reqIdentifier,s=t.operationID;if("connected"!==n.connectState)throw new he(e.ErrorCode.NetworkError,"network error, ws not connected");var a=ae();return new Promise(function(e,t){var u;n.requestMap.set(a,{resolve:e,reject:t}),null==(u=n.wsManager)||u.sendMessage({reqIdentifier:o,msgIncr:a,sendID:n.userID,operationID:s,data:r.encode(i.buffer)})})},n.triggerEvent=function(t){var r=t.event,i=t.data,o=void 0===i?null:i,s=t.errCode,u=void 0===s?0:s,c=t.errMsg,d=void 0===c?"":c,g=t.operationID,p=void 0===g?"":g;n.loginStatus!==e.LoginStatus.Logout&&(a.default.debug("%cSDK =>%c [OperationID:"+p+"] (event) trigger "+r+" with data "+JSON.stringify(o)+" errCode "+u+" errMsg "+d,"font-size:14px; background:#6F42C1; border-radius:4px; padding-inline:4px;",""),n.emit(r,{event:r,data:o,errCode:u,errMsg:d,operationID:p}))},n.login=function(t,r){try{return Promise.resolve(me(e.LoginStatus.Logged,e.RequestApi.Login,r,function(){try{var i,o=t.userID,s=t.token,u=t.wsAddr,c=t.apiAddr,d=t.platformID;if(n.wsManager)throw new he(e.ErrorCode.LoginRepeatError,"login repeat");return a.default.setLevel(null!=(i=t.logLevel)?i:e.LogLevel.Debug),n.userID=o,n.token=s,n.apiAddr=c,n.platform=d,n.wsManager=new ke(u,{sendID:o,token:s,platformID:d,operationID:r,isBackground:!1,isMsgResp:!0,sdkType:"js"},n.handleMessage,n.handleReconnectFailed,n.handleReconnecting,n.handleReconnectFailed,n.handleReconnectSuccess),n.connectState="connecting",n.loginStatus=e.LoginStatus.Logging,n.triggerEvent({event:e.CbEvents.OnConnecting,operationID:r}),Promise.resolve(Qt(function(){return Promise.resolve(n.wsManager.connect()).then(function(){})},function(t){throw n.triggerEvent({event:e.CbEvents.OnConnectFailed,errCode:e.ErrorCode.NetworkError,errMsg:t.message||"network error",operationID:r}),n.connectState="disconnected",n.loginStatus=e.LoginStatus.Logout,n.wsManager.close(),new he(e.ErrorCode.NetworkError,t.message||"network error")}))}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},n.getLoginStatus=function(t){return me(e.LoginStatus.Logged,e.RequestApi.GetLoginStatus,t,function(){try{var e;return null==(e=n.wsManager)||e.sendPing(),Promise.resolve(n.loginStatus)}catch(e){return Promise.reject(e)}})},n.forceReconnect=function(t){return me(n.loginStatus,e.RequestApi.ForceReconnect,t,function(){try{var e;return null==(e=n.wsManager)||e.forceReconnect(!0),Promise.resolve()}catch(e){return Promise.reject(e)}})},n.logout=function(t){return me(n.loginStatus,e.RequestApi.Logout,t,function(){try{return n.reset(),Promise.resolve()}catch(e){return Promise.reject(e)}})},n.internalUploadFile=function(e,t,r){return Promise.resolve(Qt(function(){var i=n.userID+"/"+e.name,o=function(e){var t,n,r=null!=(t=null==(n=e.split(".").pop())?void 0:n.toLowerCase())?t:"";return R[r]||"application/octet-stream"}(e.name),s={operationID:t,token:n.token};return Promise.resolve(function(e,t,n){return fetch(e+"/object/part_size",{method:"POST",headers:v({},n),body:JSON.stringify({size:t})}).then(b)}(n.apiAddr,e.size,s)).then(function(t){var a=t.size;function c(){var t=p.join(","),c=new u.default;return c.append(t),Promise.resolve(function(e,t,n){return fetch(e+"/object/initiate_multipart_upload",{method:"POST",headers:v({},n),body:JSON.stringify(t)}).then(b)}(n.apiAddr,{hash:c.end(),size:e.size,partSize:a,maxParts:-1,cause:"",name:i,contentType:o},s)).then(function(t){var a=t.url,u=t.upload;if(c.destroy(),a)return null==r||r(100),{url:a};var d=u.sign.parts,l=u.sign.query,f=u.sign.header,h=e.size,m=0;null==r||r(0);for(var I=0,y=[],M=function(){try{var t=en(function(){return I=3)throw new Error("Failed to upload chunk "+(t+1)+" after 3 attempts: "+e.message);var n,r=400*Math.pow(2,y-1),i=Math.floor(150*Math.random());return Promise.resolve((n=r+i,new Promise(function(e){return setTimeout(e,n)}))).then(function(){})})}))}catch(e){return Promise.reject(e)}}(t)).then(function(){})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},D=Math.min(4,d.length),S=0;Sp?g:p,count:r-t.length,conversationID:i,operationID:o,fetchedMessages:c})}return c}):Promise.resolve(a)}catch(e){return Promise.reject(e)}};return{createTextMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateTextMessage,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.TextMessage);return r.textElem={content:n},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createTextAtMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateTextAtMessage,r,function(){try{var r;if(!n.text)throw new he(e.ErrorCode.ArgsError,"text cannot be empty");if(n.atUserIDList.length>10)throw new he(e.ErrorCode.ArgsError,"atUserIDList length must be less than 10");var i,o=fe(t,e.MsgFrom.UserMsgType,e.MessageType.AtTextMessage);return(null==(r=n.message)?void 0:r.contentType)===e.MessageType.QuoteMessage&&(n.message.contentType=e.MessageType.TextMessage,n.message.textElem={content:null==(i=n.message.quoteElem)?void 0:i.text}),o.atTextElem={text:n.text,atUserList:n.atUserIDList,atUsersInfo:n.atUsersInfo,quoteMessage:n.message},Promise.resolve(o)}catch(e){return Promise.reject(e)}})},createLocationMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateLocationMessage,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.LocationMessage);return r.locationElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createCustomMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateCustomMessage,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.CustomMessage);return r.customElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createQuoteMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateQuoteMessage,r,function(){try{var r,i=fe(t,e.MsgFrom.UserMsgType,e.MessageType.QuoteMessage),o=JSON.parse(n.message);return o.contentType===e.MessageType.QuoteMessage&&(o.contentType=e.MessageType.TextMessage,o.textElem={content:null==(r=o.quoteElem)?void 0:r.text}),i.quoteElem={text:n.text,quoteMessage:o},Promise.resolve(i)}catch(e){return Promise.reject(e)}})},createCardMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateCardMessage,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.CardMessage);return r.cardElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByURL:function(n,r){return me(t.loginStatus,e.RequestApi.CreateImageMessageByURL,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.PictureMessage);return r.pictureElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createImageMessageByFile:function(r,i){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.CreateImageMessageByFile,i,function(){try{var i=fe(t,e.MsgFrom.UserMsgType,e.MessageType.PictureMessage);return n.set(r.sourcePicture.uuid,r.file),delete r.file,i.pictureElem=v({},r),Promise.resolve(i)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createSoundMessageByURL:function(n,r){return me(t.loginStatus,e.RequestApi.CreateSoundMessageByURL,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.VoiceMessage);return r.soundElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createSoundMessageByFile:function(r,i){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.CreateSoundMessageByFile,i,function(){try{var i=fe(t,e.MsgFrom.UserMsgType,e.MessageType.VoiceMessage);return n.set(r.uuid,r.file),delete r.file,i.soundElem=v({},r),Promise.resolve(i)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createVideoMessageByURL:function(n,r){return me(t.loginStatus,e.RequestApi.CreateVideoMessageByURL,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.VideoMessage);return r.videoElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createVideoMessageByFile:function(r,i){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.CreateVideoMessageByFile,i,function(){try{var i=fe(t,e.MsgFrom.UserMsgType,e.MessageType.VideoMessage);return n.set(r.videoUUID,r.videoFile),n.set(r.snapshotUUID,r.snapshotFile),delete r.videoFile,delete r.snapshotFile,i.videoElem=v({},r),Promise.resolve(i)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createFileMessageByURL:function(n,r){return me(t.loginStatus,e.RequestApi.CreateFileMessageByURL,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.FileMessage);return r.fileElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFileMessageByFile:function(r,i){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.CreateFileMessageByFile,i,function(){try{var i=fe(t,e.MsgFrom.UserMsgType,e.MessageType.FileMessage);return n.set(r.uuid,r.file),delete r.file,i.fileElem=v({},r),Promise.resolve(i)}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},createMergerMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateMergerMessage,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.MergeMessage);return r.mergeElem={title:n.title,abstractList:n.summaryList,multiMessage:n.messageList,messageEntityList:[]},Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createFaceMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateFaceMessage,r,function(){try{var r=fe(t,e.MsgFrom.UserMsgType,e.MessageType.FaceMessage);return r.faceElem=v({},n),Promise.resolve(r)}catch(e){return Promise.reject(e)}})},createForwardMessage:function(n,r){return me(t.loginStatus,e.RequestApi.CreateForwardMessage,r,function(){try{if(n.status!==e.MessageStatus.Succeed)throw new he(e.ErrorCode.ArgsError,"Only successfully sent messages can be forwarded");var r=fe(t,e.MsgFrom.UserMsgType,n.contentType);return Promise.resolve(v({},n,r,{seq:0,status:e.MessageStatus.Sending}))}catch(e){return Promise.reject(e)}})},sendMessage:function(s,a){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.SendMessage,a,function(){var u=function(){try{var r=v({},s,{message:v({},s.message)}),o=r.message,u=r.recvID,c=r.groupID,d=r.isOnlineOnly,g=r.offlinePushInfo,p=void 0===g?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:g;void 0===p.signalInfo&&(p.signalInfo="");var l=Vt[o.contentType];if(!l)throw new he(e.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");o.recvID=u,o.groupID=c,o.sessionType=c?e.SessionType.Group:e.SessionType.Single;var f={};d&&Object.values(e.MessageOptionsKey).forEach(function(e){return f[e]=!1});var h=ce(o),m=!1;return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(h,a)).then(function(r){function s(){function s(s){function d(s){function d(s){function d(s){function d(n){var s,d,g=JSON.stringify(o[l]),v={sendID:t.userID,recvID:u||"",groupID:c||"",clientMsgID:o.clientMsgID,serverMsgID:o.serverMsgID||"",senderPlatformID:t.platform,senderNickname:o.senderNickname,senderFaceURL:o.senderFaceUrl,sessionType:o.sessionType,msgFrom:o.msgFrom,contentType:o.contentType,content:Oe(g),seq:o.seq,sendTime:0,createTime:o.createTime,status:o.status,isRead:!1,options:f,offlinePushInfo:p,atUserIDList:null!=(s=null==(d=o.atTextElem)?void 0:d.atUserList)?s:[],attachedInfo:o.attachedInfoElem?JSON.stringify(o.attachedInfoElem):"",ex:o.ex||"",dstUserIDs:[],keyVersion:0};return Promise.resolve(t.messageTrigger.encryptor.encryption(h,v,a)).then(function(){var n=i.PbCoder.MsgData.encode(v).finish();return Bt(function(){return Promise.resolve(t.sendReqWaitResp({data:n,operationID:a,reqIdentifier:e.ReqIdentifier.SendMsg})).then(function(n){var i=n.serverMsgID,s=n.sendTime;return o.sendTime=s,o.serverMsgID=i,o.status=e.MessageStatus.Succeed,t.messageTrigger.setTriggeredConversationEvent(a),t.messageTrigger.cache.updateCachedMaxReadSeq(r.conversationID,{maxSeqTime:s}),t.messageTrigger.getOneConversationAndTryChange(h,a,{latestMsg:JSON.stringify(o),latestMsgSendTime:s}),o})},function(n){throw o.status=e.MessageStatus.Failed,t.messageTrigger.getOneConversationAndTryChange(h,a,{latestMsg:JSON.stringify(o)}),n})})}var g=function(){if(o.contentType===e.MessageType.FileMessage){var r,i=n.get(null==(r=o.fileElem)?void 0:r.uuid);if(!i)throw new he(e.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(i,a,function(n){return t.triggerEvent({event:e.CbEvents.OnProgress,data:{progress:n,clientMsgID:o.clientMsgID},operationID:a})})).then(function(t){var r,i=t.url,s=void 0===i?"":i,a=t.error;if(n.delete(null==(r=o.fileElem)?void 0:r.uuid),a)throw new he(e.ErrorCode.NetworkError,"Upload file failed");o.fileElem.sourceUrl=s})}}();return g&&g.then?g.then(d):d()}var g=function(){if(o.contentType===e.MessageType.VideoMessage){var r,i,s=n.get(null==(r=o.videoElem)?void 0:r.videoUUID),u=n.get(null==(i=o.videoElem)?void 0:i.snapshotUUID);if(!s||!u)throw new he(e.ErrorCode.ArgsError,"Can not find target file");var c=0,d=0,g=s.size,p=u.size,l=g+p,f=function(){t.triggerEvent({event:e.CbEvents.OnProgress,data:{progress:(c*g+d*p)/l,clientMsgID:o.clientMsgID},operationID:a})};return Promise.resolve(Promise.all([t.internalUploadFile(s,a,function(e){c=e,f()}),t.internalUploadFile(u,a,function(e){d=e,f()})])).then(function(t){var r,i;if(n.delete(null==(r=o.videoElem)?void 0:r.videoUUID),n.delete(null==(i=o.videoElem)?void 0:i.snapshotUUID),t[0].error||t[1].error)throw new he(e.ErrorCode.NetworkError,"Upload file failed");o.videoElem.videoUrl=t[0].url,o.videoElem.snapshotUrl=t[1].url})}}();return g&&g.then?g.then(d):d()}var g=function(){if(o.contentType===e.MessageType.VoiceMessage){var r,i=n.get(null==(r=o.soundElem)?void 0:r.uuid);if(!i)throw new he(e.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(i,a,function(n){return t.triggerEvent({event:e.CbEvents.OnProgress,data:{progress:n,clientMsgID:o.clientMsgID},operationID:a})})).then(function(t){var r,i=t.url,s=void 0===i?"":i,a=t.error;if(n.delete(null==(r=o.soundElem)?void 0:r.uuid),a)throw new he(e.ErrorCode.NetworkError,"Upload file failed");o.soundElem.sourceUrl=s})}}();return g&&g.then?g.then(d):d()}r.latestMsgSendTime=o.createTime,t.messageTrigger.getOneConversationAndTryChange(h,a,{latestMsg:JSON.stringify(o)},void 0,m);var g=function(){if(o.contentType===e.MessageType.PictureMessage){var r,i=n.get(null==(r=o.pictureElem)?void 0:r.sourcePicture.uuid);if(!i)throw new he(e.ErrorCode.ArgsError,"Can not find target file");return Promise.resolve(t.internalUploadFile(i,a,function(n){return t.triggerEvent({event:e.CbEvents.OnProgress,data:{progress:n,clientMsgID:o.clientMsgID},operationID:a})})).then(function(t){var r,i=t.url,s=void 0===i?"":i,a=t.error;if(n.delete(null==(r=o.pictureElem)?void 0:r.sourcePicture.uuid),a)throw new he(e.ErrorCode.NetworkError,"Upload file failed");o.pictureElem.sourcePicture.url=s,o.pictureElem.bigPicture.url=s,o.pictureElem.snapshotPicture.width=640,o.pictureElem.snapshotPicture.height=640,o.pictureElem.snapshotPicture.url=s+"?type=image&width=640&height=640"})}}();return g&&g.then?g.then(d):d()}var d=function(){if(c)return Promise.resolve(t.groupTrigger.cache.getGroupInfosWithCache([c],a)).then(function(n){return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:c,userIDList:[t.userID],operationID:a})).then(function(t){if(null==t||!t.length)throw new he(e.ErrorCode.ArgsError,"user not join target group");t[0].nickname&&(o.senderNickname=t[0].nickname),o.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},o.attachedInfoElem.groupHasReadInfo.unreadCount=n[0].memberCount-1})})}();return d&&d.then?d.then(s):s()}var d=function(){if(!r)return m=!0,Promise.resolve(t.messageTrigger.initConversation({sourceID:c||u,sessionType:o.sessionType,operationID:a})).then(function(e){r=e});r.isPrivateChat&&(f[e.MessageOptionsKey.IsNotPrivate]=!1,o.attachedInfoElem=v({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:r.burnDuration}))}();return d&&d.then?d.then(s):s()})}catch(e){return Promise.reject(e)}};return _t.includes(s.message.contentType)?o.enqueue(u):r.enqueue(u)}))}catch(e){return Promise.reject(e)}},sendMessageNotOss:function(n,o){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.SendMessage,o,function(){return r.enqueue(function(){try{var r=v({},n,{message:v({},n.message)}),s=r.message,a=r.recvID,u=r.groupID,c=r.isOnlineOnly,d=r.offlinePushInfo,g=void 0===d?{title:"you hava a new message.",desc:"you hava a new message.",ex:"",iOSPushSound:"",iOSBadgeCount:!0,signalInfo:""}:d;void 0===g.signalInfo&&(g.signalInfo="");var p=Vt[s.contentType];if(!p)throw new he(e.ErrorCode.MsgContentTypeNotSupportError,"Unknown message content type");s.recvID=a,s.groupID=u,s.sessionType=u?e.SessionType.Group:e.SessionType.Single;var l={};c&&Object.values(e.MessageOptionsKey).forEach(function(e){return l[e]=!1});var f=ce(s);return Promise.resolve(t.messageTrigger.getOneConversationAndTryChange(f,o)).then(function(n){function r(r){var c,d;n.latestMsgSendTime=s.createTime,t.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(s)});var v=JSON.stringify(s[p]),h={sendID:t.userID,recvID:a||"",groupID:u||"",clientMsgID:s.clientMsgID,serverMsgID:s.serverMsgID||"",senderPlatformID:t.platform,senderNickname:s.senderNickname,senderFaceURL:s.senderFaceUrl,sessionType:s.sessionType,msgFrom:s.msgFrom,contentType:s.contentType,content:Oe(v),seq:s.seq,sendTime:0,createTime:s.createTime,status:s.status,isRead:!1,options:l,offlinePushInfo:g,atUserIDList:null!=(c=null==(d=s.atTextElem)?void 0:d.atUserList)?c:[],attachedInfo:s.attachedInfoElem?JSON.stringify(s.attachedInfoElem):"",ex:s.ex||"",dstUserIDs:[],keyVersion:0};return Promise.resolve(t.messageTrigger.encryptor.encryption(f,h,o)).then(function(){var r=i.PbCoder.MsgData.encode(h).finish();return Bt(function(){return Promise.resolve(t.sendReqWaitResp({data:r,operationID:o,reqIdentifier:e.ReqIdentifier.SendMsg})).then(function(r){var i=r.serverMsgID,a=r.sendTime;return s.sendTime=a,s.serverMsgID=i,s.status=e.MessageStatus.Succeed,t.messageTrigger.setTriggeredConversationEvent(o),t.messageTrigger.cache.updateCachedMaxReadSeq(n.conversationID,{maxSeqTime:a}),t.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(s),latestMsgSendTime:a}),s})},function(n){throw s.status=e.MessageStatus.Failed,t.messageTrigger.getOneConversationAndTryChange(f,o,{latestMsg:JSON.stringify(s)}),n})})}var c=function(){if(!n)return Promise.resolve(t.messageTrigger.initConversation({sourceID:u||a,sessionType:s.sessionType,operationID:o})).then(function(r){return n=r,function(){if(u)return Promise.resolve(t.groupTrigger.cache.getGroupInfosWithCache([u],o)).then(function(n){return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:u,userIDList:[t.userID],operationID:o})).then(function(t){if(null==t||!t.length)throw new he(e.ErrorCode.ArgsError,"user not join target group");t[0].nickname&&(s.senderNickname=t[0].nickname),s.attachedInfoElem={groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},s.attachedInfoElem.groupHasReadInfo.unreadCount=n[0].memberCount-1})})}()});n.isPrivateChat&&(l[e.MessageOptionsKey.IsNotPrivate]=!1,s.attachedInfoElem=v({},{groupHasReadInfo:{hasReadCount:0,unreadCount:0},isPrivateChat:!1,burnDuration:0,hasReadTime:0,messageEntityList:[],isEncryption:!1,inEncryptStatus:!1},{isPrivateChat:!0,burnDuration:n.burnDuration}))}();return c&&c.then?c.then(r):r()})}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}},revokeMessage:function(n,r){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.RevokeMessage,r,function(){try{var i=function(i){return Promise.resolve(t.sendHttpRequest({reqFuncName:e.RequestApi.RevokeMessage,data:{conversationID:n.conversationID,seq:o.seq,userID:t.userID},operationID:r})).then(function(){t.messageTrigger.setTriggeredConversationEvent(r),t.messageTrigger.revokeMessage({revokerUserID:t.userID,clientMsgID:o.clientMsgID,revokeTime:Date.now(),sesstionType:o.sessionType,seq:o.seq,conversationID:n.conversationID,isAdminRevoke:!1},r)})},o=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.clientMsgID])[0];if(!o)throw new he(e.ErrorCode.ArgsError,"message not exist");var s=function(){if(o.sendID!==t.userID){if(!o.groupID)throw new he(e.ErrorCode.ArgsError,"message can not be revoked");return Promise.resolve(t.groupTrigger.cache.getGroupMembersWithCache({groupID:o.groupID,userIDList:[t.userID],operationID:r})).then(function(t){var n=t[0];if(!n||n.roleLevel===e.GroupMemberRole.Nomal)throw new he(e.ErrorCode.ArgsError,"message can not be revoked")})}}();return Promise.resolve(s&&s.then?s.then(i):i())}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},getAdvancedHistoryMessageList:function(n,r){try{return Promise.resolve(me(t.loginStatus,e.RequestApi.GetAdvancedHistoryMessageList,r,function(){try{var i={isEnd:!1,errCode:0,errMsg:"",messageList:[]};if(u!==n.conversationID&&(s=null,u=n.conversationID),n.startClientMsgID){if(null===s){var o=t.messageTrigger.cache.getCachedMessageByClientMsgIDs(n.conversationID,[n.startClientMsgID])[0];if(!o)return Promise.resolve(v({},i,{isEnd:!0}));s=o.seq}}else s=0;var d=t.messageTrigger.cache.getCachedMaxReadSeq(n.conversationID);return a.default.log("syncedSeqs",d),d?Promise.resolve(c({maxSeq:s?s-1:d.maxSeq,count:n.count,conversationID:n.conversationID,operationID:r})).then(function(o){function u(){function u(){var e,u;return i.messageList=o.map(_e),t.messageTrigger.cache.getGroupMessageHasReadInfo({conversationID:n.conversationID,messages:[].concat(i.messageList),operationID:r}),a.default.debug("getAdvancedHistoryMessageList with opid: ",r,"messageList: ",i.messageList),s=null!=(e=null==(u=o[0])?void 0:u.seq)?e:0,v({},i,{isEnd:o.lengthe.NotificationType.NotificationBegin&&d.contentTypes.length&&u.groupHasReadInfo.hasReadCount>s.length)return Promise.resolve(t.sendHttpRequest({reqFuncName:T.GetGroupMessageHasRead,data:{clientMsgID:n.clientMsgID,conversationID:n.conversationID,type:e.GroupMessageReaderFilter.Read,pagination:{pageNumber:n.offset+1,showNumber:n.count}},operationID:r})).then(function(e){var a=e.reads;if(s.length<50&&n.offset<50){var u=50-s.length;t.messageTrigger.cache.addGroupMessageReadUser(n.clientMsgID,a.slice(0,u%c [OperationID:"+t[t.length-1]+"] (invoked) run "+e+" with args "+JSON.stringify(t),"font-size:14px; background:#007BFF; border-radius:4px; padding-inline:4px;","")}(t,n),Promise.resolve(r.apply(e,n)).then(function(e){var n,r;return n=t,(r=e).errCode?a.default.debug("%cSDK =>%c [OperationID:"+r.operationID+"] (response) run "+n+" with error "+JSON.stringify(r),"font-size:14px; background:#28A745; border-radius:4px; padding-inline:4px;",""):a.default.debug("%cSDK =>%c [OperationID:"+r.operationID+"] (response) run "+n+" with response before processor "+JSON.stringify(r.data),"font-size:14px; background:#FFDC19; border-radius:4px; padding-inline:4px;",""),e.errCode?Promise.reject(e):e})}catch(e){return Promise.reject(e)}}:Reflect.get(e,t,n)}})}}); diff --git a/node_modules/@openim/client-sdk/lib/types/entity.d.ts b/node_modules/@openim/client-sdk/lib/types/entity.d.ts index d91ac19..1dd7ad7 100644 --- a/node_modules/@openim/client-sdk/lib/types/entity.d.ts +++ b/node_modules/@openim/client-sdk/lib/types/entity.d.ts @@ -420,9 +420,14 @@ export type GroupMessageReceiptInfo = { conversationID: string; groupMessageReadInfo: GroupMessageReadInfo[]; }; +export type ReadUser = { + userID: string; + readTime: number; +}; export type GroupMessageReadInfo = { clientMsgID: string; hasReadCount: number; unreadCount: number; + readUsers: ReadUser[]; readMembers: GroupMemberItem[]; }; diff --git a/node_modules/@openim/client-sdk/lib/types/enum.d.ts b/node_modules/@openim/client-sdk/lib/types/enum.d.ts index 664c863..c9474b1 100644 --- a/node_modules/@openim/client-sdk/lib/types/enum.d.ts +++ b/node_modules/@openim/client-sdk/lib/types/enum.d.ts @@ -289,7 +289,8 @@ export declare enum GroupMemberFilter { Admin = 2, Nomal = 3, AdminAndNomal = 4, - AdminAndOwner = 5 + AdminAndOwner = 5, + NotSelf = 6 } export declare enum Relationship { isBlack = 0, @@ -304,6 +305,10 @@ export declare enum OnlineState { Online = 1, Offline = 0 } +export declare enum GroupMessageReaderFilter { + Read = 0, + UnRead = 1 +} export declare enum ViewType { ViewHistory = 0, ViewSearch = 1 diff --git a/node_modules/@openim/client-sdk/lib/types/params.d.ts b/node_modules/@openim/client-sdk/lib/types/params.d.ts index 2042c36..aa32a33 100644 --- a/node_modules/@openim/client-sdk/lib/types/params.d.ts +++ b/node_modules/@openim/client-sdk/lib/types/params.d.ts @@ -1,7 +1,7 @@ +import { SdkWsProto, GroupProto, RtcProto } from '@openim/protocol'; import { CbEvents } from '../constant/callback'; import type { AtUsersInfoItem, GroupItem, MessageItem, PicBaseInfo } from './entity'; -import type { GroupAtType, GroupJoinSource, GroupMemberFilter, GroupMemberRole, LogLevel, MessageReceiveOptType, ReqIdentifier, ViewType } from './enum'; -import { GroupProto, SdkWsProto } from '@openim/protocol'; +import type { GroupAtType, GroupJoinSource, GroupMemberRole, GroupMessageReaderFilter, LogLevel, MessageReceiveOptType, ReqIdentifier, ViewType } from './enum'; export type SendWsReqParams = { data: Uint8Array; reqIdentifier: ReqIdentifier; @@ -95,7 +95,6 @@ export type AccessGroupParams = { }; export declare type GetGroupMemberParams = { groupID: string; - filter: GroupMemberFilter; offset: number; count: number; }; @@ -217,3 +216,26 @@ export type UploadFileParams = { uuid?: string; file: File; }; +export type SendGroupReadReceiptParams = { + conversationID: string; + clientMsgIDList: string[]; +}; +export declare type GetGroupMessageReaderParams = { + conversationID: string; + clientMsgID: string; + filter: GroupMessageReaderFilter; + offset: number; + count: number; +}; +export type SignalingInviteParams = { + invitation: RtcProto.InvitationInfo; + offlinePushInfo?: SdkWsProto.OfflinePushInfo; +}; +export type RtcActionParams = { + opUserID: string; + invitation: RtcProto.InvitationInfo; +}; +export type CustomSignalParams = { + roomID: string; + customInfo: string; +}; diff --git a/node_modules/@openim/client-sdk/lib/utils/aesEncryptor.d.ts b/node_modules/@openim/client-sdk/lib/utils/aesEncryptor.d.ts new file mode 100644 index 0000000..3350631 --- /dev/null +++ b/node_modules/@openim/client-sdk/lib/utils/aesEncryptor.d.ts @@ -0,0 +1,6 @@ +export declare class AESEncryptor { + private uint8ArrayToWordArray; + private wordArrayToUint8Array; + encryption(rawData: Uint8Array, keyStr: string): Uint8Array; + decryption(encryptedData: Uint8Array, keyStr: string): Uint8Array; +} diff --git a/node_modules/@openim/client-sdk/lib/utils/dataFormater.d.ts b/node_modules/@openim/client-sdk/lib/utils/dataFormater.d.ts index bbc32b7..5fbae58 100644 --- a/node_modules/@openim/client-sdk/lib/utils/dataFormater.d.ts +++ b/node_modules/@openim/client-sdk/lib/utils/dataFormater.d.ts @@ -1,9 +1,9 @@ -import { SDKMessage, GroupApplicationItem, MessageItem, ConversationItem } from "../types/entity"; -import { JsSdkProto, SdkWsProto } from "@openim/protocol"; +import { SDKMessage, GroupApplicationItem, MessageItem, ConversationItem } from '../types/entity'; +import { JsSdkProto, SdkWsProto } from '@openim/protocol'; export declare const groupApplicationFormater: (request: SdkWsProto.GroupRequest) => GroupApplicationItem; export declare const msgDataFormater: (message: SdkWsProto.MsgData) => SDKMessage; export declare const messageElemFormater: (message: SDKMessage) => MessageItem; -export declare const parseNotificationElem: (buffer: ArrayBuffer) => T; +export declare const parseNotificationElem: (buffer: ArrayBuffer | Uint8Array) => T; export declare const conversationFormater: ({ conversation, group, friend, user, lastMsg, maxSeq, readSeq, }: JsSdkProto.ConversationMsg, getPreviousSeqMessage: (params: { conversationID: string; seq: number; diff --git a/node_modules/@openim/client-sdk/lib/utils/queue.d.ts b/node_modules/@openim/client-sdk/lib/utils/queue.d.ts index cecab8d..24366c3 100644 --- a/node_modules/@openim/client-sdk/lib/utils/queue.d.ts +++ b/node_modules/@openim/client-sdk/lib/utils/queue.d.ts @@ -3,5 +3,6 @@ export declare class MessageQueue { private queue; private pending; enqueue(task: () => Promise): Promise; + cancelTasks(): void; private dequeue; } diff --git a/node_modules/@openim/client-sdk/lib/utils/requestAdapter.d.ts b/node_modules/@openim/client-sdk/lib/utils/requestAdapter.d.ts index 7afba25..08e36b7 100644 --- a/node_modules/@openim/client-sdk/lib/utils/requestAdapter.d.ts +++ b/node_modules/@openim/client-sdk/lib/utils/requestAdapter.d.ts @@ -7,5 +7,10 @@ interface AdaptReq { headers: Record; method?: AdaptMethod; } -export declare const adaptRequest: (req: AdaptReq) => Promise; +type RetryOptions = { + retries?: number; + baseDelayMs?: number; + maxDelayMs?: number; +}; +export declare const adaptRequest: (req: AdaptReq, retryOptions?: RetryOptions) => Promise; export {}; diff --git a/node_modules/@openim/client-sdk/lib/utils/stringview.d.ts b/node_modules/@openim/client-sdk/lib/utils/stringview.d.ts new file mode 100644 index 0000000..e2496a7 --- /dev/null +++ b/node_modules/@openim/client-sdk/lib/utils/stringview.d.ts @@ -0,0 +1,19 @@ +declare class StringView { + #private; + addStringCodec(encoding: any, reader: any, writer: any): void; + stringByteLength(str: any, encoding: any): number; + getString(dataView: any, byteOffset: any, byteLength: any, encoding: any): string; + getStringData(dataView: any, byteOffset: any, byteLength: any, encoding: any): { + str: string; + byteLength: number; + }; + getStringNT(dataView: any, byteOffset: any, encoding: any, terminator?: number): string; + getStringDataNT(dataView: any, byteOffset: any, encoding: any, terminator?: number): { + str: string; + byteLength: number; + }; + setString(dataView: any, byteOffset: any, value: any, encoding: any): number; + setStringNT(dataView: any, byteOffset: any, value: any, encoding: any): number; +} +declare const _default: StringView; +export default _default; diff --git a/node_modules/@openim/client-sdk/lib/utils/textCoder.d.ts b/node_modules/@openim/client-sdk/lib/utils/textCoder.d.ts index 6152589..7223a87 100644 --- a/node_modules/@openim/client-sdk/lib/utils/textCoder.d.ts +++ b/node_modules/@openim/client-sdk/lib/utils/textCoder.d.ts @@ -1,2 +1,3 @@ export declare const textDecoder: (buffer: ArrayBuffer | ArrayBufferView) => string; export declare const textEncoder: (str: string) => Uint8Array; +export declare const decodeArrayBuffer: (buf: ArrayBuffer) => string; diff --git a/node_modules/@openim/client-sdk/lib/utils/webSocketManager.d.ts b/node_modules/@openim/client-sdk/lib/utils/webSocketManager.d.ts index 6caf467..6365b7c 100644 --- a/node_modules/@openim/client-sdk/lib/utils/webSocketManager.d.ts +++ b/node_modules/@openim/client-sdk/lib/utils/webSocketManager.d.ts @@ -1,8 +1,14 @@ import { AppPlatform } from '../types/enum'; import { GeneralWsReq } from '../types/entity'; +interface HeartbeatConfig { + interval: number; + timeout: number; + maxFailures: number; +} declare class WebSocketManager { private url; private onMessage; + private onClose; private onReconnecting; private onReconnectFailed; private onReconnectSuccess; @@ -13,22 +19,46 @@ declare class WebSocketManager { private reconnectAttempts; private shouldReconnect; private isProcessingMessage; - private hasPong; + private consecutiveHeartbeatFailures; + private connectTimeoutId; platformNamespace: AppPlatform; - private heartbeatInterval; + private envListenersInstalled; + private heartbeatConfig; private heartbeatWorker; private legacyTimer; + private heartbeatTimeoutId; private workerUrl; - constructor(url: string, connectParams: Record, onMessage: (data: Blob | string, operationID: string) => Promise, onReconnecting: () => void, onReconnectFailed: () => void, onReconnectSuccess: () => void, reconnectInterval?: number, maxReconnectAttempts?: number); + private lastPongAt; + private forceImmediateReconnect; + constructor(url: string, connectParams: Record, onMessage: (data: Blob | string, operationID: string) => Promise, onClose: () => void, onReconnecting: () => void, onReconnectFailed: () => void, onReconnectSuccess: () => void, reconnectInterval?: number, maxReconnectAttempts?: number, heartbeatConfig?: Partial); private checkPlatform; private urlFormat; private startHeartbeat; private stopHeartbeat; - connect: () => Promise; + connect: (connectionTimeoutMs?: number) => Promise; private setupEventListeners; private onBinaryMessage; sendPing: () => void; + /** + * Force a health check immediately. If aggressive is true, + * make a single missed pong close the connection quickly on resume. + */ + private forceHealthCheck; + private handleVisibilityChange; + private handleOnline; + private handleOffline; + private installEnvListeners; + private removeEnvListeners; sendMessage: (req: GeneralWsReq) => void; close: () => void; + /** + * Public: Force reconnect. If immediate is true, bypass backoff + * and reconnect right away. If a socket is open, it is closed first. + */ + forceReconnect: (immediate?: boolean) => void; + /** + * Reset connection state for manual reconnection + */ + reset: () => void; } export default WebSocketManager;