As you can see in the firestore screenshot, i have two users in users collection and in one user i have engagedChatChannels collection because chat is start for one user but other don't have engagedChatChannels
I want get to all users those have engagedChatChannels,
I tried following code. I can check if user have engagedChatChannel collection or not but i am not able to add items in mutableListOf based on condition. I tried by removing condition as well but items not adding.
Image may be NSFW.
Clik here to view.
fun addUsersListener(context: Context, onListen: (List<Item>)->Unit): ListenerRegistration{
return firestoreInstance.collection("users")
.addSnapshotListener { querySnapshot, firebaseFirestoreException ->
if(firebaseFirestoreException !=null){
return@addSnapshotListener
}
val items = mutableListOf<Item>()
querySnapshot?.documents?.forEach {
firestoreInstance.collection("users")
.document(it.id).collection("engagedChatChannels").get()
.continueWith { result->
Log.v("CHATS", "Exits" + result.result?.size())
if(result.result!!.size() > 0)
items.add(
UserItem(
it.toObject(User::class.java)!!,
it.id,
0,
context
)
)
}
}
onListen(items)
}
}