BlueGit

ict rusty-teams

feat(chats): out of office notice above the composer

- 1:1 chat with someone out of office shows "<Name> is out of office and may not respond" above the composer, like Teams
- Close hides it for that chat until the app restarts
- Opening a 1:1 chat loads the partner's profile (cached), the out of office flag comes from its presence
- Group chats show no notice

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-12 · 2 weeks ago

Hash
88fb3afb1987e4bd8b544aff7e55b8debd15a875
Parent
9f12e1fe
5 files changed +151 −0
crates/app-state/src/absence_notice.rs added +78 −0
@@ -0,0 +1,78 @@
1 use gpui_kit::*;
2
3 use crate::app_state::AppState;
4
5 #[derive(Debug, Clone, PartialEq, Eq)]
6 pub struct AbsenceNotice {
7 pub name: String,
8 }
9
10 impl AbsenceNotice {
11 pub fn text(&self) -> String {
12 format!("{} is out of office and may not respond", self.name)
13 }
14 }
15
16 fn notice_for(
17 dismissed: bool,
18 out_of_office: Option<&str>,
19 profile_name: Option<&str>,
20 partner_name: &str,
21 ) -> Option<AbsenceNotice> {
22 if dismissed {
23 return None;
24 }
25 out_of_office?;
26 let name = profile_name
27 .map(str::trim)
28 .filter(|name| !name.is_empty())
29 .unwrap_or(partner_name);
30 Some(AbsenceNotice { name: name.to_owned() })
31 }
32
33 impl AppState {
34 pub fn refresh_partner_absence(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
35 if self.mode.demo {
36 return;
37 }
38 if let Some(partner) = self.one_on_one_partner(conversation_id) {
39 self.request_profile(&partner.user_id, false, cx);
40 }
41 }
42
43 pub fn absence_notice(&self, conversation_id: &str) -> Option<AbsenceNotice> {
44 let partner = self.one_on_one_partner(conversation_id)?;
45 let demo_profile;
46 let profile = if self.mode.demo {
47 demo_profile = crate::demo_profiles::profile(&partner.user_id)?;
48 &demo_profile
49 } else {
50 self.profiles.get(&partner.user_id)?.profile.as_deref()?
51 };
52 notice_for(
53 self.dismissed_absence_notices.contains(conversation_id),
54 profile.out_of_office.as_deref(),
55 profile.display_name.as_deref(),
56 &partner.name,
57 )
58 }
59
60 pub fn dismiss_absence_notice(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
61 self.dismissed_absence_notices.insert(conversation_id.to_owned());
62 cx.notify();
63 }
64 }
65
66 #[cfg(test)]
67 mod tests {
68 use super::notice_for;
69
70 #[test]
71 fn out_of_office_shows_the_notice_until_it_is_closed() {
72 let notice = notice_for(false, Some(""), Some("Lea Schneider"), "Lea").unwrap();
73 assert_eq!(notice.text(), "Lea Schneider is out of office and may not respond");
74 assert_eq!(notice_for(true, Some(""), Some("Lea Schneider"), "Lea"), None);
75 assert_eq!(notice_for(false, None, Some("Lea Schneider"), "Lea"), None);
76 assert_eq!(notice_for(false, Some("Back Monday"), Some(" "), "Lea").unwrap().name, "Lea");
77 }
78 }
@@ -0,0 +1,78 @@
1use gpui_kit::*;
2
3use crate::app_state::AppState;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct AbsenceNotice {
7 pub name: String,
8}
9
10impl AbsenceNotice {
11 pub fn text(&self) -> String {
12 format!("{} is out of office and may not respond", self.name)
13 }
14}
15
16fn notice_for(
17 dismissed: bool,
18 out_of_office: Option<&str>,
19 profile_name: Option<&str>,
20 partner_name: &str,
21) -> Option<AbsenceNotice> {
22 if dismissed {
23 return None;
24 }
25 out_of_office?;
26 let name = profile_name
27 .map(str::trim)
28 .filter(|name| !name.is_empty())
29 .unwrap_or(partner_name);
30 Some(AbsenceNotice { name: name.to_owned() })
31}
32
33impl AppState {
34 pub fn refresh_partner_absence(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
35 if self.mode.demo {
36 return;
37 }
38 if let Some(partner) = self.one_on_one_partner(conversation_id) {
39 self.request_profile(&partner.user_id, false, cx);
40 }
41 }
42
43 pub fn absence_notice(&self, conversation_id: &str) -> Option<AbsenceNotice> {
44 let partner = self.one_on_one_partner(conversation_id)?;
45 let demo_profile;
46 let profile = if self.mode.demo {
47 demo_profile = crate::demo_profiles::profile(&partner.user_id)?;
48 &demo_profile
49 } else {
50 self.profiles.get(&partner.user_id)?.profile.as_deref()?
51 };
52 notice_for(
53 self.dismissed_absence_notices.contains(conversation_id),
54 profile.out_of_office.as_deref(),
55 profile.display_name.as_deref(),
56 &partner.name,
57 )
58 }
59
60 pub fn dismiss_absence_notice(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
61 self.dismissed_absence_notices.insert(conversation_id.to_owned());
62 cx.notify();
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::notice_for;
69
70 #[test]
71 fn out_of_office_shows_the_notice_until_it_is_closed() {
72 let notice = notice_for(false, Some(""), Some("Lea Schneider"), "Lea").unwrap();
73 assert_eq!(notice.text(), "Lea Schneider is out of office and may not respond");
74 assert_eq!(notice_for(true, Some(""), Some("Lea Schneider"), "Lea"), None);
75 assert_eq!(notice_for(false, None, Some("Lea Schneider"), "Lea"), None);
76 assert_eq!(notice_for(false, Some("Back Monday"), Some(" "), "Lea").unwrap().name, "Lea");
77 }
78}
crates/app-state/src/app_state.rs +3 −0
@@ -143,6 +143,7 @@ pub struct AppState {
143 143 pub live_retry: Option<Arc<tokio::sync::Notify>>,
144 144 pub notice_count: u64,
145 145 pub followed_presence: Vec<crate::presence_follow::FollowedPerson>,
146 pub dismissed_absence_notices: std::collections::HashSet<String>,
146 147 pub followed_changes: Vec<(String, &'static str)>,
147 148 pub keep_unread: Option<String>,
148 149 pub restorable_deletes: crate::restorable_deletes::RestorableDeletes,
@@ -303,6 +304,7 @@ impl AppState {
303 304 live_retry: None,
304 305 notice_count: 0,
305 306 followed_presence: Vec::new(),
307 dismissed_absence_notices: Default::default(),
306 308 followed_changes: Vec::new(),
307 309 keep_unread: None,
308 310 restorable_deletes: Default::default(),
@@ -1000,6 +1002,7 @@ impl AppState {
1000 1002 cx.notify();
1001 1003 self.refresh_live_meeting(&conversation_id, cx);
1002 1004 self.refresh_language_stamps(&conversation_id, cx);
1005 self.refresh_partner_absence(&conversation_id, cx);
1003 1006 }
1004 1007
1005 1008 fn apply_typing(&mut self, event: TypingEvent, cx: &mut Context<Self>) {
@@ -143,6 +143,7 @@ pub struct AppState {
143 pub live_retry: Option<Arc<tokio::sync::Notify>>,
143 pub live_retry: Option<Arc<tokio::sync::Notify>>,
144 pub notice_count: u64,
144 pub notice_count: u64,
145 pub followed_presence: Vec<crate::presence_follow::FollowedPerson>,
145 pub followed_presence: Vec<crate::presence_follow::FollowedPerson>,
146 pub dismissed_absence_notices: std::collections::HashSet<String>,
146 pub followed_changes: Vec<(String, &'static str)>,
147 pub followed_changes: Vec<(String, &'static str)>,
147 pub keep_unread: Option<String>,
148 pub keep_unread: Option<String>,
148 pub restorable_deletes: crate::restorable_deletes::RestorableDeletes,
149 pub restorable_deletes: crate::restorable_deletes::RestorableDeletes,
@@ -303,6 +304,7 @@ impl AppState {
303 live_retry: None,
304 live_retry: None,
304 notice_count: 0,
305 notice_count: 0,
305 followed_presence: Vec::new(),
306 followed_presence: Vec::new(),
307 dismissed_absence_notices: Default::default(),
306 followed_changes: Vec::new(),
308 followed_changes: Vec::new(),
307 keep_unread: None,
309 keep_unread: None,
308 restorable_deletes: Default::default(),
310 restorable_deletes: Default::default(),
@@ -1000,6 +1002,7 @@ impl AppState {
1000 cx.notify();
1002 cx.notify();
1001 self.refresh_live_meeting(&conversation_id, cx);
1003 self.refresh_live_meeting(&conversation_id, cx);
1002 self.refresh_language_stamps(&conversation_id, cx);
1004 self.refresh_language_stamps(&conversation_id, cx);
1005 self.refresh_partner_absence(&conversation_id, cx);
1003 }
1006 }
1004
1007
1005 fn apply_typing(&mut self, event: TypingEvent, cx: &mut Context<Self>) {
1008 fn apply_typing(&mut self, event: TypingEvent, cx: &mut Context<Self>) {
crates/app-state/src/lib.rs +1 −0
@@ -39,6 +39,7 @@ pub mod outbox;
39 39 pub mod outgoing;
40 40 pub mod own_status;
41 41 pub mod presence_follow;
42 pub mod absence_notice;
42 43 pub mod pending_rows;
43 44 pub mod people;
44 45 pub mod post_follow;
@@ -39,6 +39,7 @@ pub mod outbox;
39pub mod outgoing;
39pub mod outgoing;
40pub mod own_status;
40pub mod own_status;
41pub mod presence_follow;
41pub mod presence_follow;
42pub mod absence_notice;
42pub mod pending_rows;
43pub mod pending_rows;
43pub mod people;
44pub mod people;
44pub mod post_follow;
45pub mod post_follow;
crates/app/src/views/conversation.rs +2 −0
@@ -36,6 +36,7 @@ mod forward_select;
36 36 pub use forward_select::{
37 37 FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG, FORWARD_FOOTER_TAG,
38 38 };
39 mod absence;
39 40 mod appear_tracker;
40 41 mod jump;
41 42 mod notes_space;
@@ -4310,6 +4311,7 @@ impl Render for ConversationView {
4310 4311 None => column.child(runway(
4311 4312 v_flex()
4312 4313 .w_full()
4314 .children(self.render_absence_notice(cx))
4313 4315 .children(self.render_proposal_card(cx).map(|card| {
4314 4316 div().w_full().pb(px(COMPOSER_TOP_GAP)).child(card)
4315 4317 }))
@@ -36,6 +36,7 @@ mod forward_select;
36pub use forward_select::{
36pub use forward_select::{
37 FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG, FORWARD_FOOTER_TAG,
37 FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG, FORWARD_FOOTER_TAG,
38};
38};
39mod absence;
39mod appear_tracker;
40mod appear_tracker;
40mod jump;
41mod jump;
41mod notes_space;
42mod notes_space;
@@ -4310,6 +4311,7 @@ impl Render for ConversationView {
4310 None => column.child(runway(
4311 None => column.child(runway(
4311 v_flex()
4312 v_flex()
4312 .w_full()
4313 .w_full()
4314 .children(self.render_absence_notice(cx))
4313 .children(self.render_proposal_card(cx).map(|card| {
4315 .children(self.render_proposal_card(cx).map(|card| {
4314 div().w_full().pb(px(COMPOSER_TOP_GAP)).child(card)
4316 div().w_full().pb(px(COMPOSER_TOP_GAP)).child(card)
4315 }))
4317 }))
crates/app/src/views/conversation/absence.rs added +67 −0
@@ -0,0 +1,67 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::h_flex;
3 use gpui_kit::*;
4
5 use super::ConversationView;
6 use crate::theme;
7 use crate::views::widgets::icon;
8
9 pub const ABSENCE_NOTICE_TAG: &str = "conversation/absence-notice";
10 const NOTICE_MARGIN_X: f32 = 20.;
11 const NOTICE_MARGIN_BOTTOM: f32 = 8.;
12 const NOTICE_PADDING: f32 = 12.;
13 const NOTICE_HEIGHT: f32 = 36.;
14 const NOTICE_RADIUS: f32 = 10.;
15 const CLOSE_SIZE: f32 = 24.;
16 const NOTICE_TINT: f32 = 0.18;
17
18 impl ConversationView {
19 pub(super) fn render_absence_notice(&self, cx: &App) -> Option<AnyElement> {
20 if self.draft_active {
21 return None;
22 }
23 let conversation_id = self.conversation_id()?;
24 let notice = self.app.read(cx).absence_notice(&conversation_id)?;
25 let app = self.app.clone();
26 Some(
27 h_flex()
28 .flex_none()
29 .mx(px(NOTICE_MARGIN_X))
30 .mb(px(NOTICE_MARGIN_BOTTOM))
31 .pl(px(NOTICE_PADDING))
32 .pr(px(NOTICE_PADDING - (CLOSE_SIZE - 14.) / 2.))
33 .h(px(NOTICE_HEIGHT))
34 .gap(px(8.))
35 .items_center()
36 .rounded(px(NOTICE_RADIUS))
37 .bg(theme::accent().opacity(NOTICE_TINT))
38 .debug_selector(|| ABSENCE_NOTICE_TAG.into())
39 .child(
40 div()
41 .flex_1()
42 .min_w_0()
43 .truncate()
44 .text_size(px(13.))
45 .text_color(theme::text())
46 .child(notice.text()),
47 )
48 .child(
49 div()
50 .id("absence-notice-close")
51 .size(px(CLOSE_SIZE))
52 .flex_none()
53 .flex()
54 .items_center()
55 .justify_center()
56 .rounded(px(6.))
57 .cursor_pointer()
58 .hover(|button| button.bg(theme::row_hover()))
59 .child(icon(IconName::Close, 14., theme::text_muted()))
60 .on_click(move |_, _, cx| {
61 app.update(cx, |state, cx| state.dismiss_absence_notice(&conversation_id, cx));
62 }),
63 )
64 .into_any_element(),
65 )
66 }
67 }
@@ -0,0 +1,67 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::h_flex;
3use gpui_kit::*;
4
5use super::ConversationView;
6use crate::theme;
7use crate::views::widgets::icon;
8
9pub const ABSENCE_NOTICE_TAG: &str = "conversation/absence-notice";
10const NOTICE_MARGIN_X: f32 = 20.;
11const NOTICE_MARGIN_BOTTOM: f32 = 8.;
12const NOTICE_PADDING: f32 = 12.;
13const NOTICE_HEIGHT: f32 = 36.;
14const NOTICE_RADIUS: f32 = 10.;
15const CLOSE_SIZE: f32 = 24.;
16const NOTICE_TINT: f32 = 0.18;
17
18impl ConversationView {
19 pub(super) fn render_absence_notice(&self, cx: &App) -> Option<AnyElement> {
20 if self.draft_active {
21 return None;
22 }
23 let conversation_id = self.conversation_id()?;
24 let notice = self.app.read(cx).absence_notice(&conversation_id)?;
25 let app = self.app.clone();
26 Some(
27 h_flex()
28 .flex_none()
29 .mx(px(NOTICE_MARGIN_X))
30 .mb(px(NOTICE_MARGIN_BOTTOM))
31 .pl(px(NOTICE_PADDING))
32 .pr(px(NOTICE_PADDING - (CLOSE_SIZE - 14.) / 2.))
33 .h(px(NOTICE_HEIGHT))
34 .gap(px(8.))
35 .items_center()
36 .rounded(px(NOTICE_RADIUS))
37 .bg(theme::accent().opacity(NOTICE_TINT))
38 .debug_selector(|| ABSENCE_NOTICE_TAG.into())
39 .child(
40 div()
41 .flex_1()
42 .min_w_0()
43 .truncate()
44 .text_size(px(13.))
45 .text_color(theme::text())
46 .child(notice.text()),
47 )
48 .child(
49 div()
50 .id("absence-notice-close")
51 .size(px(CLOSE_SIZE))
52 .flex_none()
53 .flex()
54 .items_center()
55 .justify_center()
56 .rounded(px(6.))
57 .cursor_pointer()
58 .hover(|button| button.bg(theme::row_hover()))
59 .child(icon(IconName::Close, 14., theme::text_muted()))
60 .on_click(move |_, _, cx| {
61 app.update(cx, |state, cx| state.dismiss_absence_notice(&conversation_id, cx));
62 }),
63 )
64 .into_any_element(),
65 )
66 }
67}