mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 19:16:47 +01:00
Avoids breaking the contract (changes during sorting)
This commit is contained in:
@@ -103,18 +103,26 @@ open class DiscoverChatFeedFilter(
|
||||
}
|
||||
|
||||
override fun sort(items: Set<Note>): List<Note> {
|
||||
// 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<Note> =
|
||||
compareByDescending<Note> {
|
||||
lastNote[it]
|
||||
}.thenByDescending {
|
||||
createdNote[it]
|
||||
}.thenBy {
|
||||
it.idHex
|
||||
}
|
||||
|
||||
return items.sortedWith(comparator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Note> =
|
||||
compareByDescending<Note> {
|
||||
lastNotesCreatedAt[it]
|
||||
}.thenByDescending {
|
||||
createdNote[it]
|
||||
}.thenBy {
|
||||
it.idHex
|
||||
}
|
||||
|
||||
return items.sortedWith(comparator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Note> =
|
||||
compareByDescending<Note> {
|
||||
participantCounts[it]
|
||||
}.thenByDescending {
|
||||
((it.event?.createdAt ?: 0) / 86400).toInt()
|
||||
createdNote[it]
|
||||
}.thenBy { it.idHex }
|
||||
|
||||
return items.sortedWith(feedOrder)
|
||||
|
||||
Reference in New Issue
Block a user