chore: follow up on #172 (#173)

* clean up

* wip

* clean up

* remove unused picture field
This commit is contained in:
reya
2025-10-01 13:45:13 +07:00
committed by GitHub
parent 0db48bc003
commit ebcc60cd92
12 changed files with 273 additions and 333 deletions

View File

@@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::hash::{DefaultHasher, Hash, Hasher};
use itertools::Itertools;
@@ -7,26 +6,14 @@ use nostr_sdk::prelude::*;
pub trait EventUtils {
fn uniq_id(&self) -> u64;
fn all_pubkeys(&self) -> Vec<PublicKey>;
fn compare_pubkeys(&self, other: &[PublicKey]) -> bool;
}
impl EventUtils for Event {
fn uniq_id(&self) -> u64 {
let mut hasher = DefaultHasher::new();
let mut pubkeys: Vec<PublicKey> = vec![];
// Add all public keys from event
pubkeys.push(self.pubkey);
pubkeys.extend(self.tags.public_keys().collect::<Vec<_>>());
// Generate unique hash
pubkeys
.into_iter()
.unique()
.sorted()
.collect::<Vec<_>>()
.hash(&mut hasher);
let mut pubkeys: Vec<PublicKey> = self.all_pubkeys();
pubkeys.sort();
pubkeys.hash(&mut hasher);
hasher.finish()
}
@@ -34,15 +21,7 @@ impl EventUtils for Event {
let mut public_keys: Vec<PublicKey> = self.tags.public_keys().copied().collect();
public_keys.push(self.pubkey);
public_keys
}
fn compare_pubkeys(&self, other: &[PublicKey]) -> bool {
let pubkeys = self.all_pubkeys();
let a: HashSet<_> = pubkeys.iter().collect();
let b: HashSet<_> = other.iter().collect();
a == b
public_keys.into_iter().unique().collect()
}
}
@@ -72,12 +51,4 @@ impl EventUtils for UnsignedEvent {
public_keys
}
fn compare_pubkeys(&self, other: &[PublicKey]) -> bool {
let pubkeys = self.all_pubkeys();
let a: HashSet<_> = pubkeys.iter().collect();
let b: HashSet<_> = other.iter().collect();
a == b
}
}