use super::*;
use crate::api::notifications::Unread;
use crate::data::Picked;
const RETRY_SECS: u64 = 60;
impl State {
fn unread(&self) -> Option<&Unread> {
let remote = self.data.get(&DataKey::Unread)?;
(remote.error.is_none())
.then(|| remote.data.as_ref().and_then(Unread::pick))
.flatten()
}
#[must_use]
pub(super) fn unread_polled(&mut self) -> Vec<Cmd> {
let secs = self.unread().map_or(RETRY_SECS, |u| u.poll_secs);
self.unread_poll += 1;
let ms = secs.max(1).saturating_mul(1000);
vec![Cmd::Timer(Timer::Unread(self.unread_poll), ms)]
}
#[must_use]
pub(super) fn unread_due(&mut self, poll: u64) -> Vec<Cmd> {
if poll == self.unread_poll {
self.ensure(DataKey::Unread, true)
} else {
Vec::new()
}
}
pub fn unread_label(&self) -> Option<String> {
let unread = self.unread().filter(|u| u.count > 0)?;
let plus = if unread.more { "+" } else { "" };
Some(format!("● {}{plus} unread", unread.count))
}
}