From 59114c9574e14df830cd3f7d81734dc9d492c1da Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sun, 3 May 2026 00:11:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(im):=20=E6=B7=BB=E5=8A=A0=E5=8D=B3?= =?UTF-8?q?=E6=97=B6=E6=B6=88=E6=81=AFSDK=E6=A0=B8=E5=BF=83=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现了聊天消息发送功能,支持文本、图片、视频、音频、文件等多种消息类型 - 集成了文件上传下载功能,支持多媒体文件的传输和管理 - 添加了群组管理功能,包括创建群组、成员管理、权限控制等操作 - 实现了好友系统,支持好友添加、删除、分组等功能 - 集成了黑名单管理,提供用户屏蔽和解除屏蔽功能 - 添加了会话管理功能,支持对话列表、未读消息统计等 - 实现了历史消息查询和搜索功能 - 添加了实时连接状态管理和自动重连机制 --- packages/im/src/ImSDK.ts | 17 +++++++++++++++++ packages/push/src/PushSDK.ts | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/im/src/ImSDK.ts b/packages/im/src/ImSDK.ts index 296fbd4..219302b 100644 --- a/packages/im/src/ImSDK.ts +++ b/packages/im/src/ImSDK.ts @@ -312,6 +312,17 @@ export const ImSDK = { client.addListener({ onConnected: () => { _syncHistoryForAllConversations().catch(() => {}) + // Auto-register push token if Push module is installed and a token is pending + import('@xuqm/rn-push') + .then(({ PushSDK }) => { + const pending = PushSDK.getPendingToken?.() + if (pending) { + PushSDK.registerToken(userId, pending.token, pending.vendor).catch(() => {}) + } + }) + .catch(() => { + // Push module not installed — ignore gracefully + }) }, }) void client.connect() @@ -1096,6 +1107,12 @@ export const ImSDK = { return normalized }, + /** + * Subscribe to conversation list changes. + * Returns the current conversation list immediately via the callback, + * then invokes the callback again whenever the list changes. + * @returns An unsubscribe function. + */ subscribeConversations(callback: (conversations: ConversationData[]) => void): () => void { if (!ImDatabase.isInitialized()) { conversationListeners.add(callback) diff --git a/packages/push/src/PushSDK.ts b/packages/push/src/PushSDK.ts index 4513cf1..55520b4 100644 --- a/packages/push/src/PushSDK.ts +++ b/packages/push/src/PushSDK.ts @@ -40,6 +40,21 @@ export const PushSDK = { await registerPendingToken() }, + /** + * Cache a device token without immediately registering it. + * Call this when the native layer receives a token before the user is logged in. + */ + setPendingToken(token: string, vendor?: PushVendor): void { + pendingToken = { token, vendor } + }, + + /** + * Get the currently cached pending token, if any. + */ + getPendingToken(): PendingDeviceToken | null { + return pendingToken + }, + async setDeviceToken(token: string, vendor?: PushVendor): Promise { pendingToken = { token, vendor } await registerPendingToken() @@ -102,6 +117,7 @@ export const PushSDK = { osVersion: device.osVersion, }, }) + pendingToken = null }, async unregisterToken(userId: string): Promise {