diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt index e881f0119..ab004dfc0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip28Chats/DiscoverChatFeedFilter.kt @@ -103,18 +103,26 @@ open class DiscoverChatFeedFilter( } override fun sort(items: Set): List { + // precache to avoid breaking the contract val lastNote = items.associateWith { note -> LocalCache.getPublicChatChannelIfExists(note.idHex)?.lastNote?.createdAt() ?: 0 } - return items - .sortedWith( - compareBy( - { lastNote[it] }, - { it.createdAt() }, - { it.idHex }, - ), - ).reversed() + val createdNote = + items.associateWith { note -> + note.createdAt() ?: 0 + } + + val comparator: Comparator = + compareByDescending { + lastNote[it] + }.thenByDescending { + createdNote[it] + }.thenBy { + it.idHex + } + + return items.sortedWith(comparator) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt index dc67bfc4f..e45a11bed 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip72Communities/DiscoverCommunityFeedFilter.kt @@ -125,13 +125,20 @@ open class DiscoverCommunityFeedFilter( max } - return items - .sortedWith( - compareBy( - { lastNotesCreatedAt[it] }, - { it.createdAt() }, - { it.idHex }, - ), - ).reversed() + val createdNote = + items.associateWith { note -> + note.createdAt() ?: 0 + } + + val comparator: Comparator = + compareByDescending { + lastNotesCreatedAt[it] + }.thenByDescending { + createdNote[it] + }.thenBy { + it.idHex + } + + return items.sortedWith(comparator) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt index a69801e0e..1731d7248 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip90DVMs/DiscoverNIP89FeedFilter.kt @@ -113,11 +113,16 @@ open class DiscoverNIP89FeedFilter( val participantCounts = items.associateWith { counter.countFollowsThatParticipateOn(it, followingKeySet) } + val createdNote = + items.associateWith { note -> + ((note.event?.createdAt ?: 0) / 86400).toInt() + } + val feedOrder: Comparator = compareByDescending { participantCounts[it] }.thenByDescending { - ((it.event?.createdAt ?: 0) / 86400).toInt() + createdNote[it] }.thenBy { it.idHex } return items.sortedWith(feedOrder)