Quantcast
Channel: how to add items in recyclerview if firestore users collection have specific collection in Android Kotlin - Stack Overflow
Viewing all articles
Browse latest Browse all 2

how to add items in recyclerview if firestore users collection have specific collection in Android Kotlin

0
0

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.

enter image description here

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)
        }
}

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images