根据新的 Twilio Conversation API,进度监听器现在消失了,您可以通过这种方式计算计数:
如果您只有一个或多个频道,则此代码将起作用,因此它将返回所有对话未消费消息的计数。
科特林:
lifecycleScope.launch {
val messageChannel = Channel<Int>()
val allChannels = (get my conversation from conversationClient)
allChannels?.let { item ->
item.forEach { channel ->
// Get unconsummed message count
channel.getUnreadMessagesCount { count ->
count?.let { no ->
launch {messageChannel.send(no.toInt())}
}
}
}
//Observe channel to assure that above callbacks returned data
var msgsCount = 0
val messageReceive = launch {
repeat(item.size) {
msgsCount += messageChannel.receive()
}
}
messageReceive.join()
log.i("Total message count", msgsCount)
}
}