Skip to content

Commit

Permalink
multiverse: add Events view
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnjbvr committed Jul 2, 2024
1 parent 0a7184e commit d399854
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions labs/multiverse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use matrix_sdk_ui::{
Timeline as SdkTimeline,
};
use ratatui::{prelude::*, style::palette::tailwind, widgets::*};
use tokio::{spawn, task::JoinHandle};
use tokio::{runtime::Handle, spawn, task::JoinHandle};
use tracing::error;
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _, EnvFilter};

Expand Down Expand Up @@ -112,7 +112,7 @@ enum DetailsMode {
ReadReceipts,
#[default]
TimelineItems,
// Events // TODO: Soon™
Events,
}

struct Timeline {
Expand Down Expand Up @@ -477,6 +477,7 @@ impl App {

Char('r') => self.details_mode = DetailsMode::ReadReceipts,
Char('t') => self.details_mode = DetailsMode::TimelineItems,
Char('e') => self.details_mode = DetailsMode::Events,

Char('b') if self.details_mode == DetailsMode::TimelineItems => {
self.back_paginate();
Expand Down Expand Up @@ -707,6 +708,32 @@ impl App {
render_paragraph(buf, "(room's timeline disappeared)".to_owned())
}
}

DetailsMode::Events => match self.ui_rooms.lock().unwrap().get(&room_id).cloned() {
Some(room) => {
let events = tokio::task::block_in_place(|| {
Handle::current().block_on(async {
let (room_event_cache, _drop_handles) =
room.event_cache().await.unwrap();
let (events, _) = room_event_cache.subscribe().await.unwrap();
events
})
});

let rendered_events = events
.into_iter()
.map(|sync_timeline_item| sync_timeline_item.event.json().to_string())
.collect::<Vec<_>>()
.join("\n\n");

render_paragraph(buf, format!("Events:\n\n{rendered_events}"))
}

None => render_paragraph(
buf,
"(room disappeared in the room list service)".to_owned(),
),
},
}
} else {
render_paragraph(buf, "Nothing to see here...".to_owned())
Expand Down Expand Up @@ -811,10 +838,13 @@ impl App {
} else {
match self.details_mode {
DetailsMode::ReadReceipts => {
"\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()
"\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()
}
DetailsMode::TimelineItems => {
"\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()
"\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()
}
DetailsMode::Events => {
"\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()
}
}
};
Expand Down

0 comments on commit d399854

Please sign in to comment.