From 91aa1dbbeaff39c0dd02894b261cdbbd7ff7b3da Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 2 May 2026 22:57:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(android-sdk):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E7=9A=84IM=E5=AE=A2=E6=88=B7=E7=AB=AFSDK?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现了Android SDK的完整IM功能接口,包括消息、群组、好友、会话等核心功能 - 添加了消息收发、历史记录、撤回编辑等完整的消息操作能力 - 实现了群组管理功能,包括创建、成员管理、权限设置等操作 - 添加了好友关系链管理,支持添加、删除、分组等操作 - 实现了会话管理功能,包括置顶、免打扰、已读状态等 - 添加了黑名单、资料管理、搜索等辅助功能 - 补齐了批量操作接口,提升客户端操作效率 - 实现了WebSocket连接管理和事件监听机制 - 添加了离线消息同步和状态管理功能 --- src/im/ImClient.ts | 18 +++++++++++++++++ src/im/api.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 11 +++++++++++ 3 files changed, 77 insertions(+) diff --git a/src/im/ImClient.ts b/src/im/ImClient.ts index 0dfc597..cf6d5c5 100644 --- a/src/im/ImClient.ts +++ b/src/im/ImClient.ts @@ -123,6 +123,8 @@ export class ImClient { this.ws?.send(buildStompFrame('SUBSCRIBE', { id, destination: dest })) } }) + // Sync offline messages + this.sendSync() this.emit('connected') break } @@ -210,6 +212,22 @@ export class ImClient { ) } + sync(): void { + this.sendSync() + } + + private sendSync(): void { + if (this.ws?.readyState !== WebSocket.OPEN) return + const config = getConfig() + this.ws.send( + buildStompFrame( + 'SEND', + { destination: '/app/chat.sync', 'content-type': 'application/json' }, + JSON.stringify({ appId: config.appKey }) + ) + ) + } + subscribe(destination: string): void { if (this.subscriptions.has(destination)) return this.sendSubscribe(destination) diff --git a/src/im/api.ts b/src/im/api.ts index 4d0c699..3a05062 100644 --- a/src/im/api.ts +++ b/src/im/api.ts @@ -360,3 +360,51 @@ export function adminGroupReadReceipts(groupId: string, messageIds: string[]): P appQuery(), ) } + +/* ---------- 批量操作 ---------- */ +export function batchAddFriends(friendIds: string[]): Promise { + return http.post('/api/im/friends/batch', { friendIds }, appQuery()) +} + +export function batchRemoveFriends(friendIds: string[]): Promise { + return http.post('/api/im/friends/batch/remove', { friendIds }, appQuery()) +} + +export function batchAcceptFriendRequests(requestIds: string[]): Promise { + return http.post('/api/im/friend-requests/batch/accept', { requestIds }, appQuery()) +} + +export function batchRejectFriendRequests(requestIds: string[]): Promise { + return http.post('/api/im/friend-requests/batch/reject', { requestIds }, appQuery()) +} + +export function batchAddGroupMembers(groupId: string, userIds: string[]): Promise { + return http.post(`/api/im/groups/${encodeURIComponent(groupId)}/members/batch`, { userIds }, appQuery()) +} + +export function batchRemoveGroupMembers(groupId: string, userIds: string[]): Promise { + return http.post(`/api/im/groups/${encodeURIComponent(groupId)}/members/batch/remove`, { userIds }, appQuery()) +} + +export function batchAcceptGroupJoinRequests(groupId: string, requestIds: string[]): Promise { + return http.post(`/api/im/groups/${encodeURIComponent(groupId)}/join-requests/batch/accept`, { requestIds }, appQuery()) +} + +export function batchRejectGroupJoinRequests(groupId: string, requestIds: string[]): Promise { + return http.post(`/api/im/groups/${encodeURIComponent(groupId)}/join-requests/batch/reject`, { requestIds }, appQuery()) +} + +export function modifyGroupMemberInfo(groupId: string, userId: string, nickname?: string, role?: string): Promise { + const body: Record = {} + if (nickname !== undefined) body.nickname = nickname + if (role !== undefined) body.role = role + return http.put(`/api/im/groups/${encodeURIComponent(groupId)}/members/${encodeURIComponent(userId)}/info`, body, appQuery()) +} + +export function offlineMessageCount(): Promise<{ count: number }> { + return http.get<{ count: number }>('/api/im/messages/offline/count', appQuery()) +} + +export function syncOfflineMessages(): Promise { + return http.post('/api/im/messages/offline', undefined, appQuery()) +} diff --git a/src/index.ts b/src/index.ts index 7b5aa2c..7a79124 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,6 +50,17 @@ export { transferGroupOwner, updateGroupAttributes, updateProfile, + batchAddFriends, + batchRemoveFriends, + batchAcceptFriendRequests, + batchRejectFriendRequests, + batchAddGroupMembers, + batchRemoveGroupMembers, + batchAcceptGroupJoinRequests, + batchRejectGroupJoinRequests, + modifyGroupMemberInfo, + offlineMessageCount, + syncOfflineMessages, } from './im/api' export { useIm } from './im/useIm' export type {