multiverse/widgets/room_view/details/
linked_chunk.rs

1use matrix_sdk_ui::room_list_service::Room;
2use ratatui::{
3    prelude::*,
4    widgets::{Paragraph, Wrap},
5};
6use tokio::runtime::Handle;
7
8use crate::TEXT_COLOR;
9
10pub struct LinkedChunkView<'a> {
11    room: Option<&'a Room>,
12}
13
14impl<'a> LinkedChunkView<'a> {
15    pub fn new(room: Option<&'a Room>) -> Self {
16        Self { room }
17    }
18}
19
20impl Widget for &mut LinkedChunkView<'_> {
21    fn render(self, area: Rect, buf: &mut Buffer)
22    where
23        Self: Sized,
24    {
25        match self.room {
26            Some(room) => {
27                let lines = tokio::task::block_in_place(|| {
28                    Handle::current().block_on(async {
29                        let (cache, _drop_guards) =
30                            room.event_cache().await.expect("no event cache for that room");
31                        cache.debug_string().await
32                    })
33                });
34
35                let lines: Vec<Line<'_>> = lines.into_iter().map(Line::from).collect();
36
37                Paragraph::new(lines).fg(TEXT_COLOR).wrap(Wrap { trim: false }).render(area, buf);
38            }
39
40            None => {
41                Paragraph::new("(room disappeared in the room list service)")
42                    .fg(TEXT_COLOR)
43                    .wrap(Wrap { trim: false })
44                    .render(area, buf);
45            }
46        }
47    }
48}