robespierre_models/
invites.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    autumn::Attachment,
5    id::{ChannelId, InviteId, ServerId, UserId},
6};
7
8// https://github.com/revoltchat/api/blob/097f40e37108cd3a1816b1c2cc69a137ae317069/types/Invites.ts#L4-L26
9
10#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
11#[serde(deny_unknown_fields)]
12pub struct ServerInvite {
13    #[serde(rename = "_id")]
14    pub id: InviteId,
15    pub server: ServerId,
16    pub creator: UserId,
17    /// ID of the channel this invite is for.
18    pub channel: ChannelId,
19}
20
21// https://github.com/revoltchat/api/blob/097f40e37108cd3a1816b1c2cc69a137ae317069/types/Invites.ts#L28
22
23#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
24#[serde(tag = "type")]
25#[serde(deny_unknown_fields)]
26pub enum Invite {
27    Invite(ServerInvite),
28}
29
30// https://github.com/revoltchat/api/blob/097f40e37108cd3a1816b1c2cc69a137ae317069/types/Invites.ts#L30-L42
31
32#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
33#[serde(deny_unknown_fields)]
34pub struct ServerRetrievedInvite {
35    pub server_id: ServerId,
36    pub server_name: String,
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub server_icon: Option<Attachment>,
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub server_banner: Option<Attachment>,
41    pub channel_id: ChannelId,
42    pub channel_name: String,
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub channel_description: Option<String>,
45    pub user_name: String,
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub user_avatar: Option<Attachment>,
48    pub member_count: usize,
49}
50
51#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
52#[serde(tag = "type")]
53#[serde(deny_unknown_fields)]
54pub enum RetrievedInvite {
55    Server(ServerRetrievedInvite),
56}