client-api: use a RoomTypeFilter for syncv3 (not_)room_types filters

Signed-off-by: morguldir <morguldir@protonmail.com>
This commit is contained in:
morguldir 2024-09-04 23:42:26 +02:00 committed by Jonas Platte
parent f1fbfb12ea
commit d6890ef00c
3 changed files with 24 additions and 4 deletions

View File

@ -28,7 +28,7 @@ Improvements:
(`Future` events are scheduled messages that can be controlled
with `future_tokens` to send on demand or restart the timeout)
- Change types of `SyncRequestListFilters::{room_types,not_room_types}` to
`Vec<Option<RoomType>>` instead of a vector of strings
`Vec<RoomTypeFilter>` instead of a vector of strings
- This is a breaking change, but only for users of `unstable-msc3575`
Bug fixes:

View File

@ -10,8 +10,8 @@ use js_int::UInt;
use js_option::JsOption;
use ruma_common::{
api::{request, response, Metadata},
directory::RoomTypeFilter,
metadata,
room::RoomType,
serde::{deserialize_cow_str, duration::opt_ms, Raw},
DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedMxcUri, OwnedRoomId, OwnedUserId, RoomId,
};
@ -231,14 +231,14 @@ pub struct SyncRequestListFilters {
/// returned regardless of type. This can be used to get the initial set of spaces for an
/// account.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub room_types: Vec<Option<RoomType>>,
pub room_types: Vec<RoomTypeFilter>,
/// Only list rooms that are not of these create-types, or all.
///
/// Same as "room_types" but inverted. This can be used to filter out spaces from the room
/// list.
#[serde(default, skip_serializing_if = "<[_]>::is_empty")]
pub not_room_types: Vec<Option<RoomType>>,
pub not_room_types: Vec<RoomTypeFilter>,
/// Only list rooms matching the given string, or all.
///

View File

@ -223,12 +223,32 @@ where
}
}
impl From<Option<RoomType>> for RoomTypeFilter {
fn from(t: Option<RoomType>) -> Self {
match t {
None => Self::Default,
Some(s) => match s {
RoomType::Space => Self::Space,
_ => Self::from(Some(s.as_str())),
},
}
}
}
#[cfg(test)]
mod tests {
use assert_matches2::assert_matches;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::{Filter, RoomNetwork, RoomTypeFilter};
use crate::room::RoomType;
#[test]
fn test_from_room_type() {
let test = RoomType::Space;
let other: RoomTypeFilter = RoomTypeFilter::from(Some(test));
assert_eq!(other, RoomTypeFilter::Space);
}
#[test]
fn serialize_matrix_network_only() {