import type { GetUserInfoWithCacheParams, SetSelfInfoParams, } from '@/types/params'; import OpenIMSDK from '.'; import { RequestApi } from '@/constant/api'; import type { MessageReceiveOptType } from '@/types/enum'; import type { FullUserItemWithCache, SelfUserInfo, UserOnlineState, WsResponse, } from '@/types/entity'; export function setupUser(openIMSDK: OpenIMSDK) { return { getSelfUserInfo: openIMSDK.createRequestFunctionWithoutParams( RequestApi.GetSelfUserInfo ), setSelfInfo: openIMSDK.createRequestFunction( RequestApi.SetSelfInfo ), getUsersInfoWithCache: openIMSDK.createRequestFunction< GetUserInfoWithCacheParams, FullUserItemWithCache[] >(RequestApi.GetUsersInfoWithCache, data => JSON.stringify([JSON.stringify(data.userIDList), data.groupID ?? '']) ), subscribeUsersStatus: openIMSDK.createRequestFunction< string[], UserOnlineState >(RequestApi.SubscribeUsersStatus), unsubscribeUsersStatus: openIMSDK.createRequestFunction( RequestApi.UnsubscribeUsersStatus ), getSubscribeUsersStatus: openIMSDK.createRequestFunctionWithoutParams< UserOnlineState[] >(RequestApi.GetSubscribeUsersStatus), setAppBackgroundStatus: openIMSDK.createRequestFunction( RequestApi.SetAppBackgroundStatus ), networkStatusChanged: openIMSDK.createRequestFunctionWithoutParams( RequestApi.NetworkStatusChanged ), setGlobalRecvMessageOpt: openIMSDK.createRequestFunction( RequestApi.SetGlobalRecvMessageOpt ), }; } export interface UserApi { getSelfUserInfo: (operationID?: string) => Promise>; setSelfInfo: ( params: Partial, operationID?: string ) => Promise>; getUsersInfoWithCache: ( params: GetUserInfoWithCacheParams, operationID?: string ) => Promise>; subscribeUsersStatus: ( params: string[], operationID?: string ) => Promise>; unsubscribeUsersStatus: ( params: string[], operationID?: string ) => Promise>; getSubscribeUsersStatus: ( operationID?: string ) => Promise>; setAppBackgroundStatus: ( params: boolean, operationID?: string ) => Promise>; networkStatusChanged: (operationID?: string) => Promise>; setGlobalRecvMessageOpt: ( params: MessageReceiveOptType, operationID?: string ) => Promise>; }