From 12db4fbc2b5fc8387d2532201f1a20b141ed9a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 16 Jul 2026 06:19:01 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(client):=20add=20network=20act?= =?UTF-8?q?or=20and=20auth=20gui=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/client_config.toml | 3 + crates/client/src/gui.rs | 63 +++++++- crates/client/src/gui/chat.rs | 8 +- crates/client/src/gui/login.rs | 40 ++++-- crates/client/src/gui/register.rs | 96 +++++++++++++ crates/client/src/lib.rs | 30 ++++ crates/client/src/main.rs | 9 +- crates/client/src/network.rs | 228 +++++++++++++++++++++++++++++ crates/client/src/request.rs | 229 ++++++++++++++++++++++++++++++ 9 files changed, 681 insertions(+), 25 deletions(-) create mode 100644 configs/client_config.toml create mode 100644 crates/client/src/gui/register.rs create mode 100644 crates/client/src/network.rs create mode 100644 crates/client/src/request.rs diff --git a/configs/client_config.toml b/configs/client_config.toml new file mode 100644 index 0000000..d379fba --- /dev/null +++ b/configs/client_config.toml @@ -0,0 +1,3 @@ +[client_config] +server_address = "127.0.0.1:2026" +server_name = "localhost" diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 8eb5d51..0d50676 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -1,31 +1,76 @@ +use common::user::User; use gpui::{IntoElement, ParentElement, Render, Styled, div, rgb}; use gpui_component::Root; +use tokio::sync::mpsc; -use crate::gui::{chat::Chat, login::Login}; +use crate::{ + gui::{chat::Chat, login::Login, register::Register}, + network::{NetworkEvent, NetworkHandle}, +}; mod chat; mod login; +mod register; #[derive(Debug, PartialEq, Eq)] enum Route { + Register, Login, Chat, } pub struct Yumush { + user: Option, current_route: Route, + register: Register, login: Login, chat: Chat, + network: NetworkHandle, + connected: bool, } impl Yumush { - pub fn new(window: &mut gpui::Window, cx: &mut gpui::Context) -> Self { + pub fn new( + network: NetworkHandle, + mut network_event_receiver: mpsc::Receiver, + window: &mut gpui::Window, + cx: &mut gpui::Context, + ) -> Self { + cx.spawn(async move |this, cx| { + while let Some(event) = network_event_receiver.recv().await { + let updated = this.update(cx, |yumush, cx| { + yumush.handle_network_event(event, cx); + }); + + if updated.is_err() { + break; + } + } + }) + .detach(); + Self { + user: None, current_route: Route::Login, + register: Register::new(window, cx), login: Login::new(window, cx), chat: Chat::new(window, cx), + network, + connected: false, } } + fn set_user(&mut self, user: User) { + self.user = Some(user); + } + + fn reset_user(&mut self) { + self.user = None; + } + + fn get_username(&self) -> Option<&str> { + self.user.as_ref().map(|user| user.get_username()) + } + fn change_page( &mut self, new_route: Route, @@ -35,10 +80,23 @@ impl Yumush { self.current_route = new_route; match self.current_route { + Route::Register => self.register.focus(window, cx), Route::Login => self.login.focus(window, cx), Route::Chat => self.chat.focus(window, cx), } } + + fn handle_network_event(&mut self, event: NetworkEvent, cx: &mut gpui::Context) { + match event { + NetworkEvent::Connected => self.connected = true, + NetworkEvent::ConnectionFailed(_) | NetworkEvent::Disconnected(_) => { + self.connected = false; + self.reset_user(); + } + } + + cx.notify(); + } } impl Render for Yumush { @@ -60,6 +118,7 @@ impl Render for Yumush { .bg(rgb(0x1e1e1e)) .text_color(rgb(0xffffff)) .child(match self.current_route { + Route::Register => self.register_page(cx).into_any_element(), Route::Login => self.login_page(cx).into_any_element(), Route::Chat => self.chat_page().into_any_element(), }), diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 387482b..7609fff 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -3,11 +3,7 @@ use gpui::{ AppContext, Context, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement, Styled, Window, div, rgb, }; -use gpui_component::{ - WindowExt, - input::{Input, InputEvent, InputState}, - notification::Notification, -}; +use gpui_component::input::{Input, InputEvent, InputState}; use crate::gui::Yumush; @@ -35,7 +31,7 @@ impl Chat { let message = Message::new( "1", this.chat.community.get_community_id(), - this.login.get_user().unwrap().get_username(), + this.get_username().unwrap(), &input.read(cx).text().to_string(), ); diff --git a/crates/client/src/gui/login.rs b/crates/client/src/gui/login.rs index 211ecea..38ab057 100644 --- a/crates/client/src/gui/login.rs +++ b/crates/client/src/gui/login.rs @@ -1,4 +1,3 @@ -use common::user::User; use gpui::{AppContext, Context, Entity, IntoElement, ParentElement, Styled, Window, div}; use gpui_component::{ WindowExt, @@ -11,7 +10,6 @@ use crate::gui::{Route, Yumush}; pub struct Login { username_input: Entity, - user: Option, } impl Login { @@ -31,14 +29,7 @@ impl Login { }) .detach(); - Self { - username_input, - user: None, - } - } - - pub fn get_user(&self) -> Option { - self.user.clone() + Self { username_input } } pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Yumush>) { @@ -54,12 +45,23 @@ fn login_action( window: &mut Window, cx: &mut Context<'_, Yumush>, ) { - let id = "A".to_string(); let username = input.read(cx).text().to_string(); + let network = this.network.clone(); + + cx.spawn_in(window, async move |this, cx| { + let result = network.authenticate(&username).await; - let user = User::new(&id, &username); - this.login.user = Some(user); - this.change_page(Route::Chat, window, cx); + let _ = this.update_in(cx, |yumush, window, cx| match result { + Ok(user) => { + yumush.set_user(user); + yumush.change_page(Route::Chat, window, cx); + } + Err(error_value) => { + window.push_notification(Notification::error(error_value.to_string()), cx); + } + }); + }) + .detach(); } impl Yumush { @@ -74,11 +76,21 @@ impl Yumush { }) .label("Login"); + let entity = cx.entity(); + let register_page_switch_button = Button::new("register_page_switch_button") + .on_click(move |_, window, cx| { + entity.update(cx, |this, cx| { + this.change_page(Route::Register, window, cx); + }) + }) + .label("Go to Register Page"); + div() .w_1_5() .child("Username") .child(Input::new(&self.login.username_input)) .child(login_button) + .child(register_page_switch_button) .into_element() } } diff --git a/crates/client/src/gui/register.rs b/crates/client/src/gui/register.rs new file mode 100644 index 0000000..05a75bb --- /dev/null +++ b/crates/client/src/gui/register.rs @@ -0,0 +1,96 @@ +use gpui::{AppContext, Context, Entity, IntoElement, ParentElement, Styled, Window, div}; +use gpui_component::{ + WindowExt, + button::Button, + input::{Input, InputEvent, InputState}, + notification::Notification, +}; + +use crate::gui::{Route, Yumush}; + +pub struct Register { + username_input: Entity, +} + +impl Register { + pub fn new(window: &mut Window, cx: &mut Context) -> Self { + let username_input = cx.new(|cx| { + let mut input_state = InputState::new(window, cx); + input_state.set_placeholder("Username...", window, cx); + input_state.focus(window, cx); + + input_state + }); + + cx.subscribe_in(&username_input, window, |this, input, event, window, cx| { + if matches!(event, InputEvent::PressEnter { .. }) { + register_action(this, input, window, cx); + } + }) + .detach(); + + Self { username_input } + } + + pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Yumush>) { + self.username_input.update(cx, |input, cx| { + input.focus(window, cx); + }); + } +} + +fn register_action( + this: &mut Yumush, + input: &Entity, + window: &mut Window, + cx: &mut Context<'_, Yumush>, +) { + let username = input.read(cx).text().to_string(); + let network = this.network.clone(); + + cx.spawn_in(window, async move |this, cx| { + let result = network.create_user(&username).await; + + let _ = this.update_in(cx, |yumush, window, cx| match result { + Ok(user) => { + yumush.set_user(user); + yumush.change_page(Route::Chat, window, cx); + } + Err(error_value) => { + window.push_notification(Notification::error(error_value.to_string()), cx); + } + }); + }) + .detach(); +} + +impl Yumush { + pub fn register_page(&mut self, cx: &mut Context) -> impl IntoElement { + let entity = cx.entity(); + let username_input = self.register.username_input.clone(); + let register_button = Button::new("register_button") + .on_click(move |_, window, cx| { + entity.update(cx, |this, cx| { + register_action(this, &username_input, window, cx); + }) + }) + .label("Register"); + + let entity = cx.entity(); + let login_page_switch_button = Button::new("login_page_switch_button") + .on_click(move |_, window, cx| { + entity.update(cx, |this, cx| { + this.change_page(Route::Login, window, cx); + }) + }) + .label("Go to Login Page"); + + div() + .w_1_5() + .child("Username") + .child(Input::new(&self.register.username_input)) + .child(register_button) + .child(login_page_switch_button) + .into_element() + } +} diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 14c39ab..137c433 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -1 +1,31 @@ +use common::utils::TOML; + pub mod gui; +pub mod network; +mod request; + +pub const NAME: &str = "Yumush"; + +const CLIENT_CONFIG_FILE_CONTENT: &str = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../configs/client_config.toml" +)); + +pub struct ClientConfig { + server_address: String, + server_name: String, +} + +impl Default for ClientConfig { + fn default() -> Self { + let toml = TOML::naive_toml_parser_from_content(CLIENT_CONFIG_FILE_CONTENT).unwrap(); + + let server_address = toml.fields.get("server_address").unwrap().to_owned(); + let server_name = toml.fields.get("server_name").unwrap().to_owned(); + + Self { + server_address, + server_name, + } + } +} diff --git a/crates/client/src/main.rs b/crates/client/src/main.rs index b8ae5df..dd790e9 100644 --- a/crates/client/src/main.rs +++ b/crates/client/src/main.rs @@ -1,4 +1,4 @@ -use client::gui::Yumush; +use client::{ClientConfig, NAME, gui::Yumush, network}; use gpui::{ App, AppContext, Application, Bounds, TitlebarOptions, WindowBounds, WindowOptions, px, size, }; @@ -7,13 +7,15 @@ use gpui_component::Root; fn main() { println!("Hello, world!"); + let (network_handle, network_event_receiver) = network::start(ClientConfig::default()); + Application::new().run(|cx: &mut App| { gpui_component::init(cx); let window_bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx); let titlebar = TitlebarOptions { - title: Some("Nefes".into()), + title: Some(NAME.into()), ..Default::default() }; @@ -24,7 +26,8 @@ fn main() { ..Default::default() }, |window, cx| { - let view = cx.new(|cx| Yumush::new(window, cx)); + let view = + cx.new(|cx| Yumush::new(network_handle, network_event_receiver, window, cx)); cx.new(|cx| Root::new(view, window, cx)) }, ) diff --git a/crates/client/src/network.rs b/crates/client/src/network.rs new file mode 100644 index 0000000..f8d3dc2 --- /dev/null +++ b/crates/client/src/network.rs @@ -0,0 +1,228 @@ +use std::sync::Arc; + +use common::error::Error; +use quinn::{ + Endpoint, + crypto::rustls::QuicClientConfig, + rustls::{ + self, + client::danger::{ServerCertVerified, ServerCertVerifier}, + }, +}; + +use crate::{ClientConfig, request::ClientRequest}; + +pub async fn connect(server_address: &str, server_name: &str) -> Result { + let mut endpoint = Endpoint::client("0.0.0.0:0".parse()?)?; + endpoint.set_default_client_config(config()); + + let connection = endpoint + .connect(server_address.parse().unwrap(), server_name)? + .await?; + + Ok(ClientRequest::new(connection)) +} + +fn config() -> quinn::ClientConfig { + let crypto_provider = Arc::new(rustls::crypto::ring::default_provider()); + let tls_config = rustls::ClientConfig::builder_with_provider(crypto_provider.clone()) + .with_protocol_versions(&[&rustls::version::TLS13]) + .unwrap() + .dangerous() + .with_custom_certificate_verifier(Arc::new(AcceptAnyCertificate(crypto_provider))) + .with_no_client_auth(); + + quinn::ClientConfig::new(Arc::new(QuicClientConfig::try_from(tls_config).unwrap())) +} + +use std::time::Duration; + +use common::{community::Community, error::network, message::Message, user::User}; +use tokio::sync::{mpsc, oneshot}; + +const CHANNEL_SIZE: usize = 32; +const RECONNECT_DELAY: Duration = Duration::from_secs(3); + +macro_rules! network_commands { + ($($variant:ident => $method:ident($($arg:ident), *) -> $ret:ty),* $(,)?) => { + #[derive(Debug)] + pub enum NetworkCommand { + $($variant{ + $($arg: String, )* + reply: oneshot::Sender>, + },)* + } + + impl NetworkHandle { + $(pub async fn $method(&self, $($arg: &str),*) -> Result<$ret, Error> { + let (reply, response) = oneshot::channel(); + let command = NetworkCommand::$variant { + $($arg: $arg.to_string(),)* + reply, + }; + + self.command_sender.send(command).await.map_err(|_| network::Error::ChannelClosed)?; + + response.await.map_err(|_| network::Error::ChannelClosed)? + })* + } + + async fn dispatch(client_request: ClientRequest, command: NetworkCommand) { + match command { + $(NetworkCommand::$variant { $($arg,)* reply} => { + let _ = reply.send(client_request.$method($(&$arg),*).await); + })* + } + } + }; +} + +network_commands! { + Authenticate => authenticate(authentication_token) -> User, + Deauthenticate => deauthenticate(authentication_token) -> User, + CreateUser => create_user(username) -> User, + ReadUser => read_user(user_id) -> User, + UpdateUser => update_user(user_id, username) -> User, + DeleteUser => delete_user(user_id) -> User, + CreateCommunity => create_community(community_name) -> Community, + ReadCommunity => read_community(community_id) -> Community, + UpdateCommunity => update_community(community_id, community_name) -> Community, + DeleteCommunity => delete_community(community_id) -> Community, + CreateMessage => create_message(user_id, community_id, message_body) -> Message, + ReadMessage => read_message(message_id) -> Message, + UpdateMessage => update_message(message_id, message_body) -> Message, + DeleteMessage => delete_message(message_id) -> Message, + JoinCommunity => join_community(user_id, community_id) -> (), + LeaveCommunity => leave_community(user_id, community_id) -> () +} + +#[derive(Debug)] +pub enum NetworkEvent { + Connected, + ConnectionFailed(Error), + Disconnected(Error), +} + +#[derive(Debug, Clone)] +pub struct NetworkHandle { + command_sender: mpsc::Sender, +} + +impl NetworkHandle { + fn new(command_sender: mpsc::Sender) -> Self { + Self { command_sender } + } +} + +pub fn start(client_config: ClientConfig) -> (NetworkHandle, mpsc::Receiver) { + let (command_sender, command_receiver) = mpsc::channel(CHANNEL_SIZE); + let (event_sender, event_receiver) = mpsc::channel(CHANNEL_SIZE); + + std::thread::Builder::new() + .name("network".to_string()) + .spawn(move || { + tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("network runtime") + .block_on(actor(client_config, command_receiver, event_sender)); + }) + .expect("network thread"); + + (NetworkHandle::new(command_sender), event_receiver) +} + +async fn actor( + client_config: ClientConfig, + mut command_receiver: mpsc::Receiver, + event_sender: mpsc::Sender, +) { + 'session: loop { + let client_request = loop { + match connect(&client_config.server_address, &client_config.server_name).await { + Ok(client_request) => break client_request, + Err(error_value) => { + if event_sender + .send(NetworkEvent::ConnectionFailed(error_value)) + .await + .is_err() + { + return; + } + + tokio::time::sleep(RECONNECT_DELAY).await; + } + }; + }; + + if event_sender.send(NetworkEvent::Connected).await.is_err() { + return; + } + + loop { + tokio::select! { + command = command_receiver.recv() => match command { + Some(command) => { + tokio::spawn(dispatch(client_request.clone(), command)); + } + None => break 'session, + }, + error_value = client_request.closed() => { + if event_sender.send(NetworkEvent::Disconnected(error_value.into())).await.is_err() { + return ; + } + + break; + } + } + } + } +} + +#[derive(Debug)] +struct AcceptAnyCertificate(Arc); + +impl ServerCertVerifier for AcceptAnyCertificate { + fn verify_server_cert( + &self, + _end_entity: &rustls::pki_types::CertificateDer<'_>, + _intermediates: &[rustls::pki_types::CertificateDer<'_>], + _server_name: &rustls::pki_types::ServerName<'_>, + _ocsp_response: &[u8], + _now: rustls::pki_types::UnixTime, + ) -> Result { + Ok(ServerCertVerified::assertion()) + } + + fn verify_tls12_signature( + &self, + message: &[u8], + cert: &rustls::pki_types::CertificateDer<'_>, + dss: &rustls::DigitallySignedStruct, + ) -> Result { + rustls::crypto::verify_tls12_signature( + message, + cert, + dss, + &self.0.signature_verification_algorithms, + ) + } + + fn verify_tls13_signature( + &self, + message: &[u8], + cert: &rustls::pki_types::CertificateDer<'_>, + dss: &rustls::DigitallySignedStruct, + ) -> Result { + rustls::crypto::verify_tls13_signature( + message, + cert, + dss, + &self.0.signature_verification_algorithms, + ) + } + + fn supported_verify_schemes(&self) -> Vec { + self.0.signature_verification_algorithms.supported_schemes() + } +} diff --git a/crates/client/src/request.rs b/crates/client/src/request.rs new file mode 100644 index 0000000..de43135 --- /dev/null +++ b/crates/client/src/request.rs @@ -0,0 +1,229 @@ +use common::{ + community::Community, + error::Error, + message::Message, + network::Network, + request::{ + Authentication, Deauthentication, Request, + community::{CreateCommunity, DeleteCommunity, ReadCommunity, UpdateCommunity}, + message::{CreateMessage, DeleteMessage, ReadMessage, UpdateMessage}, + user::{CreateUser, DeleteUser, ReadUser, UpdateUser}, + user_community::{JoinCommunity, LeaveCommunity}, + }, + response::Response, + user::User, +}; + +macro_rules! send_request_receive_response_then_classify { + ($request:expr, $variant:path, $connection:expr) => {{ + let (send_stream, receive_stream) = $connection.open_bi().await?; + let response = + Network::send_request_and_receive_response(&$request, send_stream, receive_stream) + .await?; + match response { + $variant(inner) => Ok(inner), + Response::Error(error) => Err(error), + _ => Err(Error::Server), + } + }}; + + (@unit $request:expr, $variant:path, $connection:expr) => {{ + let (send_stream, receive_stream) = $connection.open_bi().await?; + let response = + Network::send_request_and_receive_response(&$request, send_stream, receive_stream) + .await?; + match response { + $variant => Ok(()), + Response::Error(error_value) => Err(error_value), + _ => Err(Error::Server), + } + }}; +} + +#[derive(Debug, Clone)] +pub struct ClientRequest { + connection: quinn::Connection, +} + +impl ClientRequest { + pub fn new(connection: quinn::Connection) -> Self { + Self { connection } + } + + pub async fn closed(&self) -> Error { + self.connection.closed().await.into() + } + + pub async fn authenticate(&self, authentication_token: &str) -> Result { + let authentication = Authentication::new(authentication_token); + let request = Request::Authentication(authentication); + + send_request_receive_response_then_classify!( + request, + Response::Authentication, + self.connection + ) + } + + pub async fn deauthenticate(&self, authentication_token: &str) -> Result { + let deauthentication = Deauthentication::new(authentication_token); + let request = Request::Deauthentication(deauthentication); + + send_request_receive_response_then_classify!( + request, + Response::Deauthentication, + self.connection + ) + } + + pub async fn create_user(&self, username: &str) -> Result { + let create_user = CreateUser::new(username)?; + let request = Request::CreateUser(create_user); + + send_request_receive_response_then_classify!(request, Response::CreateUser, self.connection) + } + + pub async fn read_user(&self, user_id: &str) -> Result { + let read_user = ReadUser::new(user_id); + let request = Request::ReadUser(read_user); + + send_request_receive_response_then_classify!(request, Response::ReadUser, self.connection) + } + + pub async fn update_user(&self, user_id: &str, username: &str) -> Result { + let update_user = UpdateUser::new(user_id, username)?; + let request = Request::UpdateUser(update_user); + + send_request_receive_response_then_classify!(request, Response::UpdateUser, self.connection) + } + + pub async fn delete_user(&self, user_id: &str) -> Result { + let delete_user = DeleteUser::new(user_id); + let request = Request::DeleteUser(delete_user); + + send_request_receive_response_then_classify!(request, Response::DeleteUser, self.connection) + } + + pub async fn create_community(&self, community_name: &str) -> Result { + let create_community = CreateCommunity::new(community_name)?; + let request = Request::CreateCommunity(create_community); + + send_request_receive_response_then_classify!( + request, + Response::CreateCommunity, + self.connection + ) + } + + pub async fn read_community(&self, community_id: &str) -> Result { + let read_community = ReadCommunity::new(community_id); + let request = Request::ReadCommunity(read_community); + + send_request_receive_response_then_classify!( + request, + Response::ReadCommunity, + self.connection + ) + } + + pub async fn update_community( + &self, + community_id: &str, + community_name: &str, + ) -> Result { + let update_community = UpdateCommunity::new(community_id, community_name)?; + let request = Request::UpdateCommunity(update_community); + + send_request_receive_response_then_classify!( + request, + Response::UpdateCommunity, + self.connection + ) + } + + pub async fn delete_community(&self, community_id: &str) -> Result { + let delete_community = DeleteCommunity::new(community_id); + let request = Request::DeleteCommunity(delete_community); + + send_request_receive_response_then_classify!( + request, + Response::DeleteCommunity, + self.connection + ) + } + + pub async fn create_message( + &self, + user_id: &str, + community_id: &str, + message_body: &str, + ) -> Result { + let create_message = CreateMessage::new(user_id, community_id, message_body)?; + let request = Request::CreateMessage(create_message); + + send_request_receive_response_then_classify!( + request, + Response::CreateMessage, + self.connection + ) + } + + pub async fn read_message(&self, message_id: &str) -> Result { + let read_message = ReadMessage::new(message_id); + let request = Request::ReadMessage(read_message); + + send_request_receive_response_then_classify!( + request, + Response::ReadMessage, + self.connection + ) + } + + pub async fn update_message( + &self, + message_id: &str, + message_body: &str, + ) -> Result { + let update_message = UpdateMessage::new(message_id, message_body)?; + let request = Request::UpdateMessage(update_message); + + send_request_receive_response_then_classify!( + request, + Response::UpdateMessage, + self.connection + ) + } + + pub async fn delete_message(&self, message_id: &str) -> Result { + let delete_message = DeleteMessage::new(message_id); + let request = Request::DeleteMessage(delete_message); + + send_request_receive_response_then_classify!( + request, + Response::DeleteMessage, + self.connection + ) + } + + pub async fn join_community(&self, user_id: &str, community_id: &str) -> Result<(), Error> { + let join_community = JoinCommunity::new(user_id, community_id); + let request = Request::JoinCommunity(join_community); + + send_request_receive_response_then_classify!( + @unit request, + Response::JoinCommunity, + self.connection + ) + } + + pub async fn leave_community(&self, user_id: &str, community_id: &str) -> Result<(), Error> { + let leave_community = LeaveCommunity::new(user_id, community_id); + let request = Request::LeaveCommunity(leave_community); + + send_request_receive_response_then_classify!( + @unit request, + Response::LeaveCommunity, + self.connection + ) + } +}