BlueGit

ict rusty-teams

fix(app): image viewer opens pictures at full size (#85)

Co-authored-by: Fülöp Márk <mark.fulop@blackcell.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

metis MF · pushed by metis

Authored 2026-11-24 · 7 days ago

Hash
7d915a7cb7a17af2095852e9e3a443fc630d02f0
Parent
02e2588c
4 files changed +223 −43
crates/app/src/views/image_viewer.rs +116 −41
@@ -9,6 +9,7 @@ use gpui_kit::prelude::FluentBuilder as _;
9 9 use gpui_kit::*;
10 10
11 11 use image::{Frame, ImageReader};
12 use teams_core::ImageRef;
12 13
13 14 use super::avatar::person_avatar;
14 15 use super::shortcuts::{ZoomIn, ZoomOut, ZoomReset};
@@ -58,6 +59,13 @@ struct RotatedImage {
58 59 render: Arc<RenderImage>,
59 60 }
60 61
62 /// The file last drawn for the picture at `index`, to notice when its full-size view replaces the inline one.
63 struct Shown {
64 index: usize,
65 key: String,
66 size: Option<(u32, u32)>,
67 }
68
61 69 #[derive(Clone, Copy)]
62 70 struct Layout {
63 71 stage: Pair,
@@ -72,11 +80,14 @@ pub struct ImageViewer {
72 80 conversation_id: String,
73 81 conversation_title: String,
74 82 items: Vec<GalleryItem>,
83 /// Per item, the full-resolution view fetched when it is opened; messages carry a compressed one.
84 full_sizes: Vec<Option<ImageRef>>,
75 85 index: usize,
76 86 scale: Option<f32>,
77 87 pan: Pair,
78 88 quarter_turns: u8,
79 89 rotated: Option<RotatedImage>,
90 shown: Option<Shown>,
80 91 entered_fullscreen: bool,
81 92 drag_from: Option<Point<Pixels>>,
82 93 notice: Option<String>,
@@ -209,11 +220,17 @@ impl ImageViewer {
209 220 conversation_id: request.conversation_id,
210 221 conversation_title: request.conversation_title,
211 222 index: request.index.min(request.items.len().saturating_sub(1)),
223 full_sizes: request
224 .items
225 .iter()
226 .map(|item| item.image.full_size())
227 .collect(),
212 228 items: request.items,
213 229 scale: None,
214 230 pan: (0., 0.),
215 231 quarter_turns: 0,
216 232 rotated: None,
233 shown: None,
217 234 entered_fullscreen: false,
218 235 drag_from: None,
219 236 notice: None,
@@ -249,12 +266,14 @@ impl ImageViewer {
249 266 .saturating_sub(1)
250 267 .max((self.index + 1).min(last_index));
251 268 let directory = &self.app.read(cx).directory;
269 let full_size = self.full_sizes.get(self.index).cloned().flatten();
252 270 let missing: Vec<_> = self
253 271 .items
254 272 .get(first..=last)
255 273 .unwrap_or_default()
256 274 .iter()
257 275 .map(|item| item.image.clone())
276 .chain(full_size)
258 277 .filter(|image| directory.image(&image.url).is_none())
259 278 .collect();
260 279 if !missing.is_empty() {
@@ -290,12 +309,61 @@ impl ImageViewer {
290 309 .is_some_and(|item| self.app.read(cx).directory.image_failed(&item.image.url))
291 310 }
292 311
293 fn current_path(&self, cx: &App) -> Option<PathBuf> {
312 /// Cache key of what is drawn for the current picture: its full-size view once downloaded, until then the inline one.
313 fn shown_key(&self, cx: &App) -> Option<&str> {
294 314 let item = self.current()?;
295 let entry = self.app.read(cx).directory.image(&item.image.url)?;
315 let directory = &self.app.read(cx).directory;
316 let full_size = self
317 .full_sizes
318 .get(self.index)
319 .and_then(Option::as_ref)
320 .map(|full| full.url.as_str())
321 .filter(|url| directory.image(url).is_some());
322 Some(full_size.unwrap_or(item.image.url.as_str()))
323 }
324
325 fn current_path(&self, cx: &App) -> Option<PathBuf> {
326 let entry = self.app.read(cx).directory.image(self.shown_key(cx)?)?;
296 327 Some(entry.path.clone())
297 328 }
298 329
330 /// Keeps the zoom and rotation when the full-size view replaces the inline one under them.
331 fn follow_full_size(&mut self, window: &mut Window, cx: &mut Context<Self>) {
332 let Some(key) = self.shown_key(cx).map(str::to_owned) else {
333 self.shown = None;
334 return;
335 };
336 let size = self
337 .app
338 .read(cx)
339 .directory
340 .image(&key)
341 .and_then(|entry| entry.size);
342 let previous = self.shown.replace(Shown {
343 index: self.index,
344 key: key.clone(),
345 size,
346 });
347 let Some(previous) = previous.filter(|shown| shown.index == self.index && shown.key != key)
348 else {
349 return;
350 };
351 let widths = previous
352 .size
353 .zip(size)
354 .map(|(before, after)| (before.0, after.0));
355 if let (Some(scale), Some((before, after))) = (self.scale, widths)
356 && after > 0
357 {
358 self.scale = Some(scale * before as f32 / after as f32);
359 }
360 if self.quarter_turns != 0
361 && let Some(path) = self.current_path(cx)
362 {
363 self.start_rotation(path, window, cx);
364 }
365 }
366
299 367 fn stage_size(window: &Window) -> Pair {
300 368 let viewport = window.viewport_size();
301 369 (
@@ -306,7 +374,7 @@ impl ImageViewer {
306 374
307 375 fn layout(&self, window: &Window, cx: &App) -> Option<Layout> {
308 376 let item = self.current()?;
309 let entry = self.app.read(cx).directory.image(&item.image.url)?;
377 let entry = self.app.read(cx).directory.image(self.shown_key(cx)?)?;
310 378 let stage = Self::stage_size(window);
311 379 let declared = item.image.width.zip(item.image.height);
312 380 let source = entry
@@ -442,47 +510,57 @@ impl ImageViewer {
442 510 }
443 511
444 512 fn rotate(&mut self, window: &mut Window, cx: &mut Context<Self>) {
445 let (Some(path), Some(item)) = (self.current_path(cx), self.current()) else {
513 let Some(path) = self.current_path(cx) else {
446 514 return;
447 515 };
448 let url = item.image.url.clone();
449 516 self.quarter_turns = next_rotation(self.quarter_turns);
450 517 self.scale = None;
451 518 self.pan = (0., 0.);
452 519 self.release_rotated(window);
520 if self.quarter_turns != 0 {
521 self.start_rotation(path, window, cx);
522 }
523 cx.notify();
524 }
525
526 /// Turns the file at `path` by the current rotation; the previous rotated picture stays until this one is ready.
527 fn start_rotation(&mut self, path: PathBuf, window: &mut Window, cx: &mut Context<Self>) {
528 let Some(item) = self.current() else {
529 return;
530 };
531 let url = item.image.url.clone();
453 532 let quarter_turns = self.quarter_turns;
454 if quarter_turns != 0 {
455 cx.spawn_in(window, async move |this, cx| {
456 let rotated = cx
457 .background_spawn(async move { rotated_render(&path, quarter_turns) })
458 .await;
459 this.update_in(cx, |this, window, cx| {
460 let still_current = this.quarter_turns == quarter_turns
461 && this.current().is_some_and(|item| item.image.url == url);
462 if !still_current {
463 return;
533 cx.spawn_in(window, async move |this, cx| {
534 let source = path.clone();
535 let rotated = cx
536 .background_spawn(async move { rotated_render(&source, quarter_turns) })
537 .await;
538 this.update_in(cx, |this, window, cx| {
539 let still_current = this.quarter_turns == quarter_turns
540 && this.current().is_some_and(|item| item.image.url == url)
541 && this.current_path(cx).as_ref() == Some(&path);
542 if !still_current {
543 return;
544 }
545 match rotated {
546 Some(render) => {
547 this.release_rotated(window);
548 this.rotated = Some(RotatedImage {
549 url,
550 quarter_turns,
551 render: Arc::new(render),
552 });
464 553 }
465 match rotated {
466 Some(render) => {
467 this.release_rotated(window);
468 this.rotated = Some(RotatedImage {
469 url,
470 quarter_turns,
471 render: Arc::new(render),
472 });
473 }
474 None => {
475 this.quarter_turns = 0;
476 this.show_notice("Could not rotate", cx);
477 }
554 None => {
555 this.quarter_turns = 0;
556 this.show_notice("Could not rotate", cx);
478 557 }
479 cx.notify();
480 })
481 .ok();
558 }
559 cx.notify();
482 560 })
483 .detach();
484 }
485 cx.notify();
561 .ok();
562 })
563 .detach();
486 564 }
487 565
488 566 fn show_notice(&mut self, text: impl Into<String>, cx: &mut Context<Self>) {
@@ -798,15 +876,11 @@ impl ImageViewer {
798 876 fn picture(&self, layout: Layout, cx: &mut Context<Self>) -> AnyElement {
799 877 let display = display_size(layout.source, layout.scale);
800 878 let origin = image_origin(display, layout.stage, layout.pan);
801 let Some(item) = self.current() else {
879 if self.current().is_none() {
802 880 return div().into_any_element();
803 };
881 }
804 882 let source: Option<ImageSource> = if self.quarter_turns == 0 {
805 self.app
806 .read(cx)
807 .directory
808 .image(&item.image.url)
809 .map(|entry| entry.path.clone().into())
883 self.current_path(cx).map(Into::into)
810 884 } else {
811 885 self.rotated_render()
812 886 .map(|render| ImageSource::Render(render.clone()))
@@ -965,6 +1039,7 @@ fn loading_placeholder() -> AnyElement {
965 1039
966 1040 impl Render for ImageViewer {
967 1041 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
1042 self.follow_full_size(window, cx);
968 1043 let layout = self.layout(window, cx);
969 1044 let stage = Self::stage_size(window);
970 1045 let has_previous = self.index > 0;
@@ -9,6 +9,7 @@ use gpui_kit::prelude::FluentBuilder as _;
9use gpui_kit::*;
9use gpui_kit::*;
10
10
11use image::{Frame, ImageReader};
11use image::{Frame, ImageReader};
12use teams_core::ImageRef;
12
13
13use super::avatar::person_avatar;
14use super::avatar::person_avatar;
14use super::shortcuts::{ZoomIn, ZoomOut, ZoomReset};
15use super::shortcuts::{ZoomIn, ZoomOut, ZoomReset};
@@ -58,6 +59,13 @@ struct RotatedImage {
58 render: Arc<RenderImage>,
59 render: Arc<RenderImage>,
59}
60}
60
61
62/// The file last drawn for the picture at `index`, to notice when its full-size view replaces the inline one.
63struct Shown {
64 index: usize,
65 key: String,
66 size: Option<(u32, u32)>,
67}
68
61#[derive(Clone, Copy)]
69#[derive(Clone, Copy)]
62struct Layout {
70struct Layout {
63 stage: Pair,
71 stage: Pair,
@@ -72,11 +80,14 @@ pub struct ImageViewer {
72 conversation_id: String,
80 conversation_id: String,
73 conversation_title: String,
81 conversation_title: String,
74 items: Vec<GalleryItem>,
82 items: Vec<GalleryItem>,
83 /// Per item, the full-resolution view fetched when it is opened; messages carry a compressed one.
84 full_sizes: Vec<Option<ImageRef>>,
75 index: usize,
85 index: usize,
76 scale: Option<f32>,
86 scale: Option<f32>,
77 pan: Pair,
87 pan: Pair,
78 quarter_turns: u8,
88 quarter_turns: u8,
79 rotated: Option<RotatedImage>,
89 rotated: Option<RotatedImage>,
90 shown: Option<Shown>,
80 entered_fullscreen: bool,
91 entered_fullscreen: bool,
81 drag_from: Option<Point<Pixels>>,
92 drag_from: Option<Point<Pixels>>,
82 notice: Option<String>,
93 notice: Option<String>,
@@ -209,11 +220,17 @@ impl ImageViewer {
209 conversation_id: request.conversation_id,
220 conversation_id: request.conversation_id,
210 conversation_title: request.conversation_title,
221 conversation_title: request.conversation_title,
211 index: request.index.min(request.items.len().saturating_sub(1)),
222 index: request.index.min(request.items.len().saturating_sub(1)),
223 full_sizes: request
224 .items
225 .iter()
226 .map(|item| item.image.full_size())
227 .collect(),
212 items: request.items,
228 items: request.items,
213 scale: None,
229 scale: None,
214 pan: (0., 0.),
230 pan: (0., 0.),
215 quarter_turns: 0,
231 quarter_turns: 0,
216 rotated: None,
232 rotated: None,
233 shown: None,
217 entered_fullscreen: false,
234 entered_fullscreen: false,
218 drag_from: None,
235 drag_from: None,
219 notice: None,
236 notice: None,
@@ -249,12 +266,14 @@ impl ImageViewer {
249 .saturating_sub(1)
266 .saturating_sub(1)
250 .max((self.index + 1).min(last_index));
267 .max((self.index + 1).min(last_index));
251 let directory = &self.app.read(cx).directory;
268 let directory = &self.app.read(cx).directory;
269 let full_size = self.full_sizes.get(self.index).cloned().flatten();
252 let missing: Vec<_> = self
270 let missing: Vec<_> = self
253 .items
271 .items
254 .get(first..=last)
272 .get(first..=last)
255 .unwrap_or_default()
273 .unwrap_or_default()
256 .iter()
274 .iter()
257 .map(|item| item.image.clone())
275 .map(|item| item.image.clone())
276 .chain(full_size)
258 .filter(|image| directory.image(&image.url).is_none())
277 .filter(|image| directory.image(&image.url).is_none())
259 .collect();
278 .collect();
260 if !missing.is_empty() {
279 if !missing.is_empty() {
@@ -290,12 +309,61 @@ impl ImageViewer {
290 .is_some_and(|item| self.app.read(cx).directory.image_failed(&item.image.url))
309 .is_some_and(|item| self.app.read(cx).directory.image_failed(&item.image.url))
291 }
310 }
292
311
293 fn current_path(&self, cx: &App) -> Option<PathBuf> {
312 /// Cache key of what is drawn for the current picture: its full-size view once downloaded, until then the inline one.
313 fn shown_key(&self, cx: &App) -> Option<&str> {
294 let item = self.current()?;
314 let item = self.current()?;
295 let entry = self.app.read(cx).directory.image(&item.image.url)?;
315 let directory = &self.app.read(cx).directory;
316 let full_size = self
317 .full_sizes
318 .get(self.index)
319 .and_then(Option::as_ref)
320 .map(|full| full.url.as_str())
321 .filter(|url| directory.image(url).is_some());
322 Some(full_size.unwrap_or(item.image.url.as_str()))
323 }
324
325 fn current_path(&self, cx: &App) -> Option<PathBuf> {
326 let entry = self.app.read(cx).directory.image(self.shown_key(cx)?)?;
296 Some(entry.path.clone())
327 Some(entry.path.clone())
297 }
328 }
298
329
330 /// Keeps the zoom and rotation when the full-size view replaces the inline one under them.
331 fn follow_full_size(&mut self, window: &mut Window, cx: &mut Context<Self>) {
332 let Some(key) = self.shown_key(cx).map(str::to_owned) else {
333 self.shown = None;
334 return;
335 };
336 let size = self
337 .app
338 .read(cx)
339 .directory
340 .image(&key)
341 .and_then(|entry| entry.size);
342 let previous = self.shown.replace(Shown {
343 index: self.index,
344 key: key.clone(),
345 size,
346 });
347 let Some(previous) = previous.filter(|shown| shown.index == self.index && shown.key != key)
348 else {
349 return;
350 };
351 let widths = previous
352 .size
353 .zip(size)
354 .map(|(before, after)| (before.0, after.0));
355 if let (Some(scale), Some((before, after))) = (self.scale, widths)
356 && after > 0
357 {
358 self.scale = Some(scale * before as f32 / after as f32);
359 }
360 if self.quarter_turns != 0
361 && let Some(path) = self.current_path(cx)
362 {
363 self.start_rotation(path, window, cx);
364 }
365 }
366
299 fn stage_size(window: &Window) -> Pair {
367 fn stage_size(window: &Window) -> Pair {
300 let viewport = window.viewport_size();
368 let viewport = window.viewport_size();
301 (
369 (
@@ -306,7 +374,7 @@ impl ImageViewer {
306
374
307 fn layout(&self, window: &Window, cx: &App) -> Option<Layout> {
375 fn layout(&self, window: &Window, cx: &App) -> Option<Layout> {
308 let item = self.current()?;
376 let item = self.current()?;
309 let entry = self.app.read(cx).directory.image(&item.image.url)?;
377 let entry = self.app.read(cx).directory.image(self.shown_key(cx)?)?;
310 let stage = Self::stage_size(window);
378 let stage = Self::stage_size(window);
311 let declared = item.image.width.zip(item.image.height);
379 let declared = item.image.width.zip(item.image.height);
312 let source = entry
380 let source = entry
@@ -442,47 +510,57 @@ impl ImageViewer {
442 }
510 }
443
511
444 fn rotate(&mut self, window: &mut Window, cx: &mut Context<Self>) {
512 fn rotate(&mut self, window: &mut Window, cx: &mut Context<Self>) {
445 let (Some(path), Some(item)) = (self.current_path(cx), self.current()) else {
513 let Some(path) = self.current_path(cx) else {
446 return;
514 return;
447 };
515 };
448 let url = item.image.url.clone();
449 self.quarter_turns = next_rotation(self.quarter_turns);
516 self.quarter_turns = next_rotation(self.quarter_turns);
450 self.scale = None;
517 self.scale = None;
451 self.pan = (0., 0.);
518 self.pan = (0., 0.);
452 self.release_rotated(window);
519 self.release_rotated(window);
520 if self.quarter_turns != 0 {
521 self.start_rotation(path, window, cx);
522 }
523 cx.notify();
524 }
525
526 /// Turns the file at `path` by the current rotation; the previous rotated picture stays until this one is ready.
527 fn start_rotation(&mut self, path: PathBuf, window: &mut Window, cx: &mut Context<Self>) {
528 let Some(item) = self.current() else {
529 return;
530 };
531 let url = item.image.url.clone();
453 let quarter_turns = self.quarter_turns;
532 let quarter_turns = self.quarter_turns;
454 if quarter_turns != 0 {
533 cx.spawn_in(window, async move |this, cx| {
455 cx.spawn_in(window, async move |this, cx| {
534 let source = path.clone();
456 let rotated = cx
535 let rotated = cx
457 .background_spawn(async move { rotated_render(&path, quarter_turns) })
536 .background_spawn(async move { rotated_render(&source, quarter_turns) })
458 .await;
537 .await;
459 this.update_in(cx, |this, window, cx| {
538 this.update_in(cx, |this, window, cx| {
460 let still_current = this.quarter_turns == quarter_turns
539 let still_current = this.quarter_turns == quarter_turns
461 && this.current().is_some_and(|item| item.image.url == url);
540 && this.current().is_some_and(|item| item.image.url == url)
462 if !still_current {
541 && this.current_path(cx).as_ref() == Some(&path);
463 return;
542 if !still_current {
543 return;
544 }
545 match rotated {
546 Some(render) => {
547 this.release_rotated(window);
548 this.rotated = Some(RotatedImage {
549 url,
550 quarter_turns,
551 render: Arc::new(render),
552 });
464 }
553 }
465 match rotated {
554 None => {
466 Some(render) => {
555 this.quarter_turns = 0;
467 this.release_rotated(window);
556 this.show_notice("Could not rotate", cx);
468 this.rotated = Some(RotatedImage {
469 url,
470 quarter_turns,
471 render: Arc::new(render),
472 });
473 }
474 None => {
475 this.quarter_turns = 0;
476 this.show_notice("Could not rotate", cx);
477 }
478 }
557 }
479 cx.notify();
558 }
480 })
559 cx.notify();
481 .ok();
482 })
560 })
483 .detach();
561 .ok();
484 }
562 })
485 cx.notify();
563 .detach();
486 }
564 }
487
565
488 fn show_notice(&mut self, text: impl Into<String>, cx: &mut Context<Self>) {
566 fn show_notice(&mut self, text: impl Into<String>, cx: &mut Context<Self>) {
@@ -798,15 +876,11 @@ impl ImageViewer {
798 fn picture(&self, layout: Layout, cx: &mut Context<Self>) -> AnyElement {
876 fn picture(&self, layout: Layout, cx: &mut Context<Self>) -> AnyElement {
799 let display = display_size(layout.source, layout.scale);
877 let display = display_size(layout.source, layout.scale);
800 let origin = image_origin(display, layout.stage, layout.pan);
878 let origin = image_origin(display, layout.stage, layout.pan);
801 let Some(item) = self.current() else {
879 if self.current().is_none() {
802 return div().into_any_element();
880 return div().into_any_element();
803 };
881 }
804 let source: Option<ImageSource> = if self.quarter_turns == 0 {
882 let source: Option<ImageSource> = if self.quarter_turns == 0 {
805 self.app
883 self.current_path(cx).map(Into::into)
806 .read(cx)
807 .directory
808 .image(&item.image.url)
809 .map(|entry| entry.path.clone().into())
810 } else {
884 } else {
811 self.rotated_render()
885 self.rotated_render()
812 .map(|render| ImageSource::Render(render.clone()))
886 .map(|render| ImageSource::Render(render.clone()))
@@ -965,6 +1039,7 @@ fn loading_placeholder() -> AnyElement {
965
1039
966impl Render for ImageViewer {
1040impl Render for ImageViewer {
967 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
1041 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
1042 self.follow_full_size(window, cx);
968 let layout = self.layout(window, cx);
1043 let layout = self.layout(window, cx);
969 let stage = Self::stage_size(window);
1044 let stage = Self::stage_size(window);
970 let has_previous = self.index > 0;
1045 let has_previous = self.index > 0;
crates/chatsvc/src/lib.rs +2 −2
@@ -103,8 +103,8 @@ pub use language_settings::{
103 103 parse_language_settings, target_patch,
104 104 };
105 105 pub use links::{
106 LinkImage, LinkInfo, MessageLinks, hosted_content_image_url, is_ams_image_url,
107 is_link_image_url,
106 LinkImage, LinkInfo, MessageLinks, ams_full_size_url, hosted_content_image_url,
107 is_ams_image_url, is_link_image_url,
108 108 };
109 109 pub use mask::mask_conversation_id;
110 110 pub use members::{
@@ -103,8 +103,8 @@ pub use language_settings::{
103 parse_language_settings, target_patch,
103 parse_language_settings, target_patch,
104};
104};
105pub use links::{
105pub use links::{
106 LinkImage, LinkInfo, MessageLinks, hosted_content_image_url, is_ams_image_url,
106 LinkImage, LinkInfo, MessageLinks, ams_full_size_url, hosted_content_image_url,
107 is_link_image_url,
107 is_ams_image_url, is_link_image_url,
108};
108};
109pub use mask::mask_conversation_id;
109pub use mask::mask_conversation_id;
110pub use members::{
110pub use members::{
crates/core/src/stored.rs +36 −0
@@ -113,6 +113,18 @@ impl ImageRef {
113 113 &self.url
114 114 }
115 115
116 /// The same picture at full resolution, for the image viewer; `None` when the message already carries the only view there is.
117 pub fn full_size(&self) -> Option<ImageRef> {
118 let url = chatsvc::ams_full_size_url(&self.url)?;
119 Some(ImageRef {
120 id: format!("{}:full", self.id),
121 url,
122 width: None,
123 height: None,
124 alt: self.alt.clone(),
125 })
126 }
127
116 128 /// The Teams video clip this image is the thumbnail of.
117 129 pub fn video_url(&self) -> Option<String> {
118 130 thumbnail_video_url(&self.url)
@@ -949,6 +961,30 @@ mod tests {
949 961 assert_eq!(parsed[0].created_at, None);
950 962 }
951 963
964 #[test]
965 fn an_ams_picture_has_a_full_size_view_kept_apart_from_the_inline_one() {
966 let inline = ImageRef {
967 id: "0-weu-d1-abc".into(),
968 url: "https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgo".into(),
969 width: Some(640),
970 height: Some(360),
971 alt: Some("image".into()),
972 };
973 let full = inline.full_size().unwrap();
974 assert_eq!(
975 full.key(),
976 "https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgpsh_fullsize_anim"
977 );
978 assert_ne!(full.key(), inline.key());
979 assert_eq!((full.width, full.height), (None, None));
980 assert_eq!(full.full_size(), None);
981 let external = ImageRef {
982 url: "https://example.com/a.png".into(),
983 ..inline
984 };
985 assert_eq!(external.full_size(), None);
986 }
987
952 988 #[test]
953 989 fn images_cover_hosted_contents_and_ams_and_skip_emoji() {
954 990 let html = concat!(
@@ -113,6 +113,18 @@ impl ImageRef {
113 &self.url
113 &self.url
114 }
114 }
115
115
116 /// The same picture at full resolution, for the image viewer; `None` when the message already carries the only view there is.
117 pub fn full_size(&self) -> Option<ImageRef> {
118 let url = chatsvc::ams_full_size_url(&self.url)?;
119 Some(ImageRef {
120 id: format!("{}:full", self.id),
121 url,
122 width: None,
123 height: None,
124 alt: self.alt.clone(),
125 })
126 }
127
116 /// The Teams video clip this image is the thumbnail of.
128 /// The Teams video clip this image is the thumbnail of.
117 pub fn video_url(&self) -> Option<String> {
129 pub fn video_url(&self) -> Option<String> {
118 thumbnail_video_url(&self.url)
130 thumbnail_video_url(&self.url)
@@ -949,6 +961,30 @@ mod tests {
949 assert_eq!(parsed[0].created_at, None);
961 assert_eq!(parsed[0].created_at, None);
950 }
962 }
951
963
964 #[test]
965 fn an_ams_picture_has_a_full_size_view_kept_apart_from_the_inline_one() {
966 let inline = ImageRef {
967 id: "0-weu-d1-abc".into(),
968 url: "https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgo".into(),
969 width: Some(640),
970 height: Some(360),
971 alt: Some("image".into()),
972 };
973 let full = inline.full_size().unwrap();
974 assert_eq!(
975 full.key(),
976 "https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgpsh_fullsize_anim"
977 );
978 assert_ne!(full.key(), inline.key());
979 assert_eq!((full.width, full.height), (None, None));
980 assert_eq!(full.full_size(), None);
981 let external = ImageRef {
982 url: "https://example.com/a.png".into(),
983 ..inline
984 };
985 assert_eq!(external.full_size(), None);
986 }
987
952 #[test]
988 #[test]
953 fn images_cover_hosted_contents_and_ams_and_skip_emoji() {
989 fn images_cover_hosted_contents_and_ams_and_skip_emoji() {
954 let html = concat!(
990 let html = concat!(