From 0b014c5c7cb4f6f8052843f4a786289c087252f2 Mon Sep 17 00:00:00 2001 From: KotlinGeekDev Date: Wed, 30 Oct 2024 14:48:58 +0100 Subject: [PATCH] Move mapping function from FollowSetFeedFilter to FollowSet. --- .../amethyst/ui/dal/FollowSetFeedFilter.kt | 27 --------------- .../quartz/events/PeopleListEvent.kt | 33 ++++++++++++++++++- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt index d766d8060..34537aa80 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt @@ -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() { 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() - 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 = account .followSetNotesFlow() diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/events/PeopleListEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/events/PeopleListEvent.kt index c6059f384..4fe42f8d5 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/events/PeopleListEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/events/PeopleListEvent.kt @@ -83,7 +83,38 @@ class PeopleListEvent( val title: String, val description: String?, val profileList: Set, - ) + ) { + 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() + 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(