This commit is contained in:
2026-06-06 12:50:15 +07:00
parent 6c923a1b68
commit eb10e715d9
4 changed files with 47 additions and 16 deletions

View File

@@ -502,7 +502,7 @@ class Nostr {
name: String? = null,
bio: String? = null,
picture: String? = null
) {
): Metadata {
val currentUser = signer.currentUser ?: throw IllegalStateException("User not signed in")
try {
@@ -512,13 +512,16 @@ class Nostr {
about = bio ?: record.about,
picture = picture ?: record.picture
)
val event = EventBuilder.metadata(Metadata.fromRecord(newRecord)).signAsync(signer)
val newMetadata = Metadata.fromRecord(newRecord)
val event = EventBuilder.metadata(newMetadata).signAsync(signer)
client?.sendEvent(
event = event,
target = SendEventTarget.broadcast(),
ackPolicy = AckPolicy.none()
)
return newMetadata
} catch (e: Exception) {
throw IllegalStateException("Failed to update identity: ${e.message}", e)
}

View File

@@ -346,8 +346,6 @@ class NostrViewModel(
private suspend fun blossomUpload(file: ByteArray, contentType: String): String? {
try {
var avatarUrl: String? = null
// Upload picture to Blossom
val blossom = BlossomClient(
url = "https://blossom.band",
@@ -365,12 +363,10 @@ class NostrViewModel(
val descriptor = blossom.upload(
file = file,
contentType = contentType,
signer = nostr.signer
signer = nostr.signer.get()
)
avatarUrl = descriptor?.url
return avatarUrl
return descriptor?.url
} catch (e: Exception) {
showError("Error: ${e.message}")
return null
@@ -383,11 +379,16 @@ class NostrViewModel(
picture: ByteArray? = null,
contentType: String? = null
) {
_isLoggedIn.value = true
try {
val avatarUrl = picture?.let { blossomUpload(it, contentType ?: "image/jpeg") }
nostr.updateProfile(name, bio, avatarUrl)
val newMetadata = nostr.updateProfile(name, bio, avatarUrl)
// Update the metadata state after successfully published
updateMetadata(nostr.signer.currentUser!!, newMetadata)
} catch (e: Exception) {
showError("Error: ${e.message}")
} finally {
_isLoggedIn.value = false
}
}
@@ -414,7 +415,7 @@ class NostrViewModel(
} catch (e: Exception) {
showError("Error: ${e.message}")
} finally {
_isLoggedIn.value = true
_isLoggedIn.value = false
}
}