| 1 | use ruma::{OwnedEventId, OwnedRoomId, OwnedTransactionId}; |
| 2 | |
| 3 | #[cfg(feature = "serde")] |
| 4 | use serde::{Deserialize, Serialize}; |
| 5 | |
| 6 | use crate::Error; |
| 7 | |
| 8 | #[derive(Clone, Debug, PartialEq)] |
| 9 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 10 | #[non_exhaustive] |
| 11 | pub enum HistoryRepairCommand { |
| 12 | /// runs the open-time recent load again, joining one already running. the outcome |
| 13 | /// arrives as `RecentHistoryChanged` |
| 14 | RetryRecent { room_id: OwnedRoomId }, |
| 15 | FillGap { |
| 16 | room_id: OwnedRoomId, |
| 17 | gap_id: OwnedTransactionId, |
| 18 | }, |
| 19 | /// stops whichever history operation the room is running |
| 20 | Cancel { room_id: OwnedRoomId }, |
| 21 | } |
| 22 | |
| 23 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 24 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 25 | pub struct HistoryGap { |
| 26 | pub id: OwnedTransactionId, |
| 27 | pub older_boundary: Option<OwnedEventId>, |
| 28 | pub newer_boundary: Option<OwnedEventId>, |
| 29 | pub lifecycle: HistoryGapLifecycle, |
| 30 | pub failure: Option<String>, |
| 31 | } |
| 32 | |
| 33 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 34 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 35 | pub enum HistoryGapLifecycle { |
| 36 | Idle, |
| 37 | /// the last fill stopped short of joining, and another one carries on from there |
| 38 | Paused { |
| 39 | reason: HistoryGapPause, |
| 40 | }, |
| 41 | Failed, |
| 42 | /// accessible history ends before the older section, so this interval stays |
| 43 | Unavailable, |
| 44 | } |
| 45 | |
| 46 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 47 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 48 | pub enum HistoryGapPause { |
| 49 | CursorStalled, |
| 50 | Budget, |
| 51 | } |
| 52 | |
| 53 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 54 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 55 | pub enum HistoryContinuity { |
| 56 | Unresolved, |
| 57 | Verified, |
| 58 | AccessibleStart, |
| 59 | } |
| 60 | |
| 61 | #[derive(Clone, Debug, PartialEq)] |
| 62 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 63 | pub enum HistoryRepairPhase { |
| 64 | Bridging, |
| 65 | Ready, |
| 66 | Paused, |
| 67 | } |
| 68 | |
| 69 | #[derive(Clone, Debug, PartialEq)] |
| 70 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 71 | pub enum HistoryRepairStop { |
| 72 | Cancelled, |
| 73 | Budget, |
| 74 | HistoryUnavailable, |
| 75 | CursorStalled, |
| 76 | } |
| 77 | |
| 78 | /// one gap fill. `Bridging` when it starts, then once more when it settles |
| 79 | #[derive(Clone, Debug, PartialEq)] |
| 80 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 81 | pub struct HistoryRepairReport { |
| 82 | pub room_id: OwnedRoomId, |
| 83 | pub gap_id: OwnedTransactionId, |
| 84 | pub pages: u32, |
| 85 | pub events: u32, |
| 86 | pub phase: HistoryRepairPhase, |
| 87 | pub continuity: HistoryContinuity, |
| 88 | pub stop: Option<HistoryRepairStop>, |
| 89 | pub failure: Option<Error>, |
| 90 | } |