From 6d9877d79c156fdb2137c036e4e02995a8444f00 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 21 Oct 2021 11:51:28 +0100 Subject: [PATCH] filtering out redacted simple message events, we handle them by updating the notifications --- .../notifications/NotifiableEventProcessor.kt | 6 +++++- .../NotifiableEventProcessorTest.kt | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventProcessor.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventProcessor.kt index 858df81bf6..3d10d74fe3 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventProcessor.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventProcessor.kt @@ -19,6 +19,7 @@ package im.vector.app.features.notifications import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.notifications.ProcessedEvent.Type.KEEP import im.vector.app.features.notifications.ProcessedEvent.Type.REMOVE +import org.matrix.android.sdk.api.session.events.model.EventType import javax.inject.Inject private typealias ProcessedEvents = List> @@ -35,7 +36,10 @@ class NotifiableEventProcessor @Inject constructor( is NotifiableMessageEvent -> if (shouldIgnoreMessageEventInRoom(currentRoomId, it.roomId) || outdatedDetector.isMessageOutdated(it)) { REMOVE } else KEEP - is SimpleNotifiableEvent -> KEEP + is SimpleNotifiableEvent -> when (it.type) { + EventType.REDACTION -> REMOVE + else -> KEEP + } } ProcessedEvent(type, it) } diff --git a/vector/src/test/java/im/vector/app/features/notifications/NotifiableEventProcessorTest.kt b/vector/src/test/java/im/vector/app/features/notifications/NotifiableEventProcessorTest.kt index f6938cb4ae..229ab39d1d 100644 --- a/vector/src/test/java/im/vector/app/features/notifications/NotifiableEventProcessorTest.kt +++ b/vector/src/test/java/im/vector/app/features/notifications/NotifiableEventProcessorTest.kt @@ -21,6 +21,7 @@ import im.vector.app.test.fakes.FakeAutoAcceptInvites import im.vector.app.test.fakes.FakeOutdatedEventDetector import org.amshove.kluent.shouldBeEqualTo import org.junit.Test +import org.matrix.android.sdk.api.session.events.model.EventType private val NOT_VIEWING_A_ROOM: String? = null @@ -46,6 +47,17 @@ class NotifiableEventProcessorTest { ) } + @Test + fun `given redacted simple event when processing then remove redaction event`() { + val events = listOf(aSimpleNotifiableEvent(eventId = "event-1", type = EventType.REDACTION)) + + val result = eventProcessor.process(events, currentRoomId = NOT_VIEWING_A_ROOM, renderedEvents = emptyList()) + + result shouldBeEqualTo listOfProcessedEvents( + Type.REMOVE to events[0] + ) + } + @Test fun `given invites are auto accepted when processing then remove invitations`() { autoAcceptInvites._isEnabled = true @@ -134,14 +146,14 @@ class NotifiableEventProcessorTest { } } -fun aSimpleNotifiableEvent(eventId: String) = SimpleNotifiableEvent( +fun aSimpleNotifiableEvent(eventId: String, type: String? = null) = SimpleNotifiableEvent( matrixID = null, eventId = eventId, editedEventId = null, noisy = false, title = "title", description = "description", - type = null, + type = type, timestamp = 0, soundName = null, canBeReplaced = false,