wip: refactor

This commit is contained in:
2025-01-10 10:39:51 +07:00
parent 80506b72d9
commit 38d0061796
6 changed files with 533 additions and 314 deletions

View File

@@ -1,23 +1,14 @@
use chrono::{Duration, Local, TimeZone};
use nostr_sdk::prelude::*;
use std::hash::{DefaultHasher, Hash, Hasher};
pub fn get_room_id(author: &PublicKey, tags: &Tags) -> String {
// Get all public keys
let mut pubkeys: Vec<PublicKey> = tags.public_keys().copied().collect();
// Add author to public keys list
pubkeys.insert(0, *author);
pub fn room_hash(tags: &Tags) -> u64 {
let pubkeys: Vec<PublicKey> = tags.public_keys().copied().collect();
let mut hasher = DefaultHasher::new();
// Generate unique hash
pubkeys.hash(&mut hasher);
let hex: Vec<String> = pubkeys
.iter()
.map(|m| {
let hex = m.to_hex();
let split = &hex[..6];
split.to_owned()
})
.collect();
hex.join("-")
hasher.finish()
}
pub fn show_npub(public_key: PublicKey, len: usize) -> String {