multiple chat clients + handle showing long discussion to new client
This commit is contained in:
parent
f523ec812c
commit
4521697f48
@ -149,9 +149,6 @@ impl App for ChatApp {
|
|||||||
if msg_id > msgs.next {
|
if msg_id > msgs.next {
|
||||||
return (HttpResCode::BadRequest, "", &[]);
|
return (HttpResCode::BadRequest, "", &[]);
|
||||||
}
|
}
|
||||||
if msg_id < msgs.next.saturating_sub(MEMORY_SIZE as u16 + 1) {
|
|
||||||
return (HttpResCode::NoContent, "", &[]);
|
|
||||||
}
|
|
||||||
self.res_buf.clear();
|
self.res_buf.clear();
|
||||||
unwrap(write!(&mut self.res_buf, "<div class=\"message\"")).await;
|
unwrap(write!(&mut self.res_buf, "<div class=\"message\"")).await;
|
||||||
if msg_id == msgs.next {
|
if msg_id == msgs.next {
|
||||||
@ -171,7 +168,6 @@ impl App for ChatApp {
|
|||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
if let Some(n) = load {
|
if let Some(n) = load {
|
||||||
info!("test2");
|
|
||||||
unwrap(write!(
|
unwrap(write!(
|
||||||
&mut self.res_buf,
|
&mut self.res_buf,
|
||||||
" hx-get=\"/chat/message/{}?load={}\" \
|
" hx-get=\"/chat/message/{}?load={}\" \
|
||||||
@ -183,17 +179,37 @@ impl App for ChatApp {
|
|||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
info!("test3");
|
match msgs.get_abs(msg_id) {
|
||||||
let msg = match msgs.get_abs(msg_id) {
|
Some(msg) => {
|
||||||
Some(msg) => msg,
|
unwrap(write!(
|
||||||
None => return (HttpResCode::NoContent, "", &[]),
|
&mut self.res_buf,
|
||||||
|
"><b>{}</b>: {}</div>",
|
||||||
|
msg.author, msg.content
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
if load.is_some() {
|
||||||
|
if (msg_id as isize)
|
||||||
|
== (msgs.next as isize - MEMORY_SIZE as isize - 1)
|
||||||
|
{
|
||||||
|
unwrap(write!(
|
||||||
|
&mut self.res_buf,
|
||||||
|
"><em>Older messages forgotten</em></div>"
|
||||||
|
))
|
||||||
|
.await;
|
||||||
|
} else {
|
||||||
|
unwrap(write!(
|
||||||
|
&mut self.res_buf,
|
||||||
|
" style=\"display: none;\"></div>"
|
||||||
|
))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return (HttpResCode::NoContent, "", &[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
unwrap(write!(
|
|
||||||
&mut self.res_buf,
|
|
||||||
"><b>{}</b>: {}</div>",
|
|
||||||
msg.author, msg.content
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (HttpResCode::Ok, "html", &self.res_buf);
|
return (HttpResCode::Ok, "html", &self.res_buf);
|
||||||
@ -222,6 +238,9 @@ impl Messages {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn get_abs(&self, id: u16) -> Option<&Message> {
|
fn get_abs(&self, id: u16) -> Option<&Message> {
|
||||||
|
if (id as isize) < (self.next as isize - MEMORY_SIZE as isize) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
self.inner.get_signed((id as isize) - (self.next as isize))
|
self.inner.get_signed((id as isize) - (self.next as isize))
|
||||||
}
|
}
|
||||||
fn push(&mut self, msg: Message) {
|
fn push(&mut self, msg: Message) {
|
||||||
|
@ -172,7 +172,9 @@ async fn main(spawner: Spawner) {
|
|||||||
unwrap(spawner.spawn(socket::index_listen_task(stack, 80))).await;
|
unwrap(spawner.spawn(socket::index_listen_task(stack, 80))).await;
|
||||||
unwrap(spawner.spawn(socket::ttt_listen_task(stack, apps::ttt::Team::Zero, 8080))).await;
|
unwrap(spawner.spawn(socket::ttt_listen_task(stack, apps::ttt::Team::Zero, 8080))).await;
|
||||||
unwrap(spawner.spawn(socket::ttt_listen_task(stack, apps::ttt::Team::One, 8081))).await;
|
unwrap(spawner.spawn(socket::ttt_listen_task(stack, apps::ttt::Team::One, 8081))).await;
|
||||||
unwrap(spawner.spawn(socket::chat_listen_task(stack, 8082))).await;
|
for _ in 0..2 {
|
||||||
|
unwrap(spawner.spawn(socket::chat_listen_task(stack, 8082))).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wifi-connect")]
|
#[cfg(feature = "wifi-connect")]
|
||||||
|
@ -18,7 +18,7 @@ pub async fn index_listen_task(stack: embassy_net::Stack<'static>, port: u16) {
|
|||||||
listen_task(stack, IndexApp, port).await
|
listen_task(stack, IndexApp, port).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task(pool_size = 1)]
|
#[embassy_executor::task(pool_size = 2)]
|
||||||
pub async fn chat_listen_task(stack: embassy_net::Stack<'static>, port: u16) {
|
pub async fn chat_listen_task(stack: embassy_net::Stack<'static>, port: u16) {
|
||||||
listen_task(stack, chat::ChatApp::new(), port).await
|
listen_task(stack, chat::ChatApp::new(), port).await
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user