summaryrefslogtreecommitdiff
path: root/src/channel/history.rs
blob: 3cc7d9d0e9091b02cbfdd78536afa46aa118eba6 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::{
    event::{Created, Deleted, Event},
    Channel,
};
use crate::event::Instant;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct History {
    pub channel: Channel,
    pub created: Instant,
    pub deleted: Option<Instant>,
}

impl History {
    fn created(&self) -> Event {
        Event {
            instant: self.created,
            kind: Created {
                channel: self.channel.clone(),
            }
            .into(),
        }
    }

    fn deleted(&self) -> Option<Event> {
        self.deleted.map(|instant| Event {
            instant,
            kind: Deleted {
                channel: self.channel.id.clone(),
            }
            .into(),
        })
    }

    pub fn events(&self) -> impl Iterator<Item = Event> {
        [self.created()].into_iter().chain(self.deleted())
    }

    pub fn snapshot(&self) -> Channel {
        self.channel.clone()
    }
}