filtering out redacted simple message events, we handle them by updating the notifications

This commit is contained in:
Adam Brown 2021-10-21 11:51:28 +01:00
parent a5fe6f7212
commit 6d9877d79c
2 changed files with 19 additions and 3 deletions

View File

@ -19,6 +19,7 @@ package im.vector.app.features.notifications
import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.notifications.ProcessedEvent.Type.KEEP import im.vector.app.features.notifications.ProcessedEvent.Type.KEEP
import im.vector.app.features.notifications.ProcessedEvent.Type.REMOVE import im.vector.app.features.notifications.ProcessedEvent.Type.REMOVE
import org.matrix.android.sdk.api.session.events.model.EventType
import javax.inject.Inject import javax.inject.Inject
private typealias ProcessedEvents = List<ProcessedEvent<NotifiableEvent>> private typealias ProcessedEvents = List<ProcessedEvent<NotifiableEvent>>
@ -35,7 +36,10 @@ class NotifiableEventProcessor @Inject constructor(
is NotifiableMessageEvent -> if (shouldIgnoreMessageEventInRoom(currentRoomId, it.roomId) || outdatedDetector.isMessageOutdated(it)) { is NotifiableMessageEvent -> if (shouldIgnoreMessageEventInRoom(currentRoomId, it.roomId) || outdatedDetector.isMessageOutdated(it)) {
REMOVE REMOVE
} else KEEP } else KEEP
is SimpleNotifiableEvent -> KEEP is SimpleNotifiableEvent -> when (it.type) {
EventType.REDACTION -> REMOVE
else -> KEEP
}
} }
ProcessedEvent(type, it) ProcessedEvent(type, it)
} }

View File

@ -21,6 +21,7 @@ import im.vector.app.test.fakes.FakeAutoAcceptInvites
import im.vector.app.test.fakes.FakeOutdatedEventDetector import im.vector.app.test.fakes.FakeOutdatedEventDetector
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test import org.junit.Test
import org.matrix.android.sdk.api.session.events.model.EventType
private val NOT_VIEWING_A_ROOM: String? = null 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 @Test
fun `given invites are auto accepted when processing then remove invitations`() { fun `given invites are auto accepted when processing then remove invitations`() {
autoAcceptInvites._isEnabled = true autoAcceptInvites._isEnabled = true
@ -134,14 +146,14 @@ class NotifiableEventProcessorTest {
} }
} }
fun aSimpleNotifiableEvent(eventId: String) = SimpleNotifiableEvent( fun aSimpleNotifiableEvent(eventId: String, type: String? = null) = SimpleNotifiableEvent(
matrixID = null, matrixID = null,
eventId = eventId, eventId = eventId,
editedEventId = null, editedEventId = null,
noisy = false, noisy = false,
title = "title", title = "title",
description = "description", description = "description",
type = null, type = type,
timestamp = 0, timestamp = 0,
soundName = null, soundName = null,
canBeReplaced = false, canBeReplaced = false,