Fixes kind3 relay lists connecting with Search and Wallet connect types.

This commit is contained in:
Vitor Pamplona 2024-06-28 19:39:56 -04:00
parent 0df37d6694
commit 2230d1467c
4 changed files with 21 additions and 23 deletions

View File

@ -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<RelaySetupInfo> = localRelays.map { RelaySetupInfo(RelayUrlFormatter.normalize(it.url), it.read, it.write, it.feedTypes) }.toTypedArray()
fun convertLocalRelays(): Array<RelaySetupInfo> = localRelays.map { RelaySetupInfo(RelayUrlFormatter.normalize(it.url), it.read, it.write, it.feedTypes.minus(setOf(FeedType.SEARCH, FeedType.WALLET_CONNECT))) }.toTypedArray()
fun activeGlobalRelays(): Array<String> =
connectToRelays.value

View File

@ -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(),
),
)

View File

@ -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 <T> Iterable<T>.updated(
fun <T> togglePresenceInSet(
set: Set<T>,
item: T,
): Set<T> {
return if (set.contains(item)) set.minus(item) else set.plus(item)
}
): Set<T> = if (set.contains(item)) set.minus(item) else set.plus(item)

View File

@ -56,7 +56,7 @@ class Relay(
val url: String,
val read: Boolean = true,
val write: Boolean = true,
val activeTypes: Set<FeedType> = FeedType.values().toSet(),
val activeTypes: Set<FeedType>,
) {
companion object {
// waits 3 minutes to reconnect once things fail