From b4b3f01a5dc6252c9ac6f2ae1dea91518cb655bd Mon Sep 17 00:00:00 2001 From: Yanqi-Lin <1354016594@qq.com> Date: Mon, 3 Apr 2023 03:57:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ltd/kevinc/kchat/KChatServiceClient.kt | 5 +-- .../main/java/ltd/kevinc/chat/MainActivity.kt | 35 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/KChatSDK/src/main/java/ltd/kevinc/kchat/KChatServiceClient.kt b/KChatSDK/src/main/java/ltd/kevinc/kchat/KChatServiceClient.kt index 8c79e1b..7fe3b5c 100644 --- a/KChatSDK/src/main/java/ltd/kevinc/kchat/KChatServiceClient.kt +++ b/KChatSDK/src/main/java/ltd/kevinc/kchat/KChatServiceClient.kt @@ -139,7 +139,8 @@ class KChatServiceClient { .setMaxLength(pageSize) .build() - this.syncChannel = KChatSDKClient.chatClient.syncChatRecordStream(request) + this.syncChannel = + KChatSDKClient.chatClient.syncChatRecordStream(request, KChatSDKClient.header) this.syncChannel.flowOn(Dispatchers.IO) .onStart { @@ -151,7 +152,7 @@ class KChatServiceClient { } .onCompletion { err -> err?.printStackTrace() - Log.e("KChat.Sync", "sync closed due to some reason.") + Log.i("KChat.Sync", "sync finished.") } .collect { message -> Log.i("KChat.Sync", "pack size: ${message.recordsList.size}") diff --git a/app/src/main/java/ltd/kevinc/chat/MainActivity.kt b/app/src/main/java/ltd/kevinc/chat/MainActivity.kt index 142174d..868f5cb 100644 --- a/app/src/main/java/ltd/kevinc/chat/MainActivity.kt +++ b/app/src/main/java/ltd/kevinc/chat/MainActivity.kt @@ -14,6 +14,7 @@ import ltd.kevinc.chat.databinding.ActivityMainBinding import ltd.kevinc.kchat.KChatEventDelegate import ltd.kevinc.kchat.KChatSDKClient import ltd.kevinc.kchat.KChatServiceClient +import ltd.kevinc.kchat.KChatSyncRecordStreamDelegate import service.chat.Chat class MainActivity : AppCompatActivity() { @@ -58,24 +59,28 @@ class MainActivity : AppCompatActivity() { userGuid = KChatSDKClient.getOrCreateUser("114514", save = true) val client = KChatServiceClient() - client.listenForChatMessage(object : KChatEventDelegate { - override suspend fun onReceiveC2CMessage(message: Chat.C2CChatMessage) { - val body = message.content.toStringUtf8() - println("receiving: $body") - } - - override suspend fun channelClose(e: Throwable?) { - println("channel被关闭") - } +// client.listenForChatMessage(object : KChatEventDelegate { +// override suspend fun onReceiveC2CMessage(message: Chat.C2CChatMessage) { +// val body = message.content.toStringUtf8() +// println("receiving: $body") +// } +// +// override suspend fun channelClose(e: Throwable?) { +// println("channel被关闭") +// } +// +// override suspend fun onError(e: Throwable) { +// e.printStackTrace() +// } +// }) - override suspend fun onError(e: Throwable) { - e.printStackTrace() + client.fetchChatRecords(delegate = object : KChatSyncRecordStreamDelegate { + override suspend fun processPack(pack: List) { + for (i in pack) { + println("${i.c2CMessage.senderUserTag}__${i.c2CMessage.receiverUserTag}") + } } }) - -// KChatServiceClient.fetChatRecords().forEach { -// println("${it.c2CMessage.senderUserTag}__${it.c2CMessage.receiverUserTag}") -// } } } } \ No newline at end of file