Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4ba8fbf authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

feat:3187: listen to Murena_io topic when user is conected to a murena.io account.

parent 44030a17
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,5 +22,6 @@ interface DeviceConfiguration {
    val device: String
    val androidVersion: String
    suspend fun getLang(): String
    suspend fun isConnectedToMurenaIO(): Boolean
    suspend fun getMurenaWorkspaceGroups(): List<String>
}
+5 −0
Original line number Diff line number Diff line
@@ -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)
        }
+28 −0
Original line number Diff line number Diff line
@@ -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<Topic> {
                        assertEquals(baseUrlFixture, it.baseUrl)
                        assertEquals(topic, it.topic)
                    },
                )
            }
        }
    }

    @Test
    fun register_should_collect_workspace_groups() = runTest(testScheduler) {
        coEvery { subscriptionRepository.getSubscriptions() } returns emptyList()
+22 −2
Original line number Diff line number Diff line
@@ -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<String> {
        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<String> = withContext(Dispatchers.IO) {
        try {
            UserInfoProvider.fetch(appContext).groups
        } catch(e: IllegalStateException) {
            e("Can't fetch UserInfo", e)
            emptyList()
        }
    }

    private fun getVersionThroughReflection(): String? {