Loading app/src/main/java/foundation/e/notificationsreceiver/repositories/SubscriptionsRepositoryImpl.kt +8 −8 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package foundation.e.notificationsreceiver.repositories import android.content.Context import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.notificationsreceiver.domain.entities.TopicSubscription import foundation.e.notificationsreceiver.domain.entities.Topic import foundation.e.notificationsreceiver.domain.repositories.SubscriptionsRepository import io.heckel.ntfy.R import io.heckel.ntfy.db.Database Loading Loading @@ -47,15 +47,15 @@ class SubscriptionsRepositoryImpl @Inject constructor( return repository.getDefaultBaseUrl() ?: appContext.getString(R.string.app_base_url) } override suspend fun getSubscriptions(): List<TopicSubscription> = withContext(Dispatchers.IO) { subscriptionDao.list().map { TopicSubscription(localId = it.id, baseUrl = it.baseUrl, topic = it.topic) } override suspend fun getSubscriptions(): List<Topic> = withContext(Dispatchers.IO) { subscriptionDao.list().map { Topic(localId = it.id, baseUrl = it.baseUrl, topic = it.topic) } } override suspend fun subscribe(topicSubscription: TopicSubscription) = withContext(Dispatchers.IO) { override suspend fun subscribe(topic: Topic) = withContext(Dispatchers.IO) { val subscription = Subscription( id = randomSubscriptionId(), baseUrl = topicSubscription.baseUrl, topic = topicSubscription.topic, baseUrl = topic.baseUrl, topic = topic.topic, instant = true, dedicatedChannels = false, mutedUntil = 0, Loading @@ -75,7 +75,7 @@ class SubscriptionsRepositoryImpl @Inject constructor( subscriptionDao.add(subscription) } override suspend fun unsubscribe(topicSubscription: TopicSubscription): Unit = withContext(Dispatchers.IO) { subscriptionDao.remove(topicSubscription.localId) override suspend fun unsubscribe(topic: Topic): Unit = withContext(Dispatchers.IO) { subscriptionDao.remove(topic.localId) } } notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfigurationAndroidInterface.kt→notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfiguration.kt +1 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package foundation.e.notificationsreceiver.domain.bridges.androidinterfaces interface DeviceConfigurationAndroidInterface { interface DeviceConfiguration { val version: String? val device: String val androidVersion: String Loading notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/entities/TopicSubscription.kt→notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/entities/Topic.kt +1 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package foundation.e.notificationsreceiver.domain.entities data class TopicSubscription( data class Topic( val localId: Long = -1, val baseUrl: String, val topic: String, Loading notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEOSBroadcastProcedure.kt→notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt +9 −9 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ package foundation.e.notificationsreceiver.domain.procedures import foundation.e.notificationsreceiver.domain.bridges.androidinterfaces.DeviceConfigurationAndroidInterface import foundation.e.notificationsreceiver.domain.entities.TopicSubscription import foundation.e.notificationsreceiver.domain.bridges.androidinterfaces.DeviceConfiguration import foundation.e.notificationsreceiver.domain.entities.Topic import foundation.e.notificationsreceiver.domain.repositories.SubscriptionsRepository import foundation.e.notificationsreceiver.domain.utils.AppBackgroundScope import kotlinx.coroutines.CoroutineScope Loading @@ -28,8 +28,8 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton class RegisterToEOSBroadcastProcedure @Inject constructor( private val deviceConfigurationAndroidInterface: DeviceConfigurationAndroidInterface, class RegisterToEosNotifications @Inject constructor( private val deviceConfiguration: DeviceConfiguration, private val subscriptionRepository: SubscriptionsRepository, @AppBackgroundScope private val backgroundScope: CoroutineScope, ) { Loading Loading @@ -59,24 +59,24 @@ class RegisterToEOSBroadcastProcedure @Inject constructor( } } internal suspend fun buildTopicsList(): List<TopicSubscription> { internal suspend fun buildTopicsList(): List<Topic> { val topics = mutableListOf(ALL_DEVICES_TOPIC_BASE) val deviceName = escapeTopicElement(deviceConfigurationAndroidInterface.device) val deviceName = escapeTopicElement(deviceConfiguration.device) topics.add(deviceName) deviceConfigurationAndroidInterface.version?.split("-")?.get(0)?.let { deviceConfiguration.version?.split("-")?.get(0)?.let { val eOSVersion = escapeTopicElement(it) topics.add(eOSVersion) topics.add("$deviceName-$eOSVersion") } val lang = escapeTopicElement( deviceConfigurationAndroidInterface.getLang() deviceConfiguration.getLang() .takeIf { it in SUPPORTED_LANGUAGES } ?: DEFAULT_LANG, ) val baseUrl = subscriptionRepository.getBaseUrl() return topics.map { TopicSubscription(baseUrl = baseUrl, topic = "${EOS_BROADCAST_TOPIC_PREFIX}-$it-$lang") } return topics.map { Topic(baseUrl = baseUrl, topic = "${EOS_BROADCAST_TOPIC_PREFIX}-$it-$lang") } } private fun escapeTopicElement(element: String): String { Loading notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/repositories/SubscriptionsRepository.kt +4 −4 Original line number Diff line number Diff line Loading @@ -17,13 +17,13 @@ package foundation.e.notificationsreceiver.domain.repositories import foundation.e.notificationsreceiver.domain.entities.TopicSubscription import foundation.e.notificationsreceiver.domain.entities.Topic interface SubscriptionsRepository { fun getBaseUrl(): String suspend fun getSubscriptions(): List<TopicSubscription> suspend fun getSubscriptions(): List<Topic> suspend fun subscribe(topicSubscription: TopicSubscription) suspend fun unsubscribe(topicSubscription: TopicSubscription) suspend fun subscribe(topicSubscription: Topic) suspend fun unsubscribe(topic: Topic) } Loading
app/src/main/java/foundation/e/notificationsreceiver/repositories/SubscriptionsRepositoryImpl.kt +8 −8 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package foundation.e.notificationsreceiver.repositories import android.content.Context import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.notificationsreceiver.domain.entities.TopicSubscription import foundation.e.notificationsreceiver.domain.entities.Topic import foundation.e.notificationsreceiver.domain.repositories.SubscriptionsRepository import io.heckel.ntfy.R import io.heckel.ntfy.db.Database Loading Loading @@ -47,15 +47,15 @@ class SubscriptionsRepositoryImpl @Inject constructor( return repository.getDefaultBaseUrl() ?: appContext.getString(R.string.app_base_url) } override suspend fun getSubscriptions(): List<TopicSubscription> = withContext(Dispatchers.IO) { subscriptionDao.list().map { TopicSubscription(localId = it.id, baseUrl = it.baseUrl, topic = it.topic) } override suspend fun getSubscriptions(): List<Topic> = withContext(Dispatchers.IO) { subscriptionDao.list().map { Topic(localId = it.id, baseUrl = it.baseUrl, topic = it.topic) } } override suspend fun subscribe(topicSubscription: TopicSubscription) = withContext(Dispatchers.IO) { override suspend fun subscribe(topic: Topic) = withContext(Dispatchers.IO) { val subscription = Subscription( id = randomSubscriptionId(), baseUrl = topicSubscription.baseUrl, topic = topicSubscription.topic, baseUrl = topic.baseUrl, topic = topic.topic, instant = true, dedicatedChannels = false, mutedUntil = 0, Loading @@ -75,7 +75,7 @@ class SubscriptionsRepositoryImpl @Inject constructor( subscriptionDao.add(subscription) } override suspend fun unsubscribe(topicSubscription: TopicSubscription): Unit = withContext(Dispatchers.IO) { subscriptionDao.remove(topicSubscription.localId) override suspend fun unsubscribe(topic: Topic): Unit = withContext(Dispatchers.IO) { subscriptionDao.remove(topic.localId) } }
notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfigurationAndroidInterface.kt→notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfiguration.kt +1 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package foundation.e.notificationsreceiver.domain.bridges.androidinterfaces interface DeviceConfigurationAndroidInterface { interface DeviceConfiguration { val version: String? val device: String val androidVersion: String Loading
notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/entities/TopicSubscription.kt→notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/entities/Topic.kt +1 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ package foundation.e.notificationsreceiver.domain.entities data class TopicSubscription( data class Topic( val localId: Long = -1, val baseUrl: String, val topic: String, Loading
notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEOSBroadcastProcedure.kt→notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt +9 −9 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ package foundation.e.notificationsreceiver.domain.procedures import foundation.e.notificationsreceiver.domain.bridges.androidinterfaces.DeviceConfigurationAndroidInterface import foundation.e.notificationsreceiver.domain.entities.TopicSubscription import foundation.e.notificationsreceiver.domain.bridges.androidinterfaces.DeviceConfiguration import foundation.e.notificationsreceiver.domain.entities.Topic import foundation.e.notificationsreceiver.domain.repositories.SubscriptionsRepository import foundation.e.notificationsreceiver.domain.utils.AppBackgroundScope import kotlinx.coroutines.CoroutineScope Loading @@ -28,8 +28,8 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton class RegisterToEOSBroadcastProcedure @Inject constructor( private val deviceConfigurationAndroidInterface: DeviceConfigurationAndroidInterface, class RegisterToEosNotifications @Inject constructor( private val deviceConfiguration: DeviceConfiguration, private val subscriptionRepository: SubscriptionsRepository, @AppBackgroundScope private val backgroundScope: CoroutineScope, ) { Loading Loading @@ -59,24 +59,24 @@ class RegisterToEOSBroadcastProcedure @Inject constructor( } } internal suspend fun buildTopicsList(): List<TopicSubscription> { internal suspend fun buildTopicsList(): List<Topic> { val topics = mutableListOf(ALL_DEVICES_TOPIC_BASE) val deviceName = escapeTopicElement(deviceConfigurationAndroidInterface.device) val deviceName = escapeTopicElement(deviceConfiguration.device) topics.add(deviceName) deviceConfigurationAndroidInterface.version?.split("-")?.get(0)?.let { deviceConfiguration.version?.split("-")?.get(0)?.let { val eOSVersion = escapeTopicElement(it) topics.add(eOSVersion) topics.add("$deviceName-$eOSVersion") } val lang = escapeTopicElement( deviceConfigurationAndroidInterface.getLang() deviceConfiguration.getLang() .takeIf { it in SUPPORTED_LANGUAGES } ?: DEFAULT_LANG, ) val baseUrl = subscriptionRepository.getBaseUrl() return topics.map { TopicSubscription(baseUrl = baseUrl, topic = "${EOS_BROADCAST_TOPIC_PREFIX}-$it-$lang") } return topics.map { Topic(baseUrl = baseUrl, topic = "${EOS_BROADCAST_TOPIC_PREFIX}-$it-$lang") } } private fun escapeTopicElement(element: String): String { Loading
notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/repositories/SubscriptionsRepository.kt +4 −4 Original line number Diff line number Diff line Loading @@ -17,13 +17,13 @@ package foundation.e.notificationsreceiver.domain.repositories import foundation.e.notificationsreceiver.domain.entities.TopicSubscription import foundation.e.notificationsreceiver.domain.entities.Topic interface SubscriptionsRepository { fun getBaseUrl(): String suspend fun getSubscriptions(): List<TopicSubscription> suspend fun getSubscriptions(): List<Topic> suspend fun subscribe(topicSubscription: TopicSubscription) suspend fun unsubscribe(topicSubscription: TopicSubscription) suspend fun subscribe(topicSubscription: Topic) suspend fun unsubscribe(topic: Topic) }