diff --git a/src/storage/json.rs b/src/storage/json.rs index bd4fbc3..3e6d3e0 100644 --- a/src/storage/json.rs +++ b/src/storage/json.rs @@ -3,6 +3,7 @@ use std::io::BufReader; use std::path::PathBuf; use chrono::{DateTime, Utc}; use serde::{Serialize, Deserialize}; +use uuid::Uuid; use std::io::Write; // use sha2::{Digest, Sha512}; use std::collections::LinkedList; @@ -22,6 +23,7 @@ struct Store { hash: String, last_sync: Option>, last_edit: DateTime, + last_memo: Option, memo: Vec, } @@ -32,6 +34,7 @@ impl Default for Store { hash: "".to_string(), last_sync: None, last_edit: Utc::now(), + last_memo: None, memo: Vec::new(), }; } @@ -86,7 +89,7 @@ impl StorageDriver for JsonStorage { Context { last_edit: self.data.last_edit, last_sync: self.data.last_sync, - last_memo: None, // TODO + last_memo: self.data.last_memo, } ); } @@ -116,6 +119,7 @@ impl StorageDriver for JsonStorage { fn put(&mut self, m: Memo) -> Result<(), MemoError> { self.data.memo.retain(|x| x.id != m.id); + self.data.last_memo = Some(m.id.clone()); self.data.memo.push(m); self.data.last_edit = Utc::now(); self.save()?; diff --git a/src/storage/sqlite.rs b/src/storage/sqlite.rs index 1cdd60f..f8a73d3 100644 --- a/src/storage/sqlite.rs +++ b/src/storage/sqlite.rs @@ -89,12 +89,23 @@ impl SQLiteStorage { // } // } +/// ugly but idk +fn uuid_from_row(txt: Option) -> Option { + match txt { + Some(txt) => { + Uuid::parse_str(&txt).ok() + }, + None => None, + } +} + impl StorageDriver for SQLiteStorage { fn ctx(&self) -> Result { return Ok(self.conn.query_row("SELECT * FROM state", [], |row| { return Ok(Context { last_edit: row.get(0)?, last_sync: row.get(1).ok(), + last_memo: uuid_from_row(row.get(2).ok()), ..Default::default() }); })?); @@ -140,6 +151,7 @@ impl StorageDriver for SQLiteStorage { params![m.id.to_string(), m.tag, m.body, m.due, m.done, m.last_edit], )?; tx.execute("UPDATE state SET last_edit = ?", params![Utc::now()])?; + tx.execute("UPDATE state SET last_memo = ?", params![m.id.to_string()])?; tx.commit()?; Ok(()) }