From 555dca38f5fe6da1d9a481a45ea7cfeb4f783b45 Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 15 Oct 2026 14:19:29 +0200 Subject: [PATCH] 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 --- .../impl/DefaultNativeCallEntryPoint.kt | 2 ++ .../impl/ElementXCallLifecycleListener.kt | 5 ++++- .../impl/ElementXCallLifecycleListenerTest.kt | 7 ++++--- .../roomcall/impl/RoomCallStatePresenter.kt | 3 ++- .../roomcall/impl/RoomCallStatePresenterTest.kt | 17 ++++++++++++++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/DefaultNativeCallEntryPoint.kt b/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/DefaultNativeCallEntryPoint.kt index 2210663376..6b40e72dbf 100644 --- a/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/DefaultNativeCallEntryPoint.kt +++ b/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/DefaultNativeCallEntryPoint.kt @@ -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 diff --git a/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListener.kt b/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListener.kt index 83ec22b392..b64617639d 100644 --- a/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListener.kt +++ b/features/callnative/impl/src/main/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListener.kt @@ -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()) } } } diff --git a/features/callnative/impl/src/test/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListenerTest.kt b/features/callnative/impl/src/test/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListenerTest.kt index 6ef057e512..1e7cc0df92 100644 --- a/features/callnative/impl/src/test/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListenerTest.kt +++ b/features/callnative/impl/src/test/kotlin/io/element/android/features/callnative/impl/ElementXCallLifecycleListenerTest.kt @@ -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) } } diff --git a/features/roomcall/impl/src/main/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenter.kt b/features/roomcall/impl/src/main/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenter.kt index 7763933a29..384b912b34 100644 --- a/features/roomcall/impl/src/main/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenter.kt +++ b/features/roomcall/impl/src/main/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenter.kt @@ -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 diff --git a/features/roomcall/impl/src/test/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenterTest.kt b/features/roomcall/impl/src/test/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenterTest.kt index 9a4c3b0af0..5b0626279f 100644 --- a/features/roomcall/impl/src/test/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenterTest.kt +++ b/features/roomcall/impl/src/test/kotlin/io/element/android/features/roomcall/impl/RoomCallStatePresenterTest.kt @@ -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), ) )