@@ -9,7 +9,8 @@ use serde::{Deserialize, Serialize};
99use crate :: {
1010 avatar_cache:: clear_avatar_cache,
1111 home:: {
12- main_desktop_ui:: MainDesktopUiAction , navigation_tab_bar:: { NavigationBarAction , SelectedTab } , new_message_context_menu:: NewMessageContextMenuWidgetRefExt , room_screen:: { InviteAction , MessageAction , clear_timeline_states} , rooms_list:: { RoomsListAction , RoomsListRef , RoomsListUpdate , clear_all_invited_rooms, enqueue_rooms_list_update}
12+ invite_modal:: { InviteModalAction , InviteModalWidgetRefExt } ,
13+ main_desktop_ui:: MainDesktopUiAction , navigation_tab_bar:: { NavigationBarAction , SelectedTab } , new_message_context_menu:: NewMessageContextMenuWidgetRefExt , room_screen:: { InviteAction , MessageAction , clear_timeline_states} , rooms_list:: { RoomsListAction , RoomsListRef , RoomsListUpdate , clear_all_invited_rooms, enqueue_rooms_list_update} , room_context_menu:: RoomContextMenuWidgetRefExt
1314 } ,
1415 join_leave_room_modal:: {
1516 JoinLeaveModalKind , JoinLeaveRoomModalAction , JoinLeaveRoomModalWidgetRefExt
@@ -42,6 +43,8 @@ live_design! {
4243 use crate :: shared:: confirmation_modal:: * ;
4344 use crate :: shared:: popup_list:: * ;
4445 use crate :: home:: new_message_context_menu:: * ;
46+ use crate :: home:: room_context_menu:: * ;
47+ use crate :: home:: invite_modal:: InviteModal ;
4548 use crate :: shared:: callout_tooltip:: CalloutTooltip ;
4649 use crate :: shared:: image_viewer:: ImageViewer ;
4750 use crate :: shared:: file_previewer:: FilePreviewer ;
@@ -117,6 +120,7 @@ live_design! {
117120 // Context menus should be shown in front of other UI elements,
118121 // but behind verification modals.
119122 new_message_context_menu = <NewMessageContextMenu > { }
123+ room_context_menu = <RoomContextMenu > { }
120124
121125 // A modal to confirm sending out an invite to a room.
122126 invite_confirmation_modal = <Modal > {
@@ -132,6 +136,13 @@ live_design! {
132136 }
133137 }
134138
139+ // A modal to invite a user to a room.
140+ invite_modal = <Modal > {
141+ content: {
142+ invite_modal_inner = <InviteModal > { }
143+ }
144+ }
145+
135146 // Show the logout confirmation modal.
136147 logout_confirm_modal = <Modal > {
137148 content: {
@@ -324,6 +335,22 @@ impl MatchEvent for App {
324335 continue ;
325336 }
326337
338+ // Handle an action requesting to open the room context menu.
339+ if let RoomsListAction :: OpenRoomContextMenu { details, pos } = action. as_widget_action ( ) . cast ( ) {
340+ self . ui . callout_tooltip ( ids ! ( app_tooltip) ) . hide ( cx) ;
341+ let room_context_menu = self . ui . room_context_menu ( ids ! ( room_context_menu) ) ;
342+ let expected_dimensions = room_context_menu. show ( cx, details) ;
343+ // Ensure the context menu does not spill over the window's bounds.
344+ let rect = self . ui . window ( ids ! ( main_window) ) . area ( ) . rect ( cx) ;
345+ let pos_x = min ( pos. x , rect. size . x - expected_dimensions. x ) ;
346+ let pos_y = min ( pos. y , rect. size . y - expected_dimensions. y ) ;
347+ room_context_menu. apply_over ( cx, live ! {
348+ main_content = { margin: { left: ( pos_x) , top: ( pos_y) } }
349+ } ) ;
350+ self . ui . redraw ( cx) ;
351+ continue ;
352+ }
353+
327354 if let RoomsListAction :: Selected ( selected_room) = action. as_widget_action ( ) . cast ( ) {
328355 // A room has been selected, update the app state and navigate to the main content view.
329356 let display_name = selected_room. room_name ( ) . to_string ( ) ;
@@ -487,14 +514,28 @@ impl MatchEvent for App {
487514 }
488515
489516 // Handle a request to show the invite confirmation modal.
490- if let Some ( InviteAction :: ShowConfirmationModal ( content_opt) ) = action. downcast_ref ( ) {
517+ if let Some ( InviteAction :: ShowInviteConfirmationModal ( content_opt) ) = action. downcast_ref ( ) {
491518 if let Some ( content) = content_opt. borrow_mut ( ) . take ( ) {
492519 invite_confirmation_modal_inner. show ( cx, content) ;
493520 self . ui . modal ( ids ! ( invite_confirmation_modal) ) . open ( cx) ;
494521 }
495522 continue ;
496523 }
497524
525+ // Handle InviteModalAction to open/close the invite modal.
526+ match action. downcast_ref ( ) {
527+ Some ( InviteModalAction :: Open ( room_name_id) ) => {
528+ self . ui . invite_modal ( ids ! ( invite_modal_inner) ) . show ( cx, room_name_id. clone ( ) ) ;
529+ self . ui . modal ( ids ! ( invite_modal) ) . open ( cx) ;
530+ continue ;
531+ }
532+ Some ( InviteModalAction :: Close ) => {
533+ self . ui . modal ( ids ! ( invite_modal) ) . close ( cx) ;
534+ continue ;
535+ }
536+ _ => { }
537+ }
538+
498539 // // message source modal handling.
499540 // match action.as_widget_action().cast() {
500541 // MessageAction::MessageSourceModalOpen { room_id: _, event_id: _, original_json: _ } => {
0 commit comments