Ensure the user can join the call even if they has joined a call in another session.

This commit is contained in:
Benoit Marty
2024-11-06 09:43:38 +01:00
parent 2a35edb14a
commit 0bbb1ac23d
10 changed files with 116 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ sealed interface RoomCallState {
data class OnGoing(
val canJoinCall: Boolean,
val isUserInTheCall: Boolean,
val isUserLocallyInTheCall: Boolean,
) : RoomCallState
}

View File

@@ -22,9 +22,11 @@ open class RoomCallStateProvider : PreviewParameterProvider<RoomCallState> {
fun anOngoingCallState(
canJoinCall: Boolean = true,
isUserInTheCall: Boolean = false,
isUserLocallyInTheCall: Boolean = isUserInTheCall,
) = RoomCallState.OnGoing(
canJoinCall = canJoinCall,
isUserInTheCall = isUserInTheCall,
isUserLocallyInTheCall = isUserLocallyInTheCall,
)
fun aStandByCallState(

View File

@@ -20,6 +20,7 @@ setupAnvil()
dependencies {
api(projects.features.roomcall.api)
implementation(libs.kotlinx.collections.immutable)
implementation(projects.features.call.api)
implementation(projects.libraries.architecture)
implementation(projects.libraries.matrix.api)
implementation(projects.libraries.matrixui)

View File

@@ -12,6 +12,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import io.element.android.features.call.api.CurrentCall
import io.element.android.features.call.api.CurrentCallObserver
import io.element.android.features.roomcall.api.RoomCallState
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.matrix.api.room.MatrixRoom
@@ -20,6 +22,7 @@ import javax.inject.Inject
class RoomCallStatePresenter @Inject constructor(
private val room: MatrixRoom,
private val currentCallObserver: CurrentCallObserver,
) : Presenter<RoomCallState> {
@Composable
override fun present(): RoomCallState {
@@ -31,10 +34,17 @@ class RoomCallStatePresenter @Inject constructor(
room.sessionId in roomInfo?.activeRoomCallParticipants.orEmpty()
}
}
val currentCall by currentCallObserver.currentCall.collectAsState()
val isUserLocallyInTheCall by remember {
derivedStateOf {
(currentCall as? CurrentCall.RoomCall)?.roomId == room.roomId
}
}
val callState = when {
roomInfo?.hasRoomCall == true -> RoomCallState.OnGoing(
canJoinCall = canJoinCall,
isUserInTheCall = isUserInTheCall,
isUserLocallyInTheCall = isUserLocallyInTheCall,
)
else -> RoomCallState.StandBy(canStartCall = canJoinCall)
}