forge
Explore
Log in

Don't you dare go Hollow

Rename nefes to yumush and adopt community model

Browse files at this commit

a8e806498f968ef5abefdc6c173879e4b3229173Ahmet Kaan GümüşParent: 56893d1
  • refactor
    • rename nefes to yumush and adopt community model
Show full message
♻️ refactor(client): rename nefes to yumush and adopt community model

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.tomlmodified+1 -0
@@ -6,6 +6,7 @@ edition = "2024"
6 [dependencies]6 [dependencies]
7 common = { workspace = true, features = ["client"] }7 common = { workspace = true, features = ["client"] }
8 tokio.workspace = true8 tokio.workspace = true
9+quinn = { workspace = true, features = ["rustls-ring", "platform-verifier"] }
9 10
10 gpui = "0.2.2"11 gpui = "0.2.2"
11 gpui-component = "0.5.1"12 gpui-component = "0.5.1"
crates/client/src/gui.rsmodified+3 -3
@@ -11,13 +11,13 @@ enum Route {
11 Chat,11 Chat,
12 }12 }
13 13
14-pub struct Nefes {14+pub struct Yumush {
15 current_route: Route,15 current_route: Route,
16 login: Login,16 login: Login,
17 chat: Chat,17 chat: Chat,
18 }18 }
19 19
20-impl Nefes {20+impl Yumush {
21 pub fn new(window: &mut gpui::Window, cx: &mut gpui::Context<Self>) -> Self {21 pub fn new(window: &mut gpui::Window, cx: &mut gpui::Context<Self>) -> Self {
22 Self {22 Self {
23 current_route: Route::Login,23 current_route: Route::Login,
@@ -41,7 +41,7 @@ impl Nefes {
41 }41 }
42 }42 }
43 43
44-impl Render for Nefes {44+impl Render for Yumush {
45 fn render(45 fn render(
46 &mut self,46 &mut self,
47 window: &mut gpui::Window,47 window: &mut gpui::Window,
crates/client/src/gui/chat.rsmodified+53 -38
@@ -1,4 +1,4 @@
1-use common::{bastion::Bastion, message::Message, user::User};1+use common::{community::Community, message::Message, user::User};
2 use gpui::{2 use gpui::{
3 AppContext, Context, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement,3 AppContext, Context, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement,
4 StatefulInteractiveElement, Styled, Window, div, rgb,4 StatefulInteractiveElement, Styled, Window, div, rgb,
@@ -9,17 +9,17 @@ use gpui_component::{
9 notification::Notification,9 notification::Notification,
10 };10 };
11 11
12-use crate::gui::Nefes;12+use crate::gui::Yumush;
13 13
14 pub struct Chat {14 pub struct Chat {
15- bastion: Bastion,15+ community: Community,
16 users: Vec<User>,16 users: Vec<User>,
17 chat_messages: Vec<Message>,17 chat_messages: Vec<Message>,
18 message_input: Entity<InputState>,18 message_input: Entity<InputState>,
19 }19 }
20 20
21 impl Chat {21 impl Chat {
22- pub fn new(window: &mut Window, cx: &mut Context<Nefes>) -> Self {22+ pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self {
23 let message_input = cx.new(|cx| {23 let message_input = cx.new(|cx| {
24 let mut input_state = InputState::new(window, cx);24 let mut input_state = InputState::new(window, cx);
25 input_state.set_placeholder("", window, cx);25 input_state.set_placeholder("", window, cx);
@@ -27,57 +27,72 @@ impl Chat {
27 input_state27 input_state
28 });28 });
29 29
30- let bastion = Bastion::new("Bastion").unwrap();30+ let community = Community::new("1", "Community");
31 31
32- let bastion = || bastion.clone();32+ let community = || community.clone();
33 cx.subscribe_in(&message_input, window, |this, input, event, window, cx| {33 cx.subscribe_in(&message_input, window, |this, input, event, window, cx| {
34 if matches!(event, InputEvent::PressEnter { .. }) {34 if matches!(event, InputEvent::PressEnter { .. }) {
35- match Message::new(35+ let message = Message::new(
36- this.login.get_user().unwrap(),36+ "1",
37- this.chat.bastion.clone(),37+ this.chat.community.get_community_id(),
38- input.read(cx).text(),38+ this.login.get_user().unwrap().get_username(),
39- ) {39+ &input.read(cx).text().to_string(),
40- Ok(message) => {40+ );
41- this.chat.chat_messages.push(message);41+
42- input.update(cx, |input_state, cx| {42+ this.chat.chat_messages.push(message);
43- input_state.set_value("", window, cx);43+ input.update(cx, |input_state, cx| {
44- });44+ input_state.set_value("", window, cx);
45- }45+ });
46- Err(error_value) => {
47- window.push_notification(Notification::error(error_value.to_string()), cx)
48- }
49- }
50 }46 }
51 })47 })
52 .detach();48 .detach();
53 49
54- let person_1 = User::new("Ahmet").unwrap();50+ let person_1 = User::new("Ahmet", "Ahmet");
55- let person_2 = User::new("Kaan").unwrap();51+ let person_2 = User::new("Kaan", "Kaan");
56- let message_1 = Message::new(person_1, bastion(), "Hello, how are you?").unwrap();52+ let message_1 = Message::new(
57- let message_2 = Message::new(person_2, bastion(), "I'm doing well. How are you?").unwrap();53+ "1",
58- let person_1 = User::new("Ahmet").unwrap();54+ community().get_community_id(),
59- let message_3 =55+ person_1.get_user_id(),
60- Message::new(person_1, bastion(), "I'm good too. Thanks for asking!").unwrap();56+ "Hello, how are you?",
61- let person_2 = User::new("Kaan").unwrap();57+ );
62- let message_4 = Message::new(person_2, bastion(), "A".repeat(1024)).unwrap();58+ let message_2 = Message::new(
63- let person_1 = User::new("Ahmet").unwrap();59+ "1",
64- let person_2 = User::new("Kaan").unwrap();60+ community().get_community_id(),
61+ person_2.get_user_id(),
62+ "I'm doing well. How are you?",
63+ );
64+ let person_1 = User::new("1", "Ahmet");
65+ let message_3 = Message::new(
66+ "1",
67+ community().get_community_id(),
68+ person_1.get_username(),
69+ "I'm good too. Thanks for asking!",
70+ );
71+ let person_2 = User::new("1", "Kaan");
72+ let message_4 = Message::new(
73+ "1",
74+ community().get_community_id(),
75+ person_2.get_username(),
76+ &"A".repeat(1024),
77+ );
78+ let person_1 = User::new("1", "Ahmet");
79+ let person_2 = User::new("1", "Kaan");
65 Self {80 Self {
66- bastion: bastion(),81+ community: community(),
67 users: vec![person_1, person_2],82 users: vec![person_1, person_2],
68 chat_messages: vec![message_1, message_2, message_3, message_4],83 chat_messages: vec![message_1, message_2, message_3, message_4],
69 message_input,84 message_input,
70 }85 }
71 }86 }
72 87
73- pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Nefes>) {88+ pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Yumush>) {
74 self.message_input.update(cx, |input, cx| {89 self.message_input.update(cx, |input, cx| {
75 input.focus(window, cx);90 input.focus(window, cx);
76 });91 });
77 }92 }
78 }93 }
79 94
80-impl Nefes {95+impl Yumush {
81 pub fn chat_page(&self) -> impl IntoElement {96 pub fn chat_page(&self) -> impl IntoElement {
82 div()97 div()
83 .flex()98 .flex()
@@ -132,7 +147,7 @@ impl Nefes {
132 self.chat147 self.chat
133 .users148 .users
134 .iter()149 .iter()
135- .map(|user| div().p_1().child(user.get_username().clone())),150+ .map(|user| div().p_1().child(user.get_username().to_string())),
136 ),151 ),
137 )152 )
138 }153 }
@@ -147,7 +162,7 @@ fn render_message(message: &Message) -> impl IntoElement {
147 div()162 div()
148 .text_color(rgb(0x7289da))163 .text_color(rgb(0x7289da))
149 .font_weight(FontWeight::BOLD)164 .font_weight(FontWeight::BOLD)
150- .child(message.get_user().get_username().clone()),165+ .child(message.get_user_id().to_string()),
151 )166 )
152- .child(div().pl_2().child(message.get_message().clone()))167+ .child(div().pl_2().child(message.get_message_body().to_string()))
153 }168 }
crates/client/src/gui/login.rsmodified+11 -15
@@ -7,7 +7,7 @@ use gpui_component::{
7 notification::Notification,7 notification::Notification,
8 };8 };
9 9
10-use crate::gui::{Nefes, Route};10+use crate::gui::{Route, Yumush};
11 11
12 pub struct Login {12 pub struct Login {
13 username_input: Entity<InputState>,13 username_input: Entity<InputState>,
@@ -15,7 +15,7 @@ pub struct Login {
15 }15 }
16 16
17 impl Login {17 impl Login {
18- pub fn new(window: &mut Window, cx: &mut Context<Nefes>) -> Self {18+ pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self {
19 let username_input = cx.new(|cx| {19 let username_input = cx.new(|cx| {
20 let mut input_state = InputState::new(window, cx);20 let mut input_state = InputState::new(window, cx);
21 input_state.set_placeholder("Username...", window, cx);21 input_state.set_placeholder("Username...", window, cx);
@@ -41,7 +41,7 @@ impl Login {
41 self.user.clone()41 self.user.clone()
42 }42 }
43 43
44- pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Nefes>) {44+ pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, Yumush>) {
45 self.username_input.update(cx, |input, cx| {45 self.username_input.update(cx, |input, cx| {
46 input.focus(window, cx);46 input.focus(window, cx);
47 });47 });
@@ -49,24 +49,20 @@ impl Login {
49 }49 }
50 50
51 fn login_action(51 fn login_action(
52- this: &mut Nefes,52+ this: &mut Yumush,
53 input: &Entity<InputState>,53 input: &Entity<InputState>,
54 window: &mut Window,54 window: &mut Window,
55- cx: &mut Context<'_, Nefes>,55+ cx: &mut Context<'_, Yumush>,
56 ) {56 ) {
57+ let id = "A".to_string();
57 let username = input.read(cx).text().to_string();58 let username = input.read(cx).text().to_string();
58- match User::new(username) {59+
59- Ok(user) => {60+ let user = User::new(&id, &username);
60- this.login.user = Some(user);61+ this.login.user = Some(user);
61- this.change_page(Route::Chat, window, cx);62+ this.change_page(Route::Chat, window, cx);
62- }
63- Err(error_value) => {
64- window.push_notification(Notification::error(error_value.to_string()), cx)
65- }
66- }
67 }63 }
68 64
69-impl Nefes {65+impl Yumush {
70 pub fn login_page(&mut self, cx: &mut Context<Self>) -> impl IntoElement {66 pub fn login_page(&mut self, cx: &mut Context<Self>) -> impl IntoElement {
71 let entity = cx.entity();67 let entity = cx.entity();
72 let username_input = self.login.username_input.clone();68 let username_input = self.login.username_input.clone();
crates/client/src/main.rsmodified+2 -2
@@ -1,4 +1,4 @@
1-use client::gui::Nefes;1+use client::gui::Yumush;
2 use gpui::{2 use gpui::{
3 App, AppContext, Application, Bounds, TitlebarOptions, WindowBounds, WindowOptions, px, size,3 App, AppContext, Application, Bounds, TitlebarOptions, WindowBounds, WindowOptions, px, size,
4 };4 };
@@ -24,7 +24,7 @@ fn main() {
24 ..Default::default()24 ..Default::default()
25 },25 },
26 |window, cx| {26 |window, cx| {
27- let view = cx.new(|cx| Nefes::new(window, cx));27+ let view = cx.new(|cx| Yumush::new(window, cx));
28 cx.new(|cx| Root::new(view, window, cx))28 cx.new(|cx| Root::new(view, window, cx))
29 },29 },
30 )30 )