matrix_sdk_ui/timeline/event_type_filter.rs
1use ruma::events::{AnySyncTimelineEvent, TimelineEventType};
2
3/// A timeline filter that either includes only events with event_type included
4/// in a list or all but a list of excluded ones
5pub enum TimelineEventTypeFilter {
6 /// Only return items whose event type is included in the list
7 Include(Vec<TimelineEventType>),
8 /// Return all items except the ones whose event type is included in the
9 /// list
10 Exclude(Vec<TimelineEventType>),
11}
12
13impl TimelineEventTypeFilter {
14 /// Filters any incoming `event` using either an includes or excludes filter
15 /// based on its event type
16 pub fn filter(&self, event: &AnySyncTimelineEvent) -> bool {
17 match self {
18 TimelineEventTypeFilter::Include(event_types) => {
19 event_types.contains(&event.event_type())
20 }
21 TimelineEventTypeFilter::Exclude(event_types) => {
22 !event_types.contains(&event.event_type())
23 }
24 }
25 }
26}