Sorts chats by the latest message in Discovery

pull/749/head
Vitor Pamplona 2024-03-23 17:19:54 -04:00
rodzic 5a1c9f5a4a
commit 0b40b6d1d8
2 zmienionych plików z 10 dodań i 9 usunięć

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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 },
),