mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-11 03:46:43 +01:00
Put in the relevant code in PeopleListEvent. Use DescriptionTag instead of manual construction.
This commit is contained in:
@@ -271,7 +271,7 @@ class PeopleListEvent(
|
|||||||
dTag = dTag,
|
dTag = dTag,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
) {
|
) {
|
||||||
addUnique(arrayOf("description", description))
|
addUnique(DescriptionTag.assemble(description))
|
||||||
}
|
}
|
||||||
val list = signer.sign(event)
|
val list = signer.sign(event)
|
||||||
onReady(list)
|
onReady(list)
|
||||||
@@ -359,5 +359,51 @@ class PeopleListEvent(
|
|||||||
)
|
)
|
||||||
onReady(modified)
|
onReady(modified)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun modifyDescription(
|
||||||
|
earlierVersion: PeopleListEvent,
|
||||||
|
newDescription: String?,
|
||||||
|
signer: NostrSigner,
|
||||||
|
createdAt: Long = TimeUtils.now(),
|
||||||
|
onReady: (PeopleListEvent) -> Unit = {},
|
||||||
|
) {
|
||||||
|
val privateTags = earlierVersion.privateTags(signer) ?: throw SignerExceptions.UnauthorizedDecryptionException()
|
||||||
|
val currentDescriptionTag = earlierVersion.tags.firstOrNull { it[0] == DescriptionTag.TAG_NAME }
|
||||||
|
val currentDescription = currentDescriptionTag?.get(1)
|
||||||
|
if (currentDescription.equals(newDescription)) {
|
||||||
|
// Do nothing
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if (newDescription == null || newDescription.isEmpty()) {
|
||||||
|
val modified =
|
||||||
|
resign(
|
||||||
|
publicTags = earlierVersion.tags.remove { it[0] == DescriptionTag.TAG_NAME },
|
||||||
|
privateTags = privateTags.remove { it[0] == DescriptionTag.TAG_NAME },
|
||||||
|
signer = signer,
|
||||||
|
createdAt = createdAt,
|
||||||
|
)
|
||||||
|
onReady(modified)
|
||||||
|
} else {
|
||||||
|
val newDescriptionTag = DescriptionTag.assemble(newDescription)
|
||||||
|
val modified =
|
||||||
|
if (currentDescriptionTag == null) {
|
||||||
|
resign(
|
||||||
|
publicTags = earlierVersion.tags.plusElement(newDescriptionTag),
|
||||||
|
privateTags = privateTags,
|
||||||
|
signer = signer,
|
||||||
|
createdAt = createdAt,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
resign(
|
||||||
|
publicTags = earlierVersion.tags.replaceAll(currentDescriptionTag, newDescriptionTag),
|
||||||
|
privateTags = privateTags.replaceAll(currentDescriptionTag, newDescriptionTag),
|
||||||
|
signer = signer,
|
||||||
|
createdAt = createdAt,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onReady(modified)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user