|
1 | | -use std::{future::ready, ops::ControlFlow, time::Duration}; |
| 1 | +use std::{future::ready, ops::ControlFlow, sync::Arc, time::Duration}; |
2 | 2 |
|
3 | 3 | use assert_matches2::{assert_let, assert_matches}; |
4 | 4 | use matrix_sdk::{ |
| 5 | + config::StoreConfig, |
5 | 6 | event_cache::{ |
6 | 7 | paginator::PaginatorState, BackPaginationOutcome, EventCacheError, RoomEventCacheUpdate, |
7 | 8 | TimelineHasBeenResetWhilePaginating, |
8 | 9 | }, |
| 10 | + linked_chunk::{ChunkIdentifier, Position, Update}, |
9 | 11 | test_utils::{assert_event_matches_msg, logged_in_client_with_server, mocks::MatrixMockServer}, |
10 | 12 | }; |
| 13 | +use matrix_sdk_base::event_cache::store::{EventCacheStore, MemoryStore}; |
11 | 14 | use matrix_sdk_test::{ |
12 | 15 | async_test, event_factory::EventFactory, GlobalAccountDataTestEvent, JoinedRoomBuilder, |
13 | 16 | SyncResponseBuilder, |
@@ -146,46 +149,63 @@ async fn test_add_initial_events() { |
146 | 149 | #[async_test] |
147 | 150 | async fn test_ignored_unignored() { |
148 | 151 | let server = MatrixMockServer::new().await; |
149 | | - let client = server.client_builder().build().await; |
| 152 | + |
| 153 | + let event_cache_store = Arc::new(MemoryStore::new()); |
| 154 | + let client = server |
| 155 | + .client_builder() |
| 156 | + .store_config( |
| 157 | + StoreConfig::new("hodor".to_owned()).event_cache_store(event_cache_store.clone()), |
| 158 | + ) |
| 159 | + .build() |
| 160 | + .await; |
150 | 161 |
|
151 | 162 | // Immediately subscribe the event cache to sync updates. |
152 | 163 | client.event_cache().subscribe().unwrap(); |
| 164 | + client.event_cache().enable_storage().unwrap(); |
153 | 165 |
|
154 | | - // If I sync and get informed I've joined The Room, but with no events, |
155 | 166 | let room_id = room_id!("!omelette:fromage.fr"); |
156 | 167 | let other_room_id = room_id!("!galette:saucisse.bzh"); |
157 | 168 |
|
158 | | - server.sync_joined_room(&client, room_id).await; |
159 | | - server.sync_joined_room(&client, other_room_id).await; |
160 | | - |
161 | 169 | let dexter = user_id!("@dexter:lab.org"); |
162 | 170 | let ivan = user_id!("@ivan:lab.ch"); |
163 | 171 | let f = EventFactory::new(); |
164 | 172 |
|
165 | | - // If I add initial events to a few rooms, |
166 | | - client |
167 | | - .event_cache() |
168 | | - .add_initial_events( |
| 173 | + // Given two rooms which add initial items, |
| 174 | + event_cache_store |
| 175 | + .handle_linked_chunk_updates( |
169 | 176 | room_id, |
170 | 177 | vec![ |
171 | | - f.text_msg("hey there").sender(dexter).into_sync(), |
172 | | - f.text_msg("hoy!").sender(ivan).into_sync(), |
| 178 | + Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None }, |
| 179 | + Update::PushItems { |
| 180 | + at: Position::new(ChunkIdentifier::new(0), 0), |
| 181 | + items: vec![ |
| 182 | + f.text_msg("hey there").sender(dexter).into_sync(), |
| 183 | + f.text_msg("hoy!").sender(ivan).into_sync(), |
| 184 | + ], |
| 185 | + }, |
173 | 186 | ], |
174 | | - None, |
175 | 187 | ) |
176 | 188 | .await |
177 | 189 | .unwrap(); |
178 | 190 |
|
179 | | - client |
180 | | - .event_cache() |
181 | | - .add_initial_events( |
| 191 | + event_cache_store |
| 192 | + .handle_linked_chunk_updates( |
182 | 193 | other_room_id, |
183 | | - vec![f.text_msg("demat!").sender(ivan).into_sync()], |
184 | | - None, |
| 194 | + vec![ |
| 195 | + Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None }, |
| 196 | + Update::PushItems { |
| 197 | + at: Position::new(ChunkIdentifier::new(0), 0), |
| 198 | + items: vec![f.text_msg("demat!").sender(ivan).into_sync()], |
| 199 | + }, |
| 200 | + ], |
185 | 201 | ) |
186 | 202 | .await |
187 | 203 | .unwrap(); |
188 | 204 |
|
| 205 | + // If I get informed about these two rooms during sync, |
| 206 | + server.sync_joined_room(&client, room_id).await; |
| 207 | + server.sync_joined_room(&client, other_room_id).await; |
| 208 | + |
189 | 209 | // And subscribe to the room, |
190 | 210 | let room = client.get_room(room_id).unwrap(); |
191 | 211 | let (room_event_cache, _drop_handles) = room.event_cache().await.unwrap(); |
|
0 commit comments