Rename CurrentCallObserver to CurrentCallService

This commit is contained in:
Benoit Marty
2024-11-06 17:24:26 +01:00
parent 1e44eb3538
commit 04274b8384
7 changed files with 23 additions and 23 deletions

View File

@@ -9,7 +9,7 @@ package io.element.android.features.call.api
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
interface CurrentCallObserver { interface CurrentCallService {
/** /**
* The current call state flow, which will be updated when the active call changes. * The current call state flow, which will be updated when the active call changes.
* This value reflect the local state of the call. It is not updated if the user answers * This value reflect the local state of the call. It is not updated if the user answers

View File

@@ -83,7 +83,7 @@ class DefaultActiveCallManager @Inject constructor(
private val ringingCallNotificationCreator: RingingCallNotificationCreator, private val ringingCallNotificationCreator: RingingCallNotificationCreator,
private val notificationManagerCompat: NotificationManagerCompat, private val notificationManagerCompat: NotificationManagerCompat,
private val matrixClientProvider: MatrixClientProvider, private val matrixClientProvider: MatrixClientProvider,
private val defaultCurrentCallObserver: DefaultCurrentCallObserver, private val defaultCurrentCallService: DefaultCurrentCallService,
) : ActiveCallManager { ) : ActiveCallManager {
private var timedOutCallJob: Job? = null private var timedOutCallJob: Job? = null
@@ -217,7 +217,7 @@ class DefaultActiveCallManager @Inject constructor(
activeCall activeCall
.onEach { value -> .onEach { value ->
if (value == null) { if (value == null) {
defaultCurrentCallObserver.onCallEnded() defaultCurrentCallService.onCallEnded()
} else { } else {
when (value.callState) { when (value.callState) {
is CallState.Ringing -> { is CallState.Ringing -> {
@@ -225,8 +225,8 @@ class DefaultActiveCallManager @Inject constructor(
} }
is CallState.InCall -> { is CallState.InCall -> {
when (val callType = value.callType) { when (val callType = value.callType) {
is CallType.ExternalUrl -> defaultCurrentCallObserver.onCallStarted(CurrentCall.ExternalUrl(callType.url)) is CallType.ExternalUrl -> defaultCurrentCallService.onCallStarted(CurrentCall.ExternalUrl(callType.url))
is CallType.RoomCall -> defaultCurrentCallObserver.onCallStarted(CurrentCall.RoomCall(callType.roomId)) is CallType.RoomCall -> defaultCurrentCallService.onCallStarted(CurrentCall.RoomCall(callType.roomId))
} }
} }
} }

View File

@@ -9,7 +9,7 @@ package io.element.android.features.call.impl.utils
import com.squareup.anvil.annotations.ContributesBinding import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.features.call.api.CurrentCall import io.element.android.features.call.api.CurrentCall
import io.element.android.features.call.api.CurrentCallObserver import io.element.android.features.call.api.CurrentCallService
import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.SingleIn import io.element.android.libraries.di.SingleIn
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@@ -17,7 +17,7 @@ import javax.inject.Inject
@SingleIn(AppScope::class) @SingleIn(AppScope::class)
@ContributesBinding(AppScope::class) @ContributesBinding(AppScope::class)
class DefaultCurrentCallObserver @Inject constructor() : CurrentCallObserver { class DefaultCurrentCallService @Inject constructor() : CurrentCallService {
override val currentCall = MutableStateFlow<CurrentCall>(CurrentCall.None) override val currentCall = MutableStateFlow<CurrentCall>(CurrentCall.None)
fun onCallStarted(call: CurrentCall) { fun onCallStarted(call: CurrentCall) {

View File

@@ -15,7 +15,7 @@ import io.element.android.features.call.impl.notifications.RingingCallNotificati
import io.element.android.features.call.impl.utils.ActiveCall import io.element.android.features.call.impl.utils.ActiveCall
import io.element.android.features.call.impl.utils.CallState import io.element.android.features.call.impl.utils.CallState
import io.element.android.features.call.impl.utils.DefaultActiveCallManager import io.element.android.features.call.impl.utils.DefaultActiveCallManager
import io.element.android.features.call.impl.utils.DefaultCurrentCallObserver import io.element.android.features.call.impl.utils.DefaultCurrentCallService
import io.element.android.features.call.test.aCallNotificationData import io.element.android.features.call.test.aCallNotificationData
import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.RoomId
@@ -300,6 +300,6 @@ class DefaultActiveCallManagerTest {
), ),
notificationManagerCompat = notificationManagerCompat, notificationManagerCompat = notificationManagerCompat,
matrixClientProvider = matrixClientProvider, matrixClientProvider = matrixClientProvider,
defaultCurrentCallObserver = DefaultCurrentCallObserver(), defaultCurrentCallService = DefaultCurrentCallService(),
) )
} }

View File

@@ -8,12 +8,12 @@
package io.element.android.features.call.test package io.element.android.features.call.test
import io.element.android.features.call.api.CurrentCall import io.element.android.features.call.api.CurrentCall
import io.element.android.features.call.api.CurrentCallObserver import io.element.android.features.call.api.CurrentCallService
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
class FakeCurrentCallObserver( class FakeCurrentCallService(
initialValue: CurrentCall = CurrentCall.None, initialValue: CurrentCall = CurrentCall.None,
) : CurrentCallObserver { ) : CurrentCallService {
override val currentCall = MutableStateFlow(initialValue) override val currentCall = MutableStateFlow(initialValue)
fun setCurrentCall(value: CurrentCall) { fun setCurrentCall(value: CurrentCall) {

View File

@@ -13,7 +13,7 @@ import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import io.element.android.features.call.api.CurrentCall import io.element.android.features.call.api.CurrentCall
import io.element.android.features.call.api.CurrentCallObserver import io.element.android.features.call.api.CurrentCallService
import io.element.android.features.roomcall.api.RoomCallState import io.element.android.features.roomcall.api.RoomCallState
import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.matrix.api.room.MatrixRoom import io.element.android.libraries.matrix.api.room.MatrixRoom
@@ -22,7 +22,7 @@ import javax.inject.Inject
class RoomCallStatePresenter @Inject constructor( class RoomCallStatePresenter @Inject constructor(
private val room: MatrixRoom, private val room: MatrixRoom,
private val currentCallObserver: CurrentCallObserver, private val currentCallService: CurrentCallService,
) : Presenter<RoomCallState> { ) : Presenter<RoomCallState> {
@Composable @Composable
override fun present(): RoomCallState { override fun present(): RoomCallState {
@@ -34,7 +34,7 @@ class RoomCallStatePresenter @Inject constructor(
room.sessionId in roomInfo?.activeRoomCallParticipants.orEmpty() room.sessionId in roomInfo?.activeRoomCallParticipants.orEmpty()
} }
} }
val currentCall by currentCallObserver.currentCall.collectAsState() val currentCall by currentCallService.currentCall.collectAsState()
val isUserLocallyInTheCall by remember { val isUserLocallyInTheCall by remember {
derivedStateOf { derivedStateOf {
(currentCall as? CurrentCall.RoomCall)?.roomId == room.roomId (currentCall as? CurrentCall.RoomCall)?.roomId == room.roomId

View File

@@ -9,8 +9,8 @@ package io.element.android.features.roomcall.impl
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import io.element.android.features.call.api.CurrentCall import io.element.android.features.call.api.CurrentCall
import io.element.android.features.call.api.CurrentCallObserver import io.element.android.features.call.api.CurrentCallService
import io.element.android.features.call.test.FakeCurrentCallObserver import io.element.android.features.call.test.FakeCurrentCallService
import io.element.android.features.roomcall.api.RoomCallState import io.element.android.features.roomcall.api.RoomCallState
import io.element.android.libraries.matrix.api.room.MatrixRoom import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
@@ -112,7 +112,7 @@ class RoomCallStatePresenterTest {
} }
val presenter = createRoomCallStatePresenter( val presenter = createRoomCallStatePresenter(
matrixRoom = room, matrixRoom = room,
currentCallObserver = FakeCurrentCallObserver(initialValue = CurrentCall.RoomCall(room.roomId)), currentCallService = FakeCurrentCallService(initialValue = CurrentCall.RoomCall(room.roomId)),
) )
presenter.test { presenter.test {
skipItems(1) skipItems(1)
@@ -138,10 +138,10 @@ class RoomCallStatePresenterTest {
) )
) )
} }
val currentCallObserver = FakeCurrentCallObserver(initialValue = CurrentCall.RoomCall(room.roomId)) val currentCallService = FakeCurrentCallService(initialValue = CurrentCall.RoomCall(room.roomId))
val presenter = createRoomCallStatePresenter( val presenter = createRoomCallStatePresenter(
matrixRoom = room, matrixRoom = room,
currentCallObserver = currentCallObserver currentCallService = currentCallService
) )
presenter.test { presenter.test {
skipItems(1) skipItems(1)
@@ -152,7 +152,7 @@ class RoomCallStatePresenterTest {
isUserLocallyInTheCall = true, isUserLocallyInTheCall = true,
) )
) )
currentCallObserver.setCurrentCall(CurrentCall.None) currentCallService.setCurrentCall(CurrentCall.None)
assertThat(awaitItem()).isEqualTo( assertThat(awaitItem()).isEqualTo(
RoomCallState.OnGoing( RoomCallState.OnGoing(
canJoinCall = true, canJoinCall = true,
@@ -189,11 +189,11 @@ class RoomCallStatePresenterTest {
private fun createRoomCallStatePresenter( private fun createRoomCallStatePresenter(
matrixRoom: MatrixRoom, matrixRoom: MatrixRoom,
currentCallObserver: CurrentCallObserver = FakeCurrentCallObserver(), currentCallService: CurrentCallService = FakeCurrentCallService(),
): RoomCallStatePresenter { ): RoomCallStatePresenter {
return RoomCallStatePresenter( return RoomCallStatePresenter(
room = matrixRoom, room = matrixRoom,
currentCallObserver = currentCallObserver, currentCallService = currentCallService,
) )
} }
} }