mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-07-21 15:42:27 +02:00
Support for pruning expired events.
This commit is contained in:
@ -82,13 +82,14 @@ height="80">](https://github.com/vitorpamplona/amethyst/releases)
|
|||||||
- [x] Private Messages and Small Groups (NIP-24)
|
- [x] Private Messages and Small Groups (NIP-24)
|
||||||
- [x] Gift Wraps & Seals (NIP-59)
|
- [x] Gift Wraps & Seals (NIP-59)
|
||||||
- [x] Versioned Encrypted Payloads (NIP-44)
|
- [x] Versioned Encrypted Payloads (NIP-44)
|
||||||
|
- [x] Expiration Support (NIP-40)
|
||||||
|
- [x] Status Event (NIP-315)
|
||||||
- [ ] Marketplace (NIP-15)
|
- [ ] Marketplace (NIP-15)
|
||||||
- [ ] Image/Video Capture in the app
|
- [ ] Image/Video Capture in the app
|
||||||
- [ ] Local Database
|
- [ ] Local Database
|
||||||
- [ ] Bookmarks, Pinned Posts, Muted Events (NIP-51)
|
- [ ] Bookmarks, Pinned Posts, Muted Events (NIP-51)
|
||||||
- [ ] Proof of Work in the Phone (NIP-13, NIP-20)
|
- [ ] Proof of Work in the Phone (NIP-13, NIP-20)
|
||||||
- [ ] Workspaces
|
- [ ] Workspaces
|
||||||
- [ ] Expiration Support (NIP-40)
|
|
||||||
- [ ] Infinity Scroll
|
- [ ] Infinity Scroll
|
||||||
- [ ] Relay List Metadata (NIP-65)
|
- [ ] Relay List Metadata (NIP-65)
|
||||||
- [ ] Signing Requests (NIP-46)
|
- [ ] Signing Requests (NIP-46)
|
||||||
|
@ -126,6 +126,7 @@ object ServiceManager {
|
|||||||
LocalCache.pruneContactLists(accounts)
|
LocalCache.pruneContactLists(accounts)
|
||||||
LocalCache.pruneRepliesAndReactions(accounts)
|
LocalCache.pruneRepliesAndReactions(accounts)
|
||||||
LocalCache.prunePastVersionsOfReplaceables()
|
LocalCache.prunePastVersionsOfReplaceables()
|
||||||
|
LocalCache.pruneExpiredEvents()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import com.vitorpamplona.quartz.encoders.Nip19
|
|||||||
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
|
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
|
||||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||||
import com.vitorpamplona.quartz.events.*
|
import com.vitorpamplona.quartz.events.*
|
||||||
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
import kotlinx.collections.immutable.persistentSetOf
|
import kotlinx.collections.immutable.persistentSetOf
|
||||||
import kotlinx.collections.immutable.toImmutableSet
|
import kotlinx.collections.immutable.toImmutableSet
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@ -1269,6 +1270,39 @@ object LocalCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun pruneExpiredEvents() {
|
||||||
|
checkNotInMainThread()
|
||||||
|
|
||||||
|
val now = TimeUtils.now()
|
||||||
|
|
||||||
|
val toBeRemoved = notes.filter {
|
||||||
|
(it.value.event?.expiration() ?: Long.MAX_VALUE) < now
|
||||||
|
}.values
|
||||||
|
|
||||||
|
val childrenToBeRemoved = mutableListOf<Note>()
|
||||||
|
|
||||||
|
toBeRemoved.forEach {
|
||||||
|
notes.remove(it.idHex)
|
||||||
|
|
||||||
|
it.replyTo?.forEach { masterNote ->
|
||||||
|
masterNote.removeReply(it)
|
||||||
|
masterNote.removeBoost(it)
|
||||||
|
masterNote.removeReaction(it)
|
||||||
|
masterNote.removeZap(it)
|
||||||
|
masterNote.removeReport(it)
|
||||||
|
masterNote.clearEOSE() // allows reloading of these events
|
||||||
|
}
|
||||||
|
|
||||||
|
childrenToBeRemoved.addAll(it.removeAllChildNotes())
|
||||||
|
}
|
||||||
|
|
||||||
|
removeChildrenOf(childrenToBeRemoved)
|
||||||
|
|
||||||
|
if (toBeRemoved.size > 1) {
|
||||||
|
println("PRUNE: ${toBeRemoved.size} thread replies removed.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun pruneHiddenMessages(account: Account) {
|
fun pruneHiddenMessages(account: Account) {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user