twilight_model/gateway/payload/incoming/
message_poll_vote_add.rs

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::id::{
    marker::{ChannelMarker, GuildMarker, MessageMarker, UserMarker},
    Id,
};
use serde::{Deserialize, Serialize};

/// Sent when a user votes on a poll. If the poll allows multiple selection,
/// one event will be sent per answer.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct MessagePollVoteAdd {
    /// ID of the answer.
    pub answer_id: u8,
    /// ID of the channel.
    pub channel_id: Id<ChannelMarker>,
    /// ID of the guild.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub guild_id: Option<Id<GuildMarker>>,
    /// ID of the message.
    pub message_id: Id<MessageMarker>,
    /// ID of the user.
    pub user_id: Id<UserMarker>,
}

#[cfg(test)]
mod tests {
    use super::{Id, MessagePollVoteAdd};
    use serde_test::Token;

    #[test]
    fn test_message_poll_vote_add() {
        let value = MessagePollVoteAdd {
            answer_id: 1,
            channel_id: Id::new(2),
            guild_id: Some(Id::new(3)),
            message_id: Id::new(4),
            user_id: Id::new(5),
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "MessagePollVoteAdd",
                    len: 5,
                },
                Token::Str("answer_id"),
                Token::U8(1),
                Token::Str("channel_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("2"),
                Token::Str("guild_id"),
                Token::Some,
                Token::NewtypeStruct { name: "Id" },
                Token::Str("3"),
                Token::Str("message_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("4"),
                Token::Str("user_id"),
                Token::NewtypeStruct { name: "Id" },
                Token::Str("5"),
                Token::StructEnd,
            ],
        );
    }
}