aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/state.rs
blob: 6945d4e89dbda538713ec067b86fd177f8b9e454 (plain) (blame)
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
43
44
45
46
47
48
use std::collections::HashSet;

/// The full state of a connected IRC client.
#[derive(Debug, Default)]
pub struct ClientState {
    pub nick: String,
    pub channel: Channel,
    pub caps: HashSet<String>,
    pub server_name: Option<String>,
    pub reg: RegistrationState,
}

impl ClientState {
    pub fn new(nick: impl Into<String>) -> Self {
        Self {
            nick: nick.into(),
            ..Default::default()
        }
    }
}

/// State of the registration handshake.
#[derive(Debug, Default, PartialEq, Eq)]
pub enum RegistrationState {
    #[default]
    CapNegotiation,
    CapPending,
    WaitingForWelcome,
    Registered,
}

/// A joined channel and its current state.
#[derive(Debug, Default)]
pub struct Channel {
    pub name: String,
    pub members: HashSet<String>,
    pub topic: Option<String>,
}

impl Channel {
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            members: HashSet::new(),
            topic: None,
        }
    }
}