Two real issues I’m having here:
Issue #1
When sending a UserMessage and setting the parent message ID via the following
private fun sendTextMessage(text: String, parentId: ParentId?, type: String, callback:
GMKMessageCallback?) {
val params = UserMessageParams().apply {
setMessage(text)
setCustomType(type)
parentId?.let {
Timber.d("Setting text message parent id to $it")
setParentMessageId(it)
}
}
val tempMessage = getChannel().sendUserMessage(params) { message, error ->
error?.let { Timber.w("$it") }
callback?.invoke(message, error)
}
callback?.invoke(tempMessage, null)
}
And from my view model:
private fun sendTextMessage(text: String, parentId: ParentId?) {
messageService.sendTextMessage(text, parentId) { message, _ ->
Timber.d("Send message with parent ${message?.parentMessageId} ($parentId) - status ${message?.sendingStatus}")
message?.let { _messageState.value = MessageState.Processed(it) }
}
}
I receive the following log output:
2020-06-23 08:54:21.011 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService: Setting text message parent id to 5760282222
2020-06-23 08:54:21.015 12455-12455/gloo.phoenix.android.staging D/GroupChatViewModel$sendTextMessage: Send message with parent 5760282222 (5760282222) - status PENDING
2020-06-23 08:54:21.184 12455-12455/gloo.phoenix.android.staging D/GroupChatViewModel$sendTextMessage: Send message with parent 0 (5760282222) - status SUCCEEDED
As you can see, the parent message ID is set initially while the message is pending and, it seems, when successfully processed, the parent message ID is cleared.
Issue #2
The second issue deals with retrieving threaded messages for a parent message. Obviously, by looking at issue #1, we can probably guess that this won’t work, but here is my code and output.
I’m trying to load threaded messages via the following:
fun loadLatestComments(parentMessage: GMKBaseMessage, limit: Int, callback: GMKMessageQueryCallback?) {
Timber.d("Loading latest comments for ${parentMessage.messageId}")
val params = ThreadMessageListParams().apply {
previousResultSize = limit
isInclusive = true
messageType = BaseChannel.MessageTypeFilter.ALL
setReverse(false)
}
parentMessage.getThreadedMessagesByTimestamp(Long.MAX_VALUE, params, getThreadedMessageHandler(callback))
}
And my handler:
private fun getThreadedMessageHandler(callback: GMKMessageQueryCallback?) =
BaseMessage.GetThreadedMessagesHandler { parent, replies, error ->
error?.printStackTrace()
Timber.d("Received ${replies?.size} replies from parent ${parent?.messageId}")
replies?.forEach { Timber.d("Reply found with parent id: ${it.parentMessageId}") }
callback?.invoke(replies, error)
}
And here’s the logging output:
2020-06-23 08:59:47.890 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService: Loading latest comments for 5760282222
2020-06-23 08:59:48.085 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Received 11 replies from parent 5832347906
2020-06-23 08:59:48.086 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Reply found with parent id: 0
2020-06-23 08:59:48.090 12455-12455/gloo.phoenix.android.staging I/chatty: uid=10085(gloo.phoenix.android.staging) identical 9 lines
2020-06-23 08:59:48.090 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Reply found with parent id: 0
2020-06-23 08:59:48.207 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService: Loading previous comments for 5760282222
2020-06-23 08:59:48.314 12455-12514/gloo.phoenix.android.staging I/chatty: uid=10085(gloo.phoenix.android.staging) RenderThread identical 1 line
2020-06-23 08:59:48.377 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Received 11 replies from parent 5844605825
2020-06-23 08:59:48.377 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Reply found with parent id: 0
2020-06-23 08:59:48.380 12455-12455/gloo.phoenix.android.staging I/chatty: uid=10085(gloo.phoenix.android.staging) identical 9 lines
2020-06-23 08:59:48.381 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Reply found with parent id: 0
2020-06-23 09:00:01.375 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService: Loading previous comments for 5760282222
2020-06-23 09:00:01.561 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Received 8 replies from parent 5832125927
2020-06-23 09:00:01.562 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Reply found with parent id: 0
2020-06-23 09:00:01.566 12455-12455/gloo.phoenix.android.staging I/chatty: uid=10085(gloo.phoenix.android.staging) identical 6 lines
2020-06-23 09:00:01.566 12455-12455/gloo.phoenix.android.staging D/SendBirdMessageService$getThreadedMessageHandler: Reply found with parent id: 0
Note: I’m using paging which is why you see multiple loads
Four things I’m noticing here
- The correct parent message is being used to retrieve the threads (5760282222)
- For each load, the returned
parent
parameter has the wrong, and in each case, a different ID (5832347906, 5844605825, 5832125927, etc). But we can see that the call isLoading previous comments for 5760282222
which is using the correct parent ID. - For each load, looping through the “replies,” we can see that the
parentMessageId
field is set to0
- I also noticed, in my
RecyclerView
, that the original channel’s messages were being loaded in the thread call as well. Also, all comments made on other threads in that channel are being included. So it appears that the parent is being completely ignored when making this call.
I haven’t found examples on using the new threading calls for the SDK, but it seems like this should be working. Please let me know what I’m doing wrong if that is not the case. If this is a bug, I believe it is a pretty major bug as we now rely on using a workaround of setting the customType
of each message to relate it to a specific parent.