Skip to content

Commit fc29024

Browse files
committed
remove set_restore_status
1 parent c6befdf commit fc29024

File tree

5 files changed

+73
-88
lines changed

5 files changed

+73
-88
lines changed

src/app.rs

Lines changed: 6 additions & 15 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);
@@ -434,14 +436,6 @@ impl App {
434436
#[derive(Default, Debug)]
435437
pub struct AppState {
436438
pub rooms_panel: RoomsPanelState,
437-
/// Whether all known rooms have been loaded from the server.
438-
///
439-
/// This is necessary for two reasons:
440-
/// 1. If a RoomScreen is restored *after* all known rooms have been loaded,
441-
/// it should show the room's timeline and hide its `Pending` message.
442-
/// 2. When changing from the desktop to mobile view, we want to ensure that
443-
/// all newly-restored rooms that were loaded in the background are properly displayed.
444-
pub all_known_rooms_loaded: bool,
445439
/// Whether a user is currently logged in.
446440
pub logged_in: bool,
447441
/// The current window geometry.
@@ -505,9 +499,6 @@ pub enum RoomsPanelRestoreAction {
505499
/// and is known to our client.
506500
/// The RoomScreen for this room can now fully display the room's timeline.
507501
Success(OwnedRoomId),
508-
/// All known rooms have been received by the homeserver.
509-
/// Any `Pending` rooms (still waiting to be loaded) should display errors.
510-
AllRoomsLoaded,
511502
/// The previously-saved of the window geometry state.
512503
/// This will be handled by the top-level App to restore window's size and position.
513504
RestoreWindow(WindowGeomState),

src/home/main_desktop_ui.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use makepad_widgets::*;
22
use std::collections::HashMap;
33

4-
use crate::app::{AppState, RoomsPanelRestoreAction, SelectedRoom};
4+
use crate::app::{AppState, SelectedRoom};
55

66
use super::room_screen::RoomScreenWidgetRefExt;
77
live_design! {
@@ -120,10 +120,6 @@ impl Widget for MainDesktopUI {
120120
if let Some(ref selected_room) = &app_state.rooms_panel.selected_room {
121121
self.focus_or_create_tab(cx, selected_room.clone());
122122
}
123-
// Re-emit the action to notify recently-created RoomScreens that all rooms are loaded.
124-
if app_state.all_known_rooms_loaded {
125-
Cx::post_action(RoomsPanelRestoreAction::AllRoomsLoaded);
126-
}
127123
}
128124
Some(DockStateAction::SaveToAppState) => {
129125
let app_state = scope.data.get_mut::<AppState>().unwrap();
@@ -354,7 +350,7 @@ pub enum RoomsPanelAction {
354350
/// Actions related to saving/restoring the UI state of the dock widget.
355351
#[derive(Clone, DefaultNone, Debug)]
356352
pub enum DockStateAction {
357-
/// Save the dock state from the dock widget into the [`AppState`].
353+
/// Save the room panel state from the dock widget into the [`AppState`].
358354
SaveToAppState,
359355
/// Restores the room panel state from the [`AppState`] to the dock widget.
360356
RestoreFromAppState,

src/home/room_screen.rs

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::shared::mentionable_text_input::MentionableTextInputWidgetRefExt;
3434

3535
use rangemap::RangeSet;
3636

37-
use super::{editing_pane::{EditingPaneAction, EditingPaneWidgetExt}, event_reaction_list::ReactionData, loading_pane::LoadingPaneRef, new_message_context_menu::{MessageAbilities, MessageDetails}, room_read_receipt::{self, populate_read_receipts, MAX_VISIBLE_AVATARS_IN_READ_RECEIPT}};
37+
use super::{editing_pane::{EditingPaneAction, EditingPaneWidgetExt}, event_reaction_list::ReactionData, loading_pane::LoadingPaneRef, new_message_context_menu::{MessageAbilities, MessageDetails}, room_read_receipt::{self, populate_read_receipts, MAX_VISIBLE_AVATARS_IN_READ_RECEIPT}, rooms_list::RoomsListWidgetExt};
3838

3939
const GEO_URI_SCHEME: &str = "geo:";
4040

@@ -63,6 +63,7 @@ live_design! {
6363
use crate::home::event_reaction_list::*;
6464
use crate::home::editing_pane::*;
6565
use crate::room::room_input_bar::*;
66+
use crate::rooms_list::*;
6667

6768
IMG_DEFAULT_AVATAR = dep("crate://self/resources/img/default_avatar.png")
6869

@@ -722,7 +723,11 @@ live_design! {
722723
draw_bg: {
723724
color: (COLOR_PRIMARY_DARKER)
724725
}
725-
726+
// Used to retreive the list of loaded rooms.
727+
<CachedWidget> {
728+
width:0, height:0,
729+
rooms_list = <RoomsList> {}
730+
}
726731
restore_status_label = <Label> {
727732
align: {x: 0.0, y: 0.5},
728733
padding: {left: 5.0, right: 0.0}
@@ -930,10 +935,6 @@ pub struct RoomScreen {
930935
#[rust] room_name: String,
931936
/// The persistent UI-relevant states for the room that this widget is currently displaying.
932937
#[rust] tl_state: Option<TimelineUiState>,
933-
/// The status of this room being restored from previously-saved data in storage.
934-
/// If `Pending` or `AllRoomsLoaded`, this RoomScreen will display a message;
935-
/// otherwise, the regular RoomScreen content (the room timeline) will be shown.
936-
#[rust] restore_status: RoomsPanelRestoreAction,
937938
}
938939
impl Drop for RoomScreen {
939940
fn drop(&mut self) {
@@ -957,6 +958,23 @@ impl Widget for RoomScreen {
957958
// Currently, a Signal event is only used to tell this widget
958959
// that its timeline events have been updated in the background.
959960
if let Event::Signal = event {
961+
if let Some(room_id) = &self.room_id {
962+
let rooms_list = self.rooms_list(id!(rooms_list));
963+
if !rooms_list.is_room_loaded(room_id) {
964+
let status_text = if rooms_list.all_known_rooms_loaded() {
965+
format!(
966+
"Room {} was not found in the homeserver's list of all rooms.",
967+
self.room_name
968+
)
969+
} else {
970+
"[Placeholder for Spinner]".to_string()
971+
};
972+
self.view
973+
.label(id!(restore_status_label))
974+
.set_text(cx, &status_text);
975+
return;
976+
}
977+
}
960978
self.process_timeline_updates(cx, &portal_list);
961979

962980
// Ideally we would do this elsewhere on the main thread, because it's not room-specific,
@@ -965,6 +983,7 @@ impl Widget for RoomScreen {
965983
// and wrap it in a `if let Event::Signal` conditional.
966984
user_profile_cache::process_user_profile_updates(cx);
967985
avatar_cache::process_avatar_updates(cx);
986+
968987
}
969988

970989
if let Event::Actions(actions) = event {
@@ -1037,16 +1056,14 @@ impl Widget for RoomScreen {
10371056
match action.downcast_ref() {
10381057
Some(RoomsPanelRestoreAction::Success(room_id)) => {
10391058
if self.room_id.as_ref().is_some_and(|r| r == room_id) {
1040-
self.set_restore_status(cx, RoomsPanelRestoreAction::Success(room_id.clone()));
10411059
// Reset room_id before displaying room.
10421060
self.room_id = None;
10431061
self.set_displayed_room(cx, room_id.clone(), self.room_name.clone());
1062+
self.view
1063+
.label(id!(restore_status_label)).set_text(cx, "");
10441064
return;
10451065
}
10461066
}
1047-
Some(RoomsPanelRestoreAction::AllRoomsLoaded) => {
1048-
self.set_restore_status(cx, RoomsPanelRestoreAction::AllRoomsLoaded);
1049-
}
10501067
_ => {}
10511068
}
10521069
// Handle the highlight animation.
@@ -1295,11 +1312,10 @@ impl Widget for RoomScreen {
12951312
}
12961313

12971314
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
1298-
if matches!(
1299-
&self.restore_status,
1300-
RoomsPanelRestoreAction::Pending(_) | RoomsPanelRestoreAction::AllRoomsLoaded
1301-
) {
1302-
return self.view.draw_walk(cx, scope, walk);
1315+
if let Some(room_id) = &self.room_id {
1316+
if !self.rooms_list(id!(rooms_list)).is_room_loaded(room_id) {
1317+
return self.view.draw_walk(cx, scope, walk);
1318+
}
13031319
}
13041320

13051321
if self.tl_state.is_none() {
@@ -2280,12 +2296,6 @@ impl RoomScreen {
22802296
fn show_timeline(&mut self, cx: &mut Cx) {
22812297
let room_id = self.room_id.clone()
22822298
.expect("BUG: Timeline::show_timeline(): no room_id was set.");
2283-
// just an optional sanity check
2284-
// Remove this as there is restoring state RoomsPanelRestoreAction::Pending with early return
2285-
// assert!(self.tl_state.is_none(),
2286-
// "BUG: tried to show_timeline() into a timeline with existing state. \
2287-
// Did you forget to save the timeline state back to the global map of states?",
2288-
// );
22892299

22902300
// Obtain the current user's power levels for this room.
22912301
submit_async_request(MatrixRequest::GetRoomPowerLevels { room_id: room_id.clone() });
@@ -2295,7 +2305,6 @@ impl RoomScreen {
22952305
(existing, false)
22962306
} else {
22972307
let Some((update_sender, update_receiver, request_sender)) = take_timeline_endpoints(&room_id) else {
2298-
self.set_restore_status(cx, RoomsPanelRestoreAction::Pending(room_id.clone()));
22992308
return;
23002309
};
23012310
let new_tl_state = TimelineUiState {
@@ -2484,36 +2493,6 @@ impl RoomScreen {
24842493
self.show_timeline(cx);
24852494
}
24862495

2487-
/// This sets the RoomScreen widget to display a text label in place of the timeline.
2488-
pub fn set_restore_status(&mut self, cx: &mut Cx, status: RoomsPanelRestoreAction) {
2489-
match &status {
2490-
RoomsPanelRestoreAction::Pending(room_id) => {
2491-
// Set this RoomScreen's room_id such that it can handle a `RoomsPanelRestoreAction::Success` action.
2492-
self.room_id = Some(room_id.clone());
2493-
self.view
2494-
.label(id!(restore_status_label))
2495-
.set_text(cx, "[Placeholder for Spinner]");
2496-
self.restore_status = status;
2497-
}
2498-
RoomsPanelRestoreAction::AllRoomsLoaded => {
2499-
if let RoomsPanelRestoreAction::Pending(_) = self.restore_status {
2500-
self.view.label(id!(restore_status_label)).set_text(
2501-
cx,
2502-
&format!(
2503-
"Room {} was not found in the homeserver's list of all rooms.",
2504-
self.room_name
2505-
),
2506-
);
2507-
}
2508-
}
2509-
_ => {
2510-
self.view.label(id!(restore_status_label)).set_text(cx, "");
2511-
self.restore_status = status;
2512-
}
2513-
}
2514-
self.redraw(cx);
2515-
}
2516-
25172496
/// Sends read receipts based on the current scroll position of the timeline.
25182497
fn send_user_read_receipts_based_on_scroll_pos(
25192498
&mut self,
@@ -2624,13 +2603,6 @@ impl RoomScreenRef {
26242603
let Some(mut inner) = self.borrow_mut() else { return };
26252604
inner.set_displayed_room(cx, room_id, room_name);
26262605
}
2627-
2628-
/// See [`RoomScreen::set_restore_status()`].
2629-
pub fn set_restore_status(&self, cx: &mut Cx, status: RoomsPanelRestoreAction) {
2630-
if let Some(mut inner) = self.borrow_mut() {
2631-
inner.set_restore_status(cx, status);
2632-
}
2633-
}
26342606
}
26352607

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

src/home/rooms_list.rs

Lines changed: 32 additions & 7 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

@@ -451,6 +451,21 @@ impl RoomsList {
451451
n => format!("Found {} matching rooms.", n),
452452
}
453453
}
454+
455+
/// Determines if all known rooms have been loaded.
456+
///
457+
/// Returns `true` if the number of rooms in `all_rooms` equals or exceeds
458+
/// `max_known_rooms`, or `false` if `max_known_rooms` is `None`.
459+
460+
fn all_known_rooms_loaded(&self) -> bool {
461+
self.max_known_rooms.map_or(false, |max_rooms| self.all_rooms.len() >= max_rooms as usize)
462+
}
463+
464+
/// Returns `true` if the given `room_id` is already in the `all_rooms` list,
465+
/// and `false` if it is not.
466+
fn is_room_loaded(&self, room_id: &OwnedRoomId) -> bool {
467+
self.all_rooms.contains_key(room_id)
468+
}
454469
}
455470

456471
impl Widget for RoomsList {
@@ -473,12 +488,8 @@ impl Widget for RoomsList {
473488
}
474489
}
475490
self.update_status_rooms_count();
476-
cx.action(RoomsPanelRestoreAction::Success(room_id));
477-
if self.all_rooms.len() == self.max_known_rooms.unwrap_or(u32::MAX) as usize {
478-
cx.action(RoomsPanelRestoreAction::AllRoomsLoaded);
479-
let app_state = scope.data.get_mut::<AppState>().unwrap();
480-
app_state.all_known_rooms_loaded = true;
481-
}
491+
// Signal the UI to update the RoomScreen
492+
SignalToUI::set_ui_signal();
482493
}
483494
RoomsListUpdate::UpdateRoomAvatar { room_id, avatar } => {
484495
if let Some(room) = self.all_rooms.get_mut(&room_id) {
@@ -749,6 +760,20 @@ impl WidgetMatchEvent for RoomsList {
749760
}
750761
}
751762

763+
impl RoomsListRef {
764+
/// See [`RoomsList::all_known_rooms_loaded()`].
765+
pub fn all_known_rooms_loaded(
766+
&self,
767+
) -> bool {
768+
let Some(inner) = self.borrow() else { return false };
769+
inner.all_known_rooms_loaded()
770+
}
771+
/// See [`RoomsList::is_room_loaded()`].
772+
pub fn is_room_loaded(&self, room_id: &OwnedRoomId) -> bool {
773+
let Some(inner) = self.borrow() else { return false };
774+
inner.is_room_loaded(room_id)
775+
}
776+
}
752777
pub struct RoomsListScopeProps {
753778
/// Whether the RoomsList's inner PortalList was scrolling
754779
/// when the latest finger down event occurred.

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)