diff options
| author | Adrien Hopkins <[email protected]> | 2025-12-17 11:14:57 -0500 |
|---|---|---|
| committer | Adrien Hopkins <[email protected]> | 2025-12-17 11:15:14 -0500 |
| commit | b210b348729cb243dbed4614acd4c237492f32d7 (patch) | |
| tree | b635b76d0dac3541dc2463042c7e4b18af4fa924 /src | |
| parent | 9616938096f8281204d11a5701e9372c0dfaf6b7 (diff) | |
| download | coinos-ui-b210b348729cb243dbed4614acd4c237492f32d7.tar.gz coinos-ui-b210b348729cb243dbed4614acd4c237492f32d7.zip | |
Use coinos username in DM homepage if available
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/nip01.ts (renamed from src/lib/nip05.ts) | 6 | ||||
| -rw-r--r-- | src/routes/(app)/dm/+page.svelte | 23 | ||||
| -rw-r--r-- | src/routes/(app)/dm/[recipient]/+page.svelte | 18 |
3 files changed, 29 insertions, 18 deletions
diff --git a/src/lib/nip05.ts b/src/lib/nip01.ts index e79bdb02..f7653fa4 100644 --- a/src/lib/nip05.ts +++ b/src/lib/nip01.ts @@ -1,13 +1,13 @@ import { PUBLIC_DM_RELAYS, PUBLIC_COINOS_RELAY } from '$env/static/public'; const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(','); -const NIP05_RELAYS = [ ...DM_RELAYS_LIST, PUBLIC_COINOS_RELAY ]; +const USERINFO_RELAYS = [ ...DM_RELAYS_LIST, PUBLIC_COINOS_RELAY ]; import { SimplePool } from 'nostr-tools/pool'; const pool = new SimplePool(); -export const getNip05 = async (pubkey: string) => { +export const getNostrUserInfo = async (pubkey: string) => { const events = await pool.querySync( - NIP05_RELAYS, { kinds: [0], limit: 1, authors: [pubkey] } + USERINFO_RELAYS, { kinds: [0], limit: 1, authors: [pubkey] } ); if (events.length == 0) { diff --git a/src/routes/(app)/dm/+page.svelte b/src/routes/(app)/dm/+page.svelte index 3e9d8629..31b083d7 100644 --- a/src/routes/(app)/dm/+page.svelte +++ b/src/routes/(app)/dm/+page.svelte @@ -2,16 +2,27 @@ import { isValid } from "nostr-tools/nip05"; import { t } from "$lib/translations"; import { pTagKeys } from '$lib/nostr'; - import { getNip05 } from '$lib/nip05'; + import { getNostrUserInfo } from '$lib/nip01'; import { getMessageRumours } from '$lib/nip17'; let { data } = $props(); const { user } = data; + const usernameFromPubkey = async (pubkey: string): string => { + const response = await fetch(`/api/users/${pubkey}`); + if (response.ok) { + const userInfo = await response.json(); + return userInfo.username; + } else { + return null; + } + } + const userInfo = async (pubkey: string) => { - const nip05Info = await getNip05(pubkey); - const valid = await isValid(pubkey, nip05Info.nip05); - return { name: nip05Info.name, nip05: nip05Info.nip05, valid }; + const nostrUserInfo = await getNostrUserInfo(pubkey); + const valid = await isValid(pubkey, nostrUserInfo.nip05); + const username = await usernameFromPubkey(pubkey); + return { name: username || nostrUserInfo.name, nip05: nostrUserInfo.nip05, valid }; } const updateSendersRecipients = async (rumours: object[]) => { @@ -51,14 +62,14 @@ <p>The following people have sent messages to you:</p> <ul> {#each messageSenders as sender} - <li class={sender.valid ? "" : "invalid"}>{sender.name}{#if sender.valid} ✓{/if}</li> + <li>{sender.name} (<span class={sender.valid ? "" : "invalid"}>{sender.nip05}</span>{#if sender.valid} ✓{/if})</li> {/each} </ul> <p>The following people have received messages from you:</p> <ul> {#each messageRecipients as recipient} - <li class={recipient.valid ? "" : "invalid"}>{recipient.name}{#if recipient.valid} ✓{/if}</li> + <li>{recipient.name} (<span class={recipient.valid ? "" : "invalid"}>{recipient.nip05}</span>{#if recipient.valid} ✓{/if})</li> {/each} </ul> </div> diff --git a/src/routes/(app)/dm/[recipient]/+page.svelte b/src/routes/(app)/dm/[recipient]/+page.svelte index 787796bd..388503b5 100644 --- a/src/routes/(app)/dm/[recipient]/+page.svelte +++ b/src/routes/(app)/dm/[recipient]/+page.svelte @@ -7,7 +7,7 @@ import { isValid } from "nostr-tools/nip05"; import * as toolsnip17 from 'nostr-tools/nip17'; - import { getNip05 } from '$lib/nip05'; + import { getNostrUserInfo } from '$lib/nip01'; import { relaysSupporting } from '$lib/nip11'; import * as libnip17 from '$lib/nip17'; import { sign, getPrivateKey } from '$lib/nostr'; @@ -27,14 +27,14 @@ let expiryDays = $state(7); let canSend = $state(false); let canSendExpiring = $state(false); - let nip05info = $state({}); + let nostrUserInfo = $state({}); const userInfo = async (pubkey: string) => { - const nip05Info = await getNip05(pubkey); - const valid = await isValid(pubkey, nip05Info.nip05); - return { name: nip05Info.name, nip05: nip05Info.nip05, valid }; + const nostrUserInfo = await getNostrUserInfo(pubkey); + const valid = await isValid(pubkey, nostrUserInfo.nip05); + return { name: nostrUserInfo.name, nip05: nostrUserInfo.nip05, valid }; } - userInfo(recipient.pubkey).then(info => nip05info = info); + userInfo(recipient.pubkey).then(info => nostrUserInfo = info); const appendMultimap = (map: Map, key: string, value: object) => { if (map.has(key)) { @@ -179,9 +179,9 @@ <div class="container"> <div class="space-y-2 mx-auto space-y-5 lg:max-w-xl xl:max-w-2xl lg:pl-10 mt-5 lg:mt-0"> - <h1><a class="text-3xl" href="/{recipient.username}">{recipient.username}</a> - {#if nip05info.nip05} - <span class={"secondary timestamp text-small" + (nip05info.valid ? "" : " invalid")} title="Pubkey: {recipient.pubkey}">{nip05info.nip05}</span> + <h1><a class="text-3xl" href="/{recipient.username}">{recipient.username || nostrUserInfo.name}</a> + {#if nostrUserInfo.nip05} + <span class={"secondary timestamp text-small" + (nostrUserInfo.valid ? "" : " invalid")} title="Pubkey: {recipient.pubkey}">{nostrUserInfo.nip05}</span> {/if} </h1> |
