mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 23:53:59 +02:00
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)
This commit is contained in:
@@ -31,7 +31,6 @@ import com.vitorpamplona.amethyst.ui.note.toShortDisplay
|
|||||||
import com.vitorpamplona.quartz.experimental.bounties.addedRewardValue
|
import com.vitorpamplona.quartz.experimental.bounties.addedRewardValue
|
||||||
import com.vitorpamplona.quartz.experimental.bounties.hasAdditionalReward
|
import com.vitorpamplona.quartz.experimental.bounties.hasAdditionalReward
|
||||||
import com.vitorpamplona.quartz.lightning.LnInvoiceUtil
|
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.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
|
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
|
||||||
@@ -101,14 +100,6 @@ class AddressableNote(
|
|||||||
|
|
||||||
fun dTag(): String = address.dTag
|
fun dTag(): String = address.dTag
|
||||||
|
|
||||||
override fun wasOrShouldBeDeletedBy(
|
|
||||||
deletionEvents: Set<HexKey>,
|
|
||||||
deletionAddressables: Set<Address>,
|
|
||||||
): 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 toNAddr() = NAddress.create(address.kind, address.pubKeyHex, address.dTag, relayHintUrl())
|
||||||
|
|
||||||
fun toATag() = ATag(address, relayHintUrl())
|
fun toATag() = ATag(address, relayHintUrl())
|
||||||
@@ -911,14 +902,6 @@ open class Note(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun wasOrShouldBeDeletedBy(
|
|
||||||
deletionEvents: Set<HexKey>,
|
|
||||||
deletionAddressables: Set<Address>,
|
|
||||||
): Boolean {
|
|
||||||
val thisEvent = event
|
|
||||||
return deletionEvents.contains(idHex) || (thisEvent is AddressableEvent && deletionAddressables.contains(thisEvent.address()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toETag(): ETag {
|
fun toETag(): ETag {
|
||||||
val noteEvent = event
|
val noteEvent = event
|
||||||
return if (noteEvent != null) {
|
return if (noteEvent != null) {
|
||||||
|
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.ui.feeds
|
|||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter
|
||||||
@@ -144,11 +145,15 @@ class FeedContentState(
|
|||||||
if (deletionEvents.isEmpty()) {
|
if (deletionEvents.isEmpty()) {
|
||||||
oldNotesState.feed.value.list
|
oldNotesState.feed.value.list
|
||||||
} else {
|
} else {
|
||||||
val deletedEventIds = deletionEvents.flatMapTo(HashSet()) { it.deleteEventIds() }
|
|
||||||
val deletedEventAddresses = deletionEvents.flatMapTo(HashSet()) { it.deleteAddresses() }
|
|
||||||
oldNotesState.feed.value.list
|
oldNotesState.feed.value.list
|
||||||
.filter { !it.wasOrShouldBeDeletedBy(deletedEventIds, deletedEventAddresses) }
|
.filter {
|
||||||
.toImmutableList()
|
val noteEvent = it.event
|
||||||
|
if (noteEvent != null) {
|
||||||
|
!LocalCache.deletionIndex.hasBeenDeleted(noteEvent)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}.toImmutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
val newList =
|
val newList =
|
||||||
@@ -156,6 +161,7 @@ class FeedContentState(
|
|||||||
.updateListWith(oldList, newItems)
|
.updateListWith(oldList, newItems)
|
||||||
.distinctBy { it.idHex }
|
.distinctBy { it.idHex }
|
||||||
.toImmutableList()
|
.toImmutableList()
|
||||||
|
|
||||||
if (!equalImmutableLists(newList, oldNotesState.feed.value.list)) {
|
if (!equalImmutableLists(newList, oldNotesState.feed.value.list)) {
|
||||||
updateFeed(newList)
|
updateFeed(newList)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user