mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
Native call: always ask the core to ring, and ring a DM only once its member has joined
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+2
@@ -42,6 +42,8 @@ class DefaultNativeCallEntryPoint(
|
||||
ElementCallData(
|
||||
roomId = RoomId(callData.roomId.value),
|
||||
isAudioCall = callData.isAudioCall,
|
||||
// Temporary, to be removed from the library soon: the core already skips the ring when anyone else is in the call.
|
||||
isStartingCall = true,
|
||||
)
|
||||
)
|
||||
// The call screen asks for the microphone itself, and is where the answer normally comes
|
||||
|
||||
+4
-1
@@ -8,6 +8,7 @@
|
||||
package io.element.android.features.callnative.impl
|
||||
|
||||
import io.element.android.call.api.ElementCallData
|
||||
import io.element.android.call.api.ElementCallEndReason
|
||||
import io.element.android.call.api.ElementCallLifecycleListener
|
||||
import io.element.android.features.call.api.CallData
|
||||
import io.element.android.features.call.api.CurrentCall
|
||||
@@ -19,6 +20,7 @@ import io.element.android.services.appnavstate.api.AppForegroundStateService
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Reports a native call back to the parts of Element X that already track calls.
|
||||
@@ -47,7 +49,8 @@ class ElementXCallLifecycleListener(
|
||||
sessionCoroutineScope.launch { ringingCallTracker.onCallJoined(callData.toCallData()) }
|
||||
}
|
||||
|
||||
override fun onCallEnded(callData: ElementCallData?) {
|
||||
override fun onCallEnded(callData: ElementCallData?, reason: ElementCallEndReason) {
|
||||
Timber.i("Native call ended: $reason")
|
||||
currentCallTracker.onCallEnded()
|
||||
callData?.let { sessionCoroutineScope.launch { ringingCallTracker.onCallEnded(it.toCallData()) } }
|
||||
}
|
||||
|
||||
+4
-3
@@ -9,6 +9,7 @@ package io.element.android.features.callnative.impl
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.call.api.ElementCallData
|
||||
import io.element.android.call.api.ElementCallEndReason
|
||||
import io.element.android.call.api.rtc.id.RoomId
|
||||
import io.element.android.features.call.api.CurrentCall
|
||||
import io.element.android.features.call.test.FakeCurrentCallTracker
|
||||
@@ -30,7 +31,7 @@ class ElementXCallLifecycleListenerTest {
|
||||
val listener = createListener(currentCallTracker = currentCallTracker)
|
||||
|
||||
listener.onCallStarted(A_CALL)
|
||||
listener.onCallEnded(A_CALL)
|
||||
listener.onCallEnded(A_CALL, ElementCallEndReason.LEFT)
|
||||
|
||||
assertThat(currentCallTracker.calls).containsExactly(
|
||||
CurrentCall.RoomCall(A_ROOM_ID),
|
||||
@@ -59,7 +60,7 @@ class ElementXCallLifecycleListenerTest {
|
||||
ringingCallTracker = ringingCallTracker,
|
||||
)
|
||||
|
||||
listener.onCallEnded(null)
|
||||
listener.onCallEnded(null, ElementCallEndReason.LEFT)
|
||||
runCurrent()
|
||||
|
||||
// The current call is always cleared; only the ring needs to know which call it was.
|
||||
@@ -79,6 +80,6 @@ class ElementXCallLifecycleListenerTest {
|
||||
)
|
||||
|
||||
private companion object {
|
||||
val A_CALL = ElementCallData(roomId = RoomId(A_ROOM_ID.value), isAudioCall = true)
|
||||
val A_CALL = ElementCallData(roomId = RoomId(A_ROOM_ID.value), isAudioCall = true, isStartingCall = true)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -61,7 +61,8 @@ class RoomCallStatePresenter(
|
||||
isAudioCall = roomInfo.activeCallIntentConsensus.isAudio(),
|
||||
)
|
||||
else -> {
|
||||
val isEmptyDm = roomInfo.isDm && roomInfo.activeMembersCount <= 1
|
||||
// Joined, not active: an invited member cannot be rung (feature-hq 030 R36).
|
||||
val isEmptyDm = roomInfo.isDm && roomInfo.joinedMembersCount <= 1
|
||||
RoomCallState.StandBy(
|
||||
canStartCall = canJoinCall && !isEmptyDm,
|
||||
isDM = roomInfo.isDm
|
||||
|
||||
+16
-1
@@ -85,6 +85,21 @@ class RoomCallStatePresenterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - a DM whose other member is only invited cannot be called`() = runTest {
|
||||
val room = FakeJoinedRoom(
|
||||
baseRoom = FakeBaseRoom(
|
||||
initialRoomInfo = aRoomInfo(isDm = true, activeMembersCount = 2, joinedMembersCount = 1),
|
||||
roomPermissions = roomPermissions(true),
|
||||
)
|
||||
)
|
||||
val presenter = createRoomCallStatePresenter(joinedRoom = room)
|
||||
presenter.test {
|
||||
skipItems(1)
|
||||
assertThat(awaitItem()).isEqualTo(RoomCallState.StandBy(canStartCall = false, isDM = true))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - element call not available`() = runTest {
|
||||
val room = FakeJoinedRoom(
|
||||
@@ -128,7 +143,7 @@ class RoomCallStatePresenterTest {
|
||||
fun `present - initial state - when is DM room`() = runTest {
|
||||
val room = FakeJoinedRoom(
|
||||
baseRoom = FakeBaseRoom(
|
||||
initialRoomInfo = aRoomInfo(isDm = true),
|
||||
initialRoomInfo = aRoomInfo(isDm = true, joinedMembersCount = 2),
|
||||
roomPermissions = roomPermissions(true),
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user