Move some stuff around

This commit is contained in:
Jonathan Staab 2023-02-09 12:47:22 -06:00
parent 40f5cdff0e
commit b0a11b0823
36 changed files with 248 additions and 213 deletions

View File

@ -12,7 +12,10 @@
import {globalHistory} from "svelte-routing/src/history"
import {displayPerson, isLike} from 'src/util/nostr'
import {timedelta, shuffle, now, sleep} from 'src/util/misc'
import {database, keys, user, pool, getRelays} from 'src/agent'
import {user, getRelays} from 'src/agent/helpers'
import database from 'src/agent/database'
import pool from 'src/agent/pool'
import keys from 'src/agent/keys'
import {modal, toast, settings, logUsage, alerts, messages, loadAppData} from "src/app"
import {routes} from "src/app/ui"
import Anchor from 'src/partials/Anchor.svelte'

View File

@ -2,7 +2,10 @@ import {prop, pick, join, uniqBy, last} from 'ramda'
import {get} from 'svelte/store'
import {first} from "hurdak/lib/hurdak"
import {Tags, isRelay, roomAttrs, displayPerson} from 'src/util/nostr'
import {keys, publish, getWriteRelays, database} from 'src/agent'
import {getWriteRelays} from 'src/agent/helpers'
import database from 'src/agent/database'
import network from 'src/agent/network'
import keys from 'src/agent/keys'
const updateUser = (relays, updates) =>
publishEvent(relays, 0, {content: JSON.stringify(updates)})
@ -106,7 +109,7 @@ const publishEvent = (relays, kind, {content = '', tags = []} = {}) => {
console.log("Publishing", event, relays)
return publish(relays, event)
return network.publish(relays, event)
}
export default {

74
src/agent/helpers.ts Normal file
View File

@ -0,0 +1,74 @@
import type {Person} from 'src/util/types'
import type {Readable} from 'svelte/store'
import {uniq, reject, last, propEq, uniqBy, prop} from 'ramda'
import {derived, get} from 'svelte/store'
import {Tags} from 'src/util/nostr'
import {now, timedelta} from 'src/util/misc'
import defaults from 'src/agent/defaults'
import database from 'src/agent/database'
import keys from 'src/agent/keys'
export const user = derived(
[keys.pubkey, database.people as Readable<any>],
([pubkey, $people]) => {
if (!pubkey) {
return null
}
return ($people[pubkey] || {pubkey})
}
) as Readable<Person>
export const getMuffle = () => {
const $user = get(user) as Person
if (!$user?.muffle) {
return []
}
const shouldMuffle = t => Math.random() > parseFloat(last(t))
return Tags.wrap($user.muffle.filter(shouldMuffle)).values().all()
}
export const getFollows = pubkey => {
const person = database.getPersonWithFallback(pubkey)
return Tags.wrap(person.petnames || defaults.petnames).values().all()
}
export const getRelays = (pubkey?: string) => {
let relays = database.getPersonWithFallback(pubkey).relays
if (!relays?.length) {
relays = database.getPersonWithFallback(get(keys.pubkey)).relays
}
if (!relays?.length) {
relays = defaults.relays
}
return relays
}
export const getWriteRelays = (...args) =>
reject(propEq('write', '!'), getRelays(...args))
export const getEventRelays = event => {
return uniqBy(
prop('url'),
getRelays(event.pubkey)
.concat(Tags.from(event).relays())
.concat({url: event.seen_on})
)
}
export const getStalePubkeys = pubkeys => {
// If we're not reloading, only get pubkeys we don't already know about
return uniq(pubkeys).filter(pubkey => {
const p = database.people.get(pubkey)
return !p || p.updated_at < now() - timedelta(1, 'days')
})
}

View File

@ -1,102 +1,14 @@
import type {Person} from 'src/util/types'
import type {Readable} from 'svelte/store'
import {reject, last, propEq, uniqBy, prop} from 'ramda'
import {derived, get} from 'svelte/store'
import {Tags} from 'src/util/nostr'
import pool from 'src/agent/pool'
import keys from 'src/agent/keys'
import defaults from 'src/agent/defaults'
import database from 'src/agent/database'
import {processEvents} from 'src/agent/data'
Object.assign(window, {pool, database})
export {pool, keys, database}
export const user = derived(
[keys.pubkey, database.people as Readable<any>],
([pubkey, $people]) => {
if (!pubkey) {
return null
}
return ($people[pubkey] || {pubkey})
}
) as Readable<Person>
export const getMuffle = () => {
const $user = get(user) as Person
if (!$user?.muffle) {
return []
}
const shouldMuffle = t => Math.random() > parseFloat(last(t))
return Tags.wrap($user.muffle.filter(shouldMuffle)).values().all()
}
export const getFollows = pubkey => {
const person = database.getPersonWithFallback(pubkey)
return Tags.wrap(person.petnames || defaults.petnames).values().all()
}
export const getRelays = (pubkey?: string) => {
let relays = database.getPersonWithFallback(pubkey).relays
if (!relays?.length) {
relays = database.getPersonWithFallback(get(keys.pubkey)).relays
}
if (!relays?.length) {
relays = defaults.relays
}
return relays
}
export const getWriteRelays = (...args) =>
reject(propEq('write', '!'), getRelays(...args))
export const getEventRelays = event => {
return uniqBy(
prop('url'),
getRelays(event.pubkey)
.concat(Tags.from(event).relays())
.concat({url: event.seen_on})
)
}
export const publish = async (relays, event) => {
const signedEvent = await keys.sign(event)
await Promise.all([
pool.publish(relays, signedEvent),
processEvents(signedEvent),
])
return signedEvent
}
export const load = async (relays, filter, opts?): Promise<Record<string, unknown>[]> => {
const events = await pool.request(relays, filter, opts)
await processEvents(events)
return events
}
export const listen = (relays, filter, onEvent, {shouldProcess = true}: any = {}) => {
return pool.subscribe(relays, filter, {
onEvent: e => {
if (shouldProcess) {
processEvents(e)
}
if (onEvent) {
onEvent(e)
}
},
})
}
/**
* The dependency tree gets a little complex here:
*
* cmd
* -> network
* -> helpers, pool
* -> keys
* -> sync
* -> database
*
* In other words, command/network depend on utility functions and the network to
* do their job. The database sits at the bottom since it's shared between helpers
* which query the database, and network which both queries and updates it.
*/

View File

@ -1,15 +1,41 @@
import {uniqBy, prop, uniq, flatten, pluck, identity} from 'ramda'
import {ensurePlural, createMap, chunk} from 'hurdak/lib/hurdak'
import {findReply, personKinds, Tags} from 'src/util/nostr'
import {now, timedelta} from 'src/util/misc'
import {load, database, getFollows} from 'src/agent'
import {getFollows, getStalePubkeys} from 'src/agent/helpers'
import pool from 'src/agent/pool'
import keys from 'src/agent/keys'
import sync from 'src/agent/sync'
const getStalePubkeys = pubkeys => {
// If we're not reloading, only get pubkeys we don't already know about
return uniq(pubkeys).filter(pubkey => {
const p = database.people.get(pubkey)
const publish = async (relays, event) => {
const signedEvent = await keys.sign(event)
return !p || p.updated_at < now() - timedelta(1, 'days')
await Promise.all([
pool.publish(relays, signedEvent),
sync.processEvents(signedEvent),
])
return signedEvent
}
const load = async (relays, filter, opts?): Promise<Record<string, unknown>[]> => {
const events = await pool.request(relays, filter, opts)
await sync.processEvents(events)
return events
}
const listen = (relays, filter, onEvent, {shouldProcess = true}: any = {}) => {
return pool.subscribe(relays, filter, {
onEvent: e => {
if (shouldProcess) {
sync.processEvents(e)
}
if (onEvent) {
onEvent(e)
}
},
})
}
@ -86,4 +112,4 @@ const loadContext = async (relays, notes, {loadParents = false, depth = 0, ...op
))
}
export default {loadNetwork, loadPeople, personKinds, loadContext}
export default {publish, load, listen, loadNetwork, loadPeople, personKinds, loadContext}

View File

@ -4,7 +4,7 @@ import {uniqBy, reject, prop, find, whereEq, is} from 'ramda'
import {ensurePlural} from 'hurdak/lib/hurdak'
import {isRelay} from 'src/util/nostr'
import {sleep} from 'src/util/misc'
import {database} from 'src/agent'
import database from 'src/agent/database'
let connections = []

View File

@ -5,13 +5,7 @@ import {now} from 'src/util/misc'
import {personKinds, Tags, roomAttrs, isRelay} from 'src/util/nostr'
import database from 'src/agent/database'
export const updatePeople = async updates => {
await database.people.bulkPut(updates)
}
// Hooks
export const processEvents = async events => {
const processEvents = async events => {
await Promise.all([
processProfileEvents(events),
processRoomEvents(events),
@ -91,7 +85,7 @@ const processProfileEvents = async events => {
}
if (!isEmpty(updates)) {
await updatePeople(updates)
await database.people.bulkPatch(updates)
}
}
@ -160,6 +154,8 @@ const verifyNip05 = (pubkey, as) =>
if (result?.pubkey === pubkey) {
const person = database.getPersonWithFallback(pubkey)
updatePeople({[pubkey]: {...person, verified_as: as}})
database.people.patch({...person, verified_as: as})
}
}, noop)
export default {processEvents}

View File

@ -3,8 +3,8 @@ import {groupBy, pluck, partition, propEq} from 'ramda'
import {createMap} from 'hurdak/lib/hurdak'
import {synced, timedelta, batch, now} from 'src/util/misc'
import {isAlert, findReplyId} from 'src/util/nostr'
import {load as _load, listen as _listen, database} from 'src/agent'
import loaders from 'src/app/loaders'
import database from 'src/agent/database'
import network from 'src/agent/network'
import {annotate} from 'src/app'
let listener
@ -16,7 +16,7 @@ const onChunk = async (relays, pubkey, events) => {
events = events.filter(e => isAlert(e, pubkey))
if (events.length > 0) {
const context = await loaders.loadContext(relays, events)
const context = await network.loadContext(relays, events)
const [likes, notes] = partition(propEq('kind', 7), events)
const annotatedNotes = notes.map(n => annotate(n, context))
const likesByParent = groupBy(findReplyId, likes)
@ -35,7 +35,7 @@ const load = async (relays, pubkey) => {
const since = get(mostRecentAlert) - timedelta(30, 'days')
// Crank the threshold up since we can afford for this to be slow
const events = await _load(
const events = await network.load(
relays,
{kinds: [1, 7], '#p': [pubkey], since, limit: 1000},
{threshold: 0.9}
@ -49,7 +49,7 @@ const listen = async (relays, pubkey) => {
listener.unsub()
}
listener = await _listen(
listener = await network.listen(
relays,
{kinds: [1, 7], '#p': [pubkey], since: now()},
batch(300, events => {

View File

@ -5,19 +5,21 @@ import {createMap, ellipsize} from 'hurdak/lib/hurdak'
import {get} from 'svelte/store'
import {renderContent} from 'src/util/html'
import {Tags, displayPerson, findReplyId} from 'src/util/nostr'
import {user, database, getRelays, getWriteRelays, keys} from 'src/agent'
import {user, getRelays, getWriteRelays} from 'src/agent/helpers'
import defaults from 'src/agent/defaults'
import {toast, routes, modal, settings, logUsage} from 'src/app/ui'
import cmd from 'src/app/cmd'
import database from 'src/agent/database'
import network from 'src/agent/network'
import keys from 'src/agent/keys'
import cmd from 'src/agent/cmd'
import alerts from 'src/app/alerts'
import messages from 'src/app/messages'
import loaders from 'src/app/loaders'
import {toast, routes, modal, settings, logUsage} from 'src/app/ui'
export {toast, modal, settings, alerts, messages, logUsage}
export const loadAppData = pubkey => {
return Promise.all([
loaders.loadNetwork(getRelays(), pubkey),
network.loadNetwork(getRelays(), pubkey),
alerts.load(getRelays(), pubkey),
alerts.listen(getRelays(), pubkey),
messages.listen(getRelays(), pubkey),
@ -37,7 +39,7 @@ export const login = async ({privkey, pubkey}: {privkey?: string, pubkey?: strin
loadAppData(pubkey)
// Load our user so we can populate network and show profile info
await loaders.loadPeople(getRelays(), [pubkey])
await network.loadPeople(getRelays(), [pubkey])
// Not ideal, but the network tab depends on the user's social network being
// loaded, so put them on global when they first log in so we're not slowing

View File

@ -1,8 +1,9 @@
import {pluck, reject} from 'ramda'
import {get} from 'svelte/store'
import {synced, now, timedelta, batch} from 'src/util/misc'
import {listen as _listen, database, user} from 'src/agent'
import loaders from 'src/app/loaders'
import {user} from 'src/agent/helpers'
import database from 'src/agent/database'
import network from 'src/agent/network'
let listener
@ -15,7 +16,7 @@ const listen = async (relays, pubkey) => {
listener.unsub()
}
listener = await _listen(
listener = await network.listen(
relays,
[{kinds: [4], authors: [pubkey], since},
{kinds: [4], '#p': [pubkey], since}],
@ -26,7 +27,7 @@ const listen = async (relays, pubkey) => {
const messages = reject(e => e.pubkey === e.recipient, await database.messages.all())
if (messages.length > 0) {
await loaders.loadPeople(relays, pluck('pubkey', messages))
await network.loadPeople(relays, pluck('pubkey', messages))
mostRecentByPubkey.update(o => {
for (const {pubkey, recipient, created_at} of messages) {

View File

@ -8,7 +8,8 @@
import Badge from 'src/partials/Badge.svelte'
import Anchor from 'src/partials/Anchor.svelte'
import Spinner from 'src/partials/Spinner.svelte'
import {user, database} from 'src/agent'
import {user} from 'src/agent/helpers'
import database from 'src/agent/database'
import {renderNote} from 'src/app'
export let name

View File

@ -5,7 +5,7 @@
import {displayPerson} from "src/util/nostr"
import {fromParentOffset} from "src/util/html"
import Badge from "src/partials/Badge.svelte"
import {database} from "src/agent"
import database from "src/agent/database"
export let onSubmit

View File

@ -5,7 +5,7 @@
import Badge from "src/partials/Badge.svelte"
import {formatTimestamp} from 'src/util/misc'
import {killEvent} from 'src/util/html'
import {database} from 'src/agent'
import database from 'src/agent/database'
import {modal} from 'src/app'
export let note

View File

@ -14,8 +14,9 @@
import Badge from "src/partials/Badge.svelte"
import Compose from "src/partials/Compose.svelte"
import Card from "src/partials/Card.svelte"
import {user, database, getEventRelays} from 'src/agent'
import cmd from 'src/app/cmd'
import {user, getEventRelays} from 'src/agent/helpers'
import database from 'src/agent/database'
import cmd from 'src/agent/cmd'
export let note
export let depth = 0
@ -134,6 +135,7 @@
}}
/>
{#if $person}
<Card on:click={onClick} {interactive} {invertColors}>
<div class="flex gap-4 items-center justify-between">
<Badge person={$person} />
@ -228,3 +230,4 @@
{/each}
</div>
{/if}
{/if}

View File

@ -5,7 +5,8 @@
import {switcher} from 'hurdak/lib/hurdak'
import {fly} from 'svelte/transition'
import Toggle from "src/partials/Toggle.svelte"
import {user, pool} from "src/agent"
import {user} from "src/agent/helpers"
import pool from 'src/agent/pool'
import {addRelay, removeRelay, setRelayWriteCondition} from "src/app"
export let relay

View File

@ -3,12 +3,12 @@
import {onMount} from 'svelte'
import {fly} from 'svelte/transition'
import {now, createScroller} from 'src/util/misc'
import {database} from 'src/agent'
import {alerts} from 'src/app'
import Note from 'src/partials/Note.svelte'
import Spinner from 'src/partials/Spinner.svelte'
import Content from 'src/partials/Content.svelte'
import Like from 'src/partials/Like.svelte'
import database from 'src/agent/database'
import {alerts} from 'src/app'
let limit = 0
let notes = null

View File

@ -4,9 +4,10 @@
import {nip19} from 'nostr-tools'
import {navigate} from "svelte-routing"
import {fuzzy} from "src/util/misc"
import {getRelays, user, database, listen} from 'src/agent'
import {getRelays, user} from 'src/agent/helpers'
import network from 'src/agent/network'
import database from 'src/agent/database'
import {modal, messages} from 'src/app'
import loaders from 'src/app/loaders'
import Room from "src/partials/Room.svelte"
import Input from "src/partials/Input.svelte"
import Content from "src/partials/Content.svelte"
@ -23,7 +24,7 @@
const messages = await database.messages.all()
const pubkeys = without([$user.pubkey], uniq(messages.flatMap(m => [m.pubkey, m.recipient])))
await loaders.loadPeople(getRelays(), pubkeys)
await network.loadPeople(getRelays(), pubkeys)
return sortBy(k => -(mostRecentByPubkey[k] || 0), pubkeys)
.map(k => ({type: 'npub', id: k, ...database.getPersonWithFallback(k)}))
@ -57,7 +58,7 @@
}
onMount(() => {
const sub = listen(getRelays(), [{kinds: [40, 41]}])
const sub = network.listen(getRelays(), [{kinds: [40, 41]}])
return () => {
sub.then(s => {

View File

@ -3,10 +3,11 @@
import {nip19} from 'nostr-tools'
import {now, batch} from 'src/util/misc'
import Channel from 'src/partials/Channel.svelte'
import {getRelays, user, database, listen, load} from 'src/agent'
import {getRelays, user} from 'src/agent/helpers'
import database from 'src/agent/database'
import network from 'src/agent/network'
import {modal} from 'src/app'
import loaders from 'src/app/loaders'
import cmd from 'src/app/cmd'
import cmd from 'src/agent/cmd'
export let entity
@ -26,7 +27,7 @@
const listenForMessages = async cb => {
const relays = getRoomRelays()
return listen(
return network.listen(
relays,
// Listen for updates to the room in case we didn't get them before
[{kinds: [40, 41], ids: [roomId]},
@ -34,7 +35,7 @@
batch(300, events => {
const newMessages = events.filter(e => e.kind === 42)
loaders.loadPeople(relays, pluck('pubkey', events))
network.loadPeople(relays, pluck('pubkey', events))
cb(newMessages)
})
@ -43,10 +44,10 @@
const loadMessages = async ({until, limit}) => {
const relays = getRoomRelays()
const events = await load(relays, {kinds: [42], '#e': [roomId], until, limit})
const events = await network.load(relays, {kinds: [42], '#e': [roomId], until, limit})
if (events.length) {
await loaders.loadPeople(relays, pluck('pubkey', events))
await network.loadPeople(relays, pluck('pubkey', events))
}
return events

View File

@ -8,7 +8,7 @@
import Anchor from "src/partials/Anchor.svelte"
import Content from "src/partials/Content.svelte"
import Heading from 'src/partials/Heading.svelte'
import {keys} from "src/agent"
import keys from "src/agent/keys"
import {toast} from "src/app"
const {pubkey, privkey} = keys

View File

@ -2,7 +2,7 @@
import {fly} from 'svelte/transition'
import Anchor from 'src/partials/Anchor.svelte'
import Content from "src/partials/Content.svelte"
import {database} from 'src/agent'
import database from 'src/agent/database'
let confirmed = false

View File

@ -4,10 +4,13 @@
import {personKinds} from 'src/util/nostr'
import {batch, now} from 'src/util/misc'
import Channel from 'src/partials/Channel.svelte'
import {database, getRelays, getWriteRelays, user, listen, keys} from 'src/agent'
import {getRelays, getWriteRelays, user} from 'src/agent/helpers'
import database from 'src/agent/database'
import network from 'src/agent/network'
import keys from 'src/agent/keys'
import {messages} from 'src/app'
import {routes} from 'src/app/ui'
import cmd from 'src/app/cmd'
import cmd from 'src/agent/cmd'
export let entity
@ -28,7 +31,7 @@
return events
}
const listenForMessages = cb => listen(
const listenForMessages = cb => network.listen(
getRelays().concat(getRelays(pubkey)),
[{kinds: personKinds, authors: [pubkey]},
{kinds: [4], authors: [$user.pubkey], '#p': [pubkey]},

View File

@ -5,7 +5,7 @@
import Tabs from "src/partials/Tabs.svelte"
import Network from "src/views/notes/Network.svelte"
import Global from "src/views/notes/Global.svelte"
import {user} from 'src/agent'
import {user} from 'src/agent/helpers'
export let activeTab

View File

@ -14,11 +14,13 @@
import Notes from "src/views/person/Notes.svelte"
import Likes from "src/views/person/Likes.svelte"
import Network from "src/views/person/Network.svelte"
import {database, getRelays, getWriteRelays, listen, user, keys} from "src/agent"
import {modal} from "src/app"
import loaders from "src/app/loaders"
import {getRelays, getWriteRelays, user} from "src/agent/helpers"
import network from "src/agent/network"
import keys from "src/agent/keys"
import database from "src/agent/database"
import {routes} from "src/app/ui"
import cmd from "src/app/cmd"
import {modal} from "src/app"
import cmd from "src/agent/cmd"
export let npub
export let activeTab
@ -36,13 +38,13 @@
onMount(async () => {
// Refresh our person if needed
loaders.loadPeople(relays || getRelays(pubkey), [pubkey]).then(() => {
network.loadPeople(relays || getRelays(pubkey), [pubkey]).then(() => {
person = database.getPersonWithFallback(pubkey)
loading = false
})
// Get our followers count
subs.push(await listen(
subs.push(await network.listen(
relays || getRelays(pubkey),
[{kinds: [3], '#p': [pubkey]}],
e => {

View File

@ -10,10 +10,10 @@
import Button from "src/partials/Button.svelte"
import Content from "src/partials/Content.svelte"
import Heading from "src/partials/Heading.svelte"
import {user, getWriteRelays} from "src/agent"
import {user, getWriteRelays} from "src/agent/helpers"
import cmd from "src/agent/cmd"
import {toast} from "src/app"
import {routes} from "src/app/ui"
import cmd from "src/app/cmd"
let values = {picture: null, about: null, name: null, nip05: null}

View File

@ -9,7 +9,9 @@
import Anchor from "src/partials/Anchor.svelte"
import Content from "src/partials/Content.svelte"
import RelayCard from "src/partials/RelayCard.svelte"
import {database, pool, user} from "src/agent"
import {user} from "src/agent/helpers"
import database from 'src/agent/database'
import pool from 'src/agent/pool'
import {modal, settings} from "src/app"
import defaults from "src/agent/defaults"

View File

@ -7,7 +7,7 @@
import Button from "src/partials/Button.svelte"
import Content from "src/partials/Content.svelte"
import Heading from "src/partials/Heading.svelte"
import {user} from 'src/agent'
import {user} from 'src/agent/helpers'
import {toast, settings} from "src/app"
let values = {...$settings}

View File

@ -6,9 +6,10 @@
import Content from "src/partials/Content.svelte"
import Textarea from "src/partials/Textarea.svelte"
import Button from "src/partials/Button.svelte"
import {getWriteRelays, database} from 'src/agent'
import {getWriteRelays} from 'src/agent/helpers'
import database from 'src/agent/database'
import cmd from "src/agent/cmd"
import {toast, modal} from "src/app"
import cmd from "src/app/cmd"
export let room = {name: null, id: null, about: null, picture: null}

View File

@ -13,9 +13,10 @@
import Content from "src/partials/Content.svelte"
import Modal from "src/partials/Modal.svelte"
import Heading from 'src/partials/Heading.svelte'
import {database, user, getWriteRelays} from "src/agent"
import {user, getWriteRelays} from "src/agent/helpers"
import database from 'src/agent/database'
import cmd from "src/agent/cmd"
import {toast, modal} from "src/app"
import cmd from "src/app/cmd"
let input = null
let relays = getWriteRelays()

View File

@ -2,9 +2,9 @@
import {onMount} from 'svelte'
import {nip19} from 'nostr-tools'
import {fly} from 'svelte/transition'
import {load, getRelays} from 'src/agent'
import {getRelays} from 'src/agent/helpers'
import network from 'src/agent/network'
import {annotate} from 'src/app'
import loaders from 'src/app/loaders'
import Note from 'src/partials/Note.svelte'
import Content from 'src/partials/Content.svelte'
import Spinner from 'src/partials/Spinner.svelte'
@ -15,7 +15,7 @@
let loading = true
onMount(async () => {
const [found] = await load(relays, {ids: [note.id]})
const [found] = await network.load(relays, {ids: [note.id]})
if (found) {
// Show the main note without waiting for context
@ -23,7 +23,7 @@
note = annotate(found, [])
}
const context = await loaders.loadContext(relays, found, {
const context = await network.loadContext(relays, found, {
depth: 3,
loadParents: true,
})

View File

@ -1,14 +1,15 @@
<script type="ts">
import Content from 'src/partials/Content.svelte'
import PersonInfo from 'src/partials/PersonInfo.svelte'
import {database, getRelays} from 'src/agent'
import loaders from 'src/app/loaders'
import {getRelays} from 'src/agent/helpers'
import database from 'src/agent/database'
import network from 'src/agent/network'
export let pubkeys
const people = database.watch('people', people => people.all({pubkey: pubkeys}))
loaders.loadPeople(getRelays(), pubkeys)
network.loadPeople(getRelays(), pubkeys)
</script>
<Content gap={2}>

View File

@ -5,9 +5,9 @@
import Button from "src/partials/Button.svelte"
import Content from 'src/partials/Content.svelte'
import SelectButton from "src/partials/SelectButton.svelte"
import {user, getWriteRelays} from 'src/agent'
import {user, getWriteRelays} from 'src/agent/helpers'
import cmd from 'src/agent/cmd'
import {modal} from 'src/app'
import cmd from 'src/app/cmd'
const muffle = $user.muffle || []
const muffleOptions = ['Never', 'Sometimes', 'Often', 'Always']

View File

@ -1,7 +1,8 @@
<script>
import {fuzzy} from "src/util/misc"
import PersonInfo from 'src/partials/PersonInfo.svelte'
import {user, database} from 'src/agent'
import {user} from 'src/agent/helpers'
import database from 'src/agent/database'
export let q

View File

@ -1,8 +1,8 @@
<script>
import Notes from "src/partials/Notes.svelte"
import {Cursor, now, batch} from 'src/util/misc'
import {getRelays, getMuffle, listen, load} from 'src/agent'
import loaders from 'src/app/loaders'
import {getRelays, getMuffle} from 'src/agent/helpers'
import network from 'src/agent/network'
import {threadify} from 'src/app'
const relays = getRelays()
@ -10,16 +10,16 @@
const cursor = new Cursor()
const listenForNotes = onNotes =>
listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await loaders.loadContext(relays, notes)
network.listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await network.loadContext(relays, notes)
onNotes(threadify(notes, context, {muffle: getMuffle(), showReplies: false}))
}))
const loadNotes = async () => {
const {limit, until} = cursor
const notes = await load(relays, {...filter, limit, until})
const context = await loaders.loadContext(relays, notes)
const notes = await network.load(relays, {...filter, limit, until})
const context = await network.loadContext(relays, notes)
cursor.onChunk(notes)

View File

@ -2,30 +2,30 @@
import {uniqBy, prop} from 'ramda'
import Notes from "src/partials/Notes.svelte"
import {now, Cursor, shuffle, batch} from 'src/util/misc'
import {user, getRelays, getFollows, getMuffle, listen, load} from 'src/agent'
import loaders from 'src/app/loaders'
import {user, getRelays, getFollows, getMuffle} from 'src/agent/helpers'
import network from 'src/agent/network'
import {threadify} from 'src/app'
// Get first- and second-order follows. shuffle and slice network so we're not
// sending too many pubkeys. This will also result in some variety.
const follows = shuffle(getFollows($user?.pubkey))
const network = shuffle(follows.flatMap(getFollows)).slice(0, 50)
const authors = follows.concat(network).slice(0, 100)
const others = shuffle(follows.flatMap(getFollows)).slice(0, 50)
const authors = follows.concat(others).slice(0, 100)
const filter = {kinds: [1, 7], authors}
const cursor = new Cursor()
const relays = uniqBy(prop('url'), follows.flatMap(getRelays))
const listenForNotes = onNotes =>
listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await loaders.loadContext(relays, notes)
network.listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await network.loadContext(relays, notes)
onNotes(threadify(notes, context, {muffle: getMuffle(), showReplies: false}))
}))
const loadNotes = async () => {
const {limit, until} = cursor
const notes = await load(relays, {...filter, limit, until})
const context = await loaders.loadContext(relays, notes)
const notes = await network.load(relays, {...filter, limit, until})
const context = await network.loadContext(relays, notes)
cursor.onChunk(notes)

View File

@ -1,8 +1,8 @@
<script>
import Notes from "src/partials/Notes.svelte"
import {now, batch, Cursor} from 'src/util/misc'
import {load, listen, getRelays, getMuffle} from 'src/agent'
import loaders from 'src/app/loaders'
import {getRelays, getMuffle} from 'src/agent/helpers'
import network from 'src/agent/network'
import {threadify} from 'src/app'
export let pubkey
@ -12,16 +12,16 @@
const cursor = new Cursor()
const listenForNotes = onNotes =>
listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await loaders.loadContext(relays, notes)
network.listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await network.loadContext(relays, notes)
onNotes(threadify(notes, context, {muffle: getMuffle()}))
}))
const loadNotes = async () => {
const {limit, until} = cursor
const notes = await load(relays, {...filter, limit, until})
const context = await loaders.loadContext(relays, notes)
const notes = await network.load(relays, {...filter, limit, until})
const context = await network.loadContext(relays, notes)
return threadify(notes, context, {muffle: getMuffle()})
}

View File

@ -1,8 +1,8 @@
<script>
import Notes from "src/partials/Notes.svelte"
import {now, batch, Cursor} from 'src/util/misc'
import {load, listen, getRelays, getMuffle} from 'src/agent'
import loaders from 'src/app/loaders'
import {getRelays, getMuffle} from 'src/agent/helpers'
import network from 'src/agent/network'
import {threadify} from 'src/app'
export let pubkey
@ -12,16 +12,16 @@
const cursor = new Cursor()
const listenForNotes = onNotes =>
listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await loaders.loadContext(relays, notes)
network.listen(relays, {...filter, since: now()}, batch(300, async notes => {
const context = await network.loadContext(relays, notes)
onNotes(threadify(notes, context, {muffle: getMuffle()}))
}))
const loadNotes = async () => {
const {limit, until} = cursor
const notes = await load(relays, {...filter, limit, until})
const context = await loaders.loadContext(relays, notes)
const notes = await network.load(relays, {...filter, limit, until})
const context = await network.loadContext(relays, notes)
return threadify(notes, context, {muffle: getMuffle()})
}