use common::model::Id; use std::{future::Future, time::Duration}; use common::{ call::{ BanUser, ClearProfile, CreateUser, DeleteUser, FollowStats, ListSessions, ListUpdateClients, PurgeUser, RenameUser, ResetPassword, RevokeSession, RevokeSessions, SuspendUser, TimeoutUser, }, model::{ Account, BanScope, Hue, Role, SessionInfo, Suspension, UpdateClient, UpdateState, User, }, permission, stats::Stats, time::{DAY_MILLIS, HOUR_MILLIS, MINUTE_MILLIS, now_ms}, }; use gpui_kit::{ Anchor, AnyElement, App, Context, Div, Entity, FontWeight, InteractiveElement as _, IntoElement, ParentElement, StatefulInteractiveElement as _, Styled, Window, assets::IconName, component::{Icon, popover::Popover}, div, prelude::FluentBuilder as _, px, }; use super::BuilderTab; use super::ui::{ action_button, action_group, caption_text, card, confirm_button, meter, number, pill, rows_body, }; use crate::gui::chat::{Armed, admin::UserEdit}; use crate::lang::w; use crate::{ gui::{ Tooltip as _, Yumush, avatar, clickable, entity_action, millis_time, notify_error, parts::{self, Press}, profile::user_link, style::{Tokens, radius, size, space, text}, text, widget::{field, search_text}, }, net::{Fail, NetworkHandle}, }; const FRIENDS_MAX_H: f32 = 200.; const CLIENTS_TICK: Duration = Duration::from_secs(1); const MINUTES_PER_HOUR: u64 = HOUR_MILLIS / MINUTE_MILLIS; const MINUTES_PER_DAY: u64 = DAY_MILLIS / MINUTE_MILLIS; fn seen_text(last_seen: Option) -> String { let Some(last_seen) = last_seen else { return w().builder_users.seen_never.to_string(); }; let minutes = now_ms().saturating_sub(last_seen) / MINUTE_MILLIS; match minutes { 0 => w().builder_users.seen_now.to_string(), 1..MINUTES_PER_HOUR => w().builder_users.seen_minutes(minutes), MINUTES_PER_HOUR..MINUTES_PER_DAY => { w().builder_users.seen_hours(minutes / MINUTES_PER_HOUR) } _ => millis_time(last_seen, crate::lang::w().common.day), } } fn status(label: &str, color: gpui_kit::Hsla) -> Div { div().flex_shrink_0().child(pill(label, color)) } fn form_row( input: &Entity, t: Tokens, actions: impl IntoIterator, ) -> Div { div() .h(px(size::ROW)) .px(px(space::MD)) .flex() .items_center() .gap(px(space::SM)) .child(div().flex_1().min_w_0().child(field(t, input))) .children(actions) } impl Yumush { pub(super) fn submit_new_user(&mut self, window: &mut Window, cx: &mut Context) { let username = self.chat.admin.new_username.read(cx).text().to_string(); let password = self.chat.admin.new_password.read(cx).text().to_string(); self.chat .admin .new_password .update(cx, |input, cx| input.set_value("", window, cx)); let network = self.network.clone(); cx.spawn_in(window, async move |this, cx| { match network.call(CreateUser { username, password }).await { Ok(_) => { let _ = this.update_in(cx, |yumush, window, cx| { yumush .chat .admin .new_username .update(cx, |input, cx| input.set_value("", window, cx)); yumush.load_users(window, cx); }); } Err(error) => notify_error(&this, cx, error), } }) .detach(); } pub(super) fn delete_builder_user( &mut self, user_id: Id, window: &mut Window, cx: &mut Context, ) { if !self.arm(Armed::BuilderDeleteUser(user_id), cx) { return; } let network = self.network.clone(); cx.spawn_in(window, async move |this, cx| { match network.call(DeleteUser { user_id }).await { Ok(()) => { let _ = this.update(cx, |yumush, cx| { yumush .chat .admin .builder_users .retain(|account| account.user.id != user_id); if yumush.sessions_open(user_id) { yumush.close_builder_sessions(); } cx.notify(); }); } Err(error) => notify_error(&this, cx, error), } }) .detach(); } pub(super) fn builder_user_action( &mut self, window: &mut Window, cx: &mut Context, action: impl FnOnce(NetworkHandle) -> Fut + 'static, done: impl FnOnce(&mut Self, &mut Window, &mut Context) + 'static, ) where Fut: Future> + 'static, { let network = self.network.clone(); cx.spawn_in(window, async move |this, cx| match action(network).await { Ok(()) => { let _ = this.update_in(cx, |yumush, window, cx| { done(yumush, window, cx); yumush.load_users(window, cx); }); } Err(error) => notify_error(&this, cx, error), }) .detach(); } pub(super) fn suspend_builder_user( &mut self, user_id: Id, suspended: bool, window: &mut Window, cx: &mut Context, ) { self.builder_user_action( window, cx, move |network| async move { network.call(SuspendUser { user_id, suspended }).await }, |_, _, _| {}, ); } pub(super) fn revoke_builder_sessions( &mut self, user_id: Id, window: &mut Window, cx: &mut Context, ) { self.builder_user_action( window, cx, move |network| async move { network.call(RevokeSessions { user_id }).await }, |_, _, _| {}, ); } pub(super) fn clear_builder_profile( &mut self, user_id: Id, window: &mut Window, cx: &mut Context, ) { self.builder_user_action( window, cx, move |network| async move { network.call(ClearProfile { user_id }).await.map(|_| ()) }, |_, _, _| {}, ); } pub(super) fn toggle_builder_stats(&mut self, user_id: Id, cx: &mut Context) { let target = match self.chat.session.followed { Some((id, _)) if id == user_id => None, _ => Some(user_id), }; self.chat.session.followed = target.map(|id| (id, Stats::default())); let network = self.network.clone(); cx.spawn(async move |this, cx| { let latest = network.call(FollowStats { user_id: target }).await; let _ = this.update(cx, |yumush, cx| { if let (Ok(Some(stats)), Some(followed)) = (latest, yumush.chat.session.followed.as_mut()) && Some(followed.0) == target { followed.1 = stats; } cx.notify(); }); }) .detach(); cx.notify(); } pub(super) fn toggle_user_edit(&mut self, user_id: Id, edit: UserEdit, cx: &mut Context) { let target = Some((user_id, edit)); self.chat.admin.editing = if self.chat.admin.editing == target { None } else { target }; cx.notify(); } fn edit_open(&self, user_id: Id, edit: UserEdit) -> bool { self.chat.admin.editing == Some((user_id, edit)) } pub(super) fn reset_builder_password(&mut self, window: &mut Window, cx: &mut Context) { let Some((user_id, UserEdit::Password)) = self.chat.admin.editing else { return; }; let password = self.chat.admin.builder_password.read(cx).text().to_string(); self.builder_user_action( window, cx, move |network| async move { network.call(ResetPassword { user_id, password }).await }, |yumush, window, cx| { yumush.chat.admin.editing = None; yumush .chat .admin .builder_password .update(cx, |input, cx| input.set_value("", window, cx)); }, ); } pub(super) fn load_sessions(&self, user_id: Id, window: &mut Window, cx: &mut Context) { let network = self.network.clone(); cx.spawn_in(window, async move |this, cx| { let friends = network .call(common::call::ListUserFriends { user_id }) .await .unwrap_or_default(); match network.call(ListSessions { user_id }).await { Ok(sessions) => { let _ = this.update(cx, |yumush, cx| { yumush.chat.admin.builder_sessions = Some((user_id, sessions)); yumush.chat.admin.builder_friends = friends; cx.notify(); }); } Err(error) => notify_error(&this, cx, error), } }) .detach(); } fn sessions_open(&self, user_id: Id) -> bool { self.chat .admin .builder_sessions .as_ref() .is_some_and(|(open, _)| *open == user_id) } fn close_builder_sessions(&mut self) { self.chat.admin.builder_sessions = None; self.chat.admin.builder_clients.clear(); self.chat.admin.builder_clients_task = None; } pub(super) fn toggle_builder_sessions( &mut self, user_id: Id, window: &mut Window, cx: &mut Context, ) { if let Some((followed, _)) = self.chat.session.followed { self.toggle_builder_stats(followed, cx); } if self.sessions_open(user_id) { self.close_builder_sessions(); cx.notify(); return; } self.load_sessions(user_id, window, cx); self.chat.admin.builder_clients.clear(); self.watch_builder_clients(user_id, cx); } fn watch_builder_clients(&mut self, user_id: Id, cx: &mut Context) { let network = self.network.clone(); self.chat.admin.builder_clients_task = Some(cx.spawn(async move |this, cx| { loop { let Ok(visible) = this.update(cx, |yumush, _| yumush.on_builder_tab(BuilderTab::Users)) else { break; }; if visible && let Ok(clients) = network.call(ListUpdateClients { user_id }).await { let _ = this.update(cx, |yumush, cx| { yumush.chat.admin.builder_clients = clients; cx.notify(); }); } cx.background_executor().timer(CLIENTS_TICK).await; } })); } pub(super) fn revoke_builder_session( &mut self, user_id: Id, session_id: Id, window: &mut Window, cx: &mut Context, ) { let network = self.network.clone(); cx.spawn_in(window, async move |this, cx| { match network .call(RevokeSession { user_id, session_id, }) .await { Ok(()) => { let _ = this.update_in(cx, |yumush, window, cx| { yumush.load_sessions(user_id, window, cx) }); } Err(error) => notify_error(&this, cx, error), } }) .detach(); } pub(super) fn rename_builder_user(&mut self, window: &mut Window, cx: &mut Context) { let Some((user_id, UserEdit::Rename)) = self.chat.admin.editing else { return; }; let username = self.chat.admin.builder_rename.read(cx).text().to_string(); self.builder_user_action( window, cx, move |network| async move { network .call(RenameUser { user_id, username }) .await .map(|_| ()) }, |yumush, window, cx| { yumush.chat.admin.editing = None; yumush .chat .admin .builder_rename .update(cx, |input, cx| input.set_value("", window, cx)); }, ); } pub(super) fn confirm_builder_timeout(&mut self, window: &mut Window, cx: &mut Context) { let Some((user_id, UserEdit::Timeout)) = self.chat.admin.editing else { return; }; let minutes = self.chat.admin.builder_timeout.read(cx).text().to_string(); let Some(minutes) = number(&minutes) else { return; }; self.builder_user_action( window, cx, move |network| async move { network.call(TimeoutUser { user_id, minutes }).await }, |yumush, window, cx| { yumush.chat.admin.editing = None; yumush .chat .admin .builder_timeout .update(cx, |input, cx| input.set_value("", window, cx)); }, ); } pub(super) fn toggle_builder_ban_ip(&mut self, cx: &mut Context) { self.chat.admin.builder_ban_scope = match self.chat.admin.builder_ban_scope { BanScope::Account => BanScope::AccountAndIp, BanScope::AccountAndIp => BanScope::Account, }; cx.notify(); } pub(super) fn confirm_builder_ban(&mut self, window: &mut Window, cx: &mut Context) { let Some((user_id, UserEdit::Ban)) = self.chat.admin.editing else { return; }; let reason = self .chat .admin .builder_ban_reason .read(cx) .text() .to_string(); let reason = reason.trim().to_string(); let reason = (!reason.is_empty()).then_some(reason); let scope = self.chat.admin.builder_ban_scope; self.builder_user_action( window, cx, move |network| async move { network .call(BanUser { user_id, reason, scope, }) .await }, |yumush, window, cx| { yumush.chat.admin.editing = None; yumush .chat .admin .builder_ban_reason .update(cx, |input, cx| input.set_value("", window, cx)); }, ); } pub(super) fn purge_builder_user( &mut self, user_id: Id, window: &mut Window, cx: &mut Context, ) { if !self.arm(Armed::PurgeUser(user_id), cx) { return; } let network = self.network.clone(); cx.spawn_in(window, async move |this, cx| { match network.call(PurgeUser { user_id }).await { Ok(()) => { let _ = this.update_in(cx, |yumush, window, cx| { yumush .chat .admin .builder_messages .retain(|hit| hit.message.user_id != user_id); yumush.load_users(window, cx); }); } Err(error) => notify_error(&this, cx, error), } }) .detach(); } pub(super) fn users_body(&self, entity: &Entity, t: Tokens, cx: &App) -> Vec { let query = search_text(&self.chat.admin.builder_search, cx); let rows: Vec
= match self.user.as_ref() { Some(me) => self .chat .admin .builder_users .iter() .filter(|account| { account .user .username .to_lowercase() .contains(query.as_str()) }) .map(|account| self.builder_row(account, me, entity, t, cx)) .collect(), None => Vec::new(), }; let grow = |control: AnyElement| div().flex_1().min_w(px(size::THUMB)).child(control); let toolbar = div() .pb(px(space::SM)) .flex() .flex_wrap() .items_center() .gap(px(space::SM)) .child(grow( crate::gui::sidebar::input_box(&self.chat.admin.builder_search, t) .into_any_element(), )) .child(grow( field(t, &self.chat.admin.new_username).into_any_element(), )) .child(grow( field(t, &self.chat.admin.new_password).into_any_element(), )) .child(parts::button( "create_user", w().builder_users.create, Press::Plain, t, entity_action(entity, |yumush, window, cx| { yumush.submit_new_user(window, cx) }), )); vec![ card() .child(toolbar) .child(rows_body(rows, w().common.no_users, t)) .into_any_element(), ] } pub(super) fn builder_timeout_row(&self, user_id: Id, entity: &Entity, t: Tokens) -> Div { form_row( &self.chat.admin.builder_timeout, t, [parts::button( format!("confirm_timeout_{user_id}"), w().builder_users.confirm, Press::Plain, t, entity_action(entity, |yumush, window, cx| { yumush.confirm_builder_timeout(window, cx) }), ) .into_any_element()], ) } pub(super) fn builder_ban_row(&self, user_id: Id, entity: &Entity, t: Tokens) -> Div { let ip_label = if self.chat.admin.builder_ban_scope == BanScope::AccountAndIp { w().builder_users.ip_on } else { w().builder_users.ip_off }; form_row( &self.chat.admin.builder_ban_reason, t, [ parts::button( format!("ban_ip_{user_id}"), ip_label, Press::Plain, t, entity_action(entity, |yumush, _, cx| yumush.toggle_builder_ban_ip(cx)), ) .into_any_element(), parts::button( format!("confirm_ban_{user_id}"), w().builder_users.confirm, Press::Plain, t, entity_action(entity, |yumush, window, cx| { yumush.confirm_builder_ban(window, cx) }), ) .into_any_element(), ], ) } fn builder_friend_list(&self, t: Tokens) -> AnyElement { let friends = self.chat.admin.builder_friends.clone(); let search = self.chat.admin.builder_friend_search.clone(); let avatars = self.chat.session.avatars.clone(); let label = w().builder_users.friends_count(friends.len()); Popover::new("builder_friends") .anchor(Anchor::TopLeft) .appearance(false) .trigger(crate::gui::Trigger::new( clickable("builder_friends_trigger", t, |_, _| {}) .h(px(size::CONTROL_SM)) .flex() .items_center() .gap(px(space::SM)) .rounded(px(radius::MD)) .text_size(text(text::CAPTION)) .font_weight(FontWeight::MEDIUM) .text_color(t.paper()) .child(parts::small_icon(IconName::Users)) .child(label) .child(parts::small_icon(IconName::ChevronDown)), )) .content(move |_, _, cx| { let query = search_text(&search, cx); parts::popover(t) .w(px(size::POPOVER)) .p(px(space::SM)) .gap(px(space::XS)) .child(crate::gui::sidebar::input_box(&search, t)) .child( div() .id("builder_friends_list") .max_h(px(FRIENDS_MAX_H)) .overflow_y_scroll() .flex() .flex_col() .when(friends.is_empty(), |list| { list.child( div() .text_size(text(text::CAPTION)) .text_color(t.dim()) .child(w().builder_users.no_friends), ) }) .children( friends .iter() .filter(|friend| { friend.username.to_lowercase().contains(&query) }) .map(|friend| { div() .h(px(size::CONTROL_SM)) .flex() .items_center() .gap(px(space::SM)) .child(avatar( t, friend, px(size::ICON), text(text::CAPTION), &avatars, )) .child( div() .text_size(text(text::CAPTION)) .child(friend.username.clone()), ) }), ), ) }) .into_any_element() } pub(super) fn builder_session_row( &self, user_id: Id, session: &SessionInfo, entity: &Entity, t: Tokens, ) -> Div { let session_id = session.id; let revoke_button = action_button( format!("revoke_session_{}", session.id), IconName::LogOut, w().builder_users.revoke, w().builder_users.end_session, t.dim(), t, entity_action(entity, move |yumush, window, cx| { yumush.revoke_builder_session(user_id, session_id, window, cx) }), ); let device = if session.device.is_empty() { w().builder_users.unknown_device } else { session.device.as_str() }; div() .w_full() .h(px(size::CONTROL_SM)) .flex() .items_center() .gap(px(space::SM)) .child(parts::small_icon(IconName::Monitor).text_color(t.dim())) .child( div() .flex_1() .text_size(text(text::CAPTION)) .min_w_0() .truncate() .child(device.to_string()), ) .child( div() .flex_shrink_0() .text_size(text(text::CAPTION)) .text_color(t.dim()) .child(seen_text(session.last_seen)), ) .child(revoke_button) } fn builder_client_row(&self, client: &UpdateClient, t: Tokens) -> Div { let release = match (client.release, client.target.as_deref()) { (Some(seq), Some(target)) => format!("#{seq} · {target}"), _ => w().builder_users.unknown.to_string(), }; let state = match client.state { UpdateState::Unknown => caption_text(w().builder_users.dev, t.dim()), UpdateState::Latest => caption_text(w().builder_users.latest, t.hue(Hue::Mint)), UpdateState::Available { required, .. } => caption_text( if required { format!( "{} · {}", w().builder_users.available, w().builder_users.required ) } else { w().builder_users.available.to_string() }, t.dim(), ), UpdateState::Downloading { percent, .. } => { meter(f32::from(percent) / 100., format!("{percent}%"), t) } UpdateState::Installing { .. } => caption_text(w().builder_users.installing, t.dim()), UpdateState::Ready { .. } => caption_text(w().builder_users.ready, t.hue(Hue::Mint)), UpdateState::Failed { .. } => caption_text(w().builder_users.failed, t.bad()), }; let dot = div() .size(px(space::SM)) .flex_shrink_0() .rounded_full() .bg(if client.online { t.hue(Hue::Mint) } else { t.dim() }); let seen = (!client.online).then(|| caption_text(seen_text(Some(client.seen_ms)), t.dim())); div() .w_full() .h(px(size::CONTROL_SM)) .flex() .items_center() .gap(px(space::SM)) .child(parts::small_icon(IconName::Monitor).text_color(t.dim())) .child( div() .flex_1() .text_size(text(text::CAPTION)) .min_w_0() .truncate() .child(client.device.clone()), ) .child(caption_text(release, t.dim())) .child(state) .child(dot) .children(seen) } pub(super) fn builder_rename_row( &self, user_id: Id, entity: &Entity, t: Tokens, cx: &App, ) -> Div { let value = self.chat.admin.builder_rename.read(cx).text().to_string(); let current = self .chat .admin .builder_users .iter() .find(|account| account.user.id == user_id) .map_or("", |account| account.user.username.as_str()); let ready = !value.is_empty() && value != current; form_row( &self.chat.admin.builder_rename, t, ready.then(|| { parts::button( format!("confirm_rename_{user_id}"), w().builder_users.confirm, Press::Plain, t, entity_action(entity, |yumush, window, cx| { yumush.rename_builder_user(window, cx) }), ) .into_any_element() }), ) } pub(super) fn builder_password_row( &self, user_id: Id, entity: &Entity, t: Tokens, cx: &App, ) -> Div { let ready = !self .chat .admin .builder_password .read(cx) .text() .to_string() .is_empty(); form_row( &self.chat.admin.builder_password, t, ready.then(|| { parts::button( format!("confirm_password_{user_id}"), w().builder_users.confirm, Press::Plain, t, entity_action(entity, |yumush, window, cx| { yumush.reset_builder_password(window, cx) }), ) .into_any_element() }), ) } pub(super) fn builder_row( &self, account: &Account, me: &User, entity: &Entity, t: Tokens, cx: &App, ) -> Div { let user = &account.user; let id = user.id; let manage = permission::can_manage_user(me.role, user.id == me.id, user.role); let timed_out = matches!(account.suspension, Suspension::Until(until) if until > now_ms()); let suspended = matches!(account.suspension, Suspension::Indefinite); let expanded_sessions = self .chat .admin .builder_sessions .as_ref() .filter(|(open, _)| *open == id) .map(|(_, sessions)| sessions); let joined = millis_time(user.created_at, crate::lang::w().common.date); let seen = seen_text(account.last_seen); let toggle_button = clickable( format!("sessions_list_user_{id}"), t, entity_action(entity, move |yumush, window, cx| { yumush.toggle_builder_sessions(id, window, cx) }), ) .tip(w().builder_users.manage) .size(px(size::CONTROL_SM)) .flex_shrink_0() .flex() .items_center() .justify_center() .rounded(px(radius::MD)) .text_color(t.dim()) .when(expanded_sessions.is_some(), |this| this.bg(t.hov())) .child(Icon::new(IconName::Ellipsis).size(px(size::ICON))); let row = div() .px(px(space::LG)) .py(px(space::MD)) .flex() .items_center() .gap(px(space::MD)) .child(user_link( format!("builder_user_avatar_{id}"), Some(user), entity, avatar( t, user, px(size::AVATAR), text(text::CAPTION), &self.chat.session.avatars, ), )) .child( div() .flex_1() .min_w_0() .flex() .flex_col() .gap(px(space::XXS)) .child( div() .min_w_0() .flex() .items_center() .gap(px(space::SM)) .child(user_link( format!("builder_user_name_{id}"), Some(user), entity, div() .truncate() .text_size(text(text::LABEL)) .font_weight(FontWeight::MEDIUM) .text_color(t.paper()) .child(user.username.clone()), )) .when(user.role == Role::Builder, |this| { this.child(status(w().builder_users.tag_builder, t.paper())) }) .when(suspended, |this| { this.child(status(w().builder_users.tag_suspended, t.bad())) }) .when(timed_out, |this| { this.child(status(w().builder_users.tag_timed_out, t.bad())) }) .when(account.ghost, |this| { this.child(status(w().builder_users.tag_ghost, t.dim())) }), ) .child( div() .min_w_0() .truncate() .text_size(text(text::CAPTION)) .text_color(t.dim()) .child(w().builder_users.joined_seen(joined, seen)), ), ) .children(manage.then_some(toggle_button)); let panel = expanded_sessions .map(|sessions| self.builder_panel(account, sessions, manage, entity, t, cx)); div().flex().flex_col().child(row).children(panel) } fn builder_panel( &self, account: &Account, sessions: &[SessionInfo], manage: bool, entity: &Entity, t: Tokens, cx: &App, ) -> Div { let user = &account.user; let id = user.id; let suspended = matches!(account.suspension, Suspension::Indefinite); let manage_only = |button: AnyElement| manage.then_some(button); let rename = action_button( format!("rename_user_{id}"), IconName::Pencil, w().builder_users.rename, w().builder_users.rename_tip, t.paper(), t, entity_action(entity, move |yumush, _, cx| { yumush.toggle_user_edit(id, UserEdit::Rename, cx) }), ); let password = action_button( format!("password_user_{id}"), IconName::KeyRound, w().builder_users.password, w().builder_users.password_tip, t.paper(), t, entity_action(entity, move |yumush, _, cx| { yumush.toggle_user_edit(id, UserEdit::Password, cx) }), ); let stats = action_button( format!("stats_user_{id}"), IconName::Activity, w().builder_users.stats, w().builder_users.stats_tip, t.paper(), t, entity_action(entity, move |yumush, _, cx| { yumush.toggle_builder_stats(id, cx) }), ); let timeout = action_button( format!("timeout_user_{id}"), IconName::Timer, w().builder_users.timeout, w().builder_users.timeout_tip, t.paper(), t, entity_action(entity, move |yumush, _, cx| { yumush.toggle_user_edit(id, UserEdit::Timeout, cx) }), ); let suspend = action_button( format!("suspend_user_{id}_{suspended}"), IconName::CirclePause, if suspended { w().builder_users.unsuspend } else { w().builder_users.suspend }, if suspended { w().builder_users.allow_sign_in } else { w().builder_users.block_until_lifted }, t.paper(), t, entity_action(entity, move |yumush, window, cx| { yumush.suspend_builder_user(id, !suspended, window, cx) }), ); let sign_out = action_button( format!("sessions_user_{id}"), IconName::LogOut, w().builder_users.sign_out, w().builder_users.end_all_sessions, t.paper(), t, entity_action(entity, move |yumush, window, cx| { yumush.revoke_builder_sessions(id, window, cx) }), ); let ban = action_button( format!("ban_user_{id}"), IconName::Ban, w().builder_users.ban, w().builder_users.ban_tip, t.paper(), t, entity_action(entity, move |yumush, _, cx| { yumush.toggle_user_edit(id, UserEdit::Ban, cx) }), ); let profile = action_button( format!("profile_user_{id}"), IconName::Eraser, w().builder_users.clear_profile, w().builder_users.clear_profile_tip, t.bad(), t, entity_action(entity, move |yumush, window, cx| { yumush.clear_builder_profile(id, window, cx) }), ); let purge = confirm_button( format!("purge_user_{id}"), IconName::MessageSquareX, w().builder_users.purge, w().builder_users.purge_tip, self.armed(Armed::PurgeUser(id)), t, entity_action(entity, move |yumush, window, cx| { yumush.purge_builder_user(id, window, cx) }), ); let delete = confirm_button( format!("delete_user_{id}"), IconName::UserX, w().builder_users.delete, w().builder_users.delete_tip, self.armed(Armed::BuilderDeleteUser(id)), t, entity_action(entity, move |yumush, window, cx| { yumush.delete_builder_user(id, window, cx) }), ); let account_actions = [ manage_only(rename.into_any_element()), manage_only(password.into_any_element()), Some(stats.into_any_element()), ]; let moderation_actions = [ manage_only(timeout.into_any_element()), manage_only(suspend.into_any_element()), manage_only(ban.into_any_element()), manage_only(sign_out.into_any_element()), ]; let danger_actions = [ manage_only(profile.into_any_element()), manage_only(purge.into_any_element()), manage_only(delete.into_any_element()), ]; let sessions: Vec = sessions .iter() .map(|session| { self.builder_session_row(id, session, entity, t) .into_any_element() }) .collect(); let clients: Vec = if self.chat.admin.builder_clients.is_empty() { vec![caption_text(w().builder_users.no_clients, t.dim()).into_any_element()] } else { self.chat .admin .builder_clients .iter() .map(|client| self.builder_client_row(client, t).into_any_element()) .collect() }; let stats_open = self .chat .session .followed .as_ref() .filter(|(followed, _)| *followed == id) .map(|(_, stats)| stats); div() .flex() .flex_col() .gap(px(space::SM)) .ml(px(space::MD)) .mb(px(space::MD)) .pl(px(space::XL)) .py(px(space::SM)) .border_l(px(crate::gui::style::stroke::LINE)) .border_color(t.person(id)) .children(action_group( w().builder_users.group_account, t, account_actions.into_iter().flatten().collect(), )) .children( self.edit_open(id, UserEdit::Password) .then(|| self.builder_password_row(id, entity, t, cx)), ) .children( self.edit_open(id, UserEdit::Rename) .then(|| self.builder_rename_row(id, entity, t, cx)), ) .children(action_group( w().builder_users.group_moderation, t, moderation_actions.into_iter().flatten().collect(), )) .children( self.edit_open(id, UserEdit::Timeout) .then(|| self.builder_timeout_row(id, entity, t)), ) .children( self.edit_open(id, UserEdit::Ban) .then(|| self.builder_ban_row(id, entity, t)), ) .children(action_group( w().builder_users.group_danger, t, danger_actions.into_iter().flatten().collect(), )) .children(action_group(w().builder_users.group_sessions, t, sessions)) .children(action_group(w().builder_users.group_clients, t, clients)) .children(action_group( w().builder_users.group_friends, t, vec![self.builder_friend_list(t)], )) .children(stats_open.map(|stats| { crate::gui::voice_stats::stats_panel( stats, &|id| self.chat.name_of(id), crate::gui::voice_stats::Detail::Full, t, ) .pt(px(space::MD)) })) } }