From 0a6dc6a294351551720bc282b7328e459a5fa479 Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 23 Feb 2025 20:16:52 +0700 Subject: [PATCH] Show error screens in group calls Element Call now sends a 'close' widget action when the widget is ready to close. Usually this will be sent immediately after the 'hangup' action, but it could be sent later if the widget wants to present an error screen before closing. So by listening to the 'close' action rather than the 'hangup' action, we get to see these error screens. --- .../element/android/features/call/impl/data/WidgetMessage.kt | 3 +++ .../android/features/call/impl/ui/CallScreenPresenter.kt | 2 +- .../android/features/call/ui/CallScreenPresenterTest.kt | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/data/WidgetMessage.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/data/WidgetMessage.kt index df518caeee..0e9ddbe364 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/data/WidgetMessage.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/data/WidgetMessage.kt @@ -33,6 +33,9 @@ data class WidgetMessage( @SerialName("im.vector.hangup") HangUp, + @SerialName("io.element.close") + Close, + @SerialName("send_event") SendEvent, } diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt index ac0c89f0fd..47f5682f4c 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt @@ -135,7 +135,7 @@ class CallScreenPresenter @AssistedInject constructor( val parsedMessage = parseMessage(it) if (parsedMessage?.direction == WidgetMessage.Direction.FromWidget) { - if (parsedMessage.action == WidgetMessage.Action.HangUp) { + if (parsedMessage.action == WidgetMessage.Action.Close) { close(callWidgetDriver.value, navigator) } else if (parsedMessage.action == WidgetMessage.Action.SendEvent) { // This event is received when a member joins the call, the first one will be the current one diff --git a/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt b/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt index fb894ac9de..ce185bcdfc 100644 --- a/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt +++ b/features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt @@ -174,7 +174,7 @@ class CallScreenPresenterTest { @OptIn(ExperimentalCoroutinesApi::class) @Test - fun `present - a received hang up message closes the screen and stops the widget driver`() = runTest(UnconfinedTestDispatcher()) { + fun `present - a received close message closes the screen and stops the widget driver`() = runTest(UnconfinedTestDispatcher()) { val navigator = FakeCallScreenNavigator() val widgetDriver = FakeMatrixWidgetDriver() val presenter = createCallScreenPresenter( @@ -191,7 +191,7 @@ class CallScreenPresenterTest { val initialState = awaitItem() initialState.eventSink(CallScreenEvents.SetupMessageChannels(messageInterceptor)) - messageInterceptor.givenInterceptedMessage("""{"action":"im.vector.hangup","api":"fromWidget","widgetId":"1","requestId":"1"}""") + messageInterceptor.givenInterceptedMessage("""{"action":"io.element.close","api":"fromWidget","widgetId":"1","requestId":"1"}""") // Let background coroutines run runCurrent()