util.rs (826B)
1 use crate::types::{ 2 RadrootsNostrEvent, RadrootsNostrPublicKey, RadrootsNostrTimestamp, RadrootsNostrToBech32, 3 }; 4 5 pub fn radroots_nostr_npub_string(pk: &RadrootsNostrPublicKey) -> Option<String> { 6 pk.to_bech32().ok() 7 } 8 9 pub fn created_at_u32_saturating(ts: RadrootsNostrTimestamp) -> u32 { 10 u32::try_from(ts.as_secs()).unwrap_or(u32::MAX) 11 } 12 13 pub fn event_created_at_u32_saturating(event: &RadrootsNostrEvent) -> u32 { 14 created_at_u32_saturating(event.created_at) 15 } 16 17 #[cfg(feature = "http")] 18 pub fn ws_to_http(ws: &str) -> Option<String> { 19 let mut u = reqwest::Url::parse(ws).ok()?; 20 let scheme = u.scheme().to_owned(); 21 22 let new_scheme = match scheme.as_str() { 23 "wss" => "https", 24 "ws" => "http", 25 other => other, 26 }; 27 28 u.set_scheme(new_scheme).ok()?; 29 Some(u.into()) 30 }