@@ -9,33 +9,25 @@ use std::collections::HashMap;
99use makepad_widgets:: { makepad_micro_serde:: * , * } ;
1010use matrix_sdk:: ruma:: { OwnedRoomId , RoomId } ;
1111use crate :: {
12- home:: {
12+ avatar_cache :: clear_avatar_cache , home:: {
1313 main_desktop_ui:: MainDesktopUiAction ,
1414 new_message_context_menu:: NewMessageContextMenuWidgetRefExt ,
15- room_screen:: MessageAction ,
16- rooms_list:: RoomsListAction ,
17- } ,
18- join_leave_room_modal:: {
15+ room_screen:: { clear_timeline_states, MessageAction } ,
16+ rooms_list:: { clear_all_invited_rooms, RoomsListAction } ,
17+ } , join_leave_room_modal:: {
1918 JoinLeaveRoomModalAction ,
2019 JoinLeaveRoomModalWidgetRefExt ,
21- } ,
22- login:: login_screen:: LoginAction ,
23- persistence,
24- shared:: callout_tooltip:: {
20+ } , login:: login_screen:: LoginAction , logout:: logout_confirm_modal:: { LogoutAction , LogoutConfirmModalAction , LogoutConfirmModalWidgetRefExt } , persistence, profile:: user_profile_cache:: clear_user_profile_cache, shared:: callout_tooltip:: {
2521 CalloutTooltipOptions ,
2622 CalloutTooltipWidgetRefExt ,
2723 TooltipAction ,
28- } ,
29- sliding_sync:: current_user_id,
30- utils:: {
24+ } , sliding_sync:: current_user_id, utils:: {
3125 room_name_or_id,
3226 OwnedRoomIdRon ,
33- } ,
34- verification:: VerificationAction ,
35- verification_modal:: {
27+ } , verification:: VerificationAction , verification_modal:: {
3628 VerificationModalAction ,
3729 VerificationModalWidgetRefExt ,
38- } ,
30+ }
3931} ;
4032
4133live_design ! {
@@ -48,6 +40,7 @@ live_design! {
4840 use crate :: verification_modal:: VerificationModal ;
4941 use crate :: join_leave_room_modal:: JoinLeaveRoomModal ;
5042 use crate :: login:: login_screen:: LoginScreen ;
43+ use crate :: logout:: logout_confirm_modal:: LogoutConfirmModal ;
5144 use crate :: shared:: popup_list:: * ;
5245 use crate :: home:: new_message_context_menu:: * ;
5346 use crate :: shared:: callout_tooltip:: CalloutTooltip ;
@@ -119,6 +112,13 @@ live_design! {
119112 }
120113 }
121114
115+ // Logout confirmation modal
116+ logout_confirm_modal = <Modal > {
117+ content: {
118+ logout_confirm_modal_inner = <LogoutConfirmModal > { }
119+ }
120+ }
121+
122122 // Tooltips must be shown in front of all other UI elements,
123123 // since they can be shown as a hover atop any other widget.
124124 app_tooltip = <CalloutTooltip > { }
@@ -171,6 +171,7 @@ impl LiveRegister for App {
171171 crate :: home:: live_design ( cx) ;
172172 crate :: profile:: live_design ( cx) ;
173173 crate :: login:: live_design ( cx) ;
174+ crate :: logout:: live_design ( cx) ;
174175 }
175176}
176177
@@ -210,6 +211,38 @@ impl MatchEvent for App {
210211
211212 fn handle_actions ( & mut self , cx : & mut Cx , actions : & Actions ) {
212213 for action in actions {
214+ if let Some ( logout_modal_action) = action. downcast_ref :: < LogoutConfirmModalAction > ( ) {
215+ match logout_modal_action {
216+ LogoutConfirmModalAction :: Open => {
217+ self . ui . logout_confirm_modal ( id ! ( logout_confirm_modal_inner) ) . reset_state ( cx) ;
218+ self . ui . modal ( id ! ( logout_confirm_modal) ) . open ( cx)
219+ } ,
220+ LogoutConfirmModalAction :: Close { was_internal, .. } => {
221+ if * was_internal {
222+ self . ui . modal ( id ! ( logout_confirm_modal) ) . close ( cx) ;
223+ }
224+ } ,
225+ _ => { }
226+ }
227+ }
228+
229+ if let Some ( LogoutAction :: LogoutSuccess ) = action. downcast_ref ( ) {
230+ self . app_state . logged_in = false ;
231+ self . ui . modal ( id ! ( logout_confirm_modal) ) . close ( cx) ;
232+ self . update_login_visibility ( cx) ;
233+ self . ui . redraw ( cx) ;
234+ continue ;
235+ }
236+
237+ if let Some ( LogoutAction :: ClearAppState { on_clear_appstate } ) = action. downcast_ref ( ) {
238+ // Clear user profile cache, invited_rooms timeline states
239+ clear_all_app_state ( cx) ;
240+ // Reset all app state to its default.
241+ self . app_state = Default :: default ( ) ;
242+ on_clear_appstate. notify_one ( ) ;
243+ continue ;
244+ }
245+
213246 if let Some ( LoginAction :: LoginSuccess ) = action. downcast_ref ( ) {
214247 log ! ( "Received LoginAction::LoginSuccess, hiding login view." ) ;
215248 self . app_state . logged_in = true ;
@@ -363,6 +396,15 @@ impl MatchEvent for App {
363396 }
364397}
365398
399+ /// Clears all thread-local UI caches (user profiles, invited rooms, and timeline states).
400+ /// The `cx` parameter ensures that these thread-local caches are cleared on the main UI thread,
401+ fn clear_all_app_state ( cx : & mut Cx ) {
402+ clear_user_profile_cache ( cx) ;
403+ clear_all_invited_rooms ( cx) ;
404+ clear_timeline_states ( cx) ;
405+ clear_avatar_cache ( cx) ;
406+ }
407+
366408impl AppMain for App {
367409 fn handle_event ( & mut self , cx : & mut Cx , event : & Event ) {
368410 // if let Event::WindowGeomChange(geom) = event {
0 commit comments