Move FollowSet to it's own class.

This commit is contained in:
KotlinGeekDev
2024-10-31 16:37:05 +01:00
parent ddbaca383f
commit 3d4483ed48
2 changed files with 64 additions and 40 deletions
@@ -21,7 +21,6 @@
package com.vitorpamplona.quartz.events
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.signers.NostrSigner
import com.vitorpamplona.quartz.utils.TimeUtils
@@ -77,45 +76,6 @@ class PeopleListEvent(
}
}
@Stable
class FollowSet(
val isPrivate: Boolean,
val title: String,
val description: String?,
val profileList: Set<String>,
) {
companion object {
fun mapEventToSet(
event: PeopleListEvent,
signer: NostrSigner,
): FollowSet {
val dTag = event.dTag()
val listTitle = event.title() ?: dTag
val listDescription = event.description() ?: ""
val publicFollows = event.filterTagList("p", null)
val privateFollows = mutableListOf<String>()
event.privateTaggedUsers(signer) { userList -> privateFollows.addAll(userList) }
return if (publicFollows.isEmpty() && privateFollows.isNotEmpty()) {
FollowSet(
isPrivate = true,
title = listTitle,
description = listDescription,
profileList = privateFollows.toSet(),
)
} else if (publicFollows.isNotEmpty() && privateFollows.isEmpty()) {
FollowSet(
isPrivate = false,
title = listTitle,
description = listDescription,
profileList = publicFollows.toSet(),
)
} else {
throw Exception("Mixed follow sets are not yet supported.")
}
}
}
}
@Immutable
class UsersAndWords(
val users: Set<String> = setOf(),