diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-19 22:10:23 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-19 22:10:23 +0100 |
| commit | 29a093993ce7d0210ac39ceb1a25acc9350492e7 (patch) | |
| tree | b8ae2a13b975b051bda7e9461f1b8fddd986b3ca /src/sub_commands | |
| parent | dde029b4f5988cfa830ebc36bee0f35c93bd2544 (diff) | |
feat: save created events to cache
as soon as they are successfully sent to at least one relay
Diffstat (limited to 'src/sub_commands')
| -rw-r--r-- | src/sub_commands/init.rs | 2 | ||||
| -rw-r--r-- | src/sub_commands/push.rs | 1 | ||||
| -rw-r--r-- | src/sub_commands/send.rs | 7 |
3 files changed, 9 insertions, 1 deletions
diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 44e288f..e46bf74 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs | |||
| @@ -52,6 +52,7 @@ pub struct SubCommandArgs { | |||
| 52 | #[allow(clippy::too_many_lines)] | 52 | #[allow(clippy::too_many_lines)] |
| 53 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | 53 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { |
| 54 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 54 | let git_repo = Repo::discover().context("cannot find a git repository")?; |
| 55 | let git_repo_path = git_repo.get_path()?; | ||
| 55 | 56 | ||
| 56 | let root_commit = git_repo | 57 | let root_commit = git_repo |
| 57 | .get_root_commit() | 58 | .get_root_commit() |
| @@ -313,6 +314,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 313 | 314 | ||
| 314 | send_events( | 315 | send_events( |
| 315 | &client, | 316 | &client, |
| 317 | git_repo_path, | ||
| 316 | vec![repo_event], | 318 | vec![repo_event], |
| 317 | user_ref.relays.write(), | 319 | user_ref.relays.write(), |
| 318 | relays.clone(), | 320 | relays.clone(), |
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index 111a14a..d05158f 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs | |||
| @@ -191,6 +191,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 191 | 191 | ||
| 192 | send_events( | 192 | send_events( |
| 193 | &client, | 193 | &client, |
| 194 | git_repo_path, | ||
| 194 | patch_events, | 195 | patch_events, |
| 195 | user_ref.relays.write(), | 196 | user_ref.relays.write(), |
| 196 | repo_ref.relays.clone(), | 197 | repo_ref.relays.clone(), |
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index f94eed3..95d3eb0 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs | |||
| @@ -239,6 +239,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re | |||
| 239 | 239 | ||
| 240 | send_events( | 240 | send_events( |
| 241 | &client, | 241 | &client, |
| 242 | git_repo_path, | ||
| 242 | events.clone(), | 243 | events.clone(), |
| 243 | user_ref.relays.write(), | 244 | user_ref.relays.write(), |
| 244 | repo_ref.relays.clone(), | 245 | repo_ref.relays.clone(), |
| @@ -279,6 +280,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re | |||
| 279 | pub async fn send_events( | 280 | pub async fn send_events( |
| 280 | #[cfg(test)] client: &crate::client::MockConnect, | 281 | #[cfg(test)] client: &crate::client::MockConnect, |
| 281 | #[cfg(not(test))] client: &Client, | 282 | #[cfg(not(test))] client: &Client, |
| 283 | git_repo_path: &Path, | ||
| 282 | events: Vec<nostr::Event>, | 284 | events: Vec<nostr::Event>, |
| 283 | my_write_relays: Vec<String>, | 285 | my_write_relays: Vec<String>, |
| 284 | repo_read_relays: Vec<String>, | 286 | repo_read_relays: Vec<String>, |
| @@ -392,7 +394,10 @@ pub async fn send_events( | |||
| 392 | pb.inc(0); // need to make pb display intially | 394 | pb.inc(0); // need to make pb display intially |
| 393 | let mut failed = false; | 395 | let mut failed = false; |
| 394 | for event in &events { | 396 | for event in &events { |
| 395 | match client.send_event_to(relay.as_str(), event.clone()).await { | 397 | match client |
| 398 | .send_event_to(git_repo_path, relay.as_str(), event.clone()) | ||
| 399 | .await | ||
| 400 | { | ||
| 396 | Ok(_) => pb.inc(1), | 401 | Ok(_) => pb.inc(1), |
| 397 | Err(e) => { | 402 | Err(e) => { |
| 398 | pb.set_style(pb_after_style_failed.clone()); | 403 | pb.set_style(pb_after_style_failed.clone()); |