From 101b8689a5fa86a816aa432955ac138ef962775d Mon Sep 17 00:00:00 2001 From: Devin R Date: Wed, 15 Jul 2020 16:22:10 -0400 Subject: [PATCH] Add unstable-synapse-quirks feature for Sessions struct and fields --- .builds/beta.yml | 10 ++++++++++ .builds/stable.yml | 10 ++++++++++ ruma-client-api/Cargo.toml | 1 + ruma-client-api/src/r0.rs | 1 - ruma-client-api/src/r0/backup.rs | 9 +++++++++ .../src/r0/backup/add_backup_keys.rs | 19 ++++++------------- .../src/r0/backup/get_backup_keys.rs | 19 ++++++------------- ruma/Cargo.toml | 1 + 8 files changed, 43 insertions(+), 27 deletions(-) diff --git a/.builds/beta.yml b/.builds/beta.yml index 0b5c350d..ea256dfa 100644 --- a/.builds/beta.yml +++ b/.builds/beta.yml @@ -34,4 +34,14 @@ tasks: cargo test --all-features --verbose id_test_2_exit=$? + # ruma-client_api also has a few features. Make sure it works both with + # all of them and none of them being enabled. + cd ruma-client-api + + cargo test --no-default-features --verbose + id_test_1_exit=$? + + cargo test --all-features --verbose + id_test_2_exit=$? + exit $(( $fmt_exit || $clippy_exit || $test_exit || $id_test_1_exit || $id_test_2_exit )) diff --git a/.builds/stable.yml b/.builds/stable.yml index ecb28ee4..a362e266 100644 --- a/.builds/stable.yml +++ b/.builds/stable.yml @@ -34,6 +34,16 @@ tasks: cargo test --all-features --verbose id_test_2_exit=$? + # ruma-client_api also has a few features. Make sure it works both with + # all of them and none of them being enabled. + cd ruma-client-api + + cargo test --no-default-features --verbose + id_test_1_exit=$? + + cargo test --all-features --verbose + id_test_2_exit=$? + exit $(( $fmt_exit || $clippy_exit || $test_exit || $id_test_1_exit || $id_test_2_exit )) # TODO: Add audit task once cargo-audit binary releases are available. # See https://github.com/RustSec/cargo-audit/issues/66 diff --git a/ruma-client-api/Cargo.toml b/ruma-client-api/Cargo.toml index 3fb6a753..4fa18304 100644 --- a/ruma-client-api/Cargo.toml +++ b/ruma-client-api/Cargo.toml @@ -34,3 +34,4 @@ matches = "0.1.8" [features] unstable-pre-spec = [] +unstable-synapse-quirks = [] diff --git a/ruma-client-api/src/r0.rs b/ruma-client-api/src/r0.rs index d1577682..f33715e0 100644 --- a/ruma-client-api/src/r0.rs +++ b/ruma-client-api/src/r0.rs @@ -3,7 +3,6 @@ pub mod account; pub mod alias; pub mod appservice; -#[cfg(feature = "unstable-pre-spec")] pub mod backup; pub mod capabilities; pub mod config; diff --git a/ruma-client-api/src/r0/backup.rs b/ruma-client-api/src/r0/backup.rs index f25b41ff..600f8660 100644 --- a/ruma-client-api/src/r0/backup.rs +++ b/ruma-client-api/src/r0/backup.rs @@ -14,6 +14,15 @@ use std::collections::BTreeMap; use crate::r0::keys::AlgorithmAndDeviceId; +// TODO: remove +/// A wrapper around a mapping of session IDs to key data. +#[cfg(feature = "unstable-synapse-quirks")] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Sessions { + /// A map of session IDs to key data. + pub sessions: BTreeMap, +} + /// The algorithm used for storing backups. #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(tag = "algorithm", content = "auth_data")] diff --git a/ruma-client-api/src/r0/backup/add_backup_keys.rs b/ruma-client-api/src/r0/backup/add_backup_keys.rs index 22b025f5..8ab6537c 100644 --- a/ruma-client-api/src/r0/backup/add_backup_keys.rs +++ b/ruma-client-api/src/r0/backup/add_backup_keys.rs @@ -5,9 +5,6 @@ use std::collections::BTreeMap; use js_int::UInt; use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; - -use super::KeyData; ruma_api! { metadata: { @@ -27,7 +24,12 @@ ruma_api! { /// A map from room IDs to session IDs to key data. /// /// Note: synapse has the `sessions: {}` wrapper, the Matrix spec does not. - pub rooms: BTreeMap, + #[cfg(feature = "unstable-synapse-quirks")] + pub rooms: BTreeMap, + + /// A map from room IDs to session IDs to key data. + #[cfg(not(feature = "unstable-synapse-quirks"))] + pub rooms: BTreeMap>, } response: { @@ -41,12 +43,3 @@ ruma_api! { error: crate::Error } - -// TODO: remove -/// A wrapper around a mapping of session IDs to key data. -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Sessions { - // TODO: remove - /// A map of session IDs to key data. - pub sessions: BTreeMap, -} diff --git a/ruma-client-api/src/r0/backup/get_backup_keys.rs b/ruma-client-api/src/r0/backup/get_backup_keys.rs index ffc11a3e..0fd70dd3 100644 --- a/ruma-client-api/src/r0/backup/get_backup_keys.rs +++ b/ruma-client-api/src/r0/backup/get_backup_keys.rs @@ -4,9 +4,6 @@ use std::collections::BTreeMap; use ruma_api::ruma_api; use ruma_identifiers::RoomId; -use serde::{Deserialize, Serialize}; - -use super::KeyData; ruma_api! { metadata: { @@ -28,17 +25,13 @@ ruma_api! { /// A map from room IDs to session IDs to key data. /// /// Note: synapse has the `sessions: {}` wrapper, the Matrix spec does not. - pub rooms: BTreeMap, + #[cfg(feature = "unstable-synapse-quirks")] + pub rooms: BTreeMap, + + /// A map from room IDs to session IDs to key data. + #[cfg(not(feature = "unstable-synapse-quirks"))] + pub rooms: BTreeMap>, } error: crate::Error } - -// TODO: remove -/// A wrapper around a mapping of session IDs to key data. -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct Sessions { - // TODO: remove - /// A map of session IDs to key data. - pub sessions: BTreeMap, -} diff --git a/ruma/Cargo.toml b/ruma/Cargo.toml index 1126b45d..61bb3b84 100644 --- a/ruma/Cargo.toml +++ b/ruma/Cargo.toml @@ -16,6 +16,7 @@ edition = "2018" either = ["ruma-identifiers/either"] rand = ["ruma-identifiers/rand"] unstable-pre-spec = ["ruma-client-api/unstable-pre-spec"] +unstable-synapse-quirks = ["ruma-client-api/unstable-synapse-quirks"] appservice-api = ["ruma-api", "ruma-appservice-api", "ruma-events"] client-api = ["ruma-api", "ruma-client-api", "ruma-events"]