From 3df7129f00ffcc3405779525f4abb3185f12713d Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 22 Aug 2025 12:41:03 -0400 Subject: [PATCH] Deletes unused state class --- .../nip65RelayList/OutboxRelaySetState.kt | 114 ------------------ 1 file changed, 114 deletions(-) delete mode 100644 amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/OutboxRelaySetState.kt diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/OutboxRelaySetState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/OutboxRelaySetState.kt deleted file mode 100644 index 3d93db987..000000000 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip65RelayList/OutboxRelaySetState.kt +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Copyright (c) 2025 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.model.nip65RelayList - -import com.vitorpamplona.amethyst.model.AddressableNote -import com.vitorpamplona.amethyst.model.LocalCache -import com.vitorpamplona.amethyst.model.NoteState -import com.vitorpamplona.quartz.nip01Core.core.HexKey -import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl -import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.emitAll -import kotlinx.coroutines.flow.flowOn -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onStart -import kotlinx.coroutines.flow.stateIn -import kotlinx.coroutines.flow.transformLatest - -class OutboxRelaySetState( - usersToLoad: MutableStateFlow>, - val cache: LocalCache, - scope: CoroutineScope, -) { - fun getNIP65RelayListAddress(pubkey: HexKey) = AdvertisedRelayListEvent.Companion.createAddress(pubkey) - - fun getNIP65RelayListNote(pubkey: HexKey): AddressableNote = cache.getOrCreateAddressableNote(getNIP65RelayListAddress(pubkey)) - - fun getNIP65RelayListFlow(pubkey: HexKey): StateFlow = getNIP65RelayListNote(pubkey).flow().metadata.stateFlow - - fun getNIP65RelayList(pubkey: HexKey): AdvertisedRelayListEvent? = getNIP65RelayListNote(pubkey).event as? AdvertisedRelayListEvent - - fun allRelayListFlows(followList: Set): List> = followList.map { getNIP65RelayListFlow(it) } - - fun combineAllFlows(flows: List>): Flow> = - combine(flows) { relayListNotes: Array -> - relayListNotes.mapNotNull { - (it.note.event as? AdvertisedRelayListEvent)?.writeRelaysNorm() - } - }.map { - it.flatten().toSet() - } - - @OptIn(ExperimentalCoroutinesApi::class) - val flow: StateFlow> = - usersToLoad - .transformLatest { followList -> - val flows: List> = allRelayListFlows(followList) - val relayListFlows = - if (flows.isEmpty()) { - MutableStateFlow(emptySet()) - } else { - combineAllFlows(flows) - } - emitAll(relayListFlows) - }.onStart { - emit( - usersToLoad.value - .mapNotNull { - getNIP65RelayList(it)?.writeRelaysNorm() - }.flatten() - .toSet(), - ) - }.flowOn(Dispatchers.Default) - .stateIn( - scope, - SharingStarted.Companion.Eagerly, - emptySet(), - ) - - @OptIn(ExperimentalCoroutinesApi::class) - val flowSet: StateFlow> = - flow - .map { relayList -> - relayList.map { it.url }.toSet() - }.onStart { - emit( - usersToLoad.value - .mapNotNull { - getNIP65RelayList(it)?.writeRelaysNorm()?.map { it.url }?.toSet() - }.flatten() - .toSet(), - ) - }.flowOn(Dispatchers.Default) - .stateIn( - scope, - SharingStarted.Companion.Eagerly, - emptySet(), - ) -}