amethyst/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileNewThreadFeedFil...

31 wiersze
1.2 KiB
Kotlin
Czysty Zwykły widok Historia

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.model.User
import com.vitorpamplona.amethyst.service.model.AppRecommendationEvent
import com.vitorpamplona.amethyst.service.model.BookmarkListEvent
import com.vitorpamplona.amethyst.service.model.PeopleListEvent
2023-03-07 18:46:44 +00:00
object UserProfileNewThreadFeedFilter : FeedFilter<Note>() {
var account: Account? = null
var user: User? = null
fun loadUserProfile(accountLoggedIn: Account, user: User) {
2023-03-07 18:46:44 +00:00
account = accountLoggedIn
this.user = user
2023-03-07 18:46:44 +00:00
}
2023-03-07 18:46:44 +00:00
override fun feed(): List<Note> {
val longFormNotes = LocalCache.addressables.values
.filter { it.author == user && (it.event !is PeopleListEvent && it.event !is BookmarkListEvent && it.event !is AppRecommendationEvent) }
2023-03-07 18:46:44 +00:00
return user?.notes
?.plus(longFormNotes)
?.filter { account?.isAcceptable(it) == true && it.isNewThread() }
?.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
2023-03-07 18:46:44 +00:00
?.reversed() ?: emptyList()
}
}