notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 7f0d0106d91838ba2158ad2b5db950363ef4e9fb
parent 56f19b155d9091b66a3e8cb5924661b3e80206d1
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 10 Feb 2025 16:52:56 -0800

Merge remote-tracking branch 'github/pr/724'

Diffstat:
Mcrates/notedeck/src/storage/file_key_storage.rs | 22++++++++++++++++++----
Mcrates/notedeck/src/storage/file_storage.rs | 6+++---
Mcrates/notedeck_columns/src/decks.rs | 3++-
3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/crates/notedeck/src/storage/file_key_storage.rs b/crates/notedeck/src/storage/file_key_storage.rs @@ -47,11 +47,14 @@ impl FileKeyStorage { } fn get_selected_pubkey(&self) -> Result<Option<Pubkey>> { - let pubkey_str = self + match self .selected_key_directory - .get_file(SELECTED_PUBKEY_FILE_NAME.to_owned())?; - - Ok(serde_json::from_str(&pubkey_str)?) + .get_file(SELECTED_PUBKEY_FILE_NAME.to_owned()) + { + Ok(pubkey_str) => Ok(Some(serde_json::from_str(&pubkey_str)?)), + Err(crate::Error::Io(_)) => Ok(None), + Err(e) => Err(e), + } } fn select_pubkey(&self, pubkey: Option<Pubkey>) -> Result<()> { @@ -164,4 +167,15 @@ mod tests { assert!(resp.is_ok()); } + + #[test] + fn test_get_selected_key_when_no_file() { + let storage = FileKeyStorage::mock().unwrap(); + + // Should return Ok(None) when no key has been selected + match storage.get_selected_key() { + KeyStorageResponse::ReceivedResult(Ok(None)) => (), // This is what we expect + other => panic!("Expected Ok(None), got {:?}", other), + } + } } diff --git a/crates/notedeck/src/storage/file_storage.rs b/crates/notedeck/src/storage/file_storage.rs @@ -105,9 +105,9 @@ impl Directory { .ok_or_else(|| Error::Generic("Could not turn path to string".to_owned()))?; Ok(fs::read_to_string(filepath_str)?) } else { - Err(Error::Generic(format!( - "Requested file was not found: {}", - file_name + Err(Error::Io(io::Error::new( + io::ErrorKind::NotFound, + format!("Requested file was not found: {}", file_name), ))) } } diff --git a/crates/notedeck_columns/src/decks.rs b/crates/notedeck_columns/src/decks.rs @@ -36,8 +36,9 @@ impl Default for DecksCache { } impl DecksCache { - pub fn new(account_to_decks: HashMap<Pubkey, Decks>) -> Self { + pub fn new(mut account_to_decks: HashMap<Pubkey, Decks>) -> Self { let fallback_pubkey = FALLBACK_PUBKEY(); + account_to_decks.entry(fallback_pubkey).or_default(); Self { account_to_decks,