implement per-event filtering for per-room account_data on /sync

This commit is contained in:
Benjamin Lee 2024-05-21 14:35:09 -07:00
parent 7a0b8c986f
commit 1410b6f409
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4
2 changed files with 24 additions and 1 deletions

View file

@ -994,6 +994,7 @@ async fn load_joined_room(
})
.ok()
})
.filter(|event| filter.room.account_data.raw_event_allowed(event))
.collect()
} else {
vec![]

View file

@ -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<CompiledFilter<'a>, 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;