Skip to content

Commit d52323a

Browse files
authored
Merge pull request #636 from ReagentX/feat/cs/fix-contact-filter
Fix #635
2 parents c402574 + fc84420 commit d52323a

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

imessage-exporter/src/app/contacts.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
collections::HashMap,
2+
collections::{HashMap, HashSet},
33
fs,
44
path::{Path, PathBuf},
55
};
@@ -23,6 +23,8 @@ pub struct Name {
2323
pub full: String,
2424
/// Combined handle details from iMessage's database
2525
pub details: String,
26+
/// Set of original handle IDs that map to this name
27+
pub handle_ids: HashSet<i32>,
2628
}
2729

2830
impl Name {
@@ -50,6 +52,7 @@ impl Name {
5052
last: last.unwrap_or_default(),
5153
full,
5254
details: String::new(),
55+
handle_ids: HashSet::new(),
5356
})
5457
}
5558

@@ -82,6 +85,7 @@ impl Name {
8285
last: String::new(),
8386
full: String::new(),
8487
details: details.into(),
88+
handle_ids: HashSet::new(),
8589
}
8690
}
8791
}
@@ -95,6 +99,7 @@ impl Name {
9599
last: String::new(),
96100
full: String::new(),
97101
details: name.to_string(),
102+
handle_ids: HashSet::new(),
98103
}
99104
}
100105
}
@@ -244,18 +249,28 @@ impl ContactsIndex {
244249
participants: &HashMap<i32, String>,
245250
deduped_handles: &HashMap<i32, i32>,
246251
) -> HashMap<i32, Name> {
247-
let mut result = HashMap::new();
248-
249-
for (handle_id, details) in participants {
250-
if let Some(deduped_id) = deduped_handles.get(handle_id) {
251-
let mut name = self
252-
.lookup(details)
253-
.unwrap_or_else(|| Name::from_details(details.clone()));
254-
255-
// Update details field for the resolved Name
256-
name.details = details.clone();
257-
result.insert(*deduped_id, name);
258-
}
252+
let mut result: HashMap<i32, Name> = HashMap::new();
253+
254+
for (&handle_id, details) in participants {
255+
let Some(&deduped_id) = deduped_handles.get(&handle_id) else {
256+
continue;
257+
};
258+
259+
result
260+
.entry(deduped_id)
261+
.and_modify(|name| {
262+
name.handle_ids.insert(handle_id);
263+
})
264+
.or_insert_with(|| {
265+
let mut name = self
266+
.lookup(details)
267+
.unwrap_or_else(|| Name::from_details(details.clone()));
268+
269+
// Keep the original details string for display/fallback
270+
name.details = details.clone();
271+
name.handle_ids.insert(handle_id);
272+
name
273+
});
259274
}
260275

261276
result

imessage-exporter/src/app/runtime.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,13 @@ impl Config {
279279
let mut included_handles: BTreeSet<i32> = BTreeSet::new();
280280

281281
// First: Scan the list of participants for included handle IDs
282-
self.participants
283-
.iter()
284-
.for_each(|(handle_id, handle_name)| {
285-
for included_name in &parsed_handle_filter {
286-
if handle_name.contains(included_name) {
287-
included_handles.insert(*handle_id);
288-
}
282+
self.participants.iter().for_each(|(_, handle_name)| {
283+
for included_name in &parsed_handle_filter {
284+
if handle_name.contains(included_name) {
285+
included_handles.extend(&handle_name.handle_ids);
289286
}
290-
});
287+
}
288+
});
291289

292290
// Second: scan the list of chatrooms for IDs that contain the selected participants
293291
self.chatroom_participants
@@ -1111,6 +1109,11 @@ mod chat_filter_tests {
11111109
app.participants.insert(12, Name::fake_name("Person 12")); // Included
11121110
app.participants.insert(13, Name::fake_name("Person 13")); // Excluded
11131111

1112+
// Set the chatroom participant IDs
1113+
for (id, participant) in app.participants.iter_mut() {
1114+
participant.handle_ids.insert(*id);
1115+
}
1116+
11141117
// Chatroom 1: Included
11151118
let mut chatroom_1 = BTreeSet::new();
11161119
chatroom_1.insert(10);
@@ -1169,6 +1172,11 @@ mod chat_filter_tests {
11691172
app.participants.insert(12, Name::fake_name("Person 12")); // Excluded
11701173
app.participants.insert(13, Name::fake_name("Person 13")); // Included
11711174

1175+
// Set the chatroom participant IDs
1176+
for (id, participant) in app.participants.iter_mut() {
1177+
participant.handle_ids.insert(*id);
1178+
}
1179+
11721180
// Chatroom 1: Excluded
11731181
let mut chatroom_1 = BTreeSet::new();
11741182
chatroom_1.insert(10);

0 commit comments

Comments
 (0)