Skip to content

Commit c4a34e2

Browse files
committed
remove set_restore_status
1 parent bdd6ffe commit c4a34e2

File tree

5 files changed

+35
-66
lines changed

5 files changed

+35
-66
lines changed

src/app.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,17 @@ impl AppMain for App {
368368
if let Event::WindowGeomChange(window_geom_change_event) = event {
369369
self.app_state.window_geom = Some(window_geom_change_event.new_geom.clone());
370370
}
371-
if let (Event::WindowClosed(_) | Event::Shutdown, Some(user_id)) = (event, current_user_id()) {
372-
if let Err(e) = save_room_panel(&self.app_state.rooms_panel, &user_id) {
373-
log!("Bug! Failed to save room panel: {}", e);
374-
}
371+
if let Event::WindowClosed(_) | Event::Shutdown = event {
375372
if let Some(window_geom) = &self.app_state.window_geom {
376373
if let Err(e) = save_window_state(window_geom) {
377374
log!("Bug! Failed to save window_state: {}", e);
378375
}
379376
}
377+
if let Some(user_id) = current_user_id(){
378+
if let Err(e) = save_room_panel(&self.app_state.rooms_panel, &user_id) {
379+
log!("Bug! Failed to save room panel: {}", e);
380+
}
381+
}
380382
}
381383
// Forward events to the MatchEvent trait implementation.
382384
self.match_event(cx, event);

src/home/main_desktop_ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub enum RoomsPanelAction {
350350
/// Actions related to saving/restoring the UI state of the dock widget.
351351
#[derive(Clone, DefaultNone, Debug)]
352352
pub enum DockStateAction {
353-
/// Save the dock state from the dock widget into the [`AppState`].
353+
/// Save the room panel state from the dock widget into the [`AppState`].
354354
SaveToAppState,
355355
/// Restores the room panel state from the [`AppState`] to the dock widget.
356356
RestoreFromAppState,

src/home/room_screen.rs

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,15 @@ live_design! {
715715
draw_bg: {
716716
color: (COLOR_SECONDARY)
717717
}
718-
718+
719719
room_screen_wrapper = <View> {
720720
width: Fill, height: Fill,
721721
flow: Overlay,
722722
show_bg: true
723723
draw_bg: {
724724
color: (COLOR_PRIMARY_DARKER)
725725
}
726+
// Used to retreive the list of loaded rooms.
726727
<CachedWidget> {
727728
width:0, height:0,
728729
rooms_list = <RoomsList> {}
@@ -934,10 +935,6 @@ pub struct RoomScreen {
934935
#[rust] room_name: String,
935936
/// The persistent UI-relevant states for the room that this widget is currently displaying.
936937
#[rust] tl_state: Option<TimelineUiState>,
937-
/// The status of this room being restored from previously-saved data in storage.
938-
/// If `Pending` or `AllRoomsLoaded`, this RoomScreen will display a message;
939-
/// otherwise, the regular RoomScreen content (the room timeline) will be shown.
940-
#[rust] restore_status: RoomsPanelRestoreAction,
941938
}
942939
impl Drop for RoomScreen {
943940
fn drop(&mut self) {
@@ -961,6 +958,23 @@ impl Widget for RoomScreen {
961958
// Currently, a Signal event is only used to tell this widget
962959
// that its timeline events have been updated in the background.
963960
if let Event::Signal = event {
961+
if let Some(room_id) = &self.room_id {
962+
if !self.rooms_list(id!(rooms_list)).is_room_loaded(room_id) {
963+
if self.rooms_list(id!(rooms_list)).all_known_rooms_loaded() {
964+
self.view
965+
.label(id!(restore_status_label))
966+
.set_text(cx, &format!(
967+
"Room {} was not found in the homeserver's list of all rooms.",
968+
self.room_name
969+
));
970+
} else {
971+
self.view
972+
.label(id!(restore_status_label))
973+
.set_text(cx, "[Placeholder for Spinner]");
974+
}
975+
return;
976+
}
977+
}
964978
self.process_timeline_updates(cx, &portal_list);
965979

966980
// Ideally we would do this elsewhere on the main thread, because it's not room-specific,
@@ -969,6 +983,7 @@ impl Widget for RoomScreen {
969983
// and wrap it in a `if let Event::Signal` conditional.
970984
user_profile_cache::process_user_profile_updates(cx);
971985
avatar_cache::process_avatar_updates(cx);
986+
972987
}
973988

974989
if let Event::Actions(actions) = event {
@@ -1041,10 +1056,11 @@ impl Widget for RoomScreen {
10411056
match action.downcast_ref() {
10421057
Some(RoomsPanelRestoreAction::Success(room_id)) => {
10431058
if self.room_id.as_ref().is_some_and(|r| r == room_id) {
1044-
self.set_restore_status(cx, RoomsPanelRestoreAction::Success(room_id.clone()));
10451059
// Reset room_id before displaying room.
10461060
self.room_id = None;
10471061
self.set_displayed_room(cx, room_id.clone(), self.room_name.clone());
1062+
self.view
1063+
.label(id!(restore_status_label)).set_text(cx, "");
10481064
return;
10491065
}
10501066
}
@@ -1298,28 +1314,9 @@ impl Widget for RoomScreen {
12981314
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
12991315
if let Some(room_id) = &self.room_id {
13001316
if !self.rooms_list(id!(rooms_list)).is_room_loaded(room_id) {
1301-
if self.rooms_list(id!(rooms_list)).all_known_rooms_loaded() {
1302-
self.view
1303-
.label(id!(restore_status_label))
1304-
.set_text(cx, &format!(
1305-
"Room {} was not found in the homeserver's list of all rooms.",
1306-
self.room_name
1307-
));
1308-
return self.view.draw_walk(cx, scope, walk);
1309-
} else {
1310-
self.view
1311-
.label(id!(restore_status_label))
1312-
.set_text(cx, "[Placeholder for Spinner]");
1313-
return self.view.draw_walk(cx, scope, walk);
1314-
}
1317+
return self.view.draw_walk(cx, scope, walk);
13151318
}
13161319
}
1317-
// if matches!(
1318-
// &self.restore_status,
1319-
// RoomsPanelRestoreAction::Pending(_)) || self.rooms_list(id!(rooms_list)).all_known_rooms_loaded()
1320-
// {
1321-
// return self.view.draw_walk(cx, scope, walk);
1322-
// }
13231320

13241321
if self.tl_state.is_none() {
13251322
// Tl_state may not be ready after dock loading.
@@ -2299,11 +2296,6 @@ impl RoomScreen {
22992296
fn show_timeline(&mut self, cx: &mut Cx) {
23002297
let room_id = self.room_id.clone()
23012298
.expect("BUG: Timeline::show_timeline(): no room_id was set.");
2302-
// just an optional sanity check
2303-
assert!(self.tl_state.is_none(),
2304-
"BUG: tried to show_timeline() into a timeline with existing state. \
2305-
Did you forget to save the timeline state back to the global map of states?",
2306-
);
23072299

23082300
// Obtain the current user's power levels for this room.
23092301
submit_async_request(MatrixRequest::GetRoomPowerLevels { room_id: room_id.clone() });
@@ -2313,7 +2305,6 @@ impl RoomScreen {
23132305
(existing, false)
23142306
} else {
23152307
let Some((update_sender, update_receiver, request_sender)) = take_timeline_endpoints(&room_id) else {
2316-
self.set_restore_status(cx, RoomsPanelRestoreAction::Pending(room_id.clone()));
23172308
return;
23182309
};
23192310
let new_tl_state = TimelineUiState {
@@ -2502,25 +2493,6 @@ impl RoomScreen {
25022493
self.show_timeline(cx);
25032494
}
25042495

2505-
/// This sets the RoomScreen widget to display a text label in place of the timeline.
2506-
pub fn set_restore_status(&mut self, cx: &mut Cx, status: RoomsPanelRestoreAction) {
2507-
match &status {
2508-
RoomsPanelRestoreAction::Pending(room_id) => {
2509-
// Set this RoomScreen's room_id such that it can handle a `RoomsPanelRestoreAction::Success` action.
2510-
self.room_id = Some(room_id.clone());
2511-
self.view
2512-
.label(id!(restore_status_label))
2513-
.set_text(cx, "[Placeholder for Spinner]");
2514-
self.restore_status = status;
2515-
}
2516-
_ => {
2517-
self.view.label(id!(restore_status_label)).set_text(cx, "");
2518-
self.restore_status = status;
2519-
}
2520-
}
2521-
self.redraw(cx);
2522-
}
2523-
25242496
/// Sends read receipts based on the current scroll position of the timeline.
25252497
fn send_user_read_receipts_based_on_scroll_pos(
25262498
&mut self,
@@ -2631,13 +2603,6 @@ impl RoomScreenRef {
26312603
let Some(mut inner) = self.borrow_mut() else { return };
26322604
inner.set_displayed_room(cx, room_id, room_name);
26332605
}
2634-
2635-
/// See [`RoomScreen::set_restore_status()`].
2636-
pub fn set_restore_status(&self, cx: &mut Cx, status: RoomsPanelRestoreAction) {
2637-
if let Some(mut inner) = self.borrow_mut() {
2638-
inner.set_restore_status(cx, status);
2639-
}
2640-
}
26412606
}
26422607

26432608
/// Actions for the room screen's tooltip.

src/home/rooms_list.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use imbl::HashSet;
44
use makepad_widgets::*;
55
use matrix_sdk::ruma::{events::tag::{TagName, Tags}, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId, OwnedRoomId};
66
use bitflags::bitflags;
7-
use crate::{app::{AppState, RoomsPanelRestoreAction}, shared::jump_to_bottom_button::UnreadMessageCount, sliding_sync::{submit_async_request, MatrixRequest, PaginationDirection}};
7+
use crate::{app::AppState, shared::jump_to_bottom_button::UnreadMessageCount, sliding_sync::{submit_async_request, MatrixRequest, PaginationDirection}};
88

99
use super::{room_preview::RoomPreviewAction, rooms_sidebar::RoomsViewAction};
1010

@@ -488,7 +488,8 @@ impl Widget for RoomsList {
488488
}
489489
}
490490
self.update_status_rooms_count();
491-
cx.action(RoomsPanelRestoreAction::Success(room_id));
491+
// Signal the UI to update the RoomScreen
492+
SignalToUI::set_ui_signal();
492493
}
493494
RoomsListUpdate::UpdateRoomAvatar { room_id, avatar } => {
494495
if let Some(room) = self.all_rooms.get_mut(&room_id) {

src/sliding_sync.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ async fn add_new_room(room: &room_list_service::Room, room_list_service: &RoomLi
16931693
ALL_ROOM_INFO.lock().unwrap().insert(
16941694
room_id.clone(),
16951695
RoomInfo {
1696-
room_id,
1696+
room_id: room_id.clone(),
16971697
timeline,
16981698
timeline_singleton_endpoints: Some((timeline_update_receiver, request_sender)),
16991699
timeline_update_sender,
@@ -1702,6 +1702,7 @@ async fn add_new_room(room: &room_list_service::Room, room_list_service: &RoomLi
17021702
replaces_tombstoned_room: tombstoned_room_replaced_by_this_room,
17031703
},
17041704
);
1705+
Cx::post_action(RoomsPanelRestoreAction::Success(room_id));
17051706
Ok(())
17061707
}
17071708

0 commit comments

Comments
 (0)