ensuring that we remove read messages when they come through by respecting the processed type when creating the notifications
This commit is contained in:
parent
0bdc65b47f
commit
c67b9ee81e
|
@ -27,16 +27,21 @@ class NotificationFactory @Inject constructor(
|
|||
private val summaryGroupMessageCreator: SummaryGroupMessageCreator
|
||||
) {
|
||||
|
||||
fun Map<String, List<NotifiableMessageEvent>>.toNotifications(myUserDisplayName: String, myUserAvatarUrl: String?): List<RoomNotification> {
|
||||
fun Map<String, List<Pair<ProcessedType, NotifiableMessageEvent>>>.toNotifications(myUserDisplayName: String, myUserAvatarUrl: String?): List<RoomNotification> {
|
||||
return map { (roomId, events) ->
|
||||
when {
|
||||
events.hasNoEventsToDisplay() -> RoomNotification.Removed(roomId)
|
||||
else -> roomGroupMessageCreator.createRoomMessage(events, roomId, myUserDisplayName, myUserAvatarUrl)
|
||||
else -> {
|
||||
val messageEvents = events.filter { it.first == ProcessedType.KEEP }.map { it.second }
|
||||
roomGroupMessageCreator.createRoomMessage(messageEvents, roomId, myUserDisplayName, myUserAvatarUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<NotifiableMessageEvent>.hasNoEventsToDisplay() = isEmpty() || all { it.canNotBeDisplayed() }
|
||||
private fun List<Pair<ProcessedType, NotifiableMessageEvent>>.hasNoEventsToDisplay() = isEmpty() || all {
|
||||
it.first == ProcessedType.REMOVE || it.second.canNotBeDisplayed()
|
||||
}
|
||||
|
||||
private fun NotifiableMessageEvent.canNotBeDisplayed() = isRedacted
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class NotificationRenderer @Inject constructor(private val notificationDisplayer
|
|||
myUserDisplayName: String,
|
||||
myUserAvatarUrl: String?,
|
||||
useCompleteNotificationFormat: Boolean,
|
||||
eventsToProcess: List<Pair<ProcessedType, NotifiableEvent>>) {
|
||||
eventsToProcess: List<ProcessedEvent>) {
|
||||
val (roomEvents, simpleEvents, invitationEvents) = eventsToProcess.groupByType()
|
||||
with(notificationFactory) {
|
||||
val roomNotifications = roomEvents.toNotifications(myUserDisplayName, myUserAvatarUrl)
|
||||
|
@ -108,8 +108,8 @@ class NotificationRenderer @Inject constructor(private val notificationDisplayer
|
|||
}
|
||||
}
|
||||
|
||||
private fun List<Pair<ProcessedType, NotifiableEvent>>.groupByType(): GroupedNotificationEvents {
|
||||
val roomIdToEventMap: MutableMap<String, MutableList<NotifiableMessageEvent>> = LinkedHashMap()
|
||||
private fun List<ProcessedEvent>.groupByType(): GroupedNotificationEvents {
|
||||
val roomIdToEventMap: MutableMap<String, MutableList<Pair<ProcessedType, NotifiableMessageEvent>>> = LinkedHashMap()
|
||||
val simpleEvents: MutableList<Pair<ProcessedType, SimpleNotifiableEvent>> = ArrayList()
|
||||
val invitationEvents: MutableList<Pair<ProcessedType, InviteNotifiableEvent>> = ArrayList()
|
||||
forEach {
|
||||
|
@ -117,7 +117,7 @@ private fun List<Pair<ProcessedType, NotifiableEvent>>.groupByType(): GroupedNot
|
|||
is InviteNotifiableEvent -> invitationEvents.add(it.asPair())
|
||||
is NotifiableMessageEvent -> {
|
||||
val roomEvents = roomIdToEventMap.getOrPut(event.roomId) { ArrayList() }
|
||||
roomEvents.add(event)
|
||||
roomEvents.add(it.asPair())
|
||||
}
|
||||
is SimpleNotifiableEvent -> simpleEvents.add(it.asPair())
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ private fun List<Pair<ProcessedType, NotifiableEvent>>.groupByType(): GroupedNot
|
|||
private fun <T : NotifiableEvent> Pair<ProcessedType, *>.asPair(): Pair<ProcessedType, T> = this as Pair<ProcessedType, T>
|
||||
|
||||
data class GroupedNotificationEvents(
|
||||
val roomEvents: Map<String, List<NotifiableMessageEvent>>,
|
||||
val roomEvents: Map<String, List<Pair<ProcessedType, NotifiableMessageEvent>>>,
|
||||
val simpleEvents: List<Pair<ProcessedType, SimpleNotifiableEvent>>,
|
||||
val invitationEvents: List<Pair<ProcessedType, InviteNotifiableEvent>>
|
||||
)
|
||||
|
|
|
@ -105,7 +105,7 @@ class NotificationFactoryTest {
|
|||
fun `given room with message when mapping to notification then delegates to room group message creator`() = testWith(notificationFactory) {
|
||||
val events = listOf(A_MESSAGE_EVENT)
|
||||
val expectedNotification = roomGroupMessageCreator.givenCreatesRoomMessageFor(events, A_ROOM_ID, MY_USER_ID, MY_AVATAR_URL)
|
||||
val roomWithMessage = mapOf(A_ROOM_ID to events)
|
||||
val roomWithMessage = mapOf(A_ROOM_ID to listOf(ProcessedType.KEEP to A_MESSAGE_EVENT))
|
||||
|
||||
val result = roomWithMessage.toNotifications(MY_USER_ID, MY_AVATAR_URL)
|
||||
|
||||
|
@ -114,7 +114,8 @@ class NotificationFactoryTest {
|
|||
|
||||
@Test
|
||||
fun `given a room with no events to display when mapping to notification then is Empty`() = testWith(notificationFactory) {
|
||||
val emptyRoom: Map<String, List<NotifiableMessageEvent>> = mapOf(A_ROOM_ID to emptyList())
|
||||
val events = listOf(ProcessedType.REMOVE to A_MESSAGE_EVENT)
|
||||
val emptyRoom = mapOf(A_ROOM_ID to events)
|
||||
|
||||
val result = emptyRoom.toNotifications(MY_USER_ID, MY_AVATAR_URL)
|
||||
|
||||
|
@ -125,7 +126,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(isRedacted = true)))
|
||||
val redactedRoom = mapOf(A_ROOM_ID to listOf(ProcessedType.KEEP to A_MESSAGE_EVENT.copy(isRedacted = true)))
|
||||
|
||||
val result = redactedRoom.toNotifications(MY_USER_ID, MY_AVATAR_URL)
|
||||
|
||||
|
|
Loading…
Reference in New Issue