feat: improve event discovery

This commit is contained in:
reya
2024-05-18 08:16:05 +07:00
parent 60afbf090b
commit 99d9c70826
3 changed files with 17 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ export function Conversation({
className?: string; className?: string;
}) { }) {
const { ark } = useRouteContext({ strict: false }); const { ark } = useRouteContext({ strict: false });
const thread = ark.parse_event_thread(event.tags); const thread = ark.get_thread(event.tags);
return ( return (
<Note.Provider event={event}> <Note.Provider event={event}>

View File

@@ -1,10 +1,8 @@
import { import {
type Contact,
type Event, type Event,
type EventWithReplies, type EventWithReplies,
type Interests, type Interests,
type Keys, type Keys,
Kind,
type LumeColumn, type LumeColumn,
type Metadata, type Metadata,
type Settings, type Settings,
@@ -413,12 +411,19 @@ export class Ark {
} }
} }
public parse_event_thread(tags: string[][]) { public get_thread(tags: string[][]) {
let root: string = null; let root: string = null;
let reply: string = null; let reply: string = null;
// Get all event references from tags, ignore mention // Get all event references from tags, ignore mention
const events = tags.filter((el) => el[0] === "e" && el[3] !== "mention"); const events = tags.filter((el) => el[0] === "e" && el[3] !== "mention");
const relays = tags.filter((el) => el[0] === "e" && el[2].length);
if (relays.length >= 1) {
for (const relay of relays) {
if (relay[2]?.length) this.add_relay(relay[2]);
}
}
if (events.length === 1) { if (events.length === 1) {
root = events[0][1]; root = events[0][1];

View File

@@ -84,12 +84,17 @@ pub async fn list_connected_relays(state: State<'_, Nostr>) -> Result<Vec<Url>,
#[tauri::command] #[tauri::command]
pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> { pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
let client = &state.client; let client = &state.client;
if let Ok(_) = client.add_relay(relay).await { if let Ok(status) = client.add_relay(relay).await {
if status == true {
println!("connecting to relay: {}", relay);
let _ = client.connect_relay(relay); let _ = client.connect_relay(relay);
Ok(true) Ok(true)
} else { } else {
Ok(false) Ok(false)
} }
} else {
Ok(false)
}
} }
#[tauri::command] #[tauri::command]