From d7e88f5035a3f3be496bae93db3b609175b3c3d6 Mon Sep 17 00:00:00 2001 From: Viktor Nyblom Date: Wed, 24 Jul 2024 10:07:54 +0200 Subject: [PATCH 1/6] Make setUserId accept nullable user id to clear user id. --- .../kotlin/dev/gitlive/firebase/analytics/analytics.kt | 2 +- .../kotlin/dev/gitlive/firebase/analytics/analytics.kt | 2 +- .../iosMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt | 2 +- .../jsMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt | 2 +- .../dev/gitlive/firebase/analytics/externals/analytics.kt | 2 +- .../kotlin/dev/gitlive/firebase/analytics/analytics.jvm.kt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/firebase-analytics/src/androidMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt b/firebase-analytics/src/androidMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt index f8a15062d..6bb66ab35 100644 --- a/firebase-analytics/src/androidMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt +++ b/firebase-analytics/src/androidMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt @@ -23,7 +23,7 @@ public actual class FirebaseAnalytics(public val android: com.google.firebase.an public actual fun setUserProperty(name: String, value: String) { android.setUserProperty(name, value) } - public actual fun setUserId(id: String) { + public actual fun setUserId(id: String?) { android.setUserId(id) } public actual fun resetAnalyticsData() { diff --git a/firebase-analytics/src/commonMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt b/firebase-analytics/src/commonMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt index 43db027aa..a4fa35880 100644 --- a/firebase-analytics/src/commonMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt +++ b/firebase-analytics/src/commonMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt @@ -13,7 +13,7 @@ public expect fun Firebase.analytics(app: FirebaseApp): FirebaseAnalytics public expect class FirebaseAnalytics { public fun logEvent(name: String, parameters: Map? = null) public fun setUserProperty(name: String, value: String) - public fun setUserId(id: String) + public fun setUserId(id: String?) public fun setAnalyticsCollectionEnabled(enabled: Boolean) public fun setSessionTimeoutInterval(sessionTimeoutInterval: Duration) public suspend fun getSessionId(): Long? diff --git a/firebase-analytics/src/iosMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt b/firebase-analytics/src/iosMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt index 8d8e22b45..2b98485f5 100644 --- a/firebase-analytics/src/iosMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt +++ b/firebase-analytics/src/iosMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt @@ -23,7 +23,7 @@ public actual class FirebaseAnalytics(public val ios: FIRAnalytics.Companion) { public actual fun setUserProperty(name: String, value: String) { ios.setUserPropertyString(value, name) } - public actual fun setUserId(id: String) { + public actual fun setUserId(id: String?) { ios.setUserID(id) } public actual fun resetAnalyticsData() { diff --git a/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt b/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt index a41f7925a..cbad07eee 100644 --- a/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt +++ b/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/analytics.kt @@ -25,7 +25,7 @@ public actual class FirebaseAnalytics(public val js: dev.gitlive.firebase.analyt dev.gitlive.firebase.analytics.externals.setUserProperty(js, name, value) } - public actual fun setUserId(id: String) { + public actual fun setUserId(id: String?) { dev.gitlive.firebase.analytics.externals.setUserId(js, id) } diff --git a/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/externals/analytics.kt b/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/externals/analytics.kt index e9e9c109d..dc29bf175 100644 --- a/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/externals/analytics.kt +++ b/firebase-analytics/src/jsMain/kotlin/dev/gitlive/firebase/analytics/externals/analytics.kt @@ -11,7 +11,7 @@ public external fun getAnalytics(app: FirebaseApp? = definedExternally): Firebas public external fun logEvent(app: FirebaseAnalytics, name: String, parameters: Map?) public external fun setUserProperty(app: FirebaseAnalytics, name: String, value: String) -public external fun setUserId(app: FirebaseAnalytics, id: String) +public external fun setUserId(app: FirebaseAnalytics, id: String?) public external fun resetAnalyticsData(app: FirebaseAnalytics) public external fun setDefaultEventParameters(app: FirebaseAnalytics, parameters: Map) public external fun setAnalyticsCollectionEnabled(app: FirebaseAnalytics, enabled: Boolean) diff --git a/firebase-analytics/src/jvmMain/kotlin/dev/gitlive/firebase/analytics/analytics.jvm.kt b/firebase-analytics/src/jvmMain/kotlin/dev/gitlive/firebase/analytics/analytics.jvm.kt index afc17b53d..1c0b62d05 100644 --- a/firebase-analytics/src/jvmMain/kotlin/dev/gitlive/firebase/analytics/analytics.jvm.kt +++ b/firebase-analytics/src/jvmMain/kotlin/dev/gitlive/firebase/analytics/analytics.jvm.kt @@ -14,7 +14,7 @@ public actual fun Firebase.analytics(app: FirebaseApp): FirebaseAnalytics { public actual class FirebaseAnalytics { public actual fun setUserProperty(name: String, value: String) {} - public actual fun setUserId(id: String) {} + public actual fun setUserId(id: String?) {} public actual fun resetAnalyticsData() {} public actual fun setAnalyticsCollectionEnabled(enabled: Boolean) {} public actual fun setSessionTimeoutInterval(sessionTimeoutInterval: Duration) {} From d358e7da35de974eea0232db6d50e0348543b9cb Mon Sep 17 00:00:00 2001 From: Griffin Sorrentino Date: Wed, 24 Jul 2024 10:29:05 -0400 Subject: [PATCH 2/6] Added support for deleting FCM token --- .../kotlin/dev/gitlive/firebase/messaging/messaging.kt | 4 ++++ .../kotlin/dev/gitlive/firebase/messaging/messaging.kt | 5 +++++ .../kotlin/dev/gitlive/firebase/messaging/messaging.kt | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/firebase-messaging/src/androidMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/androidMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt index 256520af8..cd8b210d5 100644 --- a/firebase-messaging/src/androidMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt +++ b/firebase-messaging/src/androidMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -18,4 +18,8 @@ public actual class FirebaseMessaging(public val android: com.google.firebase.me } public actual suspend fun getToken(): String = android.token.await() + + public actual suspend fun deleteToken() { + android.deleteToken().await() + } } diff --git a/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt index 6428778d8..86134852f 100644 --- a/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt +++ b/firebase-messaging/src/commonMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -28,4 +28,9 @@ public expect class FirebaseMessaging { * @return [String] FCM token */ public suspend fun getToken(): String + + /** + * Delete FCM token for client + */ + public suspend fun deleteToken() } diff --git a/firebase-messaging/src/iosMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/iosMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt index 5a9d697aa..c81c08bf1 100644 --- a/firebase-messaging/src/iosMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt +++ b/firebase-messaging/src/iosMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -18,6 +18,10 @@ public actual class FirebaseMessaging(public val ios: FIRMessaging) { } public actual suspend fun getToken(): String = awaitResult { ios.tokenWithCompletion(it) } + + public actual suspend fun deleteToken() { + await { ios.deleteTokenWithCompletion(it) } + } } public suspend inline fun T.await(function: T.(callback: (NSError?) -> Unit) -> Unit) { From 5122332cd86bfa9b935509b154e9fc88e37ddd80 Mon Sep 17 00:00:00 2001 From: Siarhei Luskanau Date: Wed, 24 Jul 2024 15:23:02 +0200 Subject: [PATCH 3/6] Format kotlin files in Github Actions --- .github/workflows/push.yml | 23 +++++++++++++++++++ .../gitlive/firebase/EncodeDecodeSettings.kt | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 000000000..86097d791 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,23 @@ +name: Push + +on: [ push ] + +jobs: + formatKotlin: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + - name: formatKotlin + run: ./gradlew formatKotlin + - uses: stefanzweifel/git-auto-commit-action@v5 + - name: lintKotlin + run: ./gradlew lintKotlin diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt index d73b9ede0..8c0de9a95 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt @@ -5,7 +5,8 @@ import kotlinx.serialization.modules.SerializersModule /** * Settings used to configure encoding/decoding */ -public sealed interface EncodeDecodeSettings { +public sealed interface EncodeDecodeSettings +{ /** * The [SerializersModule] to use for serialization. This allows for polymorphic serialization on runtime From 39b829f0b7cf71b412733d45cd9bbbb0d2771291 Mon Sep 17 00:00:00 2001 From: siarhei-luskanau Date: Thu, 25 Jul 2024 09:01:02 +0000 Subject: [PATCH 4/6] Apply automatic changes --- .../kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt index 8c0de9a95..d73b9ede0 100644 --- a/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt +++ b/firebase-common/src/commonMain/kotlin/dev/gitlive/firebase/EncodeDecodeSettings.kt @@ -5,8 +5,7 @@ import kotlinx.serialization.modules.SerializersModule /** * Settings used to configure encoding/decoding */ -public sealed interface EncodeDecodeSettings -{ +public sealed interface EncodeDecodeSettings { /** * The [SerializersModule] to use for serialization. This allows for polymorphic serialization on runtime From ecfee38a834f3c3a13bfa5956260ffd5357f9d5b Mon Sep 17 00:00:00 2001 From: Griffin Sorrentino Date: Thu, 25 Jul 2024 10:26:11 -0400 Subject: [PATCH 5/6] Added js impl --- .../dev/gitlive/firebase/messaging/externals/messaging.kt | 2 ++ .../jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt | 4 ++++ .../kotlin/dev/gitlive/firebase/messaging/messaging.kt | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/externals/messaging.kt b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/externals/messaging.kt index c7a7af487..323eac8de 100644 --- a/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/externals/messaging.kt +++ b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/externals/messaging.kt @@ -9,4 +9,6 @@ public external fun getMessaging( public external fun getToken(messaging: Messaging = definedExternally, options: dynamic = definedExternally): Promise +public external fun deleteToken(messaging: Messaging = definedExternally): Promise + public external interface Messaging diff --git a/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt index 2304dc172..8a767825e 100644 --- a/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt +++ b/firebase-messaging/src/jsMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -22,4 +22,8 @@ public actual class FirebaseMessaging(public val js: Messaging) { } public actual suspend fun getToken(): String = dev.gitlive.firebase.messaging.externals.getToken(js).await() + + public actual suspend fun deleteToken() { + dev.gitlive.firebase.messaging.externals.deleteToken(js).await() + } } diff --git a/firebase-messaging/src/jvmMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt b/firebase-messaging/src/jvmMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt index b41d244f3..eeef9c26f 100644 --- a/firebase-messaging/src/jvmMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt +++ b/firebase-messaging/src/jvmMain/kotlin/dev/gitlive/firebase/messaging/messaging.kt @@ -19,4 +19,8 @@ public actual class FirebaseMessaging { public actual suspend fun getToken(): String { TODO("Not yet implemented") } + + public actual suspend fun deleteToken() { + TODO("Not yet implemented") + } } From c19aebb88c27f50c2a2e432850bbe93ad8c90101 Mon Sep 17 00:00:00 2001 From: Griffin Sorrentino Date: Thu, 25 Jul 2024 10:48:03 -0400 Subject: [PATCH 6/6] Added API declarations --- firebase-messaging/api/android/firebase-messaging.api | 1 + firebase-messaging/api/jvm/firebase-messaging.api | 1 + 2 files changed, 2 insertions(+) diff --git a/firebase-messaging/api/android/firebase-messaging.api b/firebase-messaging/api/android/firebase-messaging.api index 8ccebcd66..438484598 100644 --- a/firebase-messaging/api/android/firebase-messaging.api +++ b/firebase-messaging/api/android/firebase-messaging.api @@ -1,5 +1,6 @@ public final class dev/gitlive/firebase/messaging/FirebaseMessaging { public fun (Lcom/google/firebase/messaging/FirebaseMessaging;)V + public final fun deleteToken (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getAndroid ()Lcom/google/firebase/messaging/FirebaseMessaging; public final fun getToken (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun subscribeToTopic (Ljava/lang/String;)V diff --git a/firebase-messaging/api/jvm/firebase-messaging.api b/firebase-messaging/api/jvm/firebase-messaging.api index ce326f8ee..be6a0d6a1 100644 --- a/firebase-messaging/api/jvm/firebase-messaging.api +++ b/firebase-messaging/api/jvm/firebase-messaging.api @@ -1,5 +1,6 @@ public final class dev/gitlive/firebase/messaging/FirebaseMessaging { public fun ()V + public final fun deleteToken (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun getToken (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun subscribeToTopic (Ljava/lang/String;)V public final fun unsubscribeFromTopic (Ljava/lang/String;)V