rive_models/
channel.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    attachment::Attachment,
7    permission::{OverrideField, Permission},
8};
9
10/// Representation of a channel on Revolt
11#[derive(Deserialize, Debug, Clone)]
12#[serde(tag = "channel_type")]
13pub enum Channel {
14    /// Personal "Saved Notes" channel which allows users to save messages
15    SavedMessages {
16        /// Unique Id
17        #[serde(rename = "_id")]
18        id: String,
19        /// Id of the user this channel belongs to
20        user: String,
21    },
22
23    /// Direct message channel between two users
24    DirectMessage {
25        /// Unique Id
26        #[serde(rename = "_id")]
27        id: String,
28
29        /// Whether this direct message channel is currently open on both sides
30        active: bool,
31        /// 2-tuple of user ids participating in direct message
32        recipients: Vec<String>,
33        /// Id of the last message sent in this channel
34        last_message_id: Option<String>,
35    },
36
37    /// Group channel between 1 or more participants
38    Group {
39        /// Unique Id
40        #[serde(rename = "_id")]
41        id: String,
42
43        /// Display name of the channel
44        name: String,
45        /// User id of the owner of the group
46        owner: String,
47        /// Channel description
48        description: Option<String>,
49        /// Array of user ids participating in channel
50        recipients: Vec<String>,
51
52        /// Custom icon attachment
53        icon: Option<Attachment>,
54        /// Id of the last message sent in this channel
55        last_message_id: Option<String>,
56
57        /// Permissions assigned to members of this group
58        /// (does not apply to the owner of the group)
59        permissions: Option<Permission>,
60
61        /// Whether this group is marked as not safe for work
62        #[serde(default)]
63        nsfw: bool,
64    },
65
66    /// Text channel belonging to a server
67    TextChannel {
68        /// Unique Id
69        #[serde(rename = "_id")]
70        id: String,
71        /// Id of the server this channel belongs to
72        server: String,
73
74        /// Display name of the channel
75        name: String,
76        /// Channel description
77        description: Option<String>,
78
79        /// Custom icon attachment
80        icon: Option<Attachment>,
81        /// Id of the last message sent in this channel
82        last_message_id: Option<String>,
83
84        /// Default permissions assigned to users in this channel
85        default_permissions: Option<OverrideField>,
86        /// Permissions assigned based on role to this channel
87        #[serde(default = "HashMap::<String, OverrideField>::new")]
88        role_permissions: HashMap<String, OverrideField>,
89
90        /// Whether this channel is marked as not safe for work
91        #[serde(default)]
92        nsfw: bool,
93    },
94
95    /// Voice channel belonging to a server
96    VoiceChannel {
97        /// Unique Id
98        #[serde(rename = "_id")]
99        id: String,
100        /// Id of the server this channel belongs to
101        server: String,
102
103        /// Display name of the channel
104        name: String,
105        /// Channel description
106        description: Option<String>,
107        /// Custom icon attachment
108        icon: Option<Attachment>,
109
110        /// Default permissions assigned to users in this channel
111        default_permissions: Option<OverrideField>,
112        /// Permissions assigned based on role to this channel
113        #[serde(default = "HashMap::<String, OverrideField>::new")]
114        role_permissions: HashMap<String, OverrideField>,
115
116        /// Whether this channel is marked as not safe for work
117        #[serde(default)]
118        nsfw: bool,
119    },
120}
121
122/// Partial values of [Channel]
123#[derive(Deserialize, Debug, Default, Clone)]
124pub struct PartialChannel {
125    /// Display name of the channel
126    pub name: Option<String>,
127    /// User id of the owner of the group
128    pub owner: Option<String>,
129    /// Channel description
130    pub description: Option<String>,
131    /// Custom icon attachment
132    pub icon: Option<Attachment>,
133    /// Whether this channel is marked as not safe for work
134    pub nsfw: Option<bool>,
135    /// Whether this direct message channel is currently open on both sides
136    pub active: Option<bool>,
137    /// Permissions assigned to members of this channel
138    pub permissions: Option<Permission>,
139    /// Permissions assigned based on role to this channel
140    pub role_permissions: Option<HashMap<String, OverrideField>>,
141    /// Default permissions assigned to users in this channel
142    pub default_permissions: Option<OverrideField>,
143    /// Id of the last message sent in this channel
144    pub last_message_id: Option<String>,
145}
146
147/// Channel type
148#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)]
149pub enum ChannelType {
150    #[default]
151    Text,
152    Voice,
153}
154
155/// Optional fields on channel object
156#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
157pub enum FieldsChannel {
158    Description,
159    Icon,
160    DefaultPermissions,
161}
162
163/// Representation of an invite to a channel on Revolt
164#[derive(Deserialize, Debug, Clone)]
165#[serde(tag = "type")]
166pub enum PartialInvite {
167    /// Invite to a specific server channel
168    Server {
169        /// Invite code
170        #[serde(rename = "_id")]
171        code: String,
172        /// Id of the server this invite points to
173        server: String,
174        /// Id of user who created this invite
175        creator: String,
176        /// Id of the server channel this invite points to
177        channel: String,
178    },
179    /// Invite to a group channel
180    Group {
181        /// Invite code
182        #[serde(rename = "_id")]
183        code: String,
184        /// Id of user who created this invite
185        creator: String,
186        /// Id of the group channel this invite points to
187        channel: String,
188    },
189}
190
191/// Composite primary key consisting of channel and user ID
192#[derive(Deserialize, Debug, PartialEq, Clone)]
193pub struct ChannelCompositeKey {
194    /// Channel ID
195    pub channel: String,
196    /// User ID
197    pub user: String,
198}
199
200/// Representation of the state of a channel from the perspective of a user
201#[derive(Deserialize, Debug, Clone)]
202pub struct ChannelUnread {
203    /// Composite key pointing to a user's view of a channel
204    #[serde(rename = "_id")]
205    pub id: ChannelCompositeKey,
206
207    /// ID of the last message read in this channel by a user
208    pub last_id: Option<String>,
209    /// Array of message ids that mention the user
210    pub mentions: Option<Vec<String>>,
211}