multiverse/widgets/room_view/details/
linked_chunk.rs1use matrix_sdk::Room;
2use matrix_sdk_common::executor::Handle;
3use ratatui::{
4 prelude::*,
5 widgets::{Paragraph, Wrap},
6};
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) = room
30 .client()
31 .event_cache()
32 .unwrap()
33 .room(room.room_id())
34 .await
35 .expect("no event cache for that room");
36 cache.debug_string().await
37 })
38 });
39
40 let lines: Vec<Line<'_>> = lines.into_iter().map(Line::from).collect();
41
42 Paragraph::new(lines).fg(TEXT_COLOR).wrap(Wrap { trim: false }).render(area, buf);
43 }
44
45 None => {
46 Paragraph::new("(room disappeared in the room list service)")
47 .fg(TEXT_COLOR)
48 .wrap(Wrap { trim: false })
49 .render(area, buf);
50 }
51 }
52 }
53}