//! Who wrote a message another session sent through session control
//! ([`rho_protocol::SessionPromptQuery::from`],
//! [`rho_protocol::SessionSteerQuery::from`]).
use rho_protocol::MessageOrigin;
use super::{reopen::parse_session, Sessions};
impl Sessions {
/// The origin of a message session `from` sent: that session, with its
/// title as it is now, kept with the message from then on, or no title
/// when the daemon has not loaded it. The daemon takes `from` as said,
/// but only when it is a session id: the model reads it in a stamp
/// line, which other text must not pass for.
pub(super) fn sent_by(&self, from: rho_protocol::SessionId) -> Option<MessageOrigin> {
let id = parse_session(&from).ok()?;
let loaded = self.loaded().get(&id).cloned();
let title = loaded.and_then(|session| session.feed.title());
Some(MessageOrigin::session(from, title))
}
}