Hello! I am facing a problem while receiving new messages in my chat room.
I have called messagesRepository.getMessages() and created .subscribe(
amityMessages->{
//callback
})
But the only thing I am getting is the output:
I/SocketEventListener: onEvent(main thread: false): v3.message.didCreate
I/com.ekoapp.ekosdk.internal.api.mapper.EkoObjectPersister: object changed: id: 613b5ea4387e8e29ba683835 changedObject: EkoInternalMessage
It seems like there’s an issue with threading. You may query those messages on the wrong thread, also updating UI states on the wrong thread as well.
Could you please try to specific subscribing thread and observing thread following by this code snippet :
AmityChatClient.newMessageRepository()
.getMessages(MY_CHANNEL_ID)
.build()
.query()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
//update your ui states
}
I am receiving for example 15 messages and everything is ok. I send messages and they are shown on UI, but at some point it stops working everything, sending and receiving, both.
Alright, seems like the pipeline got disconnected somehow… may you add
AmityChatClient.newMessageRepository()
.getMessages(MY_CHANNEL_ID)
.build()
.query()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(//log to see what could be the error)
.doOnDispose(//log to see if the pipeline is disposed some how)
.subscribe {
//update your ui states
}
doOnComplete is done every time successfully when message is sent, but nothing is happening on receiving messages, still the same, as earlier.
Btw onDispose is not available for getMessages().
You need to make sure that the pipeline is disposed once it’s unused.
Or else you could reduce the number of changes by using Rx functions such as throttleLatest() or throttleFirst() in the data pipeline
Throttles items from the upstream Observable by first emitting the next item from upstream, then periodically emitting the latest item (if any) when the specified timeout elapses between them.
@Trust this seems to work now, my subscribe callback is called and is receiving all messages that are been sent from other user each second. I will try to send more messages in one second to see if it will unsubscribe again (somehow)