commit e2b8f4e0cc9441397cfdee9eee1f4ac8112e312e
parent dbddb3a3f2e945268fb41cb951a7d7fb8aaaa14f
Author: kernelkind <kernelkind@gmail.com>
Date: Mon, 9 Dec 2024 22:34:38 -0500
columns.json migration integration
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
2 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/src/app.rs b/src/app.rs
@@ -4,7 +4,7 @@ use crate::{
app_size_handler::AppSizeHandler,
args::Args,
column::Columns,
- decks::{Decks, DecksCache},
+ decks::{Decks, DecksCache, FALLBACK_PUBKEY},
draft::Drafts,
filter::FilterState,
frame_history::FrameHistory,
@@ -450,21 +450,8 @@ impl Damus {
.as_ref()
.map(|a| a.pubkey.bytes());
- let decks_cache = if parsed_args.columns.is_empty() {
- if let Some(decks_cache) = storage::load_decks_cache(&path, &ndb) {
- info!("Using decks cache from disk");
- decks_cache
- } else {
- info!("Could read not decks cache from disk");
- let mut cache = DecksCache::new_with_demo_config(&ndb);
- for account in accounts.get_accounts() {
- cache.add_deck_default(account.pubkey);
- }
- set_demo(&mut cache, &ndb, &mut accounts, &mut unknown_ids);
-
- cache
- }
- } else {
+ let decks_cache = if !parsed_args.columns.is_empty() {
+ info!("DecksCache: loading from command line arguments");
let mut columns: Columns = Columns::new();
for col in parsed_args.columns {
if let Some(timeline) = col.into_timeline(&ndb, account) {
@@ -472,14 +459,28 @@ impl Damus {
}
}
- let mut decks_cache = DecksCache::default();
- let mut decks = Decks::default();
- *decks.active_mut().columns_mut() = columns;
-
- if let Some(acc) = account {
- decks_cache.add_decks(Pubkey::new(*acc), decks);
- }
+ columns_to_decks_cache(columns, account)
+ } else if let Some(decks_cache) = storage::load_decks_cache(&path, &ndb) {
+ info!(
+ "DecksCache: loading from disk {}",
+ crate::storage::DECKS_CACHE_FILE
+ );
decks_cache
+ } else if let Some(cols) = storage::deserialize_columns(&path, &ndb, account) {
+ info!(
+ "DecksCache: loading from disk at depreciated location {}",
+ crate::storage::COLUMNS_FILE
+ );
+ columns_to_decks_cache(cols, account)
+ } else {
+ info!("DecksCache: creating new with demo configuration");
+ let mut cache = DecksCache::new_with_demo_config(&ndb);
+ for account in accounts.get_accounts() {
+ cache.add_deck_default(account.pubkey);
+ }
+ set_demo(&mut cache, &ndb, &mut accounts, &mut unknown_ids);
+
+ cache
};
let debug = parsed_args.debug;
@@ -823,3 +824,20 @@ pub fn set_demo(
.process_action(unk_ids, ndb, &txn);
accounts.select_account(accounts.num_accounts() - 1);
}
+
+fn columns_to_decks_cache(cols: Columns, key: Option<&[u8; 32]>) -> DecksCache {
+ let mut account_to_decks: HashMap<Pubkey, Decks> = Default::default();
+ let decks = Decks::new(crate::decks::Deck::new_with_columns(
+ crate::decks::Deck::default().icon,
+ "My Deck".to_owned(),
+ cols,
+ ));
+
+ let account = if let Some(key) = key {
+ Pubkey::new(*key)
+ } else {
+ FALLBACK_PUBKEY()
+ };
+ account_to_decks.insert(account, decks);
+ DecksCache::new(account_to_decks)
+}
diff --git a/src/storage/mod.rs b/src/storage/mod.rs
@@ -1,10 +1,12 @@
mod decks;
mod file_key_storage;
mod file_storage;
+mod migration;
-pub use decks::{load_decks_cache, save_decks_cache};
+pub use decks::{load_decks_cache, save_decks_cache, DECKS_CACHE_FILE};
pub use file_key_storage::FileKeyStorage;
pub use file_storage::{delete_file, write_file, DataPath, DataPathType, Directory};
+pub use migration::{deserialize_columns, COLUMNS_FILE};
#[cfg(target_os = "macos")]
mod security_framework_key_storage;