BlueGit

ict rusty-teams

feat(composer): delivery options Standard / Important / Urgent like Teams

- "Set delivery options" button right after Format, popover with the Teams texts, icons and check
- inline IMPORTANT! / URGENT! label in the compose box, urgent banner (dismiss = Standard)
- Graph send body carries "importance": "high" | "urgent" (chat, channel post, replies), outbox keeps it
- Urgent hidden like Teams (editing, notes, bot 1:1, meeting chat, channel, messaging policy), disabled above 20 people
- messaging policy read via useraggregatesettings {"messagingPolicy": true}
- edits and scheduled sends stay Standard; reset after send and on chat switch
- layout_guard: menu inside the window, banner on the composer edges, label on the icon edge

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-18 · 6 weeks ago

Hash
389b7a00aeb85922ea5c3ba73be243ffb813fdfe
Parent
74624595
20 files changed +787 −2
crates/app-state/src/app_state.rs +3 −0
@@ -140,6 +140,7 @@ pub struct AppState {
140 140 pub call_count: u64,
141 141 pub call_share_sound: bool,
142 142 pub recording_policy: teams_core::RecordingPolicy,
143 pub allow_priority_messages: bool,
143 144 pub account_sounds: Option<chatsvc::sound_settings::SoundSettings>,
144 145 pub own_tenant: Option<String>,
145 146 pub call_share_motion: bool,
@@ -294,6 +295,7 @@ impl AppState {
294 295 call_count: 0,
295 296 call_share_sound: false,
296 297 recording_policy: teams_core::RecordingPolicy::default(),
298 allow_priority_messages: true,
297 299 account_sounds: None,
298 300 own_tenant: None,
299 301 call_share_motion: false,
@@ -999,6 +1001,7 @@ impl AppState {
999 1001 self.refresh_scheduled(cx);
1000 1002 self.refresh_translation_settings(cx);
1001 1003 self.refresh_recording_policy(cx);
1004 self.refresh_messaging_policy(cx);
1002 1005 self.refresh_sound_settings(cx);
1003 1006 let waiting = self.directory.waiting_presence_ids();
1004 1007 self.request_presence(waiting, cx);
@@ -140,6 +140,7 @@ pub struct AppState {
140 pub call_count: u64,
140 pub call_count: u64,
141 pub call_share_sound: bool,
141 pub call_share_sound: bool,
142 pub recording_policy: teams_core::RecordingPolicy,
142 pub recording_policy: teams_core::RecordingPolicy,
143 pub allow_priority_messages: bool,
143 pub account_sounds: Option<chatsvc::sound_settings::SoundSettings>,
144 pub account_sounds: Option<chatsvc::sound_settings::SoundSettings>,
144 pub own_tenant: Option<String>,
145 pub own_tenant: Option<String>,
145 pub call_share_motion: bool,
146 pub call_share_motion: bool,
@@ -294,6 +295,7 @@ impl AppState {
294 call_count: 0,
295 call_count: 0,
295 call_share_sound: false,
296 call_share_sound: false,
296 recording_policy: teams_core::RecordingPolicy::default(),
297 recording_policy: teams_core::RecordingPolicy::default(),
298 allow_priority_messages: true,
297 account_sounds: None,
299 account_sounds: None,
298 own_tenant: None,
300 own_tenant: None,
299 call_share_motion: false,
301 call_share_motion: false,
@@ -999,6 +1001,7 @@ impl AppState {
999 self.refresh_scheduled(cx);
1001 self.refresh_scheduled(cx);
1000 self.refresh_translation_settings(cx);
1002 self.refresh_translation_settings(cx);
1001 self.refresh_recording_policy(cx);
1003 self.refresh_recording_policy(cx);
1004 self.refresh_messaging_policy(cx);
1002 self.refresh_sound_settings(cx);
1005 self.refresh_sound_settings(cx);
1003 let waiting = self.directory.waiting_presence_ids();
1006 let waiting = self.directory.waiting_presence_ids();
1004 self.request_presence(waiting, cx);
1007 self.request_presence(waiting, cx);
crates/app-state/src/delivery_options.rs added +263 −0
@@ -0,0 +1,263 @@
1 use gpui_kit::Context;
2 use store::MessageImportance;
3 use teams_core::NOTES_CHAT_ID;
4
5 use crate::app_state::AppState;
6 use crate::data::is_one_on_one;
7 use crate::runtime;
8
9 pub const DELIVERY_BUTTON_TITLE: &str = "Set delivery options";
10 pub const URGENT_MAX_MEMBERS: usize = 20;
11 pub const URGENT_TOO_MANY_MEMBERS: &str = "Unavailable in chats with more than 20 people";
12 const MEETING_KIND: &str = "meeting";
13
14 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
15 pub struct DeliveryOption {
16 pub importance: MessageImportance,
17 pub header: &'static str,
18 pub content: &'static str,
19 pub symbol: &'static str,
20 pub tag: &'static str,
21 }
22
23 pub const STANDARD: DeliveryOption = DeliveryOption {
24 importance: MessageImportance::Normal,
25 header: "Standard",
26 content: "Message will be sent as usual",
27 symbol: "fluent_chat",
28 tag: "standard-delivery-option",
29 };
30
31 pub const IMPORTANT: DeliveryOption = DeliveryOption {
32 importance: MessageImportance::High,
33 header: "Important",
34 content: "Message will be marked as important",
35 symbol: "fluent_important",
36 tag: "important-delivery-option",
37 };
38
39 pub const URGENT: DeliveryOption = DeliveryOption {
40 importance: MessageImportance::Urgent,
41 header: "Urgent",
42 content: "Recipient(s) notified every 2 min for 20 min",
43 symbol: "fluent_alert_urgent",
44 tag: "urgent-delivery-option",
45 };
46
47 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
48 pub enum UrgentAvailability {
49 Hidden,
50 Disabled,
51 Available,
52 }
53
54 #[derive(Debug, Clone, Copy, Default)]
55 pub struct DeliveryContext<'a> {
56 pub conversation_id: &'a str,
57 pub chat_kind: &'a str,
58 pub member_count: usize,
59 pub channel: bool,
60 pub one_on_one_bot: bool,
61 pub editing: bool,
62 pub policy_allows_urgent: bool,
63 }
64
65 /// Teams hides Urgent while editing, in notes, bot 1:1 chats, meeting chats, channels and when the messaging policy denies priority messages; more than 20 people disable it.
66 pub fn urgent_availability(context: &DeliveryContext) -> UrgentAvailability {
67 let hidden = context.editing
68 || !context.policy_allows_urgent
69 || context.conversation_id == NOTES_CHAT_ID
70 || context.one_on_one_bot
71 || context.channel
72 || context.chat_kind.eq_ignore_ascii_case(MEETING_KIND);
73 if hidden {
74 UrgentAvailability::Hidden
75 } else if context.member_count > URGENT_MAX_MEMBERS {
76 UrgentAvailability::Disabled
77 } else {
78 UrgentAvailability::Available
79 }
80 }
81
82 impl AppState {
83 pub fn urgent_availability(&self, conversation_id: &str, editing: bool) -> UrgentAvailability {
84 let chat = self
85 .sidebar
86 .chats
87 .iter()
88 .find(|chat| chat.id == conversation_id);
89 let one_on_one_bot = chat.is_some_and(|chat| {
90 is_one_on_one(chat)
91 && self
92 .bot_apps
93 .get(&chat.id)
94 .is_some_and(|apps| apps.iter().any(|app| !app.bot_ids.is_empty()))
95 });
96 urgent_availability(&DeliveryContext {
97 conversation_id,
98 chat_kind: chat.map_or("", |chat| chat.kind.as_str()),
99 member_count: chat.map_or(0, |chat| chat.members.len()),
100 channel: chat.is_none() && !conversation_id.is_empty(),
101 one_on_one_bot,
102 editing,
103 policy_allows_urgent: self.allow_priority_messages,
104 })
105 }
106
107 pub fn refresh_messaging_policy(&mut self, cx: &mut Context<Self>) {
108 let Some(engine) = self.engine.clone() else {
109 return;
110 };
111 let read = runtime::spawn(async move { engine.allow_priority_messages().await.ok() });
112 cx.spawn(async move |this, cx| {
113 let Some(allowed) = read.await.ok().flatten() else {
114 return;
115 };
116 this.update(cx, |state, cx| {
117 state.allow_priority_messages = allowed;
118 cx.notify();
119 })
120 .ok();
121 })
122 .detach();
123 }
124 }
125
126 pub fn delivery_options(urgent: UrgentAvailability) -> Vec<(DeliveryOption, bool)> {
127 let mut options = vec![(STANDARD, true), (IMPORTANT, true)];
128 match urgent {
129 UrgentAvailability::Hidden => {}
130 UrgentAvailability::Disabled => options.push((URGENT, false)),
131 UrgentAvailability::Available => options.push((URGENT, true)),
132 }
133 options
134 }
135
136 /// The importance that can still be sent once the chat or the policy changed.
137 pub fn allowed_importance(
138 importance: MessageImportance,
139 urgent: UrgentAvailability,
140 ) -> MessageImportance {
141 if importance == MessageImportance::Urgent && urgent != UrgentAvailability::Available {
142 MessageImportance::Normal
143 } else {
144 importance
145 }
146 }
147
148 pub fn urgent_banner(member_count: usize) -> &'static str {
149 if member_count > 2 {
150 "Notify recipients every 2 minutes for 20 minutes"
151 } else {
152 "Notify recipient every 2 minutes for 20 minutes"
153 }
154 }
155
156 #[cfg(test)]
157 mod tests {
158 use super::*;
159
160 fn group(member_count: usize) -> DeliveryContext<'static> {
161 DeliveryContext {
162 conversation_id: "19:group@thread.v2",
163 chat_kind: "group",
164 member_count,
165 policy_allows_urgent: true,
166 ..Default::default()
167 }
168 }
169
170 #[test]
171 fn urgent_is_offered_in_ordinary_chats() {
172 assert_eq!(
173 urgent_availability(&group(5)),
174 UrgentAvailability::Available
175 );
176 let options: Vec<_> = delivery_options(UrgentAvailability::Available)
177 .into_iter()
178 .map(|(option, enabled)| (option.header, enabled))
179 .collect();
180 assert_eq!(
181 options,
182 [("Standard", true), ("Important", true), ("Urgent", true)]
183 );
184 }
185
186 #[test]
187 fn urgent_is_hidden_where_teams_hides_it() {
188 let hidden = [
189 DeliveryContext {
190 conversation_id: NOTES_CHAT_ID,
191 ..group(1)
192 },
193 DeliveryContext {
194 chat_kind: "meeting",
195 ..group(4)
196 },
197 DeliveryContext {
198 one_on_one_bot: true,
199 ..group(1)
200 },
201 DeliveryContext {
202 channel: true,
203 ..group(4)
204 },
205 DeliveryContext {
206 editing: true,
207 ..group(4)
208 },
209 DeliveryContext {
210 policy_allows_urgent: false,
211 ..group(4)
212 },
213 ];
214 for context in hidden {
215 assert_eq!(
216 urgent_availability(&context),
217 UrgentAvailability::Hidden,
218 "{context:?}"
219 );
220 }
221 assert_eq!(delivery_options(UrgentAvailability::Hidden).len(), 2);
222 }
223
224 #[test]
225 fn more_than_twenty_people_disable_urgent() {
226 assert_eq!(
227 urgent_availability(&group(20)),
228 UrgentAvailability::Available
229 );
230 assert_eq!(
231 urgent_availability(&group(21)),
232 UrgentAvailability::Disabled
233 );
234 assert_eq!(
235 delivery_options(UrgentAvailability::Disabled)[2],
236 (URGENT, false)
237 );
238 }
239
240 #[test]
241 fn a_chosen_urgent_falls_back_to_standard_where_it_is_not_allowed() {
242 assert_eq!(
243 allowed_importance(MessageImportance::Urgent, UrgentAvailability::Disabled),
244 MessageImportance::Normal
245 );
246 assert_eq!(
247 allowed_importance(MessageImportance::High, UrgentAvailability::Hidden),
248 MessageImportance::High
249 );
250 }
251
252 #[test]
253 fn the_banner_uses_the_plural_for_more_than_two_members() {
254 assert_eq!(
255 urgent_banner(2),
256 "Notify recipient every 2 minutes for 20 minutes"
257 );
258 assert_eq!(
259 urgent_banner(3),
260 "Notify recipients every 2 minutes for 20 minutes"
261 );
262 }
263 }
@@ -0,0 +1,263 @@
1use gpui_kit::Context;
2use store::MessageImportance;
3use teams_core::NOTES_CHAT_ID;
4
5use crate::app_state::AppState;
6use crate::data::is_one_on_one;
7use crate::runtime;
8
9pub const DELIVERY_BUTTON_TITLE: &str = "Set delivery options";
10pub const URGENT_MAX_MEMBERS: usize = 20;
11pub const URGENT_TOO_MANY_MEMBERS: &str = "Unavailable in chats with more than 20 people";
12const MEETING_KIND: &str = "meeting";
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub struct DeliveryOption {
16 pub importance: MessageImportance,
17 pub header: &'static str,
18 pub content: &'static str,
19 pub symbol: &'static str,
20 pub tag: &'static str,
21}
22
23pub const STANDARD: DeliveryOption = DeliveryOption {
24 importance: MessageImportance::Normal,
25 header: "Standard",
26 content: "Message will be sent as usual",
27 symbol: "fluent_chat",
28 tag: "standard-delivery-option",
29};
30
31pub const IMPORTANT: DeliveryOption = DeliveryOption {
32 importance: MessageImportance::High,
33 header: "Important",
34 content: "Message will be marked as important",
35 symbol: "fluent_important",
36 tag: "important-delivery-option",
37};
38
39pub const URGENT: DeliveryOption = DeliveryOption {
40 importance: MessageImportance::Urgent,
41 header: "Urgent",
42 content: "Recipient(s) notified every 2 min for 20 min",
43 symbol: "fluent_alert_urgent",
44 tag: "urgent-delivery-option",
45};
46
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum UrgentAvailability {
49 Hidden,
50 Disabled,
51 Available,
52}
53
54#[derive(Debug, Clone, Copy, Default)]
55pub struct DeliveryContext<'a> {
56 pub conversation_id: &'a str,
57 pub chat_kind: &'a str,
58 pub member_count: usize,
59 pub channel: bool,
60 pub one_on_one_bot: bool,
61 pub editing: bool,
62 pub policy_allows_urgent: bool,
63}
64
65/// Teams hides Urgent while editing, in notes, bot 1:1 chats, meeting chats, channels and when the messaging policy denies priority messages; more than 20 people disable it.
66pub fn urgent_availability(context: &DeliveryContext) -> UrgentAvailability {
67 let hidden = context.editing
68 || !context.policy_allows_urgent
69 || context.conversation_id == NOTES_CHAT_ID
70 || context.one_on_one_bot
71 || context.channel
72 || context.chat_kind.eq_ignore_ascii_case(MEETING_KIND);
73 if hidden {
74 UrgentAvailability::Hidden
75 } else if context.member_count > URGENT_MAX_MEMBERS {
76 UrgentAvailability::Disabled
77 } else {
78 UrgentAvailability::Available
79 }
80}
81
82impl AppState {
83 pub fn urgent_availability(&self, conversation_id: &str, editing: bool) -> UrgentAvailability {
84 let chat = self
85 .sidebar
86 .chats
87 .iter()
88 .find(|chat| chat.id == conversation_id);
89 let one_on_one_bot = chat.is_some_and(|chat| {
90 is_one_on_one(chat)
91 && self
92 .bot_apps
93 .get(&chat.id)
94 .is_some_and(|apps| apps.iter().any(|app| !app.bot_ids.is_empty()))
95 });
96 urgent_availability(&DeliveryContext {
97 conversation_id,
98 chat_kind: chat.map_or("", |chat| chat.kind.as_str()),
99 member_count: chat.map_or(0, |chat| chat.members.len()),
100 channel: chat.is_none() && !conversation_id.is_empty(),
101 one_on_one_bot,
102 editing,
103 policy_allows_urgent: self.allow_priority_messages,
104 })
105 }
106
107 pub fn refresh_messaging_policy(&mut self, cx: &mut Context<Self>) {
108 let Some(engine) = self.engine.clone() else {
109 return;
110 };
111 let read = runtime::spawn(async move { engine.allow_priority_messages().await.ok() });
112 cx.spawn(async move |this, cx| {
113 let Some(allowed) = read.await.ok().flatten() else {
114 return;
115 };
116 this.update(cx, |state, cx| {
117 state.allow_priority_messages = allowed;
118 cx.notify();
119 })
120 .ok();
121 })
122 .detach();
123 }
124}
125
126pub fn delivery_options(urgent: UrgentAvailability) -> Vec<(DeliveryOption, bool)> {
127 let mut options = vec![(STANDARD, true), (IMPORTANT, true)];
128 match urgent {
129 UrgentAvailability::Hidden => {}
130 UrgentAvailability::Disabled => options.push((URGENT, false)),
131 UrgentAvailability::Available => options.push((URGENT, true)),
132 }
133 options
134}
135
136/// The importance that can still be sent once the chat or the policy changed.
137pub fn allowed_importance(
138 importance: MessageImportance,
139 urgent: UrgentAvailability,
140) -> MessageImportance {
141 if importance == MessageImportance::Urgent && urgent != UrgentAvailability::Available {
142 MessageImportance::Normal
143 } else {
144 importance
145 }
146}
147
148pub fn urgent_banner(member_count: usize) -> &'static str {
149 if member_count > 2 {
150 "Notify recipients every 2 minutes for 20 minutes"
151 } else {
152 "Notify recipient every 2 minutes for 20 minutes"
153 }
154}
155
156#[cfg(test)]
157mod tests {
158 use super::*;
159
160 fn group(member_count: usize) -> DeliveryContext<'static> {
161 DeliveryContext {
162 conversation_id: "19:group@thread.v2",
163 chat_kind: "group",
164 member_count,
165 policy_allows_urgent: true,
166 ..Default::default()
167 }
168 }
169
170 #[test]
171 fn urgent_is_offered_in_ordinary_chats() {
172 assert_eq!(
173 urgent_availability(&group(5)),
174 UrgentAvailability::Available
175 );
176 let options: Vec<_> = delivery_options(UrgentAvailability::Available)
177 .into_iter()
178 .map(|(option, enabled)| (option.header, enabled))
179 .collect();
180 assert_eq!(
181 options,
182 [("Standard", true), ("Important", true), ("Urgent", true)]
183 );
184 }
185
186 #[test]
187 fn urgent_is_hidden_where_teams_hides_it() {
188 let hidden = [
189 DeliveryContext {
190 conversation_id: NOTES_CHAT_ID,
191 ..group(1)
192 },
193 DeliveryContext {
194 chat_kind: "meeting",
195 ..group(4)
196 },
197 DeliveryContext {
198 one_on_one_bot: true,
199 ..group(1)
200 },
201 DeliveryContext {
202 channel: true,
203 ..group(4)
204 },
205 DeliveryContext {
206 editing: true,
207 ..group(4)
208 },
209 DeliveryContext {
210 policy_allows_urgent: false,
211 ..group(4)
212 },
213 ];
214 for context in hidden {
215 assert_eq!(
216 urgent_availability(&context),
217 UrgentAvailability::Hidden,
218 "{context:?}"
219 );
220 }
221 assert_eq!(delivery_options(UrgentAvailability::Hidden).len(), 2);
222 }
223
224 #[test]
225 fn more_than_twenty_people_disable_urgent() {
226 assert_eq!(
227 urgent_availability(&group(20)),
228 UrgentAvailability::Available
229 );
230 assert_eq!(
231 urgent_availability(&group(21)),
232 UrgentAvailability::Disabled
233 );
234 assert_eq!(
235 delivery_options(UrgentAvailability::Disabled)[2],
236 (URGENT, false)
237 );
238 }
239
240 #[test]
241 fn a_chosen_urgent_falls_back_to_standard_where_it_is_not_allowed() {
242 assert_eq!(
243 allowed_importance(MessageImportance::Urgent, UrgentAvailability::Disabled),
244 MessageImportance::Normal
245 );
246 assert_eq!(
247 allowed_importance(MessageImportance::High, UrgentAvailability::Hidden),
248 MessageImportance::High
249 );
250 }
251
252 #[test]
253 fn the_banner_uses_the_plural_for_more_than_two_members() {
254 assert_eq!(
255 urgent_banner(2),
256 "Notify recipient every 2 minutes for 20 minutes"
257 );
258 assert_eq!(
259 urgent_banner(3),
260 "Notify recipients every 2 minutes for 20 minutes"
261 );
262 }
263}
crates/app-state/src/lib.rs +1 −0
@@ -13,6 +13,7 @@ pub mod chat_actions;
13 13 pub mod chat_members;
14 14 pub mod connection_banner;
15 15 pub mod data;
16 pub mod delivery_options;
16 17 pub mod demo;
17 18 pub mod demo_meetings;
18 19 pub mod demo_profiles;
@@ -13,6 +13,7 @@ pub mod chat_actions;
13pub mod chat_members;
13pub mod chat_members;
14pub mod connection_banner;
14pub mod connection_banner;
15pub mod data;
15pub mod data;
16pub mod delivery_options;
16pub mod demo;
17pub mod demo;
17pub mod demo_meetings;
18pub mod demo_meetings;
18pub mod demo_profiles;
19pub mod demo_profiles;
crates/app-state/src/outgoing.rs +4 −0
@@ -8,6 +8,8 @@ use teams_core::{
8 8 OBJECT_MARK, UploadedFile,
9 9 };
10 10
11 use store::MessageImportance;
12
11 13 use crate::remote_image::RemoteImage;
12 14
13 15 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -57,6 +59,7 @@ pub struct Outgoing {
57 59 pub images: Vec<OutgoingImage>,
58 60 pub files: Vec<OutgoingFile>,
59 61 pub link_preview: Option<LinkPreview>,
62 pub importance: MessageImportance,
60 63 }
61 64
62 65 impl Outgoing {
@@ -95,6 +98,7 @@ impl Outgoing {
95 98
96 99 pub fn extras(&self) -> MessageExtras {
97 100 MessageExtras {
101 importance: self.importance.stored(),
98 102 kept: Vec::new(),
99 103 images: self
100 104 .images
@@ -8,6 +8,8 @@ use teams_core::{
8 OBJECT_MARK, UploadedFile,
8 OBJECT_MARK, UploadedFile,
9};
9};
10
10
11use store::MessageImportance;
12
11use crate::remote_image::RemoteImage;
13use crate::remote_image::RemoteImage;
12
14
13#[derive(Debug, Clone, PartialEq, Eq)]
15#[derive(Debug, Clone, PartialEq, Eq)]
@@ -57,6 +59,7 @@ pub struct Outgoing {
57 pub images: Vec<OutgoingImage>,
59 pub images: Vec<OutgoingImage>,
58 pub files: Vec<OutgoingFile>,
60 pub files: Vec<OutgoingFile>,
59 pub link_preview: Option<LinkPreview>,
61 pub link_preview: Option<LinkPreview>,
62 pub importance: MessageImportance,
60}
63}
61
64
62impl Outgoing {
65impl Outgoing {
@@ -95,6 +98,7 @@ impl Outgoing {
95
98
96 pub fn extras(&self) -> MessageExtras {
99 pub fn extras(&self) -> MessageExtras {
97 MessageExtras {
100 MessageExtras {
101 importance: self.importance.stored(),
98 kept: Vec::new(),
102 kept: Vec::new(),
99 images: self
103 images: self
100 .images
104 .images
crates/app-state/src/pending_rows.rs +2 −1
@@ -79,7 +79,7 @@ pub fn pending_row(
79 79 })
80 80 .collect(),
81 81 subject: outgoing.subject.clone(),
82 importance: store::MessageImportance::Normal,
82 importance: outgoing.importance,
83 83 new_marker: false,
84 84 reply_root: None,
85 85 delivery,
@@ -113,6 +113,7 @@ mod tests {
113 113 images: Vec::new(),
114 114 files: Vec::new(),
115 115 link_preview: None,
116 importance: Default::default(),
116 117 };
117 118 let row = pending_row(
118 119 "key".to_owned(),
@@ -79,7 +79,7 @@ pub fn pending_row(
79 })
79 })
80 .collect(),
80 .collect(),
81 subject: outgoing.subject.clone(),
81 subject: outgoing.subject.clone(),
82 importance: store::MessageImportance::Normal,
82 importance: outgoing.importance,
83 new_marker: false,
83 new_marker: false,
84 reply_root: None,
84 reply_root: None,
85 delivery,
85 delivery,
@@ -113,6 +113,7 @@ mod tests {
113 images: Vec::new(),
113 images: Vec::new(),
114 files: Vec::new(),
114 files: Vec::new(),
115 link_preview: None,
115 link_preview: None,
116 importance: Default::default(),
116 };
117 };
117 let row = pending_row(
118 let row = pending_row(
118 "key".to_owned(),
119 "key".to_owned(),
crates/app-state/src/scheduled_rows.rs +1 −0
@@ -35,6 +35,7 @@ pub fn scheduled_outgoing(html: &str) -> Outgoing {
35 35 images: Vec::new(),
36 36 files: Vec::new(),
37 37 link_preview: None,
38 importance: Default::default(),
38 39 }
39 40 }
40 41
@@ -35,6 +35,7 @@ pub fn scheduled_outgoing(html: &str) -> Outgoing {
35 images: Vec::new(),
35 images: Vec::new(),
36 files: Vec::new(),
36 files: Vec::new(),
37 link_preview: None,
37 link_preview: None,
38 importance: Default::default(),
38 }
39 }
39}
40}
40
41
crates/app-state/src/stored_outgoing.rs +25 −1
@@ -2,7 +2,7 @@ use std::sync::Arc;
2 2
3 3 use gpui_kit::{Image, ImageFormat};
4 4 use serde::{Deserialize, Serialize};
5 use store::AttachmentImage;
5 use store::{AttachmentImage, MessageImportance};
6 6 use teams_core::{Draft, DraftLine, LinkPreview, MentionInput};
7 7
8 8 use crate::remote_image::{RemoteImage, RemoteKind};
@@ -55,6 +55,8 @@ struct Payload {
55 55 files: Vec<OutgoingFile>,
56 56 objects: Vec<StoredObject>,
57 57 preview: Option<StoredPreview>,
58 #[serde(default)]
59 importance: Option<String>,
58 60 }
59 61
60 62 pub struct StoredOutgoing {
@@ -106,6 +108,7 @@ pub fn encode(outgoing: &Outgoing) -> Option<StoredOutgoing> {
106 108 image_width: preview.image_width,
107 109 image_height: preview.image_height,
108 110 }),
111 importance: outgoing.importance.stored().map(str::to_owned),
109 112 })
110 113 .ok()?;
111 114 Some(StoredOutgoing { payload, images })
@@ -141,6 +144,7 @@ pub fn decode(payload: &str, images: &[AttachmentImage]) -> Option<Outgoing> {
141 144 files,
142 145 objects,
143 146 preview,
147 importance,
144 148 } = serde_json::from_str(payload).ok()?;
145 149 let mut inline = images.iter();
146 150 let images = objects
@@ -167,6 +171,7 @@ pub fn decode(payload: &str, images: &[AttachmentImage]) -> Option<Outgoing> {
167 171 image_width: preview.image_width,
168 172 image_height: preview.image_height,
169 173 }),
174 importance: MessageImportance::from_stored(importance.as_deref()),
170 175 })
171 176 }
172 177
@@ -223,6 +228,7 @@ mod tests {
223 228 image_width: None,
224 229 image_height: None,
225 230 }),
231 importance: Default::default(),
226 232 }
227 233 }
228 234
@@ -243,6 +249,24 @@ mod tests {
243 249 assert_eq!(restored.edit, None);
244 250 }
245 251
252 #[test]
253 fn the_importance_survives_the_outbox_and_old_payloads_stay_standard() {
254 let original = Outgoing {
255 importance: MessageImportance::Urgent,
256 ..outgoing()
257 };
258 let stored = encode(&original).unwrap();
259 let decoded = decode(&stored.payload, &stored.images).unwrap();
260 assert_eq!(decoded.importance, MessageImportance::Urgent);
261 assert_eq!(decoded.extras().importance, Some("urgent"));
262 let plain = encode(&outgoing()).unwrap();
263 assert!(!plain.payload.contains("importance\":\""));
264 assert_eq!(
265 decode(&plain.payload, &plain.images).unwrap().importance,
266 MessageImportance::Normal
267 );
268 }
269
246 270 #[test]
247 271 fn an_unreadable_payload_decodes_to_nothing() {
248 272 assert!(decode("not json", &[]).is_none());
@@ -2,7 +2,7 @@ use std::sync::Arc;
2
2
3use gpui_kit::{Image, ImageFormat};
3use gpui_kit::{Image, ImageFormat};
4use serde::{Deserialize, Serialize};
4use serde::{Deserialize, Serialize};
5use store::AttachmentImage;
5use store::{AttachmentImage, MessageImportance};
6use teams_core::{Draft, DraftLine, LinkPreview, MentionInput};
6use teams_core::{Draft, DraftLine, LinkPreview, MentionInput};
7
7
8use crate::remote_image::{RemoteImage, RemoteKind};
8use crate::remote_image::{RemoteImage, RemoteKind};
@@ -55,6 +55,8 @@ struct Payload {
55 files: Vec<OutgoingFile>,
55 files: Vec<OutgoingFile>,
56 objects: Vec<StoredObject>,
56 objects: Vec<StoredObject>,
57 preview: Option<StoredPreview>,
57 preview: Option<StoredPreview>,
58 #[serde(default)]
59 importance: Option<String>,
58}
60}
59
61
60pub struct StoredOutgoing {
62pub struct StoredOutgoing {
@@ -106,6 +108,7 @@ pub fn encode(outgoing: &Outgoing) -> Option<StoredOutgoing> {
106 image_width: preview.image_width,
108 image_width: preview.image_width,
107 image_height: preview.image_height,
109 image_height: preview.image_height,
108 }),
110 }),
111 importance: outgoing.importance.stored().map(str::to_owned),
109 })
112 })
110 .ok()?;
113 .ok()?;
111 Some(StoredOutgoing { payload, images })
114 Some(StoredOutgoing { payload, images })
@@ -141,6 +144,7 @@ pub fn decode(payload: &str, images: &[AttachmentImage]) -> Option<Outgoing> {
141 files,
144 files,
142 objects,
145 objects,
143 preview,
146 preview,
147 importance,
144 } = serde_json::from_str(payload).ok()?;
148 } = serde_json::from_str(payload).ok()?;
145 let mut inline = images.iter();
149 let mut inline = images.iter();
146 let images = objects
150 let images = objects
@@ -167,6 +171,7 @@ pub fn decode(payload: &str, images: &[AttachmentImage]) -> Option<Outgoing> {
167 image_width: preview.image_width,
171 image_width: preview.image_width,
168 image_height: preview.image_height,
172 image_height: preview.image_height,
169 }),
173 }),
174 importance: MessageImportance::from_stored(importance.as_deref()),
170 })
175 })
171}
176}
172
177
@@ -223,6 +228,7 @@ mod tests {
223 image_width: None,
228 image_width: None,
224 image_height: None,
229 image_height: None,
225 }),
230 }),
231 importance: Default::default(),
226 }
232 }
227 }
233 }
228
234
@@ -243,6 +249,24 @@ mod tests {
243 assert_eq!(restored.edit, None);
249 assert_eq!(restored.edit, None);
244 }
250 }
245
251
252 #[test]
253 fn the_importance_survives_the_outbox_and_old_payloads_stay_standard() {
254 let original = Outgoing {
255 importance: MessageImportance::Urgent,
256 ..outgoing()
257 };
258 let stored = encode(&original).unwrap();
259 let decoded = decode(&stored.payload, &stored.images).unwrap();
260 assert_eq!(decoded.importance, MessageImportance::Urgent);
261 assert_eq!(decoded.extras().importance, Some("urgent"));
262 let plain = encode(&outgoing()).unwrap();
263 assert!(!plain.payload.contains("importance\":\""));
264 assert_eq!(
265 decode(&plain.payload, &plain.images).unwrap().importance,
266 MessageImportance::Normal
267 );
268 }
269
246 #[test]
270 #[test]
247 fn an_unreadable_payload_decodes_to_nothing() {
271 fn an_unreadable_payload_decodes_to_nothing() {
248 assert!(decode("not json", &[]).is_none());
272 assert!(decode("not json", &[]).is_none());
crates/app/src/layout_guard.rs +90 −0
@@ -176,6 +176,10 @@ mod frames {
176 176 use crate::user_activity::UserInput;
177 177 use crate::views::call_transcript::TranscriptPanel;
178 178 use crate::views::call_view::CHAT_PANEL_TAG;
179 use crate::views::composer::delivery::{
180 COMPOSER_DELIVERY_TAG, COMPOSER_IMPORTANCE_LABEL_TAG, COMPOSER_URGENT_BANNER_TAG,
181 DELIVERY_MENU_TAG,
182 };
179 183 use crate::views::composer::{
180 184 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
181 185 COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,
@@ -1620,6 +1624,92 @@ mod frames {
1620 1624 }
1621 1625 }
1622 1626
1627 #[gpui_kit::test]
1628 fn delivery_options_label_and_banner_line_up_with_the_composer(cx: &mut TestAppContext) {
1629 const DELIVERY_TAGS: [&str; 5] = [
1630 COMPOSER_BOX_TAG,
1631 COMPOSER_LEADING_TAG,
1632 COMPOSER_DELIVERY_TAG,
1633 COMPOSER_IMPORTANCE_LABEL_TAG,
1634 COMPOSER_URGENT_BANNER_TAG,
1635 ];
1636 const URGENT_OPTION: &str = "urgent-delivery-option";
1637 const BUTTON_ICON_INSET: f32 = 6.;
1638 let (handle, _) = mount(cx);
1639 let mut visual = VisualTestContext::from_window(handle, cx);
1640 for (width, height) in SIZES {
1641 visual.simulate_resize(size(px(width), px(height)));
1642 let window = Bounds {
1643 origin: point(px(0.), px(0.)),
1644 size: size(px(width), px(height)),
1645 };
1646 collect(&mut visual, Some(COMPOSER_DELIVERY_TAG));
1647 let button = visual
1648 .debug_bounds(COMPOSER_DELIVERY_TAG)
1649 .expect("delivery button");
1650 visual.simulate_click(button.center(), Default::default());
1651 collect(&mut visual, Some(URGENT_OPTION));
1652 let menu = visual.debug_bounds(DELIVERY_MENU_TAG).expect("menu");
1653 assert!(
1654 contains(window, menu),
1655 "menu {} leaves the window",
1656 describe(menu)
1657 );
1658 let urgent = visual.debug_bounds(URGENT_OPTION).expect("urgent option");
1659 visual.simulate_click(urgent.center(), Default::default());
1660 collect(&mut visual, Some(COMPOSER_URGENT_BANNER_TAG));
1661 assert!(visual.debug_bounds(DELIVERY_MENU_TAG).is_none());
1662 let tags: Vec<Tag> = DELIVERY_TAGS
1663 .iter()
1664 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
1665 .collect();
1666 let found: Vec<String> = violations(&tags, window, &DELIVERY_TAGS)
1667 .into_iter()
1668 .map(|(key, message)| format!("delivery@{width}x{height}:{key}: {message}"))
1669 .collect();
1670 assert!(found.is_empty(), "{}", found.join("\n"));
1671 let composer = visual.debug_bounds(COMPOSER_BOX_TAG).expect("composer");
1672 let banner = visual
1673 .debug_bounds(COMPOSER_URGENT_BANNER_TAG)
1674 .expect("banner");
1675 let label = visual
1676 .debug_bounds(COMPOSER_IMPORTANCE_LABEL_TAG)
1677 .expect("label");
1678 let leading = visual.debug_bounds(COMPOSER_LEADING_TAG).expect("leading");
1679 assert!(
1680 (f32::from(banner.left() - composer.left())).abs() <= TOLERANCE
1681 && (f32::from(banner.right() - composer.right())).abs() <= TOLERANCE,
1682 "banner {} not on the composer edges {}",
1683 describe(banner),
1684 describe(composer)
1685 );
1686 assert!(
1687 banner.bottom() <= composer.top(),
1688 "banner {} over the composer {}",
1689 describe(banner),
1690 describe(composer)
1691 );
1692 assert!(
1693 (inset(composer, label, Edge::Left)
1694 - inset(composer, leading, Edge::Left)
1695 - BUTTON_ICON_INSET)
1696 .abs()
1697 <= TOLERANCE,
1698 "label {} not on the icon edge of {}",
1699 describe(label),
1700 describe(leading)
1701 );
1702 let close = visual
1703 .debug_bounds(COMPOSER_URGENT_BANNER_TAG)
1704 .map(|banner| point(banner.right() - px(18.), banner.center().y))
1705 .expect("banner");
1706 visual.simulate_click(close, Default::default());
1707 collect(&mut visual, None);
1708 assert!(visual.debug_bounds(COMPOSER_URGENT_BANNER_TAG).is_none());
1709 assert!(visual.debug_bounds(COMPOSER_IMPORTANCE_LABEL_TAG).is_none());
1710 }
1711 }
1712
1623 1713 #[gpui_kit::test]
1624 1714 fn importance_label_sits_inside_its_bubble_on_the_text_edge(cx: &mut TestAppContext) {
1625 1715 let (handle, state) = mount_with(cx, true);
@@ -176,6 +176,10 @@ mod frames {
176 use crate::user_activity::UserInput;
176 use crate::user_activity::UserInput;
177 use crate::views::call_transcript::TranscriptPanel;
177 use crate::views::call_transcript::TranscriptPanel;
178 use crate::views::call_view::CHAT_PANEL_TAG;
178 use crate::views::call_view::CHAT_PANEL_TAG;
179 use crate::views::composer::delivery::{
180 COMPOSER_DELIVERY_TAG, COMPOSER_IMPORTANCE_LABEL_TAG, COMPOSER_URGENT_BANNER_TAG,
181 DELIVERY_MENU_TAG,
182 };
179 use crate::views::composer::{
183 use crate::views::composer::{
180 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
184 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
181 COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,
185 COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,
@@ -1620,6 +1624,92 @@ mod frames {
1620 }
1624 }
1621 }
1625 }
1622
1626
1627 #[gpui_kit::test]
1628 fn delivery_options_label_and_banner_line_up_with_the_composer(cx: &mut TestAppContext) {
1629 const DELIVERY_TAGS: [&str; 5] = [
1630 COMPOSER_BOX_TAG,
1631 COMPOSER_LEADING_TAG,
1632 COMPOSER_DELIVERY_TAG,
1633 COMPOSER_IMPORTANCE_LABEL_TAG,
1634 COMPOSER_URGENT_BANNER_TAG,
1635 ];
1636 const URGENT_OPTION: &str = "urgent-delivery-option";
1637 const BUTTON_ICON_INSET: f32 = 6.;
1638 let (handle, _) = mount(cx);
1639 let mut visual = VisualTestContext::from_window(handle, cx);
1640 for (width, height) in SIZES {
1641 visual.simulate_resize(size(px(width), px(height)));
1642 let window = Bounds {
1643 origin: point(px(0.), px(0.)),
1644 size: size(px(width), px(height)),
1645 };
1646 collect(&mut visual, Some(COMPOSER_DELIVERY_TAG));
1647 let button = visual
1648 .debug_bounds(COMPOSER_DELIVERY_TAG)
1649 .expect("delivery button");
1650 visual.simulate_click(button.center(), Default::default());
1651 collect(&mut visual, Some(URGENT_OPTION));
1652 let menu = visual.debug_bounds(DELIVERY_MENU_TAG).expect("menu");
1653 assert!(
1654 contains(window, menu),
1655 "menu {} leaves the window",
1656 describe(menu)
1657 );
1658 let urgent = visual.debug_bounds(URGENT_OPTION).expect("urgent option");
1659 visual.simulate_click(urgent.center(), Default::default());
1660 collect(&mut visual, Some(COMPOSER_URGENT_BANNER_TAG));
1661 assert!(visual.debug_bounds(DELIVERY_MENU_TAG).is_none());
1662 let tags: Vec<Tag> = DELIVERY_TAGS
1663 .iter()
1664 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
1665 .collect();
1666 let found: Vec<String> = violations(&tags, window, &DELIVERY_TAGS)
1667 .into_iter()
1668 .map(|(key, message)| format!("delivery@{width}x{height}:{key}: {message}"))
1669 .collect();
1670 assert!(found.is_empty(), "{}", found.join("\n"));
1671 let composer = visual.debug_bounds(COMPOSER_BOX_TAG).expect("composer");
1672 let banner = visual
1673 .debug_bounds(COMPOSER_URGENT_BANNER_TAG)
1674 .expect("banner");
1675 let label = visual
1676 .debug_bounds(COMPOSER_IMPORTANCE_LABEL_TAG)
1677 .expect("label");
1678 let leading = visual.debug_bounds(COMPOSER_LEADING_TAG).expect("leading");
1679 assert!(
1680 (f32::from(banner.left() - composer.left())).abs() <= TOLERANCE
1681 && (f32::from(banner.right() - composer.right())).abs() <= TOLERANCE,
1682 "banner {} not on the composer edges {}",
1683 describe(banner),
1684 describe(composer)
1685 );
1686 assert!(
1687 banner.bottom() <= composer.top(),
1688 "banner {} over the composer {}",
1689 describe(banner),
1690 describe(composer)
1691 );
1692 assert!(
1693 (inset(composer, label, Edge::Left)
1694 - inset(composer, leading, Edge::Left)
1695 - BUTTON_ICON_INSET)
1696 .abs()
1697 <= TOLERANCE,
1698 "label {} not on the icon edge of {}",
1699 describe(label),
1700 describe(leading)
1701 );
1702 let close = visual
1703 .debug_bounds(COMPOSER_URGENT_BANNER_TAG)
1704 .map(|banner| point(banner.right() - px(18.), banner.center().y))
1705 .expect("banner");
1706 visual.simulate_click(close, Default::default());
1707 collect(&mut visual, None);
1708 assert!(visual.debug_bounds(COMPOSER_URGENT_BANNER_TAG).is_none());
1709 assert!(visual.debug_bounds(COMPOSER_IMPORTANCE_LABEL_TAG).is_none());
1710 }
1711 }
1712
1623 #[gpui_kit::test]
1713 #[gpui_kit::test]
1624 fn importance_label_sits_inside_its_bubble_on_the_text_edge(cx: &mut TestAppContext) {
1714 fn importance_label_sits_inside_its_bubble_on_the_text_edge(cx: &mut TestAppContext) {
1625 let (handle, state) = mount_with(cx, true);
1715 let (handle, state) = mount_with(cx, true);
crates/app/src/views/composer.rs +15 −0
@@ -29,6 +29,7 @@ use teams_core::{
29 29 UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,
30 30 };
31 31
32 pub(crate) mod delivery;
32 33 mod drafts;
33 34 mod schedule;
34 35 mod table;
@@ -225,6 +226,8 @@ pub struct Composer {
225 226 active_cell: Option<(String, teams_core::Cell)>,
226 227 caret_before_table: usize,
227 228 caret_text: String,
229 importance: store::MessageImportance,
230 delivery_menu: bool,
228 231 _subscriptions: [Subscription; 4],
229 232 }
230 233
@@ -436,6 +439,8 @@ impl Composer {
436 439 active_cell: None,
437 440 caret_before_table: 0,
438 441 caret_text: String::new(),
442 importance: store::MessageImportance::Normal,
443 delivery_menu: false,
439 444 _subscriptions: [subscription, observer, image_observer, picker_subscription],
440 445 }
441 446 }
@@ -1637,6 +1642,7 @@ impl Composer {
1637 1642 self.schedule = None;
1638 1643 self.table_picker = None;
1639 1644 self.table_menu = None;
1645 self.reset_importance();
1640 1646 if !carry {
1641 1647 self.load_stored_draft(conversation_id, window, cx);
1642 1648 }
@@ -1729,6 +1735,7 @@ impl Composer {
1729 1735 } else {
1730 1736 Vec::new()
1731 1737 },
1738 importance: self.sendable_importance(cx),
1732 1739 }
1733 1740 }
1734 1741
@@ -2205,6 +2212,7 @@ impl Composer {
2205 2212 self.editing = None;
2206 2213 self.link.reset();
2207 2214 self.close_popup();
2215 self.reset_importance();
2208 2216 cx.emit(ComposerEvent::Submit(Box::new(outgoing)));
2209 2217 cx.notify();
2210 2218 }
@@ -3104,6 +3112,7 @@ impl Render for Composer {
3104 3112 .children(notice)
3105 3113 .children(self.render_reply_strip(cx))
3106 3114 .children(self.render_edit_strip(cx))
3115 .children(self.render_urgent_banner(cx))
3107 3116 .children(self.render_meeting_chip())
3108 3117 .children(self.render_link_preview(cx))
3109 3118 .child(
@@ -3114,6 +3123,7 @@ impl Render for Composer {
3114 3123 .children(self.render_emoji_popup(window, cx))
3115 3124 .children(self.render_toolbar(focused, cx))
3116 3125 .children(self.render_schedule(cx))
3126 .children(self.render_delivery_menu(cx))
3117 3127 .child(
3118 3128 v_flex()
3119 3129 .debug_selector(|| COMPOSER_BOX_TAG.into())
@@ -3136,6 +3146,7 @@ impl Render for Composer {
3136 3146 .size_full(),
3137 3147 )
3138 3148 .children(format_bar)
3149 .children(self.render_importance_label(cx))
3139 3150 .children(tray)
3140 3151 .child(
3141 3152 h_flex()
@@ -3155,6 +3166,7 @@ impl Render for Composer {
3155 3166 .flex_none()
3156 3167 .gap(px(COMPOSER_BUTTON_INSET))
3157 3168 .child(format_toggle)
3169 .children(self.render_delivery_button(cx))
3158 3170 .children(fun)
3159 3171 .children(attach),
3160 3172 )
@@ -3295,6 +3307,7 @@ mod tests {
3295 3307 name: "plan.pdf".into(),
3296 3308 },
3297 3309 }],
3310 importance: Default::default(),
3298 3311 };
3299 3312 let extras = outgoing.extras();
3300 3313 assert_eq!(extras.images[0].content_type, "image/png");
@@ -3338,6 +3351,7 @@ mod tests {
3338 3351 edit: None,
3339 3352 images,
3340 3353 files: Vec::new(),
3354 importance: Default::default(),
3341 3355 }
3342 3356 }
3343 3357
@@ -4797,6 +4811,7 @@ mod tests {
4797 4811 }),
4798 4812 images: Vec::new(),
4799 4813 files: Vec::new(),
4814 importance: Default::default(),
4800 4815 };
4801 4816 composer.begin_edit(draft, window, cx);
4802 4817 });
@@ -29,6 +29,7 @@ use teams_core::{
29 UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,
29 UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,
30};
30};
31
31
32pub(crate) mod delivery;
32mod drafts;
33mod drafts;
33mod schedule;
34mod schedule;
34mod table;
35mod table;
@@ -225,6 +226,8 @@ pub struct Composer {
225 active_cell: Option<(String, teams_core::Cell)>,
226 active_cell: Option<(String, teams_core::Cell)>,
226 caret_before_table: usize,
227 caret_before_table: usize,
227 caret_text: String,
228 caret_text: String,
229 importance: store::MessageImportance,
230 delivery_menu: bool,
228 _subscriptions: [Subscription; 4],
231 _subscriptions: [Subscription; 4],
229}
232}
230
233
@@ -436,6 +439,8 @@ impl Composer {
436 active_cell: None,
439 active_cell: None,
437 caret_before_table: 0,
440 caret_before_table: 0,
438 caret_text: String::new(),
441 caret_text: String::new(),
442 importance: store::MessageImportance::Normal,
443 delivery_menu: false,
439 _subscriptions: [subscription, observer, image_observer, picker_subscription],
444 _subscriptions: [subscription, observer, image_observer, picker_subscription],
440 }
445 }
441 }
446 }
@@ -1637,6 +1642,7 @@ impl Composer {
1637 self.schedule = None;
1642 self.schedule = None;
1638 self.table_picker = None;
1643 self.table_picker = None;
1639 self.table_menu = None;
1644 self.table_menu = None;
1645 self.reset_importance();
1640 if !carry {
1646 if !carry {
1641 self.load_stored_draft(conversation_id, window, cx);
1647 self.load_stored_draft(conversation_id, window, cx);
1642 }
1648 }
@@ -1729,6 +1735,7 @@ impl Composer {
1729 } else {
1735 } else {
1730 Vec::new()
1736 Vec::new()
1731 },
1737 },
1738 importance: self.sendable_importance(cx),
1732 }
1739 }
1733 }
1740 }
1734
1741
@@ -2205,6 +2212,7 @@ impl Composer {
2205 self.editing = None;
2212 self.editing = None;
2206 self.link.reset();
2213 self.link.reset();
2207 self.close_popup();
2214 self.close_popup();
2215 self.reset_importance();
2208 cx.emit(ComposerEvent::Submit(Box::new(outgoing)));
2216 cx.emit(ComposerEvent::Submit(Box::new(outgoing)));
2209 cx.notify();
2217 cx.notify();
2210 }
2218 }
@@ -3104,6 +3112,7 @@ impl Render for Composer {
3104 .children(notice)
3112 .children(notice)
3105 .children(self.render_reply_strip(cx))
3113 .children(self.render_reply_strip(cx))
3106 .children(self.render_edit_strip(cx))
3114 .children(self.render_edit_strip(cx))
3115 .children(self.render_urgent_banner(cx))
3107 .children(self.render_meeting_chip())
3116 .children(self.render_meeting_chip())
3108 .children(self.render_link_preview(cx))
3117 .children(self.render_link_preview(cx))
3109 .child(
3118 .child(
@@ -3114,6 +3123,7 @@ impl Render for Composer {
3114 .children(self.render_emoji_popup(window, cx))
3123 .children(self.render_emoji_popup(window, cx))
3115 .children(self.render_toolbar(focused, cx))
3124 .children(self.render_toolbar(focused, cx))
3116 .children(self.render_schedule(cx))
3125 .children(self.render_schedule(cx))
3126 .children(self.render_delivery_menu(cx))
3117 .child(
3127 .child(
3118 v_flex()
3128 v_flex()
3119 .debug_selector(|| COMPOSER_BOX_TAG.into())
3129 .debug_selector(|| COMPOSER_BOX_TAG.into())
@@ -3136,6 +3146,7 @@ impl Render for Composer {
3136 .size_full(),
3146 .size_full(),
3137 )
3147 )
3138 .children(format_bar)
3148 .children(format_bar)
3149 .children(self.render_importance_label(cx))
3139 .children(tray)
3150 .children(tray)
3140 .child(
3151 .child(
3141 h_flex()
3152 h_flex()
@@ -3155,6 +3166,7 @@ impl Render for Composer {
3155 .flex_none()
3166 .flex_none()
3156 .gap(px(COMPOSER_BUTTON_INSET))
3167 .gap(px(COMPOSER_BUTTON_INSET))
3157 .child(format_toggle)
3168 .child(format_toggle)
3169 .children(self.render_delivery_button(cx))
3158 .children(fun)
3170 .children(fun)
3159 .children(attach),
3171 .children(attach),
3160 )
3172 )
@@ -3295,6 +3307,7 @@ mod tests {
3295 name: "plan.pdf".into(),
3307 name: "plan.pdf".into(),
3296 },
3308 },
3297 }],
3309 }],
3310 importance: Default::default(),
3298 };
3311 };
3299 let extras = outgoing.extras();
3312 let extras = outgoing.extras();
3300 assert_eq!(extras.images[0].content_type, "image/png");
3313 assert_eq!(extras.images[0].content_type, "image/png");
@@ -3338,6 +3351,7 @@ mod tests {
3338 edit: None,
3351 edit: None,
3339 images,
3352 images,
3340 files: Vec::new(),
3353 files: Vec::new(),
3354 importance: Default::default(),
3341 }
3355 }
3342 }
3356 }
3343
3357
@@ -4797,6 +4811,7 @@ mod tests {
4797 }),
4811 }),
4798 images: Vec::new(),
4812 images: Vec::new(),
4799 files: Vec::new(),
4813 files: Vec::new(),
4814 importance: Default::default(),
4800 };
4815 };
4801 composer.begin_edit(draft, window, cx);
4816 composer.begin_edit(draft, window, cx);
4802 });
4817 });
crates/app/src/views/composer/delivery.rs added +268 −0
@@ -0,0 +1,268 @@
1 use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
2 use gpui_kit::prelude::FluentBuilder as _;
3 use gpui_kit::*;
4 use store::MessageImportance;
5
6 use super::{COMPOSER_BUTTON_INSET, COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer};
7 use crate::delivery_options::{
8 DELIVERY_BUTTON_TITLE, DeliveryOption, URGENT_TOO_MANY_MEMBERS, UrgentAvailability,
9 allowed_importance, delivery_options, urgent_banner,
10 };
11 use crate::importance::importance_label;
12 use crate::theme::{self, ElevatedSurface as _};
13 use crate::views::widgets::symbol;
14
15 pub const COMPOSER_DELIVERY_TAG: &str = "composer/leading/delivery";
16 pub const COMPOSER_IMPORTANCE_LABEL_TAG: &str = "composer/importance-label";
17 pub const COMPOSER_URGENT_BANNER_TAG: &str = "composer-urgent-banner";
18 pub const DELIVERY_MENU_TAG: &str = "delivery-menu";
19 const MENU_WIDTH: f32 = 320.;
20 const MENU_PADDING: f32 = 4.;
21 const ROW_PADDING: f32 = 10.;
22 const OPTION_ICON_SIZE: f32 = 20.;
23 const CHECK_SIZE: f32 = 16.;
24 const DISABLED_OPACITY: f32 = 0.4;
25 const LABEL_SIZE: f32 = 12.;
26 const LABEL_LINE_HEIGHT: f32 = 16.;
27 const BANNER_HEIGHT: f32 = 36.;
28 const BANNER_PADDING: f32 = 12.;
29 const BANNER_TINT: f32 = 0.14;
30 pub const LABEL_INSET_X: f32 =
31 COMPOSER_BUTTON_INSET + (COMPOSER_BUTTON_SIZE - COMPOSER_ICON_SIZE) / 2.;
32
33 impl Composer {
34 fn urgent_availability(&self, cx: &App) -> UrgentAvailability {
35 let conversation_id = self.conversation_id.as_deref().unwrap_or_default();
36 self.app
37 .read(cx)
38 .urgent_availability(conversation_id, self.editing.is_some())
39 }
40
41 /// Teams sends edits and scheduled messages as Standard, and drops Urgent where it is no longer offered.
42 pub(super) fn sendable_importance(&self, cx: &App) -> MessageImportance {
43 if self.editing.is_some() {
44 return MessageImportance::Normal;
45 }
46 allowed_importance(self.importance, self.urgent_availability(cx))
47 }
48
49 pub(super) fn reset_importance(&mut self) {
50 self.importance = MessageImportance::Normal;
51 self.delivery_menu = false;
52 }
53
54 fn choose_importance(
55 &mut self,
56 importance: MessageImportance,
57 window: &mut Window,
58 cx: &mut Context<Self>,
59 ) {
60 self.importance = importance;
61 self.delivery_menu = false;
62 self.focus(window, cx);
63 cx.notify();
64 }
65
66 pub(super) fn render_delivery_button(&self, cx: &mut Context<Self>) -> Option<Stateful<Div>> {
67 if self.editing.is_some() {
68 return None;
69 }
70 let open = self.delivery_menu;
71 let marked = self.importance.is_marked();
72 Some(
73 div()
74 .id("composer-delivery")
75 .debug_selector(|| COMPOSER_DELIVERY_TAG.into())
76 .size(px(COMPOSER_BUTTON_SIZE))
77 .flex_none()
78 .flex()
79 .items_center()
80 .justify_center()
81 .rounded(px(8.))
82 .cursor_pointer()
83 .when(open, |button| button.bg(theme::popup_hover()))
84 .hover(|button| button.bg(theme::popup_hover()))
85 .tooltip(|window, cx| Tooltip::new(DELIVERY_BUTTON_TITLE).build(window, cx))
86 .child(symbol(
87 "fluent_important",
88 COMPOSER_ICON_SIZE,
89 if marked {
90 theme::red()
91 } else {
92 theme::text_muted()
93 },
94 ))
95 .on_mouse_down(MouseButton::Left, |_, window, cx| {
96 window.prevent_default();
97 cx.stop_propagation();
98 })
99 .on_click(cx.listener(|this, _, _, cx| {
100 this.delivery_menu = !this.delivery_menu;
101 cx.notify();
102 })),
103 )
104 }
105
106 pub(super) fn render_delivery_menu(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
107 if !self.delivery_menu || self.editing.is_some() {
108 return None;
109 }
110 let selected = self.sendable_importance(cx);
111 let rows = delivery_options(self.urgent_availability(cx))
112 .into_iter()
113 .map(|(option, enabled)| {
114 self.render_option(option, enabled, option.importance == selected, cx)
115 })
116 .collect::<Vec<_>>();
117 Some(
118 v_flex()
119 .id("delivery-menu")
120 .debug_selector(|| DELIVERY_MENU_TAG.into())
121 .absolute()
122 .bottom(relative(1.))
123 .left_0()
124 .mb(px(6.))
125 .w(px(MENU_WIDTH))
126 .max_w(relative(1.))
127 .p(px(MENU_PADDING))
128 .rounded(px(10.))
129 .flyout_surface()
130 .occlude()
131 .on_mouse_down_out(cx.listener(|this, _, _, cx| {
132 this.delivery_menu = false;
133 cx.notify();
134 }))
135 .children(rows)
136 .into_any_element(),
137 )
138 }
139
140 fn render_option(
141 &self,
142 option: DeliveryOption,
143 enabled: bool,
144 selected: bool,
145 cx: &mut Context<Self>,
146 ) -> Stateful<Div> {
147 let accent = if option.importance.is_marked() {
148 theme::red()
149 } else {
150 theme::text_soft()
151 };
152 let row = h_flex()
153 .id(option.tag)
154 .debug_selector(|| option.tag.into())
155 .w_full()
156 .p(px(ROW_PADDING))
157 .gap(px(ROW_PADDING))
158 .items_center()
159 .rounded(px(6.))
160 .child(symbol(option.symbol, OPTION_ICON_SIZE, accent))
161 .child(
162 v_flex()
163 .flex_1()
164 .min_w_0()
165 .child(
166 div()
167 .text_size(px(13.))
168 .font_weight(FontWeight::SEMIBOLD)
169 .text_color(theme::text())
170 .child(option.header),
171 )
172 .child(
173 div()
174 .text_size(px(12.))
175 .text_color(theme::text_muted())
176 .child(option.content),
177 ),
178 )
179 .children(selected.then(|| symbol("done", CHECK_SIZE, theme::text())));
180 if !enabled {
181 return row
182 .opacity(DISABLED_OPACITY)
183 .tooltip(|window, cx| Tooltip::new(URGENT_TOO_MANY_MEMBERS).build(window, cx));
184 }
185 let importance = option.importance;
186 row.cursor_pointer()
187 .hover(|row| row.bg(theme::popup_hover()))
188 .on_click(cx.listener(move |this, _, window, cx| {
189 this.choose_importance(importance, window, cx)
190 }))
191 }
192
193 pub(super) fn render_importance_label(&self, cx: &App) -> Option<Div> {
194 let label = importance_label(self.sendable_importance(cx))?;
195 Some(
196 div()
197 .pt(px(COMPOSER_BUTTON_INSET * 2.))
198 .px(px(LABEL_INSET_X))
199 .text_size(px(LABEL_SIZE))
200 .line_height(px(LABEL_LINE_HEIGHT))
201 .font_weight(FontWeight::BOLD)
202 .text_color(theme::red())
203 .child(
204 div()
205 .debug_selector(|| COMPOSER_IMPORTANCE_LABEL_TAG.into())
206 .child(label),
207 ),
208 )
209 }
210
211 pub(super) fn render_urgent_banner(&self, cx: &mut Context<Self>) -> Option<Div> {
212 if self.sendable_importance(cx) != MessageImportance::Urgent {
213 return None;
214 }
215 let member_count = self
216 .conversation_id
217 .as_deref()
218 .and_then(|id| {
219 self.app
220 .read(cx)
221 .sidebar
222 .chats
223 .iter()
224 .find(|chat| chat.id == id)
225 .map(|chat| chat.members.len())
226 })
227 .unwrap_or_default();
228 Some(
229 h_flex()
230 .debug_selector(|| COMPOSER_URGENT_BANNER_TAG.into())
231 .w_full()
232 .h(px(BANNER_HEIGHT))
233 .mb(px(8.))
234 .px(px(BANNER_PADDING))
235 .gap(px(8.))
236 .items_center()
237 .rounded(px(10.))
238 .bg(theme::red().opacity(BANNER_TINT))
239 .text_size(px(12.))
240 .text_color(theme::red_tint())
241 .child(symbol("fluent_alert_urgent", CHECK_SIZE, theme::red_tint()))
242 .child(
243 div()
244 .flex_1()
245 .min_w_0()
246 .truncate()
247 .child(urgent_banner(member_count)),
248 )
249 .child(
250 div()
251 .id("composer-urgent-banner-close")
252 .size(px(24.))
253 .flex_none()
254 .flex()
255 .items_center()
256 .justify_center()
257 .rounded(px(6.))
258 .cursor_pointer()
259 .hover(|button| button.bg(theme::red().opacity(BANNER_TINT)))
260 .tooltip(|window, cx| Tooltip::new("Send as standard").build(window, cx))
261 .child(symbol("close", CHECK_SIZE, theme::red_tint()))
262 .on_click(cx.listener(|this, _, window, cx| {
263 this.choose_importance(MessageImportance::Normal, window, cx)
264 })),
265 ),
266 )
267 }
268 }
@@ -0,0 +1,268 @@
1use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
2use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
4use store::MessageImportance;
5
6use super::{COMPOSER_BUTTON_INSET, COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer};
7use crate::delivery_options::{
8 DELIVERY_BUTTON_TITLE, DeliveryOption, URGENT_TOO_MANY_MEMBERS, UrgentAvailability,
9 allowed_importance, delivery_options, urgent_banner,
10};
11use crate::importance::importance_label;
12use crate::theme::{self, ElevatedSurface as _};
13use crate::views::widgets::symbol;
14
15pub const COMPOSER_DELIVERY_TAG: &str = "composer/leading/delivery";
16pub const COMPOSER_IMPORTANCE_LABEL_TAG: &str = "composer/importance-label";
17pub const COMPOSER_URGENT_BANNER_TAG: &str = "composer-urgent-banner";
18pub const DELIVERY_MENU_TAG: &str = "delivery-menu";
19const MENU_WIDTH: f32 = 320.;
20const MENU_PADDING: f32 = 4.;
21const ROW_PADDING: f32 = 10.;
22const OPTION_ICON_SIZE: f32 = 20.;
23const CHECK_SIZE: f32 = 16.;
24const DISABLED_OPACITY: f32 = 0.4;
25const LABEL_SIZE: f32 = 12.;
26const LABEL_LINE_HEIGHT: f32 = 16.;
27const BANNER_HEIGHT: f32 = 36.;
28const BANNER_PADDING: f32 = 12.;
29const BANNER_TINT: f32 = 0.14;
30pub const LABEL_INSET_X: f32 =
31 COMPOSER_BUTTON_INSET + (COMPOSER_BUTTON_SIZE - COMPOSER_ICON_SIZE) / 2.;
32
33impl Composer {
34 fn urgent_availability(&self, cx: &App) -> UrgentAvailability {
35 let conversation_id = self.conversation_id.as_deref().unwrap_or_default();
36 self.app
37 .read(cx)
38 .urgent_availability(conversation_id, self.editing.is_some())
39 }
40
41 /// Teams sends edits and scheduled messages as Standard, and drops Urgent where it is no longer offered.
42 pub(super) fn sendable_importance(&self, cx: &App) -> MessageImportance {
43 if self.editing.is_some() {
44 return MessageImportance::Normal;
45 }
46 allowed_importance(self.importance, self.urgent_availability(cx))
47 }
48
49 pub(super) fn reset_importance(&mut self) {
50 self.importance = MessageImportance::Normal;
51 self.delivery_menu = false;
52 }
53
54 fn choose_importance(
55 &mut self,
56 importance: MessageImportance,
57 window: &mut Window,
58 cx: &mut Context<Self>,
59 ) {
60 self.importance = importance;
61 self.delivery_menu = false;
62 self.focus(window, cx);
63 cx.notify();
64 }
65
66 pub(super) fn render_delivery_button(&self, cx: &mut Context<Self>) -> Option<Stateful<Div>> {
67 if self.editing.is_some() {
68 return None;
69 }
70 let open = self.delivery_menu;
71 let marked = self.importance.is_marked();
72 Some(
73 div()
74 .id("composer-delivery")
75 .debug_selector(|| COMPOSER_DELIVERY_TAG.into())
76 .size(px(COMPOSER_BUTTON_SIZE))
77 .flex_none()
78 .flex()
79 .items_center()
80 .justify_center()
81 .rounded(px(8.))
82 .cursor_pointer()
83 .when(open, |button| button.bg(theme::popup_hover()))
84 .hover(|button| button.bg(theme::popup_hover()))
85 .tooltip(|window, cx| Tooltip::new(DELIVERY_BUTTON_TITLE).build(window, cx))
86 .child(symbol(
87 "fluent_important",
88 COMPOSER_ICON_SIZE,
89 if marked {
90 theme::red()
91 } else {
92 theme::text_muted()
93 },
94 ))
95 .on_mouse_down(MouseButton::Left, |_, window, cx| {
96 window.prevent_default();
97 cx.stop_propagation();
98 })
99 .on_click(cx.listener(|this, _, _, cx| {
100 this.delivery_menu = !this.delivery_menu;
101 cx.notify();
102 })),
103 )
104 }
105
106 pub(super) fn render_delivery_menu(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
107 if !self.delivery_menu || self.editing.is_some() {
108 return None;
109 }
110 let selected = self.sendable_importance(cx);
111 let rows = delivery_options(self.urgent_availability(cx))
112 .into_iter()
113 .map(|(option, enabled)| {
114 self.render_option(option, enabled, option.importance == selected, cx)
115 })
116 .collect::<Vec<_>>();
117 Some(
118 v_flex()
119 .id("delivery-menu")
120 .debug_selector(|| DELIVERY_MENU_TAG.into())
121 .absolute()
122 .bottom(relative(1.))
123 .left_0()
124 .mb(px(6.))
125 .w(px(MENU_WIDTH))
126 .max_w(relative(1.))
127 .p(px(MENU_PADDING))
128 .rounded(px(10.))
129 .flyout_surface()
130 .occlude()
131 .on_mouse_down_out(cx.listener(|this, _, _, cx| {
132 this.delivery_menu = false;
133 cx.notify();
134 }))
135 .children(rows)
136 .into_any_element(),
137 )
138 }
139
140 fn render_option(
141 &self,
142 option: DeliveryOption,
143 enabled: bool,
144 selected: bool,
145 cx: &mut Context<Self>,
146 ) -> Stateful<Div> {
147 let accent = if option.importance.is_marked() {
148 theme::red()
149 } else {
150 theme::text_soft()
151 };
152 let row = h_flex()
153 .id(option.tag)
154 .debug_selector(|| option.tag.into())
155 .w_full()
156 .p(px(ROW_PADDING))
157 .gap(px(ROW_PADDING))
158 .items_center()
159 .rounded(px(6.))
160 .child(symbol(option.symbol, OPTION_ICON_SIZE, accent))
161 .child(
162 v_flex()
163 .flex_1()
164 .min_w_0()
165 .child(
166 div()
167 .text_size(px(13.))
168 .font_weight(FontWeight::SEMIBOLD)
169 .text_color(theme::text())
170 .child(option.header),
171 )
172 .child(
173 div()
174 .text_size(px(12.))
175 .text_color(theme::text_muted())
176 .child(option.content),
177 ),
178 )
179 .children(selected.then(|| symbol("done", CHECK_SIZE, theme::text())));
180 if !enabled {
181 return row
182 .opacity(DISABLED_OPACITY)
183 .tooltip(|window, cx| Tooltip::new(URGENT_TOO_MANY_MEMBERS).build(window, cx));
184 }
185 let importance = option.importance;
186 row.cursor_pointer()
187 .hover(|row| row.bg(theme::popup_hover()))
188 .on_click(cx.listener(move |this, _, window, cx| {
189 this.choose_importance(importance, window, cx)
190 }))
191 }
192
193 pub(super) fn render_importance_label(&self, cx: &App) -> Option<Div> {
194 let label = importance_label(self.sendable_importance(cx))?;
195 Some(
196 div()
197 .pt(px(COMPOSER_BUTTON_INSET * 2.))
198 .px(px(LABEL_INSET_X))
199 .text_size(px(LABEL_SIZE))
200 .line_height(px(LABEL_LINE_HEIGHT))
201 .font_weight(FontWeight::BOLD)
202 .text_color(theme::red())
203 .child(
204 div()
205 .debug_selector(|| COMPOSER_IMPORTANCE_LABEL_TAG.into())
206 .child(label),
207 ),
208 )
209 }
210
211 pub(super) fn render_urgent_banner(&self, cx: &mut Context<Self>) -> Option<Div> {
212 if self.sendable_importance(cx) != MessageImportance::Urgent {
213 return None;
214 }
215 let member_count = self
216 .conversation_id
217 .as_deref()
218 .and_then(|id| {
219 self.app
220 .read(cx)
221 .sidebar
222 .chats
223 .iter()
224 .find(|chat| chat.id == id)
225 .map(|chat| chat.members.len())
226 })
227 .unwrap_or_default();
228 Some(
229 h_flex()
230 .debug_selector(|| COMPOSER_URGENT_BANNER_TAG.into())
231 .w_full()
232 .h(px(BANNER_HEIGHT))
233 .mb(px(8.))
234 .px(px(BANNER_PADDING))
235 .gap(px(8.))
236 .items_center()
237 .rounded(px(10.))
238 .bg(theme::red().opacity(BANNER_TINT))
239 .text_size(px(12.))
240 .text_color(theme::red_tint())
241 .child(symbol("fluent_alert_urgent", CHECK_SIZE, theme::red_tint()))
242 .child(
243 div()
244 .flex_1()
245 .min_w_0()
246 .truncate()
247 .child(urgent_banner(member_count)),
248 )
249 .child(
250 div()
251 .id("composer-urgent-banner-close")
252 .size(px(24.))
253 .flex_none()
254 .flex()
255 .items_center()
256 .justify_center()
257 .rounded(px(6.))
258 .cursor_pointer()
259 .hover(|button| button.bg(theme::red().opacity(BANNER_TINT)))
260 .tooltip(|window, cx| Tooltip::new("Send as standard").build(window, cx))
261 .child(symbol("close", CHECK_SIZE, theme::red_tint()))
262 .on_click(cx.listener(|this, _, window, cx| {
263 this.choose_importance(MessageImportance::Normal, window, cx)
264 })),
265 ),
266 )
267 }
268}
crates/app/src/views/composer/schedule.rs +1 −0
@@ -255,6 +255,7 @@ impl Composer {
255 255 if self.scheduling.is_some() || self.schedule_blocker(cx).is_some() {
256 256 return;
257 257 }
258 self.importance = store::MessageImportance::Normal;
258 259 let outgoing = self.compose(cx);
259 260 self.scheduling = Some(outgoing.html());
260 261 self.close_schedule(window, cx);
@@ -255,6 +255,7 @@ impl Composer {
255 if self.scheduling.is_some() || self.schedule_blocker(cx).is_some() {
255 if self.scheduling.is_some() || self.schedule_blocker(cx).is_some() {
256 return;
256 return;
257 }
257 }
258 self.importance = store::MessageImportance::Normal;
258 let outgoing = self.compose(cx);
259 let outgoing = self.compose(cx);
259 self.scheduling = Some(outgoing.html());
260 self.scheduling = Some(outgoing.html());
260 self.close_schedule(window, cx);
261 self.close_schedule(window, cx);
crates/app/src/views/conversation.rs +1 −0
@@ -2737,6 +2737,7 @@ impl ConversationView {
2737 2737 images: Vec::new(),
2738 2738 files: Vec::new(),
2739 2739 link_preview: None,
2740 importance: Default::default(),
2740 2741 };
2741 2742 self.show_main_composer(cx);
2742 2743 self.composer
@@ -2737,6 +2737,7 @@ impl ConversationView {
2737 images: Vec::new(),
2737 images: Vec::new(),
2738 files: Vec::new(),
2738 files: Vec::new(),
2739 link_preview: None,
2739 link_preview: None,
2740 importance: Default::default(),
2740 };
2741 };
2741 self.show_main_composer(cx);
2742 self.show_main_composer(cx);
2742 self.composer
2743 self.composer
crates/app/src/views/proposal_card.rs +1 −0
@@ -111,6 +111,7 @@ pub fn outgoing_for(entry: &ProposalEntry, reply: Option<ReplyPreview>) -> Outgo
111 111 images,
112 112 files: Vec::new(),
113 113 link_preview: None,
114 importance: Default::default(),
114 115 }
115 116 }
116 117
@@ -111,6 +111,7 @@ pub fn outgoing_for(entry: &ProposalEntry, reply: Option<ReplyPreview>) -> Outgo
111 images,
111 images,
112 files: Vec::new(),
112 files: Vec::new(),
113 link_preview: None,
113 link_preview: None,
114 importance: Default::default(),
114 }
115 }
115}
116}
116
117
crates/chatsvc/src/language_settings.rs +35 −0
@@ -3,6 +3,7 @@ use session::{Method, Request, SPACES, Scope, Session};
3 3
4 4 use crate::error::{Error, Result};
5 5 use crate::messages::ensure_success;
6 use crate::messaging_policy::{messaging_policy_body, parse_allow_priority_messages};
6 7 use crate::pins::{CsaTransport, DEFAULT_REGION, SessionTransport};
7 8 use crate::recording_policy::{RecordingPolicy, parse_recording_policy, recording_policy_body};
8 9 use crate::translate::language_code;
@@ -204,6 +205,20 @@ impl<T: CsaTransport> LanguageSettingsClient<T> {
204 205 Ok(parse_recording_policy(&answer.body))
205 206 }
206 207
208 pub async fn read_allow_priority_messages(&self) -> Result<bool> {
209 let url = format!("{}/useraggregatesettings", self.base_url);
210 let answer = self
211 .transport
212 .send(with_headers(Request::with_body(
213 Method::Post,
214 url,
215 messaging_policy_body(),
216 )))
217 .await?;
218 ensure_success(&answer)?;
219 Ok(parse_allow_priority_messages(&answer.body))
220 }
221
207 222 pub async fn patch(&self, patch: Value) -> Result<()> {
208 223 let url = format!("{}/languageAccountSettings", self.base_url);
209 224 let answer = self
@@ -415,6 +430,26 @@ mod tests {
415 430 );
416 431 }
417 432
433 #[tokio::test]
434 async fn the_messaging_policy_is_read_from_the_same_route() {
435 let answer = json!({"messagingPolicy": {"value": {"allowPriorityMessages": false}}});
436 let transport = Canned {
437 answers: Mutex::new(vec![(200, answer)].into()),
438 requests: Mutex::new(Vec::new()),
439 };
440 let allowed = LanguageSettingsClient::with_transport(&transport, "emea")
441 .read_allow_priority_messages()
442 .await
443 .unwrap();
444 assert!(!allowed);
445 let requests = transport.requests.lock().unwrap();
446 assert_eq!(
447 requests[0].url,
448 "https://teams.cloud.microsoft/api/mt/emea/beta/users/useraggregatesettings"
449 );
450 assert_eq!(requests[0].body, Some(json!({"messagingPolicy": true})));
451 }
452
418 453 #[tokio::test]
419 454 async fn an_empty_answer_is_not_settings() {
420 455 let transport = Canned {
@@ -3,6 +3,7 @@ use session::{Method, Request, SPACES, Scope, Session};
3
3
4use crate::error::{Error, Result};
4use crate::error::{Error, Result};
5use crate::messages::ensure_success;
5use crate::messages::ensure_success;
6use crate::messaging_policy::{messaging_policy_body, parse_allow_priority_messages};
6use crate::pins::{CsaTransport, DEFAULT_REGION, SessionTransport};
7use crate::pins::{CsaTransport, DEFAULT_REGION, SessionTransport};
7use crate::recording_policy::{RecordingPolicy, parse_recording_policy, recording_policy_body};
8use crate::recording_policy::{RecordingPolicy, parse_recording_policy, recording_policy_body};
8use crate::translate::language_code;
9use crate::translate::language_code;
@@ -204,6 +205,20 @@ impl<T: CsaTransport> LanguageSettingsClient<T> {
204 Ok(parse_recording_policy(&answer.body))
205 Ok(parse_recording_policy(&answer.body))
205 }
206 }
206
207
208 pub async fn read_allow_priority_messages(&self) -> Result<bool> {
209 let url = format!("{}/useraggregatesettings", self.base_url);
210 let answer = self
211 .transport
212 .send(with_headers(Request::with_body(
213 Method::Post,
214 url,
215 messaging_policy_body(),
216 )))
217 .await?;
218 ensure_success(&answer)?;
219 Ok(parse_allow_priority_messages(&answer.body))
220 }
221
207 pub async fn patch(&self, patch: Value) -> Result<()> {
222 pub async fn patch(&self, patch: Value) -> Result<()> {
208 let url = format!("{}/languageAccountSettings", self.base_url);
223 let url = format!("{}/languageAccountSettings", self.base_url);
209 let answer = self
224 let answer = self
@@ -415,6 +430,26 @@ mod tests {
415 );
430 );
416 }
431 }
417
432
433 #[tokio::test]
434 async fn the_messaging_policy_is_read_from_the_same_route() {
435 let answer = json!({"messagingPolicy": {"value": {"allowPriorityMessages": false}}});
436 let transport = Canned {
437 answers: Mutex::new(vec![(200, answer)].into()),
438 requests: Mutex::new(Vec::new()),
439 };
440 let allowed = LanguageSettingsClient::with_transport(&transport, "emea")
441 .read_allow_priority_messages()
442 .await
443 .unwrap();
444 assert!(!allowed);
445 let requests = transport.requests.lock().unwrap();
446 assert_eq!(
447 requests[0].url,
448 "https://teams.cloud.microsoft/api/mt/emea/beta/users/useraggregatesettings"
449 );
450 assert_eq!(requests[0].body, Some(json!({"messagingPolicy": true})));
451 }
452
418 #[tokio::test]
453 #[tokio::test]
419 async fn an_empty_answer_is_not_settings() {
454 async fn an_empty_answer_is_not_settings() {
420 let transport = Canned {
455 let transport = Canned {
crates/chatsvc/src/lib.rs +1 −0
@@ -23,6 +23,7 @@ pub mod read_horizon;
23 23 pub mod realtime;
24 24 pub mod recap;
25 25 pub mod receipts;
26 pub mod messaging_policy;
26 27 pub mod recording_policy;
27 28 pub mod saved;
28 29 pub mod settings;
@@ -23,6 +23,7 @@ pub mod read_horizon;
23pub mod realtime;
23pub mod realtime;
24pub mod recap;
24pub mod recap;
25pub mod receipts;
25pub mod receipts;
26pub mod messaging_policy;
26pub mod recording_policy;
27pub mod recording_policy;
27pub mod saved;
28pub mod saved;
28pub mod settings;
29pub mod settings;
crates/chatsvc/src/messaging_policy.rs added +31 −0
@@ -0,0 +1,31 @@
1 use serde_json::{Value, json};
2
3 pub fn messaging_policy_body() -> Value {
4 json!({"messagingPolicy": true})
5 }
6
7 /// Teams reads `messagingPolicy.allowPriorityMessages` and allows urgent messages unless it is `false`.
8 pub fn parse_allow_priority_messages(body: &Value) -> bool {
9 body.pointer("/messagingPolicy/value/allowPriorityMessages")
10 .and_then(Value::as_bool)
11 .unwrap_or(true)
12 }
13
14 #[cfg(test)]
15 mod tests {
16 use super::*;
17
18 #[test]
19 fn the_body_asks_for_the_messaging_policy() {
20 assert_eq!(messaging_policy_body(), json!({"messagingPolicy": true}));
21 }
22
23 #[test]
24 fn priority_messages_follow_the_policy_and_default_to_allowed() {
25 let denied = json!({"messagingPolicy": {"value": {"allowPriorityMessages": false}}});
26 let allowed = json!({"messagingPolicy": {"value": {"allowPriorityMessages": true}}});
27 assert!(!parse_allow_priority_messages(&denied));
28 assert!(parse_allow_priority_messages(&allowed));
29 assert!(parse_allow_priority_messages(&json!({})));
30 }
31 }
@@ -0,0 +1,31 @@
1use serde_json::{Value, json};
2
3pub fn messaging_policy_body() -> Value {
4 json!({"messagingPolicy": true})
5}
6
7/// Teams reads `messagingPolicy.allowPriorityMessages` and allows urgent messages unless it is `false`.
8pub fn parse_allow_priority_messages(body: &Value) -> bool {
9 body.pointer("/messagingPolicy/value/allowPriorityMessages")
10 .and_then(Value::as_bool)
11 .unwrap_or(true)
12}
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17
18 #[test]
19 fn the_body_asks_for_the_messaging_policy() {
20 assert_eq!(messaging_policy_body(), json!({"messagingPolicy": true}));
21 }
22
23 #[test]
24 fn priority_messages_follow_the_policy_and_default_to_allowed() {
25 let denied = json!({"messagingPolicy": {"value": {"allowPriorityMessages": false}}});
26 let allowed = json!({"messagingPolicy": {"value": {"allowPriorityMessages": true}}});
27 assert!(!parse_allow_priority_messages(&denied));
28 assert!(parse_allow_priority_messages(&allowed));
29 assert!(parse_allow_priority_messages(&json!({})));
30 }
31}
crates/core/src/recording_rights.rs +4 −0
@@ -9,6 +9,10 @@ impl<R: Remote> SyncEngine<R> {
9 9 self.remote.recording_policy().await
10 10 }
11 11
12 pub async fn allow_priority_messages(&self) -> Result<bool> {
13 self.remote.allow_priority_messages().await
14 }
15
12 16 pub async fn own_tenant_id(&self, chat_id: &str) -> Result<String> {
13 17 self.my_tenant_id(chat_id).await
14 18 }
@@ -9,6 +9,10 @@ impl<R: Remote> SyncEngine<R> {
9 self.remote.recording_policy().await
9 self.remote.recording_policy().await
10 }
10 }
11
11
12 pub async fn allow_priority_messages(&self) -> Result<bool> {
13 self.remote.allow_priority_messages().await
14 }
15
12 pub async fn own_tenant_id(&self, chat_id: &str) -> Result<String> {
16 pub async fn own_tenant_id(&self, chat_id: &str) -> Result<String> {
13 self.my_tenant_id(chat_id).await
17 self.my_tenant_id(chat_id).await
14 }
18 }
crates/core/src/remote.rs +10 −0
@@ -467,6 +467,10 @@ pub trait Remote {
467 467 Err(Error::Unsupported("recording policy"))
468 468 }
469 469
470 async fn allow_priority_messages(&self) -> Result<bool> {
471 Err(Error::Unsupported("messaging policy"))
472 }
473
470 474 async fn ack_urgent_message(&self, _chat_id: &str, _message_id: &str) -> Result<()> {
471 475 Err(Error::Unsupported("urgent message acknowledgement"))
472 476 }
@@ -1229,6 +1233,12 @@ impl Remote for Graph {
1229 1233 .await?)
1230 1234 }
1231 1235
1236 async fn allow_priority_messages(&self) -> Result<bool> {
1237 Ok(LanguageSettingsClient::new(self.session())
1238 .read_allow_priority_messages()
1239 .await?)
1240 }
1241
1232 1242 async fn patch_language_settings(&self, patch: serde_json::Value) -> Result<()> {
1233 1243 Ok(LanguageSettingsClient::new(self.session())
1234 1244 .patch(patch)
@@ -467,6 +467,10 @@ pub trait Remote {
467 Err(Error::Unsupported("recording policy"))
467 Err(Error::Unsupported("recording policy"))
468 }
468 }
469
469
470 async fn allow_priority_messages(&self) -> Result<bool> {
471 Err(Error::Unsupported("messaging policy"))
472 }
473
470 async fn ack_urgent_message(&self, _chat_id: &str, _message_id: &str) -> Result<()> {
474 async fn ack_urgent_message(&self, _chat_id: &str, _message_id: &str) -> Result<()> {
471 Err(Error::Unsupported("urgent message acknowledgement"))
475 Err(Error::Unsupported("urgent message acknowledgement"))
472 }
476 }
@@ -1229,6 +1233,12 @@ impl Remote for Graph {
1229 .await?)
1233 .await?)
1230 }
1234 }
1231
1235
1236 async fn allow_priority_messages(&self) -> Result<bool> {
1237 Ok(LanguageSettingsClient::new(self.session())
1238 .read_allow_priority_messages()
1239 .await?)
1240 }
1241
1232 async fn patch_language_settings(&self, patch: serde_json::Value) -> Result<()> {
1242 async fn patch_language_settings(&self, patch: serde_json::Value) -> Result<()> {
1233 Ok(LanguageSettingsClient::new(self.session())
1243 Ok(LanguageSettingsClient::new(self.session())
1234 .patch(patch)
1244 .patch(patch)
crates/core/tests/engine.rs +3 −0
@@ -2326,6 +2326,7 @@ async fn the_notes_chat_takes_every_write_without_a_graph_chat_lookup() {
2326 2326 bytes: Arc::new(vec![9]),
2327 2327 }],
2328 2328 files: Vec::new(),
2329 importance: None,
2329 2330 };
2330 2331
2331 2332 let sent = engine
@@ -2399,6 +2400,7 @@ async fn send_with_extras_hands_images_and_files_to_the_remote() {
2399 2400 bytes: Arc::new(vec![9]),
2400 2401 }],
2401 2402 files: Vec::new(),
2403 importance: None,
2402 2404 };
2403 2405
2404 2406 engine
@@ -2429,6 +2431,7 @@ async fn a_sent_image_is_cached_under_the_server_url_without_a_download() {
2429 2431 bytes: Arc::new(vec![9, 8, 7]),
2430 2432 }],
2431 2433 files: Vec::new(),
2434 importance: None,
2432 2435 };
2433 2436 let mut events = engine.subscribe();
2434 2437
@@ -2326,6 +2326,7 @@ async fn the_notes_chat_takes_every_write_without_a_graph_chat_lookup() {
2326 bytes: Arc::new(vec![9]),
2326 bytes: Arc::new(vec![9]),
2327 }],
2327 }],
2328 files: Vec::new(),
2328 files: Vec::new(),
2329 importance: None,
2329 };
2330 };
2330
2331
2331 let sent = engine
2332 let sent = engine
@@ -2399,6 +2400,7 @@ async fn send_with_extras_hands_images_and_files_to_the_remote() {
2399 bytes: Arc::new(vec![9]),
2400 bytes: Arc::new(vec![9]),
2400 }],
2401 }],
2401 files: Vec::new(),
2402 files: Vec::new(),
2403 importance: None,
2402 };
2404 };
2403
2405
2404 engine
2406 engine
@@ -2429,6 +2431,7 @@ async fn a_sent_image_is_cached_under_the_server_url_without_a_download() {
2429 bytes: Arc::new(vec![9, 8, 7]),
2431 bytes: Arc::new(vec![9, 8, 7]),
2430 }],
2432 }],
2431 files: Vec::new(),
2433 files: Vec::new(),
2434 importance: None,
2432 };
2435 };
2433 let mut events = engine.subscribe();
2436 let mut events = engine.subscribe();
2434
2437
crates/graph/src/outgoing.rs +28 −0
@@ -66,6 +66,8 @@ pub struct MessageExtras {
66 66 pub images: Vec<HostedImage>,
67 67 pub files: Vec<FileReference>,
68 68 pub kept: Vec<KeptAttachment>,
69 /// Graph `importance`: `"high"` or `"urgent"`, absent for a standard message.
70 pub importance: Option<&'static str>,
69 71 }
70 72
71 73 impl MessageExtras {
@@ -167,6 +169,9 @@ pub(crate) fn message_body(
167 169 });
168 170 body["attachments"] = Value::Array(kept.chain(files).collect());
169 171 }
172 if let Some(importance) = extras.importance {
173 body["importance"] = json!(importance);
174 }
170 175 body
171 176 }
172 177
@@ -256,6 +261,23 @@ mod tests {
256 261 }
257 262 }
258 263
264 #[test]
265 fn importance_is_sent_like_teams() {
266 let extras = MessageExtras {
267 importance: Some("urgent"),
268 ..MessageExtras::default()
269 };
270 assert_eq!(
271 message_body("<p>x</p>", &[], &extras),
272 json!({"body": {"contentType": "html", "content": "<p>x</p>"}, "importance": "urgent"})
273 );
274 assert!(
275 message_body("<p>x</p>", &[], &MessageExtras::default())
276 .get("importance")
277 .is_none()
278 );
279 }
280
259 281 #[test]
260 282 fn plain_body_has_no_hosted_contents_or_attachments() {
261 283 let body = message_body("<p>x</p>", &[], &MessageExtras::default());
@@ -271,6 +293,7 @@ mod tests {
271 293 kept: Vec::new(),
272 294 images: vec![image("image/png", &[1, 2, 3]), image("image/jpeg", &[4])],
273 295 files: Vec::new(),
296 importance: None,
274 297 };
275 298 let body = message_body("<p>hi</p>", &[], &extras);
276 299 assert_eq!(
@@ -297,6 +320,7 @@ mod tests {
297 320 image("image/png", &[3]),
298 321 ],
299 322 files: Vec::new(),
323 importance: None,
300 324 };
301 325 let html = "a <img src=\"../hostedContents/3/$value\"> <img src=\"https://giphy.com/x.gif\"> <img src=\"../hostedContents/1/$value\">";
302 326 assert_eq!(hosted_image_order(html, &extras), vec![2, 0, 1]);
@@ -309,6 +333,7 @@ mod tests {
309 333 kept: Vec::new(),
310 334 images: vec![image("image/png", &[1]), image("image/png", &[2])],
311 335 files: Vec::new(),
336 importance: None,
312 337 };
313 338 let body = message_body("a <img src=\"../hostedContents/2/$value\"> b", &[], &extras);
314 339 assert_eq!(
@@ -328,6 +353,7 @@ mod tests {
328 353 content_url: "https://x/a.pdf".into(),
329 354 name: "a.pdf".into(),
330 355 }],
356 importance: None,
331 357 };
332 358 let original_image = "<img src=\"https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/9/$value\">";
333 359 let body = message_body(&format!("<p>new</p>{original_image}"), &[], &extras);
@@ -351,6 +377,7 @@ mod tests {
351 377 content_url: None,
352 378 name: None,
353 379 }],
380 importance: None,
354 381 };
355 382 let body = message_body("<p>new</p>", &[], &extras);
356 383 assert_eq!(
@@ -371,6 +398,7 @@ mod tests {
371 398 content_url: "https://contoso.sharepoint.com/Plan.docx".into(),
372 399 name: "Plan.docx".into(),
373 400 }],
401 importance: None,
374 402 };
375 403 let body = message_body("", &[], &extras);
376 404 assert_eq!(
@@ -66,6 +66,8 @@ pub struct MessageExtras {
66 pub images: Vec<HostedImage>,
66 pub images: Vec<HostedImage>,
67 pub files: Vec<FileReference>,
67 pub files: Vec<FileReference>,
68 pub kept: Vec<KeptAttachment>,
68 pub kept: Vec<KeptAttachment>,
69 /// Graph `importance`: `"high"` or `"urgent"`, absent for a standard message.
70 pub importance: Option<&'static str>,
69}
71}
70
72
71impl MessageExtras {
73impl MessageExtras {
@@ -167,6 +169,9 @@ pub(crate) fn message_body(
167 });
169 });
168 body["attachments"] = Value::Array(kept.chain(files).collect());
170 body["attachments"] = Value::Array(kept.chain(files).collect());
169 }
171 }
172 if let Some(importance) = extras.importance {
173 body["importance"] = json!(importance);
174 }
170 body
175 body
171}
176}
172
177
@@ -256,6 +261,23 @@ mod tests {
256 }
261 }
257 }
262 }
258
263
264 #[test]
265 fn importance_is_sent_like_teams() {
266 let extras = MessageExtras {
267 importance: Some("urgent"),
268 ..MessageExtras::default()
269 };
270 assert_eq!(
271 message_body("<p>x</p>", &[], &extras),
272 json!({"body": {"contentType": "html", "content": "<p>x</p>"}, "importance": "urgent"})
273 );
274 assert!(
275 message_body("<p>x</p>", &[], &MessageExtras::default())
276 .get("importance")
277 .is_none()
278 );
279 }
280
259 #[test]
281 #[test]
260 fn plain_body_has_no_hosted_contents_or_attachments() {
282 fn plain_body_has_no_hosted_contents_or_attachments() {
261 let body = message_body("<p>x</p>", &[], &MessageExtras::default());
283 let body = message_body("<p>x</p>", &[], &MessageExtras::default());
@@ -271,6 +293,7 @@ mod tests {
271 kept: Vec::new(),
293 kept: Vec::new(),
272 images: vec![image("image/png", &[1, 2, 3]), image("image/jpeg", &[4])],
294 images: vec![image("image/png", &[1, 2, 3]), image("image/jpeg", &[4])],
273 files: Vec::new(),
295 files: Vec::new(),
296 importance: None,
274 };
297 };
275 let body = message_body("<p>hi</p>", &[], &extras);
298 let body = message_body("<p>hi</p>", &[], &extras);
276 assert_eq!(
299 assert_eq!(
@@ -297,6 +320,7 @@ mod tests {
297 image("image/png", &[3]),
320 image("image/png", &[3]),
298 ],
321 ],
299 files: Vec::new(),
322 files: Vec::new(),
323 importance: None,
300 };
324 };
301 let html = "a <img src=\"../hostedContents/3/$value\"> <img src=\"https://giphy.com/x.gif\"> <img src=\"../hostedContents/1/$value\">";
325 let html = "a <img src=\"../hostedContents/3/$value\"> <img src=\"https://giphy.com/x.gif\"> <img src=\"../hostedContents/1/$value\">";
302 assert_eq!(hosted_image_order(html, &extras), vec![2, 0, 1]);
326 assert_eq!(hosted_image_order(html, &extras), vec![2, 0, 1]);
@@ -309,6 +333,7 @@ mod tests {
309 kept: Vec::new(),
333 kept: Vec::new(),
310 images: vec![image("image/png", &[1]), image("image/png", &[2])],
334 images: vec![image("image/png", &[1]), image("image/png", &[2])],
311 files: Vec::new(),
335 files: Vec::new(),
336 importance: None,
312 };
337 };
313 let body = message_body("a <img src=\"../hostedContents/2/$value\"> b", &[], &extras);
338 let body = message_body("a <img src=\"../hostedContents/2/$value\"> b", &[], &extras);
314 assert_eq!(
339 assert_eq!(
@@ -328,6 +353,7 @@ mod tests {
328 content_url: "https://x/a.pdf".into(),
353 content_url: "https://x/a.pdf".into(),
329 name: "a.pdf".into(),
354 name: "a.pdf".into(),
330 }],
355 }],
356 importance: None,
331 };
357 };
332 let original_image = "<img src=\"https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/9/$value\">";
358 let original_image = "<img src=\"https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/9/$value\">";
333 let body = message_body(&format!("<p>new</p>{original_image}"), &[], &extras);
359 let body = message_body(&format!("<p>new</p>{original_image}"), &[], &extras);
@@ -351,6 +377,7 @@ mod tests {
351 content_url: None,
377 content_url: None,
352 name: None,
378 name: None,
353 }],
379 }],
380 importance: None,
354 };
381 };
355 let body = message_body("<p>new</p>", &[], &extras);
382 let body = message_body("<p>new</p>", &[], &extras);
356 assert_eq!(
383 assert_eq!(
@@ -371,6 +398,7 @@ mod tests {
371 content_url: "https://contoso.sharepoint.com/Plan.docx".into(),
398 content_url: "https://contoso.sharepoint.com/Plan.docx".into(),
372 name: "Plan.docx".into(),
399 name: "Plan.docx".into(),
373 }],
400 }],
401 importance: None,
374 };
402 };
375 let body = message_body("", &[], &extras);
403 let body = message_body("", &[], &extras);
376 assert_eq!(
404 assert_eq!(