File tree Expand file tree Collapse file tree 5 files changed +31
-0
lines changed
firebase-common/src/jsMain/kotlin/dev/gitlive/firebase
androidMain/kotlin/dev/gitlive/firebase/firestore
commonMain/kotlin/dev/gitlive/firebase/firestore
iosMain/kotlin/dev/gitlive/firebase/firestore
jsMain/kotlin/dev/gitlive/firebase/firestore Expand file tree Collapse file tree 5 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -376,6 +376,7 @@ external object firebase {
376376 fun where (field : String , opStr : String , value : Any? ): Query
377377 fun where (field : FieldPath , opStr : String , value : Any? ): Query
378378 fun onSnapshot (next : (snapshot: QuerySnapshot ) -> Unit , error : (error: Error ) -> Unit ): () -> Unit
379+ fun onSnapshot (options : Json , next : (snapshot: QuerySnapshot ) -> Unit , error : (error: Error ) -> Unit ): () -> Unit
379380 fun limit (limit : Double ): Query
380381 fun orderBy (field : String , direction : Any ): Query
381382 fun orderBy (field : FieldPath , direction : Any ): Query
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package dev.gitlive.firebase.firestore
77
88import com.google.firebase.Timestamp
99import com.google.firebase.firestore.FieldValue
10+ import com.google.firebase.firestore.MetadataChanges
1011import com.google.firebase.firestore.SetOptions
1112import dev.gitlive.firebase.*
1213import kotlinx.coroutines.channels.awaitClose
@@ -321,6 +322,15 @@ actual open class Query(open val android: com.google.firebase.firestore.Query) {
321322 awaitClose { listener.remove() }
322323 }
323324
325+ actual fun snapshots (includeMetadataChanges : Boolean ) = callbackFlow<QuerySnapshot > {
326+ val metadataChanges = if (includeMetadataChanges) MetadataChanges .INCLUDE else MetadataChanges .EXCLUDE
327+ val listener = android.addSnapshotListener(metadataChanges) { snapshot, exception ->
328+ snapshot?.let { safeOffer(QuerySnapshot (snapshot)) }
329+ exception?.let { close(exception) }
330+ }
331+ awaitClose { listener.remove() }
332+ }
333+
324334 internal actual fun _where (field : String , equalTo : Any? ) = Query (android.whereEqualTo(field, equalTo))
325335 internal actual fun _where (path : FieldPath , equalTo : Any? ) = Query (android.whereEqualTo(path.android, equalTo))
326336
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ expect class Transaction {
5555expect open class Query {
5656 fun limit (limit : Number ): Query
5757 val snapshots: Flow <QuerySnapshot >
58+ fun snapshots (includeMetadataChanges : Boolean = false): Flow <QuerySnapshot >
5859 suspend fun get (): QuerySnapshot
5960 internal fun _where (field : String , equalTo : Any? ): Query
6061 internal fun _where (path : FieldPath , equalTo : Any? ): Query
Original file line number Diff line number Diff line change @@ -238,6 +238,14 @@ actual open class Query(open val ios: FIRQuery) {
238238 awaitClose { listener.remove() }
239239 }
240240
241+ actual fun snapshots (includeMetadataChanges : Boolean ) = callbackFlow<QuerySnapshot > {
242+ val listener = ios.addSnapshotListenerWithIncludeMetadataChanges(includeMetadataChanges) { snapshot, error ->
243+ snapshot?.let { safeOffer(QuerySnapshot (snapshot)) }
244+ error?.let { close(error.toException()) }
245+ }
246+ awaitClose { listener.remove() }
247+ }
248+
241249 internal actual fun _where (field : String , equalTo : Any? ) = Query (ios.queryWhereField(field, isEqualTo = equalTo!! ))
242250 internal actual fun _where (path : FieldPath , equalTo : Any? ) = Query (ios.queryWhereFieldPath(path.ios, isEqualTo = equalTo!! ))
243251
Original file line number Diff line number Diff line change @@ -345,6 +345,17 @@ actual open class Query(open val js: firebase.firestore.Query) {
345345 }
346346 awaitClose { rethrow { unsubscribe() } }
347347 }
348+
349+ actual fun snapshots (includeMetadataChanges : Boolean ) = callbackFlow<QuerySnapshot > {
350+ val unsubscribe = rethrow {
351+ js.onSnapshot(
352+ json(" includeMetadataChanges" to includeMetadataChanges),
353+ { safeOffer(QuerySnapshot (it)) },
354+ { close(errorToException(it)) }
355+ )
356+ }
357+ awaitClose { rethrow { unsubscribe() } }
358+ }
348359}
349360
350361actual class CollectionReference (override val js : firebase.firestore.CollectionReference ) : Query(js) {
You can’t perform that action at this time.
0 commit comments