From 016940a45c836fdbe8f356f14a128254d9afc4ea Mon Sep 17 00:00:00 2001 From: 409 <409dev@protonmail.com> Date: Sat, 7 Jun 2025 14:11:33 +0200 Subject: [PATCH] add timestamp to `ChatMessage` struct --- Cargo.lock | 2 ++ Cargo.toml | 1 + src/message.rs | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b56e798..6118184 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -336,6 +336,7 @@ dependencies = [ "axum", "axum-valid", "axum_typed_multipart", + "chrono", "futures-util", "serde", "serde_json", @@ -353,6 +354,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-link", ] diff --git a/Cargo.toml b/Cargo.toml index 05f2535..a782790 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ axum-valid = { path = "../axum-valid", features = ["basic", "typed_multipart", " validify = "2.0.0" axum_typed_multipart = "0.16.2" serde_json = "1.0.140" +chrono = { version = "0.4.41", features = ["serde"] } diff --git a/src/message.rs b/src/message.rs index dc71ce7..09e5d14 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,3 +1,4 @@ +use chrono::{NaiveDateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -5,10 +6,15 @@ use serde::{Deserialize, Serialize}; pub struct ChatMessage { pub sender_id: u32, pub content: String, + pub timestamp: NaiveDateTime, } impl ChatMessage { pub fn new(sender_id: u32, content: String) -> Self { - Self { sender_id, content } + Self { + sender_id, + content, + timestamp: Utc::now().naive_utc(), + } } }