multiverse/widgets/room_view/details/
read_receipts.rs
1use matrix_sdk_base::read_receipts::RoomReadReceipts;
2use matrix_sdk_ui::room_list_service::Room;
3use ratatui::{
4 prelude::*,
5 widgets::{Paragraph, Wrap},
6};
7
8use crate::TEXT_COLOR;
9
10pub struct ReadReceipts<'a> {
11 room: Option<&'a Room>,
12}
13
14impl<'a> ReadReceipts<'a> {
15 pub fn new(room: Option<&'a Room>) -> Self {
16 Self { room }
17 }
18}
19
20impl Widget for &mut ReadReceipts<'_> {
21 fn render(self, area: Rect, buf: &mut Buffer)
22 where
23 Self: Sized,
24 {
25 match self.room {
26 Some(room) => {
27 let RoomReadReceipts { num_unread, num_notifications, num_mentions, .. } =
28 room.read_receipts();
29
30 let content = vec![
31 Line::from(format!("- unread: {num_unread}")),
32 Line::from(format!("- notifications: {num_notifications}")),
33 Line::from(format!("- mentions: {num_mentions}")),
34 Line::from(""),
35 Line::from("---"),
36 Line::from(format!("{:?}", room.read_receipts())),
37 Line::from("#"),
38 ];
39
40 Paragraph::new(content).fg(TEXT_COLOR).wrap(Wrap { trim: false }).render(area, buf);
41 }
42 None => {
43 let content = "(room disappeared in the room list service)";
44 Paragraph::new(content).fg(TEXT_COLOR).wrap(Wrap { trim: false }).render(area, buf);
45 }
46 }
47 }
48}