clean up code in MetadataEvent.kt

update x drawable
This commit is contained in:
David Kaspar
2024-08-14 08:11:28 +01:00
parent 97a00ff83c
commit d6d26d466b
2 changed files with 10 additions and 30 deletions
@@ -45,7 +45,7 @@ abstract class IdentityClaim(
fun create(
platformIdentity: String,
proof: String,
): IdentityClaim? {
): IdentityClaim {
val (platform, identity) = platformIdentity.split(':')
return when (platform.lowercase()) {
@@ -166,7 +166,7 @@ class MetadataEvent(
.filter { it.firstOrNull() == "i" }
.mapNotNull {
try {
IdentityClaim.create(it.get(1), it.get(2))
IdentityClaim.create(it[1], it[2])
} catch (e: Exception) {
Log.e("MetadataEvent", "Can't parse identity [${it.joinToString { "," }}]", e)
null
@@ -265,26 +265,5 @@ class MetadataEvent(
currentJson.put(key, value.trim())
}
}
fun createFromScratch(
newName: String,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (MetadataEvent) -> Unit,
) {
val prop = ObjectMapper().createObjectNode()
prop.put("name", newName.trim())
val writer = StringWriter()
ObjectMapper().writeValue(writer, prop)
val tags = mutableListOf<Array<String>>()
tags.add(
arrayOf("alt", "User profile for $newName"),
)
signer.sign(createdAt, KIND, tags.toTypedArray(), writer.buffer.toString(), onReady)
}
}
}