2023-02-18 18:06:53 +00:00
|
|
|
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
|
2023-08-16 21:58:25 +00:00
|
|
|
import com.vitorpamplona.quartz.events.AudioTrackEvent
|
|
|
|
import com.vitorpamplona.quartz.events.ClassifiedsEvent
|
|
|
|
import com.vitorpamplona.quartz.events.GenericRepostEvent
|
|
|
|
import com.vitorpamplona.quartz.events.HighlightEvent
|
|
|
|
import com.vitorpamplona.quartz.events.LongTextNoteEvent
|
|
|
|
import com.vitorpamplona.quartz.events.PollNoteEvent
|
|
|
|
import com.vitorpamplona.quartz.events.RepostEvent
|
|
|
|
import com.vitorpamplona.quartz.events.TextNoteEvent
|
2023-02-18 18:06:53 +00:00
|
|
|
|
2023-07-14 22:22:53 +00:00
|
|
|
class UserProfileNewThreadFeedFilter(val user: User, val account: Account) : AdditiveFeedFilter<Note>() {
|
2023-06-19 18:30:15 +00:00
|
|
|
override fun feedKey(): String {
|
2023-06-24 02:00:51 +00:00
|
|
|
return account.userProfile().pubkeyHex + "-" + user.pubkeyHex
|
2023-03-07 18:46:44 +00:00
|
|
|
}
|
2023-02-18 18:06:53 +00:00
|
|
|
|
2023-03-07 18:46:44 +00:00
|
|
|
override fun feed(): List<Note> {
|
2023-07-14 22:22:53 +00:00
|
|
|
val notes = innerApplyFilter(LocalCache.notes.values)
|
|
|
|
val longFormNotes = innerApplyFilter(LocalCache.addressables.values)
|
|
|
|
|
|
|
|
return sort(notes + longFormNotes)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun applyFilter(collection: Set<Note>): Set<Note> {
|
|
|
|
return innerApplyFilter(collection)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun innerApplyFilter(collection: Collection<Note>): Set<Note> {
|
|
|
|
return collection
|
2023-07-13 12:51:54 +00:00
|
|
|
.filter {
|
|
|
|
it.author == user &&
|
2023-07-13 12:52:47 +00:00
|
|
|
(
|
2023-07-14 22:22:53 +00:00
|
|
|
it.event is TextNoteEvent ||
|
|
|
|
it.event is ClassifiedsEvent ||
|
|
|
|
it.event is RepostEvent ||
|
|
|
|
it.event is GenericRepostEvent ||
|
|
|
|
it.event is LongTextNoteEvent ||
|
|
|
|
it.event is PollNoteEvent ||
|
|
|
|
it.event is HighlightEvent ||
|
|
|
|
it.event is AudioTrackEvent
|
|
|
|
) &&
|
|
|
|
it.isNewThread() &&
|
|
|
|
account.isAcceptable(it) == true
|
|
|
|
}.toSet()
|
|
|
|
}
|
2023-03-03 16:35:29 +00:00
|
|
|
|
2023-07-14 22:22:53 +00:00
|
|
|
override fun sort(collection: Set<Note>): List<Note> {
|
|
|
|
return collection.sortedWith(compareBy({ it.createdAt() }, { it.idHex })).reversed()
|
2023-03-07 18:46:44 +00:00
|
|
|
}
|
2023-07-14 22:55:57 +00:00
|
|
|
|
|
|
|
override fun limit() = 200
|
2023-03-05 17:08:49 +00:00
|
|
|
}
|