From a2c8680d7acd2874ab0efb953e37a74c6c38bb8c Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 24 Jun 2021 20:49:35 +0200 Subject: [PATCH] Fix call invite processed after call is ended because of fastlane mode. --- changelog.d/3564.bugfix | 1 + .../sdk/internal/session/call/CallEventProcessor.kt | 8 +++----- .../sdk/internal/session/call/CallSignalingHandler.kt | 5 +++-- .../sdk/internal/session/events/DefaultEventService.kt | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 changelog.d/3564.bugfix diff --git a/changelog.d/3564.bugfix b/changelog.d/3564.bugfix new file mode 100644 index 0000000000..74f71ccded --- /dev/null +++ b/changelog.d/3564.bugfix @@ -0,0 +1 @@ +Fix call invite processed after call is ended because of fastlane mode. \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallEventProcessor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallEventProcessor.kt index 8bf2014639..473adeb8d2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallEventProcessor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallEventProcessor.kt @@ -59,9 +59,8 @@ internal class CallEventProcessor @Inject constructor(private val callSignalingH return eventType == EventType.CALL_INVITE } - suspend fun processFastLane(event: Event) { - eventsToPostProcess.add(event) - onPostProcess() + fun processFastLane(event: Event) { + dispatchToCallSignalingHandlerIfNeeded(event) } override suspend fun onPostProcess() { @@ -73,13 +72,12 @@ internal class CallEventProcessor @Inject constructor(private val callSignalingH private fun dispatchToCallSignalingHandlerIfNeeded(event: Event) { val now = System.currentTimeMillis() - // TODO might check if an invite is not closed (hangup/answered) in the same event batch? event.roomId ?: return Unit.also { Timber.w("Event with no room id ${event.eventId}") } val age = now - (event.ageLocalTs ?: now) if (age > 40_000) { - // To old to ring? + // Too old to ring? return } callSignalingHandler.onCallEvent(event) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallSignalingHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallSignalingHandler.kt index d18737d31b..b0901af719 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallSignalingHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/CallSignalingHandler.kt @@ -41,6 +41,7 @@ internal class CallSignalingHandler @Inject constructor(private val activeCallHa private val mxCallFactory: MxCallFactory, @UserId private val userId: String) { + private val invitedCallIds = mutableSetOf() private val callListeners = mutableSetOf() private val callListenersDispatcher = CallListenersDispatcher(callListeners) @@ -182,17 +183,17 @@ internal class CallSignalingHandler @Inject constructor(private val activeCallHa val content = event.getClearContent().toModel() ?: return content.callId ?: return - if (activeCallHandler.getCallWithId(content.callId) != null) { + if (invitedCallIds.contains(content.callId)) { // Call is already known, maybe due to fast lane. Ignore Timber.d("Ignoring already known call invite") return } - val incomingCall = mxCallFactory.createIncomingCall( roomId = event.roomId, opponentUserId = event.senderId, content = content ) ?: return + invitedCallIds.add(content.callId) activeCallHandler.addCall(incomingCall) callListenersDispatcher.onCallInviteReceived(incomingCall, content) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt index d7e9ef2ee0..9d80f27e01 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt @@ -29,7 +29,7 @@ internal class DefaultEventService @Inject constructor( override suspend fun getEvent(roomId: String, eventId: String): Event { val event = getEventTask.execute(GetEventTask.Params(roomId, eventId)) - + event.ageLocalTs = event.unsignedData?.age?.let { System.currentTimeMillis() - it } // Fast lane to the call event processors: try to make the incoming call ring faster if (callEventProcessor.shouldProcessFastLane(event.getClearType())) { callEventProcessor.processFastLane(event)