kopia lustrzana https://github.com/vitorpamplona/amethyst
42 wiersze
1.8 KiB
Kotlin
42 wiersze
1.8 KiB
Kotlin
package com.vitorpamplona.amethyst.ui.dal
|
|
|
|
import com.vitorpamplona.amethyst.model.Account
|
|
import com.vitorpamplona.amethyst.model.LocalCache
|
|
import com.vitorpamplona.amethyst.model.Note
|
|
import com.vitorpamplona.amethyst.service.model.LongTextNoteEvent
|
|
import com.vitorpamplona.amethyst.service.model.PollNoteEvent
|
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
|
import com.vitorpamplona.amethyst.service.model.TextNoteEvent
|
|
|
|
object HomeNewThreadFeedFilter : FeedFilter<Note>() {
|
|
lateinit var account: Account
|
|
|
|
override fun feed(): List<Note> {
|
|
val user = account.userProfile()
|
|
val followingKeySet = user.cachedFollowingKeySet()
|
|
val followingTagSet = user.cachedFollowingTagSet()
|
|
|
|
val notes = LocalCache.notes.values
|
|
.filter { it ->
|
|
(it.event is TextNoteEvent || it.event is RepostEvent || it.event is PollNoteEvent) &&
|
|
(it.author?.pubkeyHex in followingKeySet || (it.event?.isTaggedHashes(followingTagSet) ?: false)) &&
|
|
// && account.isAcceptable(it) // This filter follows only. No need to check if acceptable
|
|
it.author?.let { !account.isHidden(it) } ?: true &&
|
|
it.isNewThread()
|
|
}
|
|
|
|
val longFormNotes = LocalCache.addressables.values
|
|
.filter { it ->
|
|
(it.event is LongTextNoteEvent) &&
|
|
(it.author?.pubkeyHex in followingKeySet || (it.event?.isTaggedHashes(followingTagSet) ?: false)) &&
|
|
// && account.isAcceptable(it) // This filter follows only. No need to check if acceptable
|
|
it.author?.let { !account.isHidden(it) } ?: true &&
|
|
it.isNewThread()
|
|
}
|
|
|
|
return (notes + longFormNotes)
|
|
.sortedBy { it.createdAt() }
|
|
.reversed()
|
|
}
|
|
}
|