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

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