Every recorded event reaches the mail engine
Browse files at this commitb29a66e8999cc42089ffc4af7eae6f0fec160c50Parent: 39db1dc- feat
- every recorded event reaches the mail engine
3 changed files +42 -6
- crates/izlek-web/src/board.rs +2 -1
- crates/izlek-web/src/detail.rs +10 -5
- crates/izlek-web/src/server.rs +30 -0
crates/izlek-web/src/board.rsmodified+2 -1
| @@ -85,7 +85,7 @@ pub async fn create_task( | |||
| 85 | return Ok(Some(Refusal::Forbidden)); | 85 | return Ok(Some(Refusal::Forbidden)); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | - store | 88 | + let created = store |
| 89 | .create_task(NewTask { | 89 | .create_task(NewTask { |
| 90 | board_id: &board.id, | 90 | board_id: &board.id, |
| 91 | column_id: &column_id, | 91 | column_id: &column_id, |
| @@ -96,6 +96,7 @@ pub async fn create_task( | |||
| 96 | }) | 96 | }) |
| 97 | .await | 97 | .await |
| 98 | .map_err(fail)?; | 98 | .map_err(fail)?; |
| 99 | + crate::server::mail().after_activity(store, created.activity_id); | ||
| 99 | Ok(None) | 100 | Ok(None) |
| 100 | } | 101 | } |
| 101 | 102 | ||
crates/izlek-web/src/detail.rsmodified+10 -5
| @@ -268,7 +268,7 @@ pub async fn assign(task_id: String, user_id: String) -> Result<Option<Refusal>, | |||
| 268 | .assign_task(&task_id, &person.id) | 268 | .assign_task(&task_id, &person.id) |
| 269 | .await | 269 | .await |
| 270 | .map_err(fail)?; | 270 | .map_err(fail)?; |
| 271 | - store | 271 | + let activity_id = store |
| 272 | .record_activity( | 272 | .record_activity( |
| 273 | &task_id, | 273 | &task_id, |
| 274 | Some(&actor.id), | 274 | Some(&actor.id), |
| @@ -278,6 +278,7 @@ pub async fn assign(task_id: String, user_id: String) -> Result<Option<Refusal>, | |||
| 278 | ) | 278 | ) |
| 279 | .await | 279 | .await |
| 280 | .map_err(fail)?; | 280 | .map_err(fail)?; |
| 281 | + crate::server::mail().after_activity(store, activity_id); | ||
| 281 | Ok(None) | 282 | Ok(None) |
| 282 | } | 283 | } |
| 283 | 284 | ||
| @@ -304,7 +305,7 @@ pub async fn unassign(task_id: String, user_id: String) -> Result<Option<Refusal | |||
| 304 | .unassign_task(&task_id, &person.id) | 305 | .unassign_task(&task_id, &person.id) |
| 305 | .await | 306 | .await |
| 306 | .map_err(fail)?; | 307 | .map_err(fail)?; |
| 307 | - store | 308 | + let activity_id = store |
| 308 | .record_activity( | 309 | .record_activity( |
| 309 | &task_id, | 310 | &task_id, |
| 310 | Some(&actor.id), | 311 | Some(&actor.id), |
| @@ -314,6 +315,7 @@ pub async fn unassign(task_id: String, user_id: String) -> Result<Option<Refusal | |||
| 314 | ) | 315 | ) |
| 315 | .await | 316 | .await |
| 316 | .map_err(fail)?; | 317 | .map_err(fail)?; |
| 318 | + crate::server::mail().after_activity(store, activity_id); | ||
| 317 | Ok(None) | 319 | Ok(None) |
| 318 | } | 320 | } |
| 319 | 321 | ||
| @@ -351,7 +353,7 @@ pub async fn link_tasks( | |||
| 351 | Err(StoreError::Cycle) => return Ok(Some(Refusal::Cycle)), | 353 | Err(StoreError::Cycle) => return Ok(Some(Refusal::Cycle)), |
| 352 | Err(error) => return Err(ServerFnError::new(error.to_string())), | 354 | Err(error) => return Err(ServerFnError::new(error.to_string())), |
| 353 | } | 355 | } |
| 354 | - store | 356 | + let activity_id = store |
| 355 | .record_activity( | 357 | .record_activity( |
| 356 | &task_id, | 358 | &task_id, |
| 357 | Some(&actor.id), | 359 | Some(&actor.id), |
| @@ -361,6 +363,7 @@ pub async fn link_tasks( | |||
| 361 | ) | 363 | ) |
| 362 | .await | 364 | .await |
| 363 | .map_err(|e| ServerFnError::new(e.to_string()))?; | 365 | .map_err(|e| ServerFnError::new(e.to_string()))?; |
| 366 | + crate::server::mail().after_activity(store, activity_id); | ||
| 364 | Ok(None) | 367 | Ok(None) |
| 365 | } | 368 | } |
| 366 | 369 | ||
| @@ -396,7 +399,7 @@ pub async fn unlink_tasks( | |||
| 396 | .clear_dependency(&blocked, &blocking, now) | 399 | .clear_dependency(&blocked, &blocking, now) |
| 397 | .await | 400 | .await |
| 398 | .map_err(fail)?; | 401 | .map_err(fail)?; |
| 399 | - store | 402 | + let activity_id = store |
| 400 | .record_activity( | 403 | .record_activity( |
| 401 | &task_id, | 404 | &task_id, |
| 402 | Some(&actor.id), | 405 | Some(&actor.id), |
| @@ -406,6 +409,7 @@ pub async fn unlink_tasks( | |||
| 406 | ) | 409 | ) |
| 407 | .await | 410 | .await |
| 408 | .map_err(fail)?; | 411 | .map_err(fail)?; |
| 412 | + crate::server::mail().after_activity(store, activity_id); | ||
| 409 | Ok(None) | 413 | Ok(None) |
| 410 | } | 414 | } |
| 411 | 415 | ||
| @@ -432,10 +436,11 @@ pub async fn post_comment(task_id: String, body: String) -> Result<Option<Refusa | |||
| 432 | return Ok(Some(Refusal::EmptyComment)); | 436 | return Ok(Some(Refusal::EmptyComment)); |
| 433 | } | 437 | } |
| 434 | 438 | ||
| 435 | - store | 439 | + let written = store |
| 436 | .add_comment(&task_id, &user.id, body, OffsetDateTime::now_utc()) | 440 | .add_comment(&task_id, &user.id, body, OffsetDateTime::now_utc()) |
| 437 | .await | 441 | .await |
| 438 | .map_err(|e| ServerFnError::new(e.to_string()))?; | 442 | .map_err(|e| ServerFnError::new(e.to_string()))?; |
| 443 | + crate::server::mail().after_activity(store, written.activity_id); | ||
| 439 | Ok(None) | 444 | Ok(None) |
| 440 | } | 445 | } |
| 441 | 446 | ||
crates/izlek-web/src/server.rsmodified+30 -0
| @@ -76,6 +76,36 @@ impl Mail { | |||
| 76 | }); | 76 | }); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | + /// Hands a recorded activity to the engine, off the request, the same way | ||
| 80 | + /// `after` hands a transition. | ||
| 81 | + /// | ||
| 82 | + /// The activity row is already written by the time this is called; this | ||
| 83 | + /// rehydrates it and lets the engine decide whether any rule owes a mail. | ||
| 84 | + /// `store` is the same store the request already wrote through — the | ||
| 85 | + /// engine has no public handle back to it, so the caller carries it. | ||
| 86 | + pub fn after_activity(&self, store: std::sync::Arc<dyn izlek_core::store::Store>, activity_id: String) { | ||
| 87 | + let Some(engine) = self.0.clone() else { | ||
| 88 | + return; | ||
| 89 | + }; | ||
| 90 | + tokio::spawn(async move { | ||
| 91 | + let report = match store.event(&activity_id).await { | ||
| 92 | + Ok(Some(izlek_core::store::Event::Happened(ev))) => { | ||
| 93 | + match engine.on_activity(&ev).await { | ||
| 94 | + Ok(_) => { | ||
| 95 | + engine | ||
| 96 | + .deliver_owed(time::OffsetDateTime::now_utc(), 8) | ||
| 97 | + .await | ||
| 98 | + } | ||
| 99 | + Err(problem) => Err(problem), | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + Ok(_) => return, | ||
| 103 | + Err(problem) => Err(problem), | ||
| 104 | + }; | ||
| 105 | + Self::log(report); | ||
| 106 | + }); | ||
| 107 | + } | ||
| 108 | + | ||
| 79 | /// Hands a committed delete to the engine, off the request, the same way. | 109 | /// Hands a committed delete to the engine, off the request, the same way. |
| 80 | /// | 110 | /// |
| 81 | /// A blocker being deleted frees the tasks that were waiting on it just as | 111 | /// A blocker being deleted frees the tasks that were waiting on it just as |