Skip to content

Instantly share code, notes, and snippets.

@a914-gowtham
Created September 26, 2021 17:00
Show Gist options
  • Save a914-gowtham/bd0a3317f75f18b3b15b75274bc4d33a to your computer and use it in GitHub Desktop.
Save a914-gowtham/bd0a3317f75f18b3b15b75274bc4d33a to your computer and use it in GitHub Desktop.
private fun addGroupListener() {
val fireStore= FirebaseFirestore.getInstance()
val userCollection= fireStore.collection("Users")
val groupCollection= fireStore.collection("Groups")
userCollection.document(myUserId).addSnapshotListener { snapshot, error ->
if (error == null) {
val groups = snapshot?.get("groups")
val groupsIds =
if (groups == null) ArrayList() else groups as ArrayList<String>
for(id in groupsIds)
groupCollection.document(id)
.get().addOnSuccessListener { snapshot->
val group=snapshot.toObject(Group::class.java)
groupDao.insertGroup(group)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment