diff --git a/src/app.rs b/src/app.rs index 3c24393..9d58811 100644 --- a/src/app.rs +++ b/src/app.rs @@ -25,6 +25,16 @@ pub enum Command { markdown: String, channels: Vec, }, + SetMute { + mute: bool, + }, + SetDeaf { + deaf: bool, + }, + EnterChannel { + channel: ChannelId, + user: UserId, + }, Disconnect, } @@ -43,6 +53,10 @@ pub struct ChannelState { pub struct UserState { pub name: String, pub channel: ChannelId, + pub deaf: bool, + pub mute: bool, + pub self_deaf: bool, + pub self_mute: bool, } pub struct Chat { @@ -105,7 +119,9 @@ pub fn User(id: UserId) -> Element { #[component] pub fn Channel(id: ChannelId) -> Element { + let net: Coroutine = use_coroutine_handle(); let server = STATE.server.read(); + let user = server.session?; let state = server.channels.get(&id)?; let channel_details = css!( @@ -129,7 +145,10 @@ pub fn Channel(id: ChannelId) -> Element { details { class: "{channel_details}", open: true, - summary { "{state.name}" } + summary { + ondoubleclick: move |_| net.send(EnterChannel { channel: id, user }), + "{state.name}" + } div { class: "{channel_children}", for id in state.users.iter() { @@ -229,6 +248,13 @@ pub fn ChatView() -> Element { pub fn ServerView() -> Element { let net: Coroutine = use_coroutine_handle(); let server = STATE.server.read(); + let &UserState { + deaf, + self_deaf, + mute, + self_mute, + .. + } = server.this_user()?; let grid = css!( r#" @@ -280,6 +306,11 @@ pub fn ServerView() -> Element { border: solid black 1px; grid-area: bar; + display: flex; + flex-direction: row; + gap: 16px; + align-items: center; + button { padding: 8px; } @@ -295,7 +326,32 @@ pub fn ServerView() -> Element { onclick: move |_| net.send(Disconnect), "Disconnect" } - + span { + input { + r#type: "checkbox", + id: "mute", + checked: mute || self_mute, + disabled: mute, + onchange: move |_| net.send(SetMute { mute: !self_mute }), + } + label { + r#for: "mute", + "Mute" + } + } + span { + input { + r#type: "checkbox", + id: "deaf", + checked: deaf || self_deaf, + disabled: deaf, + onchange: move |_| net.send(SetDeaf { deaf: !self_deaf }), + } + label { + r#for: "deaf", + "Deafen" + } + } } div { class: "{channel_box}", diff --git a/src/imp/desktop.rs b/src/imp/desktop.rs index a78dcbe..ea5e5da 100644 --- a/src/imp/desktop.rs +++ b/src/imp/desktop.rs @@ -67,12 +67,12 @@ pub struct AudioSystem(); impl AudioSystem { pub fn new(sender: UnboundedSender>) -> Result { - dbg!("todo"); + // dbg!("todo"); Ok(AudioSystem()) } pub fn create_player(&mut self) -> Result { - dbg!("todo"); + // dbg!("todo"); Ok(AudioPlayer()) } } @@ -81,7 +81,7 @@ pub struct AudioPlayer(); impl AudioPlayer { pub fn play_opus(&mut self, payload: &[u8]) { - dbg!("todo"); + // dbg!("todo"); } } diff --git a/src/lib.rs b/src/lib.rs index 55abbf4..2ba9d86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -164,8 +164,13 @@ fn accept_command( command: Command, send_chan: &mut UnboundedSender>, ) -> Result<(), Error> { + use Command::*; + let Some(session) = STATE.server.read().session else { + bail!("no session id") + }; + match command { - Command::SendChat { markdown, channels } => { + SendChat { markdown, channels } => { use markdown::*; let blocks = tokenize(&markdown); let html_text = match blocks.as_slice() { @@ -199,7 +204,25 @@ fn accept_command( u.set_channel_id(channels); let _ = send_chan.unbounded_send(u.into()); } - _ => (), + SetMute { mute } => { + let mut u = msgs::UserState::new(); + u.set_session(session); + u.set_self_mute(mute); + let _ = send_chan.unbounded_send(u.into()); + } + SetDeaf { deaf } => { + let mut u = msgs::UserState::new(); + u.set_session(session); + u.set_self_deaf(deaf); + let _ = send_chan.unbounded_send(u.into()); + } + EnterChannel { channel, user } => { + let mut u = msgs::UserState::new(); + u.set_session(user); + u.set_channel_id(channel); + let _ = send_chan.unbounded_send(u.into()); + } + Connect { .. } | Disconnect => (), } Ok(()) @@ -306,6 +329,18 @@ fn accept_packet( if u.has_name() { state.name = u.get_name().to_string(); } + if u.has_mute() { + state.mute = u.get_mute(); + } + if u.has_deaf() { + state.deaf = u.get_deaf(); + } + if u.has_self_mute() { + state.self_mute = u.get_self_mute(); + } + if u.has_self_deaf() { + state.self_deaf = u.get_self_deaf(); + } } ControlPacket::UserRemove(u) => { let mut server = STATE.server.write();