1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- use crate::db::notifications::get_notifications;
- use crate::db::DbClient;
- pub async fn render(db: &DbClient, user: &str) -> String {
- let notifications = match get_notifications(db, user).await {
- Ok(n) => n,
- Err(e) => {
- return format!("{:?}", e.context("getting notifications"));
- }
- };
- let mut out = String::new();
- out.push_str("<html>");
- out.push_str("<head>");
- out.push_str("<title>Triagebot Notification Data</title>");
- out.push_str("</head>");
- out.push_str("<body>");
- out.push_str(&format!("<h3>Pending notifications for {}</h3>", user));
- out.push_str("<ol>");
- for notification in notifications {
- out.push_str("<li>");
- out.push_str(&format!(
- "<a href='{}'>{}</a>",
- notification.origin_url,
- notification
- .short_description
- .as_ref()
- .unwrap_or(¬ification.origin_url)
- .replace('&', "&")
- .replace('<', "<")
- .replace('>', ">")
- .replace('"', """)
- .replace('\'', "'"),
- ));
- if let Some(metadata) = ¬ification.metadata {
- out.push_str(&format!(
- "<ul><li>{}</li></ul>",
- metadata
- .replace('&', "&")
- .replace('<', "<")
- .replace('>', ">")
- .replace('"', """)
- .replace('\'', "'"),
- ));
- }
- out.push_str("</li>");
- }
- out.push_str("</ol>");
- out.push_str("</body>");
- out.push_str("</html>");
- out
- }
|