1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use ruma::events::{AnySyncTimelineEvent, TimelineEventType};

/// A timeline filter that either includes only events with event_type included
/// in a list or all but a list of excluded ones
pub enum TimelineEventTypeFilter {
    /// Only return items whose event type is included in the list
    Include(Vec<TimelineEventType>),
    /// Return all items except the ones whose event type is included in the
    /// list
    Exclude(Vec<TimelineEventType>),
}

impl TimelineEventTypeFilter {
    /// Filters any incoming `event` using either an includes or excludes filter
    /// based on its event type
    pub fn filter(&self, event: &AnySyncTimelineEvent) -> bool {
        match self {
            TimelineEventTypeFilter::Include(event_types) => {
                event_types.contains(&event.event_type())
            }
            TimelineEventTypeFilter::Exclude(event_types) => {
                !event_types.contains(&event.event_type())
            }
        }
    }
}