diff --git a/src/base.rs b/src/base.rs index 1cd3071..9606e63 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1132,14 +1132,38 @@ impl RoomInfo { /// Indicates whether this room has unread messages. pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo { let last_message = self.messages.last_key_value(); + let last_receipt = self .user_receipts .get(&ReceiptThread::Main) .and_then(|receipts| receipts.get(&settings.profile.user_id)); + let last_receipt = last_receipt.as_ref().and_then(|event_id| { + match &self.keys.get(*event_id)? { + EventLocation::Message(_, key) | EventLocation::State(key) => Some(key), + EventLocation::Reaction(_) => None, + } + }); + + let last_unthreaded = self + .user_receipts + .get(&ReceiptThread::Unthreaded) + .and_then(|receipts| receipts.get(&settings.profile.user_id)); + let last_unthreaded = last_unthreaded.as_ref().and_then(|event_id| { + match &self.keys.get(*event_id)? { + EventLocation::Message(_, key) | EventLocation::State(key) => Some(key), + EventLocation::Reaction(_) => None, + } + }); + + let last_receipt = if last_receipt >= last_unthreaded { + last_receipt + } else { + last_unthreaded + }; match (last_message, last_receipt) { - (Some(((ts, recent), _)), Some(last_read)) => { - UnreadInfo { unread: last_read != recent, latest: Some(*ts) } + (Some(((ts, _), _)), Some((read_ts, _))) => { + UnreadInfo { unread: ts > read_ts, latest: Some(*ts) } }, (Some(((ts, _), _)), None) => { // If we've never loaded/generated a room's receipt (example,