From 47e8ba586cbc49cc235a0dd5407bd50eaac4432c Mon Sep 17 00:00:00 2001 From: Arkitu <85173315+Arkitu@users.noreply.github.com> Date: Wed, 20 Aug 2025 14:07:31 +0200 Subject: [PATCH] save --- src/apps/chat.html | 9 ++++++++- src/apps/chat.js | 4 +++- src/apps/chat.rs | 17 +++++------------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/apps/chat.html b/src/apps/chat.html index 8b3b616..f92c6e6 100644 --- a/src/apps/chat.html +++ b/src/apps/chat.html @@ -8,7 +8,14 @@
- +
diff --git a/src/apps/chat.js b/src/apps/chat.js index a52a188..24df1ab 100644 --- a/src/apps/chat.js +++ b/src/apps/chat.js @@ -41,5 +41,7 @@ ws.onmessage = (event) => { document.getElementById("send").onsubmit = (event) => { event.preventDefault(); // console.log(event, document.getElementById("sendcontent").value); - ws.send("send " + document.getElementById("sendcontent").value); + let content = document.getElementById("sendcontent"); + ws.send("send " + content.value); + content.value = ""; }; diff --git a/src/apps/chat.rs b/src/apps/chat.rs index c60008b..c39d9f8 100644 --- a/src/apps/chat.rs +++ b/src/apps/chat.rs @@ -13,21 +13,20 @@ use crate::{apps::App, socket::ws::WsMsg}; // Must be <= u8::MAX-1; pub const USERS_LEN: u8 = 4; -const MSG_MAX_SIZE: usize = 10; +const MSG_MAX_SIZE: usize = 500; #[derive(Debug, Serialize)] struct Msg<'a> { id: usize, author: u8, content: &'a str, } -// {"id"=999999,"author"="","content"=""} const MSGS_SIZE: usize = 30; #[derive(Debug)] struct Msgs { - /// Memory layout with sizes in bytes : ...|content: len|len: 2|author+1: 1|... - /// `author=0` means theres no message, it's just padding and should be skipped. - /// No message is splitted + /// * Memory layout with sizes in bytes : ...|content: len|len: 2|author+1: 1|... + /// * `author=0` means theres no message, it's just padding and should be skipped. + /// * No message is splitted inner: [u8; MSGS_SIZE], /// next byte index head: usize, @@ -53,7 +52,7 @@ impl Msgs { self.head += 3; self.next_msg += 1; } - // Iter messages from present to past + /// Iter messages from present to past fn iter(&self) -> MsgsIter { if self.head == 0 { MsgsIter { @@ -181,7 +180,6 @@ impl App for ChatApp { } fn accept_ws(&self, path: &str) -> bool { path == "/" - // path.len() > 1 && path.len() <= 17 } async fn handle_ws<'a, const BUF_SIZE: usize>( &'a mut self, @@ -237,11 +235,6 @@ impl App for ChatApp { } } -// #[derive(Deserialize)] -// enum ClientMsg { -// ReqMsg(usize), -// } - pub async fn id_to_static_str(id: u8) -> &'static str { match id { 0 => "0",