[fractal/fractal-next] message-media: Fallback to file if couldn't get thumbnail



commit 99abda19b6d9a03e00afe72c4c53a0b76969ddc1
Author: Kévin Commaille <zecakeh tedomum fr>
Date:   Mon Dec 13 17:53:57 2021 +0100

    message-media: Fallback to file if couldn't get thumbnail

 .../content/room_history/message_row/media.rs      | 24 ++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/src/session/content/room_history/message_row/media.rs 
b/src/session/content/room_history/message_row/media.rs
index 41532c1f..75e6a0af 100644
--- a/src/session/content/room_history/message_row/media.rs
+++ b/src/session/content/room_history/message_row/media.rs
@@ -367,17 +367,17 @@ impl MessageMedia {
 
     fn build<C>(&self, content: C, session: &Session)
     where
-        C: MediaEventContent + Send + Sync + 'static,
+        C: MediaEventContent + Send + Sync + Clone + 'static,
     {
         self.set_state(MediaState::Loading);
 
         let media_type = self.media_type();
         let client = session.client();
-        let handle = if media_type != MediaType::Video && content.thumbnail().is_some() {
-            spawn_tokio!(async move {
+        let handle = spawn_tokio!(async move {
+            let thumbnail = if media_type != MediaType::Video && content.thumbnail().is_some() {
                 client
                     .get_thumbnail(
-                        content,
+                        content.clone(),
                         MediaThumbnailSize {
                             method: Method::Scale,
                             width: uint!(320),
@@ -386,10 +386,18 @@ impl MessageMedia {
                         true,
                     )
                     .await
-            })
-        } else {
-            spawn_tokio!(async move { client.get_file(content, true,).await })
-        };
+                    .ok()
+                    .flatten()
+            } else {
+                None
+            };
+
+            if let Some(data) = thumbnail {
+                Ok(Some(data))
+            } else {
+                client.get_file(content, true).await
+            }
+        });
 
         spawn!(
             glib::PRIORITY_LOW,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]