Hello, I’m trying to implement pub/sub messaging for chat in my android app.
I subscribed like that
https://cannypancake.backendless.app/api/messaging/liveChat/subscribe
with this body
{
"selector": {
"discussionId": "36"
}
}
and I have this response
{
"subscriptionId": "FBE6B578-3A3E-4717-FF76-7100F43F5400"
}
Then, I get the messages with this
https://cannypancake.backendless.app/api/messaging/liveChat/FBE6B578-3A3E-4717-FF76-7100F43F5400
with a kotlin flow
private fun detectNewMessagesForChat(subscriptionId:String, discussionId:Long) {
viewModelScope.launch {
notificationRepository.getChatMessagesPubSub(
subscriptionId = subscriptionId
).collect { networkResult ->
when (networkResult.status) {
NetworkStatus.SUCCESS -> {
//we get messages and refresh the UI
Logger.d(tag = "debaga"){ "in detect message for discussion: $discussionId" }
//todo debago refresh UI
getChatMessages()
}
NetworkStatus.ERROR -> {
}
NetworkStatus.LOADING -> {
}
}
}
}
}
The first time I receive this but it’s normal
{
"messages": []
}
Then I publish a message on this channel like this
POST/ https://cannypancake.backendless.app/api/messaging/liveChat
with this body
{
"message": "ok",
"headers": {
"discussionId": "36"
}
}
and also discussionId:36 in the header of the call (because I’m not sure if it’s only in the body or also in the header.
I receive that
{
"errorMessage": null,
"messageId": "message:349DAC1E-B9A5-44AC-A1C0-4CABBC61E7E0",
"status": "scheduled"
}
The status is scheduled, and I didn’t receive anymore in my detectNewMessageForChat.
Why the status is scheduled?
When I try to send the message from backendless directly, I didn’t receive anything too. In my Kotlin code, when I launch the detectNewMessageForChat flow, should I receive the publish inside all time my viewmodel is active?
Thanks you for precisions