From 81dbebc5a4b98d60656ab95311f051378a7a6bb7 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 8 Sep 2025 16:48:58 -0400 Subject: [PATCH] Fixes deletion computation in the update of feeds (it was not considering the a-tag's date and deleting newer events than the deletion request) --- .../com/vitorpamplona/amethyst/model/Note.kt | 17 ----------------- .../amethyst/ui/feeds/FeedContentState.kt | 14 ++++++++++---- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt index b813dcfc0..dceb0d3dd 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt @@ -31,7 +31,6 @@ import com.vitorpamplona.amethyst.ui.note.toShortDisplay import com.vitorpamplona.quartz.experimental.bounties.addedRewardValue import com.vitorpamplona.quartz.experimental.bounties.hasAdditionalReward import com.vitorpamplona.quartz.lightning.LnInvoiceUtil -import com.vitorpamplona.quartz.nip01Core.core.AddressableEvent import com.vitorpamplona.quartz.nip01Core.core.Event import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle @@ -101,14 +100,6 @@ class AddressableNote( fun dTag(): String = address.dTag - override fun wasOrShouldBeDeletedBy( - deletionEvents: Set, - deletionAddressables: Set
, - ): Boolean { - val thisEvent = event - return deletionAddressables.contains(address) || (thisEvent != null && deletionEvents.contains(thisEvent.id)) - } - fun toNAddr() = NAddress.create(address.kind, address.pubKeyHex, address.dTag, relayHintUrl()) fun toATag() = ATag(address, relayHintUrl()) @@ -911,14 +902,6 @@ open class Note( } } - open fun wasOrShouldBeDeletedBy( - deletionEvents: Set, - deletionAddressables: Set
, - ): Boolean { - val thisEvent = event - return deletionEvents.contains(idHex) || (thisEvent is AddressableEvent && deletionAddressables.contains(thisEvent.address())) - } - fun toETag(): ETag { val noteEvent = event return if (noteEvent != null) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt index 8796d527b..eada2a34b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt @@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.ui.feeds import androidx.compose.runtime.MutableState import androidx.compose.runtime.Stable import androidx.compose.runtime.mutableStateOf +import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.service.checkNotInMainThread import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter @@ -144,11 +145,15 @@ class FeedContentState( if (deletionEvents.isEmpty()) { oldNotesState.feed.value.list } else { - val deletedEventIds = deletionEvents.flatMapTo(HashSet()) { it.deleteEventIds() } - val deletedEventAddresses = deletionEvents.flatMapTo(HashSet()) { it.deleteAddresses() } oldNotesState.feed.value.list - .filter { !it.wasOrShouldBeDeletedBy(deletedEventIds, deletedEventAddresses) } - .toImmutableList() + .filter { + val noteEvent = it.event + if (noteEvent != null) { + !LocalCache.deletionIndex.hasBeenDeleted(noteEvent) + } else { + false + } + }.toImmutableList() } val newList = @@ -156,6 +161,7 @@ class FeedContentState( .updateListWith(oldList, newItems) .distinctBy { it.idHex } .toImmutableList() + if (!equalImmutableLists(newList, oldNotesState.feed.value.list)) { updateFeed(newList) }