Skip to content

Commit

Permalink
directory: Stabilize room_types and room_type for /publicRooms
Browse files Browse the repository at this point in the history
  • Loading branch information
zecakeh committed Oct 1, 2022
1 parent fa64b36 commit f068c3f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 52 deletions.
1 change: 1 addition & 0 deletions crates/ruma-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Improvements:

* Add `MatrixVersion::V1_4`
* Stabilize default room server ACL push rule
* Stabilize `room_types` in `directory::Filter` and `room_type` in `directory::PublicRoomsChunk`

# 0.10.3

Expand Down
1 change: 0 additions & 1 deletion crates/ruma-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ unstable-msc3551 = ["unstable-msc1767"]
unstable-msc3552 = ["unstable-msc3551"]
unstable-msc3553 = ["unstable-msc3552"]
unstable-msc3554 = ["unstable-msc1767"]
unstable-msc3827 = []
unstable-pdu = []
unstable-sanitize = ["dep:html5ever", "dep:phf"]
unstable-unspecified = []
Expand Down
55 changes: 6 additions & 49 deletions crates/ruma-common/src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
use js_int::UInt;
use serde::{Deserialize, Serialize};

#[cfg(feature = "unstable-msc3827")]
mod filter_room_type_serde;
mod room_network_serde;

#[cfg(feature = "unstable-msc3827")]
use crate::room::RoomType;
use crate::{
room::RoomType,
serde::{Incoming, StringEnum},
OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, PrivOwnedStr,
};
Expand Down Expand Up @@ -67,16 +65,7 @@ pub struct PublicRoomsChunk {
pub join_rule: PublicRoomJoinRule,

/// The type of room from `m.room.create`, if any.
///
/// This field uses the unstable prefix from [MSC3827].
///
/// [MSC3827]: https://github.com/matrix-org/matrix-spec-proposals/pull/3827
#[cfg(feature = "unstable-msc3827")]
#[serde(
rename = "org.matrix.msc3827.room_type",
alias = "room_type",
skip_serializing_if = "Option::is_none"
)]
#[serde(skip_serializing_if = "Option::is_none")]
pub room_type: Option<RoomType>,
}

Expand Down Expand Up @@ -117,7 +106,6 @@ impl From<PublicRoomsChunkInit> for PublicRoomsChunk {
guest_can_join,
avatar_url: None,
join_rule: PublicRoomJoinRule::default(),
#[cfg(feature = "unstable-msc3827")]
room_type: None,
}
}
Expand All @@ -135,17 +123,7 @@ pub struct Filter<'a> {
/// The room types to include in the results.
///
/// Includes all room types if it is empty.
///
/// This field uses the unstable prefix from [MSC3827].
///
/// [MSC3827]: https://github.com/matrix-org/matrix-spec-proposals/pull/3827
#[cfg(feature = "unstable-msc3827")]
#[serde(
rename = "org.matrix.msc3827.room_types",
alias = "room_types",
default,
skip_serializing_if = "Vec::is_empty"
)]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub room_types: Vec<RoomTypeFilter>,
}

Expand Down Expand Up @@ -208,7 +186,6 @@ pub enum PublicRoomJoinRule {
///
/// To check for values that are not available as a documented variant here, use its string
/// representation, obtained through [`.as_str()`](Self::as_str()).
#[cfg(feature = "unstable-msc3827")]
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum RoomTypeFilter {
Expand All @@ -223,7 +200,6 @@ pub enum RoomTypeFilter {
_Custom(PrivOwnedStr),
}

#[cfg(feature = "unstable-msc3827")]
impl RoomTypeFilter {
/// Get the string representation of this `RoomTypeFilter`.
///
Expand All @@ -237,7 +213,6 @@ impl RoomTypeFilter {
}
}

#[cfg(feature = "unstable-msc3827")]
impl<T> From<Option<T>> for RoomTypeFilter
where
T: AsRef<str> + Into<Box<str>>,
Expand All @@ -255,13 +230,10 @@ where

#[cfg(test)]
mod tests {
#[cfg(feature = "unstable-msc3827")]
use assert_matches::assert_matches;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};

#[cfg(feature = "unstable-msc3827")]
use super::RoomTypeFilter;
use super::{Filter, IncomingFilter, IncomingRoomNetwork, RoomNetwork};
use super::{Filter, IncomingFilter, IncomingRoomNetwork, RoomNetwork, RoomTypeFilter};

#[test]
fn serialize_matrix_network_only() {
Expand Down Expand Up @@ -341,11 +313,9 @@ mod tests {
let json = json!({});
let filter = from_json_value::<IncomingFilter>(json).unwrap();
assert_eq!(filter.generic_search_term, None);
#[cfg(feature = "unstable-msc3827")]
assert_eq!(filter.room_types.len(), 0);
}

#[cfg(feature = "unstable-msc3827")]
#[test]
fn serialize_filter_room_types() {
let filter = Filter {
Expand All @@ -356,25 +326,12 @@ mod tests {
Some("custom_type").into(),
],
};
let json = json!({ "org.matrix.msc3827.room_types": [null, "m.space", "custom_type"] });
let json = json!({ "room_types": [null, "m.space", "custom_type"] });
assert_eq!(to_json_value(filter).unwrap(), json);
}

#[cfg(feature = "unstable-msc3827")]
#[test]
fn deserialize_filter_room_types_unstable() {
let json = json!({ "org.matrix.msc3827.room_types": [null, "m.space", "custom_type"] });
let filter = from_json_value::<IncomingFilter>(json).unwrap();
assert_eq!(filter.room_types.len(), 3);
assert_eq!(filter.room_types[0], RoomTypeFilter::Default);
assert_eq!(filter.room_types[1], RoomTypeFilter::Space);
assert_matches!(filter.room_types[2], RoomTypeFilter::_Custom(_));
assert_eq!(filter.room_types[2].as_str(), Some("custom_type"));
}

#[cfg(feature = "unstable-msc3827")]
#[test]
fn deserialize_filter_room_types_stable() {
fn deserialize_filter_room_types() {
let json = json!({ "room_types": [null, "m.space", "custom_type"] });
let filter = from_json_value::<IncomingFilter>(json).unwrap();
assert_eq!(filter.room_types.len(), 3);
Expand Down
2 changes: 0 additions & 2 deletions crates/ruma/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ unstable-msc3554 = ["ruma-common/unstable-msc3554"]
unstable-msc3575 = ["ruma-client-api?/unstable-msc3575"]
unstable-msc3618 = ["ruma-federation-api?/unstable-msc3618"]
unstable-msc3723 = ["ruma-federation-api?/unstable-msc3723"]
unstable-msc3827 = ["ruma-common/unstable-msc3827"]
unstable-pdu = ["ruma-common/unstable-pdu"]
unstable-sanitize = ["ruma-common/unstable-sanitize"]
unstable-unspecified = [
Expand Down Expand Up @@ -194,7 +193,6 @@ __ci = [
"unstable-msc3575",
"unstable-msc3618",
"unstable-msc3723",
"unstable-msc3827",
]

[dependencies]
Expand Down

0 comments on commit f068c3f

Please sign in to comment.