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>
这个提交包含在:
父节点
03261f3416
当前提交
21f27c1770
@ -219,6 +219,28 @@ export const ImSDK = {
|
|||||||
return Array.isArray(res) ? res : (res.content ?? [])
|
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[]> {
|
async fetchGroupHistory(groupId: string, page = 0, size = 50): Promise<ImMessage[]> {
|
||||||
const config = getConfig()
|
const config = getConfig()
|
||||||
|
|
||||||
@ -241,7 +263,7 @@ export const ImSDK = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const res = await apiRequest<{ content?: ImMessage[] } | ImMessage[]>(
|
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) } },
|
{ params: { appId: config.appId, page: String(page), size: String(size) } },
|
||||||
)
|
)
|
||||||
const messages = Array.isArray(res) ? res : (res.content ?? [])
|
const messages = Array.isArray(res) ? res : (res.content ?? [])
|
||||||
@ -293,6 +315,18 @@ export const ImSDK = {
|
|||||||
await ImDatabase.markRead(config.appId, targetId)
|
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.
|
* Fetch last page of messages for each known conversation from server and save locally.
|
||||||
* Called automatically after connection is established via login/loginWithToken.
|
* Called automatically after connection is established via login/loginWithToken.
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户