forge
Explore
Log in

Don't you dare go Hollow

yumush

Clone
★ 0

0 watching0 forksRustAGPL-3.07.2 MiBe6d4742Tahinli41 minutes ago401 commits

sidebar.rs1359 lines, 44.2 KiBHistoryRawDownload
1use super::text;
2use crate::lang::w;
3use common::model::Id;
4use common::{
5 model::{Community, CommunityKind, Invitation, Unread, User},
6 permission,
7 share::Kind,
8 validate::validate_community_name,
9};
10use gpui_kit::{
11 Anchor, AnimationExt, AnyElement, App, Context, Div, Entity, FontWeight, Hsla,
12 InteractiveElement, IntoElement, ParentElement, PathBuilder, StatefulInteractiveElement,
13 Styled, Window,
14 assets::IconName,
15 component::{
16 input::{Input, InputState},
17 popover::{Popover, PopoverState},
18 },
19 div,
20 prelude::FluentBuilder as _,
21 px,
22};
23
24use super::{
25 Palette, Tooltip as _, Yumush, avatar,
26 chat::{Armed, View, create_community},
27 clickable, community_icon, community_name, entity_action, hoverable, input_dialog,
28 parts::{Scale, Tone, icon_button},
29 presence_avatar,
30 profile::profile_popover,
31 social::Relation,
32 style::{radius, size, space, text},
33 widget::{bare_input, compact_frame},
34};
35
36const SLIDE: std::time::Duration = std::time::Duration::from_millis(320);
37
38fn slide() -> gpui_kit::Animation {
39 gpui_kit::Animation::new(SLIDE).with_easing(gpui_kit::ease_in_out)
40}
41
42impl Yumush {
43 pub(super) fn sidebar(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {
44 let content = if self.chat.sidebar_collapsed && !self.sliding() {
45 self.collapsed_sidebar(entity, palette).into_any_element()
46 } else {
47 self.expanded_sidebar(entity, palette)
48 };
49
50 self.folding(
51 "sidebar",
52 div()
53 .h_full()
54 .flex_shrink_0()
55 .overflow_hidden()
56 .child(content),
57 |sidebar, f| sidebar.w(px(lerp(size::SIDEBAR, size::RAIL, f))),
58 )
59 }
60
61 pub(super) fn toggle_sidebar(&mut self) {
62 self.chat.sidebar_collapsed = !self.chat.sidebar_collapsed;
63 self.chat.sidebar_toggled = Some(std::time::Instant::now());
64 }
65
66 fn sliding(&self) -> bool {
67 self.chat
68 .sidebar_toggled
69 .is_some_and(|at| at.elapsed() < SLIDE)
70 }
71
72 fn folding<E: IntoElement + 'static>(
73 &self,
74 id: &'static str,
75 element: E,
76 style: impl Fn(E, f32) -> E + 'static,
77 ) -> AnyElement {
78 let collapsed = self.chat.sidebar_collapsed;
79 let fold = move |delta: f32| if collapsed { delta } else { 1. - delta };
80 if self.sliding() {
81 element
82 .with_animation((id, collapsed as u64), slide(), move |element, delta| {
83 style(element, fold(delta))
84 })
85 .into_any_element()
86 } else {
87 style(element, fold(1.)).into_any_element()
88 }
89 }
90
91 fn collapsed_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> Div {
92 div()
93 .h_full()
94 .w(px(size::RAIL))
95 .pl(px(RAIL_SHIFT))
96 .flex()
97 .flex_col()
98 .items_center()
99 .justify_between()
100 .py(px(space::MD))
101 .child(
102 div()
103 .flex()
104 .flex_col()
105 .items_center()
106 .gap(px(space::MD))
107 .child(self.logo_toggle(
108 entity,
109 palette,
110 logo_mark(palette).size(px(size::CONTROL)),
111 )),
112 )
113 .child(
114 div()
115 .flex()
116 .flex_col()
117 .items_center()
118 .gap(px(space::MD))
119 .children(
120 self.user
121 .as_ref()
122 .map(|user| self.account_trigger(entity, user, false, palette)),
123 ),
124 )
125 }
126
127 fn expanded_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement {
128 let friends_alert =
129 !self.chat.friends.incoming.is_empty() || !self.chat.invitations.is_empty();
130
131 div()
132 .relative()
133 .h_full()
134 .w(px(size::SIDEBAR))
135 .flex()
136 .flex_col()
137 .py(px(space::LG))
138 .px(px(space::LG))
139 .gap(px(space::XL))
140 .child(
141 div()
142 .h(px(size::CONTROL))
143 .flex()
144 .items_center()
145 .gap(px(space::XS))
146 .child(self.folding(
147 "logo",
148 div().relative().child(self.logo_toggle(
149 entity,
150 palette,
151 self.folding(
152 "logo_mark",
153 logo_mark(palette).when(towing(self.wordmark_flipped), |mark| {
154 mark.path(crate::logo::NEEDLE)
155 }),
156 |mark, f| mark.size(px(lerp(size::CHIP, size::CONTROL, f))),
157 ),
158 )),
159 |logo, f| {
160 logo.left(px(
161 f * (RAIL_CENTER - space::LG - size::CONTROL / 2. - space::XXS)
162 ))
163 .top(px(f * (space::MD + space::XXS - space::LG)))
164 },
165 ))
166 .child(
167 self.folding(
168 "wordmark_fold",
169 div()
170 .id("wordmark")
171 .flex_1()
172 .text_size(text(text::TITLE))
173 .line_height(gpui_kit::relative(LEADING))
174 .font_weight(FontWeight::SEMIBOLD)
175 .text_color(palette.text)
176 .cursor_pointer()
177 .on_click({
178 let entity = entity.clone();
179 move |_, window, cx| {
180 entity.update(cx, |yumush, cx| yumush.open_jump(window, cx))
181 }
182 })
183 .flex()
184 .items_center()
185 .child("yumu")
186 .child(wordmark_tail(
187 self.wordmark_flips,
188 self.wordmark_flipped,
189 palette,
190 )),
191 |word, f| {
192 word.relative()
193 .left(px(-space::XXL * f))
194 .opacity((1. - 2. * f).max(0.))
195 },
196 ),
197 )
198 .child(self.folding(
199 "friends_fold",
200 div().child(self.friends_button(entity, friends_alert, palette)),
201 fade,
202 )),
203 )
204 .children(self.update_control(palette))
205 .child(
206 self.folding(
207 "list_fold",
208 div()
209 .id("sidebar_list")
210 .flex_1()
211 .min_h_0()
212 .overflow_y_scroll()
213 .flex()
214 .flex_col()
215 .gap(px(space::MD))
216 .children(self.sections(entity, palette)),
217 |list, f| fade(list, f).flex_1().min_h_0(),
218 ),
219 )
220 .children(self.build_control(entity, palette))
221 .children(self.account_row(entity, palette))
222 .into_any_element()
223 }
224
225 fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement {
226 let ids = self.chat.voice_ids(community_id);
227 let t = palette.tokens;
228 let direct = self.is_direct(community_id);
229 let heard: Vec<Id> = ids
230 .iter()
231 .copied()
232 .filter(|id| !(direct && self.is_me(*id)))
233 .collect();
234 let mut speakers = heard
235 .iter()
236 .filter(|id| self.chat.waves.speaking.contains(id));
237 let voice = match (speakers.next(), speakers.next()) {
238 (Some(id), None) => super::parts::Voice::Live(t.person(*id)),
239 (Some(_), Some(_)) => super::parts::Voice::Live(t.paper()),
240 _ => super::parts::Voice::Quiet,
241 };
242 let total = self.chat.waves.total(&heard);
243 div()
244 .id(format!("voice_chip_{community_id}"))
245 .tip(w().sidebar.in_call)
246 .flex_1()
247 .flex()
248 .items_center()
249 .gap(px(space::XS))
250 .child(
251 div()
252 .flex_1()
253 .min_w(px(size::CONTROL))
254 .h(px(space::MD))
255 .child(super::parts::voice_line(total.as_ref(), voice, t)),
256 )
257 .when(!direct, |this| {
258 this.child(
259 div()
260 .text_size(text(text::CAPTION))
261 .text_color(palette.muted)
262 .child(ids.len().to_string()),
263 )
264 })
265 .into_any_element()
266 }
267
268 pub(super) fn new_community(&mut self, window: &mut Window, cx: &mut Context<Self>) {
269 input_dialog(
270 w().sidebar.new_community,
271 w().sidebar.create,
272 w().sidebar.name_placeholder,
273 window,
274 cx,
275 |this, name, window, cx| {
276 let name = name.trim().to_string();
277 if validate_community_name(&name).is_ok() {
278 create_community(this, name, window, cx);
279 }
280 },
281 );
282 }
283
284 fn logo_toggle(
285 &self,
286 entity: &Entity<Self>,
287 palette: Palette,
288 mark: impl IntoElement,
289 ) -> AnyElement {
290 let tip = if self.chat.sidebar_collapsed {
291 w().sidebar.expand
292 } else {
293 w().sidebar.collapse
294 };
295 clickable(
296 "sidebar_toggle",
297 palette,
298 entity_action(entity, |yumush, _, cx| {
299 yumush.toggle_sidebar();
300 cx.notify();
301 }),
302 )
303 .tip(tip)
304 .flex_none()
305 .p(px(space::XXS))
306 .rounded(px(radius::MD))
307 .child(mark)
308 .into_any_element()
309 }
310
311 pub(super) fn open_friends(&mut self, window: &mut Window, cx: &mut Context<Self>) {
312 self.chat.friends_open = true;
313 self.chat
314 .search_input
315 .update(cx, |input, cx| input.focus(window, cx));
316 cx.notify();
317 }
318
319 pub(super) fn close_friends(&mut self, window: &mut Window, cx: &mut Context<Self>) {
320 self.chat.friends_open = false;
321 window.focus(&self.focus, cx);
322 cx.notify();
323 }
324
325 fn friends_sheet(&self, entity: &Entity<Self>, cx: &App, palette: Palette) -> Div {
326 let query = super::widget::search_text(&self.chat.search_input, cx);
327 let found = self.chat.found.as_ref().filter(|found| {
328 !self
329 .chat
330 .friends
331 .friends
332 .iter()
333 .any(|user| user.id == found.id)
334 });
335 let friends = self.friend_list(entity, &query, palette);
336 super::parts::popover(palette.tokens)
337 .w(px(size::POPOVER))
338 .px(px(space::MD))
339 .py(px(space::MD))
340 .gap(px(space::MD))
341 .child(input_box(&self.chat.search_input, palette))
342 .children(found.map(|user| self.found_row(entity, user, palette)))
343 .children(self.requests(entity, palette))
344 .when(!friends.is_empty(), |sheet| {
345 sheet.child(
346 div()
347 .id("friends_list")
348 .max_h(px(size::POPOVER))
349 .overflow_y_scroll()
350 .flex()
351 .flex_col()
352 .gap(px(space::XXS))
353 .children(friends),
354 )
355 })
356 }
357
358 fn friends_button(
359 &self,
360 entity: &Entity<Self>,
361 alert: bool,
362 palette: Palette,
363 ) -> impl IntoElement {
364 let opened = entity.clone();
365 let content = entity.clone();
366 gpui_kit::component::popover::Popover::new("friends_sheet")
367 .anchor(Anchor::TopLeft)
368 .appearance(false)
369 .open(self.chat.friends_open)
370 .on_open_change(move |open, window, cx| {
371 let open = *open;
372 opened.update(cx, |yumush, cx| {
373 if open {
374 yumush.open_friends(window, cx)
375 } else {
376 yumush.close_friends(window, cx)
377 }
378 })
379 })
380 .trigger(super::Trigger::new(hoverable(
381 "friends_button",
382 div()
383 .relative()
384 .size(px(size::CONTROL_SM))
385 .flex()
386 .items_center()
387 .justify_center()
388 .rounded_full()
389 .text_color(palette.muted)
390 .child(super::parts::small_icon(IconName::Users))
391 .children(alert.then(|| {
392 div()
393 .absolute()
394 .top(px(space::XXS))
395 .right(px(space::XXS))
396 .size(px(space::XS + space::XXS))
397 .rounded_full()
398 .bg(palette.text)
399 })),
400 palette,
401 )))
402 .content(move |_, _, cx| {
403 let yumush = content.read(cx);
404 yumush.friends_sheet(&content, cx, palette)
405 })
406 }
407
408 fn friend_list(&self, entity: &Entity<Self>, query: &str, palette: Palette) -> Vec<AnyElement> {
409 let mut friends: Vec<&User> = self
410 .chat
411 .friends
412 .friends
413 .iter()
414 .filter(|user| matches_query(&user.username, query))
415 .collect();
416 friends.sort_by_key(|user| (self.doing(user.id), user.username.to_lowercase()));
417 friends
418 .into_iter()
419 .map(|user| {
420 let user_id = user.id;
421 let open = entity.clone();
422 let remove = entity.clone();
423 let row = hoverable(
424 format!("friend_{}", user.id),
425 self.user_row(palette, user, None),
426 palette,
427 )
428 .on_click(move |_, window, cx| {
429 open.update(cx, |yumush, cx| {
430 yumush.close_friends(window, cx);
431 yumush.open_direct(user_id, window, cx)
432 })
433 });
434 let armed = Armed::RemoveFriend(user_id);
435 right_menu(
436 ("friend_menu", user_id as usize),
437 entity,
438 row,
439 move |popover, cx| {
440 super::parts::stack(space::XS).child(super::profile::menu_row(
441 ("remove_friend", user_id as usize),
442 remove
443 .read(cx)
444 .armed_label(armed, w().sidebar.remove_friend),
445 super::parts::small_icon(IconName::UserMinus),
446 palette.danger,
447 palette,
448 super::profile::armed_action(
449 armed,
450 &remove,
451 popover,
452 move |yumush, window, cx| yumush.remove_friend(user_id, window, cx),
453 ),
454 ))
455 },
456 )
457 .into_any_element()
458 })
459 .collect()
460 }
461
462 fn sections(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {
463 let pinned = &self.chat.pinned;
464 let list = |rows: Vec<AnyElement>| {
465 div()
466 .flex()
467 .flex_col()
468 .gap(px(space::XXS))
469 .children(rows)
470 .into_any_element()
471 };
472 let pins = self.rooms(entity, palette, |room| pinned.contains(&room.id));
473 let groups = self.rooms(entity, palette, |room| {
474 room.kind.is_group() && !pinned.contains(&room.id)
475 });
476 let people = std::iter::once(self.notes_row(entity, palette))
477 .chain(self.rooms(entity, palette, |room| {
478 room.kind.is_direct() && !pinned.contains(&room.id)
479 }))
480 .collect();
481 let sections: Vec<AnyElement> = [pins, groups, people]
482 .into_iter()
483 .filter(|rows| !rows.is_empty())
484 .map(list)
485 .collect();
486 let count = sections.len();
487 sections
488 .into_iter()
489 .enumerate()
490 .flat_map(|(index, section)| {
491 std::iter::once(section).chain((index + 1 < count).then(|| {
492 super::parts::thread(palette.tokens)
493 .mx(px(space::SM))
494 .into_any_element()
495 }))
496 })
497 .collect()
498 }
499
500 fn notes_row(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement {
501 let notes = self.chat.notes();
502 let active = notes.is_some_and(|notes| self.chat.is_selected(notes.id));
503 let unread = notes.and_then(|notes| self.chat.unread.get(&notes.id));
504 let open = entity.clone();
505
506 hoverable(
507 "notes",
508 room_row(
509 palette,
510 active,
511 Some(notes_tile(palette)),
512 w().sidebar.notes.to_string(),
513 unread_badge(palette, false, unread),
514 ),
515 palette,
516 )
517 .on_click(move |_, window, cx| open.update(cx, |yumush, cx| yumush.open_notes(window, cx)))
518 .into_any_element()
519 }
520
521 fn rooms(
522 &self,
523 entity: &Entity<Self>,
524 palette: Palette,
525 keep: impl Fn(&Community) -> bool,
526 ) -> Vec<AnyElement> {
527 self.unread_first(
528 self.chat
529 .communities
530 .iter()
531 .chain(
532 self.chat
533 .opened
534 .as_ref()
535 .filter(|opened| opened.kind.is_group())
536 .filter(|opened| !self.chat.joined(opened.id)),
537 )
538 .filter(|community| !matches!(community.kind, CommunityKind::Notes))
539 .filter(|community| keep(community)),
540 )
541 .into_iter()
542 .map(|community| self.room_entry(entity, community, palette))
543 .collect()
544 }
545
546 fn room_entry(
547 &self,
548 entity: &Entity<Self>,
549 community: &Community,
550 palette: Palette,
551 ) -> AnyElement {
552 self.sidebar_community_row(entity, community, palette)
553 }
554
555 fn sidebar_community_row(
556 &self,
557 entity: &Entity<Self>,
558 community: &Community,
559 palette: Palette,
560 ) -> AnyElement {
561 let active = self.chat.is_selected(community.id);
562 let group = community.kind.is_group();
563 let can_leave = group && (!active || permission::can_leave(self.actor_rank()));
564 let can_manage = !active || permission::can_manage_community(self.actor_rank());
565 let muted = self.chat.muted.contains(&community.id);
566 let unread = self.chat.unread.get(&community.id);
567 let community_id = community.id;
568 let select = entity.clone();
569
570 let pinned = self.chat.pinned.contains(&community.id);
571 let trailing = if self.chat.voice_ids(community_id).is_empty() {
572 unread_badge(palette, muted, unread).or_else(|| {
573 pinned.then(|| {
574 super::parts::small_icon(IconName::Pin)
575 .text_color(palette.muted)
576 .into_any_element()
577 })
578 })
579 } else {
580 Some(self.voice_chip(community_id, palette))
581 };
582 let face = match &community.kind {
583 CommunityKind::Direct { peer } => Some(
584 presence_avatar(
585 avatar(
586 palette,
587 peer,
588 px(size::AVATAR),
589 text(text::CAPTION),
590 &self.chat.avatars,
591 ),
592 self.presence_of(peer.id),
593 px(size::AVATAR),
594 palette,
595 )
596 .into_any_element(),
597 ),
598 CommunityKind::Group => Some(
599 community_icon(
600 palette,
601 community,
602 px(size::AVATAR),
603 text(text::CAPTION),
604 &self.chat.avatars,
605 )
606 .into_any_element(),
607 ),
608 CommunityKind::Notes => Some(notes_tile(palette)),
609 };
610 let row = hoverable(
611 format!("room_{}", community.id),
612 room_row(
613 palette,
614 active,
615 face,
616 community_name(community).to_string(),
617 trailing,
618 ),
619 palette,
620 )
621 .on_click(move |_, window, cx| {
622 select.update(cx, |yumush, cx| {
623 yumush.select_community(community_id, window, cx)
624 })
625 });
626 let menu = entity.clone();
627 right_menu(
628 ("room_menu", community_id as usize),
629 entity,
630 row,
631 move |popover, cx| {
632 let yumush = menu.read(cx);
633 super::community_card::room_rows(
634 community_id,
635 group,
636 can_leave,
637 can_manage,
638 yumush,
639 &menu,
640 popover,
641 palette,
642 )
643 },
644 )
645 .into_any_element()
646 }
647
648 fn requests(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {
649 let friends = &self.chat.friends;
650 let rows: Vec<AnyElement> = friends
651 .incoming
652 .iter()
653 .map(|user| self.incoming_row(entity, user, palette))
654 .chain(
655 friends
656 .outgoing
657 .iter()
658 .map(|user| self.outgoing_row(entity, user, palette)),
659 )
660 .chain(
661 self.chat
662 .invitations
663 .iter()
664 .map(|invitation| self.invitation_row(entity, invitation, palette)),
665 )
666 .collect();
667
668 group(w().sidebar.requests, palette, rows)
669 }
670
671 fn unread_first<'a>(&self, rooms: impl Iterator<Item = &'a Community>) -> Vec<&'a Community> {
672 let mut rooms: Vec<&Community> = rooms.collect();
673 rooms.sort_by_key(|community| {
674 self.chat
675 .unread
676 .get(&community.id)
677 .map_or((true, true), |unread| {
678 (unread.mentions == 0, unread.messages == 0)
679 })
680 });
681 rooms
682 }
683
684 pub(super) fn call_of(&self, user_id: Id) -> Option<&Community> {
685 let community_id = self
686 .chat
687 .voice
688 .iter()
689 .find(|(_, ids)| ids.contains(&user_id))
690 .map(|(community_id, _)| *community_id)?;
691 self.chat
692 .communities
693 .iter()
694 .find(|community| community.id == community_id)
695 }
696
697 fn doing(&self, user_id: Id) -> Doing {
698 if self.call_of(user_id).is_some() {
699 Doing::Call
700 } else if self.presence_of(user_id) == common::model::Presence::Offline {
701 Doing::Offline
702 } else {
703 Doing::Online
704 }
705 }
706
707 fn found_row(&self, entity: &Entity<Self>, user: &User, palette: Palette) -> AnyElement {
708 let relation = self.relation(user.id);
709 let mut trailing = Vec::new();
710
711 if relation != Relation::Myself {
712 trailing.push(row_button(
713 entity,
714 "message",
715 user.id,
716 palette,
717 IconName::MessageSquare,
718 w().sidebar.message,
719 |yumush, id, window, cx| {
720 yumush.close_friends(window, cx);
721 yumush.open_direct(id, window, cx)
722 },
723 ));
724 }
725 let action = match relation {
726 Relation::Stranger | Relation::Incoming => relation.action(),
727 _ => None,
728 };
729 if let Some((label, icon)) = action {
730 trailing.push(row_button(
731 entity,
732 "friend_action",
733 user.id,
734 palette,
735 icon,
736 label,
737 move |yumush, id, window, cx| yumush.friend_action(relation, id, window, cx),
738 ));
739 }
740
741 self.user_row(palette, user, trailing).into_any_element()
742 }
743
744 fn user_row(
745 &self,
746 palette: Palette,
747 user: &User,
748 trailing: impl IntoIterator<Item = AnyElement>,
749 ) -> Div {
750 entry(
751 palette,
752 false,
753 presence_avatar(
754 avatar(
755 palette,
756 user,
757 px(size::AVATAR),
758 text(text::CAPTION),
759 &self.chat.avatars,
760 ),
761 self.presence_of(user.id),
762 px(size::AVATAR),
763 palette,
764 ),
765 div().flex().flex_col().child(user.username.clone()).when(
766 !user.status.is_empty(),
767 |this| {
768 this.child(
769 div()
770 .text_color(palette.muted)
771 .child(super::glyph::line(
772 user.status.clone().into(),
773 text(text::CAPTION),
774 ))
775 .text_size(text(text::CAPTION)),
776 )
777 },
778 ),
779 trailing,
780 )
781 }
782
783 fn incoming_row(&self, entity: &Entity<Self>, user: &User, palette: Palette) -> AnyElement {
784 self.user_row(
785 palette,
786 user,
787 [
788 row_button(
789 entity,
790 "accept_friend",
791 user.id,
792 palette,
793 IconName::Check,
794 w().sidebar.accept,
795 |yumush, id, window, cx| yumush.accept_friend(id, window, cx),
796 ),
797 row_button(
798 entity,
799 "decline_friend",
800 user.id,
801 palette,
802 IconName::X,
803 w().sidebar.decline,
804 |yumush, id, window, cx| yumush.remove_friend(id, window, cx),
805 ),
806 ],
807 )
808 .into_any_element()
809 }
810
811 fn outgoing_row(&self, entity: &Entity<Self>, user: &User, palette: Palette) -> AnyElement {
812 self.user_row(
813 palette,
814 user,
815 [row_button(
816 entity,
817 "cancel_friend",
818 user.id,
819 palette,
820 IconName::X,
821 w().sidebar.cancel,
822 |yumush, id, window, cx| yumush.remove_friend(id, window, cx),
823 )],
824 )
825 .into_any_element()
826 }
827
828 fn invitation_row(
829 &self,
830 entity: &Entity<Self>,
831 invitation: &Invitation,
832 palette: Palette,
833 ) -> AnyElement {
834 let community = &invitation.community;
835 let label = div().flex().flex_col().child(community.name.clone()).child(
836 div()
837 .text_size(text(text::CAPTION))
838 .text_color(palette.muted)
839 .child(w().sidebar.from_user(&invitation.inviter.username)),
840 );
841
842 entry(
843 palette,
844 false,
845 community_icon(
846 palette,
847 community,
848 px(size::ICON),
849 text(text::CAPTION),
850 &self.chat.avatars,
851 ),
852 label,
853 [
854 row_button(
855 entity,
856 "accept_invitation",
857 community.id,
858 palette,
859 IconName::Check,
860 w().sidebar.accept,
861 |yumush, id, window, cx| yumush.accept_invitation(id, window, cx),
862 ),
863 row_button(
864 entity,
865 "decline_invitation",
866 community.id,
867 palette,
868 IconName::X,
869 w().sidebar.decline,
870 |yumush, id, window, cx| yumush.decline_invitation(id, window, cx),
871 ),
872 ],
873 )
874 .into_any_element()
875 }
876
877 fn account_row(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {
878 let user = self.user.as_ref()?;
879 Some(
880 div()
881 .h(px(size::CONTROL))
882 .flex()
883 .items_center()
884 .gap(px(space::XS))
885 .child(self.account_trigger(entity, user, true, palette))
886 .children((self.is_builder() && self.chat.ghost).then(|| {
887 self.folding(
888 "builder_fold",
889 div().child(
890 icon_button(
891 "builder_button".to_string(),
892 IconName::Ghost,
893 w().sidebar.ghost_on,
894 Tone::Idle,
895 Scale::Small,
896 palette.tokens,
897 entity_action(entity, |yumush, window, cx| {
898 yumush.show_view(View::Builder, window, cx)
899 }),
900 )
901 .text_color(palette.tokens.hue(super::style::my_hue())),
902 ),
903 fade,
904 )
905 })),
906 )
907 }
908
909 fn account_trigger(
910 &self,
911 entity: &Entity<Self>,
912 user: &User,
913 named: bool,
914 palette: Palette,
915 ) -> impl IntoElement {
916 let face = if named { size::AVATAR } else { size::CONTROL };
917 let picture = avatar(
918 palette,
919 user,
920 px(face),
921 text(text::CAPTION),
922 &self.chat.avatars,
923 );
924 let picture = if named {
925 self.folding("avatar_face", picture, |picture, f| {
926 picture.size(px(lerp(size::AVATAR, size::CONTROL, f)))
927 })
928 } else {
929 picture.into_any_element()
930 };
931 let picture = presence_avatar(picture, self.presence_of(user.id), px(face), palette);
932 let picture = if named {
933 self.folding("avatar", picture, |picture, f| {
934 picture
935 .left(px(
936 f * (RAIL_CENTER - space::LG - space::SM - size::CONTROL / 2.)
937 ))
938 .top(px(f * (space::LG - space::MD - space::XXS)))
939 })
940 } else {
941 picture.into_any_element()
942 };
943 profile_popover(
944 "account_profile",
945 Anchor::BottomLeft,
946 user,
947 entity,
948 hoverable(
949 "account_trigger",
950 div()
951 .flex()
952 .items_center()
953 .when(named, |trigger| trigger.h(px(size::CONTROL)))
954 .gap(px(space::SM))
955 .p(px(if named { 0. } else { space::XXS }))
956 .when(named, |trigger| trigger.px(px(space::SM)))
957 .rounded(px(radius::MD))
958 .child(picture)
959 .when(named, |trigger| {
960 trigger.child(
961 self.folding(
962 "username_fold",
963 div()
964 .min_w_0()
965 .truncate()
966 .text_color(palette.muted)
967 .child(user.username.clone()),
968 fade,
969 ),
970 )
971 }),
972 palette,
973 ),
974 )
975 .when(named, |trigger| trigger.flex_1().min_w_0())
976 }
977
978 pub(super) fn open_community_settings(
979 &mut self,
980 community_id: Id,
981 window: &mut Window,
982 cx: &mut Context<Self>,
983 ) {
984 self.select_community(community_id, window, cx);
985 self.show_view(View::CommunitySettings, window, cx);
986 }
987}
988
989pub(super) fn watch_pill(
990 entity: &Entity<Yumush>,
991 user_id: Id,
992 kind: Kind,
993 watching: bool,
994 audio: Option<&std::collections::VecDeque<f32>>,
995 palette: Palette,
996) -> impl IntoElement {
997 let icon = match kind {
998 Kind::Camera => IconName::Video,
999 Kind::Screen => IconName::ScreenShare,
1000 };
1001 let tip = match (watching, kind) {
1002 (true, _) => w().sidebar.stop_watching,
1003 (false, Kind::Camera) => w().sidebar.watch_camera,
1004 (false, Kind::Screen) => w().sidebar.watch_screen,
1005 };
1006 clickable(
1007 format!("voice_watch_{user_id}_{kind:?}"),
1008 palette,
1009 entity_action(entity, move |yumush, window, cx| {
1010 yumush.toggle_viewer(user_id, kind, window, cx)
1011 }),
1012 )
1013 .tip(tip)
1014 .h(px(size::CHIP))
1015 .px(px(space::XS))
1016 .flex()
1017 .items_center()
1018 .gap(px(space::XS))
1019 .rounded(px(radius::SM))
1020 .children(audio.map(|audio| {
1021 div()
1022 .w(px(size::CONTROL))
1023 .h(px(space::LG))
1024 .child(super::parts::voice_line(
1025 Some(audio),
1026 super::parts::Voice::Live(palette.tokens.person(user_id)),
1027 palette.tokens,
1028 ))
1029 }))
1030 .child(super::parts::small_icon(icon).text_color(if watching {
1031 palette.text
1032 } else {
1033 palette.muted
1034 }))
1035}
1036
1037pub(super) fn unread_badge(
1038 palette: Palette,
1039 muted: bool,
1040 unread: Option<&Unread>,
1041) -> Option<AnyElement> {
1042 if muted {
1043 return Some(
1044 div()
1045 .text_color(palette.muted)
1046 .child(super::parts::small_icon(IconName::BellOff))
1047 .into_any_element(),
1048 );
1049 }
1050 let unread = unread.filter(|unread| unread.messages > 0)?;
1051 if unread.mentions == 0 {
1052 return Some(
1053 div()
1054 .size(px(space::XS + space::XXS))
1055 .rounded_full()
1056 .bg(palette.text)
1057 .into_any_element(),
1058 );
1059 }
1060 let count = match unread.messages {
1061 1..=99 => unread.messages.to_string(),
1062 _ => "99+".to_string(),
1063 };
1064 Some(
1065 div()
1066 .text_size(text(text::CAPTION))
1067 .text_color(palette.text)
1068 .child(count)
1069 .into_any_element(),
1070 )
1071}
1072
1073fn matches_query(name: &str, query: &str) -> bool {
1074 name.to_lowercase().contains(query)
1075}
1076
1077pub(super) fn input_box(input: &Entity<InputState>, palette: Palette) -> Div {
1078 compact_frame(palette)
1079 .gap(px(space::SM))
1080 .text_color(palette.muted)
1081 .child(super::parts::small_icon(IconName::Search))
1082 .child(bare_input(
1083 palette,
1084 Input::new(input).token(super::glyph::token),
1085 ))
1086}
1087
1088fn group(title: &'static str, palette: Palette, rows: Vec<AnyElement>) -> Option<Div> {
1089 (!rows.is_empty()).then(|| {
1090 div()
1091 .flex()
1092 .flex_col()
1093 .gap(px(space::XXS))
1094 .child(super::parts::caption_head(title, palette.tokens))
1095 .children(rows)
1096 })
1097}
1098
1099fn notes_tile(palette: Palette) -> AnyElement {
1100 div()
1101 .size(px(size::AVATAR))
1102 .flex_none()
1103 .flex()
1104 .items_center()
1105 .justify_center()
1106 .rounded(px(radius::SM))
1107 .bg(palette.tokens.press())
1108 .child(super::parts::small_icon(IconName::Bookmark).text_color(palette.muted))
1109 .into_any_element()
1110}
1111
1112fn room_row(
1113 palette: Palette,
1114 active: bool,
1115 face: Option<AnyElement>,
1116 label: String,
1117 trailing: Option<AnyElement>,
1118) -> Div {
1119 div()
1120 .h(px(size::CONTROL))
1121 .px(px(space::SM))
1122 .rounded(px(radius::MD))
1123 .flex()
1124 .items_center()
1125 .gap(px(space::SM))
1126 .text_color(if active { palette.text } else { palette.muted })
1127 .when(active, |row| row.font_weight(FontWeight::MEDIUM))
1128 .children(face)
1129 .child(div().flex_1().min_w_0().truncate().child(label))
1130 .children(trailing)
1131}
1132
1133fn entry(
1134 palette: Palette,
1135 active: bool,
1136 leading: impl IntoElement,
1137 label: impl IntoElement,
1138 trailing: impl IntoIterator<Item = AnyElement>,
1139) -> Div {
1140 div()
1141 .min_h(px(size::CONTROL))
1142 .py(px(space::XXS))
1143 .px(px(space::SM))
1144 .flex()
1145 .items_center()
1146 .gap(px(space::SM))
1147 .rounded(px(radius::MD))
1148 .text_color(if active { palette.text } else { palette.body })
1149 .when(active, |this| this.bg(palette.tokens.press()))
1150 .child(leading)
1151 .child(div().flex_1().min_w_0().truncate().child(label))
1152 .children(trailing)
1153}
1154
1155fn row_button(
1156 entity: &Entity<Yumush>,
1157 key: &str,
1158 id: Id,
1159 palette: Palette,
1160 icon: IconName,
1161 tip: &'static str,
1162 run: impl Fn(&mut Yumush, Id, &mut Window, &mut Context<Yumush>) + 'static,
1163) -> AnyElement {
1164 icon_button(
1165 format!("{key}_{id}"),
1166 icon,
1167 tip,
1168 Tone::Idle,
1169 Scale::Small,
1170 palette.tokens,
1171 entity_action(entity, move |yumush, window, cx| {
1172 run(yumush, id, window, cx)
1173 }),
1174 )
1175 .into_any_element()
1176}
1177
1178fn right_menu(
1179 id: impl Into<gpui_kit::ElementId>,
1180 entity: &Entity<Yumush>,
1181 trigger: impl IntoElement,
1182 rows: impl Fn(&Entity<PopoverState>, &App) -> Div + 'static,
1183) -> Popover {
1184 let disarm = entity.clone();
1185 Popover::new(id)
1186 .mouse_button(gpui_kit::MouseButton::Right)
1187 .on_open_change(move |_, _, cx| disarm.update(cx, |yumush, cx| yumush.disarm(cx)))
1188 .anchor(Anchor::TopLeft)
1189 .appearance(false)
1190 .trigger(super::Trigger::new(trigger))
1191 .content(move |_, _, cx| {
1192 let popover = cx.entity();
1193 let palette = super::palette(cx);
1194 super::parts::popover(palette.tokens)
1195 .w(px(size::SIDEBAR))
1196 .p(px(space::XS))
1197 .child(rows(&popover, cx))
1198 })
1199}
1200
1201#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
1202enum Doing {
1203 Call,
1204 Online,
1205 Offline,
1206}
1207
1208const RAIL_SHIFT: f32 = space::LG;
1209const RAIL_CENTER: f32 = (size::RAIL + RAIL_SHIFT) / 2.;
1210const S_ADVANCE: f32 = 0.511;
1211const LEADING: f32 = 1.4;
1212const BASELINE: f32 = (LEADING - 0.97 - 0.305) / 2. + 0.97;
1213const MARK_VIEW: f32 = 76.;
1214const WANDER: std::time::Duration = std::time::Duration::from_secs(10);
1215const LINGER: std::time::Duration = std::time::Duration::from_secs(6);
1216const TOW: std::time::Duration = std::time::Duration::from_millis(2300);
1217
1218fn lerp(from: f32, to: f32, f: f32) -> f32 {
1219 from + (to - from) * f
1220}
1221
1222fn fade<E: Styled>(element: E, f: f32) -> E {
1223 let shown = 1. - f;
1224 element.opacity(shown)
1225}
1226
1227fn logo_mark(palette: Palette) -> gpui_kit::Svg {
1228 gpui_kit::svg()
1229 .path(crate::logo::PATH)
1230 .size(px(size::CHIP))
1231 .flex_none()
1232 .text_color(palette.text)
1233}
1234
1235pub(super) fn wander(cx: &mut Context<Yumush>) {
1236 cx.spawn(async move |this, cx| {
1237 for wait in [WANDER, LINGER].into_iter().cycle() {
1238 cx.background_executor().timer(wait).await;
1239 let flipped = this.update(cx, |yumush, cx| {
1240 yumush.wordmark_flips += 1;
1241 yumush.wordmark_flipped = Some(std::time::Instant::now());
1242 cx.notify();
1243 });
1244 cx.background_executor().timer(TOW).await;
1245 if flipped.is_err() || this.update(cx, |_, cx| cx.notify()).is_err() {
1246 break;
1247 }
1248 }
1249 })
1250 .detach();
1251}
1252
1253fn towing(flipped: Option<std::time::Instant>) -> bool {
1254 flipped.is_some_and(|at| at.elapsed() < TOW)
1255}
1256
1257fn wordmark_tail(flips: u32, flipped: Option<std::time::Instant>, palette: Palette) -> AnyElement {
1258 let turkish = flips % 2 == 1;
1259 let em = super::style::text::TITLE / super::style::text::UI;
1260 if !towing(flipped) {
1261 return if turkish {
1262 div().child("ş")
1263 } else {
1264 div().relative().child("s").child(
1265 div()
1266 .absolute()
1267 .top_0()
1268 .left(gpui_kit::rems(S_ADVANCE * em))
1269 .child("h"),
1270 )
1271 }
1272 .into_any_element();
1273 }
1274 let (ink, ground) = (palette.text, palette.panel);
1275 div()
1276 .relative()
1277 .child("s")
1278 .with_animation(
1279 ("wordmark", flips),
1280 gpui_kit::Animation::new(TOW),
1281 move |tail, progress| {
1282 tail.child(
1283 tow_canvas(progress, turkish, ink, ground)
1284 .absolute()
1285 .top_0()
1286 .left_0()
1287 .size_full(),
1288 )
1289 },
1290 )
1291 .into_any_element()
1292}
1293
1294fn tow_canvas(progress: f32, turkish: bool, ink: Hsla, ground: Hsla) -> gpui_kit::Canvas<()> {
1295 gpui_kit::canvas(
1296 |_, _, _| {},
1297 move |bounds, _, window, _| {
1298 let em =
1299 f32::from(window.rem_size()) * super::style::text::TITLE / super::style::text::UI;
1300 let unit = em / 1000.;
1301 let left = f32::from(bounds.origin.x) - super::tow::S_X * unit;
1302 let baseline = f32::from(bounds.origin.y) + BASELINE * em;
1303 let rig = super::tow::Rig {
1304 x: -(size::CHIP + space::XXS + space::XS) / unit,
1305 y: ((LEADING * em - size::CHIP) / 2. - BASELINE * em) / unit,
1306 scale: size::CHIP / MARK_VIEW / unit,
1307 };
1308 let scene = super::tow::scene(&rig, progress, turkish, progress * TOW.as_secs_f32());
1309 let at = |[x, y]: super::tow::Point| {
1310 gpui_kit::point(px(left + x * unit), px(baseline + y * unit))
1311 };
1312 trace(
1313 window,
1314 scene.gap.iter().map(|p| at(*p)),
1315 scene.halo * unit,
1316 ground,
1317 );
1318 trace(
1319 window,
1320 scene.thread.iter().map(|p| at(*p)),
1321 scene.width * unit,
1322 ink,
1323 );
1324 let mut glyph = PathBuilder::fill();
1325 let mut points = scene.glyph.iter().map(|p| at(*p));
1326 if let Some(first) = points.next() {
1327 glyph.move_to(first);
1328 points.for_each(|point| glyph.line_to(point));
1329 glyph.close();
1330 if let Ok(glyph) = glyph.build() {
1331 window.paint_path(glyph, ink);
1332 }
1333 }
1334 },
1335 )
1336}
1337
1338fn trace(
1339 window: &mut Window,
1340 mut points: impl Iterator<Item = gpui_kit::Point<gpui_kit::Pixels>>,
1341 width: f32,
1342 color: Hsla,
1343) {
1344 let Some(first) = points.next() else {
1345 return;
1346 };
1347 let mut path =
1348 PathBuilder::fill().with_style(gpui_kit::PathStyle::Stroke(gpui_kit::StrokeOptions {
1349 line_width: width,
1350 line_cap: gpui_kit::LineCap::Round,
1351 line_join: gpui_kit::LineJoin::Round,
1352 ..Default::default()
1353 }));
1354 path.move_to(first);
1355 points.for_each(|point| path.line_to(point));
1356 if let Ok(path) = path.build() {
1357 window.paint_path(path, color);
1358 }
1359}