Use a general type to represent lists, NostrList. Make FollowSet a subclass. Rename ListType to ListVisibility. Refactor accordingly.
This commit is contained in:
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.dal
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
|
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.coroutines.cancellation.CancellationException
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
@@ -29,6 +30,8 @@ import kotlin.coroutines.cancellation.CancellationException
|
|||||||
class FollowSetFeedFilter(
|
class FollowSetFeedFilter(
|
||||||
val account: Account,
|
val account: Account,
|
||||||
) : FeedFilter<FollowSet>() {
|
) : FeedFilter<FollowSet>() {
|
||||||
|
private val followSetEventPairs: MutableMap<AddressableNote, FollowSet> = mutableMapOf()
|
||||||
|
|
||||||
override fun feedKey(): String = account.userProfile().pubkeyHex
|
override fun feedKey(): String = account.userProfile().pubkeyHex
|
||||||
|
|
||||||
override fun feed(): List<FollowSet> {
|
override fun feed(): List<FollowSet> {
|
||||||
@@ -44,6 +47,14 @@ class FollowSetFeedFilter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userFollowSets.map { account.mapNoteToFollowSet(it) }
|
updateFollowSetEventPairs(userFollowSets)
|
||||||
|
return followSetEventPairs.values.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateFollowSetEventPairs(notes: Set<AddressableNote>) {
|
||||||
|
notes.forEach { note ->
|
||||||
|
val noteAndSetPair = note to account.mapNoteToFollowSet(note)
|
||||||
|
followSetEventPairs.putIfAbsent(noteAndSetPair.first, noteAndSetPair.second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -226,12 +226,12 @@ fun CustomListItem(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
followSet.type.let {
|
followSet.visibility.let {
|
||||||
val text by derivedStateOf {
|
val text by derivedStateOf {
|
||||||
when (it) {
|
when (it) {
|
||||||
ListType.Public -> "Public"
|
ListVisibility.Public -> "Public"
|
||||||
ListType.Private -> "Private"
|
ListVisibility.Private -> "Private"
|
||||||
ListType.Mixed -> "Mixed"
|
ListVisibility.Mixed -> "Mixed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Column(
|
Column(
|
||||||
@@ -243,9 +243,9 @@ fun CustomListItem(
|
|||||||
painter =
|
painter =
|
||||||
painterResource(
|
painterResource(
|
||||||
when (it) {
|
when (it) {
|
||||||
ListType.Public -> R.drawable.ic_public
|
ListVisibility.Public -> R.drawable.ic_public
|
||||||
ListType.Private -> R.drawable.incognito
|
ListVisibility.Private -> R.drawable.incognito
|
||||||
ListType.Mixed -> R.drawable.format_list_bulleted_type
|
ListVisibility.Mixed -> R.drawable.format_list_bulleted_type
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
contentDescription = "Icon for $text List",
|
contentDescription = "Icon for $text List",
|
||||||
@@ -261,7 +261,7 @@ fun CustomListItem(
|
|||||||
private fun ListItemPreview() {
|
private fun ListItemPreview() {
|
||||||
val sampleFollowSet =
|
val sampleFollowSet =
|
||||||
FollowSet(
|
FollowSet(
|
||||||
type = ListType.Mixed,
|
visibility = ListVisibility.Mixed,
|
||||||
title = "Sample List Title",
|
title = "Sample List Title",
|
||||||
description = "Sample List Description",
|
description = "Sample List Description",
|
||||||
emptySet(),
|
emptySet(),
|
||||||
|
|||||||
+4
-4
@@ -26,11 +26,11 @@ import com.vitorpamplona.quartz.nip51Lists.PeopleListEvent
|
|||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
data class FollowSet(
|
data class FollowSet(
|
||||||
val type: ListType,
|
val visibility: ListVisibility,
|
||||||
val title: String,
|
val title: String,
|
||||||
val description: String?,
|
val description: String?,
|
||||||
val profileList: Set<String>,
|
val profileList: Set<String>,
|
||||||
) {
|
) : NostrList(listVisibility = visibility, content = profileList) {
|
||||||
companion object {
|
companion object {
|
||||||
fun mapEventToSet(
|
fun mapEventToSet(
|
||||||
event: PeopleListEvent,
|
event: PeopleListEvent,
|
||||||
@@ -44,14 +44,14 @@ data class FollowSet(
|
|||||||
event.privateTaggedUsers(signer) { userList -> privateFollows.addAll(userList) }
|
event.privateTaggedUsers(signer) { userList -> privateFollows.addAll(userList) }
|
||||||
return if (publicFollows.isEmpty() && privateFollows.isNotEmpty()) {
|
return if (publicFollows.isEmpty() && privateFollows.isNotEmpty()) {
|
||||||
FollowSet(
|
FollowSet(
|
||||||
type = ListType.Private,
|
visibility = ListVisibility.Private,
|
||||||
title = listTitle,
|
title = listTitle,
|
||||||
description = listDescription,
|
description = listDescription,
|
||||||
profileList = privateFollows.toSet(),
|
profileList = privateFollows.toSet(),
|
||||||
)
|
)
|
||||||
} else if (publicFollows.isNotEmpty() && privateFollows.isEmpty()) {
|
} else if (publicFollows.isNotEmpty() && privateFollows.isEmpty()) {
|
||||||
FollowSet(
|
FollowSet(
|
||||||
type = ListType.Public,
|
visibility = ListVisibility.Public,
|
||||||
title = listTitle,
|
title = listTitle,
|
||||||
description = listDescription,
|
description = listDescription,
|
||||||
profileList = publicFollows.toSet(),
|
profileList = publicFollows.toSet(),
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.lists
|
package com.vitorpamplona.amethyst.ui.screen.loggedIn.lists
|
||||||
|
|
||||||
enum class ListType {
|
enum class ListVisibility {
|
||||||
Public,
|
Public,
|
||||||
Private,
|
Private,
|
||||||
Mixed,
|
Mixed,
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.amethyst.ui.screen.loggedIn.lists
|
||||||
|
|
||||||
|
sealed class NostrList(
|
||||||
|
val listVisibility: ListVisibility,
|
||||||
|
val content: Collection<String>,
|
||||||
|
)
|
||||||
+14
-14
@@ -62,7 +62,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.window.PopupProperties
|
import androidx.compose.ui.window.PopupProperties
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.ListType
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.ListVisibility
|
||||||
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||||
@@ -133,7 +133,7 @@ fun FollowSetsActionMenu(
|
|||||||
FollowSetItem(
|
FollowSetItem(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
listHeader = list.title,
|
listHeader = list.title,
|
||||||
listType = list.type,
|
listVisibility = list.visibility,
|
||||||
isUserInList = list.profileList.contains(userHex),
|
isUserInList = list.profileList.contains(userHex),
|
||||||
onRemoveUser = {
|
onRemoveUser = {
|
||||||
removeUser(index)
|
removeUser(index)
|
||||||
@@ -174,11 +174,11 @@ private fun DropDownMenuHeader(
|
|||||||
fun generateFollowLists(): List<FollowSet> =
|
fun generateFollowLists(): List<FollowSet> =
|
||||||
List(10) { index: Int ->
|
List(10) { index: Int ->
|
||||||
FollowSet(
|
FollowSet(
|
||||||
type =
|
visibility =
|
||||||
when {
|
when {
|
||||||
index % 2 == 0 -> ListType.Private
|
index % 2 == 0 -> ListVisibility.Private
|
||||||
index in listOf(3, 7, 9) -> ListType.Mixed
|
index in listOf(3, 7, 9) -> ListVisibility.Mixed
|
||||||
else -> ListType.Public
|
else -> ListVisibility.Public
|
||||||
},
|
},
|
||||||
title = "List No $index",
|
title = "List No $index",
|
||||||
description = null,
|
description = null,
|
||||||
@@ -190,7 +190,7 @@ fun generateFollowLists(): List<FollowSet> =
|
|||||||
fun FollowSetItem(
|
fun FollowSetItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
listHeader: String,
|
listHeader: String,
|
||||||
listType: ListType,
|
listVisibility: ListVisibility,
|
||||||
isUserInList: Boolean,
|
isUserInList: Boolean,
|
||||||
onAddUser: () -> Unit,
|
onAddUser: () -> Unit,
|
||||||
onRemoveUser: () -> Unit,
|
onRemoveUser: () -> Unit,
|
||||||
@@ -281,12 +281,12 @@ fun FollowSetItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listType.let {
|
listVisibility.let {
|
||||||
val text by derivedStateOf {
|
val text by derivedStateOf {
|
||||||
when (it) {
|
when (it) {
|
||||||
ListType.Public -> "Public"
|
ListVisibility.Public -> "Public"
|
||||||
ListType.Private -> "Private"
|
ListVisibility.Private -> "Private"
|
||||||
ListType.Mixed -> "Mixed"
|
ListVisibility.Mixed -> "Mixed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,9 +298,9 @@ fun FollowSetItem(
|
|||||||
painter =
|
painter =
|
||||||
painterResource(
|
painterResource(
|
||||||
when (it) {
|
when (it) {
|
||||||
ListType.Public -> R.drawable.ic_public
|
ListVisibility.Public -> R.drawable.ic_public
|
||||||
ListType.Private -> R.drawable.incognito
|
ListVisibility.Private -> R.drawable.incognito
|
||||||
ListType.Mixed -> R.drawable.format_list_bulleted_type
|
ListVisibility.Mixed -> R.drawable.format_list_bulleted_type
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
contentDescription = "Icon for $text List",
|
contentDescription = "Icon for $text List",
|
||||||
|
|||||||
Reference in New Issue
Block a user