@@ -12,9 +12,8 @@ use matrix_sdk::{
12
12
message:: {
13
13
AudioMessageEventContent , CustomEventContent , EmoteMessageEventContent , FileMessageEventContent , FormattedBody , ImageMessageEventContent , KeyVerificationRequestEventContent , LocationMessageEventContent , MessageFormat , MessageType , NoticeMessageEventContent , RoomMessageEventContent , ServerNoticeMessageEventContent , TextMessageEventContent , VideoMessageEventContent
14
14
} , ImageInfo , MediaSource
15
- } , sticker:: StickerEventContent } , matrix_uri:: MatrixId , uint, EventId , MatrixToUri , MatrixUri , MilliSecondsSinceUnixEpoch , OwnedEventId , OwnedRoomId , UserId
16
- } ,
17
- OwnedServerName ,
15
+ } , sticker:: StickerEventContent } , matrix_uri:: MatrixId , uint, EventId , MatrixToUri , MatrixUri , MilliSecondsSinceUnixEpoch , OwnedEventId , OwnedMxcUri , OwnedRoomId , UserId
16
+ } , OwnedServerName
18
17
} ;
19
18
use matrix_sdk_ui:: timeline:: {
20
19
self , EventTimelineItem , InReplyToDetails , MemberProfileChange , Profile , ReactionsByKeyBySender , RepliedToInfo , RoomMembershipChange , TimelineDetails , TimelineItem , TimelineItemContent , TimelineItemKind , VirtualTimelineItem
@@ -1155,7 +1154,7 @@ impl Widget for RoomScreen {
1155
1154
content: { margin: { left: ( coords. x) , top: ( coords. y) } }
1156
1155
} ,
1157
1156
) ;
1158
-
1157
+
1159
1158
if let Some ( message_widget_uid) = action. as_widget_action ( ) . map ( |a| a. widget_uid ) {
1160
1159
message_action_bar_popup. open ( cx) ;
1161
1160
message_action_bar. initialize_with_data ( cx, widget_uid, message_widget_uid, item_id) ;
@@ -1546,7 +1545,7 @@ impl RoomScreen {
1546
1545
submit_async_request ( MatrixRequest :: GetNumberUnreadMessages { room_id : room_id. clone ( ) } ) ;
1547
1546
}
1548
1547
}
1549
-
1548
+
1550
1549
if clear_cache {
1551
1550
tl. content_drawn_since_last_update . clear ( ) ;
1552
1551
tl. profile_drawn_since_last_update . clear ( ) ;
@@ -2148,7 +2147,7 @@ impl RoomScreen {
2148
2147
event_id : last_event_id. to_owned ( ) ,
2149
2148
} ) ;
2150
2149
}
2151
-
2150
+
2152
2151
}
2153
2152
}
2154
2153
}
@@ -3065,63 +3064,85 @@ fn populate_image_message_content(
3065
3064
)
3066
3065
. unwrap_or_default ( ) ;
3067
3066
3068
- // If we have a known mimetype and it's not an image (e.g., an animated)
3069
- // then show a message about it being unsupported.
3067
+ // If we have a known mimetype and it's not a static image,
3068
+ // then show a message about it being unsupported (e.g., for animated gifs) .
3070
3069
if let Some ( mime) = mimetype. as_ref ( ) {
3071
3070
if ImageFormat :: from_mimetype ( mime) . is_none ( ) {
3072
3071
text_or_image_ref. show_text ( format ! (
3073
3072
"{body}\n \n Images/Stickers of type {mime:?} are not yet supported." ,
3074
3073
) ) ;
3075
- return true ;
3074
+ return true ; // consider this as fully drawn
3076
3075
}
3077
3076
}
3078
3077
3079
- match image_info_source. map ( |( _, source) | source) {
3080
- Some ( MediaSource :: Plain ( mxc_uri) ) => {
3081
- // now that we've obtained the image URI and its metadata, try to fetch the image.
3082
- match media_cache. try_get_media_or_fetch ( mxc_uri. clone ( ) , None ) {
3083
- MediaCacheEntry :: Loaded ( data) => {
3084
- let show_image_result = text_or_image_ref. show_image ( |img| {
3085
- utils:: load_png_or_jpg ( & img, cx, & data)
3086
- . map ( |( ) | img. size_in_pixels ( cx) . unwrap ( ) )
3087
- } ) ;
3088
- if let Err ( e) = show_image_result {
3089
- let err_str = format ! ( "{body}\n \n Failed to display image: {e:?}" ) ;
3090
- error ! ( "{err_str}" ) ;
3091
- text_or_image_ref. show_text ( & err_str) ;
3092
- }
3078
+ let mut fully_drawn = false ;
3093
3079
3094
- // We're done drawing the image message content, so mark it as fully drawn.
3095
- true
3096
- }
3097
- MediaCacheEntry :: Requested => {
3098
- text_or_image_ref. show_text ( format ! ( "{body}\n \n Fetching image from {:?}" , mxc_uri) ) ;
3099
- // Do not consider this image as being fully drawn, as we're still fetching it.
3100
- false
3101
- }
3102
- MediaCacheEntry :: Failed => {
3103
- text_or_image_ref
3104
- . show_text ( format ! ( "{body}\n \n Failed to fetch image from {:?}" , mxc_uri) ) ;
3105
- // For now, we consider this as being "complete". In the future, we could support
3106
- // retrying to fetch the image on a user click/tap.
3107
- true
3080
+ // A closure that fetches and shows the image from the given `mxc_uri`,
3081
+ // marking it as fully drawn if the image was available.
3082
+ let mut fetch_and_show_image_uri = |mxc_uri : OwnedMxcUri |
3083
+ match media_cache. try_get_media_or_fetch ( mxc_uri. clone ( ) , None ) {
3084
+ MediaCacheEntry :: Loaded ( data) => {
3085
+ let show_image_result = text_or_image_ref. show_image ( |img| {
3086
+ utils:: load_png_or_jpg ( & img, cx, & data)
3087
+ . map ( |( ) | img. size_in_pixels ( cx) . unwrap_or_default ( ) )
3088
+ } ) ;
3089
+ if let Err ( e) = show_image_result {
3090
+ let err_str = format ! ( "{body}\n \n Failed to display image: {e:?}" ) ;
3091
+ error ! ( "{err_str}" ) ;
3092
+ text_or_image_ref. show_text ( & err_str) ;
3108
3093
}
3094
+
3095
+ // We're done drawing the image, so mark it as fully drawn.
3096
+ fully_drawn = true ;
3097
+ }
3098
+ MediaCacheEntry :: Requested => {
3099
+ text_or_image_ref. show_text ( format ! ( "{body}\n \n Fetching image from {:?}" , mxc_uri) ) ;
3100
+ // Do not consider this thumbnail as being fully drawn, as we're still fetching it.
3101
+ fully_drawn = false ;
3102
+ }
3103
+ MediaCacheEntry :: Failed => {
3104
+ text_or_image_ref
3105
+ . show_text ( format ! ( "{body}\n \n Failed to fetch image from {:?}" , mxc_uri) ) ;
3106
+ // For now, we consider this as being "complete". In the future, we could support
3107
+ // retrying to fetch thumbnail of the image on a user click/tap.
3108
+ fully_drawn = true ;
3109
+ }
3110
+ } ;
3111
+
3112
+ let mut fetch_and_show_media_source = |media_source : MediaSource | {
3113
+ match media_source {
3114
+ MediaSource :: Encrypted ( encrypted) => {
3115
+ // We consider this as "fully drawn" since we don't yet support encryption.
3116
+ text_or_image_ref. show_text ( format ! (
3117
+ "{body}\n \n [TODO] fetch encrypted image at {:?}" ,
3118
+ encrypted. url
3119
+ ) ) ;
3120
+ } ,
3121
+ MediaSource :: Plain ( mxc_uri) => {
3122
+ fetch_and_show_image_uri ( mxc_uri)
3109
3123
}
3110
3124
}
3111
- Some ( MediaSource :: Encrypted ( encrypted) ) => {
3112
- text_or_image_ref. show_text ( format ! (
3113
- "{body}\n \n [TODO] fetch encrypted image at {:?}" ,
3114
- encrypted. url
3115
- ) ) ;
3116
- // We consider this as "fully drawn" since we don't yet support encryption.
3117
- true
3118
- }
3125
+ } ;
3126
+
3127
+ match image_info_source {
3128
+ Some ( ( None , media_source) ) => {
3129
+ // We fetch the original (full-size) media if it does not have a thumbnail.
3130
+ fetch_and_show_media_source ( media_source) ;
3131
+ } ,
3132
+ Some ( ( Some ( image_info) , media_source) ) => {
3133
+ if let Some ( thumbnail_source) = image_info. thumbnail_source {
3134
+ fetch_and_show_media_source ( thumbnail_source) ;
3135
+ } else {
3136
+ fetch_and_show_media_source ( media_source) ;
3137
+ }
3138
+ } ,
3119
3139
None => {
3120
3140
text_or_image_ref. show_text ( "{body}\n \n Image message had no source URL." ) ;
3121
- true
3141
+ fully_drawn = true ;
3122
3142
}
3123
-
3124
3143
}
3144
+
3145
+ fully_drawn
3125
3146
}
3126
3147
3127
3148
0 commit comments