diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 5a2f030..cafc818 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -50,7 +50,7 @@ use common::{ share::{Kind, Share}, }; use gpui_kit::{ - Anchor, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image, + Anchor, AnimationExt, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image, InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement, Styled, Subscription, Task, Window, assets::IconName, @@ -166,6 +166,7 @@ pub struct Chat { scroll: ScrollHandle, pub(super) jump: Option, highlight: Option<(Id, Instant)>, + glide: Option<(Id, gpui_kit::Pixels, Instant)>, pub(super) view: View, pub(super) section: usize, pub(super) username_input: Entity, @@ -423,6 +424,7 @@ impl Chat { scroll: ScrollHandle::new(), jump: None, highlight: None, + glide: None, unread: HashMap::new(), unread_anchor: None, unseen: 0, @@ -902,7 +904,11 @@ impl Chat { Some(index) => self.scroll_to_index(index), None => self.scroll.scroll_to_bottom(), } - } else if mine || !self.away() { + } else if !self.away() { + let newest = self.messages.last().map_or(0, |message| message.id); + self.glide = Some((newest, self.scroll.offset().y, Instant::now())); + self.unseen = 0; + } else if mine { self.jump_to_bottom(); } else { self.unseen += 1; @@ -1786,12 +1792,16 @@ impl Yumush { ) } - fn message_list(&self, entity: &Entity, palette: Palette) -> impl IntoElement { + fn message_list(&self, entity: &Entity, palette: Palette) -> AnyElement { let divider = self .chat .unread_divider(self.user.as_ref().map(|user| user.id)); let entity_scroll = entity.clone(); - div() + let glide = self + .chat + .glide + .filter(|(_, _, at)| at.elapsed() < GLIDE + GLIDE_SLACK); + let list = div() .id("chat_messages") .track_scroll(&self.chat.scroll) .flex() @@ -1885,6 +1895,17 @@ impl Yumush { entity, palette, ); + let row = match glide { + Some((id, _, _)) if id == message.id => div() + .child(row) + .with_animation( + format!("chat_arrive_{id}"), + gpui_kit::Animation::new(GLIDE), + |row, delta| row.opacity(delta), + ) + .into_any_element(), + _ => row, + }; if divider == Some(index) { div() .flex() @@ -1896,7 +1917,22 @@ impl Yumush { row } }), - ) + ); + let Some((id, from, _)) = glide else { + return list.into_any_element(); + }; + let scroll = self.chat.scroll.clone(); + list.with_animation( + format!("chat_glide_{id}"), + gpui_kit::Animation::new(GLIDE).with_easing(gpui_kit::ease_out_quint()), + move |list, delta| { + let to = -scroll.max_offset().y; + let x = scroll.offset().x; + scroll.set_offset(gpui_kit::point(x, from + (to - from) * delta)); + list + }, + ) + .into_any_element() } fn composer(&self, entity: &Entity, palette: Palette, cx: &App) -> AnyElement { @@ -3271,6 +3307,8 @@ fn members_column( } const OFFLINE: usize = 5; +const GLIDE: Duration = Duration::from_millis(240); +const GLIDE_SLACK: Duration = Duration::from_millis(100); fn room_head(yumush: &Yumush, palette: Palette) -> Div { let chat = &yumush.chat;