Properly removes a note from the database

pull/152/head
Vitor Pamplona 2023-02-23 14:45:06 -05:00
rodzic f11a33f981
commit f455898ac4
3 zmienionych plików z 54 dodań i 1 usunięć

Wyświetl plik

@ -585,6 +585,19 @@ object LocalCache {
toBeRemoved.forEach { toBeRemoved.forEach {
notes.remove(it.idHex) notes.remove(it.idHex)
// Doesn't need to clean up the replies and mentions.. Too small to matter. // Doesn't need to clean up the replies and mentions.. Too small to matter.
// reverts the add
it.mentions?.forEach { user ->
user.removeTaggedPost(it)
}
it.replyTo?.forEach { replyingNote ->
replyingNote.author?.removeTaggedPost(it)
}
// Counts the replies
it.replyTo?.forEach { replyingNote ->
it.removeReply(it)
}
} }
println("PRUNE: ${toBeRemoved.size} messages removed from ${it.value.info.name}") println("PRUNE: ${toBeRemoved.size} messages removed from ${it.value.info.name}")
@ -635,6 +648,22 @@ object LocalCache {
} }
toBeRemoved.forEach { toBeRemoved.forEach {
// reverts the add
it.mentions?.forEach { user ->
user.removeTaggedPost(it)
}
it.replyTo?.forEach { replyingNote ->
replyingNote.author?.removeTaggedPost(it)
}
// Counts the replies
it.replyTo?.forEach { replyingNote ->
it.removeReply(it)
it.removeBoost(it)
it.removeReaction(it)
it.removeZap(it)
}
notes.remove(it.idHex) notes.remove(it.idHex)
} }

Wyświetl plik

@ -104,6 +104,25 @@ class Note(val idHex: String) {
} }
} }
fun removeReply(note: Note) {
replies = replies - note
}
fun removeBoost(note: Note) {
boosts = boosts - note
}
fun removeReaction(note: Note) {
reactions = reactions - note
}
fun removeZap(note: Note) {
if (zaps[note] != null) {
zaps = zaps.minus(note)
} else if (zaps.containsValue(note)) {
val toRemove = zaps.filterValues { it == note }
zaps = zaps.minus(toRemove.keys)
}
}
fun addBoost(note: Note) { fun addBoost(note: Note) {
if (note !in boosts) { if (note !in boosts) {
boosts = boosts + note boosts = boosts + note
@ -261,7 +280,8 @@ class NoteLiveSet(u: Note) {
val zaps: NoteLiveData = NoteLiveData(u) val zaps: NoteLiveData = NoteLiveData(u)
fun isInUse(): Boolean { fun isInUse(): Boolean {
return reactions.hasObservers() return metadata.hasObservers()
|| reactions.hasObservers()
|| boosts.hasObservers() || boosts.hasObservers()
|| replies.hasObservers() || replies.hasObservers()
|| reports.hasObservers() || reports.hasObservers()

Wyświetl plik

@ -123,6 +123,10 @@ class User(val pubkeyHex: String) {
} }
} }
fun removeTaggedPost(note: Note) {
taggedPosts = taggedPosts - note
}
fun addNote(note: Note) { fun addNote(note: Note) {
if (note !in notes) { if (note !in notes) {
notes = notes + note notes = notes + note