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.