From bd94b76d1ef9741ff1a16e2a9bebeaa3b97da1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Wed, 4 Oct 2023 22:12:24 +0000 Subject: [PATCH] ui: remove unnecessary url string manipulations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a follow up commit to `768ab3e9e4f55b872253d55c53983c19ab4c3d8b` in issue #1531 Testing ------- **Device:** iPhone 14 Pro simulator **iOS:** 17.0 **Damus:** This commit **Steps:** 1. Remove all relays. 2. Add the Damus relay. 3. Add `wss://relay.snort.social/` relay **(with trailing slash)**. Shows up on the relay list. (PASS) 4. Add `wss://relay.snort.social/v1` and `wss://relay.snort.social/v2` to the list. Both show up as separate relays (PASS) 4. Watch logs and wait for the relay list event to be sent out 5. Restart Damus (to help ensure the repro is stable) 6. Try removing the Snort relay by swiping. Relay is removed successfully (PASS) 7. Try removing the "v1" relay by clicking on "Disconnect relay" in the detail page. "v1" relay (and NOT "v2") is removed (PASS) 8. Try adding `nos.lol` from the recommended list. Added successfully. (PASS) 9. Remove `nos.lol` with a long press. (PASS) Changelog-Fixed: Fix issue where relays with trailing slashes cannot be removed (#1531) Closes: https://github.com/damus-io/damus/issues/1531 Signed-off-by: Daniel D’Aquino Signed-off-by: William Casarin --- damus/Nostr/RelayURL.swift | 7 +------ damus/Views/AddRelayView.swift | 6 ------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/damus/Nostr/RelayURL.swift b/damus/Nostr/RelayURL.swift index 9ad75e06..a5568916 100644 --- a/damus/Nostr/RelayURL.swift +++ b/damus/Nostr/RelayURL.swift @@ -17,12 +17,7 @@ public struct RelayURL: Hashable, Equatable, Codable, CodingKeyRepresentable { init?(_ str: String) { guard let last = str.last else { return nil } - var urlstr = str - if last == "/" { - urlstr = String(str.dropLast(1)) - } - - guard let url = URL(string: urlstr) else { + guard let url = URL(string: str) else { return nil } diff --git a/damus/Views/AddRelayView.swift b/damus/Views/AddRelayView.swift index 280fcfee..65a69355 100644 --- a/damus/Views/AddRelayView.swift +++ b/damus/Views/AddRelayView.swift @@ -82,12 +82,6 @@ struct AddRelayView: View { new_relay = "wss://" + new_relay } - /* - if new_relay.hasSuffix("/") { - new_relay.removeLast(); - } - */ - guard let url = RelayURL(new_relay), let ev = state.contacts.event, let keypair = state.keypair.to_full() else {