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:
parent
c85afa96d3
commit
3d567d0dcd
|
@ -29,7 +29,4 @@ data class InviteNotifiableEvent(
|
||||||
val timestamp: Long,
|
val timestamp: Long,
|
||||||
val soundName: String?,
|
val soundName: String?,
|
||||||
override val isRedacted: Boolean = false
|
override val isRedacted: Boolean = false
|
||||||
) : NotifiableEvent {
|
) : NotifiableEvent
|
||||||
|
|
||||||
override var hasBeenDisplayed = false
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.io.Serializable
|
||||||
sealed interface NotifiableEvent : Serializable {
|
sealed interface NotifiableEvent : Serializable {
|
||||||
val eventId: String
|
val eventId: String
|
||||||
val editedEventId: String?
|
val editedEventId: String?
|
||||||
var hasBeenDisplayed: Boolean
|
|
||||||
|
|
||||||
// Used to know if event should be replaced with the one coming from eventstream
|
// Used to know if event should be replaced with the one coming from eventstream
|
||||||
val canBeReplaced: Boolean
|
val canBeReplaced: Boolean
|
||||||
|
|
|
@ -39,8 +39,6 @@ data class NotifiableMessageEvent(
|
||||||
override val isRedacted: Boolean = false
|
override val isRedacted: Boolean = false
|
||||||
) : NotifiableEvent {
|
) : NotifiableEvent {
|
||||||
|
|
||||||
override var hasBeenDisplayed: Boolean = false
|
|
||||||
|
|
||||||
val type: String = EventType.MESSAGE
|
val type: String = EventType.MESSAGE
|
||||||
val description: String = body ?: ""
|
val description: String = body ?: ""
|
||||||
val title: String = senderName ?: ""
|
val title: String = senderName ?: ""
|
||||||
|
|
|
@ -101,7 +101,6 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
||||||
// Use setOnlyAlertOnce to ensure update notification does not interfere with sound
|
// Use setOnlyAlertOnce to ensure update notification does not interfere with sound
|
||||||
// from first notify invocation as outlined in:
|
// from first notify invocation as outlined in:
|
||||||
// https://developer.android.com/training/notify-user/build-notification#Updating
|
// https://developer.android.com/training/notify-user/build-notification#Updating
|
||||||
notifiableEvent.hasBeenDisplayed = false
|
|
||||||
eventList.remove(existing)
|
eventList.remove(existing)
|
||||||
eventList.add(notifiableEvent)
|
eventList.add(notifiableEvent)
|
||||||
} else {
|
} else {
|
||||||
|
@ -144,9 +143,9 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
|
||||||
synchronized(eventList) {
|
synchronized(eventList) {
|
||||||
eventList.replace(eventId) {
|
eventList.replace(eventId) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is InviteNotifiableEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
|
is InviteNotifiableEvent -> it.copy(isRedacted = true)
|
||||||
is NotifiableMessageEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
|
is NotifiableMessageEvent -> it.copy(isRedacted = true)
|
||||||
is SimpleNotifiableEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
|
is SimpleNotifiableEvent -> it.copy(isRedacted = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class NotificationFactory @Inject constructor(
|
||||||
|
|
||||||
private fun List<NotifiableMessageEvent>.hasNoEventsToDisplay() = isEmpty() || all { it.canNotBeDisplayed() }
|
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> {
|
fun Map<String, InviteNotifiableEvent?>.toNotifications(myUserId: String): List<OneShotNotification> {
|
||||||
return this.map { (roomId, event) ->
|
return this.map { (roomId, event) ->
|
||||||
|
|
|
@ -27,7 +27,4 @@ data class SimpleNotifiableEvent(
|
||||||
val soundName: String?,
|
val soundName: String?,
|
||||||
override var canBeReplaced: Boolean,
|
override var canBeReplaced: Boolean,
|
||||||
override val isRedacted: Boolean = false
|
override val isRedacted: Boolean = false
|
||||||
) : NotifiableEvent {
|
) : NotifiableEvent
|
||||||
|
|
||||||
override var hasBeenDisplayed: Boolean = false
|
|
||||||
}
|
|
||||||
|
|
|
@ -156,7 +156,8 @@ fun aSimpleNotifiableEvent(eventId: String) = SimpleNotifiableEvent(
|
||||||
type = null,
|
type = null,
|
||||||
timestamp = 0,
|
timestamp = 0,
|
||||||
soundName = null,
|
soundName = null,
|
||||||
isPushGatewayEvent = false
|
canBeReplaced = false,
|
||||||
|
isRedacted = false
|
||||||
)
|
)
|
||||||
|
|
||||||
fun anInviteNotifiableEvent(roomId: String) = InviteNotifiableEvent(
|
fun anInviteNotifiableEvent(roomId: String) = InviteNotifiableEvent(
|
||||||
|
@ -170,7 +171,8 @@ fun anInviteNotifiableEvent(roomId: String) = InviteNotifiableEvent(
|
||||||
type = null,
|
type = null,
|
||||||
timestamp = 0,
|
timestamp = 0,
|
||||||
soundName = null,
|
soundName = null,
|
||||||
isPushGatewayEvent = false
|
canBeReplaced = false,
|
||||||
|
isRedacted = false
|
||||||
)
|
)
|
||||||
|
|
||||||
fun aNotifiableMessageEvent(eventId: String, roomId: String) = NotifiableMessageEvent(
|
fun aNotifiableMessageEvent(eventId: String, roomId: String) = NotifiableMessageEvent(
|
||||||
|
@ -183,5 +185,7 @@ fun aNotifiableMessageEvent(eventId: String, roomId: String) = NotifiableMessage
|
||||||
body = "message-body",
|
body = "message-body",
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
roomName = "room-name",
|
roomName = "room-name",
|
||||||
roomIsDirect = false
|
roomIsDirect = false,
|
||||||
|
canBeReplaced = false,
|
||||||
|
isRedacted = false
|
||||||
)
|
)
|
||||||
|
|
|
@ -123,7 +123,7 @@ class NotificationFactoryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a room with only redacted events when mapping to notification then is Empty`() = testWith(notificationFactory) {
|
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)
|
val result = redactedRoom.toNotifications(MY_USER_ID, MY_AVATAR_URL)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue