mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 23:25:20 +00:00
* Refactor BLE transport event handling * Make image output paths unique * Keep queued Nostr read receipts alive * Refine BLE ingress fanout * Rediscover BLE service after invalidation * Extract BLE notification retry buffer * Extract BLE inbound write buffer * Extract BLE fragment assembly buffer * Tidy secure log handling from device run * Extract BLE outbound fragment scheduler * Harden app CI media tests * Redact BLE message content from logs * Extract BLE Noise session queues * Fix BLE read receipt UI updates * Allow self-authored RSR ingress replies * Harden read receipt queue test timing * Extract BLE outbound policy and incoming file storage * Avoid duplicate BLE link snapshots during send * Canonicalize Nostr relay URLs --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
52 lines
1.5 KiB
Swift
52 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
enum NostrRelayURL {
|
|
static func normalized(_ rawValue: String, defaultScheme: String? = nil) -> String? {
|
|
var value = rawValue.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !value.isEmpty else { return nil }
|
|
|
|
if !value.contains("://"), let defaultScheme {
|
|
value = "\(defaultScheme)://\(value)"
|
|
}
|
|
|
|
guard var components = URLComponents(string: value),
|
|
let rawScheme = components.scheme?.lowercased(),
|
|
let rawHost = components.host?.lowercased(),
|
|
!rawHost.isEmpty else {
|
|
return nil
|
|
}
|
|
|
|
switch rawScheme {
|
|
case "wss", "https":
|
|
components.scheme = "wss"
|
|
if components.port == 443 {
|
|
components.port = nil
|
|
}
|
|
case "ws", "http":
|
|
components.scheme = "ws"
|
|
if components.port == 80 {
|
|
components.port = nil
|
|
}
|
|
default:
|
|
return nil
|
|
}
|
|
|
|
components.host = rawHost
|
|
if components.path == "/" {
|
|
components.path = ""
|
|
}
|
|
components.fragment = nil
|
|
|
|
return components.string
|
|
}
|
|
|
|
static func directoryAddress(_ rawValue: String) -> String? {
|
|
guard var normalized = normalized(rawValue, defaultScheme: "wss") else { return nil }
|
|
for prefix in ["wss://", "ws://"] where normalized.hasPrefix(prefix) {
|
|
normalized.removeFirst(prefix.count)
|
|
break
|
|
}
|
|
return normalized
|
|
}
|
|
}
|