Skip to content

Commit

Permalink
feat(core/models): implement server members model
Browse files Browse the repository at this point in the history
closes #280
  • Loading branch information
insertish committed Aug 1, 2023
1 parent fec947b commit d9dd040
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions crates/core/database/src/util/bridge/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,28 @@ impl From<crate::Metadata> for Metadata {
}
}

impl From<crate::Member> for Member {
fn from(value: crate::Member) -> Self {
Member {
id: value.id.into(),
joined_at: value.joined_at,
nickname: value.nickname,
avatar: value.avatar.map(|f| f.into()),
roles: value.roles,
timeout: value.timeout,
}
}
}

impl From<crate::MemberCompositeKey> for MemberCompositeKey {
fn from(value: crate::MemberCompositeKey) -> Self {
MemberCompositeKey {
server: value.server,
user: value.user,
}
}
}

impl From<crate::Server> for Server {
fn from(value: crate::Server) -> Self {
Server {
Expand Down
13 changes: 7 additions & 6 deletions crates/core/models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ name = "revolt-models"
version = "0.6.5"
edition = "2021"
license = "AGPL-3.0-or-later"
authors = [ "Paul Makles <[email protected]>" ]
authors = ["Paul Makles <[email protected]>"]
description = "Revolt Backend: API Models"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
serde = [ "dep:serde", "revolt-permissions/serde" ]
schemas = [ "dep:schemars", "revolt-permissions/schemas" ]
validator = [ "dep:validator" ]
partials = [ "dep:revolt_optional_struct", "serde", "schemas" ]
serde = ["dep:serde", "revolt-permissions/serde"]
schemas = ["dep:schemars", "revolt-permissions/schemas"]
validator = ["dep:validator"]
partials = ["dep:revolt_optional_struct", "serde", "schemas"]

default = [ "serde", "partials" ]
default = ["serde", "partials"]

[dependencies]
# Core
Expand All @@ -23,6 +23,7 @@ revolt-permissions = { version = "0.6.5", path = "../permissions" }
# Serialisation
revolt_optional_struct = { version = "0.2.0", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
iso8601-timestamp = { version = "0.2.11", features = ["schema", "bson"] }

# Spec Generation
schemars = { version = "0.8.8", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/core/models/src/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ mod bots;
mod channel_webhooks;
mod channels;
mod files;
mod server_members;
mod servers;
mod users;

pub use bots::*;
pub use channel_webhooks::*;
pub use channels::*;
pub use files::*;
pub use server_members::*;
pub use servers::*;
pub use users::*;
42 changes: 42 additions & 0 deletions crates/core/models/src/v0/server_members.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use super::File;

use iso8601_timestamp::Timestamp;

auto_derived!(
/// Server Member
pub struct Member {
/// Unique member id
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
pub id: MemberCompositeKey,

/// Time at which this user joined the server
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub joined_at: Option<Timestamp>,

/// Member's nickname
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub nickname: Option<String>,
/// Avatar attachment
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub avatar: Option<File>,

/// Member's roles
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "Vec::is_empty", default)
)]
pub roles: Vec<String>,
/// Timestamp this member is timed out until
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub timeout: Option<Timestamp>,
}

/// Composite primary key consisting of server and user id
#[derive(Hash, Default)]
pub struct MemberCompositeKey {
/// Server Id
pub server: String,
/// User Id
pub user: String,
}
);

0 comments on commit d9dd040

Please sign in to comment.