Forces valid hexes for users and notes

This commit is contained in:
Vitor Pamplona
2023-09-09 14:39:41 -04:00
parent cda821e5af
commit 8518819dfa
@@ -53,6 +53,10 @@ object LocalCache {
// checkNotInMainThread() // checkNotInMainThread()
return users[key] ?: run { return users[key] ?: run {
require(isValidHex(key = key)) {
"$key is not a valid hex"
}
val newObject = User(key) val newObject = User(key)
users.putIfAbsent(key, newObject) ?: newObject users.putIfAbsent(key, newObject) ?: newObject
} }
@@ -98,7 +102,9 @@ object LocalCache {
checkNotInMainThread() checkNotInMainThread()
return notes.get(idHex) ?: run { return notes.get(idHex) ?: run {
require(isValidHex(idHex)) require(isValidHex(idHex)) {
"$idHex is not a valid hex"
}
val newObject = Note(idHex) val newObject = Note(idHex)
notes.putIfAbsent(idHex, newObject) ?: newObject notes.putIfAbsent(idHex, newObject) ?: newObject