notification_listing.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use crate::db::notifications::get_notifications;
  2. use crate::db::DbClient;
  3. pub async fn render(db: &DbClient, user: &str) -> String {
  4. let notifications = match get_notifications(db, user).await {
  5. Ok(n) => n,
  6. Err(e) => {
  7. return format!("{:?}", e.context("getting notifications"));
  8. }
  9. };
  10. let mut out = String::new();
  11. out.push_str("<html>");
  12. out.push_str("<head>");
  13. out.push_str("<title>Triagebot Notification Data</title>");
  14. out.push_str("</head>");
  15. out.push_str("<body>");
  16. out.push_str(&format!("<h3>Pending notifications for {}</h3>", user));
  17. out.push_str("<ol>");
  18. for notification in notifications {
  19. out.push_str("<li>");
  20. out.push_str(&format!(
  21. "<a href='{}'>{}</a>",
  22. notification.origin_url,
  23. notification
  24. .short_description
  25. .as_ref()
  26. .unwrap_or(&notification.origin_url)
  27. .replace('&', "&amp;")
  28. .replace('<', "&lt;")
  29. .replace('>', "&gt;")
  30. .replace('"', "&quot;")
  31. .replace('\'', "&#39;"),
  32. ));
  33. if let Some(metadata) = &notification.metadata {
  34. out.push_str(&format!(
  35. "<ul><li>{}</li></ul>",
  36. metadata
  37. .replace('&', "&amp;")
  38. .replace('<', "&lt;")
  39. .replace('>', "&gt;")
  40. .replace('"', "&quot;")
  41. .replace('\'', "&#39;"),
  42. ));
  43. }
  44. out.push_str("</li>");
  45. }
  46. out.push_str("</ol>");
  47. out.push_str("</body>");
  48. out.push_str("</html>");
  49. out
  50. }