From 2db74ce9e59f51be30b5f867a45f3eb5a7f82a4a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 11 Sep 2025 16:21:32 +0200 Subject: [PATCH] Code cleanup. Avoid usage of !! --- .../call/impl/utils/ActiveCallManager.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/ActiveCallManager.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/ActiveCallManager.kt index a3591ff945..6ec35009f9 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/ActiveCallManager.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/ActiveCallManager.kt @@ -180,20 +180,21 @@ class DefaultActiveCallManager( } override suspend fun hungUpCall(callType: CallType) = mutex.withLock { - if (activeCall.value?.callType != callType) { + Timber.tag(tag).d("Hung up call: $callType") + val currentActiveCall = activeCall.value ?: run { + Timber.tag(tag).w("No active call, ignoring hang up") + return + } + if (currentActiveCall.callType != callType) { Timber.tag(tag).w("Call type $callType does not match the active call type, ignoring") return } - - Timber.tag(tag).d("Hung up call: $callType") - if (activeCall.value?.callState is CallState.Ringing) { - val ringing = activeCall.value!!.callState as CallState.Ringing + if (currentActiveCall.callState is CallState.Ringing) { // Decline the call - matrixClientProvider.getOrRestore(ringing.notificationData.sessionId).getOrNull()?.let { client -> - client.getRoom(ringing.notificationData.roomId)?.let { room -> - room.declineCall(ringing.notificationData.eventId) - } - } + val notificationData = currentActiveCall.callState.notificationData + matrixClientProvider.getOrRestore(notificationData.sessionId).getOrNull() + ?.getRoom(notificationData.roomId) + ?.declineCall(notificationData.eventId) } cancelIncomingCallNotification()