Removing channel create and change from Notifications Feed

This commit is contained in:
Vitor Pamplona 2023-02-01 13:17:21 -03:00
parent 2e17535a60
commit 0f968ca5e5
3 changed files with 11 additions and 6 deletions

View File

@ -3,6 +3,9 @@ package com.vitorpamplona.amethyst.service
import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
import com.vitorpamplona.amethyst.service.model.RepostEvent
import nostr.postr.JsonFilter
object NostrNotificationDataSource: NostrDataSource<Note>("NotificationFeed") {
@ -21,7 +24,9 @@ object NostrNotificationDataSource: NostrDataSource<Note>("NotificationFeed") {
set.filter { it.event != null }.filter { account.isAcceptable(it) }
}
return filtered.sortedBy { it.event?.createdAt }.reversed()
return filtered.filter {
it.event !is ChannelCreateEvent && it.event !is ChannelMetadataEvent
}.sortedBy { it.event?.createdAt }.reversed()
}
override fun updateChannelFilters() {

View File

@ -18,11 +18,9 @@ class NoteCard(val note: Note): Card() {
class LikeSetCard(val note: Note, val likeEvents: List<Note>): Card() {
val createdAt = likeEvents.maxOf { it.event?.createdAt ?: 0 }
override fun createdAt(): Long {
return createdAt
}
override fun id() = note.idHex + "L" + createdAt
}

View File

@ -9,6 +9,8 @@ import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.LocalCacheState
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.NostrDataSource
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
import com.vitorpamplona.amethyst.service.model.ReactionEvent
import com.vitorpamplona.amethyst.service.model.RepostEvent
import kotlinx.coroutines.CoroutineScope
@ -56,9 +58,9 @@ class CardFeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
private fun convertToCard(notes: List<Note>): List<Card> {
val reactionsPerEvent = mutableMapOf<Note, MutableList<Note>>()
notes
.filter { it.event is ReactionEvent }
.filter { it.event is ReactionEvent}
.forEach {
val reactedPost = it.replyTo?.last()
val reactedPost = it.replyTo?.lastOrNull() { it.event !is ChannelMetadataEvent && it.event !is ChannelCreateEvent }
if (reactedPost != null)
reactionsPerEvent.getOrPut(reactedPost, { mutableListOf() }).add(it)
}
@ -69,7 +71,7 @@ class CardFeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
notes
.filter { it.event is RepostEvent }
.forEach {
val boostedPost = it.replyTo?.last()
val boostedPost = it.replyTo?.lastOrNull() { it.event !is ChannelMetadataEvent && it.event !is ChannelCreateEvent }
if (boostedPost != null)
boostsPerEvent.getOrPut(boostedPost, { mutableListOf() }).add(it)
}