use std::fmt::Display;
use url::Url;
use super::Identity;
use crate::replica::entity::snapshot::Snapshot;
pub mod history_step;
pub mod timeline;
impl Snapshot<Identity> {
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn name(&self) -> &str {
&self
.timeline()
.name_history()
.last()
.expect("This is mandated by the crate op")
.name
}
#[must_use]
pub fn email(&self) -> Option<&str> {
self.timeline()
.email_history()
.last()
.map(|item| item.email.as_str())
}
#[must_use]
pub fn login_name(&self) -> Option<&str> {
self.timeline()
.login_name_history()
.last()
.map(|item| item.login_name.as_str())
}
#[must_use]
pub fn avatar_url(&self) -> Option<&Url> {
self.timeline()
.avatar_url_history()
.last()
.map(|item| &item.avatar_url)
}
#[must_use]
pub fn metadata(&self) -> Option<impl Iterator<Item = &(String, String)>> {
self.timeline()
.metadata_history()
.last()
.map(|item| item.metadata.iter())
}
}
impl Display for Snapshot<Identity> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match (self.email(), self.login_name()) {
(None, None) => f.write_str(self.name()),
(None, Some(login)) => write!(f, "{} ({login})", self.name()),
(Some(email), None) => write!(f, "{} <{email}>", self.name()),
(Some(email), Some(_login)) => write!(f, "{} <{email}>", self.name()),
}
}
}