Don't overwrite already resolved participants, better naming of keys
This commit is contained in:
@@ -12,14 +12,8 @@ fn participants_equal_ignoring_id(a: &Participant, b: &Participant) -> bool {
|
||||
match (a, b) {
|
||||
(Participant::Me, Participant::Me) => true,
|
||||
(
|
||||
Participant::Remote {
|
||||
display_name: name_a,
|
||||
..
|
||||
},
|
||||
Participant::Remote {
|
||||
display_name: name_b,
|
||||
..
|
||||
},
|
||||
Participant::Remote { handle: name_a, .. },
|
||||
Participant::Remote { handle: name_b, .. },
|
||||
) => name_a == name_b,
|
||||
_ => false,
|
||||
}
|
||||
@@ -29,9 +23,14 @@ fn participants_vec_equal_ignoring_id(a: &[Participant], b: &[Participant]) -> b
|
||||
if a.len() != b.len() {
|
||||
return false;
|
||||
}
|
||||
a.iter()
|
||||
.zip(b.iter())
|
||||
.all(|(a, b)| participants_equal_ignoring_id(a, b))
|
||||
// For each participant in a, check if there is a matching participant in b
|
||||
a.iter().all(|a_participant| {
|
||||
b.iter().any(|b_participant| participants_equal_ignoring_id(a_participant, b_participant))
|
||||
}) &&
|
||||
// Also check the reverse to ensure no duplicates
|
||||
b.iter().all(|b_participant| {
|
||||
a.iter().any(|a_participant| participants_equal_ignoring_id(b_participant, a_participant))
|
||||
})
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -214,8 +213,8 @@ async fn test_messages() {
|
||||
// Verify second message (from Alice)
|
||||
let retrieved_message2 = messages.iter().find(|m| m.id == message2.id).unwrap();
|
||||
assert_eq!(retrieved_message2.text, "Hi there!");
|
||||
if let Participant::Remote { display_name, .. } = &retrieved_message2.sender {
|
||||
assert_eq!(display_name, "Alice");
|
||||
if let Participant::Remote { handle, .. } = &retrieved_message2.sender {
|
||||
assert_eq!(handle, "Alice");
|
||||
} else {
|
||||
panic!(
|
||||
"Expected Remote participant. Got: {:?}",
|
||||
@@ -345,14 +344,8 @@ async fn test_insert_messages_batch() {
|
||||
match (&original.sender, &retrieved.sender) {
|
||||
(Participant::Me, Participant::Me) => {}
|
||||
(
|
||||
Participant::Remote {
|
||||
display_name: o_name,
|
||||
..
|
||||
},
|
||||
Participant::Remote {
|
||||
display_name: r_name,
|
||||
..
|
||||
},
|
||||
Participant::Remote { handle: o_name, .. },
|
||||
Participant::Remote { handle: r_name, .. },
|
||||
) => assert_eq!(o_name, r_name),
|
||||
_ => panic!(
|
||||
"Sender mismatch: original {:?}, retrieved {:?}",
|
||||
|
||||
Reference in New Issue
Block a user