wip: refactor

This commit is contained in:
2025-01-11 15:40:35 +07:00
parent 08980e55a4
commit ef839102d4
7 changed files with 175 additions and 158 deletions

View File

@@ -1,6 +1,9 @@
use chrono::{Duration, Local, TimeZone};
use nostr_sdk::prelude::*;
use std::hash::{DefaultHasher, Hash, Hasher};
use std::{
collections::HashSet,
hash::{DefaultHasher, Hash, Hasher},
};
pub fn room_hash(tags: &Tags) -> u64 {
let pubkeys: Vec<PublicKey> = tags.public_keys().copied().collect();
@@ -11,6 +14,16 @@ pub fn room_hash(tags: &Tags) -> u64 {
hasher.finish()
}
pub fn compare<T>(a: &[T], b: &[T]) -> bool
where
T: Eq + Hash,
{
let a: HashSet<_> = a.iter().collect();
let b: HashSet<_> = b.iter().collect();
a == b
}
pub fn shorted_public_key(public_key: PublicKey) -> String {
let pk = public_key.to_string();
format!("{}:{}", &pk[0..4], &pk[pk.len() - 4..])