upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/login
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/login')
-rw-r--r--src/lib/login/existing.rs3
-rw-r--r--src/lib/login/fresh.rs3
-rw-r--r--src/lib/login/mod.rs14
-rw-r--r--src/lib/login/user.rs15
4 files changed, 33 insertions, 2 deletions
diff --git a/src/lib/login/existing.rs b/src/lib/login/existing.rs
index 45727b0..4606c22 100644
--- a/src/lib/login/existing.rs
+++ b/src/lib/login/existing.rs
@@ -27,6 +27,7 @@ use crate::{
27/// - `client`: include client to fetch profiles from relays that are missing 27/// - `client`: include client to fetch profiles from relays that are missing
28/// from cache 28/// from cache
29/// - `silent`: do not print outcome in termianl 29/// - `silent`: do not print outcome in termianl
30#[allow(clippy::too_many_arguments)]
30pub async fn load_existing_login( 31pub async fn load_existing_login(
31 git_repo: &Option<&Repo>, 32 git_repo: &Option<&Repo>,
32 signer_info: &Option<SignerInfo>, 33 signer_info: &Option<SignerInfo>,
@@ -36,6 +37,7 @@ pub async fn load_existing_login(
36 #[cfg(not(test))] client: Option<&Client>, 37 #[cfg(not(test))] client: Option<&Client>,
37 silent: bool, 38 silent: bool,
38 prompt_for_password: bool, 39 prompt_for_password: bool,
40 fetch_profile_updates: bool,
39) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { 41) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> {
40 let (signer_info, source) = get_signer_info(git_repo, signer_info, password, source)?; 42 let (signer_info, source) = get_signer_info(git_repo, signer_info, password, source)?;
41 43
@@ -50,6 +52,7 @@ pub async fn load_existing_login(
50 None 52 None
51 }, 53 },
52 silent, 54 silent,
55 fetch_profile_updates,
53 ) 56 )
54 .await?; 57 .await?;
55 58
diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs
index 615c0a6..7cdbde8 100644
--- a/src/lib/login/fresh.rs
+++ b/src/lib/login/fresh.rs
@@ -46,6 +46,7 @@ pub async fn fresh_login_or_signup(
46 client, 46 client,
47 true, 47 true,
48 true, 48 true,
49 false,
49 ) 50 )
50 .await?; 51 .await?;
51 break (signer, user_ref.public_key, signer_info, source); 52 break (signer, user_ref.public_key, signer_info, source);
@@ -102,6 +103,7 @@ pub async fn fresh_login_or_signup(
102 None 103 None
103 }, 104 },
104 false, 105 false,
106 false,
105 ) 107 )
106 .await?; 108 .await?;
107 print_logged_in_as(&user_ref, client.is_none(), &source)?; 109 print_logged_in_as(&user_ref, client.is_none(), &source)?;
@@ -549,6 +551,7 @@ async fn save_to_git_config(
549 None, 551 None,
550 true, 552 true,
551 true, 553 true,
554 false,
552 ) 555 )
553 .await 556 .await
554 { 557 {
diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs
index 00dbb17..0be1e5d 100644
--- a/src/lib/login/mod.rs
+++ b/src/lib/login/mod.rs
@@ -24,9 +24,19 @@ pub async fn login_or_signup(
24 password: &Option<String>, 24 password: &Option<String>,
25 #[cfg(test)] client: Option<&MockConnect>, 25 #[cfg(test)] client: Option<&MockConnect>,
26 #[cfg(not(test))] client: Option<&Client>, 26 #[cfg(not(test))] client: Option<&Client>,
27 fetch_profile_updates: bool,
27) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { 28) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> {
28 let res = 29 let res = load_existing_login(
29 load_existing_login(git_repo, signer_info, password, &None, client, false, true).await; 30 git_repo,
31 signer_info,
32 password,
33 &None,
34 client,
35 false,
36 true,
37 fetch_profile_updates,
38 )
39 .await;
30 if res.is_ok() { 40 if res.is_ok() {
31 res 41 res
32 } else { 42 } else {
diff --git a/src/lib/login/user.rs b/src/lib/login/user.rs
index 1898a1f..c13cdf5 100644
--- a/src/lib/login/user.rs
+++ b/src/lib/login/user.rs
@@ -60,8 +60,23 @@ pub async fn get_user_details(
60 #[cfg(not(test))] client: Option<&Client>, 60 #[cfg(not(test))] client: Option<&Client>,
61 git_repo_path: Option<&Path>, 61 git_repo_path: Option<&Path>,
62 cache_only: bool, 62 cache_only: bool,
63 fetch_profile_updates: bool,
63) -> Result<UserRef> { 64) -> Result<UserRef> {
64 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await { 65 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await {
66 if fetch_profile_updates {
67 if let Some(client) = client {
68 let term = console::Term::stderr();
69 term.write_line("searching for profile updates...")?;
70 let (reports, progress_reporter) = client
71 .fetch_all(git_repo_path, None, &HashSet::from_iter(vec![*public_key]))
72 .await?;
73 if !reports.iter().any(|r| r.is_err()) {
74 progress_reporter.clear()?;
75 term.clear_last_lines(1)?;
76 }
77 return get_user_ref_from_cache(git_repo_path, public_key).await;
78 }
79 }
65 Ok(user_ref) 80 Ok(user_ref)
66 } else { 81 } else {
67 let empty = UserRef { 82 let empty = UserRef {