feat: manually handle NIP-42 auth request (#132)

* improve fetch relays

* .

* .

* .

* refactor

* refactor

* remove identity

* manually auth

* auth

* prevent duplicate message

* clean up
This commit is contained in:
reya
2025-08-30 14:38:00 +07:00
committed by GitHub
parent 49a3dedd9c
commit 807851518a
33 changed files with 1810 additions and 1443 deletions
+4 -30
View File
@@ -1,7 +1,5 @@
use std::hash::Hash;
use chrono::{Local, TimeZone};
use gpui::SharedString;
use nostr_sdk::prelude::*;
#[derive(Debug, Clone)]
@@ -10,8 +8,8 @@ pub struct RenderedMessage {
/// Author's public key
pub author: PublicKey,
/// The content/text of the message
pub content: SharedString,
/// When the message was created
pub content: String,
/// Message created time as unix timestamp
pub created_at: Timestamp,
/// List of mentioned public keys in the message
pub mentions: Vec<PublicKey>,
@@ -27,7 +25,7 @@ impl From<Event> for RenderedMessage {
Self {
id: inner.id,
author: inner.pubkey,
content: inner.content.into(),
content: inner.content,
created_at: inner.created_at,
mentions,
replies_to,
@@ -44,7 +42,7 @@ impl From<UnsignedEvent> for RenderedMessage {
// Event ID must be known
id: inner.id.unwrap(),
author: inner.pubkey,
content: inner.content.into(),
content: inner.content,
created_at: inner.created_at,
mentions,
replies_to,
@@ -90,30 +88,6 @@ impl Hash for RenderedMessage {
}
}
impl RenderedMessage {
/// Returns a human-readable string representing how long ago the message was created
pub fn ago(&self) -> SharedString {
let input_time = match Local.timestamp_opt(self.created_at.as_u64() as i64, 0) {
chrono::LocalResult::Single(time) => time,
_ => return "Invalid timestamp".into(),
};
let now = Local::now();
let input_date = input_time.date_naive();
let now_date = now.date_naive();
let yesterday_date = (now - chrono::Duration::days(1)).date_naive();
let time_format = input_time.format("%H:%M %p");
match input_date {
date if date == now_date => format!("Today at {time_format}"),
date if date == yesterday_date => format!("Yesterday at {time_format}"),
_ => format!("{}, {time_format}", input_time.format("%d/%m/%y")),
}
.into()
}
}
fn extract_mentions(content: &str) -> Vec<PublicKey> {
let parser = NostrParser::new();
let tokens = parser.parse(content);