1515//! * A "cannot-send-message" notice, which is shown if the user cannot send messages to the room.
1616//!
1717
18- use makepad_widgets:: * ;
19- use matrix_sdk:: { TransmissionProgress , room:: reply:: { EnforceThread , Reply } } ;
18+ use makepad_widgets:: { file_dialogs :: FileDialog , * } ;
19+ use matrix_sdk:: room:: reply:: { EnforceThread , Reply } ;
2020use matrix_sdk_ui:: timeline:: { EmbeddedEvent , EventTimelineItem , TimelineEventItemId } ;
2121use ruma:: { events:: room:: message:: { LocationMessageEventContent , MessageType , RoomMessageEventContent } , OwnedRoomId } ;
2222use crate :: { home:: { editing_pane:: { EditingPaneState , EditingPaneWidgetExt } , location_preview:: LocationPreviewWidgetExt , room_screen:: { MessageAction , RoomScreenProps , populate_preview_of_timeline_item} , tombstone_footer:: { SuccessorRoomDetails , TombstoneFooterWidgetExt } } , location:: init_location_subscriber, shared:: { avatar:: AvatarWidgetRefExt , html_or_plaintext:: HtmlOrPlaintextWidgetRefExt , mentionable_text_input:: MentionableTextInputWidgetExt , popup_list:: { PopupItem , PopupKind , enqueue_popup_notification} , progress:: MyProgressWidgetExt , styles:: * } , sliding_sync:: { MatrixRequest , UserPowerLevels , submit_async_request} , utils} ;
@@ -248,36 +248,20 @@ impl Widget for RoomInputBar {
248248 }
249249 _ => { }
250250 }
251- if let Event :: FileDialogResult { live_id, path } = event {
251+ if let Event :: FileDialogResult { live_id : _ , path } = event {
252252 if let Some ( path) = path {
253253 log ! ( "File selected for upload: {}" , path. display( ) ) ;
254254
255- // Create a shared observable for progress updates
256- let progress_shared =
257- eyeball:: SharedObservable :: new ( TransmissionProgress { total : 100 , current : 0 } ) ;
258- self . upload_progress_subscriber = Some ( progress_shared. subscribe ( ) ) ;
255+ // Prepare the reply context if replying to a message
256+ let replied_to_event_id = self . replying_to . as_ref ( )
257+ . and_then ( |( event_tl_item, _emb) | event_tl_item. event_id ( ) . map ( ToOwned :: to_owned) ) ;
259258
260- // Show the progress bar
261- self . view . view ( ids ! ( upload_progress_view) ) . set_visible ( cx, true ) ;
262- self . redraw ( cx) ;
263-
264- submit_async_request ( MatrixRequest :: Upload {
265- room_id : room_screen_props. room_name_id . room_id ( ) . clone ( ) ,
259+ // Post action to show the file previewer modal
260+ cx. action ( crate :: shared:: file_previewer:: FilePreviewerAction :: Show {
266261 file_path : path. clone ( ) ,
267- replied_to : self . replying_to . take ( ) . and_then ( |( event_tl_item, _emb) |
268- event_tl_item. event_id ( ) . map ( |event_id|
269- Reply {
270- event_id : event_id. to_owned ( ) ,
271- enforce_thread : EnforceThread :: MaybeThreaded ,
272- }
273- )
274- ) ,
275- #[ cfg( feature = "tsp" ) ]
276- sign_with_tsp : self . is_tsp_signing_enabled ( cx) ,
277- progress_sender : Some ( progress_shared) ,
262+ room_id : room_screen_props. room_name_id . room_id ( ) . clone ( ) ,
263+ replied_to_event_id,
278264 } ) ;
279-
280- self . clear_replying_to ( cx) ;
281265 }
282266 }
283267
@@ -291,6 +275,7 @@ impl Widget for RoomInputBar {
291275 self . view . view ( ids ! ( upload_progress_view) ) . set_visible ( cx, false ) ;
292276 self . upload_progress_subscriber = None ;
293277 } else {
278+ self . view . view ( ids ! ( upload_progress_view) ) . set_visible ( cx, true ) ;
294279 // Update progress bar width as a percentage
295280 let progress_val = if progress. total > 0 {
296281 ( progress. current as f64 / progress. total as f64 ) * 100.0
@@ -353,7 +338,7 @@ impl RoomInputBar {
353338 // Handle the image upload button being clicked.
354339 if self . button ( ids ! ( image_upload_button) ) . clicked ( actions) {
355340 log ! ( "Image upload button clicked; opening file dialog..." ) ;
356- cx. open_system_openfile_dialog ( ) ;
341+ cx. open_system_openfile_dialog ( live_id ! ( upload ) , FileDialog :: new ( ) ) ;
357342 }
358343
359344 // Handle the send location button being clicked.
@@ -449,6 +434,39 @@ impl RoomInputBar {
449434 if self . view . editing_pane ( ids ! ( editing_pane) ) . was_hidden ( actions) {
450435 self . on_editing_pane_hidden ( cx) ;
451436 }
437+
438+ // Handle file upload action
439+ for action in actions {
440+ match action. downcast_ref ( ) {
441+ Some ( crate :: shared:: file_previewer:: FilePreviewerAction :: Upload { room_id, file_path, replied_to_event_id } ) => {
442+ // Reconstruct the Reply from the event_id
443+ let replied_to = replied_to_event_id. as_ref ( ) . map ( |event_id| Reply {
444+ event_id : event_id. clone ( ) ,
445+ enforce_thread : EnforceThread :: MaybeThreaded ,
446+ } ) ;
447+
448+ // Create a SharedObservable for tracking upload progress
449+ use matrix_sdk:: TransmissionProgress ;
450+ let progress_observable = eyeball:: SharedObservable :: new ( TransmissionProgress :: default ( ) ) ;
451+ let progress_subscriber = progress_observable. subscribe ( ) ;
452+
453+ // Store the subscriber so we can track progress updates
454+ self . upload_progress_subscriber = Some ( progress_subscriber) ;
455+ progress_observable. set ( TransmissionProgress { current : 0 , total : 100 } ) ;
456+ println ! ( "FilePreviewerAction::Upload" ) ;
457+ submit_async_request ( MatrixRequest :: Upload {
458+ room_id : room_id. clone ( ) ,
459+ file_path : file_path. clone ( ) ,
460+ replied_to,
461+ #[ cfg( feature = "tsp" ) ]
462+ sign_with_tsp : false ,
463+ progress_sender : Some ( progress_observable) ,
464+ } ) ;
465+ }
466+ _ => { }
467+ }
468+ }
469+
452470 }
453471
454472 /// Shows a preview of the given event that the user is currently replying to
0 commit comments