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