From d358e7da35de974eea0232db6d50e0348543b9cb Mon Sep 17 00:00:00 2001 From: Griffin Sorrentino Date: Wed, 24 Jul 2024 10:29:05 -0400 Subject: [PATCH 1/3] 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 ecfee38a834f3c3a13bfa5956260ffd5357f9d5b Mon Sep 17 00:00:00 2001 From: Griffin Sorrentino Date: Thu, 25 Jul 2024 10:26:11 -0400 Subject: [PATCH 2/3] 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 3/3] 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