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
use std::time::{SystemTime, UNIX_EPOCH};

use serde::{Deserialize, Serialize};

/// Eventmeta that is appended to every event.
#[derive(Serialize, Deserialize, Debug)]
pub struct EventMeta {
    pub t: String,
    pub c: u64,
}

impl EventMeta {
	pub fn new(t: &str) -> Self {
		EventMeta {
			t: String::from(t),
			c: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
		}
	}
}

/// User struct to de- serialize the user.
/// Holds the users nick and pubkey.
/// Used in the join and leave events.
#[derive(Serialize, Deserialize, Debug)]
pub struct User {
    pub nick: String,
	pub pubkey: String,
}

/// Event struct to decode all events from.
#[derive(Serialize, Deserialize, Debug)]
pub struct Event {
	pub e: EventMeta
}