- Protecting contact lists of all accounts in the device.
- Pruning events that are not from or cite an account.
This commit is contained in:
@@ -205,6 +205,10 @@ object LocalPreferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun allLocalAccountNPubs(): Set<String> {
|
||||||
|
return savedAccounts().toSet()
|
||||||
|
}
|
||||||
|
|
||||||
fun saveToEncryptedStorage(account: Account) {
|
fun saveToEncryptedStorage(account: Account) {
|
||||||
val prefs = encryptedPreferences(account.userProfile().pubkeyNpub())
|
val prefs = encryptedPreferences(account.userProfile().pubkeyNpub())
|
||||||
prefs.edit().apply {
|
prefs.edit().apply {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
|
|||||||
import com.vitorpamplona.amethyst.service.NostrVideoDataSource
|
import com.vitorpamplona.amethyst.service.NostrVideoDataSource
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
import com.vitorpamplona.amethyst.ui.actions.ImageUploader
|
import com.vitorpamplona.amethyst.ui.actions.ImageUploader
|
||||||
|
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object ServiceManager {
|
object ServiceManager {
|
||||||
@@ -117,11 +118,13 @@ object ServiceManager {
|
|||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
LocalCache.cleanObservers()
|
LocalCache.cleanObservers()
|
||||||
|
|
||||||
|
val accounts = LocalPreferences.allLocalAccountNPubs().mapNotNull { decodePublicKeyAsHexOrNull(it) }.toSet()
|
||||||
|
|
||||||
account?.let {
|
account?.let {
|
||||||
LocalCache.pruneOldAndHiddenMessages(it)
|
LocalCache.pruneOldAndHiddenMessages(it)
|
||||||
LocalCache.pruneHiddenMessages(it)
|
LocalCache.pruneHiddenMessages(it)
|
||||||
LocalCache.pruneContactLists(it)
|
LocalCache.pruneContactLists(accounts)
|
||||||
LocalCache.pruneRepliesAndReactions(it)
|
LocalCache.pruneRepliesAndReactions(accounts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -729,7 +729,7 @@ object LocalCache {
|
|||||||
|
|
||||||
val author = getOrCreateUser(event.pubKey)
|
val author = getOrCreateUser(event.pubKey)
|
||||||
val repliesTo = event.boostedPost().mapNotNull { checkGetOrCreateNote(it) } +
|
val repliesTo = event.boostedPost().mapNotNull { checkGetOrCreateNote(it) } +
|
||||||
event.taggedAddresses().mapNotNull { getOrCreateAddressableNote(it) }
|
event.taggedAddresses().map { getOrCreateAddressableNote(it) }
|
||||||
|
|
||||||
note.loadEvent(event, author, repliesTo)
|
note.loadEvent(event, author, repliesTo)
|
||||||
|
|
||||||
@@ -751,7 +751,7 @@ object LocalCache {
|
|||||||
|
|
||||||
val author = getOrCreateUser(event.pubKey)
|
val author = getOrCreateUser(event.pubKey)
|
||||||
val repliesTo = event.boostedPost().mapNotNull { checkGetOrCreateNote(it) } +
|
val repliesTo = event.boostedPost().mapNotNull { checkGetOrCreateNote(it) } +
|
||||||
event.taggedAddresses().mapNotNull { getOrCreateAddressableNote(it) }
|
event.taggedAddresses().map { getOrCreateAddressableNote(it) }
|
||||||
|
|
||||||
note.loadEvent(event, author, repliesTo)
|
note.loadEvent(event, author, repliesTo)
|
||||||
|
|
||||||
|
|||||||
@@ -253,8 +253,7 @@ open class Note(val idHex: String) {
|
|||||||
zaps = zaps.minus(note)
|
zaps = zaps.minus(note)
|
||||||
liveSet?.zaps?.invalidateData()
|
liveSet?.zaps?.invalidateData()
|
||||||
} else if (zaps.containsValue(note)) {
|
} else if (zaps.containsValue(note)) {
|
||||||
val toRemove = zaps.filterValues { it == note }
|
zaps = zaps.filterValues { it != note }
|
||||||
zaps = zaps.minus(toRemove.keys)
|
|
||||||
liveSet?.zaps?.invalidateData()
|
liveSet?.zaps?.invalidateData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ open class Event(
|
|||||||
override fun matchTag1With(text: String) = tags.any { it.size > 1 && it[1].contains(text, true) }
|
override fun matchTag1With(text: String) = tags.any { it.size > 1 && it[1].contains(text, true) }
|
||||||
|
|
||||||
override fun isTaggedUser(idHex: String) = tags.any { it.size > 1 && it[0] == "p" && it[1] == idHex }
|
override fun isTaggedUser(idHex: String) = tags.any { it.size > 1 && it[0] == "p" && it[1] == idHex }
|
||||||
|
override fun isTaggedUsers(idHexes: Set<String>) = tags.any { it.size > 1 && it[0] == "p" && it[1] in idHexes }
|
||||||
|
|
||||||
override fun isTaggedEvent(idHex: String) = tags.any { it.size > 1 && it[0] == "e" && it[1] == idHex }
|
override fun isTaggedEvent(idHex: String) = tags.any { it.size > 1 && it[0] == "e" && it[1] == idHex }
|
||||||
|
|
||||||
@@ -199,7 +200,7 @@ open class Event(
|
|||||||
return try {
|
return try {
|
||||||
hasCorrectIDHash() && hasVerifedSignature()
|
hasCorrectIDHash() && hasVerifedSignature()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Event", "Fail checking if event $id has a valid signature", e)
|
Log.e("Event", "Event $id does not have a valid signature: ${toJson()}", e)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ interface EventInterface {
|
|||||||
fun hasValidSignature(): Boolean
|
fun hasValidSignature(): Boolean
|
||||||
|
|
||||||
fun isTaggedUser(idHex: String): Boolean
|
fun isTaggedUser(idHex: String): Boolean
|
||||||
|
fun isTaggedUsers(idHex: Set<String>): Boolean
|
||||||
|
|
||||||
fun isTaggedEvent(idHex: String): Boolean
|
fun isTaggedEvent(idHex: String): Boolean
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user