Skip to content

Commit 31035f5

Browse files
committed
Merge remote-tracking branch 'GitLiveApp/master' into gitlive/kotlin-1.8.21-gradle-8
2 parents 13b0d2b + 129257a commit 31035f5

File tree

6 files changed

+35
-33
lines changed
  • firebase-auth/src
    • androidMain/kotlin/dev/gitlive/firebase/auth
    • commonMain/kotlin/dev/gitlive/firebase/auth
    • iosMain/kotlin/dev/gitlive/firebase/auth
    • jsMain/kotlin/dev/gitlive/firebase/auth
  • firebase-common/src/jsMain/kotlin/dev/gitlive/firebase
  • firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore

6 files changed

+35
-33
lines changed

firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/user.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import android.net.Uri
88
import com.google.firebase.auth.UserProfileChangeRequest
99
import kotlinx.coroutines.tasks.await
1010

11-
actual class FirebaseUser internal constructor(val android: com.google.firebase.auth.FirebaseUser) : FirebaseUserProfile {
11+
actual class FirebaseUser internal constructor(val android: com.google.firebase.auth.FirebaseUser) {
1212
actual val uid: String
1313
get() = android.uid
14-
override val displayName: String?
14+
actual val displayName: String?
1515
get() = android.displayName
1616
actual val email: String?
1717
get() = android.email
1818
actual val phoneNumber: String?
1919
get() = android.phoneNumber
20-
override val photoURL: String?
20+
actual val photoURL: String?
2121
get() = android.photoUrl?.toString()
2222
actual val isAnonymous: Boolean
2323
get() = android.isAnonymous
@@ -46,10 +46,10 @@ actual class FirebaseUser internal constructor(val android: com.google.firebase.
4646
actual suspend fun updateEmail(email: String) = android.updateEmail(email).await().run { Unit }
4747
actual suspend fun updatePassword(password: String) = android.updatePassword(password).await().run { Unit }
4848
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = android.updatePhoneNumber(credential.android).await().run { Unit }
49-
override suspend fun updateProfile(displayName: String?, photoUrl: String?) {
49+
actual suspend fun updateProfile(displayName: String?, photoUrl: String?) {
5050
val request = UserProfileChangeRequest.Builder()
51-
.setDisplayName(displayName)
52-
.setPhotoUri(photoUrl?.let { Uri.parse(it) })
51+
.apply { if(displayName !== UNCHANGED) setDisplayName(displayName) }
52+
.apply { if(photoUrl !== UNCHANGED) setPhotoUri(photoUrl?.let { Uri.parse(it) }) }
5353
.build()
5454
android.updateProfile(request).await()
5555
}

firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/user.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44

55
package dev.gitlive.firebase.auth
66

7-
// Javascript IR compilation has issues with referencing to actual values as default parameters, so we should use an interface instead
8-
interface FirebaseUserProfile {
9-
val displayName: String?
10-
val photoURL: String?
11-
suspend fun updateProfile(displayName: String? = this.displayName, photoUrl: String? = this.photoURL)
12-
}
7+
//workaround for https://youtrack.jetbrains.com/issue/KT-48836
8+
internal val UNCHANGED = ""
139

14-
expect class FirebaseUser : FirebaseUserProfile {
10+
expect class FirebaseUser {
1511
val uid: String
12+
val displayName: String?
1613
val email: String?
1714
val phoneNumber: String?
15+
val photoURL: String?
1816
val isAnonymous: Boolean
1917
val isEmailVerified: Boolean
2018
val metaData: UserMetaData?
@@ -33,6 +31,7 @@ expect class FirebaseUser : FirebaseUserProfile {
3331
suspend fun updateEmail(email: String)
3432
suspend fun updatePassword(password: String)
3533
suspend fun updatePhoneNumber(credential: PhoneAuthCredential)
34+
suspend fun updateProfile(displayName: String? = UNCHANGED, photoUrl: String? = UNCHANGED)
3635
suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings? = null)
3736
}
3837

firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44

55
package dev.gitlive.firebase.auth
66

7-
import cocoapods.FirebaseAuth.*
7+
import cocoapods.FirebaseAuth.FIRAuthDataResult
8+
import cocoapods.FirebaseAuth.FIRUser
9+
import cocoapods.FirebaseAuth.FIRUserInfoProtocol
10+
import cocoapods.FirebaseAuth.FIRUserMetadata
811
import platform.Foundation.NSURL
912

10-
actual class FirebaseUser internal constructor(val ios: FIRUser) : FirebaseUserProfile {
13+
actual class FirebaseUser internal constructor(val ios: FIRUser) {
1114
actual val uid: String
1215
get() = ios.uid
13-
override val displayName: String?
16+
actual val displayName: String?
1417
get() = ios.displayName
1518
actual val email: String?
1619
get() = ios.email
1720
actual val phoneNumber: String?
1821
get() = ios.phoneNumber
19-
override val photoURL: String?
22+
actual val photoURL: String?
2023
get() = ios.photoURL?.absoluteString
2124
actual val isAnonymous: Boolean
2225
get() = ios.anonymous
@@ -64,11 +67,10 @@ actual class FirebaseUser internal constructor(val ios: FIRUser) : FirebaseUserP
6467
actual suspend fun updateEmail(email: String) = ios.await { updateEmail(email, it) }.run { Unit }
6568
actual suspend fun updatePassword(password: String) = ios.await { updatePassword(password, it) }.run { Unit }
6669
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = ios.await { updatePhoneNumberCredential(credential.ios, it) }.run { Unit }
67-
override suspend fun updateProfile(displayName: String?, photoUrl: String?) {
68-
val request = ios.profileChangeRequest().apply {
69-
this.displayName = displayName
70-
this.photoURL = photoUrl?.let { NSURL.URLWithString(it) }
71-
}
70+
actual suspend fun updateProfile(displayName: String?, photoUrl: String?) {
71+
val request = ios.profileChangeRequest()
72+
.apply { if(displayName !== UNCHANGED) setDisplayName(displayName) }
73+
.apply { if(photoUrl !== UNCHANGED) setPhotoURL(photoUrl?.let { NSURL.URLWithString(it) }) }
7274
ios.await { request.commitChangesWithCompletion(it) }
7375
}
7476
actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = ios.await {

firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/user.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package dev.gitlive.firebase.auth
33
import dev.gitlive.firebase.firebase
44
import kotlinx.coroutines.await
55
import kotlin.js.Date
6+
import kotlin.js.json
67

7-
actual class FirebaseUser internal constructor(val js: firebase.user.User) : FirebaseUserProfile {
8+
actual class FirebaseUser internal constructor(val js: firebase.user.User) {
89
actual val uid: String
910
get() = rethrow { js.uid }
10-
override val displayName: String?
11+
actual val displayName: String?
1112
get() = rethrow { js.displayName }
1213
actual val email: String?
1314
get() = rethrow { js.email }
1415
actual val phoneNumber: String?
1516
get() = rethrow { js.phoneNumber }
16-
override val photoURL: String?
17+
actual val photoURL: String?
1718
get() = rethrow { js.photoURL }
1819
actual val isAnonymous: Boolean
1920
get() = rethrow { js.isAnonymous }
@@ -43,12 +44,12 @@ actual class FirebaseUser internal constructor(val js: firebase.user.User) : Fir
4344
actual suspend fun updateEmail(email: String) = rethrow { js.updateEmail(email).await() }
4445
actual suspend fun updatePassword(password: String) = rethrow { js.updatePassword(password).await() }
4546
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = rethrow { js.updatePhoneNumber(credential.js).await() }
46-
override suspend fun updateProfile(displayName: String?, photoUrl: String?) = rethrow {
47-
val request = object : firebase.user.ProfileUpdateRequest {
48-
override val displayName: String? = displayName
49-
override val photoURL: String? = photoUrl
50-
}
51-
js.updateProfile(request).await()
47+
actual suspend fun updateProfile(displayName: String?, photoUrl: String?) = rethrow {
48+
val request = listOfNotNull(
49+
displayName.takeUnless { it === UNCHANGED }?.let { "displayName" to it },
50+
photoUrl.takeUnless { it === UNCHANGED }?.let { "photoURL" to it }
51+
)
52+
js.updateProfile(json(*request.toTypedArray())).await()
5253
}
5354
actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = rethrow { js.verifyBeforeUpdateEmail(newEmail, actionCodeSettings?.toJson()).await() }
5455
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ external object firebase {
213213
fun updateEmail(newEmail: String): Promise<Unit>
214214
fun updatePassword(newPassword: String): Promise<Unit>
215215
fun updatePhoneNumber(phoneCredential: auth.AuthCredential): Promise<Unit>
216-
fun updateProfile(profile: ProfileUpdateRequest): Promise<Unit>
216+
fun updateProfile(profile: Json): Promise<Unit>
217217
fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: Any?): Promise<Unit>
218218
}
219219

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private val Any.value get() = when (this) {
8888
else -> this
8989
}
9090

91-
fun Query.where(field: String, equalTo: Any?) = _where(field, equalTo,value)
91+
fun Query.where(field: String, equalTo: Any?) = _where(field, equalTo?.value)
9292
fun Query.where(path: FieldPath, equalTo: Any?) = _where(path, equalTo?.value)
9393
fun Query.where(field: String, equalTo: DocumentReference) = _where(field, equalTo.value)
9494
fun Query.where(path: FieldPath, equalTo: DocumentReference) = _where(path, equalTo.value)

0 commit comments

Comments
 (0)