Files
opencode-mobile/fdroid/expo-notifications-patches/service/delegates/FirebaseMessagingDelegate.kt

55 lines
2.0 KiB
Kotlin

package expo.modules.notifications.service.delegates
import android.content.Context
import android.os.Bundle
import expo.modules.notifications.notifications.background.BackgroundRemoteNotificationTaskConsumer
import expo.modules.notifications.tokens.interfaces.FirebaseTokenListener
import java.lang.ref.WeakReference
import java.util.*
/**
* Stub implementation (Firebase-free) for F-Droid builds.
* This app only uses local notifications - no FCM push tokens or remote messages.
*/
open class FirebaseMessagingDelegate(protected val context: Context) :
expo.modules.notifications.service.interfaces.FirebaseMessagingDelegate {
companion object {
protected var sLastToken: String? = null
protected val sTokenListenersReferences = WeakHashMap<FirebaseTokenListener, WeakReference<FirebaseTokenListener?>?>()
protected var sBackgroundTaskConsumerReferences = WeakHashMap<BackgroundRemoteNotificationTaskConsumer, WeakReference<BackgroundRemoteNotificationTaskConsumer>>()
@JvmStatic
fun addTokenListener(listener: FirebaseTokenListener) {
if (!sTokenListenersReferences.containsKey(listener)) {
sTokenListenersReferences[listener] = WeakReference(listener)
sLastToken?.let { listener.onNewToken(it) }
}
}
fun addBackgroundTaskConsumer(taskConsumer: BackgroundRemoteNotificationTaskConsumer) {
if (!sBackgroundTaskConsumerReferences.containsKey(taskConsumer)) {
sBackgroundTaskConsumerReferences[taskConsumer] = WeakReference(taskConsumer)
}
}
fun getBackgroundTasks() = sBackgroundTaskConsumerReferences.values.mapNotNull { it.get() }
/** No-op for F-Droid builds (no FCM, local notifications only). */
fun runTaskManagerTasks(applicationContext: Context, bundle: Bundle) {
// no-op: no FCM in this build
}
}
override fun onNewToken(token: String) {
for (listenerReference in sTokenListenersReferences.values) {
listenerReference?.get()?.onNewToken(token)
}
sLastToken = token
}
override fun onDeletedMessages() {
// no-op
}
}