run cargo fmt
Some checks failed
Rust CI / build-and-test (macOS-latest) (push) Has been cancelled
Rust CI / build-and-test (ubuntu-latest) (push) Has been cancelled
Rust CI / build-and-test (windows-latest) (push) Has been cancelled
Rust CI / cross-compile (macOS-latest, x86_64-pc-windows-gnu) (push) Has been cancelled
Rust CI / cross-compile (macOS-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Rust CI / cross-compile (ubuntu-latest, x86_64-pc-windows-gnu) (push) Has been cancelled
Some checks failed
Rust CI / build-and-test (macOS-latest) (push) Has been cancelled
Rust CI / build-and-test (ubuntu-latest) (push) Has been cancelled
Rust CI / build-and-test (windows-latest) (push) Has been cancelled
Rust CI / cross-compile (macOS-latest, x86_64-pc-windows-gnu) (push) Has been cancelled
Rust CI / cross-compile (macOS-latest, x86_64-unknown-linux-gnu) (push) Has been cancelled
Rust CI / cross-compile (ubuntu-latest, x86_64-pc-windows-gnu) (push) Has been cancelled
This commit is contained in:
parent
a68e5d5324
commit
1938d68888
7 changed files with 156 additions and 135 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::keystorage::{Error, Result, KeyStorage, KeyStorageType};
|
||||
use nostr::{Keys, Event};
|
||||
use crate::keystorage::{Error, KeyStorage, KeyStorageType, Result};
|
||||
use nostr::nips::nip59::UnwrappedGift;
|
||||
use nostr::{Event, Keys};
|
||||
use pollster::FutureExt as _;
|
||||
|
||||
pub struct AccountManager {
|
||||
|
@ -15,12 +15,16 @@ impl AccountManager {
|
|||
}
|
||||
|
||||
pub fn unwrap_gift_wrap(&mut self, gift_wrap: &Event) -> Result<UnwrappedGift> {
|
||||
let target_pubkey = gift_wrap.tags.iter()
|
||||
let target_pubkey = gift_wrap
|
||||
.tags
|
||||
.iter()
|
||||
.find(|tag| tag.kind() == "p".into())
|
||||
.and_then(|tag| tag.content())
|
||||
.ok_or(Error::KeyNotFound)?;
|
||||
|
||||
let target_key = self.loaded_keys.iter()
|
||||
let target_key = self
|
||||
.loaded_keys
|
||||
.iter()
|
||||
.find(|key| key.public_key().to_string() == *target_pubkey)
|
||||
.ok_or(Error::KeyNotFound)?;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use nostr::{Event, EventBuilder, Keys, Kind, PublicKey, Tag, TagKind, TagStandard, EventId};
|
||||
use nostr::{Event, EventBuilder, EventId, Keys, Kind, PublicKey, Tag, TagKind, TagStandard};
|
||||
use pollster::FutureExt as _;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use ewebsock::{WsMessage, WsEvent};
|
||||
use crate::error;
|
||||
use ewebsock::{WsEvent, WsMessage};
|
||||
use nostr::types::Filter;
|
||||
use nostr::Event;
|
||||
use serde::de::{SeqAccess, Visitor};
|
||||
use serde::ser::SerializeSeq;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use std::fmt::{self};
|
||||
use crate::error;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct CommandResult<'a> {
|
||||
|
@ -29,7 +29,7 @@ pub enum RelayEvent<'a> {
|
|||
Closed,
|
||||
Other(&'a WsMessage),
|
||||
Error(error::Error),
|
||||
Message(RelayMessage<'a>)
|
||||
Message(RelayMessage<'a>),
|
||||
}
|
||||
|
||||
impl<'a> From<&'a WsEvent> for RelayEvent<'a> {
|
||||
|
@ -113,7 +113,7 @@ impl<'a> RelayMessage<'a> {
|
|||
}
|
||||
|
||||
// Event JSON goes until end, minus closing bracket
|
||||
let event_json = &msg[event_start..msg.len()-1];
|
||||
let event_json = &msg[event_start..msg.len() - 1];
|
||||
|
||||
return Ok(Self::event(event_json, subid));
|
||||
} else {
|
||||
|
|
|
@ -4,8 +4,8 @@ use crate::relay::Subscription;
|
|||
use crate::relay::{Relay, RelayStatus};
|
||||
use ewebsock::{WsEvent, WsMessage};
|
||||
use std::collections::HashMap;
|
||||
use tracing::{error, debug};
|
||||
use std::time::{Instant, Duration};
|
||||
use std::time::{Duration, Instant};
|
||||
use tracing::{debug, error};
|
||||
|
||||
pub const RELAY_RECONNECT_SECONDS: u64 = 5;
|
||||
|
||||
|
@ -34,7 +34,9 @@ impl RelayPool {
|
|||
let now = Instant::now();
|
||||
|
||||
// Check disconnected relays
|
||||
if now.duration_since(self.last_reconnect_attempt) >= Duration::from_secs(RELAY_RECONNECT_SECONDS) {
|
||||
if now.duration_since(self.last_reconnect_attempt)
|
||||
>= Duration::from_secs(RELAY_RECONNECT_SECONDS)
|
||||
{
|
||||
for relay in self.relays.values_mut() {
|
||||
if relay.status != RelayStatus::Connected {
|
||||
relay.status = RelayStatus::Connecting;
|
||||
|
@ -145,7 +147,11 @@ impl RelayPool {
|
|||
}
|
||||
}
|
||||
Pong(m) => {
|
||||
debug!("pong recieved from {} after approx {} seconds", &url, self.last_ping.elapsed().as_secs());
|
||||
debug!(
|
||||
"pong recieved from {} after approx {} seconds",
|
||||
&url,
|
||||
self.last_ping.elapsed().as_secs()
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
// who cares
|
||||
|
|
|
@ -34,7 +34,10 @@ impl ComposeWindow {
|
|||
.default_size([min_width, min_height])
|
||||
.min_width(300.0)
|
||||
.min_height(200.0)
|
||||
.default_pos([screen_rect.right() - min_width - 20.0, screen_rect.bottom() - min_height - 20.0])
|
||||
.default_pos([
|
||||
screen_rect.right() - min_width - 20.0,
|
||||
screen_rect.bottom() - min_height - 20.0,
|
||||
])
|
||||
.show(ctx, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
// Header section
|
||||
|
@ -42,7 +45,7 @@ impl ComposeWindow {
|
|||
ui.label("To:");
|
||||
ui.add_sized(
|
||||
[ui.available_width(), 24.0],
|
||||
egui::TextEdit::singleline(&mut state.to_field)
|
||||
egui::TextEdit::singleline(&mut state.to_field),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -50,7 +53,7 @@ impl ComposeWindow {
|
|||
ui.label("Subject:");
|
||||
ui.add_sized(
|
||||
[ui.available_width(), 24.0],
|
||||
egui::TextEdit::singleline(&mut state.subject)
|
||||
egui::TextEdit::singleline(&mut state.subject),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -75,7 +78,7 @@ impl ComposeWindow {
|
|||
.show(ui, |ui| {
|
||||
ui.add_sized(
|
||||
[ui.available_width(), available_height - 20.0],
|
||||
egui::TextEdit::multiline(&mut state.content)
|
||||
egui::TextEdit::multiline(&mut state.content),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -116,7 +119,9 @@ impl ComposeWindow {
|
|||
|
||||
// send over wire
|
||||
for event in events_to_send {
|
||||
match serde_json::to_string(&ClientMessage::Event { event: event.1 }) {
|
||||
match serde_json::to_string(&ClientMessage::Event {
|
||||
event: event.1,
|
||||
}) {
|
||||
Ok(v) => match app.relays.send(ewebsock::WsMessage::Text(v)) {
|
||||
Ok(r) => r,
|
||||
Err(e) => error!("could not send event to relays: {}", e),
|
||||
|
|
|
@ -51,7 +51,12 @@ impl OnboardingScreen {
|
|||
|
||||
// here, we are assuming that the most recent key added is the one that was generated in
|
||||
// onboarding_new()'s button click.
|
||||
let first_key = app.account_manager.loaded_keys.last().expect("wanted a key from last screen").clone();
|
||||
let first_key = app
|
||||
.account_manager
|
||||
.loaded_keys
|
||||
.last()
|
||||
.expect("wanted a key from last screen")
|
||||
.clone();
|
||||
ui.label(format!(
|
||||
"New identity: {}",
|
||||
first_key.public_key().to_bech32().unwrap()
|
||||
|
|
|
@ -107,7 +107,8 @@ impl SettingsScreen {
|
|||
// TODO: this only updates when next frame is rendered, which can be more than
|
||||
// a few seconds between renders. Make it so it updates every second.
|
||||
if relay.status == crate::relay::RelayStatus::Disconnected {
|
||||
let next_ping = crate::relay::RELAY_RECONNECT_SECONDS - last_ping.elapsed().as_secs();
|
||||
let next_ping =
|
||||
crate::relay::RELAY_RECONNECT_SECONDS - last_ping.elapsed().as_secs();
|
||||
|
||||
ui.label(format!("(Attempting reconnect in {} seconds)", next_ping));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue