79 lines
2.1 KiB
Rust
79 lines
2.1 KiB
Rust
![]() |
use serde::{Serialize, Deserialize};
|
||
|
use tetratto_shared::{snow::AlmostSnowflake, unix_epoch_timestamp};
|
||
|
|
||
|
use super::communities_permissions::CommunityPermission;
|
||
|
|
||
|
/// A channel is a more "chat-like" feed in communities.
|
||
|
#[derive(Serialize, Deserialize)]
|
||
|
pub struct Channel {
|
||
|
pub id: usize,
|
||
|
pub community: usize,
|
||
|
pub owner: usize,
|
||
|
pub created: usize,
|
||
|
/// The minimum role (as bits) that can read this channel.
|
||
|
pub minimum_role_read: u32,
|
||
|
/// The minimum role (as bits) that can write to this channel.
|
||
|
pub minimum_role_write: u32,
|
||
|
/// The position of this channel in the UI.
|
||
|
///
|
||
|
/// Top (0) to bottom.
|
||
|
pub order: usize,
|
||
|
}
|
||
|
|
||
|
impl Channel {
|
||
|
/// Create a new [`Channel`].
|
||
|
pub fn new(community: usize, owner: usize, order: usize) -> Self {
|
||
|
Self {
|
||
|
id: AlmostSnowflake::new(1234567890)
|
||
|
.to_string()
|
||
|
.parse::<usize>()
|
||
|
.unwrap(),
|
||
|
community,
|
||
|
owner,
|
||
|
created: unix_epoch_timestamp() as usize,
|
||
|
minimum_role_read: (CommunityPermission::DEFAULT | CommunityPermission::MEMBER).bits(),
|
||
|
minimum_role_write: (CommunityPermission::DEFAULT | CommunityPermission::MEMBER).bits(),
|
||
|
order,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Serialize, Deserialize)]
|
||
|
pub struct Message {
|
||
|
pub id: usize,
|
||
|
pub channel: usize,
|
||
|
pub owner: usize,
|
||
|
pub created: usize,
|
||
|
pub edited: usize,
|
||
|
pub content: String,
|
||
|
pub context: MessageContext,
|
||
|
}
|
||
|
|
||
|
impl Message {
|
||
|
pub fn new(channel: usize, owner: usize, content: String) -> Self {
|
||
|
let now = unix_epoch_timestamp() as usize;
|
||
|
|
||
|
Self {
|
||
|
id: AlmostSnowflake::new(1234567890)
|
||
|
.to_string()
|
||
|
.parse::<usize>()
|
||
|
.unwrap(),
|
||
|
channel,
|
||
|
owner,
|
||
|
created: now,
|
||
|
edited: now,
|
||
|
content,
|
||
|
context: MessageContext::default(),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Serialize, Deserialize)]
|
||
|
pub struct MessageContext;
|
||
|
|
||
|
impl Default for MessageContext {
|
||
|
fn default() -> Self {
|
||
|
Self
|
||
|
}
|
||
|
}
|