From 21f27c1770a35e67967b7ca8c061fd8d56695983 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Mon, 27 Apr 2026 11:57:52 +0800 Subject: [PATCH] feat: add leaveGroup, addGroupMember, removeGroupMember, setConversationMuted/Pinned - ImSDK: leaveGroup removes current user from group via DELETE /groups/{id}/members/{userId} - ImSDK: addGroupMember / removeGroupMember for admin operations - ImSDK: setConversationMuted / setConversationPinned exposed from ImDatabase methods - ImSDK: fetchGroupHistory uses new /messages/group-history/{groupId} endpoint Co-Authored-By: Claude Sonnet 4.6 --- packages/im/src/ImSDK.ts | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/im/src/ImSDK.ts b/packages/im/src/ImSDK.ts index 9d4b6a4..e8a8abb 100644 --- a/packages/im/src/ImSDK.ts +++ b/packages/im/src/ImSDK.ts @@ -219,6 +219,28 @@ export const ImSDK = { return Array.isArray(res) ? res : (res.content ?? []) }, + async addGroupMember(groupId: string, userId: string): Promise { + const config = getConfig() + return apiRequest(`/api/im/groups/${encodeURIComponent(groupId)}/members`, { + method: 'POST', + params: { appId: config.appId }, + body: { userId }, + }) + }, + + async removeGroupMember(groupId: string, targetUserId: string): Promise { + const config = getConfig() + return apiRequest( + `/api/im/groups/${encodeURIComponent(groupId)}/members/${encodeURIComponent(targetUserId)}`, + { method: 'DELETE', params: { appId: config.appId } }, + ) + }, + + async leaveGroup(groupId: string): Promise { + if (!_currentUserId) throw new Error('[ImSDK] Not logged in') + await ImSDK.removeGroupMember(groupId, _currentUserId) + }, + async fetchGroupHistory(groupId: string, page = 0, size = 50): Promise { const config = getConfig() @@ -241,7 +263,7 @@ export const ImSDK = { } const res = await apiRequest<{ content?: ImMessage[] } | ImMessage[]>( - `/api/im/messages/history/${encodeURIComponent(groupId)}`, + `/api/im/messages/group-history/${encodeURIComponent(groupId)}`, { params: { appId: config.appId, page: String(page), size: String(size) } }, ) const messages = Array.isArray(res) ? res : (res.content ?? []) @@ -293,6 +315,18 @@ export const ImSDK = { await ImDatabase.markRead(config.appId, targetId) }, + async setConversationMuted(targetId: string, _chatType: string, muted: boolean): Promise { + if (!ImDatabase.isInitialized()) return + const config = getConfig() + await ImDatabase.setConversationMuted(config.appId, targetId, muted) + }, + + async setConversationPinned(targetId: string, _chatType: string, pinned: boolean): Promise { + if (!ImDatabase.isInitialized()) return + const config = getConfig() + await ImDatabase.setConversationPinned(config.appId, targetId, pinned) + }, + /** * Fetch last page of messages for each known conversation from server and save locally. * Called automatically after connection is established via login/loginWithToken.