Commit 4f1c41eead
Unsigned
Layout: unified · split
src/room/mod.rs +39 −8
| @@ -143,6 +143,7 @@ const HISTORY_PAGE_TAGS: [&str; 2] = | |||
| 143 | ["matrix_history_page", "matrix_smart_filter"]; | 143 | ["matrix_history_page", "matrix_smart_filter"]; |
| 144 | const RESTORED_HISTORY_BATCH_SIZE: u16 = 25; | 144 | const RESTORED_HISTORY_BATCH_SIZE: u16 = 25; |
| 145 | const INTERACTIVE_HISTORY_BATCH_SIZE: u16 = 25; | 145 | const INTERACTIVE_HISTORY_BATCH_SIZE: u16 = 25; |
| 146 | const INTERACTIVE_HISTORY_MAX_PAGES: usize = 50; | ||
| 146 | 147 | ||
| 147 | // Restore one current page eagerly. Further pages are user-driven so a noisy | 148 | // Restore one current page eagerly. Further pages are user-driven so a noisy |
| 148 | // room cannot monopolize its history lock while the GUI is asking for older | 149 | // room cannot monopolize its history lock while the GUI is asking for older |
| @@ -2529,8 +2530,30 @@ impl MatrixRoom { | |||
| 2529 | } | 2530 | } |
| 2530 | 2531 | ||
| 2531 | pub async fn get_interactive_history_page(&self) -> HistoryPageResult { | 2532 | pub async fn get_interactive_history_page(&self) -> HistoryPageResult { |
| 2532 | self.get_messages_with_limit(INTERACTIVE_HISTORY_BATCH_SIZE) | 2533 | let mut total_added = 0; |
| 2533 | .await | 2534 | |
| 2535 | for _ in 0..INTERACTIVE_HISTORY_MAX_PAGES { | ||
| 2536 | match self | ||
| 2537 | .get_messages_with_limit(INTERACTIVE_HISTORY_BATCH_SIZE) | ||
| 2538 | .await | ||
| 2539 | { | ||
| 2540 | HistoryPageResult::Page { added, exhausted } => { | ||
| 2541 | total_added += added; | ||
| 2542 | if total_added > 0 || exhausted { | ||
| 2543 | return HistoryPageResult::Page { | ||
| 2544 | added: total_added, | ||
| 2545 | exhausted, | ||
| 2546 | }; | ||
| 2547 | } | ||
| 2548 | } | ||
| 2549 | result => return result, | ||
| 2550 | } | ||
| 2551 | } | ||
| 2552 | |||
| 2553 | HistoryPageResult::Page { | ||
| 2554 | added: total_added, | ||
| 2555 | exhausted: false, | ||
| 2556 | } | ||
| 2534 | } | 2557 | } |
| 2535 | 2558 | ||
| 2536 | async fn get_messages_with_limit(&self, limit: u16) -> HistoryPageResult { | 2559 | async fn get_messages_with_limit(&self, limit: u16) -> HistoryPageResult { |
| @@ -2562,9 +2585,13 @@ impl MatrixRoom { | |||
| 2562 | .room_messages(room, prev_batch.clone(), limit) | 2585 | .room_messages(room, prev_batch.clone(), limit) |
| 2563 | .await | 2586 | .await |
| 2564 | { | 2587 | { |
| 2565 | let added = r.chunk.len(); | 2588 | let fetched = r.chunk.len(); |
| 2566 | let (next_prev_batch, exhausted) = | 2589 | let (next_prev_batch, exhausted) = next_history_page_state( |
| 2567 | next_history_page_state(&prev_batch, r.end.clone(), added); | 2590 | &prev_batch, |
| 2591 | r.end.clone(), | ||
| 2592 | fetched, | ||
| 2593 | ); | ||
| 2594 | let mut added = 0; | ||
| 2568 | for event in | 2595 | for event in |
| 2569 | r.chunk.iter().filter_map(|e| e.raw().deserialize().ok()) | 2596 | r.chunk.iter().filter_map(|e| e.raw().deserialize().ok()) |
| 2570 | { | 2597 | { |
| @@ -2580,7 +2607,7 @@ impl MatrixRoom { | |||
| 2580 | }; | 2607 | }; |
| 2581 | *self.latest_event_id.borrow_mut() = Some(event_id); | 2608 | *self.latest_event_id.borrow_mut() = Some(event_id); |
| 2582 | } | 2609 | } |
| 2583 | self.handle_room_event(&event).await; | 2610 | added += self.handle_room_event(&event).await; |
| 2584 | } | 2611 | } |
| 2585 | 2612 | ||
| 2586 | let mut prev_batch = self.prev_batch.borrow_mut(); | 2613 | let mut prev_batch = self.prev_batch.borrow_mut(); |
| @@ -3098,7 +3125,7 @@ impl MatrixRoom { | |||
| 3098 | } | 3125 | } |
| 3099 | } | 3126 | } |
| 3100 | 3127 | ||
| 3101 | pub async fn handle_room_event(&self, event: &AnyTimelineEvent) { | 3128 | pub async fn handle_room_event(&self, event: &AnyTimelineEvent) -> usize { |
| 3102 | let thread_root = thread_root_from_timeline_event(event); | 3129 | let thread_root = thread_root_from_timeline_event(event); |
| 3103 | 3130 | ||
| 3104 | match &event { | 3131 | match &event { |
| @@ -3107,7 +3134,7 @@ impl MatrixRoom { | |||
| 3107 | content | 3134 | content |
| 3108 | } else { | 3135 | } else { |
| 3109 | tracing::error!("Unhandled redacted event: {event:?}"); | 3136 | tracing::error!("Unhandled redacted event: {event:?}"); |
| 3110 | return; | 3137 | return 0; |
| 3111 | }; | 3138 | }; |
| 3112 | let send_time = event.origin_server_ts(); | 3139 | let send_time = event.origin_server_ts(); |
| 3113 | 3140 | ||
| @@ -3151,17 +3178,21 @@ impl MatrixRoom { | |||
| 3151 | ) | 3178 | ) |
| 3152 | .await | 3179 | .await |
| 3153 | { | 3180 | { |
| 3181 | let line_count = rendered.content.lines.len(); | ||
| 3154 | self.print_rendered_event_for_relation( | 3182 | self.print_rendered_event_for_relation( |
| 3155 | Some(event.event_id()), | 3183 | Some(event.event_id()), |
| 3156 | thread_root.as_deref(), | 3184 | thread_root.as_deref(), |
| 3157 | rendered.add_backlog_tags(), | 3185 | rendered.add_backlog_tags(), |
| 3158 | ); | 3186 | ); |
| 3187 | return line_count; | ||
| 3159 | } | 3188 | } |
| 3160 | } | 3189 | } |
| 3161 | } | 3190 | } |
| 3162 | // TODO: print out state events. | 3191 | // TODO: print out state events. |
| 3163 | AnyTimelineEvent::State(_) => (), | 3192 | AnyTimelineEvent::State(_) => (), |
| 3164 | } | 3193 | } |
| 3194 | |||
| 3195 | 0 | ||
| 3165 | } | 3196 | } |
| 3166 | 3197 | ||
| 3167 | pub fn room(&self) -> Room { | 3198 | pub fn room(&self) -> Room { |