Move mapping function from FollowSetFeedFilter to FollowSet.

This commit is contained in:
KotlinGeekDev
2024-10-30 14:48:58 +01:00
parent bc7d9eef9b
commit 0b014c5c7c
2 changed files with 32 additions and 28 deletions
@@ -22,39 +22,12 @@ package com.vitorpamplona.amethyst.ui.dal
import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.quartz.events.PeopleListEvent
class FollowSetFeedFilter(
val account: Account,
) : FeedFilter<Note>() {
override fun feedKey(): String = account.userProfile().pubkeyHex
private fun mapEventToSet(event: PeopleListEvent): PeopleListEvent.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(account.signer) { userList -> privateFollows.addAll(userList) }
return if (publicFollows.isEmpty() && privateFollows.isNotEmpty()) {
PeopleListEvent.FollowSet(
isPrivate = true,
title = listTitle,
description = listDescription,
profileList = privateFollows.toSet(),
)
} else if (publicFollows.isNotEmpty() && privateFollows.isEmpty()) {
PeopleListEvent.FollowSet(
isPrivate = false,
title = listTitle,
description = listDescription,
profileList = publicFollows.toSet(),
)
} else {
throw Exception("Mixed follow sets are not yet supported.")
}
}
override fun feed(): List<Note> =
account
.followSetNotesFlow()
@@ -83,7 +83,38 @@ class PeopleListEvent(
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(