damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 500f8bc2ec39531afa8bf45f1199e26187e03624
parent 7a3be720b28525666c00b710dfcd94e0628e0db8
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 28 Jan 2024 15:22:20 -0800

purple: add querystring helper

We will be pulling out more things so this simplifies querystring
lookups a bit

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Models/Purple/DamusPurpleURL.swift | 10++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/damus/Models/Purple/DamusPurpleURL.swift b/damus/Models/Purple/DamusPurpleURL.swift @@ -17,10 +17,10 @@ enum DamusPurpleURL { guard components.scheme == "damus" else { return nil } switch components.path { case "purple:verify": - guard let checkout_id: String = components.queryItems?.first(where: { $0.name == "id" })?.value else { return nil } + guard let checkout_id = components.find("id") else { return nil } return .verify_npub(checkout_id: checkout_id) case "purple:welcome": - guard let checkout_id: String = components.queryItems?.first(where: { $0.name == "id" })?.value else { return nil } + guard let checkout_id = components.find("id") else { return nil } return .welcome(checkout_id: checkout_id) case "purple:landing": return .landing @@ -41,3 +41,9 @@ enum DamusPurpleURL { } } + +extension URLComponents { + func find(_ name: String) -> String? { + self.queryItems?.first(where: { qi in qi.name == name })?.value + } +}