From 7513036d47b7d5c627cf3e66caf892d170fcc92f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 15 Aug 2024 16:16:36 -0400 Subject: [PATCH] Refactors sorting of Notifications --- .../com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt | 4 ++++ .../ui/screen/loggedIn/notifications/CardFeedContentState.kt | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt index e5d298261..43baf14ab 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt @@ -21,6 +21,7 @@ package com.vitorpamplona.amethyst.ui.dal import com.vitorpamplona.amethyst.model.Note +import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.Card import com.vitorpamplona.quartz.events.Event val DefaultFeedOrder: Comparator = @@ -37,3 +38,6 @@ val DefaultFeedOrder: Comparator = } } }.thenBy { it.idHex } + +val DefaultFeedOrderCard: Comparator = + compareByDescending { it.createdAt() }.thenBy { it.id() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt index 4dde389ec..9a164718b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt @@ -31,6 +31,7 @@ import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.service.checkNotInMainThread import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter +import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrderCard import com.vitorpamplona.amethyst.ui.dal.FeedFilter import com.vitorpamplona.amethyst.ui.dal.NotificationFeedFilter import com.vitorpamplona.amethyst.ui.feeds.InvalidatableContent @@ -111,7 +112,7 @@ class CardFeedContentState( val updatedCards = (oldNotesState.feed.value + newCards) .distinctBy { it.id() } - .sortedWith(compareBy({ it.createdAt() }, { it.id() })) + .sortedWith(DefaultFeedOrderCard) .reversed() .take(localFilter.limit()) .toImmutableList() @@ -126,7 +127,7 @@ class CardFeedContentState( val cards = convertToCard(notes) - .sortedWith(compareBy({ it.createdAt() }, { it.id() })) + .sortedWith(DefaultFeedOrderCard) .reversed() .take(localFilter.limit()) .toImmutableList()