upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs13
-rw-r--r--src/sub_commands/login.rs1
2 files changed, 6 insertions, 8 deletions
diff --git a/src/client.rs b/src/client.rs
index 929f19a..84bfb11 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -27,7 +27,7 @@ pub struct Client {
27pub trait Connect { 27pub trait Connect {
28 fn default() -> Self; 28 fn default() -> Self;
29 fn new(opts: Params) -> Self; 29 fn new(opts: Params) -> Self;
30 async fn connect(&self) -> Result<()>; 30 async fn set_keys(&mut self, keys: &nostr::Keys);
31 async fn disconnect(&self) -> Result<()>; 31 async fn disconnect(&self) -> Result<()>;
32 fn get_fallback_relays(&self) -> &Vec<String>; 32 fn get_fallback_relays(&self) -> &Vec<String>;
33 async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>; 33 async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>;
@@ -55,12 +55,9 @@ impl Connect for Client {
55 fallback_relays: opts.fallback_relays, 55 fallback_relays: opts.fallback_relays,
56 } 56 }
57 } 57 }
58 async fn connect(&self) -> Result<()> { 58
59 for relay in &self.fallback_relays { 59 async fn set_keys(&mut self, keys: &nostr::Keys) {
60 self.client.add_relay(relay.as_str(), None).await?; 60 self.client.set_keys(keys).await;
61 }
62 self.client.connect().await;
63 Ok(())
64 } 61 }
65 62
66 async fn disconnect(&self) -> Result<()> { 63 async fn disconnect(&self) -> Result<()> {
@@ -73,6 +70,8 @@ impl Connect for Client {
73 } 70 }
74 71
75 async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> { 72 async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> {
73 self.client.add_relay(url, None).await?;
74 self.client.connect_relay(url).await?;
76 Ok(self.client.send_event_to(url, event).await?) 75 Ok(self.client.send_event_to(url, event).await?)
77 } 76 }
78 77
diff --git a/src/sub_commands/login.rs b/src/sub_commands/login.rs
index b93e9bc..43ce480 100644
--- a/src/sub_commands/login.rs
+++ b/src/sub_commands/login.rs
@@ -24,7 +24,6 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> {
24 #[cfg(test)] 24 #[cfg(test)]
25 let client = <MockConnect as std::default::Default>::default(); 25 let client = <MockConnect as std::default::Default>::default();
26 26
27 client.connect().await?;
28 login::launch(&args.nsec, &args.password, Some(&client)).await?; 27 login::launch(&args.nsec, &args.password, Some(&client)).await?;
29 client.disconnect().await?; 28 client.disconnect().await?;
30 Ok(()) 29 Ok(())