Merge pull request #8042 from vector-im/bugfix/fre/vb_move_last_message_behind_labs

[Voice Broadcast] Move the live broadcast computation in the room list behind the lab flag
This commit is contained in:
Florian Renaud 2023-01-31 11:51:14 +01:00 committed by GitHub
commit bb8ebb73bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 8 deletions

1
changelog.d/8042.misc Normal file
View file

@ -0,0 +1 @@
[Voice Broadcast] Show Live broadcast in the room list only if the feature flag is enabled in the lab

View file

@ -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? {

View file

@ -24,17 +24,15 @@ import im.vector.app.features.voicebroadcast.model.VoiceBroadcastEvent
import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent
import im.vector.app.features.voicebroadcast.sequence
import im.vector.app.features.voicebroadcast.usecase.GetVoiceBroadcastStateEventLiveUseCase
import im.vector.app.features.voicebroadcast.usecase.GetVoiceBroadcastStateEventUseCase
import im.vector.app.features.voicebroadcast.voiceBroadcastId
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.runningReduce
import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.session.events.model.RelationType
import org.matrix.android.sdk.api.session.room.model.message.MessageAudioEvent
import org.matrix.android.sdk.api.session.room.model.message.asMessageAudioEvent
@ -48,7 +46,7 @@ import javax.inject.Inject
*/
class GetLiveVoiceBroadcastChunksUseCase @Inject constructor(
private val activeSessionHolder: ActiveSessionHolder,
private val getVoiceBroadcastEventUseCase: GetVoiceBroadcastStateEventLiveUseCase,
private val getVoiceBroadcastEventUseCase: GetVoiceBroadcastStateEventUseCase,
) {
fun execute(voiceBroadcast: VoiceBroadcast): Flow<List<MessageAudioEvent>> {
@ -60,7 +58,7 @@ class GetLiveVoiceBroadcastChunksUseCase @Inject constructor(
val existingChunks = room.timelineService().getTimelineEventsRelatedTo(RelationType.REFERENCE, voiceBroadcast.voiceBroadcastId)
.mapNotNull { timelineEvent -> timelineEvent.root.asMessageAudioEvent().takeIf { it.isVoiceBroadcast() } }
val voiceBroadcastEvent = runBlocking { getVoiceBroadcastEventUseCase.execute(voiceBroadcast).firstOrNull()?.getOrNull() }
val voiceBroadcastEvent = getVoiceBroadcastEventUseCase.execute(voiceBroadcast)
val voiceBroadcastState = voiceBroadcastEvent?.content?.voiceBroadcastState
return if (voiceBroadcastState == null || voiceBroadcastState == VoiceBroadcastState.STOPPED) {

View file

@ -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

View file

@ -85,4 +85,8 @@ class FakeVectorPreferences {
fun verifySetIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) {
verify { instance.setIpAddressVisibilityInDeviceManagerScreens(isVisible) }
}
fun givenIsVoiceBroadcastEnabled(isEnabled: Boolean) {
every { instance.isVoiceBroadcastEnabled() } returns isEnabled
}
}