Created
March 12, 2023 14:48
-
-
Save anioutkazharkova/b96eb888fb2d4b0941f1129d2f6da663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun startListenToComments(postId: String, result: (List<CommentItem>) -> Unit) { | |
val collection = FirebaseFirestore.getInstance().collection("posts").document(postId) | |
.collection("comments") | |
commentListener = collection.orderBy("date", Query.Direction.DESCENDING) | |
.addSnapshotListener(MetadataChanges.INCLUDE) { data, firebaseFirestoreExceptioor -> | |
if (data != null) { | |
val comments = data.toObjects(CommentItem::class.java) | |
result(comments) | |
} | |
} | |
} | |
fun stopCommentListening() { | |
commentListener?.remove() | |
commentListener = null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment