use rho_protocol::{
display::{
NotificationCard, NotificationDelivery, NotificationPreview, NotificationTone,
NotificationVisibility,
},
MessageOrigin, RhoNotice,
};
use super::{daemon_events::DaemonView, session_picker::short_session_id};
use crate::{app::RESUME_NOTICE, title::placeholder};
struct Sender {
name: String,
from: String,
}
pub(super) fn user_view(text: String, origin: Option<&MessageOrigin>) -> DaemonView {
let sender = match origin {
None => return DaemonView::User(text),
Some(MessageOrigin::Rho {
notice: RhoNotice::Restart,
..
}) => return DaemonView::Notice(RESUME_NOTICE.to_owned()),
Some(MessageOrigin::Session { id, title, .. }) => Some(Sender {
name: title
.as_deref()
.and_then(placeholder)
.unwrap_or_else(|| format!("session {}", short_session_id(id.as_str()))),
from: format!("from session {id}"),
}),
Some(MessageOrigin::Rho { .. }) => Some(Sender {
name: "rho".to_owned(),
from: "from rho".to_owned(),
}),
Some(_) => None,
};
let first = placeholder(&text).unwrap_or_default();
let (title, subtitle) = match sender {
Some(Sender { name, from }) => (format!("{name} · {first}"), Some(from)),
None => (first, None),
};
DaemonView::Sent(Box::new(NotificationCard {
title,
sender: String::new(),
recipient: String::new(),
delivery: NotificationDelivery::Received,
tone: NotificationTone::Neutral,
preview: NotificationPreview::Full,
visibility: NotificationVisibility::Conversation,
reference: None,
subtitle,
body: text,
output: None,
details: Vec::new(),
}))
}
#[cfg(test)]
#[path = "sent_message_tests.rs"]
mod tests;