From e237328ec611a5891586530c1d3cb26c16c1093b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Sun, 1 Oct 2023 00:00:00 +0100 Subject: 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 --- src/sub_commands/login.rs | 30 +++++++++++++++++++++++++----- src/sub_commands/prs/create.rs | 3 ++- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'src/sub_commands') 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 @@ use anyhow::Result; use clap; -use crate::{login, Cli}; +#[cfg(not(test))] +use crate::client::Client; +#[cfg(test)] +use crate::client::MockConnect; +use crate::{client::Connect, login, Cli}; #[derive(clap::Args)] -pub struct SubCommandArgs; +pub struct SubCommandArgs { + /// don't fetch user metadata and relay list from relays + #[arg(long, action)] + offline: bool, +} + +pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { + if command_args.offline { + login::launch(&args.nsec, &args.password, None).await?; + Ok(()) + } else { + #[cfg(not(test))] + let client = Client::default(); + #[cfg(test)] + let client = ::default(); -pub fn launch(args: &Cli, _command_args: &SubCommandArgs) -> Result<()> { - let _ = login::launch(&args.nsec, &args.password)?; - Ok(()) + client.connect().await?; + login::launch(&args.nsec, &args.password, Some(&client)).await?; + client.disconnect().await?; + Ok(()) + } } 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( // create PR event - let keys = login::launch(&cli_args.nsec, &cli_args.password)?; + // TODO add client here + let keys = login::launch(&cli_args.nsec, &cli_args.password, None).await?; let events = generate_pr_and_patch_events(&title, &description, &to_branch, &git_repo, &ahead, keys)?; -- cgit v1.2.3