summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoscha <joscha@plugh.de>2022-09-16 00:47:20 +0200
committerJoscha <joscha@plugh.de>2022-09-16 00:47:20 +0200
commit4c7ac31699c6db2dbcb905d44329c572dbb2d68a (patch)
tree7310adf338a7cfbae4bb58c69313c8674123c26a
parente7041da0981d09245a92647e598052f056277706 (diff)
Fix inspect message only working when connected
-rw-r--r--src/ui/euph/room.rs57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/ui/euph/room.rs b/src/ui/euph/room.rs
index 6d90514..9b738ed 100644
--- a/src/ui/euph/room.rs
+++ b/src/ui/euph/room.rs
@@ -298,6 +298,33 @@ impl EuphRoom {
Text::new(info).into()
}
+ fn list_inspect_initiating_key_bindings(&self, bindings: &mut KeyBindingsList) {
+ bindings.binding("i", "inspect message");
+ bindings.binding("I", "show message links");
+ }
+
+ async fn handle_inspect_initiating_input_event(&mut self, event: &InputEvent) -> bool {
+ 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);
+ }
+ }
+ 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));
+ }
+ }
+ true
+ }
+ _ => false,
+ }
+ }
+
pub async fn list_normal_key_bindings(&self, bindings: &mut KeyBindingsList) {
bindings.binding("esc", "leave room");
@@ -321,8 +348,7 @@ impl EuphRoom {
false
};
- bindings.binding("i", "inspect message");
- bindings.binding("I", "show message links");
+ self.list_inspect_initiating_key_bindings(bindings);
bindings.empty();
self.chat.list_key_bindings(bindings, can_compose).await;
@@ -356,24 +382,8 @@ impl EuphRoom {
}
}
- 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;
- }
- 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;
- }
- _ => {}
+ if self.handle_inspect_initiating_input_event(event).await {
+ return true;
}
match status.ok().flatten() {
@@ -412,12 +422,7 @@ impl EuphRoom {
return true;
}
- 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));
- }
- }
+ if self.handle_inspect_initiating_input_event(event).await {
return true;
}