Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/matrix-synapse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ struct SynapseDeviceListResponse {
#[derive(Serialize, Deserialize)]
struct SynapseDevice {
device_id: String,

#[serde(default, skip_serializing_if = "Option::is_none")]
dehydrated: Option<bool>,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -316,6 +319,7 @@ impl HomeserverConnection for SynapseConnection {
.post(&format!("_synapse/admin/v2/users/{mxid}/devices"))
.json(&SynapseDevice {
device_id: device_id.to_owned(),
dehydrated: None,
})
.send_traced()
.await
Expand Down Expand Up @@ -410,8 +414,12 @@ impl HomeserverConnection for SynapseConnection {
.await
.context("Failed to parse response while querying devices from Synapse")?;

let existing_devices: HashSet<String> =
body.devices.into_iter().map(|d| d.device_id).collect();
let existing_devices: HashSet<String> = body
.devices
.into_iter()
.filter(|d| d.dehydrated.is_none())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also alternatively consider hiding dehydrated devices from the admin API, but in principle I think it does make sense to show them there, so happy with this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that said, shouldn't we have d.dehydrated != Some(true) here, or make dehydrated: bool with a default of false? (probably in favour of the latter since that's the simplest and the semantics match)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though the struct is serialised again, so Option<bool> makes sense unless we split the usage — I'll change the filter condition, push, merge

.map(|d| d.device_id)
.collect();

// First, delete all the devices that are not needed anymore
let to_delete = existing_devices.difference(&devices).cloned().collect();
Expand Down
Loading