Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Dec 18, 2024
1 parent 1a5b1ed commit 609902a
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 62 deletions.
8 changes: 4 additions & 4 deletions gossip-bin/src/notedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ impl NoteData {
_ => Person::new(author_pubkey),
};

let lists = match GLOBALS.db().read_person_lists(&author_pubkey) {
Ok(lists) => lists,
_ => HashMap::new(),
};
let lists = GLOBALS
.db()
.read_person_lists(&author_pubkey)
.unwrap_or_default();

let seen_on = GLOBALS
.db()
Expand Down
5 changes: 1 addition & 4 deletions gossip-bin/src/ui/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,7 @@ fn recompute_btn(app: &mut GossipUi, ui: &mut Ui) {

let feed_hash = GLOBALS.feed.get_feed_hash();
if feed_hash != app.displayed_feed_hash {
if app.displayed_feed.is_empty() {
app.displayed_feed = GLOBALS.feed.get_feed_events();
app.displayed_feed_hash = feed_hash;
} else if ui.link("Show New Updates").clicked() {
if app.displayed_feed.is_empty() || ui.link("Show New Updates").clicked() {
app.displayed_feed = GLOBALS.feed.get_feed_events();
app.displayed_feed_hash = feed_hash;
}
Expand Down
8 changes: 4 additions & 4 deletions gossip-bin/src/ui/feed/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ pub fn render_dm_note(app: &mut GossipUi, ui: &mut Ui, feed_note_params: FeedNot

if let Some(note_ref) = app.notecache.try_update_and_get(&id) {
if let Ok(note_data) = note_ref.try_borrow() {
let viewed = match GLOBALS.db().is_event_viewed(note_data.event.id) {
Ok(answer) => answer,
_ => false,
};
let viewed = GLOBALS
.db()
.is_event_viewed(note_data.event.id)
.unwrap_or_default();

if let Ok(mut note_data) = note_ref.try_borrow_mut() {
note_data.repost = Some(RepostType::GenericRepost);
Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/feed/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ fn do_replacements(draft: &str, replacements: &HashMap<String, ContentSegment>)
fn offer_attachment(app: &mut GossipUi, ctx: &Context, ui: &mut Ui, dm: bool) {
// Skip if no blossom servers configured:
let blossom_servers = GLOBALS.db().read_setting_blossom_servers();
if blossom_servers.split_whitespace().next() == None {
if blossom_servers.split_whitespace().next().is_none() {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/people/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
Page::Person(_) => person::update(app, ctx, _frame, ui),
Page::PersonFollows(who) => follows::update(app, ctx, _frame, ui, who),
Page::PersonFollowers(who) => followers::update(app, ctx, _frame, ui, who),
_ => return,
_ => (),
}
}

Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/relays/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr

widgets::page_header(
ui,
&format!(
format!(
"{} ({} relays)",
Page::RelaysActivityMonitor.name(),
relays.len()
Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/relays/known.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr

widgets::page_header(
ui,
&format!(
format!(
"{} ({} relays)",
Page::RelaysKnownNetwork(None).name(),
relays.len()
Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/relays/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr

widgets::page_header(
ui,
&format!("{} ({} relays)", Page::RelaysMine.name(), relays.len()),
format!("{} ({} relays)", Page::RelaysMine.name(), relays.len()),
|ui| {
if is_editing {
ui.disable();
Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/settings/posting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr

ui.checkbox(
&mut app.unsaved_settings.set_user_agent,
&format!(
format!(
"Send User-Agent Header to Relays: gossip/{}",
app.about.version
),
Expand Down
4 changes: 2 additions & 2 deletions gossip-bin/src/ui/theme/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ impl DefaultTheme {
}
}

/// Trait for creating different types of shadows
/// TODO @dtonon: This must be reviewed as shadow interface changed with egui 0.28
// Trait for creating different types of shadows
// TODO @dtonon: This must be reviewed as shadow interface changed with egui 0.28
// pub trait ShadowBuilder {
// fn soft_dark() -> Self;
// fn soft_light() -> Self;
Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/widgets/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'a> Switch<'a> {
// }
}

impl<'a> Widget for Switch<'a> {
impl Widget for Switch<'_> {
fn ui(self, ui: &mut Ui) -> Response {
self.show(ui)
}
Expand Down
2 changes: 1 addition & 1 deletion gossip-bin/src/ui/widgets/textedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl<'t> TextEdit<'t> {
}
}

impl<'t> Widget for TextEdit<'t> {
impl Widget for TextEdit<'_> {
fn ui(self, ui: &mut egui_winit::egui::Ui) -> egui_winit::egui::Response {
let output = self.show(ui);
output.response
Expand Down
8 changes: 4 additions & 4 deletions gossip-bin/src/ui/you/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra

fn view_line(ui: &mut Ui, field: &str, data: Option<&String>) {
ui.horizontal(|ui| {
ui.label(&format!("{}: ", field));
ui.label(format!("{}: ", field));
if let Some(value) = data {
ui.label(value);
} else {
Expand All @@ -161,7 +161,7 @@ fn view_line(ui: &mut Ui, field: &str, data: Option<&String>) {

fn edit_line(ui: &mut Ui, field: &str, data: &mut Option<String>, edit_color: Color32) {
ui.horizontal(|ui| {
ui.label(&format!("{}: ", field));
ui.label(format!("{}: ", field));
ui.with_layout(Layout::right_to_left(Align::TOP), |ui| {
if data.is_some() {
if ui.button("Remove").clicked() {
Expand Down Expand Up @@ -189,7 +189,7 @@ fn edit_line(ui: &mut Ui, field: &str, data: &mut Option<String>, edit_color: Co
fn view_lines_other(ui: &mut Ui, other: &Map<String, Value>) {
for (field, jsonvalue) in other.iter() {
ui.horizontal(|ui| {
ui.label(&format!("{}: ", field));
ui.label(format!("{}: ", field));
if let Value::String(s) = jsonvalue {
ui.label(s.to_owned());
} else if let Ok(s) = serde_json::to_string(&jsonvalue) {
Expand All @@ -206,7 +206,7 @@ fn edit_lines_other(ui: &mut Ui, other: &mut Map<String, Value>, edit_color: Col
let mut to_remove: Vec<String> = Vec::new();
for (field, jsonvalue) in other.iter_mut() {
ui.horizontal(|ui| {
ui.label(&format!("{}: ", field));
ui.label(format!("{}: ", field));
if let Value::String(s) = jsonvalue {
ui.with_layout(Layout::right_to_left(Align::TOP), |ui| {
if ui.button("Remove").clicked() {
Expand Down
10 changes: 5 additions & 5 deletions gossip-bin/src/ui/you/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ fn show_pub_key_detail(app: &mut GossipUi, ui: &mut Ui) {

let pkhex: PublicKeyHex = public_key.into();
ui.horizontal_wrapped(|ui| {
ui.label(&format!("Public Key (Hex): {}", pkhex.as_str()));
ui.label(format!("Public Key (Hex): {}", pkhex.as_str()));
if ui.add(CopyButton::new()).clicked() {
ui.output_mut(|o| o.copied_text = pkhex.into_string());
}
});

let bech32 = public_key.as_bech32_string();
ui.horizontal_wrapped(|ui| {
ui.label(&format!("Public Key (bech32): {}", bech32));
ui.label(format!("Public Key (bech32): {}", bech32));
if ui.add(CopyButton::new()).clicked() {
ui.output_mut(|o| o.copied_text = bech32.clone());
}
Expand All @@ -156,7 +156,7 @@ fn show_pub_key_detail(app: &mut GossipUi, ui: &mut Ui) {

let nprofile = profile.as_bech32_string();
ui.horizontal_wrapped(|ui| {
ui.label(&format!("Your Profile: {}", &nprofile));
ui.label(format!("Your Profile: {}", &nprofile));
if ui.add(CopyButton::new()).clicked() {
ui.output_mut(|o| o.copied_text = nprofile.clone());
}
Expand Down Expand Up @@ -382,15 +382,15 @@ fn offer_delete_or_import_pub_key(app: &mut GossipUi, ui: &mut Ui) {

let pkhex: PublicKeyHex = pk.into();
ui.horizontal(|ui| {
ui.label(&format!("Public Key (Hex): {}", pkhex.as_str()));
ui.label(format!("Public Key (Hex): {}", pkhex.as_str()));
if ui.add(CopyButton::new()).clicked() {
ui.output_mut(|o| o.copied_text = pkhex.into_string());
}
});

let bech32 = pk.as_bech32_string();
ui.horizontal(|ui| {
ui.label(&format!("Public Key (bech32): {}", bech32));
ui.label(format!("Public Key (bech32): {}", bech32));
if ui.add(CopyButton::new()).clicked() {
ui.output_mut(|o| o.copied_text = bech32);
}
Expand Down
2 changes: 1 addition & 1 deletion gossip-lib/src/blossom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Blossom {
Err(e) => {
let text = String::from_utf8_lossy(&full);
tracing::error!("Failed to deserialize Blossom Blob Descriptor: {}", text);
return Err(e.into());
Err(e.into())
}
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions gossip-lib/src/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ impl Feed {
.read_arc()
.iter()
.copied()
.reduce(|acc, elem| xor_ids(acc, elem))
.reduce(xor_ids)
} else {
self.current_feed_events
.read_arc()
.iter()
.copied()
.reduce(|acc, elem| xor_ids(acc, elem))
.reduce(xor_ids)
}
}

Expand Down Expand Up @@ -404,7 +404,7 @@ impl Feed {
.db()
.get_people_in_list(list)?
.drain(..)
.map(|(pk, _)| pk.into())
.map(|(pk, _)| pk)
.collect();
filter.kinds = feed_displayable_event_kinds(false);
filter
Expand Down Expand Up @@ -439,7 +439,7 @@ impl Feed {
FeedKind::Person(person_pubkey) => {
let filter = {
let mut filter = Filter::new();
filter.authors = vec![person_pubkey.into()];
filter.authors = vec![person_pubkey];
filter.kinds = feed_displayable_event_kinds(false);
filter
};
Expand Down
6 changes: 3 additions & 3 deletions gossip-lib/src/overlord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ impl Overlord {
let mut tags: Vec<Tag> = Vec::new();
let blossom_servers = GLOBALS.db().read_setting_blossom_servers();
for server in blossom_servers.split_whitespace() {
tags.push(Tag::new(&["server", &server]));
tags.push(Tag::new(&["server", server]));
}

let pre_event = PreEvent {
Expand Down Expand Up @@ -2718,7 +2718,7 @@ impl Overlord {
// Subscribe to replies to root
if let Some(ref root_eref) = ancestors.root {
let filter_set = match root_eref {
EventReference::Id { id, .. } => FilterSet::RepliesToId((*id).into()),
EventReference::Id { id, .. } => FilterSet::RepliesToId(*id),
EventReference::Addr(naddr) => FilterSet::RepliesToAddr(naddr.clone()),
};
let relays = root_eref.copy_relays();
Expand Down Expand Up @@ -2773,7 +2773,7 @@ impl Overlord {
reason: RelayConnectionReason::ReadThread,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::Subscribe(FilterSet::RepliesToId(id.into())),
detail: ToMinionPayloadDetail::Subscribe(FilterSet::RepliesToId(id)),
},
}];

Expand Down
11 changes: 1 addition & 10 deletions gossip-lib/src/people/follow_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,12 @@ impl From<SortablePubkey> for PublicKey {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct FollowList {
pub who: Option<PublicKey>,
pub set: BTreeSet<SortablePubkey>,
}

impl Default for FollowList {
fn default() -> FollowList {
FollowList {
who: None,
set: BTreeSet::new(),
}
}
}

impl FollowList {
pub fn reset(&mut self, pubkey: PublicKey) {
self.who = Some(pubkey);
Expand Down
2 changes: 1 addition & 1 deletion gossip-lib/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async fn add_tags_mirroring_content(content: &str, tags: &mut Vec<Tag>, direct_m
// do nothing
}
ContentSegment::Hyperlink(span) => {
if let Some(slice) = shattered_content.slice(&span) {
if let Some(slice) = shattered_content.slice(span) {
if let Some(mimetype) = crate::media_url_mimetype(slice) {
add_imeta_tag(slice, mimetype, tags).await;
}
Expand Down
5 changes: 1 addition & 4 deletions gossip-lib/src/spam_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ fn inner_filter(event_params: EventParams) -> EventFilterAction {
return EventFilterAction::Allow;
}

let author = match PersonTable::read_record(pubkey, None) {
Ok(a) => a,
Err(_) => None,
};
let author = PersonTable::read_record(pubkey, None).unwrap_or_default();

let muted = GLOBALS.people.is_person_in_list(&pubkey, PersonList::Muted);

Expand Down
4 changes: 2 additions & 2 deletions gossip-lib/src/storage/event_tci_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ impl TciKey {
.position(|b| *b == b'\"')
.ok_or::<Error>(ErrorKind::KeyInvalid.into())?;
let mid = self.0.len() - 32 - std::mem::size_of::<i64>();
let tagname = String::from_utf8_lossy(&self.0[0..q]).to_owned();
let tagval = String::from_utf8_lossy(&self.0[q + 1..mid]).to_owned();
let tagname = String::from_utf8_lossy(&self.0[0..q]).into_owned();
let tagval = String::from_utf8_lossy(&self.0[q + 1..mid]).into_owned();
let created_at = Unixtime(
(u64::MAX - u64::from_be_bytes(self.0[mid..mid + 8].try_into().unwrap())) as i64,
);
Expand Down
7 changes: 5 additions & 2 deletions gossip-lib/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ impl Storage {

// Copy to backup file, compacting
tracing::info!("Compacting LMDB...");
if let Err(_) = env.copy_to_file(&backup, heed::CompactionOption::Enabled) {
if env
.copy_to_file(&backup, heed::CompactionOption::Enabled)
.is_err()
{
// Erase the attempt
std::fs::remove_file(&backup)?;

Expand Down Expand Up @@ -1942,7 +1945,7 @@ impl Storage {
if !output.is_empty() {
use std::cmp::Ordering;
let mut filter = Filter::new();
filter.ids = output.iter().map(|id| (*id).into()).collect();
filter.ids = output.to_vec();
let mut events = self.find_events_by_filter(&filter, |_| true)?;
events.sort_by(
|a, b| match (a.pubkey == event.pubkey, b.pubkey == event.pubkey) {
Expand Down
2 changes: 1 addition & 1 deletion gossip-lib/src/storage/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Storage {
}

// Load up to 6 of their events
filter.authors = vec![person.pubkey.into()];
filter.authors = vec![person.pubkey];
let events = match self.find_events_by_filter(&filter, |_| true) {
Ok(events) => events,
Err(_) => continue, // some error we can't handle right now
Expand Down
2 changes: 1 addition & 1 deletion gossip-lib/src/storage/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub struct TableIterator<'a, I: Record> {
phantom: std::marker::PhantomData<I>,
}

impl<'a, I: Record> Iterator for TableIterator<'a, I> {
impl<I: Record> Iterator for TableIterator<'_, I> {
type Item = (I::Key, I);

fn next(&mut self) -> Option<Self::Item> {
Expand Down
4 changes: 2 additions & 2 deletions gossip-lib/src/storage/types/relay3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ impl Relay3 {
let mut score = self.score();
if factors.connected {
if !GLOBALS.connected_relays.contains_key(&self.url) {
score = score / 2.0;
score /= 2.0;
}
}
if factors.success_count {
if self.success_count > 0 {
score = score * (self.success_count as f32).log10();
score *= (self.success_count as f32).log10();
} else {
score = 0.0;
}
Expand Down

0 comments on commit 609902a

Please sign in to comment.