Stop incoming ringing call when answered on another session.
This commit is contained in:
parent
57ced5423a
commit
f1b23ff416
1 changed files with 17 additions and 8 deletions
|
|
@ -109,7 +109,7 @@ class DefaultActiveCallManager @Inject constructor(
|
||||||
|
|
||||||
// Wait for the ringing call to time out
|
// Wait for the ringing call to time out
|
||||||
delay(ElementCallConfig.RINGING_CALL_DURATION_SECONDS.seconds)
|
delay(ElementCallConfig.RINGING_CALL_DURATION_SECONDS.seconds)
|
||||||
incomingCallTimedOut()
|
incomingCallTimedOut(displayMissedCallNotification = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,14 +117,16 @@ class DefaultActiveCallManager @Inject constructor(
|
||||||
* Called when the incoming call timed out. It will remove the active call and remove any associated UI, adding a 'missed call' notification.
|
* Called when the incoming call timed out. It will remove the active call and remove any associated UI, adding a 'missed call' notification.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
fun incomingCallTimedOut() {
|
fun incomingCallTimedOut(displayMissedCallNotification: Boolean) {
|
||||||
val previousActiveCall = activeCall.value ?: return
|
val previousActiveCall = activeCall.value ?: return
|
||||||
val notificationData = (previousActiveCall.callState as? CallState.Ringing)?.notificationData ?: return
|
val notificationData = (previousActiveCall.callState as? CallState.Ringing)?.notificationData ?: return
|
||||||
activeCall.value = null
|
activeCall.value = null
|
||||||
|
|
||||||
cancelIncomingCallNotification()
|
cancelIncomingCallNotification()
|
||||||
|
|
||||||
displayMissedCallNotification(notificationData)
|
if (displayMissedCallNotification) {
|
||||||
|
displayMissedCallNotification(notificationData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hungUpCall(callType: CallType) {
|
override fun hungUpCall(callType: CallType) {
|
||||||
|
|
@ -186,28 +188,35 @@ class DefaultActiveCallManager @Inject constructor(
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
private fun observeRingingCall() {
|
private fun observeRingingCall() {
|
||||||
// This will observe ringing calls and ensure they're terminated if the room call is cancelled
|
// This will observe ringing calls and ensure they're terminated if the room call is cancelled or if the user
|
||||||
|
// has joined the call from another session.
|
||||||
activeCall
|
activeCall
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.filter { it.callState is CallState.Ringing && it.callType is CallType.RoomCall }
|
.filter { it.callState is CallState.Ringing && it.callType is CallType.RoomCall }
|
||||||
.flatMapLatest { activeCall ->
|
.flatMapLatest { activeCall ->
|
||||||
val callType = activeCall.callType as CallType.RoomCall
|
val callType = activeCall.callType as CallType.RoomCall
|
||||||
// Get a flow of updated `hasRoomCall` values for the room
|
// Get a flow of updated `hasRoomCall` and `activeRoomCallParticipants` values for the room
|
||||||
matrixClientProvider.getOrRestore(callType.sessionId).getOrNull()
|
matrixClientProvider.getOrRestore(callType.sessionId).getOrNull()
|
||||||
?.getRoom(callType.roomId)
|
?.getRoom(callType.roomId)
|
||||||
?.roomInfoFlow
|
?.roomInfoFlow
|
||||||
?.map { it.hasRoomCall }
|
?.map {
|
||||||
|
it.hasRoomCall to (callType.sessionId in it.activeRoomCallParticipants)
|
||||||
|
}
|
||||||
?: flowOf()
|
?: flowOf()
|
||||||
}
|
}
|
||||||
// We only want to check if the room active call status changes
|
// We only want to check if the room active call status changes
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
// Skip the first one, we're not interested in it (if the check below passes, it had to be active anyway)
|
// Skip the first one, we're not interested in it (if the check below passes, it had to be active anyway)
|
||||||
.drop(1)
|
.drop(1)
|
||||||
.onEach { roomHasActiveCall ->
|
.onEach { (roomHasActiveCall, userIsInTheCall) ->
|
||||||
if (!roomHasActiveCall) {
|
if (!roomHasActiveCall) {
|
||||||
// The call was cancelled
|
// The call was cancelled
|
||||||
timedOutCallJob?.cancel()
|
timedOutCallJob?.cancel()
|
||||||
incomingCallTimedOut()
|
incomingCallTimedOut(displayMissedCallNotification = true)
|
||||||
|
} else if (userIsInTheCall) {
|
||||||
|
// The user joined the call from another session
|
||||||
|
timedOutCallJob?.cancel()
|
||||||
|
incomingCallTimedOut(displayMissedCallNotification = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.launchIn(coroutineScope)
|
.launchIn(coroutineScope)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue