chore: clippy fix
This commit is contained in:
parent
b4a6991007
commit
e6b606e8fb
@ -1,6 +1,3 @@
|
|||||||
use crate::app::ZapStreamApp;
|
|
||||||
use eframe::Renderer;
|
|
||||||
use egui::Vec2;
|
|
||||||
|
|
||||||
pub mod app;
|
pub mod app;
|
||||||
mod link;
|
mod link;
|
||||||
|
@ -71,15 +71,15 @@ impl NostrLink {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
),
|
),
|
||||||
kind: Some(note.kind()),
|
kind: Some(note.kind()),
|
||||||
author: Some(note.pubkey().clone()),
|
author: Some(*note.pubkey()),
|
||||||
relays: vec![],
|
relays: vec![],
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Self {
|
Self {
|
||||||
hrp: NostrLinkType::Event,
|
hrp: NostrLinkType::Event,
|
||||||
id: IdOrStr::Id(note.id().clone()),
|
id: IdOrStr::Id(*note.id()),
|
||||||
kind: Some(note.kind()),
|
kind: Some(note.kind()),
|
||||||
author: Some(note.pubkey().clone()),
|
author: Some(*note.pubkey()),
|
||||||
relays: vec![],
|
relays: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::link::NostrLink;
|
use crate::link::NostrLink;
|
||||||
use nostrdb::Note;
|
use nostrdb::Note;
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct NoteStore<'a> {
|
pub struct NoteStore<'a> {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use nostr_sdk::util::hex;
|
use nostr_sdk::util::hex;
|
||||||
use nostrdb::{NdbStr, Note, Tag};
|
use nostrdb::{NdbStr, Note, Tag};
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
pub trait NoteUtil {
|
pub trait NoteUtil {
|
||||||
fn id_hex(&self) -> String;
|
fn id_hex(&self) -> String;
|
||||||
|
@ -37,13 +37,13 @@ impl NostrWidget for HomePage {
|
|||||||
.events
|
.events
|
||||||
.iter()
|
.iter()
|
||||||
.map(|n| services.ndb.get_note_by_key(services.tx, NoteKey::new(n.0)))
|
.map(|n| services.ndb.get_note_by_key(services.tx, NoteKey::new(n.0)))
|
||||||
.map_while(|f| f.map_or(None, |f| Some(f)))
|
.map_while(|f| f.ok())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let events = NoteStore::from_vec(events);
|
let events = NoteStore::from_vec(events);
|
||||||
ScrollArea::vertical()
|
ScrollArea::vertical()
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
widgets::StreamList::new(&events, &services).ui(ui)
|
widgets::StreamList::new(&events, services).ui(ui)
|
||||||
}).inner
|
}).inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,16 @@
|
|||||||
use crate::link::NostrLink;
|
use crate::link::NostrLink;
|
||||||
use crate::note_util::OwnedNote;
|
use crate::note_util::OwnedNote;
|
||||||
use crate::route;
|
|
||||||
use crate::route::home::HomePage;
|
use crate::route::home::HomePage;
|
||||||
use crate::route::login::LoginPage;
|
use crate::route::login::LoginPage;
|
||||||
use crate::route::stream::StreamPage;
|
use crate::route::stream::StreamPage;
|
||||||
use crate::services::image_cache::ImageCache;
|
use crate::services::image_cache::ImageCache;
|
||||||
use crate::services::ndb_wrapper::NDBWrapper;
|
use crate::services::ndb_wrapper::NDBWrapper;
|
||||||
use crate::widgets::{Header, NostrWidget, StreamList};
|
use crate::widgets::{Header, NostrWidget};
|
||||||
use egui::{Context, Response, ScrollArea, Ui, Widget};
|
use egui::{Context, Response, Ui};
|
||||||
use egui_inbox::{UiInbox, UiInboxSender};
|
use egui_inbox::{UiInbox, UiInboxSender};
|
||||||
use egui_video::{Player, PlayerState};
|
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use nostr_sdk::nips::nip01;
|
use nostr_sdk::Client;
|
||||||
use nostr_sdk::{Client, Kind, PublicKey};
|
use nostrdb::{Ndb, Transaction};
|
||||||
use nostrdb::{Filter, Ndb, Note, Transaction};
|
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod home;
|
mod home;
|
||||||
@ -93,11 +89,11 @@ impl Router {
|
|||||||
let tx = self.ndb.start_transaction();
|
let tx = self.ndb.start_transaction();
|
||||||
|
|
||||||
// handle app state changes
|
// handle app state changes
|
||||||
let mut q = self.router.read(ui);
|
let q = self.router.read(ui);
|
||||||
while let Some(r) = q.next() {
|
for r in q {
|
||||||
if let Routes::Action(a) = &r {
|
if let Routes::Action(a) = &r {
|
||||||
match a {
|
match a {
|
||||||
RouteAction::LoginPubkey(k) => self.login = Some(k.clone()),
|
RouteAction::LoginPubkey(k) => self.login = Some(*k),
|
||||||
_ => info!("Not implemented"),
|
_ => info!("Not implemented"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,8 +26,7 @@ impl StreamPage {
|
|||||||
link,
|
link,
|
||||||
sub,
|
sub,
|
||||||
event: events
|
event: events
|
||||||
.first()
|
.first().map(|n| OwnedNote(n.note_key.as_u64())),
|
||||||
.map_or(None, |n| Some(OwnedNote(n.note_key.as_u64()))),
|
|
||||||
chat: None,
|
chat: None,
|
||||||
player: None,
|
player: None,
|
||||||
new_msg: WriteChat::new(),
|
new_msg: WriteChat::new(),
|
||||||
@ -45,8 +44,7 @@ impl NostrWidget for StreamPage {
|
|||||||
let event = if let Some(k) = &self.event {
|
let event = if let Some(k) = &self.event {
|
||||||
services
|
services
|
||||||
.ndb
|
.ndb
|
||||||
.get_note_by_key(services.tx, NoteKey::new(k.0))
|
.get_note_by_key(services.tx, NoteKey::new(k.0)).ok()
|
||||||
.map_or(None, |f| Some(f))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -65,7 +63,7 @@ impl NostrWidget for StreamPage {
|
|||||||
|
|
||||||
if self.chat.is_none() {
|
if self.chat.is_none() {
|
||||||
let ok = OwnedNote(event.key().unwrap().as_u64());
|
let ok = OwnedNote(event.key().unwrap().as_u64());
|
||||||
let chat = Chat::new(self.link.clone(), ok, &services.ndb, services.tx);
|
let chat = Chat::new(self.link.clone(), ok, services.ndb, services.tx);
|
||||||
self.chat = Some(chat);
|
self.chat = Some(chat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
use egui::Image;
|
use egui::Image;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use nostr_sdk::util::hex;
|
use nostr_sdk::util::hex;
|
||||||
use sha2::digest::Update;
|
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::hash::Hash;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
@ -45,7 +43,7 @@ impl ImageCache {
|
|||||||
{
|
{
|
||||||
let u = url.into();
|
let u = url.into();
|
||||||
let path = self.find(&u);
|
let path = self.find(&u);
|
||||||
if !path.exists() && u.len() > 0 {
|
if !path.exists() && !u.is_empty() {
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
let fl = self.fetch_lock.clone();
|
let fl = self.fetch_lock.clone();
|
||||||
let ctx = self.ctx.clone();
|
let ctx = self.ctx.clone();
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
use crate::services::query::QueryManager;
|
use crate::services::query::QueryManager;
|
||||||
use egui::CursorIcon::Default;
|
use log::warn;
|
||||||
use log::{info, warn};
|
|
||||||
use nostr_sdk::secp256k1::Context;
|
|
||||||
use nostr_sdk::{nostr, Client, JsonUtil, Kind, PublicKey, RelayPoolNotification};
|
use nostr_sdk::{nostr, Client, JsonUtil, Kind, PublicKey, RelayPoolNotification};
|
||||||
use nostrdb::{
|
use nostrdb::{
|
||||||
Error, Filter, Ndb, NdbProfile, Note, NoteKey, ProfileRecord, QueryResult, Subscription,
|
Error, Filter, Ndb, NdbProfile, Note, NoteKey, ProfileRecord, QueryResult, Subscription,
|
||||||
Transaction,
|
Transaction,
|
||||||
};
|
};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::Mutex;
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
|
|
||||||
pub struct NDBWrapper {
|
pub struct NDBWrapper {
|
||||||
ctx: egui::Context,
|
ctx: egui::Context,
|
||||||
@ -31,9 +28,9 @@ impl SubWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<u64> for &SubWrapper {
|
impl From<&SubWrapper> for u64 {
|
||||||
fn into(self) -> u64 {
|
fn from(val: &SubWrapper) -> Self {
|
||||||
self.subscription.id()
|
val.subscription.id()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,14 +143,12 @@ impl NDBWrapper {
|
|||||||
.map_or(None, |p| p.record().profile());
|
.map_or(None, |p| p.record().profile());
|
||||||
|
|
||||||
// TODO: fix this shit
|
// TODO: fix this shit
|
||||||
if p.is_none() {
|
if p.is_none() && self.profiles.lock().unwrap().insert(*pubkey) {
|
||||||
if self.profiles.lock().unwrap().insert(*pubkey) {
|
self.query_manager.queue_query("profile", &[
|
||||||
self.query_manager.queue_query("profile", &[
|
nostr::Filter::new()
|
||||||
nostr::Filter::new()
|
.kinds([Kind::Metadata])
|
||||||
.kinds([Kind::Metadata])
|
.authors([PublicKey::from_slice(pubkey).unwrap()])
|
||||||
.authors([PublicKey::from_slice(pubkey).unwrap()])
|
])
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let sub = None;
|
let sub = None;
|
||||||
(p, sub)
|
(p, sub)
|
||||||
|
@ -4,10 +4,10 @@ use log::{error, info};
|
|||||||
use nostr_sdk::prelude::StreamExt;
|
use nostr_sdk::prelude::StreamExt;
|
||||||
use nostr_sdk::Kind::Metadata;
|
use nostr_sdk::Kind::Metadata;
|
||||||
use nostr_sdk::{Client, Filter, SubscribeAutoCloseOptions, SubscriptionId};
|
use nostr_sdk::{Client, Filter, SubscribeAutoCloseOptions, SubscriptionId};
|
||||||
use std::collections::{HashMap, HashSet, VecDeque};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@ -58,17 +58,14 @@ impl Query {
|
|||||||
/// Return next query batch
|
/// Return next query batch
|
||||||
pub fn next(&mut self) -> Option<QueryTrace> {
|
pub fn next(&mut self) -> Option<QueryTrace> {
|
||||||
let mut next: Vec<QueryFilter> = self.queue.drain().collect();
|
let mut next: Vec<QueryFilter> = self.queue.drain().collect();
|
||||||
if next.len() == 0 {
|
if next.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let now = Utc::now();
|
let now = Utc::now();
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
|
|
||||||
// remove filters already sent
|
// remove filters already sent
|
||||||
next = next
|
next.retain(|f| self.traces.is_empty() || !self.traces.iter().all(|y| y.filters.iter().any(|z| z == f)));
|
||||||
.into_iter()
|
|
||||||
.filter(|f| self.traces.len() == 0 || !self.traces.iter().all(|y| y.filters.iter().any(|z| z == f)))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// force profile queries into single filter
|
// force profile queries into single filter
|
||||||
if next.iter().all(|f| if let Some(k) = &f.kinds {
|
if next.iter().all(|f| if let Some(k) = &f.kinds {
|
||||||
@ -83,7 +80,7 @@ impl Query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if next.len() == 0 {
|
if next.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(QueryTrace {
|
Some(QueryTrace {
|
||||||
@ -157,10 +154,10 @@ where
|
|||||||
|
|
||||||
fn push_filters(qq: &mut HashMap<String, Query>, id: &str, filters: Vec<QueryFilter>) {
|
fn push_filters(qq: &mut HashMap<String, Query>, id: &str, filters: Vec<QueryFilter>) {
|
||||||
if let Some(q) = qq.get_mut(id) {
|
if let Some(q) = qq.get_mut(id) {
|
||||||
q.add(filters.into());
|
q.add(filters);
|
||||||
} else {
|
} else {
|
||||||
let mut q = Query::new(id);
|
let mut q = Query::new(id);
|
||||||
q.add(filters.into());
|
q.add(filters);
|
||||||
qq.insert(id.to_string(), q);
|
qq.insert(id.to_string(), q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,7 @@ impl<'a> StreamInfo for Note<'a> {
|
|||||||
|
|
||||||
fn viewers(&self) -> Option<u32> {
|
fn viewers(&self) -> Option<u32> {
|
||||||
if let Some(s) = self.get_tag_value("current_participants") {
|
if let Some(s) = self.get_tag_value("current_participants") {
|
||||||
s.variant().str()
|
s.variant().str().map(|v| v.parse::<u32>().unwrap_or(0))
|
||||||
.map_or(None, |v| Some(v.parse::<u32>().unwrap_or(0)))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ impl<'a> Avatar<'a> {
|
|||||||
pub fn pubkey(pk: &[u8; 32], svc: &'a RouteServices<'a>) -> Self {
|
pub fn pubkey(pk: &[u8; 32], svc: &'a RouteServices<'a>) -> Self {
|
||||||
let (p, sub) = svc.ndb.fetch_profile(svc.tx, pk);
|
let (p, sub) = svc.ndb.fetch_profile(svc.tx, pk);
|
||||||
Self {
|
Self {
|
||||||
image: p.and_then(|p| p.picture().and_then(|p| Some(svc.img_cache.load(p)))),
|
image: p.and_then(|p| p.picture().map(|p| svc.img_cache.load(p))),
|
||||||
sub,
|
sub,
|
||||||
size: None,
|
size: None,
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,7 @@ impl NostrWidget for Chat {
|
|||||||
.map_while(|n| {
|
.map_while(|n| {
|
||||||
services
|
services
|
||||||
.ndb
|
.ndb
|
||||||
.get_note_by_key(services.tx, NoteKey::new(n.0))
|
.get_note_by_key(services.tx, NoteKey::new(n.0)).ok()
|
||||||
.map_or(None, |n| Some(n))
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ impl NostrWidget for Chat {
|
|||||||
for ev in events.iter().sorted_by(|a, b| {
|
for ev in events.iter().sorted_by(|a, b| {
|
||||||
a.starts().cmp(&b.starts())
|
a.starts().cmp(&b.starts())
|
||||||
}) {
|
}) {
|
||||||
ChatMessage::new(&stream, &ev, services).ui(ui);
|
ChatMessage::new(&stream, ev, services).ui(ui);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}).response
|
}).response
|
||||||
|
@ -37,13 +37,11 @@ impl NostrWidget for Header {
|
|||||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||||
if let Some(pk) = services.login {
|
if let Some(pk) = services.login {
|
||||||
ui.add(Avatar::pubkey(pk, services));
|
ui.add(Avatar::pubkey(pk, services));
|
||||||
} else {
|
} else if Button::new()
|
||||||
if Button::new()
|
.show(ui, |ui| {
|
||||||
.show(ui, |ui| {
|
ui.label("Login")
|
||||||
ui.label("Login")
|
}).clicked() {
|
||||||
}).clicked() {
|
services.navigate(Routes::LoginPage);
|
||||||
services.navigate(Routes::LoginPage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -27,7 +27,7 @@ impl Widget for &mut StreamPlayer {
|
|||||||
let h = w / 16. * 9.;
|
let h = w / 16. * 9.;
|
||||||
let size = Vec2::new(w, h);
|
let size = Vec2::new(w, h);
|
||||||
|
|
||||||
if let Some(mut p) = self.player.as_mut() {
|
if let Some(p) = self.player.as_mut() {
|
||||||
p.ui(ui, size)
|
p.ui(ui, size)
|
||||||
} else {
|
} else {
|
||||||
VideoPlaceholder.ui(ui)
|
VideoPlaceholder.ui(ui)
|
||||||
|
@ -86,7 +86,7 @@ impl Widget for StreamEvent<'_> {
|
|||||||
let response = response.on_hover_and_drag_cursor(CursorIcon::PointingHand);
|
let response = response.on_hover_and_drag_cursor(CursorIcon::PointingHand);
|
||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
self.services.navigate(Routes::EventPage {
|
self.services.navigate(Routes::EventPage {
|
||||||
link: NostrLink::from_note(&self.event),
|
link: NostrLink::from_note(self.event),
|
||||||
event: None,
|
event: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ impl<'a> NostrWidget for StreamTitle<'a> {
|
|||||||
.size(32.)
|
.size(32.)
|
||||||
.ui(ui);
|
.ui(ui);
|
||||||
|
|
||||||
if let Some(summary) = self.event.get_tag_value("summary").map_or(None, |r| r.variant().str()) {
|
if let Some(summary) = self.event.get_tag_value("summary").and_then(|r| r.variant().str()) {
|
||||||
let summary = RichText::new(summary)
|
let summary = RichText::new(summary)
|
||||||
.color(Color32::WHITE);
|
.color(Color32::WHITE);
|
||||||
ui.add(Label::new(summary).wrap_mode(TextWrapMode::Truncate));
|
ui.add(Label::new(summary).wrap_mode(TextWrapMode::Truncate));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::route::RouteServices;
|
use crate::route::RouteServices;
|
||||||
use crate::theme::NEUTRAL_900;
|
use crate::theme::NEUTRAL_900;
|
||||||
use crate::widgets::NostrWidget;
|
use crate::widgets::NostrWidget;
|
||||||
use egui::{Button, Frame, Image, Margin, Rect, Response, Rounding, Sense, Shadow, Stroke, TextEdit, Ui, Vec2, Widget};
|
use egui::{Frame, Image, Margin, Response, Rounding, Sense, Stroke, TextEdit, Ui, Widget};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
pub struct WriteChat {
|
pub struct WriteChat {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user