kopia lustrzana https://github.com/vitorpamplona/amethyst
Streamlines Notification filter for performance
rodzic
28d501ed02
commit
3a082d131f
|
@ -3,6 +3,7 @@ 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.*
|
||||
|
||||
object NotificationFeedFilter : FeedFilter<Note>() {
|
||||
|
@ -10,45 +11,38 @@ object NotificationFeedFilter : FeedFilter<Note>() {
|
|||
|
||||
override fun feed(): List<Note> {
|
||||
val loggedInUser = account.userProfile()
|
||||
return LocalCache.notes.values
|
||||
.asSequence()
|
||||
.filter {
|
||||
it.event !is ChannelCreateEvent &&
|
||||
it.event !is ChannelMetadataEvent &&
|
||||
it.event !is LnZapRequestEvent &&
|
||||
it.event !is BadgeDefinitionEvent &&
|
||||
it.event !is BadgeProfilesEvent &&
|
||||
it.event?.isTaggedUser(loggedInUser.pubkeyHex) ?: false &&
|
||||
(it.author == null || (!account.isHidden(it.author!!) && it.author != loggedInUser))
|
||||
}
|
||||
.filter { it ->
|
||||
it.event !is TextNoteEvent ||
|
||||
(it.event as? TextNoteEvent)?.taggedEvents()?.any {
|
||||
LocalCache.checkGetOrCreateNote(it)?.author == loggedInUser
|
||||
} == true ||
|
||||
loggedInUser in it.directlyCiteUsers()
|
||||
}
|
||||
.filter { it ->
|
||||
it.event !is PollNoteEvent ||
|
||||
it.replyTo?.any { it.author == account.userProfile() } == true ||
|
||||
account.userProfile() in it.directlyCiteUsers()
|
||||
}
|
||||
.filter {
|
||||
it.event !is ReactionEvent ||
|
||||
it.replyTo?.lastOrNull()?.author == loggedInUser ||
|
||||
loggedInUser in it.directlyCiteUsers()
|
||||
}
|
||||
.filter {
|
||||
it.event !is RepostEvent ||
|
||||
it.replyTo?.lastOrNull()?.author == loggedInUser ||
|
||||
loggedInUser in it.directlyCiteUsers()
|
||||
}
|
||||
val loggedInUserHex = loggedInUser.pubkeyHex
|
||||
|
||||
return LocalCache.notes.values.filter {
|
||||
it.event !is ChannelCreateEvent &&
|
||||
it.event !is ChannelMetadataEvent &&
|
||||
it.event !is LnZapRequestEvent &&
|
||||
it.event !is BadgeDefinitionEvent &&
|
||||
it.event !is BadgeProfilesEvent &&
|
||||
it.author !== loggedInUser &&
|
||||
it.event?.isTaggedUser(loggedInUserHex) ?: false &&
|
||||
(it.author == null || !account.isHidden(it.author!!.pubkeyHex)) &&
|
||||
tagsAnEventByUser(it, loggedInUser)
|
||||
}
|
||||
.sortedBy { it.createdAt() }
|
||||
.toList()
|
||||
.reversed()
|
||||
}
|
||||
|
||||
fun isDifferentAccount(account: Account): Boolean {
|
||||
return this::account.isInitialized && this.account != account
|
||||
fun tagsAnEventByUser(note: Note, author: User): Boolean {
|
||||
val event = note.event
|
||||
|
||||
if (event is BaseTextNoteEvent) {
|
||||
return (event.citedUsers().contains(author.pubkeyHex) || note.replyTo?.any { it.author === author } == true)
|
||||
}
|
||||
|
||||
if (event is ReactionEvent) {
|
||||
return note.replyTo?.lastOrNull()?.author === author
|
||||
}
|
||||
|
||||
if (event is RepostEvent) {
|
||||
return note.replyTo?.lastOrNull()?.author === author
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue