diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index 4ff6829e..74d196a3 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Improvements: + +- Add convenience constructors for enabling lazy-loading in filters + # 0.16.2 Bug fixes: diff --git a/crates/ruma-client-api/src/filter.rs b/crates/ruma-client-api/src/filter.rs index 541d26ce..f89863cd 100644 --- a/crates/ruma-client-api/src/filter.rs +++ b/crates/ruma-client-api/src/filter.rs @@ -117,6 +117,18 @@ impl RoomEventFilter { Self { types: Some(vec![]), ..Default::default() } } + /// Creates a new `RoomEventFilter` with [room member lazy-loading] enabled. + /// + /// Redundant membership events are disabled. + /// + /// [room member lazy-loading]: https://spec.matrix.org/latest/client-server-api/#lazy-loading-room-members + pub fn with_lazy_loading() -> Self { + Self { + lazy_load_options: LazyLoadOptions::Enabled { include_redundant_members: false }, + ..Default::default() + } + } + /// Returns `true` if all fields are empty. pub fn is_empty(&self) -> bool { self.not_types.is_empty() @@ -188,6 +200,15 @@ impl RoomFilter { Self { rooms: Some(vec![]), ..Default::default() } } + /// Creates a new `RoomFilter` with [room member lazy-loading] enabled. + /// + /// Redundant membership events are disabled. + /// + /// [room member lazy-loading]: https://spec.matrix.org/latest/client-server-api/#lazy-loading-room-members + pub fn with_lazy_loading() -> Self { + Self { state: RoomEventFilter::with_lazy_loading(), ..Default::default() } + } + /// Returns `true` if all fields are empty. pub fn is_empty(&self) -> bool { !self.include_leave @@ -311,6 +332,15 @@ impl FilterDefinition { } } + /// Creates a new `FilterDefinition` with [room member lazy-loading] enabled. + /// + /// Redundant membership events are disabled. + /// + /// [room member lazy-loading]: https://spec.matrix.org/latest/client-server-api/#lazy-loading-room-members + pub fn with_lazy_loading() -> Self { + Self { room: RoomFilter::with_lazy_loading(), ..Default::default() } + } + /// Returns `true` if all fields are empty. pub fn is_empty(&self) -> bool { self.event_fields.is_none()