client-api: Add convenience constructors for enabling lazy-loading in filters

This commit is contained in:
Kévin Commaille 2023-02-25 11:10:29 +01:00 committed by Kévin Commaille
parent a435a83cdd
commit ba237a9cfd
2 changed files with 34 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# [unreleased] # [unreleased]
Improvements:
- Add convenience constructors for enabling lazy-loading in filters
# 0.16.2 # 0.16.2
Bug fixes: Bug fixes:

View File

@ -117,6 +117,18 @@ impl RoomEventFilter {
Self { types: Some(vec![]), ..Default::default() } 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. /// Returns `true` if all fields are empty.
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.not_types.is_empty() self.not_types.is_empty()
@ -188,6 +200,15 @@ impl RoomFilter {
Self { rooms: Some(vec![]), ..Default::default() } 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. /// Returns `true` if all fields are empty.
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
!self.include_leave !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. /// Returns `true` if all fields are empty.
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.event_fields.is_none() self.event_fields.is_none()