Impl default for chatmessage object line

This commit is contained in:
Franklin 2023-02-09 12:57:36 -04:00
parent 875b60a608
commit 1ee28e57d4

View File

@ -9,13 +9,13 @@ use sqlx::{
/// The reasoning for this is that a chatroom can have many users
/// and the backend needs to be able to tell when each of them
/// has seen this message.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct TimeSensitiveAction {
pub time: DateTime<Utc>,
pub by: u32,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct TimeSensitiveActionVec {
pub list: Vec<TimeSensitiveAction>,
}
@ -52,7 +52,7 @@ impl TimeSensitiveAction {
}
/// Base message for chat rooms.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, FromRow)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, FromRow, Default)]
pub struct ChatMessage {
pub id: u32,
/// User id
@ -142,7 +142,7 @@ impl ChatSendable for ChatMessage {
}
/// This is what clients use to send messages (DTO)
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct ChatMessageSender {
pub message: ChatMessageContent,
pub to: u32,
@ -158,3 +158,14 @@ pub enum BroadcastMessage {
DeliveredUpdate(ChatMessage),
SeenUpdate(ChatMessage),
}
impl Default for BroadcastMessage {
fn default() -> Self {
Self::NewMessage(Default::default())
}
}
impl Default for ChatMessageContent {
fn default() -> Self {
Self::Text(Default::default())
}
}