2

I am making a chat feature in the android app using Conversations SDK. The reachability is enabled from the backend side. I try to get live updates of the online/offline status of all the users. But the flow doesn't come in onUserUpdated() method of ConversationsClientListener. Below is the code I have implemented to get the live status updates.

fun getUserStatus(): Flow<User> = callbackFlow {
    val client = instantMessageRepository.getConversationsClient()
    val listener = createClientListener (
        onUserUpdated = { user, updateReason ->
            user.let { trySend(it).isSuccess }
        }
    )

    client.addListener(listener)
    awaitClose { client.removeListener(listener) }
}

And I am getting it as live data as follows:

val userStatus = chatService.getUserStatus()
    .asLiveData(viewModelScope.coroutineContext)

And listening it in my activity as follows:

 mViewModel.userStatus.observe(viewLifecycleOwner) {
        Log.d(TAG, "onViewCreated: ${it.isOnline}")
 }

Is this the right way to get live user status updates online/offline? Or do I need some corrections or change the way I'm trying to implement it?

0 Answers0