Skip to content

Commit 8d99f4a

Browse files
committed
Added timeline_loaded_notified bool in room screen and timeout in WaitForTimelineLoaded
1 parent a331d5f commit 8d99f4a

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/home/room_screen.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ pub struct RoomScreen {
859859
#[rust] is_loaded: bool,
860860
/// Whether or not all rooms have been loaded (received from the homeserver).
861861
#[rust] all_rooms_loaded: bool,
862+
/// Whether the timeline loaded notification has been sent for the current room.
863+
#[rust] timeline_loaded_notified: bool,
862864
}
863865
impl Drop for RoomScreen {
864866
fn drop(&mut self) {
@@ -1331,11 +1333,12 @@ impl Widget for RoomScreen {
13311333
};
13321334
let room_id = &tl_state.room_id;
13331335
let tl_items = &tl_state.items;
1334-
if !tl_items.is_empty() {
1336+
if !tl_items.is_empty() && !self.timeline_loaded_notified {
13351337
// Signal waiting threads that this room's timeline has loaded and is ready to jump to specific messages.
13361338
if let Ok(map) = ROOM_TIMELINE_LOADED_MAP.read() {
13371339
if let Some(notify) = map.get(room_id) {
13381340
notify.notify_one();
1341+
self.timeline_loaded_notified = true;
13391342
}
13401343
}
13411344
}
@@ -2625,6 +2628,8 @@ impl RoomScreen {
26252628
self.loading_pane(id!(loading_pane)).take_state();
26262629
self.room_name = room_name_or_id(room_name.into(), &room_id);
26272630
self.room_id = Some(room_id.clone());
2631+
// Reset timeline loaded notification flag for the new room
2632+
self.timeline_loaded_notified = false;
26282633

26292634
// We initially tell every MentionableTextInput widget that the current user
26302635
// *does not* has privileges to notify the entire room;
@@ -4406,7 +4411,7 @@ impl Widget for Message {
44064411
&scope.path,
44074412
RoomsListAction::Selected(target_selected_room)
44084413
);
4409-
submit_async_request(MatrixRequest::WaitForRoomTimelineDrawnToJump { room_id: jump_request.room_id.clone(), event_id: jump_request.event_id.clone() });
4414+
submit_async_request(MatrixRequest::WaitForRoomTimelineLoadedToJump { room_id: jump_request.room_id.clone(), event_id: jump_request.event_id.clone() });
44104415
}
44114416
}
44124417
self.view.handle_event(cx, event, scope);

src/sliding_sync.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use matrix_sdk_ui::{
2121
use robius_open::Uri;
2222
use tokio::{
2323
runtime::Handle,
24-
sync::{mpsc::{Receiver, Sender, UnboundedReceiver, UnboundedSender}, watch, Notify}, task::{AbortHandle, JoinHandle}, time::error::Elapsed,
24+
sync::{mpsc::{Receiver, Sender, UnboundedReceiver, UnboundedSender}, watch, Notify}, task::{AbortHandle, JoinHandle}, time::{error::Elapsed, timeout},
2525
};
2626
use unicode_segmentation::UnicodeSegmentation;
2727
use url::Url;
@@ -415,7 +415,7 @@ pub enum MatrixRequest {
415415
abort_previous_search: bool,
416416
},
417417
/// Wait for a room's timeline to be loaded before jumping to a specific event.
418-
WaitForRoomTimelineDrawnToJump {
418+
WaitForRoomTimelineLoadedToJump {
419419
/// The ID of the room to jump to.
420420
room_id: OwnedRoomId,
421421
/// The ID of the event to jump to.
@@ -1274,8 +1274,7 @@ async fn async_worker(
12741274
items.push_back(SearchResultItem::RoomHeader(event_room_id.clone()));
12751275
}
12761276
}
1277-
items.push_back(SearchResultItem::Event{ event:
1278-
event, formatted_content: message_option}
1277+
items.push_back(SearchResultItem::Event{ event, formatted_content: message_option}
12791278
);
12801279
}
12811280
let count = result
@@ -1316,7 +1315,7 @@ async fn async_worker(
13161315
});
13171316
search_task_abort_handler = Some(handle.abort_handle());
13181317
}
1319-
MatrixRequest::WaitForRoomTimelineDrawnToJump { room_id, event_id } => {
1318+
MatrixRequest::WaitForRoomTimelineLoadedToJump { room_id, event_id } => {
13201319
let sender = {
13211320
let mut all_joined_rooms = ALL_JOINED_ROOMS.lock().unwrap();
13221321
let Some(room_info) = all_joined_rooms.get_mut(&room_id) else {
@@ -1325,17 +1324,27 @@ async fn async_worker(
13251324
};
13261325
room_info.timeline_update_sender.clone()
13271326
};
1328-
log!("Waiting for Room {room_id} to be opened before jumping to event {event_id}");
13291327
Handle::current().spawn(async move {
13301328
if let Some(room_notify) = get_timeline_loaded_notify(&room_id) {
1331-
room_notify.notified().await;
1329+
log!("Waiting for Room {room_id} timeline to be drawn before jumping to event {event_id}");
1330+
let wait_result = timeout(ROOM_TIMELINE_JUMP_TIMEOUT, room_notify.notified()).await;
13321331
remove_timeline_loaded_notify(&room_id);
1332+
1333+
match wait_result {
1334+
Ok(()) => {
1335+
log!("Room {room_id} timeline loaded, jumping to event {event_id}");
1336+
sender
1337+
.send(TimelineUpdate::ScrollToMessage { event_id })
1338+
.unwrap();
1339+
SignalToUI::set_ui_signal();
1340+
}
1341+
Err(_) => {
1342+
error!("Timeout waiting for Room {room_id} timeline to be drawn before jumping to event {event_id}");
1343+
}
1344+
}
1345+
} else {
1346+
error!("Unable to get timeline notification for room {room_id}, event {event_id}");
13331347
}
1334-
log!("Waited for Room {room_id} to be opened before jumping to event {event_id}");
1335-
sender
1336-
.send(TimelineUpdate::ScrollToMessage { event_id })
1337-
.unwrap();
1338-
SignalToUI::set_ui_signal();
13391348
});
13401349
}
13411350
}
@@ -2376,6 +2385,7 @@ fn handle_sync_indicator_subscriber(sync_service: &SyncService) {
23762385
const SYNC_INDICATOR_DELAY: Duration = Duration::from_millis(100);
23772386
/// Duration for sync indicator delay before hiding
23782387
const SYNC_INDICATOR_HIDE_DELAY: Duration = Duration::from_millis(200);
2388+
23792389
let sync_indicator_stream = sync_service.room_list_service()
23802390
.sync_indicator(
23812391
SYNC_INDICATOR_DELAY,
@@ -2449,6 +2459,8 @@ pub struct BackwardsPaginateUntilEventRequest {
24492459
const LOG_TIMELINE_DIFFS: bool = cfg!(feature = "log_timeline_diffs");
24502460
/// Whether to enable verbose logging of all room list service diff updates.
24512461
const LOG_ROOM_LIST_DIFFS: bool = cfg!(feature = "log_room_list_diffs");
2462+
/// Timeout duration for waiting for room timeline to be drawn before jumping to event in seconds.
2463+
const ROOM_TIMELINE_JUMP_TIMEOUT: Duration = Duration::from_secs(5);
24522464

24532465
/// A per-room async task that listens for timeline updates and sends them to the UI thread.
24542466
///

0 commit comments

Comments
 (0)