fix(messages): an attachment Graph lists twice shows once
- edited posts with a link preview card came back with the same card id twice - attachments are deduplicated by id on read, so cached rows heal too Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,3 +1,5 @@
1
use std::collections::HashSet;
2
1
3
use chrono::{DateTime, Utc};
2
4
use scraper::{ElementRef, Html};
3
5
use serde::{Deserialize, Serialize};
@@ -194,7 +196,16 @@ pub struct MentionInfo {
194
196
}
195
197
196
198
pub fn attachments(record: &MessageRecord) -> Vec<AttachmentInfo> {
197
serde_json::from_str(&record.attachments_json).unwrap_or_default()
199
let mut attachments: Vec<AttachmentInfo> =
200
serde_json::from_str(&record.attachments_json).unwrap_or_default();
201
let mut seen_ids = HashSet::new();
202
attachments.retain(|attachment| {
203
attachment
204
.id
205
.as_ref()
206
.is_none_or(|id| seen_ids.insert(id.clone()))
207
});
208
attachments
198
209
}
199
210
200
211
pub fn adaptive_cards(record: &MessageRecord) -> Vec<AdaptiveCard> {
@@ -1192,6 +1203,14 @@ mod tests {
1192
1203
assert!(text.contains('\n'));
1193
1204
}
1194
1205
1206
#[test]
1207
fn an_attachment_listed_twice_shows_once() {
1208
let card = r#"{"content_type":"application/vnd.microsoft.card.adaptive","name":null,"url":null,"text":"Jira","id":"app-preview-card-1"}"#;
1209
let file = r#"{"content_type":"reference","name":"a.pdf","url":"u","text":null}"#;
1210
let parsed = attachments(&record("", &format!("[{card},{card},{file},{file}]")));
1211
assert_eq!(parsed.len(), 3);
1212
}
1213
1195
1214
#[test]
1196
1215
fn old_cached_attachments_still_parse() {
1197
1216
let parsed = attachments(&record(
@@ -1,3 +1,5 @@1
use std::collections::HashSet;2
1
use chrono::{DateTime, Utc};3
use chrono::{DateTime, Utc};2
use scraper::{ElementRef, Html};4
use scraper::{ElementRef, Html};3
use serde::{Deserialize, Serialize};5
use serde::{Deserialize, Serialize};@@ -194,7 +196,16 @@ pub struct MentionInfo {194
}196
}195
197
196
pub fn attachments(record: &MessageRecord) -> Vec<AttachmentInfo> {198
pub fn attachments(record: &MessageRecord) -> Vec<AttachmentInfo> {197
serde_json::from_str(&record.attachments_json).unwrap_or_default()199
let mut attachments: Vec<AttachmentInfo> =200
serde_json::from_str(&record.attachments_json).unwrap_or_default();201
let mut seen_ids = HashSet::new();202
attachments.retain(|attachment| {203
attachment204
.id205
.as_ref()206
.is_none_or(|id| seen_ids.insert(id.clone()))207
});208
attachments198
}209
}199
210
200
pub fn adaptive_cards(record: &MessageRecord) -> Vec<AdaptiveCard> {211
pub fn adaptive_cards(record: &MessageRecord) -> Vec<AdaptiveCard> {@@ -1192,6 +1203,14 @@ mod tests {1192
assert!(text.contains('\n'));1203
assert!(text.contains('\n'));1193
}1204
}1194
1205
1206
#[test]1207
fn an_attachment_listed_twice_shows_once() {1208
let card = r#"{"content_type":"application/vnd.microsoft.card.adaptive","name":null,"url":null,"text":"Jira","id":"app-preview-card-1"}"#;1209
let file = r#"{"content_type":"reference","name":"a.pdf","url":"u","text":null}"#;1210
let parsed = attachments(&record("", &format!("[{card},{card},{file},{file}]")));1211
assert_eq!(parsed.len(), 3);1212
}1213
1195
#[test]1214
#[test]1196
fn old_cached_attachments_still_parse() {1215
fn old_cached_attachments_still_parse() {1197
let parsed = attachments(&record(1216
let parsed = attachments(&record(