From b210b348729cb243dbed4614acd4c237492f32d7 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Wed, 17 Dec 2025 11:14:57 -0500 Subject: Use coinos username in DM homepage if available --- src/routes/(app)/dm/+page.svelte | 23 +++++++++++++++++------ src/routes/(app)/dm/[recipient]/+page.svelte | 18 +++++++++--------- 2 files changed, 26 insertions(+), 15 deletions(-) (limited to 'src/routes') 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 @@

The following people have sent messages to you:

The following people have received messages from you:

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 @@
-

{recipient.username} - {#if nip05info.nip05} - {nip05info.nip05} +

{recipient.username || nostrUserInfo.name} + {#if nostrUserInfo.nip05} + {nostrUserInfo.nip05} {/if}

-- cgit v1.2.3