diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/NotificationFeedFilter.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/NotificationFeedFilter.kt index bbdc8b61a..f1d53c073 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/NotificationFeedFilter.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/NotificationFeedFilter.kt @@ -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() { @@ -10,45 +11,38 @@ object NotificationFeedFilter : FeedFilter() { override fun feed(): List { 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 } }