use rho_protocol::display::{
NotificationCard, NotificationId, NotificationInfo, NotificationItem, NotificationOutcome,
NotificationSubject, NotificationTone, NotificationUrgency,
};
use crate::display_transcript::NotificationRow;
impl NotificationRow {
pub(crate) fn typed(
card: NotificationCard,
subject: NotificationSubject,
items: Vec<NotificationItem>,
) -> Self {
let most_urgent = items
.iter()
.map(|item| item.urgency)
.max_by_key(|urgency| rank(*urgency))
.unwrap_or(NotificationUrgency::Routine);
let id = NotificationId::new(uuid::Uuid::new_v4().to_string());
Self {
card,
info: Some(NotificationInfo::new(id, most_urgent, subject, items)),
}
}
pub(crate) fn single(
card: NotificationCard,
subject: NotificationSubject,
outcome: NotificationOutcome,
) -> Self {
let item = notification_item(outcome, card.tone, subject.clone(), card.title.clone());
Self::typed(card, subject, vec![item])
}
}
pub(crate) fn notification_item(
outcome: NotificationOutcome,
tone: NotificationTone,
subject: NotificationSubject,
text: impl Into<String>,
) -> NotificationItem {
NotificationItem::new(outcome, urgency(outcome), tone, subject, text)
}
fn urgency(outcome: NotificationOutcome) -> NotificationUrgency {
use NotificationOutcome as Outcome;
match outcome {
Outcome::Question
| Outcome::ActionRequested
| Outcome::Failed
| Outcome::FailedToStart
| Outcome::TimedOut
| Outcome::ChecksFailed
| Outcome::MergeConflict
| Outcome::Unreadable => NotificationUrgency::NeedsYou,
Outcome::Completed
| Outcome::Exited
| Outcome::Interrupted
| Outcome::CutOff
| Outcome::Refused
| Outcome::OutOfSteps
| Outcome::ChecksPassed
| Outcome::ChecksFinished
| Outcome::NewComments
| Outcome::Merged
| Outcome::Closed => NotificationUrgency::Notable,
Outcome::Update
| Outcome::Running
| Outcome::Stopped
| Outcome::Cancelled
| Outcome::NewCommits
| Outcome::WatchStopped => NotificationUrgency::Routine,
_ => NotificationUrgency::Routine,
}
}
fn rank(urgency: NotificationUrgency) -> u8 {
match urgency {
NotificationUrgency::NeedsYou => 2,
NotificationUrgency::Notable => 1,
_ => 0,
}
}