generated from t/malachite
add: model
This commit is contained in:
parent
f70b92c558
commit
d7ee379a9a
13 changed files with 394 additions and 219 deletions
74
src/model.rs
74
src/model.rs
|
@ -1 +1,73 @@
|
|||
//! Base types matching SQL table structures.
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GroupChatInfo {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum ChatStyle {
|
||||
/// Direct messages between two users.
|
||||
Direct,
|
||||
/// Messages between a group of users (up to 10).
|
||||
Group(GroupChatInfo),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Chat {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
pub style: ChatStyle,
|
||||
/// When the last member of the chat leaves, the chat will be deleted.
|
||||
pub members: Vec<usize>,
|
||||
pub last_message_created: usize,
|
||||
/// The IDs of each user in the chat who read the last message.
|
||||
///
|
||||
/// Will always have the ID of the user who sent the last message as index 0.
|
||||
///
|
||||
/// The UI should show two checkmarks once this vector has a length of at least 2.
|
||||
///
|
||||
/// Read receipts are stored by chat instead of message since it's easier to
|
||||
/// keep up with if we store by chat instead. This will also declutter
|
||||
/// the UI and prevent every message showing a read receipt.
|
||||
pub last_message_read_by: Vec<usize>,
|
||||
}
|
||||
|
||||
impl Chat {
|
||||
/// Create a new [`Chat`].
|
||||
pub fn new(style: ChatStyle, members: Vec<usize>) -> Self {
|
||||
Self {
|
||||
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
||||
created: unix_epoch_timestamp(),
|
||||
style,
|
||||
members,
|
||||
last_message_created: 0,
|
||||
last_message_read_by: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
pub owner: usize,
|
||||
pub chat: usize,
|
||||
pub content: String,
|
||||
pub uploads: Vec<usize>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
/// Create a new [`Message`].
|
||||
pub fn new(owner: usize, chat: usize, content: String, uploads: Vec<usize>) -> Self {
|
||||
Self {
|
||||
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
||||
created: unix_epoch_timestamp(),
|
||||
owner,
|
||||
chat,
|
||||
content,
|
||||
uploads,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue