Commit 86cbd7ae64
Unsigned
Layout: unified · split
src/room/mod.rs +24 −3
| @@ -95,12 +95,34 @@ pub struct RoomHandle { | |||
| 95 | inner: MatrixRoom, | 95 | inner: MatrixRoom, |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | #[derive(Debug, Clone)] | 98 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 99 | pub enum PrevBatch { | 99 | pub enum PrevBatch { |
| 100 | Forward(String), | 100 | Forward(String), |
| 101 | Backwards(String), | 101 | Backwards(String), |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | fn restored_prev_batch(prev_batch: Option<String>) -> Option<PrevBatch> { | ||
| 105 | prev_batch.map(PrevBatch::Backwards) | ||
| 106 | } | ||
| 107 | |||
| 108 | #[cfg(test)] | ||
| 109 | mod tests { | ||
| 110 | use super::{restored_prev_batch, PrevBatch}; | ||
| 111 | |||
| 112 | #[test] | ||
| 113 | fn restored_rooms_fetch_history_backwards_from_prev_batch() { | ||
| 114 | assert_eq!( | ||
| 115 | restored_prev_batch(Some("token".to_owned())), | ||
| 116 | Some(PrevBatch::Backwards("token".to_owned())) | ||
| 117 | ); | ||
| 118 | } | ||
| 119 | |||
| 120 | #[test] | ||
| 121 | fn restored_rooms_without_prev_batch_have_no_history_request() { | ||
| 122 | assert_eq!(restored_prev_batch(None), None); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 104 | impl Deref for RoomHandle { | 126 | impl Deref for RoomHandle { |
| 105 | type Target = MatrixRoom; | 127 | type Target = MatrixRoom; |
| 106 | 128 | ||
| @@ -366,8 +388,7 @@ impl RoomHandle { | |||
| 366 | room_buffer.members.restore_member(user_id).await; | 388 | room_buffer.members.restore_member(user_id).await; |
| 367 | } | 389 | } |
| 368 | 390 | ||
| 369 | *room_buffer.prev_batch.borrow_mut() = | 391 | *room_buffer.prev_batch.borrow_mut() = restored_prev_batch(prev_batch); |
| 370 | prev_batch.map(PrevBatch::Forward); | ||
| 371 | 392 | ||
| 372 | room_buffer.buffer.update_buffer_name(); | 393 | room_buffer.buffer.update_buffer_name(); |
| 373 | room_buffer.buffer.set_topic(); | 394 | room_buffer.buffer.set_topic(); |