Make a method specially for cloning/copying. Refactor createListWithDescription().

This commit is contained in:
KotlinGeekDev
2025-10-09 19:55:40 +01:00
parent a8d01e3667
commit 3c622f544c
2 changed files with 50 additions and 49 deletions

View File

@@ -191,11 +191,10 @@ class FollowSetFeedViewModel(
println("You are in read-only mode. Please login to make modifications.")
} else {
viewModelScope.launch(Dispatchers.IO) {
PeopleListEvent.createListWithDescription(
PeopleListEvent.copy(
dTag = UUID.randomUUID().toString(),
title = customCloneName ?: currentFollowSet.title,
description = customCloneDescription ?: currentFollowSet.description,
isPrivate = false,
firstPublicMembers = currentFollowSet.publicProfiles.toList(),
firstPrivateMembers = currentFollowSet.privateProfiles.toList(),
signer = account.signer,

View File

@@ -229,7 +229,6 @@ class PeopleListEvent(
createdAt: Long = TimeUtils.now(),
onReady: (PeopleListEvent) -> Unit,
) {
if (description == null) {
val newListTemplate =
build(
name = title,
@@ -248,34 +247,37 @@ class PeopleListEvent(
signer = signer,
dTag = dTag,
createdAt = createdAt,
)
) {
if (description != null) addUnique(DescriptionTag.assemble(description))
}
val newList = signer.sign(newListTemplate)
onReady(newList)
} else {
val event =
}
suspend fun copy(
dTag: String,
title: String,
description: String? = null,
firstPublicMembers: List<String> = emptyList(),
firstPrivateMembers: List<String> = emptyList(),
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (PeopleListEvent) -> Unit,
) {
val cloneTemplate =
build(
name = title,
publicPeople =
if (!isPrivate && firstPublicMembers.isNotEmpty()) {
firstPublicMembers.map { UserTag(pubKey = it) }
} else {
emptyList()
},
privatePeople =
if (isPrivate && firstPrivateMembers.isNotEmpty()) {
firstPrivateMembers.map { UserTag(pubKey = it) }
} else {
emptyList()
},
publicPeople = firstPublicMembers.map { UserTag(pubKey = it) },
privatePeople = firstPrivateMembers.map { UserTag(pubKey = it) },
signer = signer,
dTag = dTag,
createdAt = createdAt,
) {
addUnique(DescriptionTag.assemble(description))
}
val list = signer.sign(event)
onReady(list)
if (description != null) addUnique(DescriptionTag.assemble(description))
}
val listClone = signer.sign(cloneTemplate)
onReady(listClone)
}
suspend fun createListWithUser(