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
use super::*;

/// When a single message has been removed from a channel.
///
/// This is triggered via /delete <target-msg-id> on IRC.
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClearMsg {
    /// IRC tags
    pub tags: Tags,
    /// The channel this event happened on
    pub channel: String,
    /// The message being removed
    pub message: Option<String>,
}

impl ClearMsg {
    /// The channel this event happened on
    pub fn channel(&self) -> &str {
        &self.channel
    }
    /// The message.
    pub fn message(&self) -> Option<&str> {
        self.message.as_ref().map(String::as_str)
    }
}

impl ClearMsg {
    /// Name of the user who sent the message.
    pub fn login(&self) -> Option<&str> {
        self.get("login")
    }
    /// UUID of the message.
    pub fn target_msg_id(&self) -> Option<&str> {
        self.get("target-msg-id")
    }
}

impl Tag for ClearMsg {
    fn get(&self, key: &str) -> Option<&str> {
        self.tags.get(key).map(AsRef::as_ref)
    }
}