mirror of
https://github.com/nostrlabs-io/notepush.git
synced 2025-06-22 05:42:50 +00:00
run cargo fmt --all
we should try to stick to rustfmt style, many editors save it like this by default. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@ -1,39 +1,37 @@
|
||||
use nostr::{self, key::PublicKey, TagKind::SingleLetter, Alphabet, SingleLetterTag};
|
||||
use nostr::{self, key::PublicKey, Alphabet, SingleLetterTag, TagKind::SingleLetter};
|
||||
|
||||
/// Temporary scaffolding of old methods that have not been ported to use native Event methods
|
||||
pub trait ExtendedEvent {
|
||||
/// Checks if the note references a given pubkey
|
||||
fn references_pubkey(&self, pubkey: &PublicKey) -> bool;
|
||||
fn references_pubkey(&self, pubkey: &PublicKey) -> bool;
|
||||
|
||||
/// Retrieves a set of pubkeys referenced by the note
|
||||
fn referenced_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey>;
|
||||
fn referenced_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey>;
|
||||
|
||||
/// Retrieves a set of pubkeys relevant to the note
|
||||
fn relevant_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey>;
|
||||
fn relevant_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey>;
|
||||
|
||||
/// Retrieves a set of event IDs referenced by the note
|
||||
fn referenced_event_ids(&self) -> std::collections::HashSet<nostr::EventId>;
|
||||
fn referenced_event_ids(&self) -> std::collections::HashSet<nostr::EventId>;
|
||||
}
|
||||
|
||||
// This is a wrapper around the Event type from strfry-policies, which adds some useful methods
|
||||
impl ExtendedEvent for nostr::Event {
|
||||
/// Checks if the note references a given pubkey
|
||||
fn references_pubkey(&self, pubkey: &PublicKey) -> bool {
|
||||
fn references_pubkey(&self, pubkey: &PublicKey) -> bool {
|
||||
self.referenced_pubkeys().contains(pubkey)
|
||||
}
|
||||
|
||||
/// Retrieves a set of pubkeys referenced by the note
|
||||
fn referenced_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey> {
|
||||
fn referenced_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey> {
|
||||
self.get_tags_content(SingleLetter(SingleLetterTag::lowercase(Alphabet::P)))
|
||||
.iter()
|
||||
.filter_map(|tag| {
|
||||
PublicKey::from_hex(tag).ok()
|
||||
})
|
||||
.filter_map(|tag| PublicKey::from_hex(tag).ok())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Retrieves a set of pubkeys relevant to the note
|
||||
fn relevant_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey> {
|
||||
fn relevant_pubkeys(&self) -> std::collections::HashSet<nostr::PublicKey> {
|
||||
let mut pubkeys = self.referenced_pubkeys();
|
||||
pubkeys.insert(self.pubkey.clone());
|
||||
pubkeys
|
||||
@ -43,9 +41,7 @@ impl ExtendedEvent for nostr::Event {
|
||||
fn referenced_event_ids(&self) -> std::collections::HashSet<nostr::EventId> {
|
||||
self.get_tag_content(SingleLetter(SingleLetterTag::lowercase(Alphabet::E)))
|
||||
.iter()
|
||||
.filter_map(|tag| {
|
||||
nostr::EventId::from_hex(tag).ok()
|
||||
})
|
||||
.filter_map(|tag| nostr::EventId::from_hex(tag).ok())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@ -54,14 +50,16 @@ impl ExtendedEvent for nostr::Event {
|
||||
|
||||
pub trait SqlStringConvertible {
|
||||
fn to_sql_string(&self) -> String;
|
||||
fn from_sql_string(s: String) -> Result<Self, Box<dyn std::error::Error>> where Self: Sized;
|
||||
fn from_sql_string(s: String) -> Result<Self, Box<dyn std::error::Error>>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
impl SqlStringConvertible for nostr::EventId {
|
||||
fn to_sql_string(&self) -> String {
|
||||
self.to_hex()
|
||||
}
|
||||
|
||||
|
||||
fn from_sql_string(s: String) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
nostr::EventId::from_hex(s).map_err(|e| e.into())
|
||||
}
|
||||
@ -71,7 +69,7 @@ impl SqlStringConvertible for nostr::PublicKey {
|
||||
fn to_sql_string(&self) -> String {
|
||||
self.to_hex()
|
||||
}
|
||||
|
||||
|
||||
fn from_sql_string(s: String) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
nostr::PublicKey::from_hex(s).map_err(|e| e.into())
|
||||
}
|
||||
@ -81,7 +79,7 @@ impl SqlStringConvertible for nostr::Timestamp {
|
||||
fn to_sql_string(&self) -> String {
|
||||
self.as_u64().to_string()
|
||||
}
|
||||
|
||||
|
||||
fn from_sql_string(s: String) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let u64_timestamp: u64 = s.parse()?;
|
||||
Ok(nostr::Timestamp::from(u64_timestamp))
|
||||
|
Reference in New Issue
Block a user