mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 08:11:24 +01:00
implement senders and not_senders filters on /messages
This commit is contained in:
parent
0e2694a6c4
commit
75523fa3e0
1 changed files with 9 additions and 3 deletions
|
|
@ -16,7 +16,7 @@ use std::{collections::HashSet, hash::Hash};
|
|||
|
||||
use ruma::{
|
||||
api::client::filter::{RoomEventFilter, UrlFilter},
|
||||
RoomId,
|
||||
RoomId, UserId,
|
||||
};
|
||||
|
||||
use crate::{Error, PduEvent};
|
||||
|
|
@ -85,6 +85,7 @@ impl<'a, T: ?Sized + Hash + PartialEq + Eq> AllowDenyList<'a, T> {
|
|||
|
||||
pub(crate) struct CompiledRoomEventFilter<'a> {
|
||||
rooms: AllowDenyList<'a, RoomId>,
|
||||
senders: AllowDenyList<'a, UserId>,
|
||||
url_filter: Option<UrlFilter>,
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +100,10 @@ impl<'a> TryFrom<&'a RoomEventFilter> for CompiledRoomEventFilter<'a> {
|
|||
source.rooms.as_deref(),
|
||||
&source.not_rooms,
|
||||
),
|
||||
senders: AllowDenyList::from_slices(
|
||||
source.senders.as_deref(),
|
||||
&source.not_senders,
|
||||
),
|
||||
url_filter: source.url_filter,
|
||||
})
|
||||
}
|
||||
|
|
@ -118,14 +123,15 @@ impl CompiledRoomEventFilter<'_> {
|
|||
|
||||
/// Returns `true` if a PDU event is allowed by the filter.
|
||||
///
|
||||
/// This tests against the `url_filter` field.
|
||||
/// This tests against the `senders`, `not_senders`, and `url_filter`
|
||||
/// fields.
|
||||
///
|
||||
/// This does *not* check whether the event's room is allowed. It is
|
||||
/// expected that callers have already filtered out rejected rooms using
|
||||
/// [`CompiledRoomEventFilter::room_allowed`] and
|
||||
/// [`CompiledRoomFilter::rooms`].
|
||||
pub(crate) fn pdu_event_allowed(&self, pdu: &PduEvent) -> bool {
|
||||
self.allowed_by_url_filter(pdu)
|
||||
self.senders.allowed(&pdu.sender) && self.allowed_by_url_filter(pdu)
|
||||
}
|
||||
|
||||
fn allowed_by_url_filter(&self, pdu: &PduEvent) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue