Remove aliases, their time has not yet come

This commit is contained in:
Jon Staab
2025-04-16 10:36:21 -07:00
parent f3debe6c02
commit 303b8967e9
10 changed files with 41 additions and 93 deletions
+6 -4
View File
@@ -7,6 +7,8 @@
formatTimestampAsDate,
formatTimestampAsTime,
thunkIsComplete,
deriveProfile,
deriveProfileDisplay,
} from "@welshman/app"
import {isMobile} from "@lib/html"
import TapTarget from "@lib/components/TapTarget.svelte"
@@ -20,7 +22,7 @@
import ChannelMessageEmojiButton from "@app/components/ChannelMessageEmojiButton.svelte"
import ChannelMessageMenuButton from "@app/components/ChannelMessageMenuButton.svelte"
import ChannelMessageMenuMobile from "@app/components/ChannelMessageMenuMobile.svelte"
import {colors, deriveAliasedProfile, deriveAliasDisplay} from "@app/state"
import {colors} from "@app/state"
import {publishDelete, publishReaction} from "@app/commands"
import {pushModal} from "@app/modal"
@@ -37,8 +39,8 @@
const thunk = $thunks[event.id]
const today = formatTimestampAsDate(now())
const profile = deriveAliasedProfile(event.pubkey, url)
const aliasDisplay = deriveAliasDisplay(event.pubkey, url)
const profile = deriveProfile(event.pubkey, [url])
const profileDisplay = deriveProfileDisplay(event.pubkey, [url])
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
const hideMenuButton = $derived($thunk && !thunkIsComplete($thunk))
@@ -75,7 +77,7 @@
{#if showPubkey}
<div class="flex items-center gap-2">
<Button onclick={openProfile} class="text-sm font-bold" style="color: {colorValue}">
{$aliasDisplay}
{$profileDisplay}
</Button>
<span class="text-xs opacity-50">
{#if formatTimestampAsDate(event.created_at) === today}
+3 -2
View File
@@ -1,10 +1,11 @@
<script lang="ts">
import {removeNil} from "@welshman/lib"
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 {deriveAliasedProfile} from "@app/state"
type Props = {
value: ProfilePointer
@@ -13,7 +14,7 @@
const {value, url}: Props = $props()
const profile = deriveAliasedProfile(value.pubkey, url)
const profile = deriveProfile(value.pubkey, removeNil([url]))
const openProfile = () => pushModal(ProfileDetail, {pubkey: value.pubkey, url})
</script>
+7 -4
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import {removeNil} from "@welshman/lib"
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
import {
session,
@@ -6,13 +7,14 @@
deriveUserWotScore,
deriveHandleForPubkey,
displayHandle,
deriveProfile,
deriveProfileDisplay,
} from "@welshman/app"
import Button from "@lib/components/Button.svelte"
import Avatar from "@lib/components/Avatar.svelte"
import WotScore from "@lib/components/WotScore.svelte"
import ProfileDetail from "@app/components/ProfileDetail.svelte"
import {pushModal} from "@app/modal"
import {deriveAliasedProfile, deriveAliasDisplay} from "@app/state"
type Props = {
pubkey: string
@@ -21,8 +23,9 @@
const {pubkey, url}: Props = $props()
const profile = deriveAliasedProfile(pubkey, url)
const aliasDisplay = deriveAliasDisplay(pubkey, url)
const relays = removeNil([url])
const profile = deriveProfile(pubkey, relays)
const profileDisplay = deriveProfileDisplay(pubkey, relays)
const handle = deriveHandleForPubkey(pubkey)
const score = deriveUserWotScore(pubkey)
@@ -40,7 +43,7 @@
<div class="flex min-w-0 flex-col">
<div class="flex items-center gap-2">
<Button onclick={openProfile} class="text-bold overflow-hidden text-ellipsis">
{$aliasDisplay}
{$profileDisplay}
</Button>
<WotScore score={$score} active={following} />
</div>
+3 -2
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import Avatar from "@lib/components/Avatar.svelte"
import {deriveAliasedProfile} from "@app/state"
import {removeNil} from "@welshman/lib"
import {deriveProfile} from "@welshman/app"
type Props = {
pubkey: string
@@ -9,7 +10,7 @@
const {pubkey, url, ...props}: Props = $props()
const profile = deriveAliasedProfile(pubkey, url)
const profile = deriveProfile(pubkey, removeNil([url]))
</script>
<Avatar src={$profile?.picture} icon="user-circle" {...props} />
+7 -3
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import {goto} from "$app/navigation"
import {removeNil} from "@welshman/lib"
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
import {
session,
@@ -7,6 +8,8 @@
deriveUserWotScore,
deriveHandleForPubkey,
displayHandle,
deriveProfile,
deriveProfileDisplay,
} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
import Link from "@lib/components/Link.svelte"
@@ -16,7 +19,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, deriveAliasedProfile, deriveAliasDisplay} from "@app/state"
import {canDecrypt, pubkeyLink} from "@app/state"
import {pushModal} from "@app/modal"
import {makeChatPath} from "@app/routes"
@@ -27,8 +30,9 @@
const {pubkey, url}: Props = $props()
const profile = deriveAliasedProfile(pubkey, url)
const display = deriveAliasDisplay(pubkey, url)
const relays = removeNil([url])
const profile = deriveProfile(pubkey, relays)
const display = deriveProfileDisplay(pubkey, relays)
const handle = deriveHandleForPubkey(pubkey)
const score = deriveUserWotScore(pubkey)
+3 -2
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import {removeNil} from "@welshman/lib"
import {deriveProfile} from "@welshman/app"
import Content from "@app/components/Content.svelte"
import {deriveAliasedProfile} from "@app/state"
export type Props = {
pubkey: string
@@ -9,7 +10,7 @@
const {pubkey, url}: Props = $props()
const profile = deriveAliasedProfile(pubkey, url)
const profile = deriveProfile(pubkey, removeNil([url]))
</script>
{#if $profile}
+4 -3
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import {deriveAliasDisplay} from "@app/state"
import {removeNil} from "@welshman/lib"
import {deriveProfileDisplay} from "@welshman/app"
type Props = {
pubkey: string
@@ -8,7 +9,7 @@
const {pubkey, url}: Props = $props()
const aliasDisplay = deriveAliasDisplay(pubkey, url)
const profileDisplay = deriveProfileDisplay(pubkey, removeNil([url]))
</script>
{$aliasDisplay}
{$profileDisplay}
+3 -2
View File
@@ -1,11 +1,12 @@
import type {NodeViewProps} from "@tiptap/core"
import {deriveAliasDisplay} from "@app/state"
import {removeNil} from "@welshman/lib"
import {deriveProfileDisplay} from "@welshman/app"
export const makeMentionNodeView =
(url?: string) =>
({node}: NodeViewProps) => {
const dom = document.createElement("span")
const display = deriveAliasDisplay(node.attrs.pubkey, url)
const display = deriveProfileDisplay(node.attrs.pubkey, removeNil([url]))
dom.classList.add("tiptap-object")
+3 -2
View File
@@ -1,14 +1,15 @@
<script lang="ts">
import {removeNil} from "@welshman/lib"
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
import {
userFollows,
deriveUserWotScore,
deriveHandleForPubkey,
displayHandle,
deriveProfileDisplay,
} from "@welshman/app"
import WotScore from "@lib/components/WotScore.svelte"
import ProfileCircle from "@app/components/ProfileCircle.svelte"
import {deriveAliasDisplay} from "@app/state"
type Props = {
value: string
@@ -18,7 +19,7 @@
const {value, url}: Props = $props()
const pubkey = value
const profileDisplay = deriveAliasDisplay(pubkey)
const profileDisplay = deriveProfileDisplay(pubkey, removeNil([url]))
const handle = deriveHandleForPubkey(pubkey)
const score = deriveUserWotScore(pubkey)
+2 -69
View File
@@ -1,5 +1,5 @@
import twColors from "tailwindcss/colors"
import {get, derived, readable, writable} from "svelte/store"
import {get, derived} from "svelte/store"
import * as nip19 from "nostr-tools/nip19"
import {
remove,
@@ -16,7 +16,6 @@ import {
addToMapKey,
identity,
always,
omit,
} from "@welshman/lib"
import {load} from "@welshman/net"
import {
@@ -39,12 +38,10 @@ import {
displayProfile,
readList,
getListTags,
readProfile,
asDecryptedEvent,
normalizeRelayUrl,
displayPubkey,
} from "@welshman/util"
import type {TrustedEvent, Profile, SignedEvent, PublishedList, List, Filter} from "@welshman/util"
import type {TrustedEvent, SignedEvent, PublishedList, List, Filter} from "@welshman/util"
import {Nip59, decrypt} from "@welshman/signer"
import {
pubkey,
@@ -67,8 +64,6 @@ import {
makeOutboxLoader,
routerContext,
appContext,
deriveProfile,
makeCachedLoader,
} from "@welshman/app"
import type {Thunk, Relay} from "@welshman/app"
import {deriveEvents, deriveEventsMapped, withGetter, synced} from "@welshman/store"
@@ -81,8 +76,6 @@ export const GENERAL = "_"
export const PROTECTED = ["-"]
export const ALIAS = 11000
export const ALERT = 32830
export const ALERT_STATUS = 32831
@@ -376,66 +369,6 @@ export const alertStatuses = deriveEventsMapped<AlertStatus>(repository, {
},
})
// Aliases
export type Alias = {
url: string
pubkey: string
profile: Profile
}
export const encodeAliasKey = (pubkey: string, url: string) => `${pubkey}:${url}`
export const decodeAliasKey = (key: string) => {
const [pubkey, url] = key.split(/:(.*)/s)
return {pubkey, url}
}
export const aliasesByKey = withGetter(writable(new Map<string, Alias>()))
export const loadAliasByKey = makeCachedLoader({
name: "aliases",
indexStore: aliasesByKey,
load: (key: string) => {
const {pubkey, url} = decodeAliasKey(key)
return load({
relays: [url],
filters: [{kinds: [ALIAS], authors: [pubkey]}],
onEvent: (event: TrustedEvent) => {
const profile = readProfile(event)
aliasesByKey.update($aliasesByKey => {
$aliasesByKey.set(key, {url, pubkey, profile})
return $aliasesByKey
})
},
})
},
})
export const deriveAlias = (pubkey: string, url?: string) => {
if (!url) return readable(undefined)
const key = encodeAliasKey(pubkey, url)
loadAliasByKey(key)
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(deriveAliasedProfile(pubkey, url), $profile =>
displayProfile($profile, displayPubkey(pubkey)),
)
// Membership
export const hasMembershipUrl = (list: List | undefined, url: string) =>