mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
Do not compute live broadcast on last message if the feature is disabled in the lab
This commit is contained in:
parent
66e8b5bf7a
commit
2152c1d7ba
3 changed files with 19 additions and 3 deletions
|
@ -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? {
|
||||
|
|
|
@ -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<RoomSummary>()
|
||||
private val fakeGetRoomLiveVoiceBroadcastsUseCase = mockk<GetRoomLiveVoiceBroadcastsUseCase>()
|
||||
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
|
||||
|
|
|
@ -85,4 +85,8 @@ class FakeVectorPreferences {
|
|||
fun verifySetIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) {
|
||||
verify { instance.setIpAddressVisibilityInDeviceManagerScreens(isVisible) }
|
||||
}
|
||||
|
||||
fun givenIsVoiceBroadcastEnabled(isEnabled: Boolean) {
|
||||
every { instance.isVoiceBroadcastEnabled() } returns isEnabled
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue