forge
Explore
Log in

Don't you dare go Hollow

yumush

Clone
★ 0

0 watching0 forksRustAGPL-3.010.6 MiB02871e1Tahinli24 minutes ago415 commits

profile.rs939 lines, 32.0 KiBHistoryRawDownload
1use super::account_list::account_list;
2use crate::gui::glyph::Fill as _;
3use crate::lang::{Label as _, w};
4use common::model::Id;
5use gpui_kit::prelude::FluentBuilder as _;
6use std::{
7 collections::{HashMap, VecDeque},
8 sync::Arc,
9};
10
11use common::{
12 call::{BanMember, DeleteUser, Kick, SetRank, UpdatePresence},
13 model::{Presence, Rank, User},
14 permission,
15};
16use gpui_kit::{
17 Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, IntoElement,
18 ParentElement, SharedString, Stateful, StatefulInteractiveElement, StyleRefinement, Styled,
19 Window,
20 assets::IconName,
21 component::{
22 WindowExt,
23 input::InputState,
24 popover::{Popover, PopoverState},
25 slider::SliderState,
26 },
27 div, px,
28};
29
30use super::chat::{Armed, CardMenu, ReportTarget, View};
31use super::message_actions::report_bar;
32use super::parts::{
33 Ink, Scale, Text, Tone, Voice, band, icon_button, small_icon, stack, voice_line, words,
34};
35use super::social::Relation;
36use super::style::{Tokens, radius, size, space, stroke, text};
37use super::widget::spawn_done;
38use super::{
39 Tooltip as _, Trigger, Yumush, avatar, clickable, entity_action, input_dialog, millis_time,
40 notify_error, text,
41};
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44enum Removal {
45 Kick,
46 Ban,
47}
48
49impl Removal {
50 fn title(self) -> &'static str {
51 let w = &w().profile;
52 match self {
53 Removal::Kick => w.kick,
54 Removal::Ban => w.ban,
55 }
56 }
57}
58
59pub(super) fn user_link(
60 id: impl Into<ElementId>,
61 user: Option<&User>,
62 entity: &Entity<Yumush>,
63 trigger: impl IntoElement,
64) -> AnyElement {
65 match user {
66 Some(user) => profile_popover(
67 id,
68 Anchor::LeftCenter,
69 user,
70 entity,
71 div().min_w_0().cursor_pointer().child(trigger),
72 )
73 .trigger_style(StyleRefinement::default().min_w_0())
74 .into_any_element(),
75 None => trigger.into_any_element(),
76 }
77}
78
79pub(super) fn profile_popover(
80 id: impl Into<ElementId>,
81 anchor: Anchor,
82 user: &User,
83 entity: &Entity<Yumush>,
84 trigger: impl IntoElement,
85) -> Popover {
86 let user = user.clone();
87 let entity = entity.clone();
88 let notify_entity = entity.clone();
89 let volume_user_id = user.id;
90
91 Popover::new(id)
92 .anchor(anchor)
93 .appearance(false)
94 .on_open_change(move |_, _, cx| {
95 notify_entity.update(cx, |yumush, cx| {
96 yumush.chat.session.card_menu = CardMenu::Main;
97 yumush.chat.session.armed = None;
98 yumush.open_user_volume(volume_user_id, cx);
99 cx.notify()
100 })
101 })
102 .trigger(Trigger::new(trigger))
103 .content(move |_, _, cx| {
104 let yumush = entity.read(cx);
105 let card = Card {
106 is_self: yumush
107 .user
108 .as_ref()
109 .is_some_and(|viewer| viewer.id == user.id),
110 deletable: yumush.user.as_ref().is_some_and(|viewer| {
111 permission::can_delete_user(viewer.role, false, user.role)
112 }),
113 actor: yumush.actor_rank(),
114 target: yumush.chat.rank_of(&user),
115 relation: yumush.relation(user.id),
116 card_menu: yumush.chat.session.card_menu,
117 presence: yumush.presence_of(user.id),
118 armed: yumush.chat.session.armed.clone(),
119 reporting: yumush.chat.session.report == Some(ReportTarget::User(user.id)),
120 reason: yumush.chat.report_reason.clone(),
121 status: yumush.chat.status_input.clone(),
122 volume: yumush
123 .chat
124 .session
125 .volume_popover
126 .as_ref()
127 .filter(|volume| volume.user_id == user.id)
128 .map(|volume| (volume.slider.clone(), yumush.user_volume(user.id))),
129 call: yumush.call_of(user.id).map(|community| {
130 if community.kind.is_direct() {
131 w().profile.a_call.to_string()
132 } else {
133 community.name.clone()
134 }
135 }),
136 wave: yumush
137 .chat
138 .session
139 .waves
140 .voice(user.id)
141 .map(|bars| bars.iter().copied().collect()),
142 speaking: yumush.chat.session.waves.speaking.contains(&user.id),
143 user: user.clone(),
144 };
145
146 card.render(
147 &entity,
148 cx.entity(),
149 Tokens::of(cx),
150 &yumush.chat.session.avatars,
151 )
152 })
153}
154
155struct Card {
156 user: User,
157 call: Option<String>,
158 wave: Option<VecDeque<f32>>,
159 speaking: bool,
160 is_self: bool,
161 deletable: bool,
162 actor: Option<Rank>,
163 target: Option<Rank>,
164 relation: Relation,
165 card_menu: CardMenu,
166 presence: Presence,
167 armed: Option<Armed>,
168 reporting: bool,
169 reason: Entity<InputState>,
170 status: Entity<InputState>,
171 volume: Option<(Entity<SliderState>, f32)>,
172}
173
174impl Card {
175 fn social_rows(
176 &self,
177 entity: &Entity<Yumush>,
178 popover: &Entity<PopoverState>,
179 t: Tokens,
180 ) -> Vec<AnyElement> {
181 let user_id = self.user.id;
182 let message_id = user_id;
183 let mut rows = vec![
184 menu_row(
185 "profile_message",
186 w().profile.message,
187 small_icon(IconName::MessageSquare),
188 t.paper(),
189 t,
190 yumush_action(entity, popover, move |yumush, window, cx| {
191 yumush.open_direct(message_id, window, cx)
192 }),
193 )
194 .into_any_element(),
195 menu_row(
196 "profile_call",
197 w().profile.call,
198 small_icon(IconName::Phone),
199 t.paper(),
200 t,
201 yumush_action(entity, popover, move |yumush, window, cx| {
202 yumush.call_direct(message_id, window, cx)
203 }),
204 )
205 .into_any_element(),
206 ];
207
208 let report_user_id = self.user.id;
209 rows.push(
210 menu_row(
211 "profile_report",
212 w().profile.report,
213 small_icon(IconName::TriangleAlert),
214 t.bad(),
215 t,
216 entity_action(entity, move |yumush, window, cx| {
217 yumush.start_report(ReportTarget::User(report_user_id), window, cx)
218 }),
219 )
220 .into_any_element(),
221 );
222
223 if let Some((label, icon)) = self.relation.action() {
224 let relation = self.relation;
225 rows.push(
226 menu_row(
227 "profile_friend",
228 label,
229 small_icon(icon),
230 t.paper(),
231 t,
232 yumush_action(entity, popover, move |yumush, window, cx| {
233 yumush.friend_action(relation, user_id, window, cx)
234 }),
235 )
236 .into_any_element(),
237 );
238 }
239
240 rows
241 }
242
243 fn render(
244 self,
245 entity: &Entity<Yumush>,
246 popover: Entity<PopoverState>,
247 t: Tokens,
248 avatars: &HashMap<Id, Arc<Image>>,
249 ) -> Div {
250 let is_self = self.is_self;
251 let actions = if is_self {
252 div()
253 .flex()
254 .flex_col()
255 .gap(px(space::XS))
256 .children(main_self_rows(self.armed, entity, &popover, t))
257 .into_any_element()
258 } else {
259 let mut rows = self.social_rows(entity, &popover, t);
260 rows.extend(self.moderation_rows(entity, &popover, t));
261 if self.card_menu == CardMenu::More {
262 div()
263 .flex()
264 .flex_col()
265 .gap(px(space::XS))
266 .children(rows)
267 .into_any_element()
268 } else {
269 let first = rows.remove(0);
270 let second = rows.remove(0);
271 band(space::XS)
272 .child(first)
273 .child(second)
274 .child(div().flex_1())
275 .child(icon_button(
276 "profile_more",
277 IconName::Ellipsis,
278 w().profile.more,
279 Tone::Idle,
280 Scale::Normal,
281 t,
282 card_menu_action(entity, CardMenu::More),
283 ))
284 .into_any_element()
285 }
286 };
287 let location = match &self.call {
288 Some(room) => w().profile.in_room(room),
289 None => self.presence.label().to_lowercase(),
290 };
291 let place = match self.target {
292 Some(Rank::Builder) => {
293 let badge = band(space::XXS)
294 .child(small_icon(IconName::Shield).text_color(t.paper()))
295 .child(
296 words(Rank::Builder.label(), Text::Caption, Ink::Faint, t)
297 .text_color(t.paper()),
298 );
299 if is_self {
300 clickable(
301 "profile_builder",
302 t,
303 yumush_action(entity, &popover, |yumush, window, cx| {
304 yumush.show_view(View::Builder, window, cx)
305 }),
306 )
307 .rounded(px(radius::SM))
308 .child(badge)
309 .into_any_element()
310 } else {
311 badge.into_any_element()
312 }
313 }
314 Some(rank @ (Rank::Moderator | Rank::Admin | Rank::Owner)) => {
315 words(rank.label(), Text::Caption, Ink::Faint, t).into_any_element()
316 }
317 _ => words(location, Text::Caption, Ink::Faint, t).into_any_element(),
318 };
319 let tint = match self.presence {
320 Presence::Offline => t.off(),
321 _ => t.person(self.user.id),
322 };
323 let line = if self.call.is_some() {
324 div()
325 .h(px(space::LG))
326 .child(voice_line(
327 self.wave.as_ref(),
328 if self.speaking {
329 Voice::Live(t.person(self.user.id))
330 } else {
331 Voice::Quiet
332 },
333 t,
334 ))
335 .into_any_element()
336 } else {
337 div()
338 .w_full()
339 .h(px(stroke::LINE))
340 .bg(tint)
341 .into_any_element()
342 };
343 let caption = band(space::SM).justify_between().child(place).child(words(
344 millis_time(self.user.created_at, crate::lang::w().common.day_year),
345 Text::Caption,
346 Ink::Faint,
347 t,
348 ));
349
350 super::parts::popover(t)
351 .w(px(size::POPOVER))
352 .gap(px(space::LG))
353 .child(
354 band(space::LG)
355 .child(
356 super::zoomable(
357 entity,
358 "profile_picture",
359 avatar(
360 t,
361 &self.user,
362 px(size::AVATAR_LG),
363 text(text::BODY),
364 avatars,
365 ),
366 super::Zoom::new(
367 self.user.avatar_id.and_then(|id| avatars.get(&id)).cloned(),
368 true,
369 self.user.username.clone(),
370 ),
371 )
372 .on_click({
373 let popover = popover.clone();
374 move |_, window, cx| {
375 popover.update(cx, |state, cx| state.dismiss(window, cx));
376 }
377 })
378 .map(|picture| {
379 if is_self {
380 div().relative().flex_shrink_0().child(picture).child(
381 div()
382 .absolute()
383 .right(px(-space::XXS))
384 .bottom(px(-space::XXS))
385 .child(presence_menu(self.presence, entity, t)),
386 )
387 } else {
388 super::presence_avatar(
389 picture,
390 self.presence,
391 px(size::AVATAR_LG),
392 t,
393 )
394 }
395 }),
396 )
397 .child(
398 stack(space::XXS)
399 .flex_1()
400 .min_w_0()
401 .child(
402 band(space::XS)
403 .child(
404 words(
405 self.user.username.clone(),
406 Text::Body,
407 Ink::Paper,
408 t,
409 )
410 .font_weight(FontWeight::MEDIUM)
411 .min_w_0()
412 .truncate(),
413 )
414 .when(is_self, |name| {
415 name.child(account_menu(entity, &popover, t))
416 }),
417 )
418 .map(|names| {
419 if !is_self {
420 return names.children((!self.user.status.is_empty()).then(
421 || {
422 words(
423 self.user.status.clone(),
424 Text::Caption,
425 Ink::Dim,
426 t,
427 )
428 },
429 ));
430 }
431 if self.card_menu == CardMenu::Status {
432 let status = self.status.clone();
433 return names.child(
434 div()
435 .flex()
436 .items_center()
437 .border_b(px(stroke::LINE))
438 .border_color(t.paper())
439 .child(
440 super::widget::bare_input(
441 t,
442 gpui_kit::component::input::Input::new(
443 &self.status,
444 )
445 .token(super::glyph::token),
446 )
447 .text_size(text(text::CAPTION))
448 .px_0()
449 .flex_1(),
450 )
451 .child(super::glyph::picker_button(
452 "status_emoji",
453 entity,
454 t,
455 super::glyph::insert_into(status),
456 )),
457 );
458 }
459 names.child(
460 band(space::XS)
461 .children((!self.user.status.is_empty()).then(|| {
462 words(
463 self.user.status.clone(),
464 Text::Caption,
465 Ink::Dim,
466 t,
467 )
468 .min_w_0()
469 .truncate()
470 }))
471 .child(edit_status(entity, &self.user.status, t)),
472 )
473 }),
474 ),
475 )
476 .child(stack(space::XS).child(line).child(caption))
477 .children(self.volume.clone().map(|(slider, volume)| {
478 let user_id = self.user.id;
479 band(space::SM)
480 .child(icon_button(
481 "profile_mute",
482 if volume == 0. {
483 IconName::VolumeX
484 } else {
485 IconName::Volume2
486 },
487 w().profile.mute,
488 Tone::Idle,
489 Scale::Normal,
490 t,
491 entity_action(entity, move |yumush, window, cx| {
492 yumush.toggle_user_mute(user_id, window, cx)
493 }),
494 ))
495 .child(super::parts::slider(&slider, t))
496 .child(
497 words(format!("{volume:.0}%"), Text::Caption, Ink::Dim, t)
498 .w(px(size::CONTROL))
499 .text_right(),
500 )
501 }))
502 .children(self.reporting.then(|| report_bar(&self.reason, entity, t)))
503 .child(actions)
504 }
505
506 fn moderation_rows(
507 &self,
508 entity: &Entity<Yumush>,
509 popover: &Entity<PopoverState>,
510 t: Tokens,
511 ) -> Vec<AnyElement> {
512 let actor = self.actor;
513 let target = self.target;
514 let user_id = self.user.id;
515 let mut rows = Vec::new();
516
517 for rank in [Rank::Member, Rank::Moderator, Rank::Admin] {
518 if target != Some(rank) && permission::can_set_rank(actor, target, rank) {
519 let label = w().profile.make_rank(rank.label().to_lowercase());
520 rows.push(
521 menu_row(
522 label.clone(),
523 label,
524 small_icon(IconName::Shield),
525 t.paper(),
526 t,
527 yumush_action(entity, popover, move |yumush, window, cx| {
528 yumush.set_member_rank(user_id, rank, window, cx)
529 }),
530 )
531 .into_any_element(),
532 );
533 }
534 }
535
536 if permission::can_moderate(actor, target) {
537 for (id, removal, icon) in [
538 ("kick", Removal::Kick, IconName::Close),
539 ("ban", Removal::Ban, IconName::Ban),
540 ] {
541 rows.push(
542 menu_row(
543 id,
544 removal.title(),
545 small_icon(icon),
546 t.bad(),
547 t,
548 yumush_action(entity, popover, move |yumush, window, cx| {
549 yumush.open_removal(user_id, removal, window, cx)
550 }),
551 )
552 .into_any_element(),
553 );
554 }
555 }
556
557 if self.deletable {
558 let armed = Armed::DeleteUser(user_id);
559 let label = if self.armed == Some(armed.clone()) {
560 w().common.confirm
561 } else {
562 w().profile.delete_user
563 };
564
565 rows.push(
566 menu_row(
567 "delete_user",
568 label,
569 small_icon(IconName::Trash),
570 t.bad(),
571 t,
572 armed_action(armed, entity, popover, move |yumush, window, cx| {
573 yumush.delete_member_account(user_id, window, cx)
574 }),
575 )
576 .into_any_element(),
577 );
578 }
579
580 rows
581 }
582}
583
584fn main_self_rows(
585 armed: Option<Armed>,
586 entity: &Entity<Yumush>,
587 popover: &Entity<PopoverState>,
588 t: Tokens,
589) -> Vec<AnyElement> {
590 vec![
591 menu_row(
592 "profile_settings",
593 w().profile.settings,
594 small_icon(IconName::Settings),
595 t.paper(),
596 t,
597 yumush_action(entity, popover, |yumush, window, cx| {
598 yumush.show_view(View::Settings, window, cx)
599 }),
600 )
601 .into_any_element(),
602 menu_row(
603 "profile_logout",
604 if armed == Some(Armed::LogOut) {
605 w().common.confirm
606 } else {
607 w().profile.log_out
608 },
609 small_icon(IconName::LogOut),
610 t.bad(),
611 t,
612 armed_action(Armed::LogOut, entity, popover, |yumush, window, cx| {
613 yumush.logout(window, cx)
614 }),
615 )
616 .into_any_element(),
617 ]
618}
619
620fn account_menu(entity: &Entity<Yumush>, card: &Entity<PopoverState>, t: Tokens) -> Popover {
621 let entity = entity.clone();
622 let card = card.clone();
623 Popover::new("account_menu")
624 .anchor(Anchor::TopLeft)
625 .appearance(false)
626 .trigger(Trigger::new(
627 clickable("profile_accounts", t, |_, _| {})
628 .tip(w().profile.accounts)
629 .rounded(px(radius::SM))
630 .flex_shrink_0()
631 .child(small_icon(IconName::ChevronDown).text_color(t.dim())),
632 ))
633 .content(move |_, _, cx| {
634 let yumush = entity.read(cx);
635 super::parts::popover(t)
636 .p(px(space::XS))
637 .w(px(size::SIDEBAR))
638 .child(account_list(yumush, &entity, Some(card.clone()), t, cx))
639 .child(menu_row(
640 "profile_add_account",
641 w().profile.add_account,
642 small_icon(IconName::UserPlus),
643 t.paper(),
644 t,
645 yumush_action(&entity, &card, |yumush, window, cx| {
646 yumush.add_account(window, cx)
647 }),
648 ))
649 })
650}
651
652fn edit_status(entity: &Entity<Yumush>, status: &str, t: Tokens) -> impl IntoElement {
653 let status = status.to_string();
654 clickable(
655 "edit_status",
656 t,
657 entity_action(entity, move |yumush, window, cx| {
658 yumush.chat.session.card_menu = CardMenu::Status;
659 yumush.chat.status_input.update(cx, |input, cx| {
660 input.fill(status.clone(), window, cx);
661 input.focus(window, cx);
662 });
663 cx.notify();
664 }),
665 )
666 .tip(w().profile.edit_status)
667 .flex_none()
668 .p(px(space::XXS))
669 .rounded(px(radius::SM))
670 .child(small_icon(IconName::Pencil).text_color(t.faint()))
671}
672
673fn card_menu_action(
674 entity: &Entity<Yumush>,
675 menu: CardMenu,
676) -> impl Fn(&mut Window, &mut App) + 'static {
677 entity_action(entity, move |yumush, _, cx| {
678 yumush.chat.session.card_menu = menu;
679 cx.notify();
680 })
681}
682
683pub(super) fn yumush_action(
684 entity: &Entity<Yumush>,
685 popover: &Entity<PopoverState>,
686 run: impl Fn(&mut Yumush, &mut Window, &mut Context<Yumush>) + 'static,
687) -> impl Fn(&mut Window, &mut App) + 'static {
688 let entity = entity.clone();
689 let popover = popover.clone();
690
691 move |window, cx| {
692 popover.update(cx, |state, cx| state.dismiss(window, cx));
693 entity.update(cx, |yumush, cx| run(yumush, window, cx));
694 }
695}
696
697pub(super) fn armed_action(
698 armed: Armed,
699 entity: &Entity<Yumush>,
700 popover: &Entity<PopoverState>,
701 run: impl Fn(&mut Yumush, &mut Window, &mut Context<Yumush>) + 'static,
702) -> impl Fn(&mut Window, &mut App) + 'static {
703 let entity = entity.clone();
704 let popover = popover.clone();
705
706 move |window, cx| {
707 if entity.update(cx, |yumush, cx| yumush.arm(armed.clone(), cx)) {
708 popover.update(cx, |state, cx| state.dismiss(window, cx));
709 entity.update(cx, |yumush, cx| run(yumush, window, cx));
710 }
711 }
712}
713
714fn presence_dot(presence: Presence, t: Tokens) -> Div {
715 div()
716 .size(px(space::LG))
717 .rounded_full()
718 .border_2()
719 .border_color(t.raise())
720 .bg(super::presence_color(presence, t))
721}
722
723fn presence_menu(current: Presence, entity: &Entity<Yumush>, t: Tokens) -> Popover {
724 let entity = entity.clone();
725 Popover::new("presence_menu")
726 .anchor(Anchor::TopLeft)
727 .appearance(false)
728 .trigger(Trigger::new(
729 clickable("presence_dot", t, |_, _| {})
730 .rounded_full()
731 .child(presence_dot(current, t)),
732 ))
733 .content(move |_, _, cx| {
734 let popover = cx.entity();
735 super::parts::popover(t)
736 .p(px(space::XS))
737 .children(Presence::ALL.into_iter().map(|presence| {
738 let popover = popover.clone();
739 menu_row(
740 ("presence", presence as usize),
741 presence.label(),
742 div()
743 .size(px(size::ICON_SM))
744 .flex()
745 .items_center()
746 .justify_center()
747 .child(
748 div()
749 .size(px(space::SM))
750 .rounded_full()
751 .bg(super::presence_color(presence, t)),
752 ),
753 if presence == current {
754 t.paper()
755 } else {
756 t.dim()
757 },
758 t,
759 {
760 let entity = entity.clone();
761 move |window, cx| {
762 popover.update(cx, |state, cx| state.dismiss(window, cx));
763 entity.update(cx, |yumush, cx| {
764 yumush.set_presence(presence, window, cx)
765 });
766 }
767 },
768 )
769 }))
770 })
771}
772
773pub(super) fn menu_row(
774 id: impl Into<ElementId>,
775 label: impl Into<SharedString>,
776 leading: impl IntoElement,
777 color: Hsla,
778 t: Tokens,
779 on_click: impl Fn(&mut Window, &mut App) + 'static,
780) -> Stateful<Div> {
781 clickable(id, t, on_click)
782 .h(px(size::CONTROL))
783 .px(px(space::SM))
784 .flex()
785 .items_center()
786 .gap(px(space::SM))
787 .rounded(px(radius::MD))
788 .text_color(color)
789 .child(leading)
790 .child(label.into())
791}
792
793impl Yumush {
794 fn open_removal(
795 &self,
796 user_id: Id,
797 removal: Removal,
798 window: &mut Window,
799 cx: &mut Context<Self>,
800 ) {
801 let Some(community_id) = self.chat.session.selected_community_id else {
802 return;
803 };
804 input_dialog(
805 removal.title(),
806 removal.title(),
807 w().profile.reason_optional,
808 window,
809 cx,
810 move |this, text, window, cx| {
811 let reason = text.trim().to_string();
812 let reason = (!reason.is_empty()).then_some(reason);
813 this.remove_member(community_id, user_id, removal, reason, window, cx);
814 },
815 );
816 }
817
818 fn remove_member(
819 &self,
820 community_id: Id,
821 user_id: Id,
822 removal: Removal,
823 reason: Option<String>,
824 window: &mut Window,
825 cx: &mut Context<Self>,
826 ) {
827 let network = self.network.clone();
828
829 cx.spawn_in(window, async move |this, cx| {
830 let result = match removal {
831 Removal::Kick => {
832 network
833 .call(Kick {
834 community_id,
835 user_id,
836 reason,
837 })
838 .await
839 }
840 Removal::Ban => {
841 network
842 .call(BanMember {
843 community_id,
844 user_id,
845 reason,
846 })
847 .await
848 }
849 };
850 match result {
851 Ok(()) => {
852 let _ = this.update_in(cx, |yumush, window, cx| {
853 window.close_dialog(cx);
854 if removal == Removal::Ban {
855 yumush.load_bans(window, cx);
856 }
857 });
858 }
859 Err(error) => notify_error(&this, cx, error),
860 }
861 })
862 .detach();
863 }
864
865 pub(super) fn set_member_rank(
866 &self,
867 user_id: Id,
868 rank: Rank,
869 window: &mut Window,
870 cx: &mut Context<Self>,
871 ) {
872 let Some(community_id) = self.chat.session.selected_community_id else {
873 return;
874 };
875 let network = self.network.clone();
876
877 spawn_done(window, cx, async move {
878 network
879 .call(SetRank {
880 community_id,
881 user_id,
882 rank,
883 })
884 .await
885 });
886 }
887
888 pub(super) fn set_presence(
889 &mut self,
890 presence: Presence,
891 window: &mut Window,
892 cx: &mut Context<Self>,
893 ) {
894 let me = self.user.as_ref().map(|me| me.id);
895 let before = me.map(|me| self.presence_of(me));
896 if let Some(me) = me {
897 self.chat.session.presences.insert(me, presence);
898 }
899 self.chat.session.card_menu = CardMenu::Main;
900 cx.notify();
901
902 let network = self.network.clone();
903
904 cx.spawn_in(window, async move |this, cx| {
905 if let Err(error) = network.call(UpdatePresence { presence }).await {
906 let _ = this.update(cx, |yumush, cx| {
907 if let (Some(me), Some(before)) = (me, before) {
908 yumush.chat.session.presences.insert(me, before);
909 }
910 cx.notify();
911 });
912 notify_error(&this, cx, error);
913 }
914 })
915 .detach();
916 }
917
918 pub(super) fn delete_member_account(
919 &mut self,
920 user_id: Id,
921 window: &mut Window,
922 cx: &mut Context<Self>,
923 ) {
924 let network = self.network.clone();
925
926 cx.spawn_in(window, async move |this, cx| {
927 match network.call(DeleteUser { user_id }).await {
928 Ok(()) => {
929 let _ = this.update(cx, |yumush, cx| {
930 yumush.chat.remove_member(user_id);
931 cx.notify();
932 });
933 }
934 Err(error) => notify_error(&this, cx, error),
935 }
936 })
937 .detach();
938 }
939}