BlueGit

ict rusty-teams

fix(chat): forwarded video clips show their thumbnail and play

A forwarded phone recording carries the original as
`<video src=".../views/video" itemtype="http://schema.skype.com/AMSVideo">`
inside the forward. Message HTML dropped `<video>`, so the forward
rendered as an empty quote. Direct video clips had the same gap.

AMS clips now draw as their `/views/thumbnail` view with a play
button. A click downloads the clip through the AMS image path into the
image cache and opens it in the system player. Clips stay out of the
image viewer gallery.

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

metis Michael Wallner · pushed by metis

Authored 2026-11-16 · 2 weeks ago

Hash
8157220eb6a057d9bd27c6e2846223e1422922ff
Parent
4e96335d
10 files changed +180 −29
crates/app/src/views/attachments.rs +37 −19
@@ -35,9 +35,11 @@ const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";
35 35 const LOCAL_IMAGE_SUFFIX: &str = "/$value";
36 36
37 37 pub type FileActivate = Rc<dyn Fn(usize, &mut App)>;
38 /// Opens the image viewer, or plays the clip for a video thumbnail.
39 pub type ImageOpen = Rc<dyn Fn(&ImageRef, &mut App)>;
38 40 #[derive(Clone)]
39 41 pub struct ImageActions {
40 pub open: Rc<dyn Fn(&str, &mut App)>,
42 pub open: ImageOpen,
41 43 pub share: Option<ImageShare>,
42 44 }
43 45
@@ -116,6 +118,7 @@ fn image_view(
116 118 ) -> AnyElement {
117 119 let (width, height) = image_size(image, directory, sent_preview);
118 120 let image_id = ElementId::Name(format!("{id}-image").into());
121 let clip = image.video_url().is_some();
119 122 let frame = div()
120 123 .id(ElementId::Name(id.into()))
121 124 .relative()
@@ -129,6 +132,17 @@ fn image_view(
129 132 if let Some(sent) = sent_preview {
130 133 return frame.child(local_image(sent, image_id)).into_any_element();
131 134 }
135 if clip {
136 let (image, open_image) = (image.clone(), open_image.cloned());
137 return frame
138 .bg(theme::code_surface())
139 .cursor_pointer()
140 .child(play_badge())
141 .when_some(open_image, |frame, actions| {
142 frame.on_click(move |_, _, cx| (actions.open)(&image, cx))
143 })
144 .into_any_element();
145 }
132 146 return frame
133 147 .flex()
134 148 .flex_col()
@@ -147,7 +161,7 @@ fn image_view(
147 161 };
148 162 let path = entry.path.clone();
149 163 let share = open_image.and_then(|actions| actions.share.clone());
150 let (url, open_image) = (image.url.clone(), open_image.cloned());
164 let (image, open_image) = (image.clone(), open_image.cloned());
151 165 let frame = frame
152 166 .cursor_pointer()
153 167 .child(
@@ -162,10 +176,11 @@ fn image_view(
162 176 })
163 177 }),
164 178 )
179 .when(clip, |frame| frame.child(play_badge()))
165 180 .on_click({
166 181 let path = path.clone();
167 182 move |_, _, cx| match &open_image {
168 Some(actions) => (actions.open)(&url, cx),
183 Some(actions) => (actions.open)(&image, cx),
169 184 None => cx.open_with_system(&path),
170 185 }
171 186 });
@@ -325,25 +340,28 @@ fn file_preview(card: &FileCard, id: &str, directory: &Directory) -> Option<Stat
325 340 cx.stop_propagation();
326 341 }
327 342 })
328 .child(
329 h_flex()
330 .absolute()
331 .inset_0()
332 .items_center()
333 .justify_center()
334 .child(
335 h_flex()
336 .size(px(PLAY_BUTTON_SIZE))
337 .rounded_full()
338 .items_center()
339 .justify_center()
340 .bg(black().opacity(0.5))
341 .child(icon(IconName::Play, 18., theme::white())),
342 ),
343 )
343 .child(play_badge())
344 344 }))
345 345 }
346 346
347 /// A round play button centered over a video preview.
348 fn play_badge() -> Div {
349 h_flex()
350 .absolute()
351 .inset_0()
352 .items_center()
353 .justify_center()
354 .child(
355 h_flex()
356 .size(px(PLAY_BUTTON_SIZE))
357 .rounded_full()
358 .items_center()
359 .justify_center()
360 .bg(black().opacity(0.5))
361 .child(icon(IconName::Play, 18., theme::white())),
362 )
363 }
364
347 365 fn file_view(
348 366 card: &FileCard,
349 367 id: String,
@@ -35,9 +35,11 @@ const LOCAL_IMAGE_PREFIX: &str = "../hostedContents/";
35const LOCAL_IMAGE_SUFFIX: &str = "/$value";
35const LOCAL_IMAGE_SUFFIX: &str = "/$value";
36
36
37pub type FileActivate = Rc<dyn Fn(usize, &mut App)>;
37pub type FileActivate = Rc<dyn Fn(usize, &mut App)>;
38/// Opens the image viewer, or plays the clip for a video thumbnail.
39pub type ImageOpen = Rc<dyn Fn(&ImageRef, &mut App)>;
38#[derive(Clone)]
40#[derive(Clone)]
39pub struct ImageActions {
41pub struct ImageActions {
40 pub open: Rc<dyn Fn(&str, &mut App)>,
42 pub open: ImageOpen,
41 pub share: Option<ImageShare>,
43 pub share: Option<ImageShare>,
42}
44}
43
45
@@ -116,6 +118,7 @@ fn image_view(
116) -> AnyElement {
118) -> AnyElement {
117 let (width, height) = image_size(image, directory, sent_preview);
119 let (width, height) = image_size(image, directory, sent_preview);
118 let image_id = ElementId::Name(format!("{id}-image").into());
120 let image_id = ElementId::Name(format!("{id}-image").into());
121 let clip = image.video_url().is_some();
119 let frame = div()
122 let frame = div()
120 .id(ElementId::Name(id.into()))
123 .id(ElementId::Name(id.into()))
121 .relative()
124 .relative()
@@ -129,6 +132,17 @@ fn image_view(
129 if let Some(sent) = sent_preview {
132 if let Some(sent) = sent_preview {
130 return frame.child(local_image(sent, image_id)).into_any_element();
133 return frame.child(local_image(sent, image_id)).into_any_element();
131 }
134 }
135 if clip {
136 let (image, open_image) = (image.clone(), open_image.cloned());
137 return frame
138 .bg(theme::code_surface())
139 .cursor_pointer()
140 .child(play_badge())
141 .when_some(open_image, |frame, actions| {
142 frame.on_click(move |_, _, cx| (actions.open)(&image, cx))
143 })
144 .into_any_element();
145 }
132 return frame
146 return frame
133 .flex()
147 .flex()
134 .flex_col()
148 .flex_col()
@@ -147,7 +161,7 @@ fn image_view(
147 };
161 };
148 let path = entry.path.clone();
162 let path = entry.path.clone();
149 let share = open_image.and_then(|actions| actions.share.clone());
163 let share = open_image.and_then(|actions| actions.share.clone());
150 let (url, open_image) = (image.url.clone(), open_image.cloned());
164 let (image, open_image) = (image.clone(), open_image.cloned());
151 let frame = frame
165 let frame = frame
152 .cursor_pointer()
166 .cursor_pointer()
153 .child(
167 .child(
@@ -162,10 +176,11 @@ fn image_view(
162 })
176 })
163 }),
177 }),
164 )
178 )
179 .when(clip, |frame| frame.child(play_badge()))
165 .on_click({
180 .on_click({
166 let path = path.clone();
181 let path = path.clone();
167 move |_, _, cx| match &open_image {
182 move |_, _, cx| match &open_image {
168 Some(actions) => (actions.open)(&url, cx),
183 Some(actions) => (actions.open)(&image, cx),
169 None => cx.open_with_system(&path),
184 None => cx.open_with_system(&path),
170 }
185 }
171 });
186 });
@@ -325,25 +340,28 @@ fn file_preview(card: &FileCard, id: &str, directory: &Directory) -> Option<Stat
325 cx.stop_propagation();
340 cx.stop_propagation();
326 }
341 }
327 })
342 })
328 .child(
343 .child(play_badge())
329 h_flex()
330 .absolute()
331 .inset_0()
332 .items_center()
333 .justify_center()
334 .child(
335 h_flex()
336 .size(px(PLAY_BUTTON_SIZE))
337 .rounded_full()
338 .items_center()
339 .justify_center()
340 .bg(black().opacity(0.5))
341 .child(icon(IconName::Play, 18., theme::white())),
342 ),
343 )
344 }))
344 }))
345}
345}
346
346
347/// A round play button centered over a video preview.
348fn play_badge() -> Div {
349 h_flex()
350 .absolute()
351 .inset_0()
352 .items_center()
353 .justify_center()
354 .child(
355 h_flex()
356 .size(px(PLAY_BUTTON_SIZE))
357 .rounded_full()
358 .items_center()
359 .justify_center()
360 .bg(black().opacity(0.5))
361 .child(icon(IconName::Play, 18., theme::white())),
362 )
363}
364
347fn file_view(
365fn file_view(
348 card: &FileCard,
366 card: &FileCard,
349 id: String,
367 id: String,
crates/app/src/views/conversation.rs +32 −1
@@ -18,7 +18,8 @@ use gpui_kit::prelude::FluentBuilder as _;
18 18 use gpui_kit::*;
19 19 use store::{ChannelTabRecord, MessageRecord, OutboxState, OutboxTarget, is_bot_id};
20 20 use teams_core::{
21 ExecuteAction, FileCard, JumpPlan, LinkPreview, WindowDirection, is_notes_chat, without_islands,
21 ExecuteAction, FileCard, ImageRef, JumpPlan, LinkPreview, WindowDirection, is_notes_chat,
22 without_islands,
22 23 };
23 24
24 25 mod channel_details;
@@ -520,6 +521,36 @@ impl ConversationView {
520 521 .update(cx, |state, cx| state.request_image_viewer(request, cx));
521 522 }
522 523
524 /// Downloads a Teams video clip into the image cache, then opens it in the system player.
525 fn play_clip(&mut self, url: String, cx: &mut Context<Self>) {
526 let Some(engine) = self.app.read(cx).engine.clone() else {
527 return;
528 };
529 let clip = ImageRef {
530 id: url.clone(),
531 url,
532 width: None,
533 height: None,
534 alt: None,
535 };
536 let fetched = runtime::spawn(async move { engine.fetch_image(&clip).await });
537 cx.spawn(async move |this, cx| {
538 let Ok(outcome) = fetched.await else {
539 return;
540 };
541 this.update(cx, |this, cx| match outcome {
542 Ok(Some(path)) => cx.open_with_system(&path),
543 Ok(None) => {}
544 Err(error) => this.show_notice(
545 &format!("Could not play the video: {}", short_error(&error)),
546 cx,
547 ),
548 })
549 .ok();
550 })
551 .detach();
552 }
553
523 554 fn activate_file(
524 555 &mut self,
525 556 conversation_id: &str,
@@ -18,7 +18,8 @@ use gpui_kit::prelude::FluentBuilder as _;
18use gpui_kit::*;
18use gpui_kit::*;
19use store::{ChannelTabRecord, MessageRecord, OutboxState, OutboxTarget, is_bot_id};
19use store::{ChannelTabRecord, MessageRecord, OutboxState, OutboxTarget, is_bot_id};
20use teams_core::{
20use teams_core::{
21 ExecuteAction, FileCard, JumpPlan, LinkPreview, WindowDirection, is_notes_chat, without_islands,
21 ExecuteAction, FileCard, ImageRef, JumpPlan, LinkPreview, WindowDirection, is_notes_chat,
22 without_islands,
22};
23};
23
24
24mod channel_details;
25mod channel_details;
@@ -520,6 +521,36 @@ impl ConversationView {
520 .update(cx, |state, cx| state.request_image_viewer(request, cx));
521 .update(cx, |state, cx| state.request_image_viewer(request, cx));
521 }
522 }
522
523
524 /// Downloads a Teams video clip into the image cache, then opens it in the system player.
525 fn play_clip(&mut self, url: String, cx: &mut Context<Self>) {
526 let Some(engine) = self.app.read(cx).engine.clone() else {
527 return;
528 };
529 let clip = ImageRef {
530 id: url.clone(),
531 url,
532 width: None,
533 height: None,
534 alt: None,
535 };
536 let fetched = runtime::spawn(async move { engine.fetch_image(&clip).await });
537 cx.spawn(async move |this, cx| {
538 let Ok(outcome) = fetched.await else {
539 return;
540 };
541 this.update(cx, |this, cx| match outcome {
542 Ok(Some(path)) => cx.open_with_system(&path),
543 Ok(None) => {}
544 Err(error) => this.show_notice(
545 &format!("Could not play the video: {}", short_error(&error)),
546 cx,
547 ),
548 })
549 .ok();
550 })
551 .detach();
552 }
553
523 fn activate_file(
554 fn activate_file(
524 &mut self,
555 &mut self,
525 conversation_id: &str,
556 conversation_id: &str,
crates/app/src/views/conversation/render_env.rs +5 −2
@@ -311,9 +311,12 @@ impl RenderEnv {
311 311 let (open_view, open_key) = (view.clone(), message.key.clone());
312 312 let (share_view, share_key) = (view.clone(), message.key.clone());
313 313 ImageActions {
314 open: Rc::new(move |url: &str, cx: &mut App| {
314 open: Rc::new(move |image: &ImageRef, cx: &mut App| {
315 315 open_view
316 .update(cx, |this, cx| this.open_image_viewer(&open_key, url, cx))
316 .update(cx, |this, cx| match image.video_url() {
317 Some(clip) => this.play_clip(clip, cx),
318 None => this.open_image_viewer(&open_key, &image.url, cx),
319 })
317 320 .ok();
318 321 }),
319 322 share: Some(Rc::new(move |cx: &mut App| {
@@ -311,9 +311,12 @@ impl RenderEnv {
311 let (open_view, open_key) = (view.clone(), message.key.clone());
311 let (open_view, open_key) = (view.clone(), message.key.clone());
312 let (share_view, share_key) = (view.clone(), message.key.clone());
312 let (share_view, share_key) = (view.clone(), message.key.clone());
313 ImageActions {
313 ImageActions {
314 open: Rc::new(move |url: &str, cx: &mut App| {
314 open: Rc::new(move |image: &ImageRef, cx: &mut App| {
315 open_view
315 open_view
316 .update(cx, |this, cx| this.open_image_viewer(&open_key, url, cx))
316 .update(cx, |this, cx| match image.video_url() {
317 Some(clip) => this.play_clip(clip, cx),
318 None => this.open_image_viewer(&open_key, &image.url, cx),
319 })
317 .ok();
320 .ok();
318 }),
321 }),
319 share: Some(Rc::new(move |cx: &mut App| {
322 share: Some(Rc::new(move |cx: &mut App| {
crates/core/src/ams_video.rs added +41 −0
@@ -0,0 +1,41 @@
1 //! Teams video clips: an AMS `<video src=".../views/video">`, shown through the object's thumbnail view.
2
3 const VIDEO_VIEW: &str = "/views/video";
4 const THUMBNAIL_VIEW: &str = "/views/thumbnail";
5
6 /// The thumbnail view of the AMS video clip at `src`.
7 pub fn video_thumbnail_url(src: &str) -> Option<String> {
8 let object = src.strip_suffix(VIDEO_VIEW)?;
9 chatsvc::is_ams_image_url(src).then(|| format!("{object}{THUMBNAIL_VIEW}"))
10 }
11
12 /// The clip behind a thumbnail from [`video_thumbnail_url`].
13 pub fn thumbnail_video_url(url: &str) -> Option<String> {
14 let object = url.strip_suffix(THUMBNAIL_VIEW)?;
15 chatsvc::is_ams_image_url(url).then(|| format!("{object}{VIDEO_VIEW}"))
16 }
17
18 #[cfg(test)]
19 mod tests {
20 use super::*;
21
22 const CLIP: &str = "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/video";
23
24 #[test]
25 fn an_ams_clip_is_shown_by_its_thumbnail_and_played_from_it() {
26 let thumbnail = video_thumbnail_url(CLIP).unwrap();
27 assert_eq!(
28 thumbnail,
29 "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/thumbnail"
30 );
31 assert_eq!(thumbnail_video_url(&thumbnail).as_deref(), Some(CLIP));
32 assert_eq!(
33 video_thumbnail_url("https://x.example/v1/objects/a/views/video"),
34 None
35 );
36 assert_eq!(
37 thumbnail_video_url("https://eu-api.asm.skype.com/v1/objects/a/views/imgo"),
38 None
39 );
40 }
41 }
@@ -0,0 +1,41 @@
1//! Teams video clips: an AMS `<video src=".../views/video">`, shown through the object's thumbnail view.
2
3const VIDEO_VIEW: &str = "/views/video";
4const THUMBNAIL_VIEW: &str = "/views/thumbnail";
5
6/// The thumbnail view of the AMS video clip at `src`.
7pub fn video_thumbnail_url(src: &str) -> Option<String> {
8 let object = src.strip_suffix(VIDEO_VIEW)?;
9 chatsvc::is_ams_image_url(src).then(|| format!("{object}{THUMBNAIL_VIEW}"))
10}
11
12/// The clip behind a thumbnail from [`video_thumbnail_url`].
13pub fn thumbnail_video_url(url: &str) -> Option<String> {
14 let object = url.strip_suffix(THUMBNAIL_VIEW)?;
15 chatsvc::is_ams_image_url(url).then(|| format!("{object}{VIDEO_VIEW}"))
16}
17
18#[cfg(test)]
19mod tests {
20 use super::*;
21
22 const CLIP: &str = "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/video";
23
24 #[test]
25 fn an_ams_clip_is_shown_by_its_thumbnail_and_played_from_it() {
26 let thumbnail = video_thumbnail_url(CLIP).unwrap();
27 assert_eq!(
28 thumbnail,
29 "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/thumbnail"
30 );
31 assert_eq!(thumbnail_video_url(&thumbnail).as_deref(), Some(CLIP));
32 assert_eq!(
33 video_thumbnail_url("https://x.example/v1/objects/a/views/video"),
34 None
35 );
36 assert_eq!(
37 thumbnail_video_url("https://eu-api.asm.skype.com/v1/objects/a/views/imgo"),
38 None
39 );
40 }
41}
crates/core/src/forwarded.rs +31 −0
@@ -359,6 +359,37 @@ mod tests {
359 359 assert!(edit_preserved(&given_up).kept.is_empty());
360 360 }
361 361
362 #[test]
363 fn a_forwarded_video_clip_shows_its_thumbnail_and_plays_the_clip() {
364 const CLIP: &str = "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/video";
365 let mut record = forwarded_record();
366 let content = serde_json::json!({
367 "originalMessageId": "1792149081221",
368 "originalMessageContent": format!(
369 r#"<p><video src="{CLIP}" itemtype="http://schema.skype.com/AMSVideo" width="720" height="1280"></video></p>"#
370 ),
371 });
372 record.attachments_json = serde_json::json!([{
373 "content_type": FORWARDED_CONTENT_TYPE,
374 "id": "1792149081221",
375 "content": content.to_string(),
376 }])
377 .to_string();
378 let found = crate::stored::images(&record);
379 let [clip] = found.as_slice() else {
380 panic!("expected the clip thumbnail, got {found:?}");
381 };
382 assert_eq!((clip.width, clip.height), (Some(720), Some(1280)));
383 assert_eq!(clip.video_url().as_deref(), Some(CLIP));
384 let spans = linked_message_spans_with(&record, &|_| None, &no_forward_header);
385 let [Span::BlockQuote(children)] = spans.as_slice() else {
386 panic!("expected one forward blockquote, got {spans:?}");
387 };
388 assert!(children.contains(&Span::Image {
389 hosted_content_url: clip.url.clone()
390 }));
391 }
392
362 393 #[test]
363 394 fn a_deleted_forward_is_not_forwarded() {
364 395 let mut record = forwarded_record();
@@ -359,6 +359,37 @@ mod tests {
359 assert!(edit_preserved(&given_up).kept.is_empty());
359 assert!(edit_preserved(&given_up).kept.is_empty());
360 }
360 }
361
361
362 #[test]
363 fn a_forwarded_video_clip_shows_its_thumbnail_and_plays_the_clip() {
364 const CLIP: &str = "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/video";
365 let mut record = forwarded_record();
366 let content = serde_json::json!({
367 "originalMessageId": "1792149081221",
368 "originalMessageContent": format!(
369 r#"<p><video src="{CLIP}" itemtype="http://schema.skype.com/AMSVideo" width="720" height="1280"></video></p>"#
370 ),
371 });
372 record.attachments_json = serde_json::json!([{
373 "content_type": FORWARDED_CONTENT_TYPE,
374 "id": "1792149081221",
375 "content": content.to_string(),
376 }])
377 .to_string();
378 let found = crate::stored::images(&record);
379 let [clip] = found.as_slice() else {
380 panic!("expected the clip thumbnail, got {found:?}");
381 };
382 assert_eq!((clip.width, clip.height), (Some(720), Some(1280)));
383 assert_eq!(clip.video_url().as_deref(), Some(CLIP));
384 let spans = linked_message_spans_with(&record, &|_| None, &no_forward_header);
385 let [Span::BlockQuote(children)] = spans.as_slice() else {
386 panic!("expected one forward blockquote, got {spans:?}");
387 };
388 assert!(children.contains(&Span::Image {
389 hosted_content_url: clip.url.clone()
390 }));
391 }
392
362 #[test]
393 #[test]
363 fn a_deleted_forward_is_not_forwarded() {
394 fn a_deleted_forward_is_not_forwarded() {
364 let mut record = forwarded_record();
395 let mut record = forwarded_record();
crates/core/src/images.rs +2 −0
@@ -158,6 +158,8 @@ fn file_extension(content_type: &str, bytes: &[u8]) -> &'static str {
158 158 "image/gif" => "gif",
159 159 "image/webp" => "webp",
160 160 "image/bmp" => "bmp",
161 "video/mp4" => "mp4",
162 "video/quicktime" => "mov",
161 163 _ => "bin",
162 164 }
163 165 }
@@ -158,6 +158,8 @@ fn file_extension(content_type: &str, bytes: &[u8]) -> &'static str {
158 "image/gif" => "gif",
158 "image/gif" => "gif",
159 "image/webp" => "webp",
159 "image/webp" => "webp",
160 "image/bmp" => "bmp",
160 "image/bmp" => "bmp",
161 "video/mp4" => "mp4",
162 "video/quicktime" => "mov",
161 _ => "bin",
163 _ => "bin",
162 }
164 }
163}
165}
crates/core/src/lib.rs +1 −0
@@ -1,6 +1,7 @@
1 1 mod actions;
2 2 mod activity_sync;
3 3 mod adaptive_card;
4 mod ams_video;
4 5 mod announcement;
5 6 mod announcement_post;
6 7 mod avatars;
@@ -1,6 +1,7 @@
1mod actions;
1mod actions;
2mod activity_sync;
2mod activity_sync;
3mod adaptive_card;
3mod adaptive_card;
4mod ams_video;
4mod announcement;
5mod announcement;
5mod announcement_post;
6mod announcement_post;
6mod avatars;
7mod avatars;
crates/core/src/spans.rs +12 −0
@@ -1,5 +1,6 @@
1 1 use scraper::{ElementRef, Html, Node};
2 2
3 use crate::ams_video::video_thumbnail_url;
3 4 use crate::jumbo::without_repeated_skin_tone;
4 5
5 6 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -190,6 +191,7 @@ fn convert_unindented(element: ElementRef<'_>, spans: &mut Vec<Span>) {
190 191 "emoji" => push_emoji(element, spans),
191 192 "customemoji" => push_custom_emoji(element, spans),
192 193 "img" => push_image(element, spans),
194 "video" => push_video(element, spans),
193 195 _ => spans.extend(convert_children(element)),
194 196 }
195 197 }
@@ -458,6 +460,16 @@ fn push_image(element: ElementRef<'_>, spans: &mut Vec<Span>) {
458 460 }
459 461 }
460 462
463 /// A Teams video clip draws as its thumbnail; other videos keep only their fallback content.
464 fn push_video(element: ElementRef<'_>, spans: &mut Vec<Span>) {
465 match element.value().attr("src").and_then(video_thumbnail_url) {
466 Some(thumbnail) => spans.push(Span::Image {
467 hosted_content_url: thumbnail,
468 }),
469 None => spans.extend(convert_children(element)),
470 }
471 }
472
461 473 fn raw_text(element: ElementRef<'_>) -> String {
462 474 element.text().collect()
463 475 }
@@ -1,5 +1,6 @@
1use scraper::{ElementRef, Html, Node};
1use scraper::{ElementRef, Html, Node};
2
2
3use crate::ams_video::video_thumbnail_url;
3use crate::jumbo::without_repeated_skin_tone;
4use crate::jumbo::without_repeated_skin_tone;
4
5
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -190,6 +191,7 @@ fn convert_unindented(element: ElementRef<'_>, spans: &mut Vec<Span>) {
190 "emoji" => push_emoji(element, spans),
191 "emoji" => push_emoji(element, spans),
191 "customemoji" => push_custom_emoji(element, spans),
192 "customemoji" => push_custom_emoji(element, spans),
192 "img" => push_image(element, spans),
193 "img" => push_image(element, spans),
194 "video" => push_video(element, spans),
193 _ => spans.extend(convert_children(element)),
195 _ => spans.extend(convert_children(element)),
194 }
196 }
195}
197}
@@ -458,6 +460,16 @@ fn push_image(element: ElementRef<'_>, spans: &mut Vec<Span>) {
458 }
460 }
459}
461}
460
462
463/// A Teams video clip draws as its thumbnail; other videos keep only their fallback content.
464fn push_video(element: ElementRef<'_>, spans: &mut Vec<Span>) {
465 match element.value().attr("src").and_then(video_thumbnail_url) {
466 Some(thumbnail) => spans.push(Span::Image {
467 hosted_content_url: thumbnail,
468 }),
469 None => spans.extend(convert_children(element)),
470 }
471}
472
461fn raw_text(element: ElementRef<'_>) -> String {
473fn raw_text(element: ElementRef<'_>) -> String {
462 element.text().collect()
474 element.text().collect()
463}
475}
crates/core/src/stored.rs +14 −6
@@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
6 6 use store::MessageRecord;
7 7
8 8 use crate::adaptive_card::{AdaptiveCard, card_content_text};
9 use crate::ams_video::{thumbnail_video_url, video_thumbnail_url};
9 10 use crate::external_image::{external_image_url, is_giphy_url};
10 11 use crate::forwarded::{
11 12 ForwardHeader, ForwardInfo, forwarded_texts, inline_forwards, no_forward_header,
@@ -112,6 +113,11 @@ impl ImageRef {
112 113 &self.url
113 114 }
114 115
116 /// The Teams video clip this image is the thumbnail of.
117 pub fn video_url(&self) -> Option<String> {
118 thumbnail_video_url(&self.url)
119 }
120
115 121 pub fn kind(&self) -> ImageKind {
116 122 match external_image_url(&self.url) {
117 123 None => ImageKind::Inline,
@@ -319,10 +325,12 @@ pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
319 325 let is_emoji = value
320 326 .attr("itemtype")
321 327 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
322 let Some(url) = value
323 .attr("src")
324 .filter(|url| value.name() == "img" && !is_emoji && !url.is_empty())
325 else {
328 let src = value.attr("src").filter(|src| !src.is_empty());
329 let Some(url) = (match value.name() {
330 "img" if !is_emoji => src.map(str::to_owned),
331 "video" => src.and_then(video_thumbnail_url),
332 _ => None,
333 }) else {
326 334 continue;
327 335 };
328 336 if found.iter().any(|image| image.url == url) {
@@ -330,8 +338,8 @@ pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
330 338 }
331 339 let style = value.attr("style").unwrap_or_default();
332 340 found.push(ImageRef {
333 id: image_id(found.len(), url),
334 url: url.to_owned(),
341 id: image_id(found.len(), &url),
342 url,
335 343 width: dimension(value.attr("width"), style, "width"),
336 344 height: dimension(value.attr("height"), style, "height"),
337 345 alt: value
@@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
6use store::MessageRecord;
6use store::MessageRecord;
7
7
8use crate::adaptive_card::{AdaptiveCard, card_content_text};
8use crate::adaptive_card::{AdaptiveCard, card_content_text};
9use crate::ams_video::{thumbnail_video_url, video_thumbnail_url};
9use crate::external_image::{external_image_url, is_giphy_url};
10use crate::external_image::{external_image_url, is_giphy_url};
10use crate::forwarded::{
11use crate::forwarded::{
11 ForwardHeader, ForwardInfo, forwarded_texts, inline_forwards, no_forward_header,
12 ForwardHeader, ForwardInfo, forwarded_texts, inline_forwards, no_forward_header,
@@ -112,6 +113,11 @@ impl ImageRef {
112 &self.url
113 &self.url
113 }
114 }
114
115
116 /// The Teams video clip this image is the thumbnail of.
117 pub fn video_url(&self) -> Option<String> {
118 thumbnail_video_url(&self.url)
119 }
120
115 pub fn kind(&self) -> ImageKind {
121 pub fn kind(&self) -> ImageKind {
116 match external_image_url(&self.url) {
122 match external_image_url(&self.url) {
117 None => ImageKind::Inline,
123 None => ImageKind::Inline,
@@ -319,10 +325,12 @@ pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
319 let is_emoji = value
325 let is_emoji = value
320 .attr("itemtype")
326 .attr("itemtype")
321 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
327 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
322 let Some(url) = value
328 let src = value.attr("src").filter(|src| !src.is_empty());
323 .attr("src")
329 let Some(url) = (match value.name() {
324 .filter(|url| value.name() == "img" && !is_emoji && !url.is_empty())
330 "img" if !is_emoji => src.map(str::to_owned),
325 else {
331 "video" => src.and_then(video_thumbnail_url),
332 _ => None,
333 }) else {
326 continue;
334 continue;
327 };
335 };
328 if found.iter().any(|image| image.url == url) {
336 if found.iter().any(|image| image.url == url) {
@@ -330,8 +338,8 @@ pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
330 }
338 }
331 let style = value.attr("style").unwrap_or_default();
339 let style = value.attr("style").unwrap_or_default();
332 found.push(ImageRef {
340 found.push(ImageRef {
333 id: image_id(found.len(), url),
341 id: image_id(found.len(), &url),
334 url: url.to_owned(),
342 url,
335 width: dimension(value.attr("width"), style, "width"),
343 width: dimension(value.attr("width"), style, "width"),
336 height: dimension(value.attr("height"), style, "height"),
344 height: dimension(value.attr("height"), style, "height"),
337 alt: value
345 alt: value