From 2230d1467c288fa7ab2c6136cc4f3a5b6078751d Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 28 Jun 2024 19:39:56 -0400 Subject: [PATCH] Fixes kind3 relay lists connecting with Search and Wallet connect types. --- .../vitorpamplona/amethyst/model/Account.kt | 6 ++-- .../ui/actions/relays/Kind3RelayListView.kt | 3 +- .../actions/relays/Kind3RelayListViewModel.kt | 33 +++++++++---------- .../vitorpamplona/ammolite/relays/Relay.kt | 2 +- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index 60fe2689f..f4cb70743 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -2685,12 +2685,12 @@ class Account( val url = RelayUrlFormatter.normalize(it.key) val localFeedTypes = - localRelays.firstOrNull { localRelay -> RelayUrlFormatter.normalize(localRelay.url) == url }?.feedTypes + localRelays.firstOrNull { localRelay -> RelayUrlFormatter.normalize(localRelay.url) == url }?.feedTypes?.minus(setOf(FeedType.SEARCH, FeedType.WALLET_CONNECT)) ?: Constants.defaultRelays .filter { defaultRelay -> defaultRelay.url == url } .firstOrNull() ?.feedTypes - ?: FeedType.values().toSet() + ?: Constants.activeTypesGlobalChats RelaySetupInfo(url, it.value.read, it.value.write, localFeedTypes) } ?: return null @@ -2698,7 +2698,7 @@ class Account( return usersRelayList.toTypedArray() } - fun convertLocalRelays(): Array = localRelays.map { RelaySetupInfo(RelayUrlFormatter.normalize(it.url), it.read, it.write, it.feedTypes) }.toTypedArray() + fun convertLocalRelays(): Array = localRelays.map { RelaySetupInfo(RelayUrlFormatter.normalize(it.url), it.read, it.write, it.feedTypes.minus(setOf(FeedType.SEARCH, FeedType.WALLET_CONNECT))) }.toTypedArray() fun activeGlobalRelays(): Array = connectToRelays.value diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt index 8741f2cdb..0a6b966ad 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListView.kt @@ -88,6 +88,7 @@ import com.vitorpamplona.amethyst.ui.theme.largeRelayIconModifier import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.warningColor import com.vitorpamplona.ammolite.relays.Constants +import com.vitorpamplona.ammolite.relays.Constants.activeTypesGlobalChats import com.vitorpamplona.ammolite.relays.FeedType import com.vitorpamplona.ammolite.relays.RelayBriefInfoCache import com.vitorpamplona.ammolite.relays.RelayStat @@ -753,7 +754,7 @@ fun Kind3RelayEditBox( url = RelayUrlFormatter.normalize(url), read = read, write = write, - feedTypes = FeedType.entries.toSet(), + feedTypes = activeTypesGlobalChats, relayStat = RelayStat(), ), ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt index de48cb790..a0f66e2f3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Kind3RelayListViewModel.kt @@ -25,6 +25,7 @@ import androidx.lifecycle.viewModelScope import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.service.Nip11CachedRetriever import com.vitorpamplona.ammolite.relays.Constants +import com.vitorpamplona.ammolite.relays.Constants.activeTypesGlobalChats import com.vitorpamplona.ammolite.relays.FeedType import com.vitorpamplona.ammolite.relays.RelaySetupInfo import com.vitorpamplona.ammolite.relays.RelayStats @@ -99,7 +100,7 @@ class Kind3RelayListViewModel : ViewModel() { .filter { defaultRelay -> defaultRelay.url == it.key } .firstOrNull() ?.feedTypes - ?: FeedType.values().toSet().toImmutableSet() + ?: activeTypesGlobalChats.toImmutableSet() Kind3BasicRelaySetupInfo( url = RelayUrlFormatter.normalize(it.key), @@ -108,8 +109,7 @@ class Kind3RelayListViewModel : ViewModel() { feedTypes = localInfoFeedTypes, relayStat = RelayStats.get(it.key), ) - } - .distinctBy { it.url } + }.distinctBy { it.url } .sortedBy { it.relayStat.receivedBytes } .reversed() } else { @@ -122,8 +122,7 @@ class Kind3RelayListViewModel : ViewModel() { feedTypes = it.feedTypes, relayStat = RelayStats.get(it.url), ) - } - .distinctBy { it.url } + }.distinctBy { it.url } .sortedBy { it.relayStat.receivedBytes } .reversed() } @@ -134,16 +133,16 @@ class Kind3RelayListViewModel : ViewModel() { hasModified = true _relays.update { - defaultRelays.map { - Kind3BasicRelaySetupInfo( - url = RelayUrlFormatter.normalize(it.url), - read = it.read, - write = it.write, - feedTypes = it.feedTypes, - relayStat = RelayStats.get(it.url), - ) - } - .distinctBy { it.url } + defaultRelays + .map { + Kind3BasicRelaySetupInfo( + url = RelayUrlFormatter.normalize(it.url), + read = it.read, + write = it.write, + feedTypes = it.feedTypes, + relayStat = RelayStats.get(it.url), + ) + }.distinctBy { it.url } .sortedBy { it.relayStat.receivedBytes } .reversed() } @@ -223,6 +222,4 @@ fun Iterable.updated( fun togglePresenceInSet( set: Set, item: T, -): Set { - return if (set.contains(item)) set.minus(item) else set.plus(item) -} +): Set = if (set.contains(item)) set.minus(item) else set.plus(item) diff --git a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/Relay.kt b/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/Relay.kt index b403af399..6d9f0fad2 100644 --- a/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/Relay.kt +++ b/ammolite/src/main/java/com/vitorpamplona/ammolite/relays/Relay.kt @@ -56,7 +56,7 @@ class Relay( val url: String, val read: Boolean = true, val write: Boolean = true, - val activeTypes: Set = FeedType.values().toSet(), + val activeTypes: Set, ) { companion object { // waits 3 minutes to reconnect once things fail