mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 01:02:33 +02:00
Pruning Messages from Hidden Users.
This commit is contained in:
@@ -72,6 +72,8 @@ object ServiceManager {
|
|||||||
|
|
||||||
account?.let {
|
account?.let {
|
||||||
LocalCache.pruneOldAndHiddenMessages(it)
|
LocalCache.pruneOldAndHiddenMessages(it)
|
||||||
|
LocalCache.pruneHiddenMessages(it)
|
||||||
|
//LocalCache.pruneNonFollows(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -567,6 +567,56 @@ object LocalCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun pruneNonFollows(account: Account) {
|
||||||
|
val follows = account.userProfile().follows
|
||||||
|
val knownPMs = account.userProfile().privateChatrooms.filter {
|
||||||
|
account.userProfile().hasSentMessagesTo(it.key) && account.isAcceptable(it.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
val followsFollow = follows.map {
|
||||||
|
it.follows
|
||||||
|
}.flatten()
|
||||||
|
|
||||||
|
val followSet = follows.plus(knownPMs).plus(account.userProfile()).plus(followsFollow)
|
||||||
|
|
||||||
|
val toBeRemoved = notes
|
||||||
|
.filter {
|
||||||
|
(it.value.author == null || it.value.author!! !in followSet) && it.value.event?.kind == TextNoteEvent.kind && it.value.liveSet?.isInUse() != true
|
||||||
|
}
|
||||||
|
|
||||||
|
toBeRemoved.forEach {
|
||||||
|
notes.remove(it.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
val toBeRemovedUsers = users
|
||||||
|
.filter {
|
||||||
|
(it.value !in followSet) && it.value.liveSet?.isInUse() != true
|
||||||
|
}
|
||||||
|
|
||||||
|
toBeRemovedUsers.forEach {
|
||||||
|
users.remove(it.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
println("PRUNE: ${toBeRemoved.size} messages removed because they came from NonFollows")
|
||||||
|
println("PRUNE: ${toBeRemovedUsers.size} users removed because are NonFollows")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun pruneHiddenMessages(account: Account) {
|
||||||
|
val toBeRemoved = account.hiddenUsers.map {
|
||||||
|
users[it]?.notes ?: emptySet()
|
||||||
|
}.flatten()
|
||||||
|
|
||||||
|
account.hiddenUsers.forEach {
|
||||||
|
users[it]?.clearNotes()
|
||||||
|
}
|
||||||
|
|
||||||
|
toBeRemoved.forEach {
|
||||||
|
notes.remove(it.idHex)
|
||||||
|
}
|
||||||
|
|
||||||
|
println("PRUNE: ${toBeRemoved.size} messages removed because they were Hidden")
|
||||||
|
}
|
||||||
|
|
||||||
// Observers line up here.
|
// Observers line up here.
|
||||||
val live: LocalCacheLiveData = LocalCacheLiveData(this)
|
val live: LocalCacheLiveData = LocalCacheLiveData(this)
|
||||||
|
|
||||||
|
@@ -126,6 +126,10 @@ class User(val pubkeyHex: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clearNotes() {
|
||||||
|
notes = setOf<Note>()
|
||||||
|
}
|
||||||
|
|
||||||
fun addReport(note: Note) {
|
fun addReport(note: Note) {
|
||||||
val author = note.author ?: return
|
val author = note.author ?: return
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user