From 1f3547b7729e73770bec9d6ddae60f37613007df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 00:32:04 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(core):=20renames,=20deadlines?= =?UTF-8?q?=20and=20deletions=20reach=20the=20mail=20engine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/izlek-core/src/store/mod.rs | 9 +++++-- crates/izlek-core/src/store/turso_store.rs | 31 +++++++++++----------- crates/izlek-core/tests/store.rs | 21 +++++++++++++-- crates/izlek-web/src/detail.rs | 12 ++++++--- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/crates/izlek-core/src/store/mod.rs b/crates/izlek-core/src/store/mod.rs index 41b2aec..d207ba6 100644 --- a/crates/izlek-core/src/store/mod.rs +++ b/crates/izlek-core/src/store/mod.rs @@ -421,6 +421,9 @@ pub struct Deletion { /// The recorded freeing, written only when something was actually freed: /// a delete that frees nobody is not an event any rule can fire on. pub event: Option, + /// The id of the Deleted activity row, always written, so the mail engine + /// can fire on it the same way it does the rest of a task's trail. + pub activity_id: String, } /// One row of a task's activity trail, as an event a rule can fire on. Covers @@ -702,7 +705,9 @@ pub trait Store: BoardReads + DetailReads + 'static { async fn delete_attachment(&self, id: &str) -> Result; /// Writes the title, description and deadline the detail screen saved, and - /// records one activity line per field that actually changed. + /// records one activity line per field that actually changed. Returns the + /// ids of the activity rows it wrote, in write order — empty when nothing + /// changed — so the caller can hand each to the mail engine. async fn save_task( &self, task_id: &str, @@ -711,7 +716,7 @@ pub trait Store: BoardReads + DetailReads + 'static { deadline: Option, actor_id: &str, at: OffsetDateTime, - ) -> Result<()>; + ) -> Result>; /// Moves a task into a column and records the crossing, both in one /// transaction, so a transition never exists without the move that caused diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index 265827b..dd9844b 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -1561,7 +1561,7 @@ impl Store for TursoStore { deadline: Option, actor_id: &str, at: OffsetDateTime, - ) -> Result<()> { + ) -> Result> { let deadline = deadline.map(day_text).transpose()?; let stamp = stamp(at)?; @@ -1582,7 +1582,7 @@ impl Store for TursoStore { ) .await?; let Some(row) = rows.next().await? else { - return Ok(false); + return Ok(None); }; let was_title = row.get::(0)?; let was_description = row.get::(1)?; @@ -1609,28 +1609,24 @@ impl Store for TursoStore { None => lines.push((ActivityKind::DeadlineCleared.as_str(), String::new())), } } + let mut ids = Vec::with_capacity(lines.len()); for (kind, detail) in lines { + let id = Uuid::new_v4().to_string(); tx.execute( "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \ VALUES (?1, ?2, ?3, ?4, ?5, ?6)", - params![ - Uuid::new_v4().to_string(), - task_id, - actor_id, - kind, - detail, - stamp.clone() - ], + params![id.clone(), task_id, actor_id, kind, detail, stamp.clone()], ) .await?; + ids.push(id); } - Ok::<_, turso::Error>(true) + Ok::<_, turso::Error>(Some(ids)) } .await; match written { - Ok(true) => tx.commit().await.map_err(backend), - Ok(false) => { + Ok(Some(ids)) => tx.commit().await.map(|_| ids).map_err(backend), + Ok(None) => { let _ = tx.rollback().await; Err(StoreError::NotFound) } @@ -1870,11 +1866,12 @@ impl Store for TursoStore { params![task_id, stamp.clone()], ) .await?; + let deleted_activity_id = Uuid::new_v4().to_string(); tx.execute( "INSERT INTO activity (id, task_id, actor_id, kind, detail, created_at) \ VALUES (?1, ?2, ?3, ?4, '', ?5)", params![ - Uuid::new_v4().to_string(), + deleted_activity_id.clone(), task_id, actor_id, ActivityKind::Deleted.as_str(), @@ -1948,7 +1945,11 @@ impl Store for TursoStore { .await?; Some(event) }; - Ok::<_, turso::Error>(Some(Deletion { freed, event })) + Ok::<_, turso::Error>(Some(Deletion { + freed, + event, + activity_id: deleted_activity_id, + })) } .await; diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index c1c88ed..a439e3b 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -2375,6 +2375,10 @@ async fn deleting_a_task_frees_what_was_waiting_on_it() { deletion.event.is_some(), "a delete that freed somebody is an event the rules can fire on" ); + match store.event(&deletion.activity_id).await.unwrap() { + Some(Event::Happened(ev)) => assert_eq!(ev.kind, ActivityKind::Deleted), + other => panic!("expected a Happened Deleted event, got {other:?}"), + } // The deleted task is gone from the board and from the edges it stood in. let board = board_of(store, &workspace).await; @@ -2433,7 +2437,7 @@ async fn saving_a_task_records_only_what_changed() { let store = &scratch.store; let task = add_task(store, &workspace, "Backlog", "first title", None, &admin).await; - store + let ids = store .save_task( &task, "first title", @@ -2444,6 +2448,7 @@ async fn saving_a_task_records_only_what_changed() { ) .await .unwrap(); + assert_eq!(ids, Vec::::new(), "a save that changed nothing writes nothing"); let detail = load_detail(store, &workspace, &task) .await .unwrap() @@ -2455,7 +2460,7 @@ async fn saving_a_task_records_only_what_changed() { "a save that changed nothing says nothing" ); - store + let ids = store .save_task( &task, "second title", @@ -2466,6 +2471,18 @@ async fn saving_a_task_records_only_what_changed() { ) .await .unwrap(); + let expected_kinds = [ + ActivityKind::Retitled, + ActivityKind::Described, + ActivityKind::DeadlineSet, + ]; + assert_eq!(ids.len(), expected_kinds.len()); + for (id, kind) in ids.iter().zip(expected_kinds) { + match store.event(id).await.unwrap() { + Some(Event::Happened(ev)) => assert_eq!(ev.kind, kind), + other => panic!("expected a Happened event for {id}, got {other:?}"), + } + } let detail = load_detail(store, &workspace, &task) .await .unwrap() diff --git a/crates/izlek-web/src/detail.rs b/crates/izlek-web/src/detail.rs index 8842f2a..e2807f4 100644 --- a/crates/izlek-web/src/detail.rs +++ b/crates/izlek-web/src/detail.rs @@ -222,8 +222,8 @@ pub async fn save_task( }, }; - accounts() - .store() + let store = accounts().store().clone(); + let activity_ids = store .save_task( &task_id, &title, @@ -234,6 +234,9 @@ pub async fn save_task( ) .await .map_err(|e| ServerFnError::new(e.to_string()))?; + for activity_id in activity_ids { + crate::server::mail().after_activity(store.clone(), activity_id); + } Ok(None) } @@ -478,8 +481,8 @@ pub async fn delete_task(task_id: String) -> Result, ServerFnErr Ok(pair) => pair, Err(refusal) => return Ok(Some(refusal)), }; - let deletion = accounts() - .store() + let store = accounts().store().clone(); + let deletion = store .delete_task(&task_id, &user.id, OffsetDateTime::now_utc()) .await .map_err(|e| ServerFnError::new(e.to_string()))?; @@ -489,6 +492,7 @@ pub async fn delete_task(task_id: String) -> Result, ServerFnErr if let Some(freeing) = deletion.event { crate::server::mail().after_freeing(freeing, deletion.freed); } + crate::server::mail().after_activity(store, deletion.activity_id); Ok(None) }