Skip to content

Commit c61f707

Browse files
committed
fix: RelationalLinkedChunk handles Update::Clear.
What the title says.
1 parent 2abbf58 commit c61f707

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

crates/matrix-sdk-common/src/linked_chunk/relational.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ impl<Item, Gap> RelationalLinkedChunk<Item, Gap> {
179179
}
180180

181181
Update::StartReattachItems | Update::EndReattachItems => { /* nothing */ }
182+
183+
Update::Clear => {
184+
self.chunks.clear();
185+
self.items.clear();
186+
}
182187
}
183188
}
184189

@@ -670,4 +675,57 @@ mod tests {
670675
assert!(relational_linked_chunk.chunks.is_empty());
671676
assert!(relational_linked_chunk.items.is_empty());
672677
}
678+
679+
#[test]
680+
fn test_clear() {
681+
let room_id = room_id!("!r0:matrix.org");
682+
let mut relational_linked_chunk = RelationalLinkedChunk::<char, ()>::new();
683+
684+
relational_linked_chunk.apply_updates(
685+
room_id,
686+
vec![
687+
// new chunk (this is not mandatory for this test, but let's try to be realistic)
688+
Update::NewItemsChunk { previous: None, new: CId::new(0), next: None },
689+
// new items on 0
690+
Update::PushItems { at: Position::new(CId::new(0), 0), items: vec!['a', 'b', 'c'] },
691+
],
692+
);
693+
694+
// Chunks are correctly linked.
695+
assert_eq!(
696+
relational_linked_chunk.chunks,
697+
&[ChunkRow {
698+
room_id: room_id.to_owned(),
699+
previous_chunk: None,
700+
chunk: CId::new(0),
701+
next_chunk: None,
702+
}],
703+
);
704+
// Items contains the pushed items.
705+
assert_eq!(
706+
relational_linked_chunk.items,
707+
&[
708+
ItemRow {
709+
room_id: room_id.to_owned(),
710+
position: Position::new(CId::new(0), 0),
711+
item: Either::Item('a')
712+
},
713+
ItemRow {
714+
room_id: room_id.to_owned(),
715+
position: Position::new(CId::new(0), 1),
716+
item: Either::Item('b')
717+
},
718+
ItemRow {
719+
room_id: room_id.to_owned(),
720+
position: Position::new(CId::new(0), 2),
721+
item: Either::Item('c')
722+
},
723+
],
724+
);
725+
726+
// Now, time for a clean up.
727+
relational_linked_chunk.apply_updates(room_id, vec![Update::Clear]);
728+
assert!(relational_linked_chunk.chunks.is_empty());
729+
assert!(relational_linked_chunk.items.is_empty());
730+
}
673731
}

0 commit comments

Comments
 (0)