From 03261f3416c6e0fe16e81fd2db4d872e3940391f Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 25 Apr 2026 17:27:19 +0800 Subject: [PATCH] feat(im): add listFriends, addFriend, removeFriend to ImSDK Co-Authored-By: Claude Sonnet 4.6 --- packages/im/src/ImSDK.ts | 25 +++++++++++++++++++++++++ packages/im/src/index.ts | 6 ++++++ src/index.ts | 1 + 3 files changed, 32 insertions(+) diff --git a/packages/im/src/ImSDK.ts b/packages/im/src/ImSDK.ts index caa7d1f..9d4b6a4 100644 --- a/packages/im/src/ImSDK.ts +++ b/packages/im/src/ImSDK.ts @@ -424,6 +424,31 @@ export const ImSDK = { return ImSDK.sendMessage(toId, chatType, 'FILE', content) }, + async listFriends(): Promise { + const config = getConfig() + const res = await apiRequest<{ data?: string[] } | string[]>('/api/im/friends', { + params: { appId: config.appId }, + }) + if (Array.isArray(res)) return res + return (res as { data?: string[] }).data ?? [] + }, + + async addFriend(friendId: string): Promise { + const config = getConfig() + await apiRequest('/api/im/friends', { + method: 'POST', + params: { appId: config.appId, friendId }, + }) + }, + + async removeFriend(friendId: string): Promise { + const config = getConfig() + await apiRequest(`/api/im/friends/${encodeURIComponent(friendId)}`, { + method: 'DELETE', + params: { appId: config.appId }, + }) + }, + disconnect(): void { client?.disconnect() client = null diff --git a/packages/im/src/index.ts b/packages/im/src/index.ts index 8db9a2d..f8667df 100644 --- a/packages/im/src/index.ts +++ b/packages/im/src/index.ts @@ -1,5 +1,11 @@ export { ImSDK } from './ImSDK' export type { ConversationData } from './ImSDK' +import { ImSDK as _ImSDK } from './ImSDK' + +// Convenience named exports for friend APIs +export const listFriends = (): Promise => _ImSDK.listFriends() +export const addFriend = (friendId: string): Promise => _ImSDK.addFriend(friendId) +export const removeFriend = (friendId: string): Promise => _ImSDK.removeFriend(friendId) export { ImClient } from './ImClient' export { ImDatabase } from './db/ImDatabase' export type { MessageSearchParams } from './db/ImDatabase' diff --git a/src/index.ts b/src/index.ts index 7bfaeeb..f04ec5e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ export { ScaledImage } from '../packages/common/src' export { ImSDK } from '../packages/im/src' export { ImClient } from '../packages/im/src' export { uploadFile } from '../packages/im/src' +export { listFriends, addFriend, removeFriend } from '../packages/im/src' export type { ImMessage, ImGroup, ChatType, MsgType, MsgStatus, ImEventListener, SendMessageParams,