From 8aeafff248c07e1a68e41de4fa696885182d5588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 29 Nov 2026 07:14:11 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20member=20moves=20between=20?= =?UTF-8?q?in=20voice=20/=20online=20/=20offline:=20arriving=20row=20grows?= =?UTF-8?q?=20in=20with=20a=20person-coloured=20line=20sweeping=20under=20?= =?UTF-8?q?it,=20the=20left=20section's=20gap=20closes;=20first=20sight=20?= =?UTF-8?q?and=20community=20switch=20don't=20animate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/gui/chat.rs | 171 +++++++++++++++++++++++++++++++--- 1 file changed, 159 insertions(+), 12 deletions(-) diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index e4e1f37..68a398d 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -4,6 +4,7 @@ use crate::gui::CLOCK; use crate::gui::glyph::Fill as _; use crate::lang::w; use std::{ + cell::RefCell, collections::{BTreeMap, HashMap, HashSet, VecDeque}, sync::Arc, time::{Duration, Instant}, @@ -271,6 +272,7 @@ pub struct Chat { pub(super) share_loss: HashMap<(Id, Kind), VecDeque<(u64, f32)>>, pub(super) stats_at: Option, pub(super) offline_open: bool, + pub(super) moves: RefCell, pub(super) usage_monitor: crate::usage::Monitor, pub(super) ringing: HashSet, pub(super) ring_task: Option>, @@ -561,6 +563,7 @@ impl Chat { share_loss: HashMap::new(), stats_at: None, offline_open: false, + moves: RefCell::default(), usage_monitor: { let monitor = crate::usage::Monitor::default(); if let Some(dir) = crate::config_dir() { @@ -3047,6 +3050,69 @@ struct MemberRow { presence: Presence, } +impl MemberRow { + fn place(&self) -> Place { + match (self.in_voice, self.presence) { + (true, _) => Place::Voice, + (false, Presence::Offline) => Place::Offline, + (false, _) => Place::Online, + } + } +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub(super) enum Place { + Voice, + Online, + Offline, +} + +#[derive(Default)] +pub(super) struct Moves { + community: Option, + places: HashMap)>, +} + +impl Moves { + fn track(&mut self, community_id: Id, rows: &[MemberRow], now: Instant) { + if self.community != Some(community_id) { + *self = Moves { + community: Some(community_id), + ..Moves::default() + }; + } + for row in rows { + let place = row.place(); + match self.places.get_mut(&row.user.id) { + Some(entry) if entry.0 != place => *entry = (place, Some((entry.0, now))), + Some(_) => {} + None => { + self.places.insert(row.user.id, (place, None)); + } + } + } + } + + fn moved(&self, user_id: Id, now: Instant) -> bool { + self.places + .get(&user_id) + .and_then(|(_, from)| *from) + .is_some_and(|(_, at)| now - at < SWEEP) + } + + fn left(&self, place: Place, now: Instant) -> usize { + self.places + .values() + .filter_map(|(_, from)| *from) + .filter(|(from, at)| *from == place && now - *at < GROW) + .count() + } +} + +const GROW: Duration = Duration::from_millis(160); +const SWEEP: Duration = Duration::from_millis(700); +const ROW_MAX: f32 = size::CONTROL * 2.; + fn members_column( entity: &Entity, yumush: &Yumush, @@ -3071,6 +3137,9 @@ fn members_column( presence: yumush.presence_of(member.user.id), }) .collect(); + let now = Instant::now(); + chat.moves.borrow_mut().track(community_id, &members, now); + let moves = chat.moves.borrow(); let avatars = &chat.avatars; let entity = entity.clone(); let row = |MemberRow { @@ -3093,11 +3162,6 @@ fn members_column( ) }) }; - let place = match (in_voice, presence) { - (true, _) => 0, - (false, Presence::Offline) => 2, - (false, _) => 1, - }; let line = in_voice.then(|| { let speaking = chat.waves.speaking.contains(&user.id); div() @@ -3185,14 +3249,48 @@ fn members_column( .children(line) .children(watch(Kind::Camera)) .children(watch(Kind::Screen)) + }; + let arrive = |member: &MemberRow| -> AnyElement { + let user_id = member.user.id; + if !moves.moved(user_id, now) { + return row(member).into_any_element(); + } + let place = member.place(); + div() .relative() + .overflow_hidden() + .child(row(member)) + .child( + div() + .absolute() + .bottom_0() + .left_0() + .h(px(stroke::LINE)) + .bg(palette.tokens.person(user_id)) + .with_animation( + format!("member_sweep_{user_id}_{place:?}"), + gpui_kit::Animation::new(SWEEP).with_easing(gpui_kit::ease_in_out), + |line, delta| { + line.w(gpui_kit::relative((delta * 2.).min(1.))) + .opacity((2. - delta * 2.).min(1.)) + }, + ), + ) .with_animation( - format!("member_move_{}_{place}", user.id), - super::parts::motion(), - |row, delta| row.opacity(delta).top(px((1. - delta) * space::SM)), + format!("member_grow_{user_id}_{place:?}"), + gpui_kit::Animation::new(GROW).with_easing(gpui_kit::ease_out_quint()), + |row, delta| row.max_h(px(delta * ROW_MAX)), ) + .into_any_element() }; - let section = |title: &'static str, rows: Vec<&MemberRow>, cap: usize| { + let leave = |place: Place, index: usize| { + div().with_animation( + format!("member_leave_{place:?}_{index}"), + gpui_kit::Animation::new(GROW).with_easing(gpui_kit::ease_out_quint()), + |gap, delta| gap.h(px((1. - delta) * size::CONTROL)), + ) + }; + let section = |title: &'static str, place: Place, rows: Vec<&MemberRow>, cap: usize| { (!rows.is_empty()).then(|| { let total = rows.len(); let more = total.saturating_sub(cap); @@ -3203,7 +3301,8 @@ fn members_column( super::parts::caption_head(format!("{title} ยท {total}"), palette.tokens) .pb(px(space::XS)), ) - .children(rows.into_iter().take(cap).map(row)) + .children(rows.into_iter().take(cap).map(arrive)) + .children((0..moves.left(place, now)).map(|index| leave(place, index))) .when(more > 0, |this| { this.child( clickable( @@ -3246,7 +3345,12 @@ fn members_column( .flex_col() .gap(px(space::SM)) .children(join) - .children(section(w().chat.in_voice, in_call, usize::MAX)) + .children(section( + w().chat.in_voice, + Place::Voice, + in_call, + usize::MAX, + )) }); let online = members .iter() @@ -3268,9 +3372,15 @@ fn members_column( .gap(px(space::LG)) .child(room_head(yumush, palette)) .children(call) - .children(section(w().common.presence_online, online, usize::MAX)) + .children(section( + w().common.presence_online, + Place::Online, + online, + usize::MAX, + )) .children(section( w().common.presence_offline, + Place::Offline, offline, if chat.offline_open { usize::MAX @@ -3759,3 +3869,40 @@ fn stage_button( }) .child(super::parts::small_icon(icon)) } + +#[cfg(test)] +mod tests { + use super::*; + + fn member(id: Id, in_voice: bool) -> MemberRow { + MemberRow { + user: User { + id, + username: String::new(), + role: common::model::Role::User, + status: String::new(), + hue: None, + avatar_id: None, + created_at: 0, + }, + in_voice, + muted: false, + presence: Presence::Online, + } + } + + #[test] + fn moves_only_after_first_sight_and_reset_per_community() { + let mut moves = Moves::default(); + let start = Instant::now(); + moves.track(1, &[member(7, false)], start); + assert!(!moves.moved(7, start)); + moves.track(1, &[member(7, true)], start); + assert!(moves.moved(7, start)); + assert_eq!(moves.left(Place::Online, start), 1); + assert!(!moves.moved(7, start + SWEEP)); + assert_eq!(moves.left(Place::Online, start + GROW), 0); + moves.track(2, &[member(7, false)], start); + assert!(!moves.moved(7, start)); + } +}