removing no longer needed hasBeenDisplayed state, the eventList is our source of truth

- when events have finished being displayed they should be removed from the eventList via notification delete actions
This commit is contained in:
Adam Brown 2021-10-07 14:18:27 +01:00
parent c85afa96d3
commit 3d567d0dcd
8 changed files with 14 additions and 20 deletions

View File

@ -29,7 +29,4 @@ data class InviteNotifiableEvent(
val timestamp: Long,
val soundName: String?,
override val isRedacted: Boolean = false
) : NotifiableEvent {
override var hasBeenDisplayed = false
}
) : NotifiableEvent

View File

@ -23,7 +23,6 @@ import java.io.Serializable
sealed interface NotifiableEvent : Serializable {
val eventId: String
val editedEventId: String?
var hasBeenDisplayed: Boolean
// Used to know if event should be replaced with the one coming from eventstream
val canBeReplaced: Boolean

View File

@ -39,8 +39,6 @@ data class NotifiableMessageEvent(
override val isRedacted: Boolean = false
) : NotifiableEvent {
override var hasBeenDisplayed: Boolean = false
val type: String = EventType.MESSAGE
val description: String = body ?: ""
val title: String = senderName ?: ""

View File

@ -101,7 +101,6 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
// Use setOnlyAlertOnce to ensure update notification does not interfere with sound
// from first notify invocation as outlined in:
// https://developer.android.com/training/notify-user/build-notification#Updating
notifiableEvent.hasBeenDisplayed = false
eventList.remove(existing)
eventList.add(notifiableEvent)
} else {
@ -144,9 +143,9 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
synchronized(eventList) {
eventList.replace(eventId) {
when (it) {
is InviteNotifiableEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
is NotifiableMessageEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
is SimpleNotifiableEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
is InviteNotifiableEvent -> it.copy(isRedacted = true)
is NotifiableMessageEvent -> it.copy(isRedacted = true)
is SimpleNotifiableEvent -> it.copy(isRedacted = true)
}
}
}

View File

@ -38,7 +38,7 @@ class NotificationFactory @Inject constructor(
private fun List<NotifiableMessageEvent>.hasNoEventsToDisplay() = isEmpty() || all { it.canNotBeDisplayed() }
private fun NotifiableMessageEvent.canNotBeDisplayed() = hasBeenDisplayed || isRedacted
private fun NotifiableMessageEvent.canNotBeDisplayed() = isRedacted
fun Map<String, InviteNotifiableEvent?>.toNotifications(myUserId: String): List<OneShotNotification> {
return this.map { (roomId, event) ->

View File

@ -27,7 +27,4 @@ data class SimpleNotifiableEvent(
val soundName: String?,
override var canBeReplaced: Boolean,
override val isRedacted: Boolean = false
) : NotifiableEvent {
override var hasBeenDisplayed: Boolean = false
}
) : NotifiableEvent

View File

@ -156,7 +156,8 @@ fun aSimpleNotifiableEvent(eventId: String) = SimpleNotifiableEvent(
type = null,
timestamp = 0,
soundName = null,
isPushGatewayEvent = false
canBeReplaced = false,
isRedacted = false
)
fun anInviteNotifiableEvent(roomId: String) = InviteNotifiableEvent(
@ -170,7 +171,8 @@ fun anInviteNotifiableEvent(roomId: String) = InviteNotifiableEvent(
type = null,
timestamp = 0,
soundName = null,
isPushGatewayEvent = false
canBeReplaced = false,
isRedacted = false
)
fun aNotifiableMessageEvent(eventId: String, roomId: String) = NotifiableMessageEvent(
@ -183,5 +185,7 @@ fun aNotifiableMessageEvent(eventId: String, roomId: String) = NotifiableMessage
body = "message-body",
roomId = roomId,
roomName = "room-name",
roomIsDirect = false
roomIsDirect = false,
canBeReplaced = false,
isRedacted = false
)

View File

@ -123,7 +123,7 @@ class NotificationFactoryTest {
@Test
fun `given a room with only redacted events when mapping to notification then is Empty`() = testWith(notificationFactory) {
val redactedRoom = mapOf(A_ROOM_ID to listOf(A_MESSAGE_EVENT.copy().apply { isRedacted = true }))
val redactedRoom = mapOf(A_ROOM_ID to listOf(A_MESSAGE_EVENT.copy(isRedacted = true)))
val result = redactedRoom.toNotifications(MY_USER_ID, MY_AVATAR_URL)