forge
Explore
Log in

Don't you dare go Hollow

Member moves between in voice / online / offline: arriving row grows in with a person-coloured line sweeping under it, the left section's gap closes

Browse files at this commit

8aeafff248c07e1a68e41de4fa696885182d5588Ahmet Kaan GümüşParent: 5291617
  • feat
    • member moves between in voice / online / offline: arriving row grows in with a person-coloured line sweeping under it, the left section's gap closes
    • first sight and community switch don't animate
Show full message
✨ feat: member moves between in voice / online / offline: arriving row grows in with a person-coloured line sweeping under it, the left section's gap closes; first sight and community switch don't animate
crates/client/src/gui/chat.rsmodified+159 -12
@@ -4,6 +4,7 @@ use crate::gui::CLOCK;
4 use crate::gui::glyph::Fill as _;4 use crate::gui::glyph::Fill as _;
5 use crate::lang::w;5 use crate::lang::w;
6 use std::{6 use std::{
7+ cell::RefCell,
7 collections::{BTreeMap, HashMap, HashSet, VecDeque},8 collections::{BTreeMap, HashMap, HashSet, VecDeque},
8 sync::Arc,9 sync::Arc,
9 time::{Duration, Instant},10 time::{Duration, Instant},
@@ -271,6 +272,7 @@ pub struct Chat {
271 pub(super) share_loss: HashMap<(Id, Kind), VecDeque<(u64, f32)>>,272 pub(super) share_loss: HashMap<(Id, Kind), VecDeque<(u64, f32)>>,
272 pub(super) stats_at: Option<StatsAt>,273 pub(super) stats_at: Option<StatsAt>,
273 pub(super) offline_open: bool,274 pub(super) offline_open: bool,
275+ pub(super) moves: RefCell<Moves>,
274 pub(super) usage_monitor: crate::usage::Monitor,276 pub(super) usage_monitor: crate::usage::Monitor,
275 pub(super) ringing: HashSet<Id>,277 pub(super) ringing: HashSet<Id>,
276 pub(super) ring_task: Option<Task<()>>,278 pub(super) ring_task: Option<Task<()>>,
@@ -561,6 +563,7 @@ impl Chat {
561 share_loss: HashMap::new(),563 share_loss: HashMap::new(),
562 stats_at: None,564 stats_at: None,
563 offline_open: false,565 offline_open: false,
566+ moves: RefCell::default(),
564 usage_monitor: {567 usage_monitor: {
565 let monitor = crate::usage::Monitor::default();568 let monitor = crate::usage::Monitor::default();
566 if let Some(dir) = crate::config_dir() {569 if let Some(dir) = crate::config_dir() {
@@ -3047,6 +3050,69 @@ struct MemberRow {
3047 presence: Presence,3050 presence: Presence,
3048 }3051 }
3049 3052
3053+impl MemberRow {
3054+ fn place(&self) -> Place {
3055+ match (self.in_voice, self.presence) {
3056+ (true, _) => Place::Voice,
3057+ (false, Presence::Offline) => Place::Offline,
3058+ (false, _) => Place::Online,
3059+ }
3060+ }
3061+}
3062+
3063+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
3064+pub(super) enum Place {
3065+ Voice,
3066+ Online,
3067+ Offline,
3068+}
3069+
3070+#[derive(Default)]
3071+pub(super) struct Moves {
3072+ community: Option<Id>,
3073+ places: HashMap<Id, (Place, Option<(Place, Instant)>)>,
3074+}
3075+
3076+impl Moves {
3077+ fn track(&mut self, community_id: Id, rows: &[MemberRow], now: Instant) {
3078+ if self.community != Some(community_id) {
3079+ *self = Moves {
3080+ community: Some(community_id),
3081+ ..Moves::default()
3082+ };
3083+ }
3084+ for row in rows {
3085+ let place = row.place();
3086+ match self.places.get_mut(&row.user.id) {
3087+ Some(entry) if entry.0 != place => *entry = (place, Some((entry.0, now))),
3088+ Some(_) => {}
3089+ None => {
3090+ self.places.insert(row.user.id, (place, None));
3091+ }
3092+ }
3093+ }
3094+ }
3095+
3096+ fn moved(&self, user_id: Id, now: Instant) -> bool {
3097+ self.places
3098+ .get(&user_id)
3099+ .and_then(|(_, from)| *from)
3100+ .is_some_and(|(_, at)| now - at < SWEEP)
3101+ }
3102+
3103+ fn left(&self, place: Place, now: Instant) -> usize {
3104+ self.places
3105+ .values()
3106+ .filter_map(|(_, from)| *from)
3107+ .filter(|(from, at)| *from == place && now - *at < GROW)
3108+ .count()
3109+ }
3110+}
3111+
3112+const GROW: Duration = Duration::from_millis(160);
3113+const SWEEP: Duration = Duration::from_millis(700);
3114+const ROW_MAX: f32 = size::CONTROL * 2.;
3115+
3050 fn members_column(3116 fn members_column(
3051 entity: &Entity<Yumush>,3117 entity: &Entity<Yumush>,
3052 yumush: &Yumush,3118 yumush: &Yumush,
@@ -3071,6 +3137,9 @@ fn members_column(
3071 presence: yumush.presence_of(member.user.id),3137 presence: yumush.presence_of(member.user.id),
3072 })3138 })
3073 .collect();3139 .collect();
3140+ let now = Instant::now();
3141+ chat.moves.borrow_mut().track(community_id, &members, now);
3142+ let moves = chat.moves.borrow();
3074 let avatars = &chat.avatars;3143 let avatars = &chat.avatars;
3075 let entity = entity.clone();3144 let entity = entity.clone();
3076 let row = |MemberRow {3145 let row = |MemberRow {
@@ -3093,11 +3162,6 @@ fn members_column(
3093 )3162 )
3094 })3163 })
3095 };3164 };
3096- let place = match (in_voice, presence) {
3097- (true, _) => 0,
3098- (false, Presence::Offline) => 2,
3099- (false, _) => 1,
3100- };
3101 let line = in_voice.then(|| {3165 let line = in_voice.then(|| {
3102 let speaking = chat.waves.speaking.contains(&user.id);3166 let speaking = chat.waves.speaking.contains(&user.id);
3103 div()3167 div()
@@ -3185,14 +3249,48 @@ fn members_column(
3185 .children(line)3249 .children(line)
3186 .children(watch(Kind::Camera))3250 .children(watch(Kind::Camera))
3187 .children(watch(Kind::Screen))3251 .children(watch(Kind::Screen))
3252+ };
3253+ let arrive = |member: &MemberRow| -> AnyElement {
3254+ let user_id = member.user.id;
3255+ if !moves.moved(user_id, now) {
3256+ return row(member).into_any_element();
3257+ }
3258+ let place = member.place();
3259+ div()
3188 .relative()3260 .relative()
3261+ .overflow_hidden()
3262+ .child(row(member))
3263+ .child(
3264+ div()
3265+ .absolute()
3266+ .bottom_0()
3267+ .left_0()
3268+ .h(px(stroke::LINE))
3269+ .bg(palette.tokens.person(user_id))
3270+ .with_animation(
3271+ format!("member_sweep_{user_id}_{place:?}"),
3272+ gpui_kit::Animation::new(SWEEP).with_easing(gpui_kit::ease_in_out),
3273+ |line, delta| {
3274+ line.w(gpui_kit::relative((delta * 2.).min(1.)))
3275+ .opacity((2. - delta * 2.).min(1.))
3276+ },
3277+ ),
3278+ )
3189 .with_animation(3279 .with_animation(
3190- format!("member_move_{}_{place}", user.id),3280+ format!("member_grow_{user_id}_{place:?}"),
3191- super::parts::motion(),3281+ gpui_kit::Animation::new(GROW).with_easing(gpui_kit::ease_out_quint()),
3192- |row, delta| row.opacity(delta).top(px((1. - delta) * space::SM)),3282+ |row, delta| row.max_h(px(delta * ROW_MAX)),
3193 )3283 )
3284+ .into_any_element()
3194 };3285 };
3195- let section = |title: &'static str, rows: Vec<&MemberRow>, cap: usize| {3286+ let leave = |place: Place, index: usize| {
3287+ div().with_animation(
3288+ format!("member_leave_{place:?}_{index}"),
3289+ gpui_kit::Animation::new(GROW).with_easing(gpui_kit::ease_out_quint()),
3290+ |gap, delta| gap.h(px((1. - delta) * size::CONTROL)),
3291+ )
3292+ };
3293+ let section = |title: &'static str, place: Place, rows: Vec<&MemberRow>, cap: usize| {
3196 (!rows.is_empty()).then(|| {3294 (!rows.is_empty()).then(|| {
3197 let total = rows.len();3295 let total = rows.len();
3198 let more = total.saturating_sub(cap);3296 let more = total.saturating_sub(cap);
@@ -3203,7 +3301,8 @@ fn members_column(
3203 super::parts::caption_head(format!("{title} · {total}"), palette.tokens)3301 super::parts::caption_head(format!("{title} · {total}"), palette.tokens)
3204 .pb(px(space::XS)),3302 .pb(px(space::XS)),
3205 )3303 )
3206- .children(rows.into_iter().take(cap).map(row))3304+ .children(rows.into_iter().take(cap).map(arrive))
3305+ .children((0..moves.left(place, now)).map(|index| leave(place, index)))
3207 .when(more > 0, |this| {3306 .when(more > 0, |this| {
3208 this.child(3307 this.child(
3209 clickable(3308 clickable(
@@ -3246,7 +3345,12 @@ fn members_column(
3246 .flex_col()3345 .flex_col()
3247 .gap(px(space::SM))3346 .gap(px(space::SM))
3248 .children(join)3347 .children(join)
3249- .children(section(w().chat.in_voice, in_call, usize::MAX))3348+ .children(section(
3349+ w().chat.in_voice,
3350+ Place::Voice,
3351+ in_call,
3352+ usize::MAX,
3353+ ))
3250 });3354 });
3251 let online = members3355 let online = members
3252 .iter()3356 .iter()
@@ -3268,9 +3372,15 @@ fn members_column(
3268 .gap(px(space::LG))3372 .gap(px(space::LG))
3269 .child(room_head(yumush, palette))3373 .child(room_head(yumush, palette))
3270 .children(call)3374 .children(call)
3271- .children(section(w().common.presence_online, online, usize::MAX))3375+ .children(section(
3376+ w().common.presence_online,
3377+ Place::Online,
3378+ online,
3379+ usize::MAX,
3380+ ))
3272 .children(section(3381 .children(section(
3273 w().common.presence_offline,3382 w().common.presence_offline,
3383+ Place::Offline,
3274 offline,3384 offline,
3275 if chat.offline_open {3385 if chat.offline_open {
3276 usize::MAX3386 usize::MAX
@@ -3759,3 +3869,40 @@ fn stage_button(
3759 })3869 })
3760 .child(super::parts::small_icon(icon))3870 .child(super::parts::small_icon(icon))
3761 }3871 }
3872+
3873+#[cfg(test)]
3874+mod tests {
3875+ use super::*;
3876+
3877+ fn member(id: Id, in_voice: bool) -> MemberRow {
3878+ MemberRow {
3879+ user: User {
3880+ id,
3881+ username: String::new(),
3882+ role: common::model::Role::User,
3883+ status: String::new(),
3884+ hue: None,
3885+ avatar_id: None,
3886+ created_at: 0,
3887+ },
3888+ in_voice,
3889+ muted: false,
3890+ presence: Presence::Online,
3891+ }
3892+ }
3893+
3894+ #[test]
3895+ fn moves_only_after_first_sight_and_reset_per_community() {
3896+ let mut moves = Moves::default();
3897+ let start = Instant::now();
3898+ moves.track(1, &[member(7, false)], start);
3899+ assert!(!moves.moved(7, start));
3900+ moves.track(1, &[member(7, true)], start);
3901+ assert!(moves.moved(7, start));
3902+ assert_eq!(moves.left(Place::Online, start), 1);
3903+ assert!(!moves.moved(7, start + SWEEP));
3904+ assert_eq!(moves.left(Place::Online, start + GROW), 0);
3905+ moves.track(2, &[member(7, false)], start);
3906+ assert!(!moves.moved(7, start));
3907+ }
3908+}