From b4ba8fbf45973d088c3f765eda5d705c29a7e588 Mon Sep 17 00:00:00 2001 From: jacquarg Date: Thu, 23 Oct 2025 10:24:45 +0200 Subject: [PATCH] feat:3187: listen to Murena_io topic when user is conected to a murena.io account. --- .../androidinterfaces/DeviceConfiguration.kt | 1 + .../procedures/RegisterToEosNotifications.kt | 5 ++++ .../RegisterToEOSBroadcastProcedureTest.kt | 28 +++++++++++++++++++ .../DeviceConfigurationImpl.kt | 24 ++++++++++++++-- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfiguration.kt b/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfiguration.kt index a5b3cd2..a1db95b 100644 --- a/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfiguration.kt +++ b/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/bridges/androidinterfaces/DeviceConfiguration.kt @@ -22,5 +22,6 @@ interface DeviceConfiguration { val device: String val androidVersion: String suspend fun getLang(): String + suspend fun isConnectedToMurenaIO(): Boolean suspend fun getMurenaWorkspaceGroups(): List } diff --git a/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt b/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt index d5672ae..a53067c 100644 --- a/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt +++ b/notificationsreceiver-domain/src/main/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEosNotifications.kt @@ -36,6 +36,7 @@ class RegisterToEosNotifications @Inject constructor( companion object { const val EOS_BROADCAST_TOPIC_PREFIX = "eOS" private const val ALL_DEVICES_TOPIC_BASE = "all" + private const val MURENA_IO_TOPIC_BASE = "Murena_io" private const val DEFAULT_LANG = "en" private val SUPPORTED_LANGUAGES = setOf("de", "en", "es", "fr", "it") } @@ -79,6 +80,10 @@ class RegisterToEosNotifications @Inject constructor( .takeIf { it in SUPPORTED_LANGUAGES } ?: DEFAULT_LANG, ) + if (deviceConfiguration.isConnectedToMurenaIO()) { + topics.add(MURENA_IO_TOPIC_BASE) + } + deviceConfiguration.getMurenaWorkspaceGroups().forEach { topics.add(it) } diff --git a/notificationsreceiver-domain/src/test/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEOSBroadcastProcedureTest.kt b/notificationsreceiver-domain/src/test/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEOSBroadcastProcedureTest.kt index 4fb3866..a4557e3 100644 --- a/notificationsreceiver-domain/src/test/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEOSBroadcastProcedureTest.kt +++ b/notificationsreceiver-domain/src/test/java/foundation/e/notificationsreceiver/domain/procedures/RegisterToEOSBroadcastProcedureTest.kt @@ -54,6 +54,7 @@ class RegisterToEOSBroadcastProcedureTest { every { deviceConfiguration.androidVersion } returns "13" every { deviceConfiguration.device } returns "FP3" coEvery { deviceConfiguration.getMurenaWorkspaceGroups() } returns emptyList() + coEvery { deviceConfiguration.isConnectedToMurenaIO() } returns false coEvery { deviceConfiguration.getLang() } returns "en" @@ -213,6 +214,33 @@ class RegisterToEOSBroadcastProcedureTest { } } + @Test + fun register_should_collect_murena_io() = runTest(testScheduler) { + coEvery { subscriptionRepository.getSubscriptions() } returns emptyList() + coEvery { deviceConfiguration.isConnectedToMurenaIO() } returns true + + // When + useCase.updateRegistration() + + // Then + listOf( + "eOS-all-en", + "eOS-FP3-en", + "eOS-2_9-en", + "eOS-FP3-2_9-en", + "eOS-Murena_io-en", + ).forEach { topic -> + coVerify { + subscriptionRepository.createSubscription( + withArg { + assertEquals(baseUrlFixture, it.baseUrl) + assertEquals(topic, it.topic) + }, + ) + } + } + } + @Test fun register_should_collect_workspace_groups() = runTest(testScheduler) { coEvery { subscriptionRepository.getSubscriptions() } returns emptyList() diff --git a/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/DeviceConfigurationImpl.kt b/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/DeviceConfigurationImpl.kt index 12a2f2a..d177a16 100644 --- a/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/DeviceConfigurationImpl.kt +++ b/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/DeviceConfigurationImpl.kt @@ -22,8 +22,11 @@ import android.content.Context import android.os.Build import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.notificationsreceiver.domain.bridges.androidinterfaces.DeviceConfiguration +import foundation.e.notificationsreceiver.domain.utils.e import foundation.e.notificationsreceiver.domain.utils.w import foundation.e.userinfoservice.lib.UserInfoProvider +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import javax.inject.Inject import javax.inject.Singleton @@ -40,8 +43,25 @@ class DeviceConfigurationImpl @Inject constructor( return runCatching { appContext.resources.configuration.locales.get(0).language }.getOrNull() ?: "en" } - override suspend fun getMurenaWorkspaceGroups(): List { - return UserInfoProvider.fetch(appContext).groups + override suspend fun isConnectedToMurenaIO(): Boolean = withContext(Dispatchers.IO) { + try { + UserInfoProvider.fetch(appContext).let { + it.id.isNotBlank() || it.email.isNotBlank() + } + } catch(e: IllegalStateException) { + e("Can't fetch UserInfo", e) + false + } + } + + + override suspend fun getMurenaWorkspaceGroups(): List = withContext(Dispatchers.IO) { + try { + UserInfoProvider.fetch(appContext).groups + } catch(e: IllegalStateException) { + e("Can't fetch UserInfo", e) + emptyList() + } } private fun getVersionThroughReflection(): String? { -- GitLab