Commit b01dbe5a5d
Unregistered key
Layout: unified · split
src/base.rs +22 −2
| @@ -1133,14 +1133,34 @@ impl RoomInfo { | |||
| 1133 | /// Indicates whether this room has unread messages. | 1133 | /// Indicates whether this room has unread messages. |
| 1134 | pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo { | 1134 | pub fn unreads(&self, settings: &ApplicationSettings) -> UnreadInfo { |
| 1135 | let last_message = self.messages.last_key_value(); | 1135 | let last_message = self.messages.last_key_value(); |
| 1136 | |||
| 1136 | let last_receipt = self | 1137 | let last_receipt = self |
| 1137 | .user_receipts | 1138 | .user_receipts |
| 1138 | .get(&ReceiptThread::Main) | 1139 | .get(&ReceiptThread::Main) |
| 1139 | .and_then(|receipts| receipts.get(&settings.profile.user_id)); | 1140 | .and_then(|receipts| receipts.get(&settings.profile.user_id)); |
| 1141 | let last_receipt = last_receipt.as_ref().and_then(|event_id| { | ||
| 1142 | match &self.keys.get(*event_id)? { | ||
| 1143 | EventLocation::Message(_, key) | EventLocation::State(key) => Some(key), | ||
| 1144 | EventLocation::Reaction(_) => None, | ||
| 1145 | } | ||
| 1146 | }); | ||
| 1147 | |||
| 1148 | let last_unthreaded = self | ||
| 1149 | .user_receipts | ||
| 1150 | .get(&ReceiptThread::Unthreaded) | ||
| 1151 | .and_then(|receipts| receipts.get(&settings.profile.user_id)); | ||
| 1152 | let last_unthreaded = last_unthreaded.as_ref().and_then(|event_id| { | ||
| 1153 | match &self.keys.get(*event_id)? { | ||
| 1154 | EventLocation::Message(_, key) | EventLocation::State(key) => Some(key), | ||
| 1155 | EventLocation::Reaction(_) => None, | ||
| 1156 | } | ||
| 1157 | }); | ||
| 1158 | |||
| 1159 | let last_receipt = std::cmp::max(last_receipt, last_unthreaded); | ||
| 1140 | 1160 | ||
| 1141 | match (last_message, last_receipt) { | 1161 | match (last_message, last_receipt) { |
| 1142 | (Some(((ts, recent), _)), Some(last_read)) => { | 1162 | (Some(((ts, _), _)), Some((read_ts, _))) => { |
| 1143 | UnreadInfo { unread: last_read != recent, latest: Some(*ts) } | 1163 | UnreadInfo { unread: ts > read_ts, latest: Some(*ts) } |
| 1144 | }, | 1164 | }, |
| 1145 | (Some(((ts, _), _)), None) => { | 1165 | (Some(((ts, _), _)), None) => { |
| 1146 | // If we've never loaded/generated a room's receipt (example, | 1166 | // If we've never loaded/generated a room's receipt (example, |