Skip to content

Commit

Permalink
fix(sdk): SlidingSyncBuilder restores the rooms from the cache.
Browse files Browse the repository at this point in the history
This patch fixes a bug where rooms stored in the sliding sync cache
aren't restored by the `SlidingSyncBuilder`.

This patch also removes `SlidingSyncBuilder::rooms` fields which was
used but never modified. It's dead code.
  • Loading branch information
Hywan authored and bnjbvr committed Jul 16, 2024
1 parent 84dfb78 commit 62137e5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions crates/matrix-sdk/src/sliding_sync/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use super::{
cache::{format_storage_key_prefix, restore_sliding_sync_state},
sticky_parameters::SlidingSyncStickyManager,
Error, SlidingSync, SlidingSyncInner, SlidingSyncListBuilder, SlidingSyncPositionMarkers,
SlidingSyncRoom,
};
use crate::{sliding_sync::SlidingSyncStickyParameters, Client, Result};

Expand All @@ -38,7 +37,6 @@ pub struct SlidingSyncBuilder {
lists: Vec<SlidingSyncListBuilder>,
extensions: Option<ExtensionsConfig>,
subscriptions: BTreeMap<OwnedRoomId, v4::RoomSubscription>,
rooms: BTreeMap<OwnedRoomId, SlidingSyncRoom>,
poll_timeout: Duration,
network_timeout: Duration,
#[cfg(feature = "e2e-encryption")]
Expand All @@ -60,7 +58,6 @@ impl SlidingSyncBuilder {
lists: Vec::new(),
extensions: None,
subscriptions: BTreeMap::new(),
rooms: BTreeMap::new(),
poll_timeout: Duration::from_secs(30),
network_timeout: Duration::from_secs(30),
#[cfg(feature = "e2e-encryption")]
Expand Down Expand Up @@ -254,23 +251,23 @@ impl SlidingSyncBuilder {
let restored_fields =
restore_sliding_sync_state(&client, &self.storage_key, &lists).await?;

let (delta_token, pos) = if let Some(fields) = restored_fields {
let (delta_token, pos, rooms) = if let Some(fields) = restored_fields {
#[cfg(feature = "e2e-encryption")]
let pos = if self.share_pos { fields.pos } else { None };
#[cfg(not(feature = "e2e-encryption"))]
let pos = None;

(fields.delta_token, pos)
(fields.delta_token, pos, fields.rooms)
} else {
(None, None)
(None, None, BTreeMap::new())
};

#[cfg(feature = "e2e-encryption")]
let share_pos = self.share_pos;
#[cfg(not(feature = "e2e-encryption"))]
let share_pos = false;

let rooms = AsyncRwLock::new(self.rooms);
let rooms = AsyncRwLock::new(rooms);
let lists = AsyncRwLock::new(lists);

// Use the configured sliding sync proxy, or if not set, try to use the one
Expand Down

0 comments on commit 62137e5

Please sign in to comment.