Add setting for max relays to try

This commit is contained in:
Jonathan Staab 2023-02-18 11:54:06 -06:00
parent 7c38ccab67
commit bab545f789
15 changed files with 61 additions and 24 deletions

11
package-lock.json generated
View File

@ -28,6 +28,7 @@
"svelte-link-preview": "^0.3.3",
"svelte-loading-spinners": "^0.3.4",
"svelte-preprocess": "^5.0.1",
"svelte-range-slider-pips": "^2.1.1",
"svelte-routing": "^1.6.0",
"svelte-switch": "^0.0.5",
"throttle-debounce": "^5.0.0",
@ -5201,6 +5202,11 @@
"node": ">=12"
}
},
"node_modules/svelte-range-slider-pips": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/svelte-range-slider-pips/-/svelte-range-slider-pips-2.1.1.tgz",
"integrity": "sha512-fLkhfnyEc4uMOCZCl8IPyC0e9lujrjqdSyrKw28Y8j99YUPZR+pHnSxde7PqhM0ST6eyO4ugh2nFnLZTIoG9aQ=="
},
"node_modules/svelte-routing": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/svelte-routing/-/svelte-routing-1.6.0.tgz",
@ -9432,6 +9438,11 @@
}
}
},
"svelte-range-slider-pips": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/svelte-range-slider-pips/-/svelte-range-slider-pips-2.1.1.tgz",
"integrity": "sha512-fLkhfnyEc4uMOCZCl8IPyC0e9lujrjqdSyrKw28Y8j99YUPZR+pHnSxde7PqhM0ST6eyO4ugh2nFnLZTIoG9aQ=="
},
"svelte-routing": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/svelte-routing/-/svelte-routing-1.6.0.tgz",

View File

@ -47,6 +47,7 @@
"svelte-link-preview": "^0.3.3",
"svelte-loading-spinners": "^0.3.4",
"svelte-preprocess": "^5.0.1",
"svelte-range-slider-pips": "^2.1.1",
"svelte-routing": "^1.6.0",
"svelte-switch": "^0.0.5",
"throttle-debounce": "^5.0.0",

View File

@ -261,11 +261,11 @@
{#if $toast}
<div
class="fixed top-0 left-0 right-0 z-10 click-events-none"
class="fixed top-0 left-0 right-0 z-10 pointer-events-none"
transition:fly={{y: -50, duration: 300}}>
<div
class="rounded bg-accent shadow-xl mx-24 sm:mx-32 mt-2 p-3 text-white text-center
border border-dark click-events-all">
border border-dark pointer-events-all">
{#if is(String, $toast.message)}
{$toast.message}
{:else}

View File

@ -96,7 +96,7 @@ const loadPeople = async (pubkeys, {relays = null, kinds = personKinds, force =
const chunkRelays = relays || (
getAllPubkeyWriteRelays(chunk)
.concat(getUserReadRelays())
.slice(0, 3)
.slice(0, 10)
)
await load(chunkRelays, {kinds, authors: chunk}, opts)

View File

@ -3,6 +3,7 @@ import {warn} from 'src/util/logger'
import {pick, objOf, map, assoc, sortBy, uniqBy, prop} from 'ramda'
import {first, createMap} from 'hurdak/lib/hurdak'
import {Tags, isRelay, findReplyId} from 'src/util/nostr'
import {shuffle} from 'src/util/misc'
import database from 'src/agent/database'
import user from 'src/agent/user'
@ -124,6 +125,8 @@ export const uniqByUrl = uniqBy(prop('url'))
export const sortByScore = sortBy(r => -r.score)
export const sampleRelays = relays => shuffle(relays).slice(0, 30)
export const aggregateScores = relayGroups => {
const scores = {} as Record<string, {
score: number,

View File

@ -79,6 +79,7 @@ export const modal = {
export const settings = synced("coracle/settings", {
reportAnalytics: true,
showLinkPreviews: true,
relayLimit: 30,
dufflepudUrl: import.meta.env.VITE_DUFFLEPUD_URL,
})

View File

@ -17,7 +17,10 @@
let input = null
let prevContent = ''
const search = fuzzy(database.people.all(), {keys: ["kind0.name", "pubkey"]})
const search = fuzzy(
database.people.all({'kind0.name:!nil': null}),
{keys: ["kind0.name", "pubkey"]}
)
const getText = () => {
const selection = document.getSelection()

View File

@ -208,9 +208,11 @@
{#if !showParent}
<div class="absolute h-px w-3 bg-light z-10" style="left: 0px; top: 27px;" />
{/if}
<Anchor class="text-lg font-bold" href={routes.person($person.pubkey)}>
<ImageCircle size={10} src={$person.kind0?.picture} />
</Anchor>
<div>
<Anchor class="text-lg font-bold" href={routes.person($person.pubkey)}>
<ImageCircle size={10} src={$person.kind0?.picture} />
</Anchor>
</div>
<div class="flex flex-col gap-2 flex-grow min-w-0">
<div class="flex items-center justify-between">
<Anchor type="unstyled" class="text-lg font-bold flex gap-2 items-center" href={routes.person($person.pubkey)}>

View File

@ -26,10 +26,14 @@
const messages = await database.messages.all()
const pubkeys = without([user.getPubkey()], uniq(messages.flatMap(m => [m.pubkey, m.recipient])))
await network.loadPeople(pubkeys)
network.loadPeople(pubkeys)
return sortBy(k => -(mostRecentByPubkey[k] || 0), pubkeys)
.map(k => ({type: 'npub', id: k, ...database.getPersonWithFallback(k)}))
.map(k => {
const person = database.getPersonWithFallback(k)
return {type: 'npub', id: k, ...person, ...person.kind0}
})
.concat(rooms.map(room => ({type: 'note', ...room})))
})
@ -72,7 +76,7 @@
{#if $rooms}
<Content>
<div class="flex justify-between">
<div class="flex justify-between mt-10">
<div class="flex gap-2 items-center">
<i class="fa fa-server fa-lg" />
<h2 class="staatliches text-2xl">Your rooms</h2>

View File

@ -1,6 +1,7 @@
<script lang="ts">
import {nip19} from 'nostr-tools'
import {sortBy, pluck} from 'ramda'
import {renameProp} from 'hurdak/lib/hurdak'
import {personKinds, displayPerson} from 'src/util/nostr'
import {now} from 'src/util/misc'
import Channel from 'src/partials/Channel.svelte'
@ -28,10 +29,10 @@
for (const event of events) {
const key = event.pubkey === pubkey ? pubkey : event.recipient
event.content = await crypt.decrypt(key, event.content)
event.decryptedContent = await crypt.decrypt(key, event.content)
}
return events
return events.map(renameProp('decryptedContent', 'content'))
}
const listenForMessages = cb => network.listen(

View File

@ -49,8 +49,8 @@
.concat(getPubkeyWriteRelays(pubkey).slice(0, 3))
.concat(getUserReadRelays().slice(0, 3))
// Refresh our person if needed
network.loadPeople([pubkey]).then(() => {
// Refresh our person
network.loadPeople([pubkey], {force: true}).then(() => {
person = database.getPersonWithFallback(pubkey)
loading = false
})

View File

@ -17,7 +17,7 @@
<i class="fa fa-server fa-lg" />
<h2 class="staatliches text-2xl">Your relays</h2>
</div>
<Anchor type="button" on:click={() => modal.set({type: 'relay/add'})}>
<Anchor type="button-accent" on:click={() => modal.set({type: 'relay/add'})}>
<i class="fa-solid fa-plus" /> Add Relay
</Anchor>
</div>

View File

@ -38,7 +38,7 @@
<div class="flex flex-col gap-8 w-full">
<div class="flex flex-col gap-1">
<div class="flex gap-2 items-center">
<strong>Show Link Previews</strong>
<strong>Show link and image previews</strong>
<Toggle bind:value={values.showLinkPreviews} />
</div>
<p class="text-sm text-light">
@ -46,6 +46,17 @@
in any note.
</p>
</div>
<div class="flex flex-col gap-1">
<div class="flex justify-between">
<strong>Max relays per request</strong>
<div>{values.relayLimit} relays</div>
</div>
<Input type="range" bind:value={values.relayLimit} min={1} max={50} />
<p class="text-sm text-light mt-2">
This controls how many relays to max out at when loading feeds and event context.
More is faster, but will require more bandwidth and processing power.
</p>
</div>
<div class="flex flex-col gap-1">
<strong>Dufflepud URL</strong>
<Input bind:value={values.dufflepudUrl}>
@ -58,7 +69,7 @@
</div>
<div class="flex flex-col gap-1">
<div class="flex gap-2 items-center">
<strong>Report Errors and Analytics</strong>
<strong>Report errors and analytics</strong>
<Toggle bind:value={values.reportAnalytics} />
</div>
<p class="text-sm text-light">

View File

@ -1,5 +1,5 @@
import {debounce, throttle} from 'throttle-debounce'
import {allPass, prop, pipe, isNil, complement, equals, is, pluck, sum, identity, sortBy} from "ramda"
import {path as getPath, allPass, prop, pipe, isNil, complement, equals, is, pluck, sum, identity, sortBy} from "ramda"
import Fuse from "fuse.js/dist/fuse.min.js"
import {writable} from 'svelte/store'
import {isObject} from 'hurdak/lib/hurdak'
@ -218,7 +218,7 @@ export const where = filters =>
.map(([key, value]) => {
/* eslint prefer-const: 0 */
let [field, operator = 'eq'] = key.split(':')
let test, modifier = identity
let test, modifier = identity, parts = field.split('.')
if (operator.startsWith('!')) {
operator = operator.slice(1)
@ -243,7 +243,7 @@ export const where = filters =>
throw new Error(`Invalid operator ${operator}`)
}
return pipe(prop(field), modifier(test))
return pipe(getPath(parts), modifier(test))
})
)

View File

@ -16,15 +16,15 @@
const {petnamePubkeys} = user
database.watch('people', people => {
database.watch('people', table => {
search = fuzzy(
people.all({'name:!nil': null}),
{keys: ["name", "about", "pubkey"]}
table.all({'kind0.name:!nil': null}),
{keys: ["kind0.name", "kind0.about", "pubkey"]}
)
})
// Prime our database, in case we don't have any people stored yet
network.listenUntilEose(getUserReadRelays(), {kinds: personKinds, limit: 300})
network.listenUntilEose(getUserReadRelays(), {kinds: personKinds, limit: 50})
</script>
<Input bind:value={q} placeholder="Search for people">