forked from coracle/flotilla
Remove aliases, their time has not yet come
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
formatTimestampAsDate,
|
formatTimestampAsDate,
|
||||||
formatTimestampAsTime,
|
formatTimestampAsTime,
|
||||||
thunkIsComplete,
|
thunkIsComplete,
|
||||||
|
deriveProfile,
|
||||||
|
deriveProfileDisplay,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import {isMobile} from "@lib/html"
|
import {isMobile} from "@lib/html"
|
||||||
import TapTarget from "@lib/components/TapTarget.svelte"
|
import TapTarget from "@lib/components/TapTarget.svelte"
|
||||||
@@ -20,7 +22,7 @@
|
|||||||
import ChannelMessageEmojiButton from "@app/components/ChannelMessageEmojiButton.svelte"
|
import ChannelMessageEmojiButton from "@app/components/ChannelMessageEmojiButton.svelte"
|
||||||
import ChannelMessageMenuButton from "@app/components/ChannelMessageMenuButton.svelte"
|
import ChannelMessageMenuButton from "@app/components/ChannelMessageMenuButton.svelte"
|
||||||
import ChannelMessageMenuMobile from "@app/components/ChannelMessageMenuMobile.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 {publishDelete, publishReaction} from "@app/commands"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
|
|
||||||
@@ -37,8 +39,8 @@
|
|||||||
|
|
||||||
const thunk = $thunks[event.id]
|
const thunk = $thunks[event.id]
|
||||||
const today = formatTimestampAsDate(now())
|
const today = formatTimestampAsDate(now())
|
||||||
const profile = deriveAliasedProfile(event.pubkey, url)
|
const profile = deriveProfile(event.pubkey, [url])
|
||||||
const aliasDisplay = deriveAliasDisplay(event.pubkey, url)
|
const profileDisplay = deriveProfileDisplay(event.pubkey, [url])
|
||||||
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
|
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
|
||||||
const hideMenuButton = $derived($thunk && !thunkIsComplete($thunk))
|
const hideMenuButton = $derived($thunk && !thunkIsComplete($thunk))
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@
|
|||||||
{#if showPubkey}
|
{#if showPubkey}
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Button onclick={openProfile} class="text-sm font-bold" style="color: {colorValue}">
|
<Button onclick={openProfile} class="text-sm font-bold" style="color: {colorValue}">
|
||||||
{$aliasDisplay}
|
{$profileDisplay}
|
||||||
</Button>
|
</Button>
|
||||||
<span class="text-xs opacity-50">
|
<span class="text-xs opacity-50">
|
||||||
{#if formatTimestampAsDate(event.created_at) === today}
|
{#if formatTimestampAsDate(event.created_at) === today}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {removeNil} from "@welshman/lib"
|
||||||
import type {ProfilePointer} from "@welshman/content"
|
import type {ProfilePointer} from "@welshman/content"
|
||||||
import {displayProfile} from "@welshman/util"
|
import {displayProfile} from "@welshman/util"
|
||||||
|
import {deriveProfile} from "@welshman/app"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import ProfileDetail from "@app/components/ProfileDetail.svelte"
|
import ProfileDetail from "@app/components/ProfileDetail.svelte"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {deriveAliasedProfile} from "@app/state"
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
value: ProfilePointer
|
value: ProfilePointer
|
||||||
@@ -13,7 +14,7 @@
|
|||||||
|
|
||||||
const {value, url}: Props = $props()
|
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})
|
const openProfile = () => pushModal(ProfileDetail, {pubkey: value.pubkey, url})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {removeNil} from "@welshman/lib"
|
||||||
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
|
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
|
||||||
import {
|
import {
|
||||||
session,
|
session,
|
||||||
@@ -6,13 +7,14 @@
|
|||||||
deriveUserWotScore,
|
deriveUserWotScore,
|
||||||
deriveHandleForPubkey,
|
deriveHandleForPubkey,
|
||||||
displayHandle,
|
displayHandle,
|
||||||
|
deriveProfile,
|
||||||
|
deriveProfileDisplay,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import Avatar from "@lib/components/Avatar.svelte"
|
import Avatar from "@lib/components/Avatar.svelte"
|
||||||
import WotScore from "@lib/components/WotScore.svelte"
|
import WotScore from "@lib/components/WotScore.svelte"
|
||||||
import ProfileDetail from "@app/components/ProfileDetail.svelte"
|
import ProfileDetail from "@app/components/ProfileDetail.svelte"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {deriveAliasedProfile, deriveAliasDisplay} from "@app/state"
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
pubkey: string
|
pubkey: string
|
||||||
@@ -21,8 +23,9 @@
|
|||||||
|
|
||||||
const {pubkey, url}: Props = $props()
|
const {pubkey, url}: Props = $props()
|
||||||
|
|
||||||
const profile = deriveAliasedProfile(pubkey, url)
|
const relays = removeNil([url])
|
||||||
const aliasDisplay = deriveAliasDisplay(pubkey, url)
|
const profile = deriveProfile(pubkey, relays)
|
||||||
|
const profileDisplay = deriveProfileDisplay(pubkey, relays)
|
||||||
const handle = deriveHandleForPubkey(pubkey)
|
const handle = deriveHandleForPubkey(pubkey)
|
||||||
const score = deriveUserWotScore(pubkey)
|
const score = deriveUserWotScore(pubkey)
|
||||||
|
|
||||||
@@ -40,7 +43,7 @@
|
|||||||
<div class="flex min-w-0 flex-col">
|
<div class="flex min-w-0 flex-col">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Button onclick={openProfile} class="text-bold overflow-hidden text-ellipsis">
|
<Button onclick={openProfile} class="text-bold overflow-hidden text-ellipsis">
|
||||||
{$aliasDisplay}
|
{$profileDisplay}
|
||||||
</Button>
|
</Button>
|
||||||
<WotScore score={$score} active={following} />
|
<WotScore score={$score} active={following} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from "@lib/components/Avatar.svelte"
|
import Avatar from "@lib/components/Avatar.svelte"
|
||||||
import {deriveAliasedProfile} from "@app/state"
|
import {removeNil} from "@welshman/lib"
|
||||||
|
import {deriveProfile} from "@welshman/app"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
pubkey: string
|
pubkey: string
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
|
|
||||||
const {pubkey, url, ...props}: Props = $props()
|
const {pubkey, url, ...props}: Props = $props()
|
||||||
|
|
||||||
const profile = deriveAliasedProfile(pubkey, url)
|
const profile = deriveProfile(pubkey, removeNil([url]))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Avatar src={$profile?.picture} icon="user-circle" {...props} />
|
<Avatar src={$profile?.picture} icon="user-circle" {...props} />
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {goto} from "$app/navigation"
|
import {goto} from "$app/navigation"
|
||||||
|
import {removeNil} from "@welshman/lib"
|
||||||
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
|
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
|
||||||
import {
|
import {
|
||||||
session,
|
session,
|
||||||
@@ -7,6 +8,8 @@
|
|||||||
deriveUserWotScore,
|
deriveUserWotScore,
|
||||||
deriveHandleForPubkey,
|
deriveHandleForPubkey,
|
||||||
displayHandle,
|
displayHandle,
|
||||||
|
deriveProfile,
|
||||||
|
deriveProfileDisplay,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Link from "@lib/components/Link.svelte"
|
import Link from "@lib/components/Link.svelte"
|
||||||
@@ -16,7 +19,7 @@
|
|||||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||||
import ProfileInfo from "@app/components/ProfileInfo.svelte"
|
import ProfileInfo from "@app/components/ProfileInfo.svelte"
|
||||||
import ChatEnable from "@app/components/ChatEnable.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 {pushModal} from "@app/modal"
|
||||||
import {makeChatPath} from "@app/routes"
|
import {makeChatPath} from "@app/routes"
|
||||||
|
|
||||||
@@ -27,8 +30,9 @@
|
|||||||
|
|
||||||
const {pubkey, url}: Props = $props()
|
const {pubkey, url}: Props = $props()
|
||||||
|
|
||||||
const profile = deriveAliasedProfile(pubkey, url)
|
const relays = removeNil([url])
|
||||||
const display = deriveAliasDisplay(pubkey, url)
|
const profile = deriveProfile(pubkey, relays)
|
||||||
|
const display = deriveProfileDisplay(pubkey, relays)
|
||||||
const handle = deriveHandleForPubkey(pubkey)
|
const handle = deriveHandleForPubkey(pubkey)
|
||||||
const score = deriveUserWotScore(pubkey)
|
const score = deriveUserWotScore(pubkey)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {removeNil} from "@welshman/lib"
|
||||||
|
import {deriveProfile} from "@welshman/app"
|
||||||
import Content from "@app/components/Content.svelte"
|
import Content from "@app/components/Content.svelte"
|
||||||
import {deriveAliasedProfile} from "@app/state"
|
|
||||||
|
|
||||||
export type Props = {
|
export type Props = {
|
||||||
pubkey: string
|
pubkey: string
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
|
|
||||||
const {pubkey, url}: Props = $props()
|
const {pubkey, url}: Props = $props()
|
||||||
|
|
||||||
const profile = deriveAliasedProfile(pubkey, url)
|
const profile = deriveProfile(pubkey, removeNil([url]))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $profile}
|
{#if $profile}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {deriveAliasDisplay} from "@app/state"
|
import {removeNil} from "@welshman/lib"
|
||||||
|
import {deriveProfileDisplay} from "@welshman/app"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
pubkey: string
|
pubkey: string
|
||||||
@@ -8,7 +9,7 @@
|
|||||||
|
|
||||||
const {pubkey, url}: Props = $props()
|
const {pubkey, url}: Props = $props()
|
||||||
|
|
||||||
const aliasDisplay = deriveAliasDisplay(pubkey, url)
|
const profileDisplay = deriveProfileDisplay(pubkey, removeNil([url]))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{$aliasDisplay}
|
{$profileDisplay}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import type {NodeViewProps} from "@tiptap/core"
|
import type {NodeViewProps} from "@tiptap/core"
|
||||||
import {deriveAliasDisplay} from "@app/state"
|
import {removeNil} from "@welshman/lib"
|
||||||
|
import {deriveProfileDisplay} from "@welshman/app"
|
||||||
|
|
||||||
export const makeMentionNodeView =
|
export const makeMentionNodeView =
|
||||||
(url?: string) =>
|
(url?: string) =>
|
||||||
({node}: NodeViewProps) => {
|
({node}: NodeViewProps) => {
|
||||||
const dom = document.createElement("span")
|
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")
|
dom.classList.add("tiptap-object")
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {removeNil} from "@welshman/lib"
|
||||||
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
|
import {displayPubkey, getPubkeyTagValues, getListTags} from "@welshman/util"
|
||||||
import {
|
import {
|
||||||
userFollows,
|
userFollows,
|
||||||
deriveUserWotScore,
|
deriveUserWotScore,
|
||||||
deriveHandleForPubkey,
|
deriveHandleForPubkey,
|
||||||
displayHandle,
|
displayHandle,
|
||||||
|
deriveProfileDisplay,
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import WotScore from "@lib/components/WotScore.svelte"
|
import WotScore from "@lib/components/WotScore.svelte"
|
||||||
import ProfileCircle from "@app/components/ProfileCircle.svelte"
|
import ProfileCircle from "@app/components/ProfileCircle.svelte"
|
||||||
import {deriveAliasDisplay} from "@app/state"
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
value: string
|
value: string
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
const {value, url}: Props = $props()
|
const {value, url}: Props = $props()
|
||||||
|
|
||||||
const pubkey = value
|
const pubkey = value
|
||||||
const profileDisplay = deriveAliasDisplay(pubkey)
|
const profileDisplay = deriveProfileDisplay(pubkey, removeNil([url]))
|
||||||
const handle = deriveHandleForPubkey(pubkey)
|
const handle = deriveHandleForPubkey(pubkey)
|
||||||
const score = deriveUserWotScore(pubkey)
|
const score = deriveUserWotScore(pubkey)
|
||||||
|
|
||||||
|
|||||||
+2
-69
@@ -1,5 +1,5 @@
|
|||||||
import twColors from "tailwindcss/colors"
|
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 * as nip19 from "nostr-tools/nip19"
|
||||||
import {
|
import {
|
||||||
remove,
|
remove,
|
||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
addToMapKey,
|
addToMapKey,
|
||||||
identity,
|
identity,
|
||||||
always,
|
always,
|
||||||
omit,
|
|
||||||
} from "@welshman/lib"
|
} from "@welshman/lib"
|
||||||
import {load} from "@welshman/net"
|
import {load} from "@welshman/net"
|
||||||
import {
|
import {
|
||||||
@@ -39,12 +38,10 @@ import {
|
|||||||
displayProfile,
|
displayProfile,
|
||||||
readList,
|
readList,
|
||||||
getListTags,
|
getListTags,
|
||||||
readProfile,
|
|
||||||
asDecryptedEvent,
|
asDecryptedEvent,
|
||||||
normalizeRelayUrl,
|
normalizeRelayUrl,
|
||||||
displayPubkey,
|
|
||||||
} from "@welshman/util"
|
} 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 {Nip59, decrypt} from "@welshman/signer"
|
||||||
import {
|
import {
|
||||||
pubkey,
|
pubkey,
|
||||||
@@ -67,8 +64,6 @@ import {
|
|||||||
makeOutboxLoader,
|
makeOutboxLoader,
|
||||||
routerContext,
|
routerContext,
|
||||||
appContext,
|
appContext,
|
||||||
deriveProfile,
|
|
||||||
makeCachedLoader,
|
|
||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import type {Thunk, Relay} from "@welshman/app"
|
import type {Thunk, Relay} from "@welshman/app"
|
||||||
import {deriveEvents, deriveEventsMapped, withGetter, synced} from "@welshman/store"
|
import {deriveEvents, deriveEventsMapped, withGetter, synced} from "@welshman/store"
|
||||||
@@ -81,8 +76,6 @@ export const GENERAL = "_"
|
|||||||
|
|
||||||
export const PROTECTED = ["-"]
|
export const PROTECTED = ["-"]
|
||||||
|
|
||||||
export const ALIAS = 11000
|
|
||||||
|
|
||||||
export const ALERT = 32830
|
export const ALERT = 32830
|
||||||
|
|
||||||
export const ALERT_STATUS = 32831
|
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
|
// Membership
|
||||||
|
|
||||||
export const hasMembershipUrl = (list: List | undefined, url: string) =>
|
export const hasMembershipUrl = (list: List | undefined, url: string) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user