Refactors sorting of Notifications

This commit is contained in:
Vitor Pamplona
2024-08-15 16:16:36 -04:00
parent c82c594926
commit 7513036d47
2 changed files with 7 additions and 2 deletions

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.ui.dal package com.vitorpamplona.amethyst.ui.dal
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.Card
import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.events.Event
val DefaultFeedOrder: Comparator<Note> = val DefaultFeedOrder: Comparator<Note> =
@@ -37,3 +38,6 @@ val DefaultFeedOrder: Comparator<Note> =
} }
} }
}.thenBy { it.idHex } }.thenBy { it.idHex }
val DefaultFeedOrderCard: Comparator<Card> =
compareByDescending<Card> { it.createdAt() }.thenBy { it.id() }

View File

@@ -31,6 +31,7 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.checkNotInMainThread import com.vitorpamplona.amethyst.service.checkNotInMainThread
import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter 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.FeedFilter
import com.vitorpamplona.amethyst.ui.dal.NotificationFeedFilter import com.vitorpamplona.amethyst.ui.dal.NotificationFeedFilter
import com.vitorpamplona.amethyst.ui.feeds.InvalidatableContent import com.vitorpamplona.amethyst.ui.feeds.InvalidatableContent
@@ -111,7 +112,7 @@ class CardFeedContentState(
val updatedCards = val updatedCards =
(oldNotesState.feed.value + newCards) (oldNotesState.feed.value + newCards)
.distinctBy { it.id() } .distinctBy { it.id() }
.sortedWith(compareBy({ it.createdAt() }, { it.id() })) .sortedWith(DefaultFeedOrderCard)
.reversed() .reversed()
.take(localFilter.limit()) .take(localFilter.limit())
.toImmutableList() .toImmutableList()
@@ -126,7 +127,7 @@ class CardFeedContentState(
val cards = val cards =
convertToCard(notes) convertToCard(notes)
.sortedWith(compareBy({ it.createdAt() }, { it.id() })) .sortedWith(DefaultFeedOrderCard)
.reversed() .reversed()
.take(localFilter.limit()) .take(localFilter.limit())
.toImmutableList() .toImmutableList()