mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-19 00:31:24 +01:00
implement per-event filtering for per-room account_data on /sync
This commit is contained in:
parent
7a0b8c986f
commit
1410b6f409
2 changed files with 24 additions and 1 deletions
|
|
@ -994,6 +994,7 @@ async fn load_joined_room(
|
||||||
})
|
})
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
|
.filter(|event| filter.room.account_data.raw_event_allowed(event))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ use std::{borrow::Cow, collections::HashSet, hash::Hash};
|
||||||
use regex::RegexSet;
|
use regex::RegexSet;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::filter::{
|
api::client::filter::{
|
||||||
FilterDefinition, RoomEventFilter, RoomFilter, UrlFilter,
|
Filter, FilterDefinition, RoomEventFilter, RoomFilter, UrlFilter,
|
||||||
},
|
},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
OwnedUserId, RoomId, UserId,
|
OwnedUserId, RoomId, UserId,
|
||||||
|
|
@ -164,6 +164,11 @@ pub(crate) struct CompiledFilterDefinition<'a> {
|
||||||
pub(crate) room: CompiledRoomFilter<'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> {
|
pub(crate) struct CompiledRoomFilter<'a> {
|
||||||
rooms: AllowDenyList<'a, RoomId>,
|
rooms: AllowDenyList<'a, RoomId>,
|
||||||
pub(crate) account_data: CompiledRoomEventFilter<'a>,
|
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> {
|
impl<'a> TryFrom<&'a RoomFilter> for CompiledRoomFilter<'a> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue