feat(im): 添加群组管理 API 和群历史消息接口
- types.ts:新增 ImGroup 类型 - imSDK.ts:新增 createGroup / listGroups / fetchGroupHistory - index.ts:导出 ImGroup 类型 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
b747901cfe
当前提交
97150538bc
@ -1,7 +1,7 @@
|
|||||||
import { getConfig } from '../core/config'
|
import { getConfig } from '../core/config'
|
||||||
import { apiRequest, getToken, saveToken } from '../core/http'
|
import { apiRequest, getToken, saveToken } from '../core/http'
|
||||||
import { ImClient } from './imClient'
|
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
|
let client: ImClient | null = null
|
||||||
|
|
||||||
@ -91,4 +91,36 @@ export const ImSDK = {
|
|||||||
isConnected() {
|
isConnected() {
|
||||||
return client?.isConnected() ?? false
|
return client?.isConnected() ?? false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async createGroup(name: string, memberIds: string[]): Promise<ImGroup> {
|
||||||
|
const config = getConfig()
|
||||||
|
return apiRequest<ImGroup>('/api/im/groups', {
|
||||||
|
method: 'POST',
|
||||||
|
params: { appId: config.appId },
|
||||||
|
body: { name, memberIds },
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
async listGroups(): Promise<ImGroup[]> {
|
||||||
|
const config = getConfig()
|
||||||
|
const res = await apiRequest<ImGroup[] | { content?: ImGroup[] }>('/api/im/groups', {
|
||||||
|
params: { appId: config.appId },
|
||||||
|
})
|
||||||
|
return Array.isArray(res) ? res : (res.content ?? [])
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchGroupHistory(groupId: string, page = 0, size = 50): Promise<ImMessage[]> {
|
||||||
|
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 ?? [])
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,3 +45,13 @@ export interface SendMessageParams {
|
|||||||
content: string
|
content: string
|
||||||
mentionedUserIds?: string
|
mentionedUserIds?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ImGroup {
|
||||||
|
id: string
|
||||||
|
appId: string
|
||||||
|
name: string
|
||||||
|
creatorId: string
|
||||||
|
memberIds: string
|
||||||
|
adminIds: string
|
||||||
|
createdAt: string
|
||||||
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export { XuqmSDK } from './core/sdk'
|
|||||||
|
|
||||||
export { ImSDK } from './im/imSDK'
|
export { ImSDK } from './im/imSDK'
|
||||||
export { ImClient } from './im/imClient'
|
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 { PushSDK } from './push/pushSDK'
|
||||||
export type { PushVendor } from './push/pushSDK'
|
export type { PushVendor } from './push/pushSDK'
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户