import { get } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; interface Message { created_at: number; } interface Note { created_at: number; seen: number; } export async function load({ parent, url }) { const { user } = await parent(); const username = url.searchParams.get("username"); if (user.username !== username) redirect(307, `/${username}`); const since = url.searchParams.get("since") || 0; let messages = []; let notes = []; if (user?.pubkey) { const { pubkey } = user; try { messages = await get(`/${pubkey}/${since}/messages`); messages = messages.sort((a: Message, b: Message) => b.created_at - a.created_at); } catch (e) { console.log("failed to fetch nostr messages", e); } try { notes = await get(`/${pubkey}/notes`); } catch (e) { console.log(`failed to fetch nostr notes for ${pubkey}`, e); } notes.map((e: Note) => { e.seen = e.created_at; }); } return { messages, notes }; }