31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1 | mod support; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 2 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 3 | use std::time::Duration; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 4 | |
fe4133dbcd47 | atagen | 2026-09-26 09:05 UTC | 5 | use macltok::{ |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 6 | ConnectionState, Engine, EngineConfig, EngineError, Event, PackUsage, Retain, RoomMembership, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 7 | Termination, ThreadUnread, |
fe4133dbcd47 | atagen | 2026-09-26 09:05 UTC | 8 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 9 | use matrix_sdk::{ |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 10 | ThreadingSupport, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 11 | ruma::{ |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 12 | MilliSecondsSinceUnixEpoch, RoomId, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 13 | api::client::sync::sync_events::v5, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 14 | event_id, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 15 | events::{ |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 16 | AnySyncStateEvent, AnyTimelineEvent, Mentions, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 17 | receipt::{ReceiptThread, ReceiptType}, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 18 | }, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 19 | room_id, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 20 | serde::Raw, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 21 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 22 | test_utils::mocks::MatrixMockServer, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 23 | }; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 24 | use matrix_sdk_test::{ALICE, JoinedRoomBuilder, event_factory::EventFactory}; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 25 | use serde_json::json; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 26 | use tokio::sync::watch; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 27 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 28 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 29 | async fn rooms_changed_invalidates_room_summaries() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 30 | let server = MatrixMockServer::new().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 31 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 32 | .mock_sliding_sync() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 33 | .ok(v5::Response::new("1".to_owned())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 34 | .mount() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 35 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 36 | let client = server.client_builder().build().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 37 | let room_id = room_id!("!state:localhost"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 38 | server.mock_room_state_encryption().plain().mount().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 39 | server.sync_joined_room(&client, room_id).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 40 | let config = EngineConfig::default().with_initial_history_limit(0); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 41 | let (engine, handle, mut events) = Engine::from_client(client, config).await.unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 42 | let running = tokio::spawn(engine.run()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 43 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 44 | support::receive_until(&mut events, |event| matches!(event, Event::RoomsChanged)).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 45 | let rooms = handle.rooms().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 46 | let summary = rooms |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 47 | .iter() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 48 | .find(|summary| summary.room_id == room_id) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 49 | .expect("synced room was absent from the room summaries"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 50 | assert_eq!(summary.membership, RoomMembership::Joined); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 51 | assert!(!summary.name.is_empty()); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 52 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 53 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 54 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 55 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 56 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 57 | async fn connection_watch_tracks_the_engine_lifecycle() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 58 | let server = MatrixMockServer::new().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 59 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 60 | .mock_sliding_sync() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 61 | .ok(v5::Response::new("1".to_owned())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 62 | .mount() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 63 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 64 | let client = server.client_builder().build().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 65 | let config = EngineConfig::default().with_initial_history_limit(0); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 66 | let (engine, handle, mut events) = Engine::from_client(client, config).await.unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 67 | let mut connection = handle.connection_state(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 68 | let connection_peer = connection.clone(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 69 | assert_eq!(*connection.borrow(), ConnectionState::Idle); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 70 | assert_eq!(*connection_peer.borrow(), ConnectionState::Idle); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 71 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 72 | let running = tokio::spawn(engine.run()); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 73 | support::receive_until(&mut events, |event| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 74 | matches!(event, Event::ConnectionChanged(ConnectionState::Connecting)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 75 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 76 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 77 | assert_ne!(*connection.borrow(), ConnectionState::Idle); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 78 | support::receive_until(&mut events, |event| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 79 | matches!(event, Event::ConnectionChanged(ConnectionState::Online)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 80 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 81 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 82 | wait_for_connection(&mut connection, ConnectionState::Online).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 83 | assert_eq!(*connection_peer.borrow(), ConnectionState::Online); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 84 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 85 | support::shut_down(&handle, &mut events, running).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 86 | wait_for_connection(&mut connection, ConnectionState::Stopped).await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 87 | assert_eq!(*connection_peer.borrow(), ConnectionState::Stopped); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 88 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 89 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 90 | #[tokio::test] |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 91 | async fn soft_logout_says_so_and_stops_the_engine() { |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 92 | let server = MatrixMockServer::new().await; |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 93 | server |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 94 | .mock_sliding_sync() |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 95 | .error_unknown_token(true) |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 96 | .mount() |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 97 | .await; |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 98 | let client = server.client_builder().build().await; |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 99 | let (engine, _handle, mut events) = Engine::from_client( |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 100 | client, |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 101 | EngineConfig::default().with_initial_history_limit(0), |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 102 | ) |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 103 | .await |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 104 | .unwrap(); |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 105 | let running = tokio::spawn(engine.run()); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 106 | support::receive_until(&mut events, |event| { |
7c26fad34822 | atagen | 2026-09-26 09:41 UTC | 107 | matches!( |
7c26fad34822 | atagen | 2026-09-26 09:41 UTC | 108 | event, |
7c26fad34822 | atagen | 2026-09-26 09:41 UTC | 109 | Event::SessionAccessRejected { |
7c26fad34822 | atagen | 2026-09-26 09:41 UTC | 110 | soft_logout: Some(_) |
7c26fad34822 | atagen | 2026-09-26 09:41 UTC | 111 | } |
7c26fad34822 | atagen | 2026-09-26 09:41 UTC | 112 | ) |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 113 | }) |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 114 | .await; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 115 | support::receive_until(&mut events, |event| matches!(event, Event::Stopped)).await; |
fe4133dbcd47 | atagen | 2026-09-26 09:05 UTC | 116 | let termination = running.await.unwrap().unwrap(); |
fe4133dbcd47 | atagen | 2026-09-26 09:05 UTC | 117 | assert!(matches!(termination, Termination::SoftLoggedOut { .. })); |
fe4133dbcd47 | atagen | 2026-09-26 09:05 UTC | 118 | assert_eq!(termination.retain(), Retain::Store); |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 119 | } |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 120 | |
fa9114fcf75f | atagen | 2026-09-24 12:51 UTC | 121 | #[tokio::test] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 122 | async fn closing_the_event_stream_stops_an_idle_engine() { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 123 | let server = MatrixMockServer::new().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 124 | server |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 125 | .mock_sliding_sync() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 126 | .ok(v5::Response::new("1".to_owned())) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 127 | .mount() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 128 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 129 | let client = server.client_builder().build().await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 130 | let (engine, handle, mut events) = Engine::from_client( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 131 | client, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 132 | EngineConfig::default().with_initial_history_limit(0), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 133 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 134 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 135 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 136 | let running = tokio::spawn(engine.run()); |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 137 | support::receive_until(&mut events, |event| { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 138 | matches!(event, Event::ConnectionChanged(ConnectionState::Online)) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 139 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 140 | .await; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 141 | drop(events); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 142 | let result = tokio::time::timeout(Duration::from_secs(2), running) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 143 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 144 | .expect("engine did not stop after its event receiver closed") |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 145 | .unwrap(); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 146 | assert!(matches!(result, Err(EngineError::EventReceiverClosed))); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 147 | drop(handle); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 148 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 149 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 150 | async fn wait_for_connection( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 151 | connection: &mut watch::Receiver<ConnectionState>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 152 | expected: ConnectionState, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 153 | ) { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 154 | tokio::time::timeout(Duration::from_secs(2), async { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 155 | loop { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 156 | if *connection.borrow_and_update() == expected { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 157 | return; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 158 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 159 | connection |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 160 | .changed() |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 161 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 162 | .expect("connection watch closed before the expected state"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 163 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 164 | }) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 165 | .await |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 166 | .expect("expected connection state did not arrive"); |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 167 | } |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 168 | |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 169 | #[tokio::test] |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 170 | async fn image_packs_follow_room_state_and_account_data() { |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 171 | let server = MatrixMockServer::new().await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 172 | server |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 173 | .mock_sliding_sync() |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 174 | .ok(v5::Response::new("1".to_owned())) |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 175 | .mount() |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 176 | .await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 177 | let client = server.client_builder().build().await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 178 | let room_id = room_id!("!packs:localhost"); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 179 | server.mock_room_state_encryption().plain().mount().await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 180 | server.sync_joined_room(&client, room_id).await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 181 | let config = EngineConfig::default().with_initial_history_limit(0); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 182 | let (engine, handle, mut events) = Engine::from_client(client.clone(), config).await.unwrap(); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 183 | let running = tokio::spawn(engine.run()); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 184 | |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 185 | let pack: Raw<AnySyncStateEvent> = serde_json::from_value(json!({ |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 186 | "type": "im.ponies.room_emotes", |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 187 | "state_key": "cats", |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 188 | "event_id": "$pack", |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 189 | "sender": "@example:localhost", |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 190 | "origin_server_ts": 1, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 191 | "content": { |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 192 | "pack": { "display_name": "cats", "usage": ["emoticon"] }, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 193 | "images": { |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 194 | "blep": { "url": "mxc://localhost/blep" }, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 195 | "broken": { "url": "not an mxc" }, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 196 | "sticker": { "url": "mxc://localhost/sticker", "usage": ["sticker"] }, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 197 | }, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 198 | }, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 199 | })) |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 200 | .unwrap(); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 201 | server |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 202 | .mock_sync() |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 203 | .ok_and_run(&client, |builder| { |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 204 | builder.add_joined_room(JoinedRoomBuilder::new(room_id).add_state_event(pack)); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 205 | builder.add_custom_global_account_data(json!({ |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 206 | "type": "im.ponies.emote_rooms", |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 207 | "content": { "rooms": { "!packs:localhost": { "cats": {} } } }, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 208 | })); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 209 | }) |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 210 | .await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 211 | support::receive_until(&mut events, |event| { |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 212 | matches!(event, Event::ImagePacksChanged) |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 213 | }) |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 214 | .await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 215 | |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 216 | let packs = handle.image_packs().await.unwrap(); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 217 | let offered = packs.for_room(Some(room_id)); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 218 | assert_eq!(offered.len(), 1, "an enabled room's pack was offered twice"); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 219 | let pack = offered[0]; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 220 | assert_eq!(pack.id, "room:!packs:localhost:cats"); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 221 | assert_eq!(packs.global, vec![pack.clone()]); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 222 | let images: Vec<_> = pack |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 223 | .images |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 224 | .iter() |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 225 | .map(|image| { |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 226 | ( |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 227 | image.shortcode.as_str(), |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 228 | image.reaction_key.as_str(), |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 229 | image.usage.clone(), |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 230 | ) |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 231 | }) |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 232 | .collect(); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 233 | assert_eq!( |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 234 | images, |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 235 | [ |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 236 | ("blep", "mxc://localhost/blep", vec![PackUsage::Emoticon]), |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 237 | ( |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 238 | "sticker", |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 239 | "mxc://localhost/sticker", |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 240 | vec![PackUsage::Sticker] |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 241 | ), |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 242 | ] |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 243 | ); |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 244 | |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 245 | support::shut_down(&handle, &mut events, running).await; |
17e042fbc331 | atagen | 2026-10-08 12:39 UTC | 246 | } |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 247 | |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 248 | /// the sdk counts none of this once threads are on, and a threaded receipt never reaches |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 249 | /// room info, so only our own recount notices it |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 250 | #[tokio::test] |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 251 | async fn thread_unreads_follow_threaded_receipts() { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 252 | let server = MatrixMockServer::new().await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 253 | server |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 254 | .mock_sliding_sync() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 255 | .ok(v5::Response::new("1".to_owned())) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 256 | .mount() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 257 | .await; |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 258 | let client = server |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 259 | .client_builder() |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 260 | .on_builder(|builder| { |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 261 | builder.with_threading_support(ThreadingSupport::Enabled { |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 262 | with_subscriptions: false, |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 263 | }) |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 264 | }) |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 265 | .build() |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 266 | .await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 267 | let room_id = room_id!("!threads:localhost"); |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 268 | let own = client.user_id().unwrap().to_owned(); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 269 | server.mock_room_state_encryption().plain().mount().await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 270 | client.event_cache().subscribe().unwrap(); |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 271 | // without our own member event there's no push context, so no push actions to count |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 272 | server |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 273 | .sync_room( |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 274 | &client, |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 275 | JoinedRoomBuilder::new(room_id) |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 276 | .add_state_event(EventFactory::new().room(room_id).member(&own)), |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 277 | ) |
21b9227729a4 | atagen | 2026-10-25 11:03 UTC | 278 | .await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 279 | let config = EngineConfig::default().with_initial_history_limit(0); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 280 | let (engine, handle, mut events) = Engine::from_client(client.clone(), config).await.unwrap(); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 281 | let running = tokio::spawn(engine.run()); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 282 | |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 283 | let (root, first, second) = ( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 284 | event_id!("$root"), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 285 | event_id!("$first"), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 286 | event_id!("$second"), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 287 | ); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 288 | let factory = EventFactory::new().room(room_id).sender(&ALICE); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 289 | server |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 290 | .sync_room( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 291 | &client, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 292 | JoinedRoomBuilder::new(room_id) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 293 | .add_timeline_event(factory.text_msg("root").event_id(root)) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 294 | .add_timeline_event( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 295 | factory |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 296 | .text_msg("you there?") |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 297 | .in_thread(root, root) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 298 | .mentions(Mentions::with_user_ids([own.clone()])) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 299 | .event_id(first), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 300 | ) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 301 | .add_timeline_event( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 302 | factory |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 303 | .text_msg("hello?") |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 304 | .in_thread(root, first) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 305 | .event_id(second), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 306 | ), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 307 | ) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 308 | .await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 309 | let unread = thread_unread_once(&handle, &mut events, room_id, |unread| { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 310 | unread.is_some_and(|unread| unread.messages == 2) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 311 | }) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 312 | .await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 313 | assert_eq!(unread.mentions, 1); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 314 | let summary = room(&handle, room_id).await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 315 | assert!( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 316 | summary.unread_mentions >= 1, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 317 | "the thread mention left the room's count" |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 318 | ); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 319 | |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 320 | server |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 321 | .sync_room( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 322 | &client, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 323 | JoinedRoomBuilder::new(room_id).add_receipt( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 324 | factory |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 325 | .read_receipts() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 326 | .add( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 327 | first, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 328 | &own, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 329 | ReceiptType::Read, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 330 | ReceiptThread::Thread(root.to_owned()), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 331 | ) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 332 | .into_event(), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 333 | ), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 334 | ) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 335 | .await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 336 | let unread = thread_unread_once(&handle, &mut events, room_id, |unread| { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 337 | unread.is_some_and(|unread| unread.messages == 1) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 338 | }) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 339 | .await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 340 | assert_eq!(unread.mentions, 0); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 341 | |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 342 | server |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 343 | .sync_room( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 344 | &client, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 345 | JoinedRoomBuilder::new(room_id).add_receipt( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 346 | factory |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 347 | .read_receipts() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 348 | .add(second, &own, ReceiptType::Read, ReceiptThread::Unthreaded) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 349 | .into_event(), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 350 | ), |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 351 | ) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 352 | .await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 353 | thread_unread_once(&handle, &mut events, room_id, |unread| unread.is_none()).await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 354 | |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 355 | support::shut_down(&handle, &mut events, running).await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 356 | } |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 357 | |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 358 | async fn room(handle: &macltok::ClientHandle, room_id: &RoomId) -> macltok::RoomSummary { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 359 | handle |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 360 | .rooms() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 361 | .await |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 362 | .into_iter() |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 363 | .find(|summary| summary.room_id == room_id) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 364 | .expect("synced room was absent from the room summaries") |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 365 | } |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 366 | |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 367 | /// waits out `RoomsChanged` until the root's counts satisfy `done` |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 368 | async fn thread_unread_once( |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 369 | handle: &macltok::ClientHandle, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 370 | events: &mut macltok::EventStream, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 371 | room_id: &RoomId, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 372 | done: impl Fn(Option<&ThreadUnread>) -> bool, |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 373 | ) -> ThreadUnread { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 374 | let root = event_id!("$root"); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 375 | tokio::time::timeout(Duration::from_secs(10), async { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 376 | loop { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 377 | let summary = room(handle, room_id).await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 378 | let unread = summary.thread_unreads.get(root); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 379 | if done(unread) { |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 380 | return unread.copied().unwrap_or_default(); |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 381 | } |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 382 | support::receive_until(events, |event| matches!(event, Event::RoomsChanged)).await; |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 383 | } |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 384 | }) |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 385 | .await |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 386 | .expect("thread unreads never settled") |
e5c6427adb35 | atagen | 2026-10-25 10:23 UTC | 387 | } |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 388 | |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 389 | /// continuwuity 26.9 bundles a thread's latest reply as bare content, so nothing dates the |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 390 | /// page's count, and the cache handing back replies the server already counted counted them |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 391 | /// again |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 392 | #[tokio::test] |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 393 | async fn a_thread_list_page_keeps_the_servers_count() { |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 394 | let server = MatrixMockServer::new().await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 395 | server |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 396 | .mock_sliding_sync() |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 397 | .ok(v5::Response::new("1".to_owned())) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 398 | .mount() |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 399 | .await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 400 | let client = server |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 401 | .client_builder() |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 402 | .on_builder(|builder| { |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 403 | builder.with_threading_support(ThreadingSupport::Enabled { |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 404 | with_subscriptions: false, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 405 | }) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 406 | }) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 407 | .build() |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 408 | .await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 409 | let room_id = room_id!("!thread-list:localhost"); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 410 | let own = client.user_id().unwrap().to_owned(); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 411 | server.mock_room_state_encryption().plain().mount().await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 412 | client.event_cache().subscribe().unwrap(); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 413 | let factory = EventFactory::new().room(room_id).sender(&ALICE); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 414 | let (root, first, second, third) = ( |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 415 | event_id!("$list-root"), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 416 | event_id!("$list-first"), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 417 | event_id!("$list-second"), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 418 | event_id!("$list-third"), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 419 | ); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 420 | let reply = |event_id, previous, body| { |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 421 | factory |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 422 | .text_msg(body) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 423 | .in_thread(root, previous) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 424 | .event_id(event_id) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 425 | }; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 426 | server |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 427 | .sync_room( |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 428 | &client, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 429 | JoinedRoomBuilder::new(room_id) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 430 | .add_state_event(EventFactory::new().room(room_id).member(&own)) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 431 | .add_timeline_event(factory.text_msg("root").event_id(root)) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 432 | .add_timeline_event(reply(first, root, "one")) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 433 | .add_timeline_event(reply(second, first, "two")), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 434 | ) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 435 | .await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 436 | let listed: Raw<AnyTimelineEvent> = serde_json::from_value(json!({ |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 437 | "type": "m.room.message", |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 438 | "event_id": root, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 439 | "room_id": room_id, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 440 | "sender": &*ALICE, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 441 | "origin_server_ts": 1, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 442 | "content": { "msgtype": "m.text", "body": "root" }, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 443 | "unsigned": { "m.relations": { "m.thread": { |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 444 | "latest_event": { "msgtype": "m.text", "body": "two" }, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 445 | "count": 2, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 446 | "current_user_participated": false, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 447 | } } }, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 448 | })) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 449 | .unwrap(); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 450 | server |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 451 | .mock_room_threads() |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 452 | .ok(vec![listed], None) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 453 | .mount() |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 454 | .await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 455 | let config = EngineConfig::default().with_initial_history_limit(0); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 456 | let (engine, handle, mut events) = Engine::from_client(client.clone(), config).await.unwrap(); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 457 | let running = tokio::spawn(engine.run()); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 458 | |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 459 | handle.open_thread_list(room_id.to_owned()).await.unwrap(); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 460 | handle |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 461 | .paginate_thread_list(room_id.to_owned(), 20) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 462 | .await |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 463 | .unwrap(); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 464 | tokio::time::sleep(Duration::from_millis(5)).await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 465 | server |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 466 | .sync_room( |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 467 | &client, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 468 | JoinedRoomBuilder::new(room_id) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 469 | .add_timeline_event(reply(first, root, "one")) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 470 | .add_timeline_event(reply(second, first, "two")) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 471 | .add_timeline_event( |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 472 | reply(third, second, "three").server_ts(MilliSecondsSinceUnixEpoch::now()), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 473 | ), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 474 | ) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 475 | .await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 476 | let changed = tokio::time::timeout( |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 477 | Duration::from_secs(10), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 478 | support::receive_until(&mut events, |event| { |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 479 | matches!(event, Event::ThreadListChanged { upserts, .. } |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 480 | if upserts.iter().any(|entry| entry.summary.latest_event_id.as_deref() == Some(third))) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 481 | }), |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 482 | ) |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 483 | .await |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 484 | .expect("the new reply never reached the thread list"); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 485 | let Event::ThreadListChanged { upserts, .. } = changed else { |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 486 | unreachable!() |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 487 | }; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 488 | let entry = upserts.last().unwrap(); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 489 | assert_eq!( |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 490 | entry.summary.reply_count, 3, |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 491 | "replies the server had counted were counted again" |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 492 | ); |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 493 | |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 494 | support::shut_down(&handle, &mut events, running).await; |
e7c1b037154d | atagen | 2026-10-25 13:50 UTC | 495 | } |