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 <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-04-27 11:57:52 +08:00
父节点 03261f3416
当前提交 21f27c1770

查看文件

@ -219,6 +219,28 @@ export const ImSDK = {
return Array.isArray(res) ? res : (res.content ?? [])
},
async addGroupMember(groupId: string, userId: string): Promise<ImGroup> {
const config = getConfig()
return apiRequest<ImGroup>(`/api/im/groups/${encodeURIComponent(groupId)}/members`, {
method: 'POST',
params: { appId: config.appId },
body: { userId },
})
},
async removeGroupMember(groupId: string, targetUserId: string): Promise<ImGroup> {
const config = getConfig()
return apiRequest<ImGroup>(
`/api/im/groups/${encodeURIComponent(groupId)}/members/${encodeURIComponent(targetUserId)}`,
{ method: 'DELETE', params: { appId: config.appId } },
)
},
async leaveGroup(groupId: string): Promise<void> {
if (!_currentUserId) throw new Error('[ImSDK] Not logged in')
await ImSDK.removeGroupMember(groupId, _currentUserId)
},
async fetchGroupHistory(groupId: string, page = 0, size = 50): Promise<ImMessage[]> {
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<void> {
if (!ImDatabase.isInitialized()) return
const config = getConfig()
await ImDatabase.setConversationMuted(config.appId, targetId, muted)
},
async setConversationPinned(targetId: string, _chatType: string, pinned: boolean): Promise<void> {
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.