mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-19 06:04:31 -04:00
feat(sdk): Persist sliding-sync to-device extension since value
This commit is contained in:
committed by
Jonas Platte
parent
b82cd7fa5a
commit
bb39c2aa9d
@@ -379,10 +379,12 @@ impl SlidingSyncConfig {
|
||||
storage_key,
|
||||
client,
|
||||
mut views,
|
||||
extensions,
|
||||
mut extensions,
|
||||
subscriptions,
|
||||
} = self;
|
||||
let rooms = if let Some(storage_key) = storage_key.as_ref() {
|
||||
let mut rooms = Default::default();
|
||||
|
||||
if let Some(storage_key) = storage_key.as_ref() {
|
||||
if let Some(mut f) = client
|
||||
.store()
|
||||
.get_custom_value(storage_key.as_bytes())
|
||||
@@ -396,15 +398,20 @@ impl SlidingSyncConfig {
|
||||
}
|
||||
}
|
||||
|
||||
f.rooms
|
||||
rooms = f
|
||||
.rooms
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, SlidingSyncRoom::from_frozen(v, client.clone())))
|
||||
.collect()
|
||||
} else {
|
||||
Default::default()
|
||||
.collect();
|
||||
|
||||
if let Some(since) = f.to_device_since {
|
||||
extensions
|
||||
.get_or_insert_with(Default::default)
|
||||
.to_device
|
||||
.get_or_insert_with(Default::default)
|
||||
.since = Some(since);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
|
||||
let rooms = Arc::new(MutableBTreeMap::with_values(rooms));
|
||||
@@ -598,6 +605,8 @@ pub struct SlidingSync {
|
||||
struct FrozenSlidingSync {
|
||||
views: BTreeMap<String, FrozenSlidingSyncView>,
|
||||
rooms: BTreeMap<OwnedRoomId, FrozenSlidingSyncRoom>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
to_device_since: Option<String>,
|
||||
}
|
||||
|
||||
impl From<&SlidingSync> for FrozenSlidingSync {
|
||||
@@ -605,6 +614,12 @@ impl From<&SlidingSync> for FrozenSlidingSync {
|
||||
FrozenSlidingSync {
|
||||
views: v.views.lock_ref().iter().map(|v| (v.name.clone(), v.into())).collect(),
|
||||
rooms: v.rooms.lock_ref().iter().map(|(k, v)| (k.clone(), v.into())).collect(),
|
||||
to_device_since: v
|
||||
.extensions
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.and_then(|ext| ext.to_device.as_ref()?.since.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user