@@ -58,9 +58,8 @@ pub use ui::{
5858} ;
5959pub use vec3:: Vec3 ;
6060
61- /// Relay URL used for PNS event publishing and subscription.
62- /// TODO: make this configurable in the UI
63- const PNS_RELAY_URL : & str = "ws://relay.jb55.com/" ;
61+ /// Default relay URL used for PNS event publishing and subscription.
62+ const DEFAULT_PNS_RELAY : & str = "ws://relay.jb55.com/" ;
6463
6564/// Extract a 32-byte secret key from a keypair.
6665fn secret_key_bytes ( keypair : KeypairUnowned < ' _ > ) -> Option < [ u8 ; 32 ] > {
@@ -143,6 +142,8 @@ pub struct Dave {
143142 pending_deletions : Vec < DeletedSessionInfo > ,
144143 /// Local machine hostname, included in session state events.
145144 hostname : String ,
145+ /// PNS relay URL (configurable via DAVE_RELAY env or settings UI).
146+ pns_relay_url : String ,
146147}
147148
148149use update:: PermissionPublish ;
@@ -323,6 +324,10 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
323324 }
324325
325326 let settings = DaveSettings :: from_model_config ( & model_config) ;
327+ let pns_relay_url = model_config
328+ . pns_relay
329+ . clone ( )
330+ . unwrap_or_else ( || DEFAULT_PNS_RELAY . to_string ( ) ) ;
326331
327332 let directory_picker = DirectoryPicker :: new ( ) ;
328333
@@ -375,6 +380,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
375380 pending_perm_responses : Vec :: new ( ) ,
376381 pending_deletions : Vec :: new ( ) ,
377382 hostname,
383+ pns_relay_url,
378384 }
379385 }
380386
@@ -386,6 +392,10 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
386392 /// Apply new settings. Note: Provider changes require app restart to take effect.
387393 pub fn apply_settings ( & mut self , settings : DaveSettings ) {
388394 self . model_config = ModelConfig :: from_settings ( & settings) ;
395+ self . pns_relay_url = settings
396+ . pns_relay
397+ . clone ( )
398+ . unwrap_or_else ( || DEFAULT_PNS_RELAY . to_string ( ) ) ;
389399 self . settings = settings;
390400 }
391401
@@ -1950,9 +1960,10 @@ impl notedeck::App for Dave {
19501960 // Process relay events into ndb (needed when dave is the active app).
19511961 // Re-send PNS subscription when the relay (re)connects.
19521962 let pns_sub_id = self . pns_relay_sub . clone ( ) ;
1963+ let pns_relay = self . pns_relay_url . clone ( ) ;
19531964 try_process_events_core ( ctx, ui. ctx ( ) , |app_ctx, ev| {
19541965 if let enostr:: RelayEvent :: Opened = ( & ev. event ) . into ( ) {
1955- if ev. relay == PNS_RELAY_URL {
1966+ if ev. relay == pns_relay {
19561967 if let Some ( sub_id) = & pns_sub_id {
19571968 if let Some ( sk) =
19581969 app_ctx. accounts . get_selected_account ( ) . keypair ( ) . secret_key
@@ -1963,7 +1974,7 @@ impl notedeck::App for Dave {
19631974 . authors ( [ pns_keys. keypair . pubkey . bytes ( ) ] )
19641975 . build ( ) ;
19651976 let req = enostr:: ClientMessage :: req ( sub_id. clone ( ) , vec ! [ pns_filter] ) ;
1966- app_ctx. pool . send_to ( & req, PNS_RELAY_URL ) ;
1977+ app_ctx. pool . send_to ( & req, & pns_relay ) ;
19671978 tracing:: info!( "re-subscribed for PNS events after relay reconnect" ) ;
19681979 }
19691980 }
@@ -2001,8 +2012,8 @@ impl notedeck::App for Dave {
20012012 // Ensure the PNS relay is in the pool
20022013 let egui_ctx = ui. ctx ( ) . clone ( ) ;
20032014 let wakeup = move || egui_ctx. request_repaint ( ) ;
2004- if let Err ( e) = ctx. pool . add_url ( PNS_RELAY_URL . to_string ( ) , wakeup) {
2005- tracing:: warn!( "failed to add PNS relay {}: {:?}" , PNS_RELAY_URL , e) ;
2015+ if let Err ( e) = ctx. pool . add_url ( self . pns_relay_url . clone ( ) , wakeup) {
2016+ tracing:: warn!( "failed to add PNS relay {}: {:?}" , self . pns_relay_url , e) ;
20062017 }
20072018
20082019 // Remote: subscribe on PNS relay for kind-1080 authored by our PNS pubkey
@@ -2012,9 +2023,9 @@ impl notedeck::App for Dave {
20122023 . build ( ) ;
20132024 let sub_id = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
20142025 let req = enostr:: ClientMessage :: req ( sub_id. clone ( ) , vec ! [ pns_filter] ) ;
2015- ctx. pool . send_to ( & req, PNS_RELAY_URL ) ;
2026+ ctx. pool . send_to ( & req, & self . pns_relay_url ) ;
20162027 self . pns_relay_sub = Some ( sub_id) ;
2017- tracing:: info!( "subscribed for PNS events on {}" , PNS_RELAY_URL ) ;
2028+ tracing:: info!( "subscribed for PNS events on {}" , self . pns_relay_url ) ;
20182029
20192030 // Local: subscribe in ndb for kind-31988 session state events
20202031 let state_filter = nostrdb:: Filter :: new ( )
@@ -2210,7 +2221,7 @@ impl notedeck::App for Dave {
22102221 for event in all_events {
22112222 match session_events:: wrap_pns ( & event. note_json , & pns_keys) {
22122223 Ok ( pns_json) => match enostr:: ClientMessage :: event_json ( pns_json) {
2213- Ok ( msg) => ctx. pool . send_to ( & msg, PNS_RELAY_URL ) ,
2224+ Ok ( msg) => ctx. pool . send_to ( & msg, & self . pns_relay_url ) ,
22142225 Err ( e) => tracing:: warn!( "failed to build relay message: {:?}" , e) ,
22152226 } ,
22162227 Err ( e) => tracing:: warn!( "failed to PNS-wrap event: {}" , e) ,
0 commit comments