Use new ALIAS kind

This commit is contained in:
Jon Staab
2025-04-15 15:45:48 -07:00
parent 374ca7f265
commit f3debe6c02
12 changed files with 67 additions and 87 deletions

View File

@@ -20,7 +20,7 @@
import ChannelMessageEmojiButton from "@app/components/ChannelMessageEmojiButton.svelte"
import ChannelMessageMenuButton from "@app/components/ChannelMessageMenuButton.svelte"
import ChannelMessageMenuMobile from "@app/components/ChannelMessageMenuMobile.svelte"
import {colors, deriveAlias, deriveAliasDisplay} from "@app/state"
import {colors, deriveAliasedProfile, deriveAliasDisplay} from "@app/state"
import {publishDelete, publishReaction} from "@app/commands"
import {pushModal} from "@app/modal"
@@ -37,7 +37,7 @@
const thunk = $thunks[event.id]
const today = formatTimestampAsDate(now())
const alias = deriveAlias(event.pubkey, url)
const profile = deriveAliasedProfile(event.pubkey, url)
const aliasDisplay = deriveAliasDisplay(event.pubkey, url)
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
const hideMenuButton = $derived($thunk && !thunkIsComplete($thunk))
@@ -66,10 +66,7 @@
<div class="flex w-full gap-3 overflow-auto">
{#if showPubkey}
<Button onclick={openProfile} class="flex items-start">
<Avatar
src={$alias?.profile?.picture}
class="border border-solid border-base-content"
size={8} />
<Avatar src={$profile?.picture} class="border border-solid border-base-content" size={8} />
</Button>
{:else}
<div class="w-8 min-w-8 max-w-8"></div>

View File

@@ -2,12 +2,10 @@
import type {Snippet} from "svelte"
import {onMount} from "svelte"
import {int, nthNe, MINUTE, sortBy, remove} from "@welshman/lib"
import {load} from "@welshman/net"
import type {TrustedEvent, EventContent} from "@welshman/util"
import {createEvent, DIRECT_MESSAGE, INBOX_RELAYS} from "@welshman/util"
import {
pubkey,
Router,
tagPubkey,
loadUsingOutbox,
formatTimestampAsDate,
@@ -28,7 +26,13 @@
import ChatMessage from "@app/components/ChatMessage.svelte"
import ChatCompose from "@app/components/ChannelCompose.svelte"
import ChatComposeParent from "@app/components/ChannelComposeParent.svelte"
import {INDEXER_RELAYS, userSettingValues, deriveChat, splitChatId, PLATFORM_NAME} from "@app/state"
import {
INDEXER_RELAYS,
userSettingValues,
deriveChat,
splitChatId,
PLATFORM_NAME,
} from "@app/state"
import {pushModal} from "@app/modal"
import {sendWrapped, prependParent} from "@app/commands"

View File

@@ -2,7 +2,13 @@
import {type Instance} from "tippy.js"
import {hash} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
import {thunks, formatTimestampAsTime, pubkey} from "@welshman/app"
import {
thunks,
formatTimestampAsTime,
pubkey,
deriveProfile,
deriveProfileDisplay,
} from "@welshman/app"
import {isMobile} from "@lib/html"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
@@ -15,7 +21,7 @@
import ProfileDetail from "@app/components/ProfileDetail.svelte"
import ChatMessageMenu from "@app/components/ChatMessageMenu.svelte"
import ChatMessageMenuMobile from "@app/components/ChatMessageMenuMobile.svelte"
import {colors, deriveAlias, deriveAliasDisplay} from "@app/state"
import {colors} from "@app/state"
import {makeDelete, makeReaction, sendWrapped} from "@app/commands"
import {pushModal} from "@app/modal"
@@ -30,8 +36,8 @@
const thunk = $thunks[event.id]
const isOwn = event.pubkey === $pubkey
const alias = deriveAlias(event.pubkey)
const aliasDisplay = deriveAliasDisplay(event.pubkey)
const profile = deriveProfile(event.pubkey)
const profileDisplay = deriveProfileDisplay(event.pubkey)
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
const reply = () => replyTo(event)
@@ -101,12 +107,12 @@
{#if !isOwn}
<Button onclick={openProfile} class="flex items-center gap-1">
<Avatar
src={$alias?.profile?.picture}
src={$profile?.picture}
class="border border-solid border-base-content"
size={4} />
<div class="flex items-center gap-2">
<Button onclick={openProfile} class="text-sm font-bold" style="color: {colorValue}">
{$aliasDisplay}
{$profileDisplay}
</Button>
</div>
</Button>

View File

@@ -1,11 +1,10 @@
<script lang="ts">
import type {ProfilePointer} from "@welshman/content"
import {displayProfile} from "@welshman/util"
import {deriveProfile} from "@welshman/app"
import Button from "@lib/components/Button.svelte"
import ProfileDetail from "@app/components/ProfileDetail.svelte"
import {pushModal} from "@app/modal"
import {deriveAlias} from "@app/state"
import {deriveAliasedProfile} from "@app/state"
type Props = {
value: ProfilePointer
@@ -14,11 +13,11 @@
const {value, url}: Props = $props()
const alias = deriveAlias(value.pubkey, url)
const profile = deriveAliasedProfile(value.pubkey, url)
const openProfile = () => pushModal(ProfileDetail, {pubkey: value.pubkey, url})
</script>
<Button onclick={openProfile} class="link-content">
@{displayProfile($alias?.profile)}
@{displayProfile($profile)}
</Button>

View File

@@ -12,7 +12,7 @@
import WotScore from "@lib/components/WotScore.svelte"
import ProfileDetail from "@app/components/ProfileDetail.svelte"
import {pushModal} from "@app/modal"
import {deriveAlias, deriveAliasDisplay} from "@app/state"
import {deriveAliasedProfile, deriveAliasDisplay} from "@app/state"
type Props = {
pubkey: string
@@ -21,7 +21,7 @@
const {pubkey, url}: Props = $props()
const alias = deriveAlias(pubkey, url)
const profile = deriveAliasedProfile(pubkey, url)
const aliasDisplay = deriveAliasDisplay(pubkey, url)
const handle = deriveHandleForPubkey(pubkey)
const score = deriveUserWotScore(pubkey)
@@ -35,7 +35,7 @@
<div class="flex max-w-full gap-3">
<Button onclick={openProfile} class="py-1">
<Avatar src={$alias?.profile?.picture} size={10} />
<Avatar src={$profile?.picture} size={10} />
</Button>
<div class="flex min-w-0 flex-col">
<div class="flex items-center gap-2">

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import Avatar from "@lib/components/Avatar.svelte"
import {deriveAlias} from "@app/state"
import {deriveAliasedProfile} from "@app/state"
type Props = {
pubkey: string
@@ -9,7 +9,7 @@
const {pubkey, url, ...props}: Props = $props()
const alias = deriveAlias(pubkey, url)
const profile = deriveAliasedProfile(pubkey, url)
</script>
<Avatar src={$alias?.profile?.picture} icon="user-circle" {...props} />
<Avatar src={$profile?.picture} icon="user-circle" {...props} />

View File

@@ -16,7 +16,7 @@
import ModalFooter from "@lib/components/ModalFooter.svelte"
import ProfileInfo from "@app/components/ProfileInfo.svelte"
import ChatEnable from "@app/components/ChatEnable.svelte"
import {canDecrypt, pubkeyLink, deriveAlias, deriveAliasDisplay} from "@app/state"
import {canDecrypt, pubkeyLink, deriveAliasedProfile, deriveAliasDisplay} from "@app/state"
import {pushModal} from "@app/modal"
import {makeChatPath} from "@app/routes"
@@ -27,8 +27,8 @@
const {pubkey, url}: Props = $props()
const alias = deriveAlias(pubkey, url)
const aliasDisplay = deriveAliasDisplay(pubkey, url)
const profile = deriveAliasedProfile(pubkey, url)
const display = deriveAliasDisplay(pubkey, url)
const handle = deriveHandleForPubkey(pubkey)
const score = deriveUserWotScore(pubkey)
@@ -46,12 +46,12 @@
<div class="column gap-4">
<div class="flex max-w-full gap-3">
<span class="py-1">
<Avatar src={$alias?.profile?.picture} size={10} />
<Avatar src={$profile?.picture} size={10} />
</span>
<div class="flex min-w-0 flex-col">
<div class="flex items-center gap-2">
<span class="text-bold overflow-hidden text-ellipsis">
{$aliasDisplay}
{$display}
</span>
<WotScore score={$score} active={following} />
</div>

View File

@@ -91,8 +91,8 @@
{/snippet}
{#snippet info()}
<p>
If enabled, changes will be published to the broader nostr network in addition to
spaces you are a member of.
If enabled, changes will be published to the broader nostr network in addition to spaces you
are a member of.
</p>
{/snippet}
</FieldInline>

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import Content from "@app/components/Content.svelte"
import {deriveAlias} from "@app/state"
import {deriveAliasedProfile} from "@app/state"
export type Props = {
pubkey: string
@@ -9,9 +9,9 @@
const {pubkey, url}: Props = $props()
const alias = deriveAlias(pubkey, url)
const profile = deriveAliasedProfile(pubkey, url)
</script>
{#if $alias?.profile}
<Content event={{content: $alias.profile.about, tags: []}} hideMediaAtDepth={0} />
{#if $profile}
<Content event={{content: $profile.about, tags: []}} hideMediaAtDepth={0} />
{/if}

View File

@@ -1,5 +1,5 @@
import twColors from "tailwindcss/colors"
import {get, derived, writable} from "svelte/store"
import {get, derived, readable, writable} from "svelte/store"
import * as nip19 from "nostr-tools/nip19"
import {
remove,
@@ -16,6 +16,7 @@ import {
addToMapKey,
identity,
always,
omit,
} from "@welshman/lib"
import {load} from "@welshman/net"
import {
@@ -31,7 +32,6 @@ import {
GROUPS,
THREAD,
COMMENT,
PROFILE,
getGroupTags,
getRelayTagValues,
getPubkeyTagValues,
@@ -44,7 +44,6 @@ import {
normalizeRelayUrl,
displayPubkey,
} from "@welshman/util"
import {LOCAL_RELAY_URL} from "@welshman/relay"
import type {TrustedEvent, Profile, SignedEvent, PublishedList, List, Filter} from "@welshman/util"
import {Nip59, decrypt} from "@welshman/signer"
import {
@@ -82,6 +81,8 @@ export const GENERAL = "_"
export const PROTECTED = ["-"]
export const ALIAS = 11000
export const ALERT = 32830
export const ALERT_STATUS = 32831
@@ -401,7 +402,7 @@ export const loadAliasByKey = makeCachedLoader({
return load({
relays: [url],
filters: [{kinds: [PROFILE], authors: [pubkey]}],
filters: [{kinds: [ALIAS], authors: [pubkey]}],
onEvent: (event: TrustedEvent) => {
const profile = readProfile(event)
@@ -416,50 +417,23 @@ export const loadAliasByKey = makeCachedLoader({
})
export const deriveAlias = (pubkey: string, url?: string) => {
const membershipUrls = getMembershipUrls(userMembership.get())
if (!url) return readable(undefined)
// Attempt to load all relevant aliases
for (const $url of [url, ...membershipUrls]) {
if ($url) {
const key = encodeAliasKey(pubkey, $url)
const key = encodeAliasKey(pubkey, url)
loadAliasByKey(key)
}
}
loadAliasByKey(key)
return derived([aliasesByKey, deriveProfile(pubkey)], ([$aliasesByKey, $profile]) => {
// Try to find an alias for the url we were asked about
if (url) {
const alias = $aliasesByKey.get(encodeAliasKey(pubkey, url))
if (alias) {
return alias
}
}
// Fall back to global profiles
if ($profile) {
return {
pubkey,
url: LOCAL_RELAY_URL,
profile: $profile,
}
}
// Fall back to other aliases we know about
for (const $url of membershipUrls) {
const alias = $aliasesByKey.get(encodeAliasKey(pubkey, $url))
if (alias) {
return alias
}
}
})
return derived(aliasesByKey, $aliasesByKey => $aliasesByKey.get(key))
}
export const deriveAliasedProfile = (pubkey: string, url?: string) =>
derived([deriveProfile(pubkey), deriveAlias(pubkey, url)], ([$profile, $alias]) =>
omit(["event"], {...$profile, ...$alias}),
)
export const deriveAliasDisplay = (pubkey: string, url?: string) =>
derived(deriveAlias(pubkey, url), $alias =>
displayProfile($alias?.profile, displayPubkey(pubkey)),
derived(deriveAliasedProfile(pubkey, url), $profile =>
displayProfile($profile, displayPubkey(pubkey)),
)
// Membership

View File

@@ -9,7 +9,7 @@
import {bytesToHex, hexToBytes} from "@noble/hashes/utils"
import {identity, memoize, sleep, defer, ago, WEEK, TaskQueue} from "@welshman/lib"
import type {TrustedEvent, StampedEvent} from "@welshman/util"
import {WRAP, PROFILE, getTag} from "@welshman/util"
import {WRAP} from "@welshman/util"
import {Nip46Broker, makeSecret} from "@welshman/signer"
import type {Socket} from "@welshman/net"
import {request, defaultSocketPolicies, makeSocketPolicyAuth} from "@welshman/net"

View File

@@ -2,7 +2,7 @@
import * as nip19 from "nostr-tools/nip19"
import {hexToBytes} from "@noble/hashes/utils"
import {displayPubkey, displayProfile} from "@welshman/util"
import {pubkey, session, displayNip05} from "@welshman/app"
import {pubkey, session, displayNip05, deriveProfile} from "@welshman/app"
import {slideAndFade} from "@lib/transition"
import Icon from "@lib/components/Icon.svelte"
import FieldInline from "@lib/components/FieldInline.svelte"
@@ -13,11 +13,11 @@
import ProfileDelete from "@app/components/ProfileDelete.svelte"
import InfoKeys from "@app/components/InfoKeys.svelte"
import Alerts from "@app/components/Alerts.svelte"
import {PLATFORM_NAME, deriveAlias} from "@app/state"
import {PLATFORM_NAME} from "@app/state"
import {pushModal} from "@app/modal"
import {clip} from "@app/toast"
const alias = deriveAlias($pubkey!)
const profile = deriveProfile($pubkey!)
const pubkeyDisplay = displayPubkey($pubkey!)
@@ -39,16 +39,16 @@
<div class="flex justify-between gap-2">
<div class="flex max-w-full gap-3">
<div class="py-1">
<Avatar src={$alias?.profile?.picture} size={10} />
<Avatar src={$profile?.picture} size={10} />
</div>
<div class="flex min-w-0 flex-col">
<div class="flex items-center gap-2">
<div class="text-bold overflow-hidden text-ellipsis">
{displayProfile($alias?.profile, pubkeyDisplay)}
{displayProfile($profile, pubkeyDisplay)}
</div>
</div>
<div class="overflow-hidden text-ellipsis text-sm opacity-75">
{$alias?.profile?.nip05 ? displayNip05($alias?.profile.nip05) : pubkeyDisplay}
{$profile?.nip05 ? displayNip05($profile.nip05) : pubkeyDisplay}
</div>
</div>
</div>
@@ -56,8 +56,8 @@
<Icon icon="pen-new-square" />
</Button>
</div>
{#key $alias?.profile?.about}
<Content event={{content: $alias?.profile?.about || "", tags: []}} hideMediaAtDepth={0} />
{#key $profile?.about}
<Content event={{content: $profile?.about || "", tags: []}} hideMediaAtDepth={0} />
{/key}
</div>
{#if $session?.email}