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 {
376
376
fun where (field : String , opStr : String , value : Any? ): Query
377
377
fun where (field : FieldPath , opStr : String , value : Any? ): Query
378
378
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
379
380
fun limit (limit : Double ): Query
380
381
fun orderBy (field : String , direction : Any ): Query
381
382
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
7
7
8
8
import com.google.firebase.Timestamp
9
9
import com.google.firebase.firestore.FieldValue
10
+ import com.google.firebase.firestore.MetadataChanges
10
11
import com.google.firebase.firestore.SetOptions
11
12
import dev.gitlive.firebase.*
12
13
import kotlinx.coroutines.channels.awaitClose
@@ -321,6 +322,15 @@ actual open class Query(open val android: com.google.firebase.firestore.Query) {
321
322
awaitClose { listener.remove() }
322
323
}
323
324
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
+
324
334
internal actual fun _where (field : String , equalTo : Any? ) = Query (android.whereEqualTo(field, equalTo))
325
335
internal actual fun _where (path : FieldPath , equalTo : Any? ) = Query (android.whereEqualTo(path.android, equalTo))
326
336
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ expect class Transaction {
55
55
expect open class Query {
56
56
fun limit (limit : Number ): Query
57
57
val snapshots: Flow <QuerySnapshot >
58
+ fun snapshots (includeMetadataChanges : Boolean = false): Flow <QuerySnapshot >
58
59
suspend fun get (): QuerySnapshot
59
60
internal fun _where (field : String , equalTo : Any? ): Query
60
61
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) {
238
238
awaitClose { listener.remove() }
239
239
}
240
240
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
+
241
249
internal actual fun _where (field : String , equalTo : Any? ) = Query (ios.queryWhereField(field, isEqualTo = equalTo!! ))
242
250
internal actual fun _where (path : FieldPath , equalTo : Any? ) = Query (ios.queryWhereFieldPath(path.ios, isEqualTo = equalTo!! ))
243
251
Original file line number Diff line number Diff line change @@ -345,6 +345,17 @@ actual open class Query(open val js: firebase.firestore.Query) {
345
345
}
346
346
awaitClose { rethrow { unsubscribe() } }
347
347
}
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
+ }
348
359
}
349
360
350
361
actual class CollectionReference (override val js : firebase.firestore.CollectionReference ) : Query(js) {
You can’t perform that action at this time.
0 commit comments