@@ -1885,6 +1885,129 @@ mod tests {
18851885 assert ! ( room_info_notable_update_stream. is_empty( ) ) ;
18861886 }
18871887
1888+ #[ async_test]
1889+ async fn test_fully_read_marker_can_trigger_a_notable_update_reason ( ) {
1890+ // Given a logged-in client,
1891+ let client = logged_in_base_client ( None ) . await ;
1892+ let mut room_info_notable_update_stream = client. room_info_notable_update_receiver ( ) ;
1893+
1894+ // When I receive a sliding sync response containing a new room,
1895+ let room_id = room_id ! ( "!r:e.uk" ) ;
1896+ let room = http:: response:: Room :: new ( ) ;
1897+ let response = response_with_room ( room_id, room) ;
1898+ client
1899+ . process_sliding_sync (
1900+ & response,
1901+ & RequestedRequiredStates :: default ( ) ,
1902+ & client. state_store_lock ( ) . lock ( ) . await ,
1903+ )
1904+ . await
1905+ . expect ( "Failed to process sync" ) ;
1906+
1907+ // Other notable updates are received, but not the ones we are interested by.
1908+ assert_matches ! (
1909+ room_info_notable_update_stream. recv( ) . await ,
1910+ Ok ( RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons } ) => {
1911+ assert_eq!( received_room_id, room_id) ;
1912+ assert!( received_reasons. contains( RoomInfoNotableUpdateReasons :: NONE ) , "{received_reasons:?}" ) ;
1913+ }
1914+ ) ;
1915+ assert_matches ! (
1916+ room_info_notable_update_stream. recv( ) . await ,
1917+ Ok ( RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons } ) => {
1918+ assert_eq!( received_room_id, room_id) ;
1919+ assert!( received_reasons. contains( RoomInfoNotableUpdateReasons :: DISPLAY_NAME ) , "{received_reasons:?}" ) ;
1920+ }
1921+ ) ;
1922+ assert ! ( room_info_notable_update_stream. is_empty( ) ) ;
1923+
1924+ // When I receive a sliding sync response containing an `m.fully_read`
1925+ // account-data event,
1926+ let room_account_data_events = vec ! [
1927+ Raw :: from_json_string(
1928+ json!( {
1929+ "type" : "m.fully_read" ,
1930+ "content" : { "event_id" : "$first" } ,
1931+ } )
1932+ . to_string( ) ,
1933+ )
1934+ . unwrap( ) ,
1935+ ] ;
1936+ let mut response = response_with_room ( room_id, http:: response:: Room :: new ( ) ) ;
1937+ response. extensions . account_data . rooms . insert ( room_id. to_owned ( ) , room_account_data_events) ;
1938+
1939+ client
1940+ . process_sliding_sync (
1941+ & response,
1942+ & RequestedRequiredStates :: default ( ) ,
1943+ & client. state_store_lock ( ) . lock ( ) . await ,
1944+ )
1945+ . await
1946+ . expect ( "Failed to process sync" ) ;
1947+
1948+ // Then a `FULLY_READ` notable update is received,
1949+ assert_matches ! (
1950+ room_info_notable_update_stream. recv( ) . await ,
1951+ Ok ( RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons } ) => {
1952+ assert_eq!( received_room_id, room_id) ;
1953+ assert!( received_reasons. contains( RoomInfoNotableUpdateReasons :: FULLY_READ ) , "{received_reasons:?}" ) ;
1954+ }
1955+ ) ;
1956+
1957+ let room = client. get_room ( room_id) . expect ( "room should exist" ) ;
1958+ assert_eq ! ( room. fully_read_event_id( ) . as_deref( ) . map( |id| id. as_str( ) ) , Some ( "$first" ) , ) ;
1959+
1960+ // But getting the same value again won't trigger a new notable update…
1961+ client
1962+ . process_sliding_sync (
1963+ & response,
1964+ & RequestedRequiredStates :: default ( ) ,
1965+ & client. state_store_lock ( ) . lock ( ) . await ,
1966+ )
1967+ . await
1968+ . expect ( "Failed to process sync" ) ;
1969+
1970+ assert_matches ! (
1971+ room_info_notable_update_stream. recv( ) . await ,
1972+ Ok ( RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons } ) => {
1973+ assert_eq!( received_room_id, room_id) ;
1974+ assert!( !received_reasons. contains( RoomInfoNotableUpdateReasons :: FULLY_READ ) , "{received_reasons:?}" ) ;
1975+ }
1976+ ) ;
1977+ assert ! ( room_info_notable_update_stream. is_empty( ) ) ;
1978+
1979+ // … Unless the event ID changes!
1980+ let room_account_data_events = vec ! [
1981+ Raw :: from_json_string(
1982+ json!( {
1983+ "type" : "m.fully_read" ,
1984+ "content" : { "event_id" : "$second" } ,
1985+ } )
1986+ . to_string( ) ,
1987+ )
1988+ . unwrap( ) ,
1989+ ] ;
1990+ response. extensions . account_data . rooms . insert ( room_id. to_owned ( ) , room_account_data_events) ;
1991+ client
1992+ . process_sliding_sync (
1993+ & response,
1994+ & RequestedRequiredStates :: default ( ) ,
1995+ & client. state_store_lock ( ) . lock ( ) . await ,
1996+ )
1997+ . await
1998+ . expect ( "Failed to process sync" ) ;
1999+
2000+ assert_matches ! (
2001+ room_info_notable_update_stream. recv( ) . await ,
2002+ Ok ( RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons } ) => {
2003+ assert_eq!( received_room_id, room_id) ;
2004+ assert!( received_reasons. contains( RoomInfoNotableUpdateReasons :: FULLY_READ ) , "{received_reasons:?}" ) ;
2005+ }
2006+ ) ;
2007+ assert_eq ! ( room. fully_read_event_id( ) . as_deref( ) . map( |id| id. as_str( ) ) , Some ( "$second" ) , ) ;
2008+ assert ! ( room_info_notable_update_stream. is_empty( ) ) ;
2009+ }
2010+
18882011 #[ async_test]
18892012 async fn test_unstable_unread_marker_is_ignored_after_stable ( ) {
18902013 // Given a logged-in client,
0 commit comments