Add message inspection popup
This commit is contained in:
parent
d92c7cb98e
commit
d7e19b5eca
5 changed files with 196 additions and 8 deletions
|
|
@ -1,5 +1,6 @@
|
|||
mod account;
|
||||
mod auth;
|
||||
mod inspect;
|
||||
mod links;
|
||||
mod nick;
|
||||
mod nick_list;
|
||||
|
|
|
|||
94
src/ui/euph/inspect.rs
Normal file
94
src/ui/euph/inspect.rs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use euphoxide::api::Message;
|
||||
use toss::styled::Styled;
|
||||
|
||||
use crate::ui::input::{key, InputEvent, KeyBindingsList};
|
||||
use crate::ui::widgets::popup::Popup;
|
||||
use crate::ui::widgets::text::Text;
|
||||
use crate::ui::widgets::BoxedWidget;
|
||||
|
||||
macro_rules! line {
|
||||
( $text:ident, $name:expr, $val:expr ) => {
|
||||
$text = $text
|
||||
.then($name, ContentStyle::default().cyan())
|
||||
.then_plain(format!(" {}\n", $val));
|
||||
};
|
||||
( $text:ident, $name:expr, $val:expr, debug ) => {
|
||||
$text = $text
|
||||
.then($name, ContentStyle::default().cyan())
|
||||
.then_plain(format!(" {:?}\n", $val));
|
||||
};
|
||||
( $text:ident, $name:expr, $val:expr, optional ) => {
|
||||
if let Some(val) = $val {
|
||||
$text = $text
|
||||
.then($name, ContentStyle::default().cyan())
|
||||
.then_plain(format!(" {val}\n"));
|
||||
} else {
|
||||
$text = $text
|
||||
.then($name, ContentStyle::default().cyan())
|
||||
.then_plain(" ")
|
||||
.then("none", ContentStyle::default().italic().grey())
|
||||
.then_plain("\n");
|
||||
}
|
||||
};
|
||||
( $text:ident, $name:expr, $val:expr, yes or no ) => {
|
||||
$text = $text
|
||||
.then($name, ContentStyle::default().cyan())
|
||||
.then_plain(if $val { " yes\n" } else { " no\n" });
|
||||
};
|
||||
}
|
||||
|
||||
pub fn message_widget(msg: &Message) -> BoxedWidget {
|
||||
let heading_style = ContentStyle::default().bold();
|
||||
|
||||
let mut text = Styled::new("Message", heading_style).then_plain("\n");
|
||||
line!(text, "id", msg.id);
|
||||
line!(text, "parent", msg.parent, optional);
|
||||
line!(text, "previous_edit_id", msg.previous_edit_id, optional);
|
||||
line!(text, "time", msg.time.0);
|
||||
line!(text, "encryption_key_id", &msg.encryption_key_id, optional);
|
||||
line!(text, "edited", msg.edited.map(|t| t.0), optional);
|
||||
line!(text, "deleted", msg.deleted.map(|t| t.0), optional);
|
||||
line!(text, "truncated", msg.truncated, yes or no);
|
||||
text = text.then_plain("\n");
|
||||
|
||||
text = text.then("Sender", heading_style).then_plain("\n");
|
||||
line!(text, "id", msg.sender.id);
|
||||
line!(text, "name", msg.sender.name);
|
||||
line!(text, "name (raw)", msg.sender.name, debug);
|
||||
line!(text, "server_id", msg.sender.server_id);
|
||||
line!(text, "server_era", msg.sender.server_era);
|
||||
line!(text, "session_id", msg.sender.session_id);
|
||||
line!(text, "is_staff", msg.sender.is_staff, yes or no);
|
||||
line!(text, "is_manager", msg.sender.is_manager, yes or no);
|
||||
line!(
|
||||
text,
|
||||
"client_address",
|
||||
msg.sender.client_address.as_ref(),
|
||||
optional
|
||||
);
|
||||
line!(
|
||||
text,
|
||||
"real_client_address",
|
||||
msg.sender.real_client_address.as_ref(),
|
||||
optional
|
||||
);
|
||||
|
||||
Popup::new(Text::new(text)).title("Inspect message").build()
|
||||
}
|
||||
|
||||
pub fn list_key_bindings(bindings: &mut KeyBindingsList) {
|
||||
bindings.binding("esc", "close");
|
||||
}
|
||||
|
||||
pub enum EventResult {
|
||||
NotHandled,
|
||||
Close,
|
||||
}
|
||||
|
||||
pub fn handle_input_event(event: &InputEvent) -> EventResult {
|
||||
match event {
|
||||
key!(Esc) => EventResult::Close,
|
||||
_ => EventResult::NotHandled,
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ use std::collections::VecDeque;
|
|||
use std::sync::Arc;
|
||||
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use euphoxide::api::{Data, PacketType, Snowflake};
|
||||
use euphoxide::api::{Data, Message, PacketType, Snowflake};
|
||||
use euphoxide::conn::{Joined, Joining, Status};
|
||||
use parking_lot::FairMutex;
|
||||
use tokio::sync::oneshot::error::TryRecvError;
|
||||
|
|
@ -30,15 +30,17 @@ use crate::vault::EuphVault;
|
|||
use super::account::{self, AccountUiState};
|
||||
use super::links::{self, LinksState};
|
||||
use super::popup::RoomPopup;
|
||||
use super::{auth, nick, nick_list};
|
||||
use super::{auth, inspect, nick, nick_list};
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum State {
|
||||
Normal,
|
||||
Auth(EditorState),
|
||||
Nick(EditorState),
|
||||
Account(AccountUiState),
|
||||
Links(LinksState),
|
||||
// TODO Inspect messages and users
|
||||
InspectMessage(Message),
|
||||
// TODO Inspect users
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
|
|
@ -225,6 +227,7 @@ impl EuphRoom {
|
|||
State::Nick(editor) => layers.push(nick::widget(editor)),
|
||||
State::Account(account) => layers.push(account.widget()),
|
||||
State::Links(links) => layers.push(links.widget()),
|
||||
State::InspectMessage(message) => layers.push(inspect::message_widget(message)),
|
||||
}
|
||||
|
||||
for popup in &self.popups {
|
||||
|
|
@ -319,6 +322,7 @@ impl EuphRoom {
|
|||
false
|
||||
};
|
||||
|
||||
bindings.binding("i", "inspect message");
|
||||
bindings.binding("I", "show message links");
|
||||
|
||||
bindings.empty();
|
||||
|
|
@ -353,13 +357,24 @@ impl EuphRoom {
|
|||
}
|
||||
}
|
||||
|
||||
if let key!('I') = event {
|
||||
if let Some(id) = self.chat.cursor().await {
|
||||
if let Some(msg) = self.vault.msg(&id).await {
|
||||
self.state = State::Links(LinksState::new(&msg.content));
|
||||
match event {
|
||||
key!('i') => {
|
||||
if let Some(id) = self.chat.cursor().await {
|
||||
if let Some(msg) = self.vault.full_msg(id).await {
|
||||
self.state = State::InspectMessage(msg);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
key!('I') => {
|
||||
if let Some(id) = self.chat.cursor().await {
|
||||
if let Some(msg) = self.vault.msg(&id).await {
|
||||
self.state = State::Links(LinksState::new(&msg.content));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match status.ok().flatten() {
|
||||
|
|
@ -425,6 +440,7 @@ impl EuphRoom {
|
|||
State::Nick(_) => nick::list_key_bindings(bindings),
|
||||
State::Account(account) => account.list_key_bindings(bindings),
|
||||
State::Links(links) => links.list_key_bindings(bindings),
|
||||
State::InspectMessage(_) => inspect::list_key_bindings(bindings),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -442,6 +458,8 @@ impl EuphRoom {
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO Use a common EventResult
|
||||
|
||||
match &mut self.state {
|
||||
State::Normal => {
|
||||
self.handle_normal_input_event(terminal, crossterm_lock, event)
|
||||
|
|
@ -494,6 +512,13 @@ impl EuphRoom {
|
|||
true
|
||||
}
|
||||
},
|
||||
State::InspectMessage(_) => match inspect::handle_input_event(event) {
|
||||
inspect::EventResult::NotHandled => false,
|
||||
inspect::EventResult::Close => {
|
||||
self.state = State::Normal;
|
||||
true
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue