diff --git a/src/im/imSDK.ts b/src/im/imSDK.ts index 68aa791..de70845 100644 --- a/src/im/imSDK.ts +++ b/src/im/imSDK.ts @@ -1,7 +1,7 @@ import { getConfig } from '../core/config' import { apiRequest, getToken, saveToken } from '../core/http' import { ImClient } from './imClient' -import type { ChatType, ImEventListener, ImMessage, MsgType } from './types' +import type { ChatType, ImEventListener, ImGroup, ImMessage, MsgType } from './types' let client: ImClient | null = null @@ -91,4 +91,36 @@ export const ImSDK = { isConnected() { return client?.isConnected() ?? false }, + + async createGroup(name: string, memberIds: string[]): Promise { + const config = getConfig() + return apiRequest('/api/im/groups', { + method: 'POST', + params: { appId: config.appId }, + body: { name, memberIds }, + }) + }, + + async listGroups(): Promise { + const config = getConfig() + const res = await apiRequest('/api/im/groups', { + params: { appId: config.appId }, + }) + return Array.isArray(res) ? res : (res.content ?? []) + }, + + async fetchGroupHistory(groupId: string, page = 0, size = 50): Promise { + const config = getConfig() + const res = await apiRequest<{ content?: ImMessage[] } | ImMessage[]>( + `/api/im/messages/history/${encodeURIComponent(groupId)}`, + { + params: { + appId: config.appId, + page: String(page), + size: String(size), + }, + }, + ) + return Array.isArray(res) ? res : (res.content ?? []) + }, } diff --git a/src/im/types.ts b/src/im/types.ts index c559e86..62ae252 100644 --- a/src/im/types.ts +++ b/src/im/types.ts @@ -45,3 +45,13 @@ export interface SendMessageParams { content: string mentionedUserIds?: string } + +export interface ImGroup { + id: string + appId: string + name: string + creatorId: string + memberIds: string + adminIds: string + createdAt: string +} diff --git a/src/index.ts b/src/index.ts index d098828..524d018 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ export { XuqmSDK } from './core/sdk' export { ImSDK } from './im/imSDK' export { ImClient } from './im/imClient' -export type { ImMessage, ChatType, MsgType, MsgStatus, ImEventListener, SendMessageParams } from './im/types' +export type { ImMessage, ChatType, MsgType, MsgStatus, ImEventListener, SendMessageParams, ImGroup } from './im/types' export { PushSDK } from './push/pushSDK' export type { PushVendor } from './push/pushSDK'