Move mapping function from FollowSetFeedFilter to FollowSet.
This commit is contained in:
@@ -22,39 +22,12 @@ package com.vitorpamplona.amethyst.ui.dal
|
|||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.quartz.events.PeopleListEvent
|
|
||||||
|
|
||||||
class FollowSetFeedFilter(
|
class FollowSetFeedFilter(
|
||||||
val account: Account,
|
val account: Account,
|
||||||
) : FeedFilter<Note>() {
|
) : FeedFilter<Note>() {
|
||||||
override fun feedKey(): String = account.userProfile().pubkeyHex
|
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> =
|
override fun feed(): List<Note> =
|
||||||
account
|
account
|
||||||
.followSetNotesFlow()
|
.followSetNotesFlow()
|
||||||
|
|||||||
@@ -83,7 +83,38 @@ class PeopleListEvent(
|
|||||||
val title: String,
|
val title: String,
|
||||||
val description: String?,
|
val description: String?,
|
||||||
val profileList: Set<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
|
@Immutable
|
||||||
class UsersAndWords(
|
class UsersAndWords(
|
||||||
|
|||||||
Reference in New Issue
Block a user