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 7f2f601bd6..b381b3ed27 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 @@ -89,6 +89,7 @@ class DefaultActiveCallManager @Inject constructor( override fun registerIncomingCall(notificationData: CallNotificationData) { if (activeCall.value != null) { + displayMissedCallNotification(notificationData) Timber.w("Already have an active call, ignoring incoming call: $notificationData") return } @@ -99,7 +100,6 @@ class DefaultActiveCallManager @Inject constructor( ) timedOutCallJob = coroutineScope.launch { - registerIncomingCall(notificationData) showIncomingCallNotification(notificationData) // Wait for the call to end @@ -115,13 +115,7 @@ class DefaultActiveCallManager @Inject constructor( cancelIncomingCallNotification() - coroutineScope.launch { - onMissedCallNotificationHandler.addMissedCallNotification( - sessionId = previousActiveCall.sessionId, - roomId = previousActiveCall.roomId, - eventId = notificationData.eventId, - ) - } + displayMissedCallNotification(notificationData) } override fun hungUpCall() { @@ -174,6 +168,16 @@ class DefaultActiveCallManager @Inject constructor( private fun cancelIncomingCallNotification() { notificationManagerCompat.cancel(NotificationIdProvider.getForegroundServiceNotificationId(ForegroundServiceType.INCOMING_CALL)) } + + private fun displayMissedCallNotification(notificationData: CallNotificationData) { + coroutineScope.launch { + onMissedCallNotificationHandler.addMissedCallNotification( + sessionId = notificationData.sessionId, + roomId = notificationData.roomId, + eventId = notificationData.eventId, + ) + } + } } /** diff --git a/features/call/impl/src/test/kotlin/io/element/android/features/call/utils/DefaultActiveCallManagerTest.kt b/features/call/impl/src/test/kotlin/io/element/android/features/call/utils/DefaultActiveCallManagerTest.kt index 3ae95665be..92b727c05f 100644 --- a/features/call/impl/src/test/kotlin/io/element/android/features/call/utils/DefaultActiveCallManagerTest.kt +++ b/features/call/impl/src/test/kotlin/io/element/android/features/call/utils/DefaultActiveCallManagerTest.kt @@ -27,6 +27,7 @@ import io.element.android.features.call.test.aCallNotificationData import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.SessionId +import io.element.android.libraries.matrix.test.AN_EVENT_ID import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_ROOM_ID_2 import io.element.android.libraries.matrix.test.A_SESSION_ID @@ -39,10 +40,12 @@ import io.element.android.libraries.push.test.notifications.FakeImageLoaderHolde import io.element.android.libraries.push.test.notifications.FakeOnMissedCallNotificationHandler import io.element.android.libraries.push.test.notifications.push.FakeNotificationBitmapLoader import io.element.android.tests.testutils.lambda.lambdaRecorder +import io.element.android.tests.testutils.lambda.value import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.advanceTimeBy import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Test @@ -77,9 +80,14 @@ class DefaultActiveCallManagerTest { verify { notificationManagerCompat.notify(notificationId, any()) } } + @OptIn(ExperimentalCoroutinesApi::class) @Test - fun `registerIncomingCall - when there is an already active call does nothing`() = runTest { - val manager = createActiveCallManager() + fun `registerIncomingCall - when there is an already active call adds missed call notification`() = runTest { + val addMissedCallNotificationLambda = lambdaRecorder { _, _, _ -> } + val onMissedCallNotificationHandler = FakeOnMissedCallNotificationHandler(addMissedCallNotificationLambda = addMissedCallNotificationLambda) + val manager = createActiveCallManager( + onMissedCallNotificationHandler = onMissedCallNotificationHandler, + ) // Register existing call val callNotificationData = aCallNotificationData() @@ -91,6 +99,12 @@ class DefaultActiveCallManagerTest { assertThat(manager.activeCall.value).isEqualTo(activeCall) assertThat(manager.activeCall.value?.roomId).isNotEqualTo(A_ROOM_ID_2) + + advanceTimeBy(1) + + addMissedCallNotificationLambda.assertions() + .isCalledOnce() + .with(value(A_SESSION_ID), value(A_ROOM_ID_2), value(AN_EVENT_ID)) } @Test @@ -119,12 +133,10 @@ class DefaultActiveCallManagerTest { assertThat(manager.activeCall.value).isNotNull() manager.incomingCallTimedOut() - assertThat(manager.activeCall.value).isNull() - - runCurrent() + advanceTimeBy(1) + assertThat(manager.activeCall.value).isNull() addMissedCallNotificationLambda.assertions().isCalledOnce() - verify { notificationManagerCompat.cancel(notificationId) } } diff --git a/libraries/matrix/api/src/test/kotlin/io/element/android/libraries/matrix/api/notification/NotificationDataTest.kt b/libraries/matrix/api/src/test/kotlin/io/element/android/libraries/matrix/api/notification/NotificationDataTest.kt index 0bd661637c..cb9eee808e 100644 --- a/libraries/matrix/api/src/test/kotlin/io/element/android/libraries/matrix/api/notification/NotificationDataTest.kt +++ b/libraries/matrix/api/src/test/kotlin/io/element/android/libraries/matrix/api/notification/NotificationDataTest.kt @@ -17,9 +17,8 @@ package io.element.android.libraries.matrix.api.notification import com.google.common.truth.Truth.assertThat -import io.element.android.libraries.matrix.test.AN_EVENT_ID -import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_USER_ID +import io.element.android.libraries.matrix.test.notification.aNotificationData import org.junit.Test class NotificationDataTest { @@ -49,25 +48,4 @@ class NotificationDataTest { ) assertThat(sut.getDisambiguatedDisplayName(A_USER_ID)).isEqualTo("Alice (@alice:server.org)") } - - private fun aNotificationData( - senderDisplayName: String?, - senderIsNameAmbiguous: Boolean, - ): NotificationData { - return NotificationData( - eventId = AN_EVENT_ID, - roomId = A_ROOM_ID, - senderAvatarUrl = null, - senderDisplayName = senderDisplayName, - senderIsNameAmbiguous = senderIsNameAmbiguous, - roomAvatarUrl = null, - roomDisplayName = null, - isDirect = false, - isEncrypted = false, - isNoisy = false, - timestamp = 0L, - content = NotificationContent.MessageLike.RoomEncrypted, - hasMention = false, - ) - } } diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notification/NotificationData.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notification/NotificationData.kt new file mode 100644 index 0000000000..330db62274 --- /dev/null +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/notification/NotificationData.kt @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.libraries.matrix.test.notification + +import io.element.android.libraries.matrix.api.notification.NotificationContent +import io.element.android.libraries.matrix.api.notification.NotificationData +import io.element.android.libraries.matrix.test.AN_EVENT_ID +import io.element.android.libraries.matrix.test.A_ROOM_ID + +fun aNotificationData( + senderDisplayName: String?, + senderIsNameAmbiguous: Boolean, +): NotificationData { + return NotificationData( + eventId = AN_EVENT_ID, + roomId = A_ROOM_ID, + senderAvatarUrl = null, + senderDisplayName = senderDisplayName, + senderIsNameAmbiguous = senderIsNameAmbiguous, + roomAvatarUrl = null, + roomDisplayName = null, + isDirect = false, + isEncrypted = false, + isNoisy = false, + timestamp = 0L, + content = NotificationContent.MessageLike.RoomEncrypted, + hasMention = false, + ) +} diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/CallNotificationEventResolver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/CallNotificationEventResolver.kt new file mode 100644 index 0000000000..b14fcdeab3 --- /dev/null +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/CallNotificationEventResolver.kt @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.libraries.push.impl.notifications + +import com.squareup.anvil.annotations.ContributesBinding +import io.element.android.libraries.di.AppScope +import io.element.android.libraries.matrix.api.core.SessionId +import io.element.android.libraries.matrix.api.notification.NotificationContent +import io.element.android.libraries.matrix.api.notification.NotificationData +import io.element.android.libraries.matrix.api.timeline.item.event.EventType +import io.element.android.libraries.push.impl.R +import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent +import io.element.android.libraries.push.impl.notifications.model.NotifiableRingingCallEvent +import io.element.android.services.toolbox.api.strings.StringProvider +import javax.inject.Inject + +/** + * Helper to resolve a valid [NotifiableEvent] from a [NotificationData]. + */ +interface CallNotificationEventResolver { + /** + * Resolve a call notification event from a notification data depending on whether it should be a ringing one or not. + * @param sessionId the current session id + * @param notificationData the notification data + * @param forceNotify `true` to force the notification to be non-ringing, `false` to use the default behaviour. Default is `false`. + * @return a [NotifiableEvent] if the notification data is a call notification, null otherwise + */ + fun resolveEvent(sessionId: SessionId, notificationData: NotificationData, forceNotify: Boolean = false): NotifiableEvent? +} + +@ContributesBinding(AppScope::class) +class DefaultCallNotificationEventResolver @Inject constructor( + private val stringProvider: StringProvider, +) : CallNotificationEventResolver { + override fun resolveEvent(sessionId: SessionId, notificationData: NotificationData, forceNotify: Boolean): NotifiableEvent? { + val content = notificationData.content as? NotificationContent.MessageLike.CallNotify ?: return null + return notificationData.run { + if (NotifiableRingingCallEvent.shouldRing(content.type, timestamp) && !forceNotify) { + NotifiableRingingCallEvent( + sessionId = sessionId, + roomId = roomId, + eventId = eventId, + roomName = roomDisplayName, + editedEventId = null, + canBeReplaced = true, + timestamp = this.timestamp, + isRedacted = false, + isUpdated = false, + description = stringProvider.getString(R.string.notification_incoming_call), + senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId), + roomAvatarUrl = roomAvatarUrl, + callNotifyType = content.type, + senderId = content.senderId, + senderAvatarUrl = senderAvatarUrl, + ) + } else { + // Create a simple message notification event + buildNotifiableMessageEvent( + sessionId = sessionId, + senderId = content.senderId, + roomId = roomId, + eventId = eventId, + noisy = true, + timestamp = this.timestamp, + senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId), + body = "☎️ ${stringProvider.getString(R.string.notification_incoming_call)}", + roomName = roomDisplayName, + roomIsDirect = isDirect, + roomAvatarPath = roomAvatarUrl, + senderAvatarPath = senderAvatarUrl, + type = EventType.CALL_NOTIFY, + ) + } + } + } +} diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt index 646bbaa621..30ede8f3d1 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolver.kt @@ -52,7 +52,6 @@ import io.element.android.libraries.push.impl.notifications.model.FallbackNotifi import io.element.android.libraries.push.impl.notifications.model.InviteNotifiableEvent import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent import io.element.android.libraries.push.impl.notifications.model.NotifiableMessageEvent -import io.element.android.libraries.push.impl.notifications.model.NotifiableRingingCallEvent import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.services.toolbox.api.strings.StringProvider import io.element.android.services.toolbox.api.systemclock.SystemClock @@ -79,6 +78,7 @@ class DefaultNotifiableEventResolver @Inject constructor( private val notificationMediaRepoFactory: NotificationMediaRepo.Factory, @ApplicationContext private val context: Context, private val permalinkParser: PermalinkParser, + private val callNotificationEventResolver: CallNotificationEventResolver, ) : NotifiableEventResolver { override suspend fun resolveEvent(sessionId: SessionId, roomId: RoomId, eventId: EventId): NotifiableEvent? { // Restore session @@ -174,42 +174,7 @@ class DefaultNotifiableEventResolver @Inject constructor( ) } is NotificationContent.MessageLike.CallNotify -> { - if (NotifiableRingingCallEvent.shouldRing(content.type, timestamp)) { - NotifiableRingingCallEvent( - sessionId = userId, - roomId = roomId, - eventId = eventId, - roomName = roomDisplayName, - editedEventId = null, - canBeReplaced = true, - timestamp = this.timestamp, - isRedacted = false, - isUpdated = false, - description = stringProvider.getString(R.string.notification_incoming_call), - senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId), - roomAvatarUrl = roomAvatarUrl, - callNotifyType = content.type, - senderId = content.senderId, - senderAvatarUrl = senderAvatarUrl, - ) - } else { - // Create a simple message notification event - buildNotifiableMessageEvent( - sessionId = userId, - senderId = content.senderId, - roomId = roomId, - eventId = eventId, - noisy = true, - timestamp = this.timestamp, - senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId), - body = "☎️ ${stringProvider.getString(R.string.notification_incoming_call)}", - roomName = roomDisplayName, - roomIsDirect = isDirect, - roomAvatarPath = roomAvatarUrl, - senderAvatarPath = senderAvatarUrl, - type = EventType.CALL_NOTIFY, - ) - } + callNotificationEventResolver.resolveEvent(userId, this) } NotificationContent.MessageLike.KeyVerificationAccept, NotificationContent.MessageLike.KeyVerificationCancel, @@ -349,7 +314,7 @@ class DefaultNotifiableEventResolver @Inject constructor( } @Suppress("LongParameterList") -private fun buildNotifiableMessageEvent( +internal fun buildNotifiableMessageEvent( sessionId: SessionId, senderId: UserId, roomId: RoomId, diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandler.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandler.kt index 7a62f53d39..dcc1fce3a8 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandler.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandler.kt @@ -18,6 +18,7 @@ package io.element.android.libraries.push.impl.notifications import com.squareup.anvil.annotations.ContributesBinding import io.element.android.libraries.di.AppScope +import io.element.android.libraries.matrix.api.MatrixClientProvider import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.core.SessionId @@ -26,8 +27,9 @@ import javax.inject.Inject @ContributesBinding(AppScope::class) class DefaultOnMissedCallNotificationHandler @Inject constructor( + private val matrixClientProvider: MatrixClientProvider, private val defaultNotificationDrawerManager: DefaultNotificationDrawerManager, - private val notifiableEventResolver: NotifiableEventResolver, + private val callNotificationEventResolver: CallNotificationEventResolver, ) : OnMissedCallNotificationHandler { override suspend fun addMissedCallNotification( sessionId: SessionId, @@ -35,7 +37,18 @@ class DefaultOnMissedCallNotificationHandler @Inject constructor( eventId: EventId, ) { // Resolve the event and add a notification for it, at this point it should no longer be a ringing one - val notifiableEvent = notifiableEventResolver.resolveEvent(sessionId, roomId, eventId) + val notificationData = matrixClientProvider.getOrRestore(sessionId).getOrNull() + ?.notificationService() + ?.getNotification(sessionId, roomId, eventId) + ?.getOrNull() + ?: return + + val notifiableEvent = callNotificationEventResolver.resolveEvent( + sessionId = sessionId, + notificationData = notificationData, + // Make sure the notifiable event is not a ringing one + forceNotify = true, + ) notifiableEvent?.let { defaultNotificationDrawerManager.onNotifiableEventReceived(it) } } } diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt index afcdc90b9d..6caaac207b 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotifiableEventResolverTest.kt @@ -660,6 +660,9 @@ class DefaultNotifiableEventResolverTest { notificationMediaRepoFactory = notificationMediaRepoFactory, context = context, permalinkParser = FakePermalinkParser(), + callNotificationEventResolver = DefaultCallNotificationEventResolver( + stringProvider = AndroidStringProvider(context.resources) + ), ) } diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt index ce2a698ae1..34be1bc1e6 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/DefaultOnMissedCallNotificationHandlerTest.kt @@ -19,11 +19,16 @@ package io.element.android.libraries.push.impl.notifications import io.element.android.libraries.matrix.test.AN_EVENT_ID import io.element.android.libraries.matrix.test.A_ROOM_ID import io.element.android.libraries.matrix.test.A_SESSION_ID +import io.element.android.libraries.matrix.test.A_USER_NAME +import io.element.android.libraries.matrix.test.FakeMatrixClient import io.element.android.libraries.matrix.test.FakeMatrixClientProvider +import io.element.android.libraries.matrix.test.notification.FakeNotificationService +import io.element.android.libraries.matrix.test.notification.aNotificationData import io.element.android.libraries.push.impl.notifications.fake.FakeActiveNotificationsProvider import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationDataFactory import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationDisplayer import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent +import io.element.android.libraries.push.test.notifications.FakeCallNotificationEventResolver import io.element.android.libraries.push.test.notifications.FakeImageLoaderHolder import io.element.android.services.appnavstate.test.FakeAppNavigationStateService import io.element.android.tests.testutils.lambda.lambdaRecorder @@ -47,7 +52,15 @@ class DefaultOnMissedCallNotificationHandlerTest { val dataFactory = FakeNotificationDataFactory( messageEventToNotificationsResult = lambdaRecorder { _, _, _ -> emptyList() } ) + // Create a fake matrix client provider that returns a fake matrix client with a fake notification service that returns a valid notification data + val matrixClientProvider = FakeMatrixClientProvider(getClient = { + val notificationService = FakeNotificationService().apply { + givenGetNotificationResult(Result.success(aNotificationData(senderDisplayName = A_USER_NAME, senderIsNameAmbiguous = false))) + } + Result.success(FakeMatrixClient(notificationService = notificationService)) + }) val defaultOnMissedCallNotificationHandler = DefaultOnMissedCallNotificationHandler( + matrixClientProvider = matrixClientProvider, defaultNotificationDrawerManager = DefaultNotificationDrawerManager( notificationManager = mockk(relaxed = true), notificationRenderer = NotificationRenderer( @@ -60,7 +73,7 @@ class DefaultOnMissedCallNotificationHandlerTest { imageLoaderHolder = FakeImageLoaderHolder(), activeNotificationsProvider = FakeActiveNotificationsProvider(), ), - notifiableEventResolver = FakeNotifiableEventResolver(notifiableEventResult = { _, _, _ -> aNotifiableMessageEvent() }), + callNotificationEventResolver = FakeCallNotificationEventResolver(resolveEventLambda = { _, _, _ -> aNotifiableMessageEvent() }), ) defaultOnMissedCallNotificationHandler.addMissedCallNotification( diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fixtures/NotifiableEventFixture.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fixtures/NotifiableEventFixture.kt index cd2c66178f..fabe4bd353 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fixtures/NotifiableEventFixture.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/fixtures/NotifiableEventFixture.kt @@ -104,7 +104,7 @@ fun aNotifiableMessageEvent( type = type, ) -fun anNotifiableCallEvent( +fun aNotifiableCallEvent( sessionId: SessionId = A_SESSION_ID, roomId: RoomId = A_ROOM_ID, eventId: EventId = AN_EVENT_ID, diff --git a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt index 9205a72530..9e37aae29d 100644 --- a/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt +++ b/libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandlerTest.kt @@ -37,8 +37,8 @@ import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationSer import io.element.android.libraries.matrix.test.core.aBuildMeta import io.element.android.libraries.push.impl.notifications.FakeNotifiableEventResolver import io.element.android.libraries.push.impl.notifications.channels.FakeNotificationChannels +import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableCallEvent import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent -import io.element.android.libraries.push.impl.notifications.fixtures.anNotifiableCallEvent import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent import io.element.android.libraries.push.impl.test.DefaultTestPush import io.element.android.libraries.push.impl.troubleshoot.DiagnosticPushHandler @@ -240,7 +240,7 @@ class DefaultPushHandlerTest { val elementCallEntryPoint = FakeElementCallEntryPoint(handleIncomingCallResult = handleIncomingCallLambda) val defaultPushHandler = createDefaultPushHandler( elementCallEntryPoint = elementCallEntryPoint, - notifiableEventResult = { _, _, _ -> anNotifiableCallEvent(callNotifyType = CallNotifyType.RING, timestamp = Instant.now().toEpochMilli()) }, + notifiableEventResult = { _, _, _ -> aNotifiableCallEvent(callNotifyType = CallNotifyType.RING, timestamp = Instant.now().toEpochMilli()) }, incrementPushCounterResult = {}, pushClientSecret = FakePushClientSecret( getUserIdFromSecretResult = { A_USER_ID } diff --git a/libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/notifications/FakeCallNotificationEventResolver.kt b/libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/notifications/FakeCallNotificationEventResolver.kt new file mode 100644 index 0000000000..b8fc620619 --- /dev/null +++ b/libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/notifications/FakeCallNotificationEventResolver.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.libraries.push.test.notifications + +import io.element.android.libraries.matrix.api.core.SessionId +import io.element.android.libraries.matrix.api.notification.NotificationData +import io.element.android.libraries.push.impl.notifications.CallNotificationEventResolver +import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent + +class FakeCallNotificationEventResolver( + var resolveEventLambda: (sessionId: SessionId, notificationData: NotificationData, forceNotify: Boolean) -> NotifiableEvent? = { _, _, _ -> null }, +) : CallNotificationEventResolver { + override fun resolveEvent(sessionId: SessionId, notificationData: NotificationData, forceNotify: Boolean): NotifiableEvent? { + return resolveEventLambda(sessionId, notificationData, forceNotify) + } +}