add: chat message reactions

This commit is contained in:
trisua 2025-06-21 03:11:29 -04:00
parent a4298f95f6
commit a37312fecf
20 changed files with 557 additions and 25 deletions

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
@ -79,6 +81,7 @@ pub struct Message {
pub edited: usize,
pub content: String,
pub context: MessageContext,
pub reactions: HashMap<String, usize>,
}
impl Message {
@ -93,6 +96,7 @@ impl Message {
edited: now,
content,
context: MessageContext,
reactions: HashMap::new(),
}
}
}
@ -105,3 +109,25 @@ impl Default for MessageContext {
Self
}
}
#[derive(Clone, Serialize, Deserialize)]
pub struct MessageReaction {
pub id: usize,
pub created: usize,
pub owner: usize,
pub message: usize,
pub emoji: String,
}
impl MessageReaction {
/// Create a new [`MessageReaction`].
pub fn new(owner: usize, message: usize, emoji: String) -> Self {
Self {
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
created: unix_epoch_timestamp(),
owner,
message,
emoji,
}
}
}