Revert "NotificationDataFactory: improve API"
This reverts commit b0e5e6cc61.
# Conflicts:
# libraries/push/impl/src/test/kotlin/io/element/android/libraries/push/impl/notifications/NotificationDataFactoryTest.kt
This commit is contained in:
parent
e6934aacfa
commit
fb4114adad
4 changed files with 46 additions and 37 deletions
|
|
@ -28,26 +28,30 @@ import io.element.android.libraries.push.impl.notifications.model.SimpleNotifiab
|
||||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||||
|
|
||||||
interface NotificationDataFactory {
|
interface NotificationDataFactory {
|
||||||
suspend fun List<NotifiableMessageEvent>.toNotifications(
|
suspend fun toNotifications(
|
||||||
|
messages: List<NotifiableMessageEvent>,
|
||||||
imageLoader: ImageLoader,
|
imageLoader: ImageLoader,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<RoomNotification>
|
): List<RoomNotification>
|
||||||
|
|
||||||
@JvmName("toNotificationInvites")
|
@JvmName("toNotificationInvites")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
fun List<InviteNotifiableEvent>.toNotifications(
|
fun toNotifications(
|
||||||
|
invites: List<InviteNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification>
|
): List<OneShotNotification>
|
||||||
|
|
||||||
@JvmName("toNotificationSimpleEvents")
|
@JvmName("toNotificationSimpleEvents")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
fun List<SimpleNotifiableEvent>.toNotifications(
|
fun toNotifications(
|
||||||
|
simpleEvents: List<SimpleNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification>
|
): List<OneShotNotification>
|
||||||
|
|
||||||
@JvmName("toNotificationFallbackEvents")
|
@JvmName("toNotificationFallbackEvents")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
fun List<FallbackNotifiableEvent>.toNotifications(
|
fun toNotifications(
|
||||||
|
fallback: List<FallbackNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification>
|
): List<OneShotNotification>
|
||||||
|
|
||||||
|
|
@ -68,11 +72,12 @@ class DefaultNotificationDataFactory(
|
||||||
private val activeNotificationsProvider: ActiveNotificationsProvider,
|
private val activeNotificationsProvider: ActiveNotificationsProvider,
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
) : NotificationDataFactory {
|
) : NotificationDataFactory {
|
||||||
override suspend fun List<NotifiableMessageEvent>.toNotifications(
|
override suspend fun toNotifications(
|
||||||
|
messages: List<NotifiableMessageEvent>,
|
||||||
imageLoader: ImageLoader,
|
imageLoader: ImageLoader,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<RoomNotification> {
|
): List<RoomNotification> {
|
||||||
val messagesToDisplay = filterNot { it.canNotBeDisplayed() }
|
val messagesToDisplay = messages.filterNot { it.canNotBeDisplayed() }
|
||||||
.groupBy { it.roomId }
|
.groupBy { it.roomId }
|
||||||
return messagesToDisplay.flatMap { (roomId, events) ->
|
return messagesToDisplay.flatMap { (roomId, events) ->
|
||||||
val roomName = events.lastOrNull()?.roomName ?: roomId.value
|
val roomName = events.lastOrNull()?.roomName ?: roomId.value
|
||||||
|
|
@ -109,10 +114,11 @@ class DefaultNotificationDataFactory(
|
||||||
|
|
||||||
@JvmName("toNotificationInvites")
|
@JvmName("toNotificationInvites")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
override fun List<InviteNotifiableEvent>.toNotifications(
|
override fun toNotifications(
|
||||||
|
invites: List<InviteNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification> {
|
): List<OneShotNotification> {
|
||||||
return map { event ->
|
return invites.map { event ->
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
tag = event.roomId.value,
|
tag = event.roomId.value,
|
||||||
notification = notificationCreator.createRoomInvitationNotification(notificationAccountParams, event),
|
notification = notificationCreator.createRoomInvitationNotification(notificationAccountParams, event),
|
||||||
|
|
@ -125,10 +131,11 @@ class DefaultNotificationDataFactory(
|
||||||
|
|
||||||
@JvmName("toNotificationSimpleEvents")
|
@JvmName("toNotificationSimpleEvents")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
override fun List<SimpleNotifiableEvent>.toNotifications(
|
override fun toNotifications(
|
||||||
|
simpleEvents: List<SimpleNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification> {
|
): List<OneShotNotification> {
|
||||||
return map { event ->
|
return simpleEvents.map { event ->
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
tag = event.eventId.value,
|
tag = event.eventId.value,
|
||||||
notification = notificationCreator.createSimpleEventNotification(notificationAccountParams, event),
|
notification = notificationCreator.createSimpleEventNotification(notificationAccountParams, event),
|
||||||
|
|
@ -141,10 +148,11 @@ class DefaultNotificationDataFactory(
|
||||||
|
|
||||||
@JvmName("toNotificationFallbackEvents")
|
@JvmName("toNotificationFallbackEvents")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
override fun List<FallbackNotifiableEvent>.toNotifications(
|
override fun toNotifications(
|
||||||
|
fallback: List<FallbackNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification> {
|
): List<OneShotNotification> {
|
||||||
return map { event ->
|
return fallback.map { event ->
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
tag = event.eventId.value,
|
tag = event.eventId.value,
|
||||||
notification = notificationCreator.createFallbackNotification(notificationAccountParams, event),
|
notification = notificationCreator.createFallbackNotification(notificationAccountParams, event),
|
||||||
|
|
|
||||||
|
|
@ -51,18 +51,10 @@ class NotificationRenderer(
|
||||||
showSessionId = numberOfAccounts > 1,
|
showSessionId = numberOfAccounts > 1,
|
||||||
)
|
)
|
||||||
val groupedEvents = eventsToProcess.groupByType()
|
val groupedEvents = eventsToProcess.groupByType()
|
||||||
val roomNotifications = with(notificationDataFactory) {
|
val roomNotifications = notificationDataFactory.toNotifications(groupedEvents.roomEvents, imageLoader, notificationAccountParams)
|
||||||
groupedEvents.roomEvents.toNotifications(imageLoader, notificationAccountParams)
|
val invitationNotifications = notificationDataFactory.toNotifications(groupedEvents.invitationEvents, notificationAccountParams)
|
||||||
}
|
val simpleNotifications = notificationDataFactory.toNotifications(groupedEvents.simpleEvents, notificationAccountParams)
|
||||||
val invitationNotifications = with(notificationDataFactory) {
|
val fallbackNotifications = notificationDataFactory.toNotifications(groupedEvents.fallbackEvents, notificationAccountParams)
|
||||||
groupedEvents.invitationEvents.toNotifications(notificationAccountParams)
|
|
||||||
}
|
|
||||||
val simpleNotifications = with(notificationDataFactory) {
|
|
||||||
groupedEvents.simpleEvents.toNotifications(notificationAccountParams)
|
|
||||||
}
|
|
||||||
val fallbackNotifications = with(notificationDataFactory) {
|
|
||||||
groupedEvents.fallbackEvents.toNotifications(notificationAccountParams)
|
|
||||||
}
|
|
||||||
val summaryNotification = notificationDataFactory.createSummaryNotification(
|
val summaryNotification = notificationDataFactory.createSummaryNotification(
|
||||||
roomNotifications = roomNotifications,
|
roomNotifications = roomNotifications,
|
||||||
invitationNotifications = invitationNotifications,
|
invitationNotifications = invitationNotifications,
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,9 @@ class NotificationDataFactoryTest {
|
||||||
aNotificationAccountParams(),
|
aNotificationAccountParams(),
|
||||||
AN_INVITATION_EVENT,
|
AN_INVITATION_EVENT,
|
||||||
)
|
)
|
||||||
val result = listOf(AN_INVITATION_EVENT).toNotifications(aNotificationAccountParams())
|
val roomInvitation = listOf(AN_INVITATION_EVENT)
|
||||||
|
val result = toNotifications(roomInvitation, aNotificationAccountParams())
|
||||||
|
|
||||||
assertThat(result).isEqualTo(
|
assertThat(result).isEqualTo(
|
||||||
listOf(
|
listOf(
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
|
|
@ -75,7 +77,7 @@ class NotificationDataFactoryTest {
|
||||||
aNotificationAccountParams(),
|
aNotificationAccountParams(),
|
||||||
AN_INVITATION_EVENT,
|
AN_INVITATION_EVENT,
|
||||||
)
|
)
|
||||||
val result = listOf(A_SIMPLE_EVENT).toNotifications(aNotificationAccountParams())
|
val result = toNotifications(listOf(A_SIMPLE_EVENT), aNotificationAccountParams())
|
||||||
assertThat(result).containsExactly(
|
assertThat(result).containsExactly(
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
notification = expectedNotification,
|
notification = expectedNotification,
|
||||||
|
|
@ -109,7 +111,8 @@ class NotificationDataFactoryTest {
|
||||||
threadId = null,
|
threadId = null,
|
||||||
)
|
)
|
||||||
val fakeImageLoader = FakeImageLoader()
|
val fakeImageLoader = FakeImageLoader()
|
||||||
val result = listOf(A_MESSAGE_EVENT).toNotifications(
|
val result = toNotifications(
|
||||||
|
messages = listOf(A_MESSAGE_EVENT),
|
||||||
notificationAccountParams = aNotificationAccountParams(
|
notificationAccountParams = aNotificationAccountParams(
|
||||||
user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
|
user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
|
||||||
),
|
),
|
||||||
|
|
@ -125,7 +128,8 @@ class NotificationDataFactoryTest {
|
||||||
fun `given a room with only redacted events when mapping to notification then is Empty`() = testWith(notificationDataFactory) {
|
fun `given a room with only redacted events when mapping to notification then is Empty`() = testWith(notificationDataFactory) {
|
||||||
val redactedRoom = A_MESSAGE_EVENT.copy(isRedacted = true)
|
val redactedRoom = A_MESSAGE_EVENT.copy(isRedacted = true)
|
||||||
val fakeImageLoader = FakeImageLoader()
|
val fakeImageLoader = FakeImageLoader()
|
||||||
val result = listOf(redactedRoom).toNotifications(
|
val result = toNotifications(
|
||||||
|
messages = listOf(redactedRoom),
|
||||||
notificationAccountParams = aNotificationAccountParams(
|
notificationAccountParams = aNotificationAccountParams(
|
||||||
user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
|
user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
|
||||||
),
|
),
|
||||||
|
|
@ -164,7 +168,8 @@ class NotificationDataFactoryTest {
|
||||||
)
|
)
|
||||||
|
|
||||||
val fakeImageLoader = FakeImageLoader()
|
val fakeImageLoader = FakeImageLoader()
|
||||||
val result = roomWithRedactedMessage.toNotifications(
|
val result = toNotifications(
|
||||||
|
messages = roomWithRedactedMessage,
|
||||||
notificationAccountParams = aNotificationAccountParams(
|
notificationAccountParams = aNotificationAccountParams(
|
||||||
user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
|
user = MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -40,35 +40,39 @@ class FakeNotificationDataFactory(
|
||||||
var fallbackEventToNotificationsResult: LambdaOneParamRecorder<List<FallbackNotifiableEvent>, List<OneShotNotification>> =
|
var fallbackEventToNotificationsResult: LambdaOneParamRecorder<List<FallbackNotifiableEvent>, List<OneShotNotification>> =
|
||||||
lambdaRecorder { _ -> emptyList() },
|
lambdaRecorder { _ -> emptyList() },
|
||||||
) : NotificationDataFactory {
|
) : NotificationDataFactory {
|
||||||
override suspend fun List<NotifiableMessageEvent>.toNotifications(
|
override suspend fun toNotifications(
|
||||||
|
messages: List<NotifiableMessageEvent>,
|
||||||
imageLoader: ImageLoader,
|
imageLoader: ImageLoader,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<RoomNotification> {
|
): List<RoomNotification> {
|
||||||
return messageEventToNotificationsResult(this, imageLoader, notificationAccountParams)
|
return messageEventToNotificationsResult(messages, imageLoader, notificationAccountParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmName("toNotificationInvites")
|
@JvmName("toNotificationInvites")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
override fun List<InviteNotifiableEvent>.toNotifications(
|
override fun toNotifications(
|
||||||
|
invites: List<InviteNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification> {
|
): List<OneShotNotification> {
|
||||||
return inviteToNotificationsResult(this)
|
return inviteToNotificationsResult(invites)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmName("toNotificationSimpleEvents")
|
@JvmName("toNotificationSimpleEvents")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
override fun List<SimpleNotifiableEvent>.toNotifications(
|
override fun toNotifications(
|
||||||
|
simpleEvents: List<SimpleNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification> {
|
): List<OneShotNotification> {
|
||||||
return simpleEventToNotificationsResult(this)
|
return simpleEventToNotificationsResult(simpleEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmName("toNotificationFallbackEvents")
|
@JvmName("toNotificationFallbackEvents")
|
||||||
@Suppress("INAPPLICABLE_JVM_NAME")
|
@Suppress("INAPPLICABLE_JVM_NAME")
|
||||||
override fun List<FallbackNotifiableEvent>.toNotifications(
|
override fun toNotifications(
|
||||||
|
fallback: List<FallbackNotifiableEvent>,
|
||||||
notificationAccountParams: NotificationAccountParams,
|
notificationAccountParams: NotificationAccountParams,
|
||||||
): List<OneShotNotification> {
|
): List<OneShotNotification> {
|
||||||
return fallbackEventToNotificationsResult(this)
|
return fallbackEventToNotificationsResult(fallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createSummaryNotification(
|
override fun createSummaryNotification(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue