Skip to content

Commit

Permalink
测试完毕
Browse files Browse the repository at this point in the history
  • Loading branch information
czf0613 committed Apr 2, 2023
1 parent 0530099 commit b4b3f01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
5 changes: 3 additions & 2 deletions KChatSDK/src/main/java/ltd/kevinc/kchat/KChatServiceClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}")
Expand Down
35 changes: 20 additions & 15 deletions app/src/main/java/ltd/kevinc/chat/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<Chat.ChatMessageWrapper>) {
for (i in pack) {
println("${i.c2CMessage.senderUserTag}__${i.c2CMessage.receiverUserTag}")
}
}
})

// KChatServiceClient.fetChatRecords().forEach {
// println("${it.c2CMessage.senderUserTag}__${it.c2CMessage.receiverUserTag}")
// }
}
}
}

0 comments on commit b4b3f01

Please sign in to comment.