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> {
|
override fun sort(items: Set<Note>): List<Note> {
|
||||||
|
// precache to avoid breaking the contract
|
||||||
val lastNote =
|
val lastNote =
|
||||||
items.associateWith { note ->
|
items.associateWith { note ->
|
||||||
LocalCache.getPublicChatChannelIfExists(note.idHex)?.lastNote?.createdAt() ?: 0
|
LocalCache.getPublicChatChannelIfExists(note.idHex)?.lastNote?.createdAt() ?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return items
|
val createdNote =
|
||||||
.sortedWith(
|
items.associateWith { note ->
|
||||||
compareBy(
|
note.createdAt() ?: 0
|
||||||
{ lastNote[it] },
|
}
|
||||||
{ it.createdAt() },
|
|
||||||
{ it.idHex },
|
val comparator: Comparator<Note> =
|
||||||
),
|
compareByDescending<Note> {
|
||||||
).reversed()
|
lastNote[it]
|
||||||
|
}.thenByDescending {
|
||||||
|
createdNote[it]
|
||||||
|
}.thenBy {
|
||||||
|
it.idHex
|
||||||
|
}
|
||||||
|
|
||||||
|
return items.sortedWith(comparator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,13 +125,20 @@ open class DiscoverCommunityFeedFilter(
|
|||||||
max
|
max
|
||||||
}
|
}
|
||||||
|
|
||||||
return items
|
val createdNote =
|
||||||
.sortedWith(
|
items.associateWith { note ->
|
||||||
compareBy(
|
note.createdAt() ?: 0
|
||||||
{ lastNotesCreatedAt[it] },
|
}
|
||||||
{ it.createdAt() },
|
|
||||||
{ it.idHex },
|
val comparator: Comparator<Note> =
|
||||||
),
|
compareByDescending<Note> {
|
||||||
).reversed()
|
lastNotesCreatedAt[it]
|
||||||
|
}.thenByDescending {
|
||||||
|
createdNote[it]
|
||||||
|
}.thenBy {
|
||||||
|
it.idHex
|
||||||
|
}
|
||||||
|
|
||||||
|
return items.sortedWith(comparator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,11 +113,16 @@ open class DiscoverNIP89FeedFilter(
|
|||||||
val participantCounts =
|
val participantCounts =
|
||||||
items.associateWith { counter.countFollowsThatParticipateOn(it, followingKeySet) }
|
items.associateWith { counter.countFollowsThatParticipateOn(it, followingKeySet) }
|
||||||
|
|
||||||
|
val createdNote =
|
||||||
|
items.associateWith { note ->
|
||||||
|
((note.event?.createdAt ?: 0) / 86400).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
val feedOrder: Comparator<Note> =
|
val feedOrder: Comparator<Note> =
|
||||||
compareByDescending<Note> {
|
compareByDescending<Note> {
|
||||||
participantCounts[it]
|
participantCounts[it]
|
||||||
}.thenByDescending {
|
}.thenByDescending {
|
||||||
((it.event?.createdAt ?: 0) / 86400).toInt()
|
createdNote[it]
|
||||||
}.thenBy { it.idHex }
|
}.thenBy { it.idHex }
|
||||||
|
|
||||||
return items.sortedWith(feedOrder)
|
return items.sortedWith(feedOrder)
|
||||||
|
|||||||
Reference in New Issue
Block a user