Use Garmelon/vault

This commit is contained in:
Joscha 2023-02-12 23:09:59 +01:00
parent 35a140e21f
commit 7e9e441c1e
15 changed files with 442 additions and 458 deletions

View file

@ -10,12 +10,12 @@ use std::fmt;
use std::sync::Arc;
use async_trait::async_trait;
use log::error;
use parking_lot::FairMutex;
use tokio::sync::Mutex;
use toss::frame::{Frame, Pos, Size};
use toss::terminal::Terminal;
use crate::macros::logging_unwrap;
use crate::store::{Msg, MsgStore};
use crate::ui::input::{key, InputEvent, KeyBindingsList};
use crate::ui::util;
@ -439,13 +439,7 @@ where
async fn render(self: Box<Self>, frame: &mut Frame) {
let mut guard = self.inner.lock().await;
let blocks = match guard.relayout(self.nick, self.focused, frame).await {
Ok(blocks) => blocks,
Err(err) => {
error!("{err}");
panic!("{err}");
}
};
let blocks = logging_unwrap!(guard.relayout(self.nick, self.focused, frame).await);
let size = frame.size();
for block in blocks.into_blocks().blocks {

View file

@ -5,7 +5,6 @@ use crossterm::style::{ContentStyle, Stylize};
use euphoxide::api::{Data, Message, MessageId, PacketType, SessionId};
use euphoxide::bot::instance::{Event, ServerConfig};
use euphoxide::conn::{self, Joined, Joining, SessionInfo};
use log::error;
use parking_lot::FairMutex;
use tokio::sync::oneshot::error::TryRecvError;
use tokio::sync::{mpsc, oneshot};
@ -14,6 +13,7 @@ use toss::terminal::Terminal;
use crate::config;
use crate::euph;
use crate::macros::logging_unwrap;
use crate::ui::chat::{ChatState, Reaction};
use crate::ui::input::{key, InputEvent, KeyBindingsList};
use crate::ui::widgets::border::Border;
@ -143,7 +143,7 @@ impl EuphRoom {
}
pub async fn unseen_msgs_count(&self) -> usize {
self.vault().unseen_msgs_count().await
logging_unwrap!(self.vault().unseen_msgs_count().await)
}
async fn stabilize_pseudo_msg(&mut self) {
@ -327,17 +327,11 @@ impl EuphRoom {
Some(euph::State::Connected(_, conn::State::Joined(_)))
);
let reaction = match self
let reaction = self
.chat
.handle_input_event(terminal, crossterm_lock, event, can_compose)
.await
{
Ok(reaction) => reaction,
Err(err) => {
error!("{err}");
panic!("{err}");
}
};
.await;
let reaction = logging_unwrap!(reaction);
match reaction {
Reaction::NotHandled => {}
@ -434,7 +428,7 @@ impl EuphRoom {
match event {
key!('i') => {
if let Some(id) = self.chat.cursor().await {
if let Some(msg) = self.vault().full_msg(id).await {
if let Some(msg) = logging_unwrap!(self.vault().full_msg(id).await) {
self.state = State::InspectMessage(msg);
}
}
@ -442,7 +436,7 @@ impl EuphRoom {
}
key!('I') => {
if let Some(id) = self.chat.cursor().await {
if let Some(msg) = self.vault().msg(id).await {
if let Some(msg) = logging_unwrap!(self.vault().msg(id).await) {
self.state = State::Links(LinksState::new(&msg.content));
}
}
@ -679,7 +673,7 @@ impl EuphRoom {
}
}
pub fn handle_event(&mut self, event: Event) -> bool {
pub async fn handle_event(&mut self, event: Event) -> bool {
let handled = if self.room.is_some() {
if let Event::Packet(_, packet, _) = &event {
match &packet.content {
@ -694,7 +688,7 @@ impl EuphRoom {
};
if let Some(room) = &mut self.room {
room.handle_event(event);
room.handle_event(event).await;
}
handled

View file

@ -13,6 +13,7 @@ use toss::terminal::Terminal;
use crate::config::{Config, RoomsSortOrder};
use crate::euph;
use crate::macros::logging_unwrap;
use crate::vault::Vault;
use super::euph::room::EuphRoom;
@ -69,8 +70,8 @@ impl Rooms {
vault: Vault,
ui_event_tx: mpsc::UnboundedSender<UiEvent>,
) -> Self {
let euph_server_config =
ServerConfig::default().cookies(Arc::new(Mutex::new(vault.euph().cookies().await)));
let cookies = logging_unwrap!(vault.euph().cookies().await);
let euph_server_config = ServerConfig::default().cookies(Arc::new(Mutex::new(cookies)));
let mut result = Self {
config,
@ -112,13 +113,8 @@ impl Rooms {
/// - failed connection attempts, or
/// - rooms that were deleted from the db.
async fn stabilize_rooms(&mut self) {
let mut rooms_set = self
.vault
.euph()
.rooms()
.await
.into_iter()
.collect::<HashSet<_>>();
let rooms = logging_unwrap!(self.vault.euph().rooms().await);
let mut rooms_set = rooms.into_iter().collect::<HashSet<_>>();
// Prevent room that is currently being shown from being removed. This
// could otherwise happen when connecting to a room that doesn't exist.
@ -533,7 +529,7 @@ impl Rooms {
}
key!(Enter) if editor.text() == *name => {
self.euph_rooms.remove(name);
self.vault.euph().delete(name.clone());
logging_unwrap!(self.vault.euph().room(name.clone()).delete().await);
self.state = State::ShowList;
return true;
}
@ -548,10 +544,10 @@ impl Rooms {
false
}
pub fn handle_euph_event(&mut self, event: Event) -> bool {
pub async fn handle_euph_event(&mut self, event: Event) -> bool {
let instance_name = event.config().name.clone();
let room = self.get_or_insert_room(instance_name.clone());
let handled = room.handle_event(event);
let handled = room.handle_event(event).await;
let room_visible = match &self.state {
State::ShowRoom(name) => *name == instance_name,