chore: clippy fix

This commit is contained in:
kieran 2024-10-18 13:11:21 +01:00
parent b4a6991007
commit e6b606e8fb
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
18 changed files with 47 additions and 72 deletions

View File

@ -1,6 +1,3 @@
use crate::app::ZapStreamApp;
use eframe::Renderer;
use egui::Vec2;
pub mod app;
mod link;

View File

@ -71,15 +71,15 @@ impl NostrLink {
.to_string(),
),
kind: Some(note.kind()),
author: Some(note.pubkey().clone()),
author: Some(*note.pubkey()),
relays: vec![],
}
} else {
Self {
hrp: NostrLinkType::Event,
id: IdOrStr::Id(note.id().clone()),
id: IdOrStr::Id(*note.id()),
kind: Some(note.kind()),
author: Some(note.pubkey().clone()),
author: Some(*note.pubkey()),
relays: vec![],
}
}

View File

@ -1,6 +1,5 @@
use crate::link::NostrLink;
use nostrdb::Note;
use std::borrow::Borrow;
use std::collections::HashMap;
pub struct NoteStore<'a> {

View File

@ -1,6 +1,5 @@
use nostr_sdk::util::hex;
use nostrdb::{NdbStr, Note, Tag};
use std::fmt::Display;
pub trait NoteUtil {
fn id_hex(&self) -> String;

View File

@ -37,13 +37,13 @@ impl NostrWidget for HomePage {
.events
.iter()
.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();
let events = NoteStore::from_vec(events);
ScrollArea::vertical()
.show(ui, |ui| {
widgets::StreamList::new(&events, &services).ui(ui)
widgets::StreamList::new(&events, services).ui(ui)
}).inner
}
}

View File

@ -1,20 +1,16 @@
use crate::link::NostrLink;
use crate::note_util::OwnedNote;
use crate::route;
use crate::route::home::HomePage;
use crate::route::login::LoginPage;
use crate::route::stream::StreamPage;
use crate::services::image_cache::ImageCache;
use crate::services::ndb_wrapper::NDBWrapper;
use crate::widgets::{Header, NostrWidget, StreamList};
use egui::{Context, Response, ScrollArea, Ui, Widget};
use crate::widgets::{Header, NostrWidget};
use egui::{Context, Response, Ui};
use egui_inbox::{UiInbox, UiInboxSender};
use egui_video::{Player, PlayerState};
use log::{info, warn};
use nostr_sdk::nips::nip01;
use nostr_sdk::{Client, Kind, PublicKey};
use nostrdb::{Filter, Ndb, Note, Transaction};
use std::borrow::Borrow;
use nostr_sdk::Client;
use nostrdb::{Ndb, Transaction};
use std::path::PathBuf;
mod home;
@ -93,11 +89,11 @@ impl Router {
let tx = self.ndb.start_transaction();
// handle app state changes
let mut q = self.router.read(ui);
while let Some(r) = q.next() {
let q = self.router.read(ui);
for r in q {
if let Routes::Action(a) = &r {
match a {
RouteAction::LoginPubkey(k) => self.login = Some(k.clone()),
RouteAction::LoginPubkey(k) => self.login = Some(*k),
_ => info!("Not implemented"),
}
} else {

View File

@ -26,8 +26,7 @@ impl StreamPage {
link,
sub,
event: events
.first()
.map_or(None, |n| Some(OwnedNote(n.note_key.as_u64()))),
.first().map(|n| OwnedNote(n.note_key.as_u64())),
chat: None,
player: None,
new_msg: WriteChat::new(),
@ -45,8 +44,7 @@ impl NostrWidget for StreamPage {
let event = if let Some(k) = &self.event {
services
.ndb
.get_note_by_key(services.tx, NoteKey::new(k.0))
.map_or(None, |f| Some(f))
.get_note_by_key(services.tx, NoteKey::new(k.0)).ok()
} else {
None
};
@ -65,7 +63,7 @@ impl NostrWidget for StreamPage {
if self.chat.is_none() {
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);
}

View File

@ -1,11 +1,9 @@
use egui::Image;
use log::{error, info};
use nostr_sdk::util::hex;
use sha2::digest::Update;
use sha2::{Digest, Sha256};
use std::collections::HashSet;
use std::fs;
use std::hash::Hash;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::Mutex;
@ -45,7 +43,7 @@ impl ImageCache {
{
let u = url.into();
let path = self.find(&u);
if !path.exists() && u.len() > 0 {
if !path.exists() && !u.is_empty() {
let path = path.clone();
let fl = self.fetch_lock.clone();
let ctx = self.ctx.clone();

View File

@ -1,15 +1,12 @@
use crate::services::query::QueryManager;
use egui::CursorIcon::Default;
use log::{info, warn};
use nostr_sdk::secp256k1::Context;
use log::warn;
use nostr_sdk::{nostr, Client, JsonUtil, Kind, PublicKey, RelayPoolNotification};
use nostrdb::{
Error, Filter, Ndb, NdbProfile, Note, NoteKey, ProfileRecord, QueryResult, Subscription,
Transaction,
};
use std::collections::HashSet;
use std::sync::{Arc, Mutex, RwLock};
use tokio::sync::mpsc::UnboundedSender;
use std::sync::Mutex;
pub struct NDBWrapper {
ctx: egui::Context,
@ -31,9 +28,9 @@ impl SubWrapper {
}
}
impl Into<u64> for &SubWrapper {
fn into(self) -> u64 {
self.subscription.id()
impl From<&SubWrapper> for u64 {
fn from(val: &SubWrapper) -> Self {
val.subscription.id()
}
}
@ -146,14 +143,12 @@ impl NDBWrapper {
.map_or(None, |p| p.record().profile());
// TODO: fix this shit
if p.is_none() {
if self.profiles.lock().unwrap().insert(*pubkey) {
self.query_manager.queue_query("profile", &[
nostr::Filter::new()
.kinds([Kind::Metadata])
.authors([PublicKey::from_slice(pubkey).unwrap()])
])
}
if p.is_none() && self.profiles.lock().unwrap().insert(*pubkey) {
self.query_manager.queue_query("profile", &[
nostr::Filter::new()
.kinds([Kind::Metadata])
.authors([PublicKey::from_slice(pubkey).unwrap()])
])
}
let sub = None;
(p, sub)

View File

@ -4,10 +4,10 @@ use log::{error, info};
use nostr_sdk::prelude::StreamExt;
use nostr_sdk::Kind::Metadata;
use nostr_sdk::{Client, Filter, SubscribeAutoCloseOptions, SubscriptionId};
use std::collections::{HashMap, HashSet, VecDeque};
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
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::task::JoinHandle;
use uuid::Uuid;
@ -58,17 +58,14 @@ impl Query {
/// Return next query batch
pub fn next(&mut self) -> Option<QueryTrace> {
let mut next: Vec<QueryFilter> = self.queue.drain().collect();
if next.len() == 0 {
if next.is_empty() {
return None;
}
let now = Utc::now();
let id = Uuid::new_v4();
// remove filters already sent
next = next
.into_iter()
.filter(|f| self.traces.len() == 0 || !self.traces.iter().all(|y| y.filters.iter().any(|z| z == f)))
.collect();
next.retain(|f| self.traces.is_empty() || !self.traces.iter().all(|y| y.filters.iter().any(|z| z == f)));
// force profile queries into single filter
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;
}
Some(QueryTrace {
@ -157,10 +154,10 @@ where
fn push_filters(qq: &mut HashMap<String, Query>, id: &str, filters: Vec<QueryFilter>) {
if let Some(q) = qq.get_mut(id) {
q.add(filters.into());
q.add(filters);
} else {
let mut q = Query::new(id);
q.add(filters.into());
q.add(filters);
qq.insert(id.to_string(), q);
}
}

View File

@ -84,8 +84,7 @@ impl<'a> StreamInfo for Note<'a> {
fn viewers(&self) -> Option<u32> {
if let Some(s) = self.get_tag_value("current_participants") {
s.variant().str()
.map_or(None, |v| Some(v.parse::<u32>().unwrap_or(0)))
s.variant().str().map(|v| v.parse::<u32>().unwrap_or(0))
} else {
None
}

View File

@ -40,7 +40,7 @@ impl<'a> Avatar<'a> {
pub fn pubkey(pk: &[u8; 32], svc: &'a RouteServices<'a>) -> Self {
let (p, sub) = svc.ndb.fetch_profile(svc.tx, pk);
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,
size: None,
}

View File

@ -50,8 +50,7 @@ impl NostrWidget for Chat {
.map_while(|n| {
services
.ndb
.get_note_by_key(services.tx, NoteKey::new(n.0))
.map_or(None, |n| Some(n))
.get_note_by_key(services.tx, NoteKey::new(n.0)).ok()
})
.collect();
@ -70,7 +69,7 @@ impl NostrWidget for Chat {
for ev in events.iter().sorted_by(|a, b| {
a.starts().cmp(&b.starts())
}) {
ChatMessage::new(&stream, &ev, services).ui(ui);
ChatMessage::new(&stream, ev, services).ui(ui);
}
})
}).response

View File

@ -37,13 +37,11 @@ impl NostrWidget for Header {
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if let Some(pk) = services.login {
ui.add(Avatar::pubkey(pk, services));
} else {
if Button::new()
.show(ui, |ui| {
ui.label("Login")
}).clicked() {
services.navigate(Routes::LoginPage);
}
} else if Button::new()
.show(ui, |ui| {
ui.label("Login")
}).clicked() {
services.navigate(Routes::LoginPage);
}
});
},

View File

@ -27,7 +27,7 @@ impl Widget for &mut StreamPlayer {
let h = w / 16. * 9.;
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)
} else {
VideoPlaceholder.ui(ui)

View File

@ -86,7 +86,7 @@ impl Widget for StreamEvent<'_> {
let response = response.on_hover_and_drag_cursor(CursorIcon::PointingHand);
if response.clicked() {
self.services.navigate(Routes::EventPage {
link: NostrLink::from_note(&self.event),
link: NostrLink::from_note(self.event),
event: None,
});
}

View File

@ -32,7 +32,7 @@ impl<'a> NostrWidget for StreamTitle<'a> {
.size(32.)
.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)
.color(Color32::WHITE);
ui.add(Label::new(summary).wrap_mode(TextWrapMode::Truncate));

View File

@ -1,7 +1,7 @@
use crate::route::RouteServices;
use crate::theme::NEUTRAL_900;
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;
pub struct WriteChat {