@@ -21,7 +21,7 @@ use matrix_sdk_ui::{
2121use robius_open:: Uri ;
2222use 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} ;
2626use unicode_segmentation:: UnicodeSegmentation ;
2727use 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 {
24492459const LOG_TIMELINE_DIFFS : bool = cfg ! ( feature = "log_timeline_diffs" ) ;
24502460/// Whether to enable verbose logging of all room list service diff updates.
24512461const 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