From a8e806498f968ef5abefdc6c173879e4b3229173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 10 Jun 2026 20:41:40 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(client):=20rename?= =?UTF-8?q?=20nefes=20to=20yumush=20and=20adopt=20community=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename the root view to match the project name and adapt chat and login to the flattened id-based User, Message and Community types. --- crates/client/Cargo.toml | 1 + crates/client/src/gui.rs | 6 +-- crates/client/src/gui/chat.rs | 91 ++++++++++++++++++++-------------- crates/client/src/gui/login.rs | 26 ++++------ crates/client/src/main.rs | 4 +- 5 files changed, 70 insertions(+), 58 deletions(-) diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 1d77975..284e995 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] common = { workspace = true, features = ["client"] } tokio.workspace = true +quinn = { workspace = true, features = ["rustls-ring", "platform-verifier"] } gpui = "0.2.2" gpui-component = "0.5.1" diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 1423818..8eb5d51 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -11,13 +11,13 @@ enum Route { Chat, } -pub struct Nefes { +pub struct Yumush { current_route: Route, login: Login, chat: Chat, } -impl Nefes { +impl Yumush { pub fn new(window: &mut gpui::Window, cx: &mut gpui::Context) -> Self { Self { current_route: Route::Login, @@ -41,7 +41,7 @@ impl Nefes { } } -impl Render for Nefes { +impl Render for Yumush { fn render( &mut self, window: &mut gpui::Window, diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 8005f09..387482b 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -1,4 +1,4 @@ -use common::{bastion::Bastion, message::Message, user::User}; +use common::{community::Community, message::Message, user::User}; use gpui::{ AppContext, Context, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, StatefulInteractiveElement, Styled, Window, div, rgb, @@ -9,17 +9,17 @@ use gpui_component::{ notification::Notification, }; -use crate::gui::Nefes; +use crate::gui::Yumush; pub struct Chat { - bastion: Bastion, + community: Community, users: Vec, chat_messages: Vec, message_input: Entity, } impl Chat { - pub fn new(window: &mut Window, cx: &mut Context) -> Self { + pub fn new(window: &mut Window, cx: &mut Context) -> Self { let message_input = cx.new(|cx| { let mut input_state = InputState::new(window, cx); input_state.set_placeholder("", window, cx); @@ -27,57 +27,72 @@ impl Chat { input_state }); - let bastion = Bastion::new("Bastion").unwrap(); + let community = Community::new("1", "Community"); - let bastion = || bastion.clone(); + let community = || community.clone(); cx.subscribe_in(&message_input, window, |this, input, event, window, cx| { if matches!(event, InputEvent::PressEnter { .. }) { - match Message::new( - this.login.get_user().unwrap(), - this.chat.bastion.clone(), - input.read(cx).text(), - ) { - Ok(message) => { - this.chat.chat_messages.push(message); - input.update(cx, |input_state, cx| { - input_state.set_value("", window, cx); - }); - } - Err(error_value) => { - window.push_notification(Notification::error(error_value.to_string()), cx) - } - } + let message = Message::new( + "1", + this.chat.community.get_community_id(), + this.login.get_user().unwrap().get_username(), + &input.read(cx).text().to_string(), + ); + + this.chat.chat_messages.push(message); + input.update(cx, |input_state, cx| { + input_state.set_value("", window, cx); + }); } }) .detach(); - let person_1 = User::new("Ahmet").unwrap(); - let person_2 = User::new("Kaan").unwrap(); - let message_1 = Message::new(person_1, bastion(), "Hello, how are you?").unwrap(); - let message_2 = Message::new(person_2, bastion(), "I'm doing well. How are you?").unwrap(); - let person_1 = User::new("Ahmet").unwrap(); - let message_3 = - Message::new(person_1, bastion(), "I'm good too. Thanks for asking!").unwrap(); - let person_2 = User::new("Kaan").unwrap(); - let message_4 = Message::new(person_2, bastion(), "A".repeat(1024)).unwrap(); - let person_1 = User::new("Ahmet").unwrap(); - let person_2 = User::new("Kaan").unwrap(); + let person_1 = User::new("Ahmet", "Ahmet"); + let person_2 = User::new("Kaan", "Kaan"); + let message_1 = Message::new( + "1", + community().get_community_id(), + person_1.get_user_id(), + "Hello, how are you?", + ); + let message_2 = Message::new( + "1", + community().get_community_id(), + person_2.get_user_id(), + "I'm doing well. How are you?", + ); + let person_1 = User::new("1", "Ahmet"); + let message_3 = Message::new( + "1", + community().get_community_id(), + person_1.get_username(), + "I'm good too. Thanks for asking!", + ); + let person_2 = User::new("1", "Kaan"); + let message_4 = Message::new( + "1", + community().get_community_id(), + person_2.get_username(), + &"A".repeat(1024), + ); + let person_1 = User::new("1", "Ahmet"); + let person_2 = User::new("1", "Kaan"); Self { - bastion: bastion(), + community: community(), users: vec![person_1, person_2], chat_messages: vec![message_1, message_2, message_3, message_4], message_input, } } - pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Nefes>) { + pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Yumush>) { self.message_input.update(cx, |input, cx| { input.focus(window, cx); }); } } -impl Nefes { +impl Yumush { pub fn chat_page(&self) -> impl IntoElement { div() .flex() @@ -132,7 +147,7 @@ impl Nefes { self.chat .users .iter() - .map(|user| div().p_1().child(user.get_username().clone())), + .map(|user| div().p_1().child(user.get_username().to_string())), ), ) } @@ -147,7 +162,7 @@ fn render_message(message: &Message) -> impl IntoElement { div() .text_color(rgb(0x7289da)) .font_weight(FontWeight::BOLD) - .child(message.get_user().get_username().clone()), + .child(message.get_user_id().to_string()), ) - .child(div().pl_2().child(message.get_message().clone())) + .child(div().pl_2().child(message.get_message_body().to_string())) } diff --git a/crates/client/src/gui/login.rs b/crates/client/src/gui/login.rs index 4c1ae8f..211ecea 100644 --- a/crates/client/src/gui/login.rs +++ b/crates/client/src/gui/login.rs @@ -7,7 +7,7 @@ use gpui_component::{ notification::Notification, }; -use crate::gui::{Nefes, Route}; +use crate::gui::{Route, Yumush}; pub struct Login { username_input: Entity, @@ -15,7 +15,7 @@ pub struct Login { } impl Login { - pub fn new(window: &mut Window, cx: &mut Context) -> Self { + 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); @@ -41,7 +41,7 @@ impl Login { self.user.clone() } - pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Nefes>) { + pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Yumush>) { self.username_input.update(cx, |input, cx| { input.focus(window, cx); }); @@ -49,24 +49,20 @@ impl Login { } fn login_action( - this: &mut Nefes, + this: &mut Yumush, input: &Entity, window: &mut Window, - cx: &mut Context<'_, Nefes>, + cx: &mut Context<'_, Yumush>, ) { + let id = "A".to_string(); let username = input.read(cx).text().to_string(); - match User::new(username) { - Ok(user) => { - this.login.user = Some(user); - this.change_page(Route::Chat, window, cx); - } - Err(error_value) => { - window.push_notification(Notification::error(error_value.to_string()), cx) - } - } + + let user = User::new(&id, &username); + this.login.user = Some(user); + this.change_page(Route::Chat, window, cx); } -impl Nefes { +impl Yumush { pub fn login_page(&mut self, cx: &mut Context) -> impl IntoElement { let entity = cx.entity(); let username_input = self.login.username_input.clone(); diff --git a/crates/client/src/main.rs b/crates/client/src/main.rs index e6a6e90..b8ae5df 100644 --- a/crates/client/src/main.rs +++ b/crates/client/src/main.rs @@ -1,4 +1,4 @@ -use client::gui::Nefes; +use client::gui::Yumush; use gpui::{ App, AppContext, Application, Bounds, TitlebarOptions, WindowBounds, WindowOptions, px, size, }; @@ -24,7 +24,7 @@ fn main() { ..Default::default() }, |window, cx| { - let view = cx.new(|cx| Nefes::new(window, cx)); + let view = cx.new(|cx| Yumush::new(window, cx)); cx.new(|cx| Root::new(view, window, cx)) }, )