events: Remove unstable-spec feature

Everything that was gated behind it was stabilized with Matrix v1.2.
This commit is contained in:
Jonas Platte 2022-02-02 23:11:36 +01:00
parent e9994b89c8
commit 71a7dbdc43
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
8 changed files with 7 additions and 56 deletions

View File

@ -21,8 +21,7 @@ markdown = ["pulldown-cmark"]
unstable-exhaustive-types = [] unstable-exhaustive-types = []
unstable-pdu = [] unstable-pdu = []
unstable-pre-spec = ["unstable-spec"] unstable-pre-spec = []
unstable-spec = []
[dependencies] [dependencies]
criterion = { version = "0.3.3", optional = true } criterion = { version = "0.3.3", optional = true }

View File

@ -74,9 +74,7 @@ event_enum! {
"m.room.third_party_invite", "m.room.third_party_invite",
"m.room.tombstone", "m.room.tombstone",
"m.room.topic", "m.room.topic",
#[cfg(feature = "unstable-spec")]
"m.space.child", "m.space.child",
#[cfg(feature = "unstable-spec")]
"m.space.parent", "m.space.parent",
} }

View File

@ -172,7 +172,6 @@ pub mod room;
pub mod room_key; pub mod room_key;
pub mod room_key_request; pub mod room_key_request;
pub mod secret; pub mod secret;
#[cfg(feature = "unstable-spec")]
pub mod space; pub mod space;
pub mod sticker; pub mod sticker;
pub mod tag; pub mod tag;

View File

@ -4,11 +4,9 @@
use ruma_events_macros::EventContent; use ruma_events_macros::EventContent;
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId}; use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
#[cfg(feature = "unstable-spec")]
use ruma_serde::StringEnum; use ruma_serde::StringEnum;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-spec")]
use crate::PrivOwnedStr; use crate::PrivOwnedStr;
/// The content of an `m.room.create` event. /// The content of an `m.room.create` event.
@ -47,7 +45,6 @@ pub struct RoomCreateEventContent {
/// The room type. /// The room type.
/// ///
/// This is currently only used for spaces. /// This is currently only used for spaces.
#[cfg(feature = "unstable-spec")]
#[serde(skip_serializing_if = "Option::is_none", rename = "type")] #[serde(skip_serializing_if = "Option::is_none", rename = "type")]
pub room_type: Option<RoomType>, pub room_type: Option<RoomType>,
} }
@ -60,7 +57,6 @@ impl RoomCreateEventContent {
federate: true, federate: true,
room_version: default_room_version_id(), room_version: default_room_version_id(),
predecessor: None, predecessor: None,
#[cfg(feature = "unstable-spec")]
room_type: None, room_type: None,
} }
} }
@ -71,7 +67,6 @@ impl RoomCreateEventContent {
/// This type can hold an arbitrary string. To check for formats that are not available as a /// This type can hold an arbitrary string. To check for formats that are not available as a
/// documented variant here, use its string representation, obtained through `.as_str()`. /// documented variant here, use its string representation, obtained through `.as_str()`.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)] #[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[cfg(feature = "unstable-spec")]
#[non_exhaustive] #[non_exhaustive]
pub enum RoomType { pub enum RoomType {
/// Defines the room as a space. /// Defines the room as a space.
@ -83,7 +78,6 @@ pub enum RoomType {
_Custom(PrivOwnedStr), _Custom(PrivOwnedStr),
} }
#[cfg(feature = "unstable-spec")]
impl RoomType { impl RoomType {
/// Creates a string slice from this `RoomType`. /// Creates a string slice from this `RoomType`.
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {
@ -120,10 +114,7 @@ mod tests {
use ruma_identifiers::{user_id, RoomVersionId}; use ruma_identifiers::{user_id, RoomVersionId};
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::RoomCreateEventContent; use super::{RoomCreateEventContent, RoomType};
#[cfg(feature = "unstable-spec")]
use super::RoomType;
#[test] #[test]
fn serialization() { fn serialization() {
@ -132,7 +123,6 @@ mod tests {
federate: false, federate: false,
room_version: RoomVersionId::V4, room_version: RoomVersionId::V4,
predecessor: None, predecessor: None,
#[cfg(feature = "unstable-spec")]
room_type: None, room_type: None,
}; };
@ -145,7 +135,6 @@ mod tests {
assert_eq!(to_json_value(&content).unwrap(), json); assert_eq!(to_json_value(&content).unwrap(), json);
} }
#[cfg(feature = "unstable-spec")]
#[test] #[test]
fn space_serialization() { fn space_serialization() {
let content = RoomCreateEventContent { let content = RoomCreateEventContent {
@ -181,7 +170,6 @@ mod tests {
federate: true, federate: true,
room_version: RoomVersionId::V4, room_version: RoomVersionId::V4,
predecessor: None, predecessor: None,
#[cfg(feature = "unstable-spec")]
room_type: None, room_type: None,
} if creator == "@carl:example.com" } if creator == "@carl:example.com"
); );

View File

@ -3,20 +3,14 @@
//! [`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-spec")]
use ruma_identifiers::RoomId; use ruma_identifiers::RoomId;
#[cfg(feature = "unstable-spec")]
use ruma_serde::from_raw_json_value; use ruma_serde::from_raw_json_value;
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, Value as JsonValue};
#[cfg(feature = "unstable-spec")] use std::{borrow::Cow, collections::BTreeMap};
use serde_json::Value as JsonValue;
use std::borrow::Cow;
#[cfg(feature = "unstable-spec")]
use std::collections::BTreeMap;
use crate::PrivOwnedStr; use crate::PrivOwnedStr;
@ -41,7 +35,6 @@ 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-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 +73,6 @@ 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-spec")]
#[serde(rename = "restricted")] #[serde(rename = "restricted")]
Restricted(Restricted), Restricted(Restricted),
@ -100,7 +92,6 @@ impl JoinRule {
JoinRule::Invite => "invite", JoinRule::Invite => "invite",
JoinRule::Knock => "knock", JoinRule::Knock => "knock",
JoinRule::Private => "private", JoinRule::Private => "private",
#[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,
@ -129,7 +120,6 @@ 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-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()))),
@ -138,7 +128,6 @@ impl<'de> Deserialize<'de> for JoinRule {
} }
/// Configuration of the `Restricted` join rule. /// Configuration of the `Restricted` join rule.
#[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 {
@ -146,7 +135,6 @@ pub struct Restricted {
allow: Vec<AllowRule>, allow: Vec<AllowRule>,
} }
#[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 {
@ -155,7 +143,6 @@ 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-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")]
@ -168,7 +155,6 @@ pub enum AllowRule {
_Custom(CustomAllowRule), _Custom(CustomAllowRule),
} }
#[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 {
@ -177,7 +163,6 @@ 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-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 {
@ -185,7 +170,6 @@ pub struct RoomMembership {
pub room_id: Box<RoomId>, pub room_id: Box<RoomId>,
} }
#[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 {
@ -193,7 +177,6 @@ impl RoomMembership {
} }
} }
#[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)]
@ -204,7 +187,6 @@ pub struct CustomAllowRule {
extra: BTreeMap<String, JsonValue>, extra: BTreeMap<String, JsonValue>,
} }
#[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
@ -235,12 +217,9 @@ 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-spec")]
use ruma_identifiers::room_id; use ruma_identifiers::room_id;
#[cfg(feature = "unstable-spec")] use super::{AllowRule, JoinRule, RoomJoinRulesEventContent, SyncRoomJoinRulesEvent};
use super::AllowRule;
use super::{JoinRule, RoomJoinRulesEventContent, SyncRoomJoinRulesEvent};
#[test] #[test]
fn deserialize() { fn deserialize() {
@ -249,7 +228,6 @@ mod tests {
assert_matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public }); assert_matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public });
} }
#[cfg(feature = "unstable-spec")]
#[test] #[test]
fn deserialize_restricted() { fn deserialize_restricted() {
let json = r#"{ let json = r#"{

View File

@ -98,7 +98,6 @@ pub struct RoomMemberEventContent {
pub reason: Option<String>, pub reason: Option<String>,
/// Arbitrarily chosen `UserId` (MxID) of a local user who can send an invite. /// Arbitrarily chosen `UserId` (MxID) of a local user who can send an invite.
#[cfg(feature = "unstable-spec")]
#[serde(rename = "join_authorised_via_users_server")] #[serde(rename = "join_authorised_via_users_server")]
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub join_authorized_via_users_server: Option<Box<UserId>>, pub join_authorized_via_users_server: Option<Box<UserId>>,
@ -116,7 +115,6 @@ impl RoomMemberEventContent {
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
blurhash: None, blurhash: None,
reason: None, reason: None,
#[cfg(feature = "unstable-spec")]
join_authorized_via_users_server: None, join_authorized_via_users_server: None,
} }
} }
@ -128,7 +126,6 @@ impl RedactContent for RoomMemberEventContent {
fn redact(self, _version: &RoomVersionId) -> RedactedRoomMemberEventContent { fn redact(self, _version: &RoomVersionId) -> RedactedRoomMemberEventContent {
RedactedRoomMemberEventContent { RedactedRoomMemberEventContent {
membership: self.membership, membership: self.membership,
#[cfg(feature = "unstable-spec")]
join_authorized_via_users_server: match _version { join_authorized_via_users_server: match _version {
RoomVersionId::V9 => self.join_authorized_via_users_server, RoomVersionId::V9 => self.join_authorized_via_users_server,
_ => None, _ => None,
@ -148,7 +145,6 @@ pub struct RedactedRoomMemberEventContent {
/// ///
/// This is redacted in room versions 8 and below. It is used for validating /// This is redacted in room versions 8 and below. It is used for validating
/// joins when the join rule is restricted. /// joins when the join rule is restricted.
#[cfg(feature = "unstable-spec")]
#[serde(rename = "join_authorised_via_users_server")] #[serde(rename = "join_authorised_via_users_server")]
pub join_authorized_via_users_server: Option<Box<UserId>>, pub join_authorized_via_users_server: Option<Box<UserId>>,
} }
@ -156,11 +152,7 @@ pub struct RedactedRoomMemberEventContent {
impl RedactedRoomMemberEventContent { impl RedactedRoomMemberEventContent {
/// Create a `RedactedRoomMemberEventContent` with the given membership. /// Create a `RedactedRoomMemberEventContent` with the given membership.
pub fn new(membership: MembershipState) -> Self { pub fn new(membership: MembershipState) -> Self {
Self { Self { membership, join_authorized_via_users_server: None }
membership,
#[cfg(feature = "unstable-spec")]
join_authorized_via_users_server: None,
}
} }
} }
@ -352,7 +344,6 @@ fn membership_change(
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
blurhash: None, blurhash: None,
reason: None, reason: None,
#[cfg(feature = "unstable-spec")]
join_authorized_via_users_server: None, join_authorized_via_users_server: None,
} }
}; };
@ -746,7 +737,6 @@ mod tests {
); );
} }
#[cfg(feature = "unstable-spec")]
#[test] #[test]
fn serde_with_join_authorized() { fn serde_with_join_authorized() {
let json = json!({ let json = json!({

View File

@ -17,7 +17,7 @@ all-features = true
[features] [features]
compat = [] compat = []
unstable-exhaustive-types = [] unstable-exhaustive-types = []
unstable-spec = ["ruma-events/unstable-spec"] unstable-spec = []
# Private, only used in test / benchmarking code # Private, only used in test / benchmarking code
__unstable-pre-spec = ["ruma-events/unstable-pre-spec", "unstable-spec"] __unstable-pre-spec = ["ruma-events/unstable-pre-spec", "unstable-spec"]

View File

@ -121,7 +121,6 @@ unstable-pre-spec = [
] ]
unstable-spec = [ unstable-spec = [
"ruma-client-api/unstable-spec", "ruma-client-api/unstable-spec",
"ruma-events/unstable-spec",
] ]
[dependencies] [dependencies]