| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
#![allow(clippy::needless_pass_by_value)] |
| 84 |
|
| 85 |
use chrono::{DateTime, Utc}; |
| 86 |
use goingson_core::EmailId; |
| 87 |
use quasi_declare::declare; |
| 88 |
use quasi_router::layout::{FieldKind, Tone}; |
| 89 |
use quasi_router::screen::{Choice, Field, Tag}; |
| 90 |
use quasi_router::{Action, Node, Response, RouteError, Router}; |
| 91 |
|
| 92 |
use crate::state::{AppState, DESKTOP_USER_ID}; |
| 93 |
|
| 94 |
#[cfg(test)] |
| 95 |
mod tests; |
| 96 |
|
| 97 |
|
| 98 |
const BODY: &str = "compose"; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
const SAVED: &str = "compose-saved"; |
| 104 |
|
| 105 |
|
| 106 |
const FROM: &str = "from"; |
| 107 |
const TO: &str = "to"; |
| 108 |
const CC: &str = "cc"; |
| 109 |
const BCC: &str = "bcc"; |
| 110 |
const SUBJECT: &str = "subject"; |
| 111 |
const MESSAGE: &str = "body"; |
| 112 |
|
| 113 |
const SEND_AFTER: &str = "send_after"; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
const MAX_TOTAL_ATTACHMENT_BYTES: i64 = 25 * 1024 * 1024; |
| 122 |
|
| 123 |
|
| 124 |
fn start(state: &AppState, _request: quasi_router::Request) -> Result<Response, RouteError> { |
| 125 |
let draft = save(state, EmailId::new(), Fields::default())?; |
| 126 |
Ok(Response::goto(Action::get(format!( |
| 127 |
"/compose/{}", |
| 128 |
draft.id |
| 129 |
)))) |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
#[derive(Default)] |
| 134 |
struct Fields { |
| 135 |
from: Option<EmailId>, |
| 136 |
to: Option<String>, |
| 137 |
cc: Option<String>, |
| 138 |
bcc: Option<String>, |
| 139 |
subject: Option<String>, |
| 140 |
body: Option<String>, |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
fn save(state: &AppState, id: EmailId, fields: Fields) -> Result<goingson_core::Email, RouteError> { |
| 150 |
let existing = state |
| 151 |
.emails |
| 152 |
.get_by_id(id, DESKTOP_USER_ID) |
| 153 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 154 |
|
| 155 |
let held = existing.as_ref(); |
| 156 |
let account = fields |
| 157 |
.from |
| 158 |
.map(|id| goingson_core::EmailAccountId::from(uuid::Uuid::from(id))) |
| 159 |
.or_else(|| held.and_then(|email| email.draft_account_id)); |
| 160 |
|
| 161 |
let from = match account { |
| 162 |
Some(id) => state |
| 163 |
.email_accounts |
| 164 |
.get_by_id(id, DESKTOP_USER_ID) |
| 165 |
.map_err(|error| RouteError::internal(error.to_string()))? |
| 166 |
.map(|account| account.email_address) |
| 167 |
.unwrap_or_default(), |
| 168 |
None => held.map(|email| email.from.clone()).unwrap_or_default(), |
| 169 |
}; |
| 170 |
|
| 171 |
let pick = |given: Option<String>, kept: Option<String>| given.or(kept).unwrap_or_default(); |
| 172 |
|
| 173 |
state |
| 174 |
.emails |
| 175 |
.save_draft( |
| 176 |
id, |
| 177 |
DESKTOP_USER_ID, |
| 178 |
&from, |
| 179 |
&pick(fields.to, held.map(|email| email.to.clone())), |
| 180 |
Some(&pick( |
| 181 |
fields.cc, |
| 182 |
held.and_then(|email| email.cc_address.clone()), |
| 183 |
)), |
| 184 |
Some(&pick( |
| 185 |
fields.bcc, |
| 186 |
held.and_then(|email| email.bcc_address.clone()), |
| 187 |
)), |
| 188 |
&pick(fields.subject, held.map(|email| email.subject.clone())), |
| 189 |
&pick(fields.body, held.map(|email| email.body.clone())), |
| 190 |
account, |
| 191 |
held.and_then(|email| email.in_reply_to.clone()).as_deref(), |
| 192 |
None, |
| 193 |
held.and_then(|email| email.thread_id.clone()).as_deref(), |
| 194 |
) |
| 195 |
.map_err(|error| RouteError::internal(error.to_string())) |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
struct Loaded { |
| 204 |
id: EmailId, |
| 205 |
subject: String, |
| 206 |
to: String, |
| 207 |
cc: String, |
| 208 |
bcc: String, |
| 209 |
body: String, |
| 210 |
|
| 211 |
from: Option<String>, |
| 212 |
|
| 213 |
accounts: Vec<Choice>, |
| 214 |
|
| 215 |
queued: bool, |
| 216 |
files: Vec<goingson_core::Attachment>, |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
fn read(state: &AppState, id: EmailId) -> Result<Loaded, RouteError> { |
| 221 |
let draft = state |
| 222 |
.emails |
| 223 |
.get_by_id(id, DESKTOP_USER_ID) |
| 224 |
.map_err(|error| RouteError::internal(error.to_string()))? |
| 225 |
.filter(|email| email.is_draft) |
| 226 |
.ok_or_else(|| RouteError::not_found("no such draft"))?; |
| 227 |
|
| 228 |
let accounts = state |
| 229 |
.email_accounts |
| 230 |
.list_by_user(DESKTOP_USER_ID) |
| 231 |
.map_err(|error| RouteError::internal(error.to_string()))? |
| 232 |
.into_iter() |
| 233 |
.map(|account| Choice::new(account.id.to_string(), account.email_address)) |
| 234 |
.collect(); |
| 235 |
|
| 236 |
let files = state |
| 237 |
.attachments |
| 238 |
.list_for_email(id, DESKTOP_USER_ID) |
| 239 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 240 |
|
| 241 |
Ok(Loaded { |
| 242 |
id, |
| 243 |
queued: draft.is_queued(), |
| 244 |
subject: draft.subject, |
| 245 |
to: draft.to, |
| 246 |
cc: draft.cc_address.unwrap_or_default(), |
| 247 |
bcc: draft.bcc_address.unwrap_or_default(), |
| 248 |
body: draft.body, |
| 249 |
from: draft.draft_account_id.map(|id| id.to_string()), |
| 250 |
accounts, |
| 251 |
files, |
| 252 |
}) |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
fn field_route(id: EmailId, name: &str) -> Action { |
| 257 |
Action::post(format!("/compose/{id}/field")).with("field", name) |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
fn heading(loaded: &Loaded) -> &str { |
| 262 |
if loaded.subject.is_empty() { |
| 263 |
"New message" |
| 264 |
} else { |
| 265 |
&loaded.subject |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
fn from_value(loaded: &Loaded) -> Option<&str> { |
| 271 |
loaded.from.as_deref() |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
fn no_files(loaded: &Loaded) -> bool { |
| 276 |
loaded.files.is_empty() |
| 277 |
} |
| 278 |
|
| 279 |
declare! { |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
shape attached(loaded: &Loaded) -> Vec<Node>; |
| 296 |
|
| 297 |
list { |
| 298 |
row "Attached" when no_files(loaded) { |
| 299 |
meta "Nothing"; |
| 300 |
} |
| 301 |
|
| 302 |
for file in loaded.files.iter() { |
| 303 |
row "Attached" { |
| 304 |
secondary file.filename.clone(); |
| 305 |
meta size(file.file_size); |
| 306 |
act "Remove" to post "/compose/{loaded.id}/detach/{file.id}" |
| 307 |
unless loaded.queued { |
| 308 |
tone Danger; |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
act "Attach a file" to post "/compose/{loaded.id}/attach" by_host awaiting |
| 315 |
unless loaded.queued; |
| 316 |
} |
| 317 |
|
| 318 |
declare! { |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
shape screen(loaded: &Loaded) -> Screen; |
| 333 |
|
| 334 |
screen list_detail "Compose" false { |
| 335 |
at_place super::shell::EMAILS; |
| 336 |
|
| 337 |
region BODY as Pane { |
| 338 |
page heading(loaded); |
| 339 |
|
| 340 |
field Select FROM "From" { |
| 341 |
options loaded.accounts.clone(); |
| 342 |
for from in from_value(loaded).into_iter() { |
| 343 |
value from; |
| 344 |
} |
| 345 |
writes field_route(loaded.id, FROM); |
| 346 |
} |
| 347 |
|
| 348 |
field Text TO "To" { |
| 349 |
value loaded.to.clone(); |
| 350 |
writes field_route(loaded.id, TO); |
| 351 |
} |
| 352 |
|
| 353 |
field Text CC "Cc" { |
| 354 |
value loaded.cc.clone(); |
| 355 |
writes field_route(loaded.id, CC); |
| 356 |
} |
| 357 |
|
| 358 |
field Text BCC "Bcc" { |
| 359 |
value loaded.bcc.clone(); |
| 360 |
writes field_route(loaded.id, BCC); |
| 361 |
} |
| 362 |
|
| 363 |
field Text SUBJECT "Subject" { |
| 364 |
value loaded.subject.clone(); |
| 365 |
writes field_route(loaded.id, SUBJECT); |
| 366 |
} |
| 367 |
|
| 368 |
extend attached(loaded); |
| 369 |
|
| 370 |
field Textarea MESSAGE "Message" { |
| 371 |
value loaded.body.clone(); |
| 372 |
writes field_route(loaded.id, MESSAGE); |
| 373 |
} |
| 374 |
|
| 375 |
text "This message is in the Out box. Take it back to edit it." |
| 376 |
when loaded.queued; |
| 377 |
act "Take it back" to post "/compose/{loaded.id}/unqueue" when loaded.queued; |
| 378 |
|
| 379 |
act "Queue" to post "/compose/{loaded.id}/queue" unless loaded.queued { |
| 380 |
tone Success; |
| 381 |
} |
| 382 |
|
| 383 |
act "Queue later" to post "/compose/{loaded.id}/queue" unless loaded.queued { |
| 384 |
asking Field::new(FieldKind::DateTime, SEND_AFTER, "Send after"); |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
region "compose-aside" as Pane { |
| 393 |
act "Open in a window" to get "/compose/{loaded.id}" elsewhere; |
| 394 |
act "Discard" to post "/compose/{loaded.id}/discard" { |
| 395 |
tone Danger; |
| 396 |
confirm "Throw this message away?"; |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
fn size(bytes: i64) -> String { |
| 404 |
let bytes = bytes.max(0); |
| 405 |
if bytes < 1024 { |
| 406 |
return format!("{bytes} bytes"); |
| 407 |
} |
| 408 |
let units = ["KB", "MB", "GB"]; |
| 409 |
let mut value = bytes as f64 / 1024.0; |
| 410 |
let mut unit = 0; |
| 411 |
while value >= 1024.0 && unit < units.len() - 1 { |
| 412 |
value /= 1024.0; |
| 413 |
unit += 1; |
| 414 |
} |
| 415 |
format!("{value:.1} {}", units[unit]) |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
fn attach(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 420 |
let id = asked_for(&request)?; |
| 421 |
let picked = request |
| 422 |
.payload |
| 423 |
.get("file") |
| 424 |
.unwrap_or_default() |
| 425 |
.trim() |
| 426 |
.to_owned(); |
| 427 |
if picked.is_empty() { |
| 428 |
return Err(RouteError::conflict("No file was picked.").as_toast()); |
| 429 |
} |
| 430 |
|
| 431 |
match crate::commands::attachment::attach_path(state, None, None, Some(id), &picked) { |
| 432 |
Ok(file) => Ok(Response::screen(screen(&read(state, id)?)) |
| 433 |
.toast(Tone::Success, format!("Attached {}.", file.filename))), |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
Err(crate::commands::attachment::AttachFailure::Failed(message)) => { |
| 438 |
Err(RouteError::internal(message)) |
| 439 |
} |
| 440 |
Err(failure) => Err(RouteError::conflict(failure.message()).as_toast()), |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
fn detach(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 446 |
let id = asked_for(&request)?; |
| 447 |
let file = request |
| 448 |
.captures |
| 449 |
.get("file") |
| 450 |
.unwrap_or_default() |
| 451 |
.parse::<uuid::Uuid>() |
| 452 |
.map(goingson_core::AttachmentId::from) |
| 453 |
.map_err(|_| RouteError::not_found("not an attachment id"))?; |
| 454 |
|
| 455 |
state |
| 456 |
.attachments |
| 457 |
.delete(file, DESKTOP_USER_ID) |
| 458 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 459 |
|
| 460 |
|
| 461 |
Ok(Response::screen(screen(&read(state, id)?)).toast(Tone::Success, "Taken off.")) |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
fn show(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 466 |
Ok(screen(&read(state, asked_for(&request)?)?).into()) |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
fn asked_for(request: &quasi_router::Request) -> Result<EmailId, RouteError> { |
| 471 |
request |
| 472 |
.captures |
| 473 |
.get("id") |
| 474 |
.unwrap_or_default() |
| 475 |
.parse::<uuid::Uuid>() |
| 476 |
.map(Into::into) |
| 477 |
.map_err(|_| RouteError::not_found("not a message id")) |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
fn write_field(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 482 |
let id = asked_for(&request)?; |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
let which = request |
| 487 |
.payload |
| 488 |
.get("field") |
| 489 |
.or_else(|| request.carried.get("field")) |
| 490 |
.unwrap_or_default() |
| 491 |
.to_owned(); |
| 492 |
let value = request.payload.get(&which).unwrap_or_default().to_owned(); |
| 493 |
|
| 494 |
let mut fields = Fields::default(); |
| 495 |
match which.as_str() { |
| 496 |
FROM => { |
| 497 |
fields.from = value.parse::<uuid::Uuid>().ok().map(Into::into); |
| 498 |
} |
| 499 |
TO => fields.to = Some(value), |
| 500 |
CC => fields.cc = Some(value), |
| 501 |
BCC => fields.bcc = Some(value), |
| 502 |
SUBJECT => fields.subject = Some(value), |
| 503 |
MESSAGE => fields.body = Some(value), |
| 504 |
|
| 505 |
|
| 506 |
_ => return Err(RouteError::not_found("no such field")), |
| 507 |
} |
| 508 |
|
| 509 |
save(state, id, fields)?; |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
Ok(Response::fragment(SAVED, Node::text(""))) |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
fn queue(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 522 |
let id = asked_for(&request)?; |
| 523 |
let send_after = read_instant(&request)?; |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
let draft = state |
| 529 |
.emails |
| 530 |
.get_by_id(id, DESKTOP_USER_ID) |
| 531 |
.map_err(|error| RouteError::internal(error.to_string()))? |
| 532 |
.filter(|email| email.is_draft) |
| 533 |
.ok_or_else(|| RouteError::not_found("no such draft"))?; |
| 534 |
|
| 535 |
if draft.draft_account_id.is_none() { |
| 536 |
return Err( |
| 537 |
RouteError::conflict("Choose which account this is from before queueing it.") |
| 538 |
.as_toast(), |
| 539 |
); |
| 540 |
} |
| 541 |
if draft.to.trim().is_empty() { |
| 542 |
return Err(RouteError::conflict("Say who it is going to.").as_toast()); |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
let files = state |
| 550 |
.attachments |
| 551 |
.list_for_email(id, DESKTOP_USER_ID) |
| 552 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 553 |
let total: i64 = files.iter().map(|file| file.file_size.max(0)).sum(); |
| 554 |
if total > MAX_TOTAL_ATTACHMENT_BYTES { |
| 555 |
return Err(RouteError::conflict(format!( |
| 556 |
"The files come to {}, over the {} MB a message can carry.", |
| 557 |
size(total), |
| 558 |
MAX_TOTAL_ATTACHMENT_BYTES / (1024 * 1024) |
| 559 |
)) |
| 560 |
.as_toast()); |
| 561 |
} |
| 562 |
|
| 563 |
state |
| 564 |
.emails |
| 565 |
.queue_draft(id, DESKTOP_USER_ID, send_after) |
| 566 |
.map_err(|error| RouteError::internal(error.to_string()))? |
| 567 |
.ok_or_else(|| RouteError::not_found("no such draft"))?; |
| 568 |
|
| 569 |
Ok(Response::goto(Action::get("/outbox")).toast( |
| 570 |
Tone::Success, |
| 571 |
match send_after { |
| 572 |
Some(at) => format!( |
| 573 |
"In the Out box, going after {}.", |
| 574 |
at.format("%b %-d, %H:%M") |
| 575 |
), |
| 576 |
None => "In the Out box.".to_owned(), |
| 577 |
}, |
| 578 |
)) |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
fn read_instant(request: &quasi_router::Request) -> Result<Option<DateTime<Utc>>, RouteError> { |
| 583 |
let raw = request.payload.get(SEND_AFTER).unwrap_or_default(); |
| 584 |
if raw.trim().is_empty() { |
| 585 |
return Ok(None); |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
chrono::NaiveDateTime::parse_from_str(raw, "%Y-%m-%dT%H:%M") |
| 591 |
.ok() |
| 592 |
.and_then(|naive| naive.and_local_timezone(chrono::Local).single()) |
| 593 |
.map(|local| local.with_timezone(&Utc)) |
| 594 |
.map(Some) |
| 595 |
.ok_or_else(|| RouteError::conflict("That is not a time this understands.").as_toast()) |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
fn unqueue(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 600 |
let id = asked_for(&request)?; |
| 601 |
state |
| 602 |
.emails |
| 603 |
.unqueue_draft(id, DESKTOP_USER_ID) |
| 604 |
.map_err(|error| RouteError::internal(error.to_string()))? |
| 605 |
.ok_or_else(|| RouteError::not_found("not in the Out box"))?; |
| 606 |
Ok(Response::screen(screen(&read(state, id)?)).toast( |
| 607 |
Tone::Success, |
| 608 |
"Taken back. It will not go until you queue it.", |
| 609 |
)) |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
fn discard(state: &AppState, request: quasi_router::Request) -> Result<Response, RouteError> { |
| 614 |
let id = asked_for(&request)?; |
| 615 |
state |
| 616 |
.emails |
| 617 |
.delete(id, DESKTOP_USER_ID) |
| 618 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 619 |
Ok(Response::goto(Action::get("/emails")).toast(Tone::Success, "Thrown away.")) |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
fn waiting_subject(email: &goingson_core::Email) -> &str { |
| 624 |
if email.subject.is_empty() { |
| 625 |
"(no subject)" |
| 626 |
} else { |
| 627 |
&email.subject |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
fn is_stuck(email: &goingson_core::Email) -> bool { |
| 633 |
email.send_error.is_some() |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
fn stuck_reason(email: &goingson_core::Email) -> &str { |
| 638 |
email.send_error.as_deref().unwrap_or_default() |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
fn when_going(email: &goingson_core::Email) -> String { |
| 646 |
match email.send_after { |
| 647 |
Some(at) => format!("after {}", at.format("%b %-d, %H:%M")), |
| 648 |
None => "next pass".to_owned(), |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
declare! { |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
shape outbox_screen(waiting: &[goingson_core::Email]) -> Screen; |
| 659 |
|
| 660 |
screen list_detail "Out box" false { |
| 661 |
at_place super::shell::OUTBOX; |
| 662 |
|
| 663 |
region "outbox" as Pane { |
| 664 |
page "Out box"; |
| 665 |
|
| 666 |
empty "Nothing waiting to go." when waiting.is_empty(); |
| 667 |
|
| 668 |
list { |
| 669 |
for email in waiting.iter() { |
| 670 |
row waiting_subject(email) { |
| 671 |
secondary email.to.clone(); |
| 672 |
token Tag::badge("Stuck after {email.send_attempts}").tone(Tone::Danger) |
| 673 |
when is_stuck(email); |
| 674 |
meta stuck_reason(email) when is_stuck(email); |
| 675 |
meta when_going(email) unless is_stuck(email); |
| 676 |
act "Take it back" to post "/compose/{email.id}/unqueue"; |
| 677 |
activate to get "/compose/{email.id}"; |
| 678 |
} |
| 679 |
} |
| 680 |
} unless waiting.is_empty(); |
| 681 |
} |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
fn outbox(state: &AppState, _request: quasi_router::Request) -> Result<Response, RouteError> { |
| 687 |
let waiting = state |
| 688 |
.emails |
| 689 |
.list_outbox(DESKTOP_USER_ID) |
| 690 |
.map_err(|error| RouteError::internal(error.to_string()))?; |
| 691 |
Ok(outbox_screen(&waiting).into()) |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
#[must_use] |
| 696 |
pub fn routes(router: Router<AppState>) -> Router<AppState> { |
| 697 |
router |
| 698 |
.post("/compose", start) |
| 699 |
.get("/outbox", outbox) |
| 700 |
.get("/compose/{id}", show) |
| 701 |
.post("/compose/{id}/field", write_field) |
| 702 |
.post("/compose/{id}/queue", queue) |
| 703 |
.post("/compose/{id}/unqueue", unqueue) |
| 704 |
.post("/compose/{id}/attach", attach) |
| 705 |
.post("/compose/{id}/detach/{file}", detach) |
| 706 |
.post("/compose/{id}/discard", discard) |
| 707 |
} |
| 708 |
|