commit c22f5e90a33ab039cc08d4df440ad90e26c7898f
parent f2fe02032ed1debdc1101095ea9abd832a520281
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Mon, 11 Dec 2023 19:25:01 +0000
Add regional relay suggestions to Relay Config View
This patch makes sure that regional relays (e.g. Japan relays) are suggested to the relevant users on the Relay configuration view.
It also makes some small improvements to the recommended relays view layout, to allow it to comfortably show more than 4 relay suggestions without "squeezing" items.
Testing
-------
PASS
Devices:
- iPhone 15 Pro simulator running iOS 17.0.1
- iPad Air 5th generation running iOS 16.4
Damus: This commit
Configuration: No relays selected, region set to Canada
Steps:
1. Go to Relay Config view
2. Check that recommended relays are: Damus, nos.lol, nostr.wine, nostr.land. PASS
3. Change region to Japan on settings
4. Open relay config view again
5. Check that Japan relays are suggested on top of the list presented in step 2. PASS
6. Check that layout looks ok, not broken. PASS
7. Check that it is possible to scroll horizontally to see all the options. PASS
8. Add some relays. Check that it is possible to add relays. PASS
9. Check that borders of the recommended relay view fades away nicely (not just clip). PASS
10. Remove some relays. Check that they return to the suggested relays list. PASS
Real device smoke test
----------------------
Device: iPhone 13 mini running iOS 17.1
Damus: This commit
Configuration: Several relays selected. Region set to Canada.
Steps:
1. Check relay config view does not look broken. PASS
2. Remove some recommended relays. Check that they display nicely on the recommended view. PASS
3. Scroll horizontally. Scrolling should work and layout should not be broken. PASS
4. Add those recommended relays again. Should work. PASS
Closes: https://github.com/damus-io/damus/issues/1730
Changelog-Added: Add regional relay recommendations to Relay configuration view (currently for Japanese users only)
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/damus/Util/Relays/RelayBootstrap.swift b/damus/Util/Relays/RelayBootstrap.swift
@@ -7,14 +7,15 @@
import Foundation
-let BOOTSTRAP_RELAYS = [
+// This is `fileprivate` because external code should use the `get_default_bootstrap_relays` instead.
+fileprivate let BOOTSTRAP_RELAYS = [
"wss://relay.damus.io",
"wss://eden.nostr.land",
"wss://nostr.wine",
"wss://nos.lol",
]
-let REGION_SPECIFIC_BOOTSTRAP_RELAYS: [Locale.Region: [String]] = [
+fileprivate let REGION_SPECIFIC_BOOTSTRAP_RELAYS: [Locale.Region: [String]] = [
Locale.Region.japan: [
"wss://relay-jp.nostr.wirednet.jp",
"wss://yabu.me",
diff --git a/damus/Views/Relays/RecommendedRelayView.swift b/damus/Views/Relays/RecommendedRelayView.swift
@@ -23,15 +23,6 @@ struct RecommendedRelayView: View {
self.model_cache = damus.relay_model_cache
}
- var recommended: [RelayDescriptor] {
- let rs: [RelayDescriptor] = []
- return BOOTSTRAP_RELAYS.reduce(into: rs) { xs, x in
- if damus.pool.get_relay(x) == nil, let url = RelayURL(x) {
- xs.append(RelayDescriptor(url: url, info: .rw))
- }
- }
- }
-
var body: some View {
let meta = model_cache.model(with_relay_id: relay)?.metadata
@@ -84,6 +75,8 @@ struct RecommendedRelayView: View {
HStack {
Text(meta?.name ?? relay)
.lineLimit(1)
+ .frame(maxWidth: 150)
+ .padding(.vertical, 5)
}
.contextMenu {
CopyAction(relay: relay)
diff --git a/damus/Views/Relays/RelayConfigView.swift b/damus/Views/Relays/RelayConfigView.swift
@@ -23,7 +23,8 @@ struct RelayConfigView: View {
var recommended: [RelayDescriptor] {
let rs: [RelayDescriptor] = []
- return BOOTSTRAP_RELAYS.reduce(into: rs) { xs, x in
+ let recommended_relay_addresses = get_default_bootstrap_relays()
+ return recommended_relay_addresses.reduce(into: rs) { xs, x in
if state.pool.get_relay(x) == nil, let url = RelayURL(x) {
xs.append(RelayDescriptor(url: url, info: .rw))
}
@@ -87,11 +88,29 @@ struct RelayConfigView: View {
.stroke(DamusLightGradient.gradient)
}
- HStack(spacing: 20) {
- ForEach(recommended, id: \.url) { r in
- RecommendedRelayView(damus: state, relay: r.url.id)
+ ScrollView(.horizontal) {
+ HStack(spacing: 20) {
+ ForEach(recommended, id: \.url) { r in
+ RecommendedRelayView(damus: state, relay: r.url.id)
+ }
}
+ .padding(.horizontal, 30)
+ .padding(.vertical, 5)
}
+ .scrollIndicators(.hidden)
+ .mask(
+ HStack(spacing: 0) {
+ LinearGradient(gradient: Gradient(colors: [Color.clear, Color.white]), startPoint: .leading, endPoint: .trailing)
+ .frame(width: 30)
+
+ Rectangle()
+ .fill(Color.white)
+ .frame(maxWidth: .infinity)
+
+ LinearGradient(gradient: Gradient(colors: [Color.white, Color.clear]), startPoint: .leading, endPoint: .trailing)
+ .frame(width: 30)
+ }
+ )
.padding()
}
.frame(minWidth: 250, maxWidth: .infinity, minHeight: 250, alignment: .center)