From 97150538bc2d632a1a3e6fec7cd9027d4749723a Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Fri, 24 Apr 2026 11:14:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(im):=20=E6=B7=BB=E5=8A=A0=E7=BE=A4?= =?UTF-8?q?=E7=BB=84=E7=AE=A1=E7=90=86=20API=20=E5=92=8C=E7=BE=A4=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=B6=88=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - types.ts:新增 ImGroup 类型 - imSDK.ts:新增 createGroup / listGroups / fetchGroupHistory - index.ts:导出 ImGroup 类型 Co-Authored-By: Claude Sonnet 4.6 --- src/im/imSDK.ts | 34 +++++++++++++++++++++++++++++++++- src/im/types.ts | 10 ++++++++++ src/index.ts | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) 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'