Move restricted join rules and room versions 8, 9 from unstable-pre-spec to unstable-spec
This commit is contained in:
parent
8348b97091
commit
1a4e464422
@ -21,7 +21,8 @@ markdown = ["pulldown-cmark"]
|
|||||||
|
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
unstable-pdu = []
|
unstable-pdu = []
|
||||||
unstable-pre-spec = ["ruma-identifiers/unstable-pre-spec"]
|
unstable-pre-spec = ["unstable-spec"]
|
||||||
|
unstable-spec = ["ruma-identifiers/unstable-spec"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
criterion = { version = "0.3.3", optional = true }
|
criterion = { version = "0.3.3", optional = true }
|
||||||
|
@ -94,9 +94,7 @@ event_enum! {
|
|||||||
"m.key.verification.mac",
|
"m.key.verification.mac",
|
||||||
"m.key.verification.done",
|
"m.key.verification.done",
|
||||||
"m.room.encrypted",
|
"m.room.encrypted",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
"m.secret.request",
|
"m.secret.request",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
"m.secret.send",
|
"m.secret.send",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,6 @@ pub mod relation;
|
|||||||
pub mod room;
|
pub mod room;
|
||||||
pub mod room_key;
|
pub mod room_key;
|
||||||
pub mod room_key_request;
|
pub mod room_key_request;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
pub mod secret;
|
pub mod secret;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
pub mod space;
|
pub mod space;
|
||||||
|
@ -3,19 +3,19 @@
|
|||||||
//! [`m.room.join_rules`]: https://spec.matrix.org/v1.1/client-server-api/#mroomjoin_rules
|
//! [`m.room.join_rules`]: https://spec.matrix.org/v1.1/client-server-api/#mroomjoin_rules
|
||||||
|
|
||||||
use ruma_events_macros::EventContent;
|
use ruma_events_macros::EventContent;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
use ruma_identifiers::RoomId;
|
use ruma_identifiers::RoomId;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{Deserializer, Error},
|
de::{Deserializer, Error},
|
||||||
Deserialize, Serialize,
|
Deserialize, Serialize,
|
||||||
};
|
};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use crate::PrivOwnedStr;
|
use crate::PrivOwnedStr;
|
||||||
@ -41,7 +41,7 @@ impl RoomJoinRulesEventContent {
|
|||||||
|
|
||||||
/// Creates a new `RoomJoinRulesEventContent` with the restricted rule and the given set of
|
/// Creates a new `RoomJoinRulesEventContent` with the restricted rule and the given set of
|
||||||
/// allow rules.
|
/// allow rules.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
pub fn restricted(allow: Vec<AllowRule>) -> Self {
|
pub fn restricted(allow: Vec<AllowRule>) -> Self {
|
||||||
Self { join_rule: JoinRule::Restricted(Restricted::new(allow)) }
|
Self { join_rule: JoinRule::Restricted(Restricted::new(allow)) }
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ pub enum JoinRule {
|
|||||||
|
|
||||||
/// Users can join the room if they are invited, or if they meet any of the conditions
|
/// Users can join the room if they are invited, or if they meet any of the conditions
|
||||||
/// described in a set of [`AllowRule`]s.
|
/// described in a set of [`AllowRule`]s.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
#[serde(rename = "restricted")]
|
#[serde(rename = "restricted")]
|
||||||
Restricted(Restricted),
|
Restricted(Restricted),
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ impl JoinRule {
|
|||||||
JoinRule::Invite => "invite",
|
JoinRule::Invite => "invite",
|
||||||
JoinRule::Knock => "knock",
|
JoinRule::Knock => "knock",
|
||||||
JoinRule::Private => "private",
|
JoinRule::Private => "private",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
JoinRule::Restricted(_) => "restricted",
|
JoinRule::Restricted(_) => "restricted",
|
||||||
JoinRule::Public => "public",
|
JoinRule::Public => "public",
|
||||||
JoinRule::_Custom(rule) => &rule.0,
|
JoinRule::_Custom(rule) => &rule.0,
|
||||||
@ -113,7 +113,7 @@ impl<'de> Deserialize<'de> for JoinRule {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
fn from_raw_json_value<T: DeserializeOwned, E: Error>(raw: &RawJsonValue) -> Result<T, E> {
|
fn from_raw_json_value<T: DeserializeOwned, E: Error>(raw: &RawJsonValue) -> Result<T, E> {
|
||||||
serde_json::from_str(raw.get()).map_err(E::custom)
|
serde_json::from_str(raw.get()).map_err(E::custom)
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ impl<'de> Deserialize<'de> for JoinRule {
|
|||||||
"invite" => Ok(Self::Invite),
|
"invite" => Ok(Self::Invite),
|
||||||
"knock" => Ok(Self::Knock),
|
"knock" => Ok(Self::Knock),
|
||||||
"private" => Ok(Self::Private),
|
"private" => Ok(Self::Private),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
"restricted" => from_raw_json_value(&json).map(Self::Restricted),
|
"restricted" => from_raw_json_value(&json).map(Self::Restricted),
|
||||||
"public" => Ok(Self::Public),
|
"public" => Ok(Self::Public),
|
||||||
_ => Ok(Self::_Custom(PrivOwnedStr(join_rule.into()))),
|
_ => Ok(Self::_Custom(PrivOwnedStr(join_rule.into()))),
|
||||||
@ -143,7 +143,7 @@ impl<'de> Deserialize<'de> for JoinRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration of the `Restricted` join rule.
|
/// Configuration of the `Restricted` join rule.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct Restricted {
|
pub struct Restricted {
|
||||||
@ -151,7 +151,7 @@ pub struct Restricted {
|
|||||||
allow: Vec<AllowRule>,
|
allow: Vec<AllowRule>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
impl Restricted {
|
impl Restricted {
|
||||||
/// Constructs a new rule set for restricted rooms with the given rules.
|
/// Constructs a new rule set for restricted rooms with the given rules.
|
||||||
pub fn new(allow: Vec<AllowRule>) -> Self {
|
pub fn new(allow: Vec<AllowRule>) -> Self {
|
||||||
@ -160,7 +160,7 @@ impl Restricted {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An allow rule which defines a condition that allows joining a room.
|
/// An allow rule which defines a condition that allows joining a room.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
@ -173,7 +173,7 @@ pub enum AllowRule {
|
|||||||
_Custom(CustomAllowRule),
|
_Custom(CustomAllowRule),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
impl AllowRule {
|
impl AllowRule {
|
||||||
/// Constructs an `AllowRule` with membership of the room with the given id as its predicate.
|
/// Constructs an `AllowRule` with membership of the room with the given id as its predicate.
|
||||||
pub fn room_membership(room_id: Box<RoomId>) -> Self {
|
pub fn room_membership(room_id: Box<RoomId>) -> Self {
|
||||||
@ -182,7 +182,7 @@ impl AllowRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Allow rule which grants permission to join based on the membership of another room.
|
/// Allow rule which grants permission to join based on the membership of another room.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct RoomMembership {
|
pub struct RoomMembership {
|
||||||
@ -190,7 +190,7 @@ pub struct RoomMembership {
|
|||||||
pub room_id: Box<RoomId>,
|
pub room_id: Box<RoomId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
impl RoomMembership {
|
impl RoomMembership {
|
||||||
/// Constructs a new room membership rule for the given room id.
|
/// Constructs a new room membership rule for the given room id.
|
||||||
pub fn new(room_id: Box<RoomId>) -> Self {
|
pub fn new(room_id: Box<RoomId>) -> Self {
|
||||||
@ -198,7 +198,7 @@ impl RoomMembership {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
@ -209,7 +209,7 @@ pub struct CustomAllowRule {
|
|||||||
extra: BTreeMap<String, JsonValue>,
|
extra: BTreeMap<String, JsonValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
impl<'de> Deserialize<'de> for AllowRule {
|
impl<'de> Deserialize<'de> for AllowRule {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<AllowRule, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<AllowRule, D::Error>
|
||||||
where
|
where
|
||||||
@ -244,10 +244,10 @@ impl<'de> Deserialize<'de> for AllowRule {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
use ruma_identifiers::room_id;
|
use ruma_identifiers::room_id;
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
use super::AllowRule;
|
use super::AllowRule;
|
||||||
use super::{JoinRule, RoomJoinRulesEventContent, SyncRoomJoinRulesEvent};
|
use super::{JoinRule, RoomJoinRulesEventContent, SyncRoomJoinRulesEvent};
|
||||||
|
|
||||||
@ -258,9 +258,9 @@ mod tests {
|
|||||||
assert_matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public });
|
assert_matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public });
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_unstable() {
|
fn deserialize_restricted() {
|
||||||
let json = r#"{
|
let json = r#"{
|
||||||
"join_rule": "restricted",
|
"join_rule": "restricted",
|
||||||
"allow": [
|
"allow": [
|
||||||
|
@ -23,7 +23,7 @@ default = ["serde"]
|
|||||||
compat = ["ruma-identifiers-validation/compat"]
|
compat = ["ruma-identifiers-validation/compat"]
|
||||||
rand = ["rand_crate", "uuid"]
|
rand = ["rand_crate", "uuid"]
|
||||||
serde = ["ruma-serde", "serde1"]
|
serde = ["ruma-serde", "serde1"]
|
||||||
unstable-pre-spec = []
|
unstable-spec = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
either = { version = "1.6.1", optional = true }
|
either = { version = "1.6.1", optional = true }
|
||||||
|
@ -46,11 +46,11 @@ pub enum RoomVersionId {
|
|||||||
V7,
|
V7,
|
||||||
|
|
||||||
/// A version 8 room.
|
/// A version 8 room.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
V8,
|
V8,
|
||||||
|
|
||||||
/// A version 9 room.
|
/// A version 9 room.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
V9,
|
V9,
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@ -70,9 +70,9 @@ impl RoomVersionId {
|
|||||||
Self::V5 => "5",
|
Self::V5 => "5",
|
||||||
Self::V6 => "6",
|
Self::V6 => "6",
|
||||||
Self::V7 => "7",
|
Self::V7 => "7",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
Self::V8 => "8",
|
Self::V8 => "8",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
Self::V9 => "9",
|
Self::V9 => "9",
|
||||||
Self::_Custom(version) => version.as_str(),
|
Self::_Custom(version) => version.as_str(),
|
||||||
}
|
}
|
||||||
@ -94,9 +94,9 @@ impl From<RoomVersionId> for String {
|
|||||||
RoomVersionId::V5 => "5".to_owned(),
|
RoomVersionId::V5 => "5".to_owned(),
|
||||||
RoomVersionId::V6 => "6".to_owned(),
|
RoomVersionId::V6 => "6".to_owned(),
|
||||||
RoomVersionId::V7 => "7".to_owned(),
|
RoomVersionId::V7 => "7".to_owned(),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
RoomVersionId::V8 => "8".to_owned(),
|
RoomVersionId::V8 => "8".to_owned(),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
RoomVersionId::V9 => "9".to_owned(),
|
RoomVersionId::V9 => "9".to_owned(),
|
||||||
RoomVersionId::_Custom(version) => version.into(),
|
RoomVersionId::_Custom(version) => version.into(),
|
||||||
}
|
}
|
||||||
@ -164,9 +164,9 @@ where
|
|||||||
"5" => RoomVersionId::V5,
|
"5" => RoomVersionId::V5,
|
||||||
"6" => RoomVersionId::V6,
|
"6" => RoomVersionId::V6,
|
||||||
"7" => RoomVersionId::V7,
|
"7" => RoomVersionId::V7,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
"8" => RoomVersionId::V8,
|
"8" => RoomVersionId::V8,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
"9" => RoomVersionId::V9,
|
"9" => RoomVersionId::V9,
|
||||||
custom => {
|
custom => {
|
||||||
ruma_identifiers_validation::room_version_id::validate(custom)?;
|
ruma_identifiers_validation::room_version_id::validate(custom)?;
|
||||||
|
@ -17,7 +17,7 @@ all-features = true
|
|||||||
[features]
|
[features]
|
||||||
compat = ["tracing"]
|
compat = ["tracing"]
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
unstable-pre-spec = ["ruma-identifiers/unstable-pre-spec"]
|
unstable-pre-spec = ["ruma-identifiers/unstable-spec"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
|
@ -16,7 +16,7 @@ all-features = true
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
compat = []
|
compat = []
|
||||||
unstable-pre-spec = ["ruma-events/unstable-pre-spec", "ruma-identifiers/unstable-pre-spec"]
|
unstable-pre-spec = ["ruma-events/unstable-pre-spec", "ruma-identifiers/unstable-spec"]
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -113,14 +113,16 @@ unstable-pre-spec = [
|
|||||||
"ruma-client-api/unstable-pre-spec",
|
"ruma-client-api/unstable-pre-spec",
|
||||||
"ruma-events/unstable-pre-spec",
|
"ruma-events/unstable-pre-spec",
|
||||||
"ruma-federation-api/unstable-pre-spec",
|
"ruma-federation-api/unstable-pre-spec",
|
||||||
"ruma-identifiers/unstable-pre-spec",
|
|
||||||
"ruma-signatures/unstable-pre-spec",
|
"ruma-signatures/unstable-pre-spec",
|
||||||
"ruma-state-res/unstable-pre-spec"
|
"ruma-state-res/unstable-pre-spec",
|
||||||
#"ruma-identity-service-api/unstable-pre-spec",
|
# If you enable bleeding-edge pre-spec features, you
|
||||||
#"ruma-push-gateway-api/unstable-pre-spec",
|
# probably want things from the unstable spec too
|
||||||
|
"unstable-spec",
|
||||||
]
|
]
|
||||||
unstable-spec = [
|
unstable-spec = [
|
||||||
"ruma-client-api/unstable-spec"
|
"ruma-client-api/unstable-spec",
|
||||||
|
"ruma-events/unstable-spec",
|
||||||
|
"ruma-identifiers/unstable-spec",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user