Loading app/src/main/java/foundation/e/notificationsreceiver/repositories/SubscriptionsRepositoryImpl.kt +7 −1 Original line number Diff line number Diff line Loading @@ -17,10 +17,12 @@ package foundation.e.notificationsreceiver.repositories import android.content.Context import android.database.sqlite.SQLiteConstraintException import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.notificationsreceiver.domain.entities.Topic import foundation.e.notificationsreceiver.domain.repositories.SubscriptionsRepository import foundation.e.notificationsreceiver.domain.utils.AppBackgroundScope import foundation.e.notificationsreceiver.domain.utils.w import io.heckel.ntfy.R import io.heckel.ntfy.db.Database import io.heckel.ntfy.db.Repository Loading Loading @@ -95,7 +97,11 @@ class SubscriptionsRepositoryImpl @Inject constructor( lastActive = Date().time / 1000, ) try { subscriptionDao.add(subscription) } catch (e: SQLiteConstraintException) { w("Skip insert subscription, looks already there: ${e.message}") } debouncedRefreshSubscriptions() } Loading notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt +17 −11 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import foundation.e.notificationsreceiver.domain.utils.AppBackgroundScope import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import javax.inject.Inject import javax.inject.Singleton Loading @@ -41,6 +43,8 @@ class RegisterToEosNotifications @Inject constructor( private val SUPPORTED_LANGUAGES = setOf("de", "en", "es", "fr", "it") } private val mutex = Mutex() fun register() { backgroundScope.launch(Dispatchers.IO) { updateRegistration() Loading @@ -48,6 +52,7 @@ class RegisterToEosNotifications @Inject constructor( } internal suspend fun updateRegistration() { mutex.withLock { val toSubscribeTopics = buildTopicsList() val savedEOSTopics = subscriptionRepository.getSubscriptions() Loading @@ -63,6 +68,7 @@ class RegisterToEosNotifications @Inject constructor( subscriptionRepository.createSubscription(it) } } } internal suspend fun buildTopicsList(): List<Topic> { val topics = mutableListOf(ALL_DEVICES_TOPIC_BASE) Loading Loading
app/src/main/java/foundation/e/notificationsreceiver/repositories/SubscriptionsRepositoryImpl.kt +7 −1 Original line number Diff line number Diff line Loading @@ -17,10 +17,12 @@ package foundation.e.notificationsreceiver.repositories import android.content.Context import android.database.sqlite.SQLiteConstraintException import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.notificationsreceiver.domain.entities.Topic import foundation.e.notificationsreceiver.domain.repositories.SubscriptionsRepository import foundation.e.notificationsreceiver.domain.utils.AppBackgroundScope import foundation.e.notificationsreceiver.domain.utils.w import io.heckel.ntfy.R import io.heckel.ntfy.db.Database import io.heckel.ntfy.db.Repository Loading Loading @@ -95,7 +97,11 @@ class SubscriptionsRepositoryImpl @Inject constructor( lastActive = Date().time / 1000, ) try { subscriptionDao.add(subscription) } catch (e: SQLiteConstraintException) { w("Skip insert subscription, looks already there: ${e.message}") } debouncedRefreshSubscriptions() } Loading
notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt +17 −11 Original line number Diff line number Diff line Loading @@ -24,6 +24,8 @@ import foundation.e.notificationsreceiver.domain.utils.AppBackgroundScope import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import javax.inject.Inject import javax.inject.Singleton Loading @@ -41,6 +43,8 @@ class RegisterToEosNotifications @Inject constructor( private val SUPPORTED_LANGUAGES = setOf("de", "en", "es", "fr", "it") } private val mutex = Mutex() fun register() { backgroundScope.launch(Dispatchers.IO) { updateRegistration() Loading @@ -48,6 +52,7 @@ class RegisterToEosNotifications @Inject constructor( } internal suspend fun updateRegistration() { mutex.withLock { val toSubscribeTopics = buildTopicsList() val savedEOSTopics = subscriptionRepository.getSubscriptions() Loading @@ -63,6 +68,7 @@ class RegisterToEosNotifications @Inject constructor( subscriptionRepository.createSubscription(it) } } } internal suspend fun buildTopicsList(): List<Topic> { val topics = mutableListOf(ALL_DEVICES_TOPIC_BASE) Loading