@@ -226,6 +226,67 @@ impl From<crate::Metadata> for Metadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<crate::Server> for Server {
|
||||||
|
fn from(value: crate::Server) -> Self {
|
||||||
|
Server {
|
||||||
|
id: value.id,
|
||||||
|
owner: value.owner,
|
||||||
|
name: value.name,
|
||||||
|
description: value.description,
|
||||||
|
channels: value.channels,
|
||||||
|
categories: value
|
||||||
|
.categories
|
||||||
|
.map(|categories| categories.into_iter().map(|v| v.into()).collect()),
|
||||||
|
system_messages: value.system_messages.map(|v| v.into()),
|
||||||
|
roles: value
|
||||||
|
.roles
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| (k, v.into()))
|
||||||
|
.collect(),
|
||||||
|
default_permissions: value.default_permissions,
|
||||||
|
icon: value.icon.map(|f| f.into()),
|
||||||
|
banner: value.banner.map(|f| f.into()),
|
||||||
|
flags: value.flags.unwrap_or_default() as u32,
|
||||||
|
nsfw: value.nsfw,
|
||||||
|
analytics: value.analytics,
|
||||||
|
discoverable: value.discoverable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::Category> for Category {
|
||||||
|
fn from(value: crate::Category) -> Self {
|
||||||
|
Category {
|
||||||
|
id: value.id,
|
||||||
|
title: value.title,
|
||||||
|
channels: value.channels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::SystemMessageChannels> for SystemMessageChannels {
|
||||||
|
fn from(value: crate::SystemMessageChannels) -> Self {
|
||||||
|
SystemMessageChannels {
|
||||||
|
user_joined: value.user_joined,
|
||||||
|
user_left: value.user_left,
|
||||||
|
user_kicked: value.user_kicked,
|
||||||
|
user_banned: value.user_banned,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::Role> for Role {
|
||||||
|
fn from(value: crate::Role) -> Self {
|
||||||
|
Role {
|
||||||
|
name: value.name,
|
||||||
|
permissions: value.permissions,
|
||||||
|
colour: value.colour,
|
||||||
|
hoist: value.hoist,
|
||||||
|
rank: value.rank,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl crate::User {
|
impl crate::User {
|
||||||
pub async fn into<P>(self, perspective: P) -> User
|
pub async fn into<P>(self, perspective: P) -> User
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ mod bots;
|
|||||||
mod channel_webhooks;
|
mod channel_webhooks;
|
||||||
mod channels;
|
mod channels;
|
||||||
mod files;
|
mod files;
|
||||||
|
mod servers;
|
||||||
mod users;
|
mod users;
|
||||||
|
|
||||||
pub use bots::*;
|
pub use bots::*;
|
||||||
pub use channel_webhooks::*;
|
pub use channel_webhooks::*;
|
||||||
pub use channels::*;
|
pub use channels::*;
|
||||||
pub use files::*;
|
pub use files::*;
|
||||||
|
pub use servers::*;
|
||||||
pub use users::*;
|
pub use users::*;
|
||||||
|
|||||||
124
crates/core/models/src/v0/servers.rs
Normal file
124
crates/core/models/src/v0/servers.rs
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
use super::File;
|
||||||
|
|
||||||
|
use revolt_permissions::OverrideField;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
auto_derived!(
|
||||||
|
/// Server
|
||||||
|
pub struct Server {
|
||||||
|
/// Unique Id
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||||
|
pub id: String,
|
||||||
|
/// User id of the owner
|
||||||
|
pub owner: String,
|
||||||
|
|
||||||
|
/// Name of the server
|
||||||
|
pub name: String,
|
||||||
|
/// Description for the server
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub description: Option<String>,
|
||||||
|
|
||||||
|
/// Channels within this server
|
||||||
|
// ! FIXME: this may be redundant
|
||||||
|
pub channels: Vec<String>,
|
||||||
|
/// Categories for this server
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub categories: Option<Vec<Category>>,
|
||||||
|
/// Configuration for sending system event messages
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub system_messages: Option<SystemMessageChannels>,
|
||||||
|
|
||||||
|
/// Roles for this server
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(
|
||||||
|
default = "HashMap::<String, Role>::new",
|
||||||
|
skip_serializing_if = "HashMap::<String, Role>::is_empty"
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub roles: HashMap<String, Role>,
|
||||||
|
/// Default set of server and channel permissions
|
||||||
|
pub default_permissions: i64,
|
||||||
|
|
||||||
|
/// Icon attachment
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub icon: Option<File>,
|
||||||
|
/// Banner attachment
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub banner: Option<File>,
|
||||||
|
|
||||||
|
/// Bitfield of server flags
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_zero_u32", default)
|
||||||
|
)]
|
||||||
|
pub flags: u32,
|
||||||
|
|
||||||
|
/// Whether this server is flagged as not safe for work
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_false", default)
|
||||||
|
)]
|
||||||
|
pub nsfw: bool,
|
||||||
|
/// Whether to enable analytics
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_false", default)
|
||||||
|
)]
|
||||||
|
pub analytics: bool,
|
||||||
|
/// Whether this server should be publicly discoverable
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_false", default)
|
||||||
|
)]
|
||||||
|
pub discoverable: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Channel category
|
||||||
|
pub struct Category {
|
||||||
|
/// Unique ID for this category
|
||||||
|
pub id: String,
|
||||||
|
/// Title for this category
|
||||||
|
pub title: String,
|
||||||
|
/// Channels in this category
|
||||||
|
pub channels: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Role
|
||||||
|
pub struct Role {
|
||||||
|
/// Role name
|
||||||
|
pub name: String,
|
||||||
|
/// Permissions available to this role
|
||||||
|
pub permissions: OverrideField,
|
||||||
|
/// Colour used for this role
|
||||||
|
///
|
||||||
|
/// This can be any valid CSS colour
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub colour: Option<String>,
|
||||||
|
/// Whether this role should be shown separately on the member sidebar
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_false", default)
|
||||||
|
)]
|
||||||
|
pub hoist: bool,
|
||||||
|
/// Ranking of this role
|
||||||
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
|
pub rank: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// System message channel assignments
|
||||||
|
pub struct SystemMessageChannels {
|
||||||
|
/// ID of channel to send user join messages in
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub user_joined: Option<String>,
|
||||||
|
/// ID of channel to send user left messages in
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub user_left: Option<String>,
|
||||||
|
/// ID of channel to send user kicked messages in
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub user_kicked: Option<String>,
|
||||||
|
/// ID of channel to send user banned messages in
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub user_banned: Option<String>,
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -4,40 +4,52 @@ auto_derived!(
|
|||||||
/// User
|
/// User
|
||||||
pub struct User {
|
pub struct User {
|
||||||
/// Unique Id
|
/// Unique Id
|
||||||
#[serde(rename = "_id")]
|
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||||
pub id: String,
|
pub id: String,
|
||||||
/// Username
|
/// Username
|
||||||
pub username: String,
|
pub username: String,
|
||||||
/// Discriminator
|
/// Discriminator
|
||||||
pub discriminator: String,
|
pub discriminator: String,
|
||||||
/// Display name
|
/// Display name
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub display_name: Option<String>,
|
pub display_name: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
/// Avatar attachment
|
/// Avatar attachment
|
||||||
pub avatar: Option<File>,
|
pub avatar: Option<File>,
|
||||||
/// Relationships with other users
|
/// Relationships with other users
|
||||||
#[serde(skip_serializing_if = "Vec::is_empty", default)]
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "Vec::is_empty", default)
|
||||||
|
)]
|
||||||
pub relations: Vec<Relationship>,
|
pub relations: Vec<Relationship>,
|
||||||
|
|
||||||
/// Bitfield of user badges
|
/// Bitfield of user badges
|
||||||
#[serde(skip_serializing_if = "crate::if_zero_u32", default)]
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_zero_u32", default)
|
||||||
|
)]
|
||||||
pub badges: u32,
|
pub badges: u32,
|
||||||
/// User's current status
|
/// User's current status
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub status: Option<UserStatus>,
|
pub status: Option<UserStatus>,
|
||||||
/// User's profile page
|
/// User's profile page
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub profile: Option<UserProfile>,
|
pub profile: Option<UserProfile>,
|
||||||
|
|
||||||
/// Enum of user flags
|
/// Enum of user flags
|
||||||
#[serde(skip_serializing_if = "crate::if_zero_u32", default)]
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_zero_u32", default)
|
||||||
|
)]
|
||||||
pub flags: u32,
|
pub flags: u32,
|
||||||
/// Whether this user is privileged
|
/// Whether this user is privileged
|
||||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
#[cfg_attr(
|
||||||
|
feature = "serde",
|
||||||
|
serde(skip_serializing_if = "crate::if_false", default)
|
||||||
|
)]
|
||||||
pub privileged: bool,
|
pub privileged: bool,
|
||||||
/// Bot information
|
/// Bot information
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub bot: Option<BotInformation>,
|
pub bot: Option<BotInformation>,
|
||||||
|
|
||||||
/// Current session user's relationship with this user
|
/// Current session user's relationship with this user
|
||||||
@@ -49,20 +61,29 @@ auto_derived!(
|
|||||||
/// User's relationship with another user (or themselves)
|
/// User's relationship with another user (or themselves)
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum RelationshipStatus {
|
pub enum RelationshipStatus {
|
||||||
|
/// No relationship with other user
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
|
/// Other user is us
|
||||||
User,
|
User,
|
||||||
|
/// Friends with the other user
|
||||||
Friend,
|
Friend,
|
||||||
|
/// Pending friend request to user
|
||||||
Outgoing,
|
Outgoing,
|
||||||
|
/// Incoming friend request from user
|
||||||
Incoming,
|
Incoming,
|
||||||
|
/// Blocked this user
|
||||||
Blocked,
|
Blocked,
|
||||||
|
/// Blocked by this user
|
||||||
BlockedOther,
|
BlockedOther,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Relationship entry indicating current status with other user
|
/// Relationship entry indicating current status with other user
|
||||||
pub struct Relationship {
|
pub struct Relationship {
|
||||||
#[serde(rename = "_id")]
|
/// Other user's Id
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
|
/// Relationship status with them
|
||||||
pub status: RelationshipStatus,
|
pub status: RelationshipStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,20 +104,20 @@ auto_derived!(
|
|||||||
/// User's active status
|
/// User's active status
|
||||||
pub struct UserStatus {
|
pub struct UserStatus {
|
||||||
/// Custom status text
|
/// Custom status text
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "String::is_empty"))]
|
||||||
pub text: String,
|
pub text: String,
|
||||||
/// Current presence option
|
/// Current presence option
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub presence: Option<Presence>,
|
pub presence: Option<Presence>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// User's profile
|
/// User's profile
|
||||||
pub struct UserProfile {
|
pub struct UserProfile {
|
||||||
/// Text content on user's profile
|
/// Text content on user's profile
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "String::is_empty"))]
|
||||||
pub content: String,
|
pub content: String,
|
||||||
/// Background visible on user's profile
|
/// Background visible on user's profile
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub background: Option<File>,
|
pub background: Option<File>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +164,7 @@ auto_derived!(
|
|||||||
/// Bot information for if the user is a bot
|
/// Bot information for if the user is a bot
|
||||||
pub struct BotInformation {
|
pub struct BotInformation {
|
||||||
/// Id of the owner of this bot
|
/// Id of the owner of this bot
|
||||||
#[serde(rename = "owner")]
|
#[cfg_attr(feature = "serde", serde(rename = "owner"))]
|
||||||
pub owner_id: String,
|
pub owner_id: String,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user