diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
| commit | e237328ec611a5891586530c1d3cb26c16c1093b (patch) | |
| tree | 22ac36baa240354d06ae82eb070609fa3e3fcb82 /src/sub_commands | |
| parent | 000901c0cbca8464b5a89bcc93c5474f6564bafd (diff) | |
feat(login) fetch user relays and metadata
get user relay list and metadata events from relays when keys are
used and last fetch attempt was more than an hour ago
uses user's write relays if known, otherwise uses fallback relays
to achieve this a method for intergration testing event fetching
from relays was added
Diffstat (limited to 'src/sub_commands')
| -rw-r--r-- | src/sub_commands/login.rs | 30 | ||||
| -rw-r--r-- | src/sub_commands/prs/create.rs | 3 |
2 files changed, 27 insertions, 6 deletions
diff --git a/src/sub_commands/login.rs b/src/sub_commands/login.rs index 5391024..b93e9bc 100644 --- a/src/sub_commands/login.rs +++ b/src/sub_commands/login.rs | |||
| @@ -1,12 +1,32 @@ | |||
| 1 | use anyhow::Result; | 1 | use anyhow::Result; |
| 2 | use clap; | 2 | use clap; |
| 3 | 3 | ||
| 4 | use crate::{login, Cli}; | 4 | #[cfg(not(test))] |
| 5 | use crate::client::Client; | ||
| 6 | #[cfg(test)] | ||
| 7 | use crate::client::MockConnect; | ||
| 8 | use crate::{client::Connect, login, Cli}; | ||
| 5 | 9 | ||
| 6 | #[derive(clap::Args)] | 10 | #[derive(clap::Args)] |
| 7 | pub struct SubCommandArgs; | 11 | pub struct SubCommandArgs { |
| 12 | /// don't fetch user metadata and relay list from relays | ||
| 13 | #[arg(long, action)] | ||
| 14 | offline: bool, | ||
| 15 | } | ||
| 16 | |||
| 17 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | ||
| 18 | if command_args.offline { | ||
| 19 | login::launch(&args.nsec, &args.password, None).await?; | ||
| 20 | Ok(()) | ||
| 21 | } else { | ||
| 22 | #[cfg(not(test))] | ||
| 23 | let client = Client::default(); | ||
| 24 | #[cfg(test)] | ||
| 25 | let client = <MockConnect as std::default::Default>::default(); | ||
| 8 | 26 | ||
| 9 | pub fn launch(args: &Cli, _command_args: &SubCommandArgs) -> Result<()> { | 27 | client.connect().await?; |
| 10 | let _ = login::launch(&args.nsec, &args.password)?; | 28 | login::launch(&args.nsec, &args.password, Some(&client)).await?; |
| 11 | Ok(()) | 29 | client.disconnect().await?; |
| 30 | Ok(()) | ||
| 31 | } | ||
| 12 | } | 32 | } |
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs index 3047e92..0249488 100644 --- a/src/sub_commands/prs/create.rs +++ b/src/sub_commands/prs/create.rs | |||
| @@ -86,7 +86,8 @@ pub async fn launch( | |||
| 86 | 86 | ||
| 87 | // create PR event | 87 | // create PR event |
| 88 | 88 | ||
| 89 | let keys = login::launch(&cli_args.nsec, &cli_args.password)?; | 89 | // TODO add client here |
| 90 | let keys = login::launch(&cli_args.nsec, &cli_args.password, None).await?; | ||
| 90 | 91 | ||
| 91 | let events = | 92 | let events = |
| 92 | generate_pr_and_patch_events(&title, &description, &to_branch, &git_repo, &ahead, keys)?; | 93 | generate_pr_and_patch_events(&title, &description, &to_branch, &git_repo, &ahead, keys)?; |