BlueGit

ict rusty-teams

feat(messages): shared videos and images show a preview in the file card

- SharePoint video and image files get the Graph thumbnail, videos a play overlay
- FileKind::Video for mp4, mov, webm, mkv, avi, m4v

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-05 · 3 weeks ago

Hash
0c7de303683bf88dfd2a7c355d1aa577ca0ca229
Parent
758bbe2e
5 files changed +101 −19
crates/app-base/src/agent_api/extras.rs +1 −0
@@ -76,6 +76,7 @@ fn file_type(kind: teams_core::FileKind) -> &'static str {
76 76 teams_core::FileKind::PowerPoint => "powerpoint",
77 77 teams_core::FileKind::Pdf => "pdf",
78 78 teams_core::FileKind::Image => "image",
79 teams_core::FileKind::Video => "video",
79 80 teams_core::FileKind::Archive => "archive",
80 81 teams_core::FileKind::Loop => "loop",
81 82 teams_core::FileKind::Other => "other",
@@ -76,6 +76,7 @@ fn file_type(kind: teams_core::FileKind) -> &'static str {
76 teams_core::FileKind::PowerPoint => "powerpoint",
76 teams_core::FileKind::PowerPoint => "powerpoint",
77 teams_core::FileKind::Pdf => "pdf",
77 teams_core::FileKind::Pdf => "pdf",
78 teams_core::FileKind::Image => "image",
78 teams_core::FileKind::Image => "image",
79 teams_core::FileKind::Video => "video",
79 teams_core::FileKind::Archive => "archive",
80 teams_core::FileKind::Archive => "archive",
80 teams_core::FileKind::Loop => "loop",
81 teams_core::FileKind::Loop => "loop",
81 teams_core::FileKind::Other => "other",
82 teams_core::FileKind::Other => "other",
crates/app/src/views/attachments.rs +54 −11
@@ -26,6 +26,8 @@ const FILE_BADGE_SIZE: f32 = 34.;
26 26 const SAVE_BUTTON_SIZE: f32 = 28.;
27 27 const SAVE_BUTTON_RADIUS: f32 = 6.;
28 28 const SAVE_PROGRESS_HEIGHT: f32 = 2.;
29 const FILE_PREVIEW_HEIGHT: f32 = FILE_CARD_WIDTH * 9. / 16.;
30 const PLAY_BUTTON_SIZE: f32 = 40.;
29 31 const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";
30 32 const LOCAL_IMAGE_SUFFIX: &str = "/$value";
31 33
@@ -141,6 +143,7 @@ fn kind_style(kind: FileKind) -> KindStyle {
141 143 FileKind::PowerPoint => ("PPT", "PowerPoint", 0xC2410C),
142 144 FileKind::Pdf => ("PDF", "PDF document", 0xB91C1C),
143 145 FileKind::Image => ("IMG", "Image", 0x7C3AED),
146 FileKind::Video => ("VID", "Video", 0xBE185D),
144 147 FileKind::Archive => ("ZIP", "Archive", 0xB45309),
145 148 FileKind::Loop => ("", "Loop component", 0x7C3AED),
146 149 FileKind::Other => ("", "File", 0x525252),
@@ -240,11 +243,47 @@ fn save_button(
240 243 }
241 244 }
242 245
246 fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
247 let image = card
248 .preview()
249 .and_then(|preview| directory.image(&preview.url).map(|entry| entry.path.clone()));
250 if image.is_none() && card.kind != FileKind::Video {
251 return None;
252 }
253 let frame = div()
254 .relative()
255 .w_full()
256 .h(px(FILE_PREVIEW_HEIGHT))
257 .overflow_hidden()
258 .bg(theme::code_surface());
259 let frame = match image {
260 Some(path) => frame.child(img(path).size_full().object_fit(match card.kind {
261 FileKind::Video => ObjectFit::Cover,
262 _ => ObjectFit::Contain,
263 })),
264 None => frame,
265 };
266 Some(frame.when(card.kind == FileKind::Video, |frame| {
267 frame.child(
268 h_flex().absolute().inset_0().items_center().justify_center().child(
269 h_flex()
270 .size(px(PLAY_BUTTON_SIZE))
271 .rounded_full()
272 .items_center()
273 .justify_center()
274 .bg(black().opacity(0.5))
275 .child(icon(IconName::Play, 18., theme::white())),
276 ),
277 )
278 }))
279 }
280
243 281 fn file_view(
244 282 card: &FileCard,
245 283 id: String,
246 284 index: usize,
247 285 actions: Option<&FileActions>,
286 directory: &Directory,
248 287 ) -> AnyElement {
249 288 let badge = file_badge(card.kind, FILE_BADGE_SIZE);
250 289 let url = card.open_url.clone();
@@ -255,20 +294,12 @@ fn file_view(
255 294 let button = actions
256 295 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
257 296 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
258 h_flex()
259 .id(ElementId::Name(id.into()))
260 .relative()
261 .overflow_hidden()
297 let row = h_flex()
262 298 .w_full()
263 .max_w(px(FILE_CARD_WIDTH))
264 299 .gap(px(12.))
265 300 .px(px(8.))
266 301 .py(px(8.))
267 302 .items_center()
268 .rounded(px(10.))
269 .bg(theme::surface())
270 .cursor_pointer()
271 .hover(|card| card.bg(theme::row_hover()))
272 303 .child(badge)
273 304 .child(
274 305 v_flex()
@@ -290,7 +321,19 @@ fn file_view(
290 321 ),
291 322 )
292 323 .child(icon(IconName::ExternalLink, 14., theme::text_muted()))
293 .children(button)
324 .children(button);
325 v_flex()
326 .id(ElementId::Name(id.into()))
327 .relative()
328 .overflow_hidden()
329 .w_full()
330 .max_w(px(FILE_CARD_WIDTH))
331 .rounded(px(10.))
332 .bg(theme::surface())
333 .cursor_pointer()
334 .hover(|card| card.bg(theme::row_hover()))
335 .children(file_preview(card, directory))
336 .child(row)
294 337 .when_some(progress, |card, fraction| {
295 338 card.child(
296 339 div()
@@ -424,7 +467,7 @@ pub fn attachments_view(
424 467 }),
425 468 )
426 469 .children(files.iter().enumerate().map(|(index, card)| {
427 file_view(card, format!("{id}-file-{index}"), index, file_actions)
470 file_view(card, format!("{id}-file-{index}"), index, file_actions, directory)
428 471 })),
429 472 )
430 473 }
@@ -26,6 +26,8 @@ const FILE_BADGE_SIZE: f32 = 34.;
26const SAVE_BUTTON_SIZE: f32 = 28.;
26const SAVE_BUTTON_SIZE: f32 = 28.;
27const SAVE_BUTTON_RADIUS: f32 = 6.;
27const SAVE_BUTTON_RADIUS: f32 = 6.;
28const SAVE_PROGRESS_HEIGHT: f32 = 2.;
28const SAVE_PROGRESS_HEIGHT: f32 = 2.;
29const FILE_PREVIEW_HEIGHT: f32 = FILE_CARD_WIDTH * 9. / 16.;
30const PLAY_BUTTON_SIZE: f32 = 40.;
29const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";
31const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";
30const LOCAL_IMAGE_SUFFIX: &str = "/$value";
32const LOCAL_IMAGE_SUFFIX: &str = "/$value";
31
33
@@ -141,6 +143,7 @@ fn kind_style(kind: FileKind) -> KindStyle {
141 FileKind::PowerPoint => ("PPT", "PowerPoint", 0xC2410C),
143 FileKind::PowerPoint => ("PPT", "PowerPoint", 0xC2410C),
142 FileKind::Pdf => ("PDF", "PDF document", 0xB91C1C),
144 FileKind::Pdf => ("PDF", "PDF document", 0xB91C1C),
143 FileKind::Image => ("IMG", "Image", 0x7C3AED),
145 FileKind::Image => ("IMG", "Image", 0x7C3AED),
146 FileKind::Video => ("VID", "Video", 0xBE185D),
144 FileKind::Archive => ("ZIP", "Archive", 0xB45309),
147 FileKind::Archive => ("ZIP", "Archive", 0xB45309),
145 FileKind::Loop => ("", "Loop component", 0x7C3AED),
148 FileKind::Loop => ("", "Loop component", 0x7C3AED),
146 FileKind::Other => ("", "File", 0x525252),
149 FileKind::Other => ("", "File", 0x525252),
@@ -240,11 +243,47 @@ fn save_button(
240 }
243 }
241}
244}
242
245
246fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
247 let image = card
248 .preview()
249 .and_then(|preview| directory.image(&preview.url).map(|entry| entry.path.clone()));
250 if image.is_none() && card.kind != FileKind::Video {
251 return None;
252 }
253 let frame = div()
254 .relative()
255 .w_full()
256 .h(px(FILE_PREVIEW_HEIGHT))
257 .overflow_hidden()
258 .bg(theme::code_surface());
259 let frame = match image {
260 Some(path) => frame.child(img(path).size_full().object_fit(match card.kind {
261 FileKind::Video => ObjectFit::Cover,
262 _ => ObjectFit::Contain,
263 })),
264 None => frame,
265 };
266 Some(frame.when(card.kind == FileKind::Video, |frame| {
267 frame.child(
268 h_flex().absolute().inset_0().items_center().justify_center().child(
269 h_flex()
270 .size(px(PLAY_BUTTON_SIZE))
271 .rounded_full()
272 .items_center()
273 .justify_center()
274 .bg(black().opacity(0.5))
275 .child(icon(IconName::Play, 18., theme::white())),
276 ),
277 )
278 }))
279}
280
243fn file_view(
281fn file_view(
244 card: &FileCard,
282 card: &FileCard,
245 id: String,
283 id: String,
246 index: usize,
284 index: usize,
247 actions: Option<&FileActions>,
285 actions: Option<&FileActions>,
286 directory: &Directory,
248) -> AnyElement {
287) -> AnyElement {
249 let badge = file_badge(card.kind, FILE_BADGE_SIZE);
288 let badge = file_badge(card.kind, FILE_BADGE_SIZE);
250 let url = card.open_url.clone();
289 let url = card.open_url.clone();
@@ -255,20 +294,12 @@ fn file_view(
255 let button = actions
294 let button = actions
256 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
295 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
257 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
296 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
258 h_flex()
297 let row = h_flex()
259 .id(ElementId::Name(id.into()))
260 .relative()
261 .overflow_hidden()
262 .w_full()
298 .w_full()
263 .max_w(px(FILE_CARD_WIDTH))
264 .gap(px(12.))
299 .gap(px(12.))
265 .px(px(8.))
300 .px(px(8.))
266 .py(px(8.))
301 .py(px(8.))
267 .items_center()
302 .items_center()
268 .rounded(px(10.))
269 .bg(theme::surface())
270 .cursor_pointer()
271 .hover(|card| card.bg(theme::row_hover()))
272 .child(badge)
303 .child(badge)
273 .child(
304 .child(
274 v_flex()
305 v_flex()
@@ -290,7 +321,19 @@ fn file_view(
290 ),
321 ),
291 )
322 )
292 .child(icon(IconName::ExternalLink, 14., theme::text_muted()))
323 .child(icon(IconName::ExternalLink, 14., theme::text_muted()))
293 .children(button)
324 .children(button);
325 v_flex()
326 .id(ElementId::Name(id.into()))
327 .relative()
328 .overflow_hidden()
329 .w_full()
330 .max_w(px(FILE_CARD_WIDTH))
331 .rounded(px(10.))
332 .bg(theme::surface())
333 .cursor_pointer()
334 .hover(|card| card.bg(theme::row_hover()))
335 .children(file_preview(card, directory))
336 .child(row)
294 .when_some(progress, |card, fraction| {
337 .when_some(progress, |card, fraction| {
295 card.child(
338 card.child(
296 div()
339 div()
@@ -424,7 +467,7 @@ pub fn attachments_view(
424 }),
467 }),
425 )
468 )
426 .children(files.iter().enumerate().map(|(index, card)| {
469 .children(files.iter().enumerate().map(|(index, card)| {
427 file_view(card, format!("{id}-file-{index}"), index, file_actions)
470 file_view(card, format!("{id}-file-{index}"), index, file_actions, directory)
428 })),
471 })),
429 )
472 )
430}
473}
crates/app/src/views/conversation/render_env.rs +2 −1
@@ -8,7 +8,7 @@ use gpui_kit::component::{
8 8 };
9 9 use gpui_kit::*;
10 10 use mcp::ReactionProposal;
11 use teams_core::{ImageRef, LinkPreview};
11 use teams_core::{FileCard, ImageRef, LinkPreview};
12 12
13 13 use super::forward_select::SelectionSnapshot;
14 14 use super::{ConversationView, HoverSlot, PENDING_KEY_PREFIX};
@@ -78,6 +78,7 @@ impl RenderEnv {
78 78 .as_ref()
79 79 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
80 80 )
81 .chain(message.files.iter().filter_map(FileCard::preview))
81 82 .chain(
82 83 message
83 84 .reactions
@@ -8,7 +8,7 @@ use gpui_kit::component::{
8};
8};
9use gpui_kit::*;
9use gpui_kit::*;
10use mcp::ReactionProposal;
10use mcp::ReactionProposal;
11use teams_core::{ImageRef, LinkPreview};
11use teams_core::{FileCard, ImageRef, LinkPreview};
12
12
13use super::forward_select::SelectionSnapshot;
13use super::forward_select::SelectionSnapshot;
14use super::{ConversationView, HoverSlot, PENDING_KEY_PREFIX};
14use super::{ConversationView, HoverSlot, PENDING_KEY_PREFIX};
@@ -78,6 +78,7 @@ impl RenderEnv {
78 .as_ref()
78 .as_ref()
79 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
79 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
80 )
80 )
81 .chain(message.files.iter().filter_map(FileCard::preview))
81 .chain(
82 .chain(
82 message
83 message
83 .reactions
84 .reactions
crates/core/src/call_event.rs +9 −7
@@ -72,15 +72,17 @@ impl Recording {
72 72 }
73 73
74 74 pub fn thumbnail_url(&self) -> Option<String> {
75 let url = self
76 .url
77 .as_deref()
78 .filter(|url| url.contains(SHAREPOINT_HOST))?;
79 Some(format!(
75 sharepoint_thumbnail_url(self.url.as_deref()?)
76 }
77 }
78
79 pub fn sharepoint_thumbnail_url(url: &str) -> Option<String> {
80 url.contains(SHAREPOINT_HOST).then(|| {
81 format!(
80 82 "{GRAPH_SHARES}{}{THUMBNAIL_PATH}",
81 83 chatsvc::transcripts::share_id(url)
82 ))
83 }
84 )
85 })
84 86 }
85 87
86 88 fn is_recording_stamp(stamp: &str) -> bool {
@@ -72,15 +72,17 @@ impl Recording {
72 }
72 }
73
73
74 pub fn thumbnail_url(&self) -> Option<String> {
74 pub fn thumbnail_url(&self) -> Option<String> {
75 let url = self
75 sharepoint_thumbnail_url(self.url.as_deref()?)
76 .url
76 }
77 .as_deref()
77}
78 .filter(|url| url.contains(SHAREPOINT_HOST))?;
78
79 Some(format!(
79pub fn sharepoint_thumbnail_url(url: &str) -> Option<String> {
80 url.contains(SHAREPOINT_HOST).then(|| {
81 format!(
80 "{GRAPH_SHARES}{}{THUMBNAIL_PATH}",
82 "{GRAPH_SHARES}{}{THUMBNAIL_PATH}",
81 chatsvc::transcripts::share_id(url)
83 chatsvc::transcripts::share_id(url)
82 ))
84 )
83 }
85 })
84}
86}
85
87
86fn is_recording_stamp(stamp: &str) -> bool {
88fn is_recording_stamp(stamp: &str) -> bool {
crates/core/src/stored.rs +35 −0
@@ -46,6 +46,7 @@ pub enum FileKind {
46 46 PowerPoint,
47 47 Pdf,
48 48 Image,
49 Video,
49 50 Archive,
50 51 Loop,
51 52 Other,
@@ -64,6 +65,7 @@ impl FileKind {
64 65 "png" | "jpg" | "jpeg" | "gif" | "bmp" | "webp" | "svg" | "heic" | "tif" | "tiff" => {
65 66 FileKind::Image
66 67 }
68 "mp4" | "mov" | "webm" | "mkv" | "avi" | "m4v" => FileKind::Video,
67 69 "zip" | "rar" | "7z" | "tar" | "gz" | "tgz" => FileKind::Archive,
68 70 _ => FileKind::Other,
69 71 }
@@ -405,6 +407,21 @@ pub struct FileCard {
405 407 pub open_url: String,
406 408 }
407 409
410 impl FileCard {
411 pub fn preview(&self) -> Option<ImageRef> {
412 if !matches!(self.kind, FileKind::Image | FileKind::Video) {
413 return None;
414 }
415 Some(ImageRef {
416 id: format!("file-preview-{}", self.open_url),
417 url: crate::call_event::sharepoint_thumbnail_url(&self.open_url)?,
418 width: None,
419 height: None,
420 alt: Some(self.name.clone()),
421 })
422 }
423 }
424
408 425 /// File attachments (`reference` type) with a name and a URL. `size` is rarely known; Graph does not send it for these.
409 426 pub fn files(record: &MessageRecord) -> Vec<FileCard> {
410 427 let all = attachments(record);
@@ -1096,6 +1113,24 @@ mod tests {
1096 1113 assert!(preserved.kept.is_empty());
1097 1114 }
1098 1115
1116 #[test]
1117 fn sharepoint_videos_and_images_get_a_graph_thumbnail() {
1118 let card = |name: &str, url: &str| FileCard {
1119 name: name.to_owned(),
1120 kind: FileKind::from_name(name),
1121 content_type: Some("reference".to_owned()),
1122 size: None,
1123 open_url: url.to_owned(),
1124 };
1125 let sharepoint = "https://contoso.sharepoint.com/personal/a/Documents/clip.mp4";
1126 let preview = card("clip.mp4", sharepoint).preview().unwrap();
1127 assert!(preview.url.starts_with("https://graph.microsoft.com/v1.0/shares/u!"));
1128 assert!(preview.url.ends_with("/driveItem/thumbnails/0/large/content"));
1129 assert!(card("shot.PNG", sharepoint).preview().is_some());
1130 assert_eq!(card("plan.docx", sharepoint).preview(), None);
1131 assert_eq!(card("clip.mov", "https://example.com/clip.mov").preview(), None);
1132 }
1133
1099 1134 #[test]
1100 1135 fn file_kind_follows_the_extension_then_the_content_type() {
1101 1136 let kind = |name: Option<&str>, content_type: &str| {
@@ -46,6 +46,7 @@ pub enum FileKind {
46 PowerPoint,
46 PowerPoint,
47 Pdf,
47 Pdf,
48 Image,
48 Image,
49 Video,
49 Archive,
50 Archive,
50 Loop,
51 Loop,
51 Other,
52 Other,
@@ -64,6 +65,7 @@ impl FileKind {
64 "png" | "jpg" | "jpeg" | "gif" | "bmp" | "webp" | "svg" | "heic" | "tif" | "tiff" => {
65 "png" | "jpg" | "jpeg" | "gif" | "bmp" | "webp" | "svg" | "heic" | "tif" | "tiff" => {
65 FileKind::Image
66 FileKind::Image
66 }
67 }
68 "mp4" | "mov" | "webm" | "mkv" | "avi" | "m4v" => FileKind::Video,
67 "zip" | "rar" | "7z" | "tar" | "gz" | "tgz" => FileKind::Archive,
69 "zip" | "rar" | "7z" | "tar" | "gz" | "tgz" => FileKind::Archive,
68 _ => FileKind::Other,
70 _ => FileKind::Other,
69 }
71 }
@@ -405,6 +407,21 @@ pub struct FileCard {
405 pub open_url: String,
407 pub open_url: String,
406}
408}
407
409
410impl FileCard {
411 pub fn preview(&self) -> Option<ImageRef> {
412 if !matches!(self.kind, FileKind::Image | FileKind::Video) {
413 return None;
414 }
415 Some(ImageRef {
416 id: format!("file-preview-{}", self.open_url),
417 url: crate::call_event::sharepoint_thumbnail_url(&self.open_url)?,
418 width: None,
419 height: None,
420 alt: Some(self.name.clone()),
421 })
422 }
423}
424
408/// File attachments (`reference` type) with a name and a URL. `size` is rarely known; Graph does not send it for these.
425/// File attachments (`reference` type) with a name and a URL. `size` is rarely known; Graph does not send it for these.
409pub fn files(record: &MessageRecord) -> Vec<FileCard> {
426pub fn files(record: &MessageRecord) -> Vec<FileCard> {
410 let all = attachments(record);
427 let all = attachments(record);
@@ -1096,6 +1113,24 @@ mod tests {
1096 assert!(preserved.kept.is_empty());
1113 assert!(preserved.kept.is_empty());
1097 }
1114 }
1098
1115
1116 #[test]
1117 fn sharepoint_videos_and_images_get_a_graph_thumbnail() {
1118 let card = |name: &str, url: &str| FileCard {
1119 name: name.to_owned(),
1120 kind: FileKind::from_name(name),
1121 content_type: Some("reference".to_owned()),
1122 size: None,
1123 open_url: url.to_owned(),
1124 };
1125 let sharepoint = "https://contoso.sharepoint.com/personal/a/Documents/clip.mp4";
1126 let preview = card("clip.mp4", sharepoint).preview().unwrap();
1127 assert!(preview.url.starts_with("https://graph.microsoft.com/v1.0/shares/u!"));
1128 assert!(preview.url.ends_with("/driveItem/thumbnails/0/large/content"));
1129 assert!(card("shot.PNG", sharepoint).preview().is_some());
1130 assert_eq!(card("plan.docx", sharepoint).preview(), None);
1131 assert_eq!(card("clip.mov", "https://example.com/clip.mov").preview(), None);
1132 }
1133
1099 #[test]
1134 #[test]
1100 fn file_kind_follows_the_extension_then_the_content_type() {
1135 fn file_kind_follows_the_extension_then_the_content_type() {
1101 let kind = |name: Option<&str>, content_type: &str| {
1136 let kind = |name: Option<&str>, content_type: &str| {