kopia lustrzana https://github.com/vitorpamplona/amethyst
Sorts chats by the latest message in Discovery
rodzic
5a1c9f5a4a
commit
0b40b6d1d8
|
@ -108,10 +108,9 @@ class LiveActivitiesChannel(val address: ATag) : Channel(address.toTag()) {
|
|||
@Stable
|
||||
abstract class Channel(val idHex: String) {
|
||||
var creator: User? = null
|
||||
|
||||
var updatedMetadataAt: Long = 0
|
||||
|
||||
val notes = LargeCache<HexKey, Note>()
|
||||
var lastNoteCreatedAt: Long = 0
|
||||
|
||||
open fun id() = Hex.decode(idHex)
|
||||
|
||||
|
@ -147,6 +146,10 @@ abstract class Channel(val idHex: String) {
|
|||
|
||||
fun addNote(note: Note) {
|
||||
notes.put(note.idHex, note)
|
||||
|
||||
if ((note.createdAt() ?: 0) > lastNoteCreatedAt) {
|
||||
lastNoteCreatedAt = note.createdAt() ?: 0
|
||||
}
|
||||
}
|
||||
|
||||
fun removeNote(note: Note) {
|
||||
|
|
|
@ -85,17 +85,15 @@ open class DiscoverChatFeedFilter(val account: Account) : AdditiveFeedFilter<Not
|
|||
}
|
||||
|
||||
override fun sort(collection: Set<Note>): List<Note> {
|
||||
val followingKeySet =
|
||||
account.liveDiscoveryFollowLists.value?.users ?: account.liveKind3Follows.value.users
|
||||
|
||||
val counter = ParticipantListBuilder()
|
||||
val participantCounts =
|
||||
collection.associate { it to counter.countFollowsThatParticipateOn(it, followingKeySet) }
|
||||
val lastNote =
|
||||
collection.associateWith { note ->
|
||||
LocalCache.getChannelIfExists(note.idHex)?.lastNoteCreatedAt ?: 0
|
||||
}
|
||||
|
||||
return collection
|
||||
.sortedWith(
|
||||
compareBy(
|
||||
{ participantCounts[it] },
|
||||
{ lastNote[it] },
|
||||
{ it.createdAt() },
|
||||
{ it.idHex },
|
||||
),
|
||||
|
|
Ładowanie…
Reference in New Issue