diff --git a/src/app/components/ChannelMessage.svelte b/src/app/components/ChannelMessage.svelte index d26b6de..d23dec8 100644 --- a/src/app/components/ChannelMessage.svelte +++ b/src/app/components/ChannelMessage.svelte @@ -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 @@
{#if showPubkey} {:else}
diff --git a/src/app/components/Chat.svelte b/src/app/components/Chat.svelte index 717251d..48824a3 100644 --- a/src/app/components/Chat.svelte +++ b/src/app/components/Chat.svelte @@ -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" diff --git a/src/app/components/ChatMessage.svelte b/src/app/components/ChatMessage.svelte index b96ba94..d954985 100644 --- a/src/app/components/ChatMessage.svelte +++ b/src/app/components/ChatMessage.svelte @@ -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}
diff --git a/src/app/components/ContentMention.svelte b/src/app/components/ContentMention.svelte index 9d92775..d29ff28 100644 --- a/src/app/components/ContentMention.svelte +++ b/src/app/components/ContentMention.svelte @@ -1,11 +1,10 @@ diff --git a/src/app/components/Profile.svelte b/src/app/components/Profile.svelte index 839cb33..5bc4c48 100644 --- a/src/app/components/Profile.svelte +++ b/src/app/components/Profile.svelte @@ -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 @@
diff --git a/src/app/components/ProfileCircle.svelte b/src/app/components/ProfileCircle.svelte index 94304a4..2606e00 100644 --- a/src/app/components/ProfileCircle.svelte +++ b/src/app/components/ProfileCircle.svelte @@ -1,6 +1,6 @@ - + diff --git a/src/app/components/ProfileDetail.svelte b/src/app/components/ProfileDetail.svelte index 04e3f7c..bcdf964 100644 --- a/src/app/components/ProfileDetail.svelte +++ b/src/app/components/ProfileDetail.svelte @@ -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 @@
- +
- {$aliasDisplay} + {$display}
diff --git a/src/app/components/ProfileEditForm.svelte b/src/app/components/ProfileEditForm.svelte index ff75253..13288e2 100644 --- a/src/app/components/ProfileEditForm.svelte +++ b/src/app/components/ProfileEditForm.svelte @@ -91,8 +91,8 @@ {/snippet} {#snippet info()}

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

{/snippet} diff --git a/src/app/components/ProfileInfo.svelte b/src/app/components/ProfileInfo.svelte index 0fca5f7..904784a 100644 --- a/src/app/components/ProfileInfo.svelte +++ b/src/app/components/ProfileInfo.svelte @@ -1,6 +1,6 @@ -{#if $alias?.profile} - +{#if $profile} + {/if} diff --git a/src/app/state.ts b/src/app/state.ts index 32a3397..a559aeb 100644 --- a/src/app/state.ts +++ b/src/app/state.ts @@ -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 diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index df6e242..3918556 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -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" diff --git a/src/routes/settings/profile/+page.svelte b/src/routes/settings/profile/+page.svelte index ca293ce..2553635 100644 --- a/src/routes/settings/profile/+page.svelte +++ b/src/routes/settings/profile/+page.svelte @@ -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 @@
- +
- {displayProfile($alias?.profile, pubkeyDisplay)} + {displayProfile($profile, pubkeyDisplay)}
- {$alias?.profile?.nip05 ? displayNip05($alias?.profile.nip05) : pubkeyDisplay} + {$profile?.nip05 ? displayNip05($profile.nip05) : pubkeyDisplay}
@@ -56,8 +56,8 @@
- {#key $alias?.profile?.about} - + {#key $profile?.about} + {/key}
{#if $session?.email}