Code cleanup. Avoid usage of !!

This commit is contained in:
Benoit Marty 2025-09-11 16:21:32 +02:00
parent 3ee2e5575b
commit 2db74ce9e5

View file

@ -180,20 +180,21 @@ class DefaultActiveCallManager(
} }
override suspend fun hungUpCall(callType: CallType) = mutex.withLock { 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") Timber.tag(tag).w("Call type $callType does not match the active call type, ignoring")
return return
} }
if (currentActiveCall.callState is CallState.Ringing) {
Timber.tag(tag).d("Hung up call: $callType")
if (activeCall.value?.callState is CallState.Ringing) {
val ringing = activeCall.value!!.callState as CallState.Ringing
// Decline the call // Decline the call
matrixClientProvider.getOrRestore(ringing.notificationData.sessionId).getOrNull()?.let { client -> val notificationData = currentActiveCall.callState.notificationData
client.getRoom(ringing.notificationData.roomId)?.let { room -> matrixClientProvider.getOrRestore(notificationData.sessionId).getOrNull()
room.declineCall(ringing.notificationData.eventId) ?.getRoom(notificationData.roomId)
} ?.declineCall(notificationData.eventId)
}
} }
cancelIncomingCallNotification() cancelIncomingCallNotification()