diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 3aea0a2b..c25f78c0 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -994,6 +994,7 @@ async fn load_joined_room( }) .ok() }) + .filter(|event| filter.room.account_data.raw_event_allowed(event)) .collect() } else { vec![] diff --git a/src/utils/filter.rs b/src/utils/filter.rs index 1947df98..3f113d93 100644 --- a/src/utils/filter.rs +++ b/src/utils/filter.rs @@ -25,7 +25,7 @@ use std::{borrow::Cow, collections::HashSet, hash::Hash}; use regex::RegexSet; use ruma::{ api::client::filter::{ - FilterDefinition, RoomEventFilter, RoomFilter, UrlFilter, + Filter, FilterDefinition, RoomEventFilter, RoomFilter, UrlFilter, }, serde::Raw, OwnedUserId, RoomId, UserId, @@ -164,6 +164,11 @@ pub(crate) struct CompiledFilterDefinition<'a> { pub(crate) room: CompiledRoomFilter<'a>, } +pub(crate) struct CompiledFilter<'a> { + pub(crate) types: WildcardAllowDenyList, + pub(crate) senders: AllowDenyList<'a, UserId>, +} + pub(crate) struct CompiledRoomFilter<'a> { rooms: AllowDenyList<'a, RoomId>, pub(crate) account_data: CompiledRoomEventFilter<'a>, @@ -195,6 +200,23 @@ impl<'a> TryFrom<&'a FilterDefinition> for CompiledFilterDefinition<'a> { } } +impl<'a> TryFrom<&'a Filter> for CompiledFilter<'a> { + type Error = Error; + + fn try_from(source: &'a Filter) -> Result, Error> { + Ok(CompiledFilter { + types: WildcardAllowDenyList::new( + source.types.as_deref(), + &source.not_types, + )?, + senders: AllowDenyList::from_slices( + source.senders.as_deref(), + &source.not_senders, + ), + }) + } +} + impl<'a> TryFrom<&'a RoomFilter> for CompiledRoomFilter<'a> { type Error = Error;