From 2152c1d7bac3a39d5a08e037727fcfe38fc89638 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 30 Jan 2023 17:24:27 +0100 Subject: [PATCH] Do not compute live broadcast on last message if the feature is disabled in the lab --- .../usecase/GetLatestPreviewableEventUseCase.kt | 14 +++++++++++--- .../GetLatestPreviewableEventUseCaseTest.kt | 4 ++++ .../vector/app/test/fakes/FakeVectorPreferences.kt | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCase.kt b/vector/src/main/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCase.kt index 6a50e87562..94f9136a2f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCase.kt @@ -17,6 +17,7 @@ package im.vector.app.features.home.room.list.usecase import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.voicebroadcast.isLive import im.vector.app.features.voicebroadcast.isVoiceBroadcast import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent @@ -35,14 +36,21 @@ import javax.inject.Inject class GetLatestPreviewableEventUseCase @Inject constructor( private val sessionHolder: ActiveSessionHolder, private val getRoomLiveVoiceBroadcastsUseCase: GetRoomLiveVoiceBroadcastsUseCase, + private val vectorPreferences: VectorPreferences, ) { fun execute(roomId: String): TimelineEvent? { val room = sessionHolder.getSafeActiveSession()?.getRoom(roomId) ?: return null val roomSummary = room.roomSummary() ?: return null - return getCallEvent(roomSummary) - ?: getLiveVoiceBroadcastEvent(room) - ?: getDefaultLatestEvent(room, roomSummary) + // FIXME Observing live broadcasts results in many db requests, + // to prevent performances issues, we only enable this mechanism if the voice broadcast flag is enabled + return if (vectorPreferences.isVoiceBroadcastEnabled()) { + getCallEvent(roomSummary) + ?: getLiveVoiceBroadcastEvent(room) + ?: getDefaultLatestEvent(room, roomSummary) + } else { + roomSummary.latestPreviewableEvent + } } private fun getCallEvent(roomSummary: RoomSummary): TimelineEvent? { diff --git a/vector/src/test/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCaseTest.kt index 5d526c783b..f7dd5da30e 100644 --- a/vector/src/test/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/home/room/list/usecase/GetLatestPreviewableEventUseCaseTest.kt @@ -23,6 +23,7 @@ import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent import im.vector.app.features.voicebroadcast.usecase.GetRoomLiveVoiceBroadcastsUseCase import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakeRoom +import im.vector.app.test.fakes.FakeVectorPreferences import io.mockk.every import io.mockk.mockk import org.amshove.kluent.shouldBe @@ -46,10 +47,12 @@ internal class GetLatestPreviewableEventUseCaseTest { private val fakeSessionHolder = FakeActiveSessionHolder() private val fakeRoomSummary = mockk() private val fakeGetRoomLiveVoiceBroadcastsUseCase = mockk() + private val fakeVectorPreferences = FakeVectorPreferences() private val getLatestPreviewableEventUseCase = GetLatestPreviewableEventUseCase( fakeSessionHolder.instance, fakeGetRoomLiveVoiceBroadcastsUseCase, + fakeVectorPreferences.instance, ) @Before @@ -62,6 +65,7 @@ internal class GetLatestPreviewableEventUseCaseTest { every { eventId } returns firstArg() } } + fakeVectorPreferences.givenIsVoiceBroadcastEnabled(true) } @Test diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt index 3d3f415778..7a5831ffed 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt @@ -85,4 +85,8 @@ class FakeVectorPreferences { fun verifySetIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) { verify { instance.setIpAddressVisibilityInDeviceManagerScreens(isVisible) } } + + fun givenIsVoiceBroadcastEnabled(isEnabled: Boolean) { + every { instance.isVoiceBroadcastEnabled() } returns isEnabled + } }