Continue refactoring of models to make things correct.

This commit is contained in:
KotlinGeekDev
2025-09-30 15:37:02 +01:00
parent 80906f2c5a
commit dfb683e00d
3 changed files with 24 additions and 39 deletions

View File

@@ -31,7 +31,7 @@ data class FollowSet(
val identifierTag: String, val identifierTag: String,
val title: String, val title: String,
val description: String?, val description: String?,
val visibility: SetVisibility, val visibility: SetVisibility = SetVisibility.Mixed,
val privateProfiles: Set<String> = emptySet(), val privateProfiles: Set<String> = emptySet(),
val publicProfiles: Set<String> = emptySet(), val publicProfiles: Set<String> = emptySet(),
) : NostrSet(setVisibility = visibility, privateContent = privateProfiles, publicContent = publicProfiles) { ) : NostrSet(setVisibility = visibility, privateContent = privateProfiles, publicContent = publicProfiles) {
@@ -54,7 +54,6 @@ data class FollowSet(
identifierTag = dTag, identifierTag = dTag,
title = listTitle, title = listTitle,
description = listDescription, description = listDescription,
visibility = SetVisibility.Private,
privateProfiles = privateFollows.toSet(), privateProfiles = privateFollows.toSet(),
) )
} else if (publicFollows.isNotEmpty() && privateFollows.isEmpty()) { } else if (publicFollows.isNotEmpty() && privateFollows.isEmpty()) {
@@ -62,7 +61,6 @@ data class FollowSet(
identifierTag = dTag, identifierTag = dTag,
title = listTitle, title = listTitle,
description = listDescription, description = listDescription,
visibility = SetVisibility.Public,
publicProfiles = publicFollows.toSet(), publicProfiles = publicFollows.toSet(),
) )
} else { } else {
@@ -70,7 +68,6 @@ data class FollowSet(
identifierTag = dTag, identifierTag = dTag,
title = listTitle, title = listTitle,
description = listDescription, description = listDescription,
visibility = SetVisibility.Public,
privateProfiles = privateFollows.toSet(), privateProfiles = privateFollows.toSet(),
publicProfiles = publicFollows.toSet(), publicProfiles = publicFollows.toSet(),
) )

View File

@@ -31,7 +31,6 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.AddressableNote import com.vitorpamplona.amethyst.model.AddressableNote
import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.nip51Lists.followSets.FollowSet import com.vitorpamplona.amethyst.model.nip51Lists.followSets.FollowSet
import com.vitorpamplona.amethyst.model.nip51Lists.followSets.SetVisibility
import com.vitorpamplona.amethyst.service.checkNotInMainThread import com.vitorpamplona.amethyst.service.checkNotInMainThread
import com.vitorpamplona.amethyst.ui.dal.FeedFilter import com.vitorpamplona.amethyst.ui.dal.FeedFilter
import com.vitorpamplona.amethyst.ui.dal.FollowSetFeedFilter import com.vitorpamplona.amethyst.ui.dal.FollowSetFeedFilter
@@ -117,8 +116,8 @@ class FollowSetFeedViewModel(
fun addFollowSet( fun addFollowSet(
setName: String, setName: String,
setDescription: String?, setDescription: String?,
isListPrivate: Boolean,
optionalFirstMemberHex: String? = null, optionalFirstMemberHex: String? = null,
firstMemberShouldBePrivate: Boolean = false,
account: Account, account: Account,
) { ) {
if (!account.settings.isWriteable()) { if (!account.settings.isWriteable()) {
@@ -129,7 +128,7 @@ class FollowSetFeedViewModel(
dTag = UUID.randomUUID().toString(), dTag = UUID.randomUUID().toString(),
title = setName, title = setName,
description = setDescription, description = setDescription,
isPrivate = isListPrivate, isPrivate = firstMemberShouldBePrivate,
firstMemberHex = optionalFirstMemberHex, firstMemberHex = optionalFirstMemberHex,
signer = account.signer, signer = account.signer,
) { ) {
@@ -179,6 +178,7 @@ class FollowSetFeedViewModel(
fun addUserToSet( fun addUserToSet(
userProfileHex: String, userProfileHex: String,
followSet: FollowSet, followSet: FollowSet,
shouldBePrivateMember: Boolean,
account: Account, account: Account,
) { ) {
if (!account.settings.isWriteable()) { if (!account.settings.isWriteable()) {
@@ -190,7 +190,7 @@ class FollowSetFeedViewModel(
PeopleListEvent.addUser( PeopleListEvent.addUser(
earlierVersion = followSetEvent, earlierVersion = followSetEvent,
pubKeyHex = userProfileHex, pubKeyHex = userProfileHex,
isPrivate = followSet.visibility == SetVisibility.Private, isPrivate = shouldBePrivateMember,
signer = account.signer, signer = account.signer,
) { ) {
account.sendMyPublicAndPrivateOutbox(it) account.sendMyPublicAndPrivateOutbox(it)

View File

@@ -228,23 +228,25 @@ class PeopleListEvent(
createdAt: Long = TimeUtils.now(), createdAt: Long = TimeUtils.now(),
onReady: (PeopleListEvent) -> Unit, onReady: (PeopleListEvent) -> Unit,
) { ) {
val isFirstMemberSpecified = firstMemberHex != null
if (description == null) { if (description == null) {
val newList = val newListTemplate =
create( build(
name = title, name = title,
person = UserTag(pubKey = firstMemberHex ?: signer.pubKey), publicPeople = if (!isPrivate && isFirstMemberSpecified) listOf(UserTag(pubKey = firstMemberHex)) else emptyList(),
isPrivate = isPrivate, privatePeople = if (isPrivate && isFirstMemberSpecified) listOf(UserTag(pubKey = firstMemberHex)) else emptyList(),
signer = signer, signer = signer,
dTag = dTag, dTag = dTag,
createdAt = createdAt, createdAt = createdAt,
) )
val newList = signer.sign(newListTemplate)
onReady(newList) onReady(newList)
} else { } else {
if (isPrivate) {
val event = val event =
build( build(
name = title, name = title,
privatePeople = listOf(UserTag(pubKey = firstMemberHex ?: signer.pubKey)), publicPeople = if (!isPrivate && isFirstMemberSpecified) listOf(UserTag(pubKey = firstMemberHex)) else emptyList(),
privatePeople = if (isPrivate && isFirstMemberSpecified) listOf(UserTag(pubKey = firstMemberHex)) else emptyList(),
signer = signer, signer = signer,
dTag = dTag, dTag = dTag,
createdAt = createdAt, createdAt = createdAt,
@@ -253,20 +255,6 @@ class PeopleListEvent(
} }
val list = signer.sign(event) val list = signer.sign(event)
onReady(list) onReady(list)
} else {
val event =
build(
name = title,
publicPeople = listOf(UserTag(pubKey = firstMemberHex ?: signer.pubKey)),
signer = signer,
dTag = dTag,
createdAt = createdAt,
) {
addUnique(arrayOf("description", description))
}
val list = signer.sign(event)
onReady(list)
}
} }
} }