Switch to pnpm, use new welshman stuff
This commit is contained in:
+26
-29
@@ -1,6 +1,6 @@
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {get} from "svelte/store"
|
||||
import {ctx, randomId, uniq, equals} from "@welshman/lib"
|
||||
import {randomId, poll, uniq, equals} from "@welshman/lib"
|
||||
import {
|
||||
DELETE,
|
||||
REPORT,
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
unionFilters,
|
||||
} from "@welshman/util"
|
||||
import type {TrustedEvent, Filter, EventContent, EventTemplate} from "@welshman/util"
|
||||
import {PublishStatus, AuthStatus, SocketStatus} from "@welshman/net"
|
||||
import {Pool, PublishStatus, AuthStatus, SocketStatus} from "@welshman/net"
|
||||
import {Nip59, makeSecret, stamp, Nip46Broker} from "@welshman/signer"
|
||||
import {
|
||||
pubkey,
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
dropSession,
|
||||
tagEventForComment,
|
||||
tagEventForQuote,
|
||||
Router,
|
||||
} from "@welshman/app"
|
||||
import type {Thunk} from "@welshman/app"
|
||||
import {
|
||||
@@ -101,7 +102,7 @@ export const prependParent = (parent: TrustedEvent | undefined, {content, tags}:
|
||||
id: parent.id,
|
||||
kind: parent.kind,
|
||||
author: parent.pubkey,
|
||||
relays: ctx.app.router.Event(parent).limit(3).getUrls(),
|
||||
relays: Router.get().Event(parent).limit(3).getUrls(),
|
||||
})
|
||||
|
||||
tags = [...tags, tagEventForQuote(parent)]
|
||||
@@ -203,7 +204,7 @@ export const nip29 = {
|
||||
export const addSpaceMembership = async (url: string) => {
|
||||
const list = get(userMembership) || makeList({kind: GROUPS})
|
||||
const event = await addToListPublicly(list, ["r", url]).reconcile(nip44EncryptToSelf)
|
||||
const relays = uniq([...ctx.app.router.FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
const relays = uniq([...Router.get().FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
|
||||
return publishThunk({event, relays})
|
||||
}
|
||||
@@ -212,11 +213,7 @@ export const removeSpaceMembership = async (url: string) => {
|
||||
const list = get(userMembership) || makeList({kind: GROUPS})
|
||||
const pred = (t: string[]) => t[t[0] === "r" ? 1 : 2] === url
|
||||
const event = await removeFromListByPredicate(list, pred).reconcile(nip44EncryptToSelf)
|
||||
const relays = uniq([
|
||||
url,
|
||||
...ctx.app.router.FromUser().getUrls(),
|
||||
...getRelayTagValues(event.tags),
|
||||
])
|
||||
const relays = uniq([url, ...Router.get().FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
|
||||
return publishThunk({event, relays})
|
||||
}
|
||||
@@ -228,7 +225,7 @@ export const addRoomMembership = async (url: string, room: string, name: string)
|
||||
["group", room, url, name],
|
||||
]
|
||||
const event = await addToListPublicly(list, ...newTags).reconcile(nip44EncryptToSelf)
|
||||
const relays = uniq([...ctx.app.router.FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
const relays = uniq([...Router.get().FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
|
||||
return publishThunk({event, relays})
|
||||
}
|
||||
@@ -237,11 +234,7 @@ export const removeRoomMembership = async (url: string, room: string) => {
|
||||
const list = get(userMembership) || makeList({kind: GROUPS})
|
||||
const pred = (t: string[]) => equals(["group", room, url], t.slice(0, 3))
|
||||
const event = await removeFromListByPredicate(list, pred).reconcile(nip44EncryptToSelf)
|
||||
const relays = uniq([
|
||||
url,
|
||||
...ctx.app.router.FromUser().getUrls(),
|
||||
...getRelayTagValues(event.tags),
|
||||
])
|
||||
const relays = uniq([url, ...Router.get().FromUser().getUrls(), ...getRelayTagValues(event.tags)])
|
||||
|
||||
return publishThunk({event, relays})
|
||||
}
|
||||
@@ -263,7 +256,7 @@ export const setRelayPolicy = (url: string, read: boolean, write: boolean) => {
|
||||
relays: [
|
||||
url,
|
||||
...INDEXER_RELAYS,
|
||||
...ctx.app.router.FromUser().getUrls(),
|
||||
...Router.get().FromUser().getUrls(),
|
||||
...userRoomsByUrl.get().keys(),
|
||||
],
|
||||
})
|
||||
@@ -284,7 +277,7 @@ export const setInboxRelayPolicy = (url: string, enabled: boolean) => {
|
||||
event: createEvent(list.kind, {tags}),
|
||||
relays: [
|
||||
...INDEXER_RELAYS,
|
||||
...ctx.app.router.FromUser().getUrls(),
|
||||
...Router.get().FromUser().getUrls(),
|
||||
...userRoomsByUrl.get().keys(),
|
||||
],
|
||||
})
|
||||
@@ -294,9 +287,9 @@ export const setInboxRelayPolicy = (url: string, enabled: boolean) => {
|
||||
// Relay access
|
||||
|
||||
export const checkRelayAccess = async (url: string, claim = "") => {
|
||||
const connection = ctx.net.pool.get(url)
|
||||
const socket = Pool.getSingleton().get(url)
|
||||
|
||||
await connection.auth.attempt(5000)
|
||||
await socket.auth.attemptAuth(signer.get().sign)
|
||||
|
||||
const thunk = publishThunk({
|
||||
event: createEvent(AUTH_JOIN, {tags: [["claim", claim]]}),
|
||||
@@ -307,7 +300,7 @@ export const checkRelayAccess = async (url: string, claim = "") => {
|
||||
|
||||
if (result[url].status === PublishStatus.Failure) {
|
||||
const message =
|
||||
connection.auth.message?.replace(/^.*: /, "") ||
|
||||
socket.auth.details?.replace(/^.*: /, "") ||
|
||||
result[url].message?.replace(/^.*: /, "") ||
|
||||
"join request rejected"
|
||||
|
||||
@@ -328,26 +321,30 @@ export const checkRelayProfile = async (url: string) => {
|
||||
}
|
||||
|
||||
export const checkRelayConnection = async (url: string) => {
|
||||
const connection = ctx.net.pool.get(url)
|
||||
const socket = Pool.getSingleton().get(url)
|
||||
|
||||
await connection.socket.open()
|
||||
await connection.socket.wait(3000)
|
||||
socket.attemptToOpen()
|
||||
|
||||
if (connection.socket.status !== SocketStatus.Open) {
|
||||
await poll({
|
||||
signal: AbortSignal.timeout(3000),
|
||||
condition: () => socket.status === SocketStatus.Open,
|
||||
})
|
||||
|
||||
if (socket.status !== SocketStatus.Open) {
|
||||
return `Failed to connect`
|
||||
}
|
||||
}
|
||||
|
||||
export const checkRelayAuth = async (url: string, timeout = 3000) => {
|
||||
const connection = ctx.net.pool.get(url)
|
||||
const socket = Pool.getSingleton().get(url)
|
||||
const okStatuses = [AuthStatus.None, AuthStatus.Ok]
|
||||
|
||||
await connection.auth.attempt(timeout)
|
||||
await socket.auth.attemptAuth(signer.get().sign)
|
||||
|
||||
// Only raise an error if it's not a timeout.
|
||||
// If it is, odds are the problem is with our signer, not the relay
|
||||
if (!okStatuses.includes(connection.auth.status) && connection.auth.message) {
|
||||
return `Failed to authenticate (${connection.auth.message})`
|
||||
if (!okStatuses.includes(socket.auth.status) && socket.auth.details) {
|
||||
return `Failed to authenticate (${socket.auth.details})`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +381,7 @@ export const sendWrapped = async ({
|
||||
await Promise.all(
|
||||
uniq(pubkeys).map(async recipient => ({
|
||||
event: await nip59.wrap(recipient, stamp(template)),
|
||||
relays: ctx.app.router.PubkeyInbox(recipient).getUrls(),
|
||||
relays: Router.get().PubkeyInbox(recipient).getUrls(),
|
||||
delay,
|
||||
})),
|
||||
),
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
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,
|
||||
formatTimestampAsDate,
|
||||
inboxRelaySelectionsByPubkey,
|
||||
load,
|
||||
} from "@welshman/app"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Link from "@lib/components/Link.svelte"
|
||||
@@ -106,7 +107,10 @@
|
||||
|
||||
onMount(() => {
|
||||
// Don't use loadInboxRelaySelection because we want to force reload
|
||||
load({filters: [{kinds: [INBOX_RELAYS], authors: others}]})
|
||||
load({
|
||||
relays: Router.get().FromPubkeys(others).getUrls(),
|
||||
filters: [{kinds: [INBOX_RELAYS], authors: others}],
|
||||
})
|
||||
|
||||
const observer = new ResizeObserver(() => {
|
||||
dynamicPadding!.style.minHeight = `${chatCompose!.offsetHeight}px`
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import {nip19} from "nostr-tools"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {goto} from "$app/navigation"
|
||||
import {ctx, nthEq} from "@welshman/lib"
|
||||
import {tracker, repository} from "@welshman/app"
|
||||
import {nthEq} from "@welshman/lib"
|
||||
import {Router, tracker, repository} from "@welshman/app"
|
||||
import {Address, DIRECT_MESSAGE, MESSAGE, THREAD, EVENT_TIME} from "@welshman/util"
|
||||
import {scrollToEvent} from "@lib/html"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
const {id, identifier, kind, pubkey, relays: relayHints = []} = value
|
||||
const idOrAddress = id || new Address(kind, pubkey, identifier).toString()
|
||||
const mergedRelays = [
|
||||
...relays,
|
||||
...ctx.app.router.Quote(event, idOrAddress, relayHints).getUrls(),
|
||||
]
|
||||
const mergedRelays = [...relays, ...Router.get().Quote(event, idOrAddress, relayHints).getUrls()]
|
||||
const quote = deriveEvent(idOrAddress, mergedRelays)
|
||||
const entity = id
|
||||
? nip19.neventEncode({id, relays: mergedRelays})
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
import {onMount} from "svelte"
|
||||
import {max} from "@welshman/lib"
|
||||
import {COMMENT} from "@welshman/util"
|
||||
import {load} from "@welshman/net"
|
||||
import {deriveEvents} from "@welshman/store"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {formatTimestampRelative, repository, load} from "@welshman/app"
|
||||
import {formatTimestampRelative, repository} from "@welshman/app"
|
||||
import {notifications} from "@app/notifications"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import {nip19} from "nostr-tools"
|
||||
import {ctx} from "@welshman/lib"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {Router} from "@welshman/app"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import FieldInline from "@lib/components/FieldInline.svelte"
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
const {url, event}: Props = $props()
|
||||
|
||||
const relays = url ? [url] : ctx.app.router.Event(event).getUrls()
|
||||
const relays = url ? [url] : Router.get().Event(event).getUrls()
|
||||
const nevent1 = nip19.neventEncode({...event, relays})
|
||||
const npub1 = nip19.npubEncode(event.pubkey)
|
||||
const json = JSON.stringify(event, null, 2)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
const signUp = () => pushModal(SignUp)
|
||||
|
||||
const onSuccess = async (session: Session, relays: string[] = []) => {
|
||||
await loadUserData(session.pubkey, {relays})
|
||||
await loadUserData(session.pubkey, relays)
|
||||
|
||||
addSession(session)
|
||||
pushToast({message: "Successfully logged in!"})
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<script lang="ts">
|
||||
import cx from "classnames"
|
||||
import type {Snippet} from "svelte"
|
||||
import {nip19} from "nostr-tools"
|
||||
import {ctx} from "@welshman/lib"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {getListTags, getPubkeyTagValues} from "@welshman/util"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {formatTimestamp, userMutes} from "@welshman/app"
|
||||
import {formatTimestamp, Router, userMutes} from "@welshman/app"
|
||||
import Link from "@lib/components/Link.svelte"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
@@ -27,7 +26,7 @@
|
||||
class?: string
|
||||
} = $props()
|
||||
|
||||
const relays = ctx.app.router.Event(event).getUrls()
|
||||
const relays = Router.get().Event(event).getUrls()
|
||||
const nevent = nip19.neventEncode({id: event.id, relays})
|
||||
|
||||
const ignoreMute = () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {ctx} from "@welshman/lib"
|
||||
import type {Filter} from "@welshman/util"
|
||||
import {deriveEvents} from "@welshman/store"
|
||||
import {repository, load, loadRelaySelections, formatTimestampRelative} from "@welshman/app"
|
||||
import {load} from "@welshman/net"
|
||||
import {Router, repository, loadRelaySelections, formatTimestampRelative} from "@welshman/app"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Link from "@lib/components/Link.svelte"
|
||||
import Profile from "@app/components/Profile.svelte"
|
||||
@@ -22,7 +22,7 @@
|
||||
// Load at least one note, regardless of time frame
|
||||
load({
|
||||
filters: [{authors: [pubkey], limit: 1}],
|
||||
relays: ctx.app.router.FromPubkeys([pubkey]).getUrls(),
|
||||
relays: Router.get().FromPubkeys([pubkey]).getUrls(),
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import {ctx} from "@welshman/lib"
|
||||
import type {Profile} from "@welshman/util"
|
||||
import {
|
||||
createEvent,
|
||||
@@ -8,7 +7,7 @@
|
||||
createProfile,
|
||||
isPublishedProfile,
|
||||
} from "@welshman/util"
|
||||
import {pubkey, profilesByPubkey, publishThunk} from "@welshman/app"
|
||||
import {Router, pubkey, profilesByPubkey, publishThunk} from "@welshman/app"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
|
||||
import {clearModals} from "@app/modal"
|
||||
@@ -19,7 +18,7 @@
|
||||
const back = () => history.back()
|
||||
|
||||
const onsubmit = (profile: Profile) => {
|
||||
const relays = ctx.app.router.FromUser().getUrls()
|
||||
const relays = Router.get().FromUser().getUrls()
|
||||
const template = isPublishedProfile(profile) ? editProfile(profile) : createProfile(profile)
|
||||
const event = createEvent(template.kind, template)
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
import {REACTION, getTag, REPORT, DELETE} from "@welshman/util"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {deriveEvents} from "@welshman/store"
|
||||
import {pubkey, repository, load, displayProfileByPubkey} from "@welshman/app"
|
||||
import type {MultiRequest} from "@welshman/net"
|
||||
import {load, request, RequestEvent} from "@welshman/net"
|
||||
import {pubkey, repository, displayProfileByPubkey} from "@welshman/app"
|
||||
import {displayList} from "@lib/util"
|
||||
import {isMobile, preventDefault, stopPropagation} from "@lib/html"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
@@ -51,17 +53,27 @@
|
||||
)
|
||||
|
||||
onMount(() => {
|
||||
let req: MultiRequest
|
||||
|
||||
if (url) {
|
||||
load({
|
||||
req = request({
|
||||
relays: [url],
|
||||
filters: [{kinds: [REACTION, REPORT, DELETE], "#e": [event.id]}],
|
||||
onEvent: batch(300, (events: TrustedEvent[]) => {
|
||||
})
|
||||
|
||||
req.on(
|
||||
RequestEvent.Event,
|
||||
batch(300, (events: TrustedEvent[]) => {
|
||||
load({
|
||||
relays: [url],
|
||||
filters: [{kinds: [DELETE], "#e": events.map(e => e.id)}],
|
||||
})
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return () => {
|
||||
req?.close()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {ctx, sleep} from "@welshman/lib"
|
||||
import {sleep} from "@welshman/lib"
|
||||
import {Pool, AuthStatus} from "@welshman/net"
|
||||
import {displayRelayUrl} from "@welshman/util"
|
||||
import {preventDefault} from "@lib/html"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
@@ -17,7 +18,7 @@
|
||||
const back = () => history.back()
|
||||
|
||||
const next = () => {
|
||||
if (!error && ctx.net.pool.get(url).stats.lastAuth === 0) {
|
||||
if (!error && Pool.getSingleton().get(url).auth.status === AuthStatus.None) {
|
||||
pushModal(SpaceVisitConfirm, {url}, {replaceState: true})
|
||||
} else {
|
||||
confirmSpaceVisit(url)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {sleep, identity, nthEq} from "@welshman/lib"
|
||||
import {load} from "@welshman/app"
|
||||
import {load} from "@welshman/net"
|
||||
import {displayRelayUrl, AUTH_INVITE} from "@welshman/util"
|
||||
import {slide} from "@lib/transition"
|
||||
import Spinner from "@lib/components/Spinner.svelte"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {ctx, tryCatch} from "@welshman/lib"
|
||||
import {tryCatch} from "@welshman/lib"
|
||||
import {isRelayUrl, normalizeRelayUrl} from "@welshman/util"
|
||||
import {Pool, AuthStatus} from "@welshman/net"
|
||||
import {preventDefault} from "@lib/html"
|
||||
import Spinner from "@lib/components/Spinner.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
@@ -25,9 +26,9 @@
|
||||
return pushToast({theme: "error", message: error})
|
||||
}
|
||||
|
||||
const connection = ctx.net.pool.get(url)
|
||||
const socket = Pool.getSingleton().get(url)
|
||||
|
||||
if (connection.stats.lastAuth === 0) {
|
||||
if (socket.auth.status === AuthStatus.None) {
|
||||
pushModal(SpaceJoinConfirm, {url}, {replaceState: true})
|
||||
} else {
|
||||
await confirmSpaceJoin(url)
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import {mount} from "svelte"
|
||||
import type {Writable} from "svelte/store"
|
||||
import {get} from "svelte/store"
|
||||
import {Editor} from "@tiptap/core"
|
||||
import {ctx} from "@welshman/lib"
|
||||
import type {StampedEvent} from "@welshman/util"
|
||||
import {signer, profileSearch} from "@welshman/app"
|
||||
import {MentionSuggestion, WelshmanExtension} from "@welshman/editor"
|
||||
import {Router, signer, profileSearch} from "@welshman/app"
|
||||
import {Editor, MentionSuggestion, WelshmanExtension} from "@welshman/editor"
|
||||
import {getSetting, userSettingValues} from "@app/state"
|
||||
import {MentionNodeView} from "./MentionNodeView"
|
||||
import ProfileSuggestion from "./ProfileSuggestion.svelte"
|
||||
@@ -84,7 +82,7 @@ export const makeEditor = ({
|
||||
MentionSuggestion({
|
||||
editor: (this as any).editor,
|
||||
search: (term: string) => get(profileSearch).searchValues(term),
|
||||
getRelays: (pubkey: string) => ctx.app.router.FromPubkeys([pubkey]).getUrls(),
|
||||
getRelays: (pubkey: string) => Router.get().FromPubkeys([pubkey]).getUrls(),
|
||||
createSuggestion: (value: string) => {
|
||||
const target = document.createElement("div")
|
||||
|
||||
|
||||
+43
-45
@@ -28,15 +28,14 @@ import {
|
||||
} from "@welshman/util"
|
||||
import type {TrustedEvent, Filter, List} from "@welshman/util"
|
||||
import {feedFromFilters, makeRelayFeed, makeIntersectionFeed} from "@welshman/feeds"
|
||||
import type {Subscription, SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {load, request, RequestEvent} from "@welshman/net"
|
||||
import type {MultiRequest} from "@welshman/net"
|
||||
import type {AppSyncOpts, Thunk} from "@welshman/app"
|
||||
import {
|
||||
subscribe,
|
||||
load,
|
||||
repository,
|
||||
pull,
|
||||
hasNegentropy,
|
||||
thunkWorker,
|
||||
thunkQueue,
|
||||
createFeedController,
|
||||
loadRelay,
|
||||
loadMutes,
|
||||
@@ -152,13 +151,11 @@ export const makeFeed = ({
|
||||
onExhausted,
|
||||
})
|
||||
|
||||
const sub = subscribe({
|
||||
relays,
|
||||
filters: subscriptionFilters,
|
||||
onEvent: (e: TrustedEvent) => {
|
||||
if (matchFilters(feedFilters, e)) insertEvent(e)
|
||||
if (e.kind === DELETE) handleDelete(e)
|
||||
},
|
||||
const req = request({relays, filters: subscriptionFilters})
|
||||
|
||||
req.on(RequestEvent.Event, (e: TrustedEvent) => {
|
||||
if (matchFilters(feedFilters, e)) insertEvent(e)
|
||||
if (e.kind === DELETE) handleDelete(e)
|
||||
})
|
||||
|
||||
const scroller = createScroller({
|
||||
@@ -176,14 +173,14 @@ export const makeFeed = ({
|
||||
},
|
||||
})
|
||||
|
||||
thunkWorker.addGlobalHandler(onThunk)
|
||||
const unsubscribe = thunkQueue.subscribe(onThunk)
|
||||
|
||||
return {
|
||||
events,
|
||||
cleanup: () => {
|
||||
sub.close()
|
||||
req.close()
|
||||
unsubscribe()
|
||||
scroller.stop()
|
||||
thunkWorker.removeGlobalHandler(onThunk)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -245,22 +242,22 @@ export const makeCalendarFeed = ({
|
||||
}
|
||||
}
|
||||
|
||||
const sub = subscribe({
|
||||
relays,
|
||||
filters: subscriptionFilters,
|
||||
onEvent: (e: TrustedEvent) => {
|
||||
if (matchFilters(feedFilters, e)) insertEvent(e)
|
||||
},
|
||||
const req = request({relays, filters: subscriptionFilters})
|
||||
|
||||
req.on(RequestEvent.Event, (e: TrustedEvent) => {
|
||||
if (matchFilters(feedFilters, e)) insertEvent(e)
|
||||
})
|
||||
|
||||
const loadTimeframe = (since: number, until: number) => {
|
||||
const hashes = daysBetween(since, until).map(String)
|
||||
|
||||
load({
|
||||
const req = request({
|
||||
relays,
|
||||
autoClose: true,
|
||||
filters: [{kinds: [EVENT_TIME], "#D": hashes}],
|
||||
onEvent: insertEvent,
|
||||
})
|
||||
|
||||
req.on(RequestEvent.Event, insertEvent)
|
||||
}
|
||||
|
||||
const maybeExhausted = () => {
|
||||
@@ -302,15 +299,15 @@ export const makeCalendarFeed = ({
|
||||
},
|
||||
})
|
||||
|
||||
thunkWorker.addGlobalHandler(onThunk)
|
||||
const unsubscribe = thunkQueue.subscribe(onThunk)
|
||||
|
||||
return {
|
||||
events,
|
||||
cleanup: () => {
|
||||
thunkWorker.removeGlobalHandler(onThunk)
|
||||
backwardScroller.stop()
|
||||
forwardScroller.stop()
|
||||
sub.close()
|
||||
unsubscribe()
|
||||
req.close()
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -332,7 +329,7 @@ export const loadAlertStatuses = (pubkey: string) =>
|
||||
// Application requests
|
||||
|
||||
export const listenForNotifications = () => {
|
||||
const subs: Subscription[] = []
|
||||
const reqs: MultiRequest[] = []
|
||||
|
||||
for (const [url, allRooms] of userRoomsByUrl.get()) {
|
||||
// Limit how many rooms we load at a time, since we have to send a separate filter
|
||||
@@ -350,8 +347,8 @@ export const listenForNotifications = () => {
|
||||
],
|
||||
})
|
||||
|
||||
subs.push(
|
||||
subscribe({
|
||||
reqs.push(
|
||||
request({
|
||||
relays: [url],
|
||||
filters: [
|
||||
{kinds: [THREAD, EVENT_TIME], since: now()},
|
||||
@@ -363,25 +360,22 @@ export const listenForNotifications = () => {
|
||||
}
|
||||
|
||||
return () => {
|
||||
for (const sub of subs) {
|
||||
sub.close()
|
||||
for (const req of reqs) {
|
||||
req.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const loadUserData = (
|
||||
pubkey: string,
|
||||
request: Partial<SubscribeRequestWithHandlers> = {},
|
||||
) => {
|
||||
export const loadUserData = (pubkey: string, relays: string[] = []) => {
|
||||
const promise = Promise.race([
|
||||
sleep(3000),
|
||||
Promise.all([
|
||||
loadInboxRelaySelections(pubkey, request),
|
||||
loadMembership(pubkey, request),
|
||||
loadSettings(pubkey, request),
|
||||
loadProfile(pubkey, request),
|
||||
loadFollows(pubkey, request),
|
||||
loadMutes(pubkey, request),
|
||||
loadInboxRelaySelections(pubkey, relays),
|
||||
loadMembership(pubkey, relays),
|
||||
loadSettings(pubkey, relays),
|
||||
loadProfile(pubkey, relays),
|
||||
loadFollows(pubkey, relays),
|
||||
loadMutes(pubkey, relays),
|
||||
loadAlertStatuses(pubkey),
|
||||
loadAlerts(pubkey),
|
||||
]),
|
||||
@@ -396,10 +390,10 @@ export const loadUserData = (
|
||||
await sleep(1000)
|
||||
|
||||
for (const pubkey of pubkeys) {
|
||||
loadMembership(pubkey, {relays})
|
||||
loadProfile(pubkey, {relays})
|
||||
loadFollows(pubkey, {relays})
|
||||
loadMutes(pubkey, {relays})
|
||||
loadMembership(pubkey, relays)
|
||||
loadProfile(pubkey, relays)
|
||||
loadFollows(pubkey, relays)
|
||||
loadMutes(pubkey, relays)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -408,4 +402,8 @@ export const loadUserData = (
|
||||
}
|
||||
|
||||
export const discoverRelays = (lists: List[]) =>
|
||||
Promise.all(uniq(lists.flatMap(getRelayUrls)).filter(isShareableRelayUrl).map(loadRelay))
|
||||
Promise.all(
|
||||
uniq(lists.flatMap(getRelayUrls))
|
||||
.filter(isShareableRelayUrl)
|
||||
.map(url => loadRelay(url)),
|
||||
)
|
||||
|
||||
+16
-25
@@ -1,9 +1,7 @@
|
||||
import twColors from "tailwindcss/colors"
|
||||
import {get, derived} from "svelte/store"
|
||||
import {nip19} from "nostr-tools"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {
|
||||
ctx,
|
||||
setContext,
|
||||
remove,
|
||||
sortBy,
|
||||
sort,
|
||||
@@ -17,7 +15,9 @@ import {
|
||||
memoize,
|
||||
addToMapKey,
|
||||
identity,
|
||||
always,
|
||||
} from "@welshman/lib"
|
||||
import {load} from "@welshman/net"
|
||||
import {
|
||||
getIdFilters,
|
||||
WRAP,
|
||||
@@ -46,12 +46,8 @@ import {Nip59, decrypt} from "@welshman/signer"
|
||||
import {
|
||||
pubkey,
|
||||
repository,
|
||||
load,
|
||||
collection,
|
||||
profilesByPubkey,
|
||||
getDefaultAppContext,
|
||||
getDefaultNetContext,
|
||||
makeRouter,
|
||||
tracker,
|
||||
makeTrackerStore,
|
||||
makeRepositoryStore,
|
||||
@@ -64,9 +60,12 @@ import {
|
||||
thunks,
|
||||
walkThunks,
|
||||
signer,
|
||||
Router,
|
||||
loadWithAsapMetaRelayUrls,
|
||||
routerContext,
|
||||
appContext,
|
||||
} from "@welshman/app"
|
||||
import type {Thunk, Relay} from "@welshman/app"
|
||||
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {deriveEvents, deriveEventsMapped, withGetter, synced} from "@welshman/store"
|
||||
|
||||
export const fromCsv = (s: string) => (s || "").split(",").filter(identity)
|
||||
@@ -162,10 +161,8 @@ export const imgproxy = (url: string, {w = 640, h = 1024} = {}) => {
|
||||
|
||||
export const entityLink = (entity: string) => `https://coracle.social/${entity}`
|
||||
|
||||
export const pubkeyLink = (
|
||||
pubkey: string,
|
||||
relays = ctx.app.router.FromPubkeys([pubkey]).getUrls(),
|
||||
) => entityLink(nip19.nprofileEncode({pubkey, relays}))
|
||||
export const pubkeyLink = (pubkey: string, relays = Router.get().FromPubkeys([pubkey]).getUrls()) =>
|
||||
entityLink(nip19.nprofileEncode({pubkey, relays}))
|
||||
|
||||
export const tagRoom = (room: string, url: string) => [ROOM, room]
|
||||
|
||||
@@ -283,15 +280,9 @@ export const deriveEventsForUrl = (url: string, filters: Filter[]) =>
|
||||
|
||||
// Context
|
||||
|
||||
setContext({
|
||||
net: getDefaultNetContext(),
|
||||
app: getDefaultAppContext({
|
||||
dufflepudUrl: DUFFLEPUD_URL,
|
||||
indexerRelays: INDEXER_RELAYS,
|
||||
requestTimeout: 5000,
|
||||
router: makeRouter(),
|
||||
}),
|
||||
})
|
||||
appContext.dufflepudUrl = DUFFLEPUD_URL
|
||||
|
||||
routerContext.getIndexerRelays = always(INDEXER_RELAYS)
|
||||
|
||||
// Settings
|
||||
|
||||
@@ -341,8 +332,8 @@ export const {
|
||||
name: "settings",
|
||||
store: settings,
|
||||
getKey: settings => settings.event.pubkey,
|
||||
load: (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) =>
|
||||
load({...request, filters: [{kinds: [SETTINGS], authors: [pubkey]}]}),
|
||||
load: (pubkey: string, relays: string[]) =>
|
||||
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [SETTINGS], authors: [pubkey]}]),
|
||||
})
|
||||
|
||||
// Alerts
|
||||
@@ -419,8 +410,8 @@ export const {
|
||||
name: "memberships",
|
||||
store: memberships,
|
||||
getKey: list => list.event.pubkey,
|
||||
load: (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) =>
|
||||
load({...request, filters: [{kinds: [GROUPS], authors: [pubkey]}]}),
|
||||
load: (pubkey: string, relays: string[]) =>
|
||||
loadWithAsapMetaRelayUrls(pubkey, relays, [{kinds: [GROUPS], authors: [pubkey]}]),
|
||||
})
|
||||
|
||||
// Chats
|
||||
|
||||
Reference in New Issue
Block a user