Skip to content

Commit 2be8466

Browse files
committed
multiverse: add Events view
This allows seeing the events directly from the room event cache. I'm hoping this will give us some interesting insights about duplicates, among other things.
1 parent 02b0954 commit 2be8466

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

labs/multiverse/src/main.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use matrix_sdk_ui::{
3434
Timeline as SdkTimeline,
3535
};
3636
use ratatui::{prelude::*, style::palette::tailwind, widgets::*};
37-
use tokio::{spawn, task::JoinHandle};
37+
use tokio::{runtime::Handle, spawn, task::JoinHandle};
3838
use tracing::error;
3939
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _, EnvFilter};
4040

@@ -112,7 +112,7 @@ enum DetailsMode {
112112
ReadReceipts,
113113
#[default]
114114
TimelineItems,
115-
// Events // TODO: Soon™
115+
Events,
116116
}
117117

118118
struct Timeline {
@@ -477,6 +477,7 @@ impl App {
477477

478478
Char('r') => self.details_mode = DetailsMode::ReadReceipts,
479479
Char('t') => self.details_mode = DetailsMode::TimelineItems,
480+
Char('e') => self.details_mode = DetailsMode::Events,
480481

481482
Char('b') if self.details_mode == DetailsMode::TimelineItems => {
482483
self.back_paginate();
@@ -707,6 +708,32 @@ impl App {
707708
render_paragraph(buf, "(room's timeline disappeared)".to_owned())
708709
}
709710
}
711+
712+
DetailsMode::Events => match self.ui_rooms.lock().unwrap().get(&room_id).cloned() {
713+
Some(room) => {
714+
let events = tokio::task::block_in_place(|| {
715+
Handle::current().block_on(async {
716+
let (room_event_cache, _drop_handles) =
717+
room.event_cache().await.unwrap();
718+
let (events, _) = room_event_cache.subscribe().await.unwrap();
719+
events
720+
})
721+
});
722+
723+
let rendered_events = events
724+
.into_iter()
725+
.map(|sync_timeline_item| sync_timeline_item.event.json().to_string())
726+
.collect::<Vec<_>>()
727+
.join("\n\n");
728+
729+
render_paragraph(buf, format!("Events:\n\n{rendered_events}"))
730+
}
731+
732+
None => render_paragraph(
733+
buf,
734+
"(room disappeared in the room list service)".to_owned(),
735+
),
736+
},
710737
}
711738
} else {
712739
render_paragraph(buf, "Nothing to see here...".to_owned())
@@ -811,10 +838,13 @@ impl App {
811838
} else {
812839
match self.details_mode {
813840
DetailsMode::ReadReceipts => {
814-
"\nUse j/k to move, s/S to start/stop the sync service, m to mark as read, t to show the timeline.".to_owned()
841+
"\nUse j/k to move, s/S to start/stop the sync service, m to mark as read, t to show the timeline, e to show events.".to_owned()
815842
}
816843
DetailsMode::TimelineItems => {
817-
"\nUse j/k to move, s/S to start/stop the sync service, r to show read receipts, Q to enable/disable the send queue, M to send a message.".to_owned()
844+
"\nUse j/k to move, s/S to start/stop the sync service, r to show read receipts, e to show events, Q to enable/disable the send queue, M to send a message.".to_owned()
845+
}
846+
DetailsMode::Events => {
847+
"\nUse j/k to move, s/S to start/stop the sync service, r to show read receipts, t to show the timeline".to_owned()
818848
}
819849
}
820850
};

0 commit comments

Comments
 (0)