BlueGit

ict rusty-teams

feat(messages): Share to Outlook in the message menu

- "Share to Outlook" after Translate in chats and channels
- Opens an Outlook on the web compose deeplink: subject = post subject or conversation title, plain text body = sender and time, message text, message link
- Deviation: Teams opens an in-app compose dialog backed by shareToOutlookService (Outlook draft, sendEmailMessage, deleteShareToOutlookEmailDraft) and sends from there; that route is not verified, so we only open a new mail and send nothing
- outlook_compose_link landed with the mentions commit in teams-core

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-04 · 3 weeks ago

Hash
232a2126c719f6148418a1edf7530a7b15564d90
Parent
65ce5931
5 files changed +173 −1
crates/app-state/src/lib.rs +1 −0
@@ -45,6 +45,7 @@ pub mod scheduled;
45 45 pub mod scheduled_rows;
46 46 pub mod section_actions;
47 47 pub mod settings_section;
48 pub mod share_outlook;
48 49 pub mod sidebar_model;
49 50 pub mod sound_actions;
50 51 pub mod stored_outgoing;
@@ -45,6 +45,7 @@ pub mod scheduled;
45pub mod scheduled_rows;
45pub mod scheduled_rows;
46pub mod section_actions;
46pub mod section_actions;
47pub mod settings_section;
47pub mod settings_section;
48pub mod share_outlook;
48pub mod sidebar_model;
49pub mod sidebar_model;
49pub mod sound_actions;
50pub mod sound_actions;
50pub mod stored_outgoing;
51pub mod stored_outgoing;
crates/app-state/src/share_outlook.rs added +148 −0
@@ -0,0 +1,148 @@
1 use chrono::{DateTime, Local, Utc};
2 use gpui_kit::*;
3 use store::MessageRecord;
4
5 use crate::app_state::AppState;
6 use crate::notice::short_error;
7 use crate::rows::message_text;
8 use crate::runtime;
9
10 pub const SHARE_TO_OUTLOOK_LABEL: &str = "Share to Outlook";
11
12 pub fn share_subject(record: &MessageRecord, conversation_title: &str) -> String {
13 record
14 .subject
15 .as_deref()
16 .map(str::trim)
17 .filter(|subject| !subject.is_empty())
18 .unwrap_or(conversation_title)
19 .to_owned()
20 }
21
22 pub fn share_body(record: &MessageRecord, link: Option<&str>) -> String {
23 let sender = record.sender_name.as_deref().unwrap_or_default();
24 let header = format!("{sender} {}", sent_label(record.created_at))
25 .trim()
26 .to_owned();
27 let mut parts = vec![header, message_text(record)];
28 parts.extend(link.map(str::to_owned));
29 parts
30 .into_iter()
31 .filter(|part| !part.trim().is_empty())
32 .collect::<Vec<_>>()
33 .join("\n\n")
34 }
35
36 fn sent_label(sent_at: DateTime<Utc>) -> String {
37 sent_at
38 .with_timezone(&Local)
39 .format("%d/%m/%Y %H:%M")
40 .to_string()
41 }
42
43 impl AppState {
44 pub fn share_to_outlook(
45 &mut self,
46 conversation_id: &str,
47 message_id: &str,
48 conversation_title: &str,
49 cx: &mut Context<Self>,
50 ) {
51 let Some(record) = self.message_record(conversation_id, message_id) else {
52 return;
53 };
54 let subject = share_subject(&record, conversation_title);
55 let Some(engine) = self.engine.clone() else {
56 if self.mode.demo {
57 let link = teams_core::chat_message_link(conversation_id, message_id, None);
58 let body = share_body(&record, Some(&link));
59 cx.open_url(&teams_core::outlook_compose_link(&subject, &body));
60 }
61 return;
62 };
63 let (conversation_id, message_id) = (conversation_id.to_owned(), message_id.to_owned());
64 let receiver =
65 runtime::spawn(async move { engine.message_link(&conversation_id, &message_id).await });
66 cx.spawn(async move |this, cx| {
67 let link = match receiver.await {
68 Ok(Ok(link)) => Ok(link),
69 Ok(Err(error)) => Err(short_error(&error)),
70 Err(_) => Err("cancelled".to_owned()),
71 };
72 this.update(cx, |state, cx| {
73 if let Err(reason) = &link {
74 state.raise_notice(format!("No link to the message: {reason}"), None, cx);
75 }
76 let body = share_body(&record, link.as_deref().ok());
77 cx.open_url(&teams_core::outlook_compose_link(&subject, &body));
78 })
79 .ok();
80 })
81 .detach();
82 }
83 }
84
85 #[cfg(test)]
86 mod tests {
87 use chrono::DateTime;
88 use store::MessageRecord;
89
90 use super::{share_body, share_subject};
91
92 fn record(subject: Option<&str>, html: &str) -> MessageRecord {
93 MessageRecord {
94 conversation_id: "19:c@thread.v2".into(),
95 message_id: "1".into(),
96 reply_to_id: None,
97 sender_id: Some("u".into()),
98 sender_name: Some("Ada Example".into()),
99 sender_application_id: None,
100 links_json: "[]".to_owned(),
101 created_at: DateTime::from_timestamp(1_790_000_000, 0).unwrap(),
102 edited_at: None,
103 deleted: false,
104 body_html: html.into(),
105 attachments_json: "[]".into(),
106 reactions_json: "[]".into(),
107 mentions_json: "[]".into(),
108 subject: subject.map(str::to_owned),
109 call_event_json: None,
110 importance: Default::default(),
111 }
112 }
113
114 #[test]
115 fn the_subject_is_the_post_subject_or_the_conversation_title() {
116 assert_eq!(
117 share_subject(&record(Some("Launch"), "<p>x</p>"), "General"),
118 "Launch"
119 );
120 assert_eq!(
121 share_subject(&record(Some(" "), "<p>x</p>"), "General"),
122 "General"
123 );
124 assert_eq!(
125 share_subject(&record(None, "<p>x</p>"), "Release planning"),
126 "Release planning"
127 );
128 }
129
130 #[test]
131 fn the_body_has_sender_and_time_then_the_text_then_the_link() {
132 let body = share_body(
133 &record(None, "<p>Ship it <b>today</b></p>"),
134 Some("https://teams.microsoft.com/l/message/1"),
135 );
136 let parts: Vec<&str> = body.split("\n\n").collect();
137 assert_eq!(parts.len(), 3);
138 assert!(parts[0].starts_with("Ada Example "));
139 assert!(parts[1].contains("Ship it"));
140 assert_eq!(parts[2], "https://teams.microsoft.com/l/message/1");
141 assert_eq!(
142 share_body(&record(None, "<p>hi</p>"), None)
143 .split("\n\n")
144 .count(),
145 2
146 );
147 }
148 }
@@ -0,0 +1,148 @@
1use chrono::{DateTime, Local, Utc};
2use gpui_kit::*;
3use store::MessageRecord;
4
5use crate::app_state::AppState;
6use crate::notice::short_error;
7use crate::rows::message_text;
8use crate::runtime;
9
10pub const SHARE_TO_OUTLOOK_LABEL: &str = "Share to Outlook";
11
12pub fn share_subject(record: &MessageRecord, conversation_title: &str) -> String {
13 record
14 .subject
15 .as_deref()
16 .map(str::trim)
17 .filter(|subject| !subject.is_empty())
18 .unwrap_or(conversation_title)
19 .to_owned()
20}
21
22pub fn share_body(record: &MessageRecord, link: Option<&str>) -> String {
23 let sender = record.sender_name.as_deref().unwrap_or_default();
24 let header = format!("{sender} {}", sent_label(record.created_at))
25 .trim()
26 .to_owned();
27 let mut parts = vec![header, message_text(record)];
28 parts.extend(link.map(str::to_owned));
29 parts
30 .into_iter()
31 .filter(|part| !part.trim().is_empty())
32 .collect::<Vec<_>>()
33 .join("\n\n")
34}
35
36fn sent_label(sent_at: DateTime<Utc>) -> String {
37 sent_at
38 .with_timezone(&Local)
39 .format("%d/%m/%Y %H:%M")
40 .to_string()
41}
42
43impl AppState {
44 pub fn share_to_outlook(
45 &mut self,
46 conversation_id: &str,
47 message_id: &str,
48 conversation_title: &str,
49 cx: &mut Context<Self>,
50 ) {
51 let Some(record) = self.message_record(conversation_id, message_id) else {
52 return;
53 };
54 let subject = share_subject(&record, conversation_title);
55 let Some(engine) = self.engine.clone() else {
56 if self.mode.demo {
57 let link = teams_core::chat_message_link(conversation_id, message_id, None);
58 let body = share_body(&record, Some(&link));
59 cx.open_url(&teams_core::outlook_compose_link(&subject, &body));
60 }
61 return;
62 };
63 let (conversation_id, message_id) = (conversation_id.to_owned(), message_id.to_owned());
64 let receiver =
65 runtime::spawn(async move { engine.message_link(&conversation_id, &message_id).await });
66 cx.spawn(async move |this, cx| {
67 let link = match receiver.await {
68 Ok(Ok(link)) => Ok(link),
69 Ok(Err(error)) => Err(short_error(&error)),
70 Err(_) => Err("cancelled".to_owned()),
71 };
72 this.update(cx, |state, cx| {
73 if let Err(reason) = &link {
74 state.raise_notice(format!("No link to the message: {reason}"), None, cx);
75 }
76 let body = share_body(&record, link.as_deref().ok());
77 cx.open_url(&teams_core::outlook_compose_link(&subject, &body));
78 })
79 .ok();
80 })
81 .detach();
82 }
83}
84
85#[cfg(test)]
86mod tests {
87 use chrono::DateTime;
88 use store::MessageRecord;
89
90 use super::{share_body, share_subject};
91
92 fn record(subject: Option<&str>, html: &str) -> MessageRecord {
93 MessageRecord {
94 conversation_id: "19:c@thread.v2".into(),
95 message_id: "1".into(),
96 reply_to_id: None,
97 sender_id: Some("u".into()),
98 sender_name: Some("Ada Example".into()),
99 sender_application_id: None,
100 links_json: "[]".to_owned(),
101 created_at: DateTime::from_timestamp(1_790_000_000, 0).unwrap(),
102 edited_at: None,
103 deleted: false,
104 body_html: html.into(),
105 attachments_json: "[]".into(),
106 reactions_json: "[]".into(),
107 mentions_json: "[]".into(),
108 subject: subject.map(str::to_owned),
109 call_event_json: None,
110 importance: Default::default(),
111 }
112 }
113
114 #[test]
115 fn the_subject_is_the_post_subject_or_the_conversation_title() {
116 assert_eq!(
117 share_subject(&record(Some("Launch"), "<p>x</p>"), "General"),
118 "Launch"
119 );
120 assert_eq!(
121 share_subject(&record(Some(" "), "<p>x</p>"), "General"),
122 "General"
123 );
124 assert_eq!(
125 share_subject(&record(None, "<p>x</p>"), "Release planning"),
126 "Release planning"
127 );
128 }
129
130 #[test]
131 fn the_body_has_sender_and_time_then_the_text_then_the_link() {
132 let body = share_body(
133 &record(None, "<p>Ship it <b>today</b></p>"),
134 Some("https://teams.microsoft.com/l/message/1"),
135 );
136 let parts: Vec<&str> = body.split("\n\n").collect();
137 assert_eq!(parts.len(), 3);
138 assert!(parts[0].starts_with("Ada Example "));
139 assert!(parts[1].contains("Ship it"));
140 assert_eq!(parts[2], "https://teams.microsoft.com/l/message/1");
141 assert_eq!(
142 share_body(&record(None, "<p>hi</p>"), None)
143 .split("\n\n")
144 .count(),
145 2
146 );
147 }
148}
crates/app/src/views/conversation.rs +1 −0
@@ -3111,6 +3111,7 @@ impl ConversationView {
3111 3111 copy: action(|this, key, _, cx| this.copy_text(key, cx)),
3112 3112 translate: Some(action(|this, key, _, cx| this.translate_message(key, cx))),
3113 3113 translate_label,
3114 share_to_outlook: Some(action(|this, key, _, cx| this.share_to_outlook(key, cx))),
3114 3115 save: Some(action(|this, key, _, cx| this.toggle_saved(key, cx))),
3115 3116 saved,
3116 3117 toggle_pinned: pinnable
@@ -3111,6 +3111,7 @@ impl ConversationView {
3111 copy: action(|this, key, _, cx| this.copy_text(key, cx)),
3111 copy: action(|this, key, _, cx| this.copy_text(key, cx)),
3112 translate: Some(action(|this, key, _, cx| this.translate_message(key, cx))),
3112 translate: Some(action(|this, key, _, cx| this.translate_message(key, cx))),
3113 translate_label,
3113 translate_label,
3114 share_to_outlook: Some(action(|this, key, _, cx| this.share_to_outlook(key, cx))),
3114 save: Some(action(|this, key, _, cx| this.toggle_saved(key, cx))),
3115 save: Some(action(|this, key, _, cx| this.toggle_saved(key, cx))),
3115 saved,
3116 saved,
3116 toggle_pinned: pinnable
3117 toggle_pinned: pinnable
crates/app/src/views/conversation/pins.rs +12 −1
@@ -9,7 +9,7 @@ use gpui_kit::component::WindowExt as _;
9 9 use gpui_kit::component::button::{Button, ButtonVariants as _};
10 10 use gpui_kit::component::dialog::DialogFooter;
11 11
12 use crate::app_state::{AppState, Selection};
12 use crate::app_state::{AppState, Selection, selection_title};
13 13 use crate::channel_menu::post_pin_dialog;
14 14 use crate::rows::reply_excerpt;
15 15 use crate::runtime;
@@ -253,6 +253,17 @@ impl ConversationView {
253 253 }
254 254 }
255 255
256 pub(super) fn share_to_outlook(&mut self, message_id: &str, cx: &mut Context<Self>) {
257 let Some(current) = self.current.as_ref() else {
258 return;
259 };
260 let conversation_id = current.selection.conversation_id().to_owned();
261 let title = selection_title(&self.app.read(cx).sidebar, &current.selection);
262 self.app.update(cx, |state, cx| {
263 state.share_to_outlook(&conversation_id, message_id, &title, cx)
264 });
265 }
266
256 267 pub(super) fn toggle_saved(&mut self, message_id: &str, cx: &mut Context<Self>) {
257 268 if let Some(conversation_id) = self.conversation_id() {
258 269 self.app.update(cx, |state, cx| {
@@ -9,7 +9,7 @@ use gpui_kit::component::WindowExt as _;
9use gpui_kit::component::button::{Button, ButtonVariants as _};
9use gpui_kit::component::button::{Button, ButtonVariants as _};
10use gpui_kit::component::dialog::DialogFooter;
10use gpui_kit::component::dialog::DialogFooter;
11
11
12use crate::app_state::{AppState, Selection};
12use crate::app_state::{AppState, Selection, selection_title};
13use crate::channel_menu::post_pin_dialog;
13use crate::channel_menu::post_pin_dialog;
14use crate::rows::reply_excerpt;
14use crate::rows::reply_excerpt;
15use crate::runtime;
15use crate::runtime;
@@ -253,6 +253,17 @@ impl ConversationView {
253 }
253 }
254 }
254 }
255
255
256 pub(super) fn share_to_outlook(&mut self, message_id: &str, cx: &mut Context<Self>) {
257 let Some(current) = self.current.as_ref() else {
258 return;
259 };
260 let conversation_id = current.selection.conversation_id().to_owned();
261 let title = selection_title(&self.app.read(cx).sidebar, &current.selection);
262 self.app.update(cx, |state, cx| {
263 state.share_to_outlook(&conversation_id, message_id, &title, cx)
264 });
265 }
266
256 pub(super) fn toggle_saved(&mut self, message_id: &str, cx: &mut Context<Self>) {
267 pub(super) fn toggle_saved(&mut self, message_id: &str, cx: &mut Context<Self>) {
257 if let Some(conversation_id) = self.conversation_id() {
268 if let Some(conversation_id) = self.conversation_id() {
258 self.app.update(cx, |state, cx| {
269 self.app.update(cx, |state, cx| {
crates/app/src/views/message_actions.rs +11 −0
@@ -17,6 +17,7 @@ use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};
17 17 use super::widgets::{icon, symbol};
18 18 use crate::forward_selection::{FORWARD_LABEL, MULTIPLE_MESSAGES_LABEL, THIS_MESSAGE_LABEL};
19 19 use crate::rows::reaction_glyph;
20 use crate::share_outlook::SHARE_TO_OUTLOOK_LABEL;
20 21 use crate::theme::{self, ElevatedSurface as _};
21 22
22 23 const BAR_BUTTON: f32 = 30.;
@@ -47,6 +48,7 @@ pub struct MessageMenu {
47 48 pub copy: Action,
48 49 pub translate: Option<Action>,
49 50 pub translate_label: &'static str,
51 pub share_to_outlook: Option<Action>,
50 52 pub save: Option<Action>,
51 53 pub saved: bool,
52 54 pub toggle_pinned: Option<Action>,
@@ -199,6 +201,7 @@ fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {
199 201 delete,
200 202 mark_unread,
201 203 refresh_card,
204 share_to_outlook,
202 205 pin,
203 206 ) = (
204 207 menu.reply.clone(),
@@ -212,6 +215,7 @@ fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {
212 215 menu.delete.clone(),
213 216 menu.mark_unread.clone(),
214 217 menu.refresh_card.clone(),
218 menu.share_to_outlook.clone(),
215 219 menu.pin.clone(),
216 220 );
217 221 let (saved, pinned, translate_label) = (menu.saved, menu.pinned, menu.translate_label);
@@ -266,6 +270,13 @@ fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {
266 270 if let Some(translate) = translate.clone() {
267 271 popup = popup.item(item(translate_label, IconName::Languages, translate));
268 272 }
273 if let Some(share_to_outlook) = share_to_outlook.clone() {
274 popup = popup.item(item(
275 SHARE_TO_OUTLOOK_LABEL,
276 IconName::Mail,
277 share_to_outlook,
278 ));
279 }
269 280 if let Some(save) = save.clone() {
270 281 popup = popup.item(if saved {
271 282 item("Unsave message", IconName::BookmarkOff, save)
@@ -17,6 +17,7 @@ use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};
17use super::widgets::{icon, symbol};
17use super::widgets::{icon, symbol};
18use crate::forward_selection::{FORWARD_LABEL, MULTIPLE_MESSAGES_LABEL, THIS_MESSAGE_LABEL};
18use crate::forward_selection::{FORWARD_LABEL, MULTIPLE_MESSAGES_LABEL, THIS_MESSAGE_LABEL};
19use crate::rows::reaction_glyph;
19use crate::rows::reaction_glyph;
20use crate::share_outlook::SHARE_TO_OUTLOOK_LABEL;
20use crate::theme::{self, ElevatedSurface as _};
21use crate::theme::{self, ElevatedSurface as _};
21
22
22const BAR_BUTTON: f32 = 30.;
23const BAR_BUTTON: f32 = 30.;
@@ -47,6 +48,7 @@ pub struct MessageMenu {
47 pub copy: Action,
48 pub copy: Action,
48 pub translate: Option<Action>,
49 pub translate: Option<Action>,
49 pub translate_label: &'static str,
50 pub translate_label: &'static str,
51 pub share_to_outlook: Option<Action>,
50 pub save: Option<Action>,
52 pub save: Option<Action>,
51 pub saved: bool,
53 pub saved: bool,
52 pub toggle_pinned: Option<Action>,
54 pub toggle_pinned: Option<Action>,
@@ -199,6 +201,7 @@ fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {
199 delete,
201 delete,
200 mark_unread,
202 mark_unread,
201 refresh_card,
203 refresh_card,
204 share_to_outlook,
202 pin,
205 pin,
203 ) = (
206 ) = (
204 menu.reply.clone(),
207 menu.reply.clone(),
@@ -212,6 +215,7 @@ fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {
212 menu.delete.clone(),
215 menu.delete.clone(),
213 menu.mark_unread.clone(),
216 menu.mark_unread.clone(),
214 menu.refresh_card.clone(),
217 menu.refresh_card.clone(),
218 menu.share_to_outlook.clone(),
215 menu.pin.clone(),
219 menu.pin.clone(),
216 );
220 );
217 let (saved, pinned, translate_label) = (menu.saved, menu.pinned, menu.translate_label);
221 let (saved, pinned, translate_label) = (menu.saved, menu.pinned, menu.translate_label);
@@ -266,6 +270,13 @@ fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {
266 if let Some(translate) = translate.clone() {
270 if let Some(translate) = translate.clone() {
267 popup = popup.item(item(translate_label, IconName::Languages, translate));
271 popup = popup.item(item(translate_label, IconName::Languages, translate));
268 }
272 }
273 if let Some(share_to_outlook) = share_to_outlook.clone() {
274 popup = popup.item(item(
275 SHARE_TO_OUTLOOK_LABEL,
276 IconName::Mail,
277 share_to_outlook,
278 ));
279 }
269 if let Some(save) = save.clone() {
280 if let Some(save) = save.clone() {
270 popup = popup.item(if saved {
281 popup = popup.item(if saved {
271 item("Unsave message", IconName::BookmarkOff, save)
282 item("Unsave message", IconName::BookmarkOff, save)