mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 11:05:32 -04:00
feat(sdk): Don't remove and re-insert a room when it exists.
Prior to this patch, to check a room exists, it was removed from the collection, then re-added if it exists. Instead of doing this `remove` + `insert` dance, we can simply use `get_mut`, which also returns an `Option`. This patch does that, in addition to rewrite the code to use a `match` instead of a `if` + `else`.
This commit is contained in:
@@ -325,23 +325,24 @@ impl SlidingSync {
|
||||
room_data.timeline.drain(..).map(Into::into).collect()
|
||||
};
|
||||
|
||||
if let Some(mut room) = rooms_map.remove(&room_id) {
|
||||
match rooms_map.get_mut(&room_id) {
|
||||
// The room existed before, let's update it.
|
||||
Some(room) => {
|
||||
room.update(room_data, timeline);
|
||||
}
|
||||
|
||||
room.update(room_data, timeline);
|
||||
rooms_map.insert(room_id.clone(), room);
|
||||
} else {
|
||||
// First time we need this room, let's create it.
|
||||
|
||||
rooms_map.insert(
|
||||
room_id.clone(),
|
||||
SlidingSyncRoom::new(
|
||||
self.inner.client.clone(),
|
||||
None => {
|
||||
rooms_map.insert(
|
||||
room_id.clone(),
|
||||
room_data,
|
||||
timeline,
|
||||
),
|
||||
);
|
||||
SlidingSyncRoom::new(
|
||||
self.inner.client.clone(),
|
||||
room_id.clone(),
|
||||
room_data,
|
||||
timeline,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
updated_rooms.push(room_id);
|
||||
|
||||
Reference in New Issue
Block a user