diff --git a/data/src/history.rs b/data/src/history.rs index 69958a09a..af8804184 100644 --- a/data/src/history.rs +++ b/data/src/history.rs @@ -224,10 +224,17 @@ impl History { } => { // Read marker is prior to last message on disk // or prior to unflushed messages in memory - last_on_disk.zip(metadata.read_marker).map_or( - last_on_disk.is_some() && metadata.read_marker.is_none(), - |(a, b)| a > b.date_time(), - ) || metadata.unread_count(messages) > 0 + if let Some(read_marker) = metadata.read_marker { + last_on_disk.is_some_and(|last| read_marker.date_time() < last) + || messages.iter().any(|message| { + read_marker.date_time() < message.server_time + && message.triggers_unread() + }) + } + // Default state == unread + else { + true + } } History::Full { .. } => false, } diff --git a/data/src/history/metadata.rs b/data/src/history/metadata.rs index accc3a770..3778ab98b 100644 --- a/data/src/history/metadata.rs +++ b/data/src/history/metadata.rs @@ -38,24 +38,6 @@ impl Metadata { read_marker: ReadMarker::latest(messages).or(self.read_marker), } } - - pub fn unread_count(&self, messages: &[Message]) -> usize { - messages - .iter() - .filter(|message| self.triggers_unread(message)) - .count() - } - - pub fn triggers_unread(&self, message: &Message) -> bool { - message.triggers_unread() && self.after_read_marker(message) - } - - pub fn after_read_marker(&self, message: &Message) -> bool { - self.read_marker.is_none() - || self - .read_marker - .is_some_and(|read_marker| message.server_time > read_marker.0) - } } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Deserialize, Serialize)]