feat: channel model implementation (#250)
Co-authored-by: ToastXC <100072983+toastxc@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,9 @@ partials = [ "dep:revolt_optional_struct", "serde", "schemas" ]
|
||||
default = [ "serde", "partials" ]
|
||||
|
||||
[dependencies]
|
||||
# Core
|
||||
revolt-permissions = { version = "0.6.0-rc.1", path = "../permissions", features = [ "serde" ] }
|
||||
|
||||
# Serialisation
|
||||
revolt_optional_struct = { version = "0.2.0", optional = true }
|
||||
serde = { version = "1", features = ["derive"], optional = true }
|
||||
|
||||
208
crates/core/models/src/v0/channels.rs
Normal file
208
crates/core/models/src/v0/channels.rs
Normal file
@@ -0,0 +1,208 @@
|
||||
use super::File;
|
||||
|
||||
use revolt_permissions::OverrideField;
|
||||
use std::collections::HashMap;
|
||||
|
||||
auto_derived!(
|
||||
/// Channel
|
||||
pub enum Channel {
|
||||
/// Personal "Saved Notes" channel which allows users to save messages
|
||||
SavedMessages {
|
||||
/// Unique Id
|
||||
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||
id: String,
|
||||
/// Id of the user this channel belongs to
|
||||
user: String,
|
||||
},
|
||||
/// Direct message channel between two users
|
||||
DirectMessage {
|
||||
/// Unique Id
|
||||
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||
id: String,
|
||||
|
||||
/// Whether this direct message channel is currently open on both sides
|
||||
active: bool,
|
||||
/// 2-tuple of user ids participating in direct message
|
||||
recipients: Vec<String>,
|
||||
/// Id of the last message sent in this channel
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
last_message_id: Option<String>,
|
||||
},
|
||||
/// Group channel between 1 or more participants
|
||||
Group {
|
||||
/// Unique Id
|
||||
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||
id: String,
|
||||
|
||||
/// Display name of the channel
|
||||
name: String,
|
||||
/// User id of the owner of the group
|
||||
owner: String,
|
||||
/// Channel description
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
description: Option<String>,
|
||||
/// Array of user ids participating in channel
|
||||
recipients: Vec<String>,
|
||||
|
||||
/// Custom icon attachment
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
icon: Option<File>,
|
||||
/// Id of the last message sent in this channel
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
last_message_id: Option<String>,
|
||||
|
||||
/// Permissions assigned to members of this group
|
||||
/// (does not apply to the owner of the group)
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
permissions: Option<i64>,
|
||||
|
||||
/// Whether this group is marked as not safe for work
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
serde(skip_serializing_if = "crate::if_false", default)
|
||||
)]
|
||||
nsfw: bool,
|
||||
},
|
||||
/// Text channel belonging to a server
|
||||
TextChannel {
|
||||
/// Unique Id
|
||||
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||
id: String,
|
||||
/// Id of the server this channel belongs to
|
||||
server: String,
|
||||
|
||||
/// Display name of the channel
|
||||
name: String,
|
||||
/// Channel description
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
description: Option<String>,
|
||||
|
||||
/// Custom icon attachment
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
icon: Option<File>,
|
||||
/// Id of the last message sent in this channel
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
last_message_id: Option<String>,
|
||||
|
||||
/// Default permissions assigned to users in this channel
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
default_permissions: Option<OverrideField>,
|
||||
/// Permissions assigned based on role to this channel
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
serde(
|
||||
default = "HashMap::<String, OverrideField>::new",
|
||||
skip_serializing_if = "HashMap::<String, OverrideField>::is_empty"
|
||||
)
|
||||
)]
|
||||
role_permissions: HashMap<String, OverrideField>,
|
||||
|
||||
/// Whether this channel is marked as not safe for work
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
serde(skip_serializing_if = "crate::if_false", default)
|
||||
)]
|
||||
nsfw: bool,
|
||||
},
|
||||
/// Voice channel belonging to a server
|
||||
VoiceChannel {
|
||||
/// Unique Id
|
||||
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||
id: String,
|
||||
/// Id of the server this channel belongs to
|
||||
server: String,
|
||||
|
||||
/// Display name of the channel
|
||||
name: String,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
/// Channel description
|
||||
description: Option<String>,
|
||||
/// Custom icon attachment
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
icon: Option<File>,
|
||||
|
||||
/// Default permissions assigned to users in this channel
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
default_permissions: Option<OverrideField>,
|
||||
/// Permissions assigned based on role to this channel
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
serde(
|
||||
default = "HashMap::<String, OverrideField>::new",
|
||||
skip_serializing_if = "HashMap::<String, OverrideField>::is_empty"
|
||||
)
|
||||
)]
|
||||
role_permissions: HashMap<String, OverrideField>,
|
||||
|
||||
/// Whether this channel is marked as not safe for work
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
serde(skip_serializing_if = "crate::if_false", default)
|
||||
)]
|
||||
nsfw: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// Partial representation of a channel
|
||||
#[derive(Default)]
|
||||
pub struct PartialChannel {
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub name: Option<String>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub owner: Option<String>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub description: Option<String>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub icon: Option<File>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub nsfw: Option<bool>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub active: Option<bool>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub permissions: Option<i64>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub role_permissions: Option<HashMap<String, OverrideField>>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub default_permissions: Option<OverrideField>,
|
||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub last_message_id: Option<String>,
|
||||
}
|
||||
|
||||
/// Optional fields on channel object
|
||||
pub enum FieldsChannel {
|
||||
Description,
|
||||
Icon,
|
||||
DefaultPermissions,
|
||||
}
|
||||
|
||||
/// New webhook information
|
||||
#[cfg_attr(feature = "validator", derive(validator::Validate))]
|
||||
pub struct DataEditChannel {
|
||||
/// Channel name
|
||||
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
|
||||
pub name: Option<String>,
|
||||
|
||||
/// Channel description
|
||||
#[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
|
||||
pub description: Option<String>,
|
||||
|
||||
/// Group owner
|
||||
pub owner: Option<String>,
|
||||
|
||||
/// Icon
|
||||
///
|
||||
/// Provide an Autumn attachment Id.
|
||||
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
|
||||
pub icon: Option<String>,
|
||||
|
||||
/// Whether this channel is age-restricted
|
||||
pub nsfw: Option<bool>,
|
||||
|
||||
/// Whether this channel is archived
|
||||
pub archived: Option<bool>,
|
||||
|
||||
/// Fields to remove from channel
|
||||
#[cfg_attr(feature = "serde", serde(default))]
|
||||
pub remove: Option<Vec<FieldsChannel>>,
|
||||
}
|
||||
);
|
||||
@@ -1,11 +1,13 @@
|
||||
mod account_strikes;
|
||||
mod bots;
|
||||
mod channel_webhooks;
|
||||
mod channels;
|
||||
mod files;
|
||||
mod users;
|
||||
|
||||
pub use account_strikes::*;
|
||||
pub use bots::*;
|
||||
pub use channel_webhooks::*;
|
||||
pub use channels::*;
|
||||
pub use files::*;
|
||||
pub use users::*;
|
||||
|
||||
Reference in New Issue
Block a user