Skip to content

Commit abc5670

Browse files
committed
add expects for DocumentReference.snapshots(includeMetadataChanges: Boolean)
implement in js and android
1 parent 2ec16e0 commit abc5670

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ subprojects {
6262
}
6363

6464
tasks.withType<Sign>().configureEach {
65-
onlyIf { !project.gradle.startParameter.taskNames.contains("publishToMavenLocal") }
65+
onlyIf { !project.gradle.startParameter.taskNames.any { "MavenLocal" in it } && !project.gradle.startParameter.taskNames.contains("publishToGitHubPackagesRepository") }
6666
}
6767

6868
tasks {

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ external object firebase {
454454
fun update(field: String, value: Any?, vararg moreFieldsAndValues: Any?): Promise<Unit>
455455
fun update(field: FieldPath, value: Any?, vararg moreFieldsAndValues: Any?): Promise<Unit>
456456
fun delete(): Promise<Unit>
457-
fun onSnapshot(next: (snapshot: DocumentSnapshot) -> Unit, error: (error: Error) -> Unit): ()->Unit
457+
fun onSnapshot(options: Json, next: (snapshot: DocumentSnapshot) -> Unit, error: (error: Error) -> Unit): ()->Unit
458458
}
459459

460460
open class WriteBatch {

firebase-firestore/src/androidMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.google.firebase.firestore.MetadataChanges
1010
import com.google.firebase.firestore.SetOptions
1111
import dev.gitlive.firebase.*
1212
import kotlinx.coroutines.channels.awaitClose
13+
import kotlinx.coroutines.flow.Flow
1314
import kotlinx.coroutines.flow.callbackFlow
1415
import kotlinx.coroutines.runBlocking
1516
import kotlinx.coroutines.tasks.await
@@ -263,8 +264,11 @@ actual class DocumentReference(val android: com.google.firebase.firestore.Docume
263264
actual suspend fun get() =
264265
DocumentSnapshot(android.get().await())
265266

266-
actual val snapshots get() = callbackFlow<DocumentSnapshot> {
267-
val listener = android.addSnapshotListener { snapshot, exception ->
267+
actual val snapshots: Flow<DocumentSnapshot> get() = snapshots()
268+
269+
actual fun snapshots(includeMetadataChanges: Boolean) = callbackFlow {
270+
val metadataChanges = if(includeMetadataChanges) MetadataChanges.INCLUDE else MetadataChanges.EXCLUDE
271+
val listener = android.addSnapshotListener(metadataChanges) { snapshot, exception ->
268272
snapshot?.let { trySend(DocumentSnapshot(snapshot)) }
269273
exception?.let { close(exception) }
270274
}

firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ expect class DocumentReference {
126126
val path: String
127127
val snapshots: Flow<DocumentSnapshot>
128128
val parent: CollectionReference
129+
fun snapshots(includeMetadataChanges: Boolean = false): Flow<DocumentSnapshot>
129130

130131
fun collection(collectionPath: String): CollectionReference
131132
suspend fun get(): DocumentSnapshot

firebase-firestore/src/jsMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dev.gitlive.firebase.*
88
import kotlinx.coroutines.GlobalScope
99
import kotlinx.coroutines.await
1010
import kotlinx.coroutines.channels.awaitClose
11+
import kotlinx.coroutines.flow.Flow
1112
import kotlinx.coroutines.flow.callbackFlow
1213
import kotlinx.coroutines.promise
1314
import kotlinx.serialization.DeserializationStrategy
@@ -234,8 +235,11 @@ actual class DocumentReference(val js: firebase.firestore.DocumentReference) {
234235

235236
actual suspend fun get() = rethrow { DocumentSnapshot(js.get().await()) }
236237

237-
actual val snapshots get() = callbackFlow<DocumentSnapshot> {
238+
actual val snapshots: Flow<DocumentSnapshot> get() = snapshots()
239+
240+
actual fun snapshots(includeMetadataChanges: Boolean) = callbackFlow {
238241
val unsubscribe = js.onSnapshot(
242+
json("includeMetadataChanges" to includeMetadataChanges),
239243
{ trySend(DocumentSnapshot(it)) },
240244
{ close(errorToException(it)) }
241245
)

0 commit comments

Comments
 (0)