Small fixes, re-introduce 10001 temporarily

This commit is contained in:
Jonathan Staab 2023-02-16 20:55:14 -06:00
parent 7eeeb63e82
commit 0b35ccc64d
9 changed files with 40 additions and 24 deletions

View File

@ -166,6 +166,7 @@
<Router {url}>
<div use:links class="h-full">
{#if $ready}
<div class="pt-16 text-white h-full lg:ml-56">
<Route path="/alerts" component={Alerts} />
<Route path="/search/:activeTab" let:params>
@ -208,6 +209,7 @@
</Route>
<Route path="*" component={NotFound} />
</div>
{/if}
<SideNav />
<TopNav />

View File

@ -4,9 +4,8 @@ import {chunk} from 'hurdak/lib/hurdak'
import {batch, shuffle, timedelta, now} from 'src/util/misc'
import {
getRelaysForEventParent, getAllPubkeyWriteRelays, aggregateScores,
getUserReadRelays,
getUserReadRelays, getRelaysForEventChildren,
} from 'src/agent/relays'
import {getUserNetwork} from 'src/agent/social'
import database from 'src/agent/database'
import pool from 'src/agent/pool'
import keys from 'src/agent/keys'
@ -106,14 +105,9 @@ const loadParents = notes => {
}
const streamContext = ({notes, updateNotes, depth = 0}) => {
// We could also use getRelaysForEventChildren for a more complete view of replies,
// but it's also more likely to include spam. Checking our user's social graph
// avoids this problem. TODO: review this, maybe add note authors's graphs to this
// as well.
const relays = getAllPubkeyWriteRelays(getUserNetwork()).slice(0, 3)
// Some relays reject very large filters, send multiple
// Some relays reject very large filters, send multiple subscriptions
chunk(256, notes).forEach(chunk => {
const relays = aggregateScores(chunk.map(getRelaysForEventChildren)).slice(0, 3)
const authors = getStalePubkeys(pluck('pubkey', chunk))
const filter = [{kinds: [1, 7], '#e': pluck('id', chunk)}] as Array<object>

View File

@ -181,7 +181,7 @@ const subscribe = async (relays, filters, {onEvent, onEose}: Record<string, (e:
if (relays.length === 0) {
error(`Attempted to start subscription ${id} with zero relays`, filters)
} else {
log(`Starting subscription ${id} with ${relays.length} relays`, filters)
log(`Starting subscription ${id} with ${relays.length} relays`, filters, relays)
}
// Don't await before returning so we're not blocking on slow connects

View File

@ -2,7 +2,7 @@ import type {Relay} from 'src/util/types'
import {get} from 'svelte/store'
import {pick, map, assoc, sortBy, uniqBy, prop} from 'ramda'
import {first} from 'hurdak/lib/hurdak'
import {Tags} from 'src/util/nostr'
import {Tags, findReplyId} from 'src/util/nostr'
import {synced} from 'src/util/misc'
import database from 'src/agent/database'
import keys from 'src/agent/keys'
@ -53,14 +53,13 @@ export const getUserWriteRelays = () => getUserRelays().filter(prop('write'))
// Event-related special cases
// If we're looking for an event's parent, tags are the most reliable hint,
// but we can also look at where other people in the thread write to.
// but we can also look at where the author of the note reads from
export const getRelaysForEventParent = event => {
const tags = Tags.from(event)
const relays = tags.relays()
const pubkeys = tags.type("p").values().all()
const pubkeyRelays = pubkeys.flatMap(getPubkeyWriteRelays)
const parentId = findReplyId(event)
const relayHints = Tags.from(event).equals(parentId).relays()
const pubkeyRelays = getPubkeyReadRelays(event.pubkey)
return uniqByUrl(relays.concat(pubkeyRelays).concat({url: event.seen_on}))
return uniqByUrl(relayHints.concat({url: event.seen_on}).concat(pubkeyRelays))
}
// If we're looking for an event's children, the read relays the author has
@ -68,10 +67,12 @@ export const getRelaysForEventParent = event => {
// will write replies there. However, this may include spam, so we may want
// to read from the current user's network's read relays instead.
export const getRelaysForEventChildren = event => {
return uniqByUrl(getPubkeyReadRelays(event.pubkey).concat({url: event.seen_on}))
return uniqByUrl(getPubkeyReadRelays(event.pubkey)
.concat({url: event.seen_on, score: 1}))
}
export const getRelayForEventHint = event => ({url: event.seen_on})
export const getRelayForEventHint = event =>
({url: event.seen_on, score: 1})
export const getRelayForPersonHint = (pubkey, event) =>
first(getPubkeyWriteRelays(pubkey)) || getRelayForEventHint(event)

View File

@ -38,7 +38,12 @@ const processProfileEvents = async events => {
content.nip05_updated_at = e.created_at
}
return content
if (e.created_at > (person.profile_updated_at || 0)) {
return {
...content,
profile_updated_at: e.created_at,
}
}
})
},
3: () => ({petnames: e.tags}),
@ -173,6 +178,19 @@ const processRoutes = async events => {
})
})
},
// DEPRECATED
10001: () => {
e.tags
.forEach(([url, read, write]) => {
if (write !== '!') {
calculateRoute(e.pubkey, url, 'kind:10002', 'write', e.created_at)
}
if (read !== '!') {
calculateRoute(e.pubkey, url, 'kind:10002', 'read', e.created_at)
}
})
},
10002: () => {
e.tags
.forEach(([url, read, mode]) => {

View File

@ -201,7 +201,7 @@
{#if $person && shouldDisplay(note)}
<div bind:this={noteContainer} class="note relative">
<div class="absolute w-px bg-light z-10 ml-8 mt-12 transition-all h-0" bind:this={border} />
<div class="absolute w-px bg-light z-10 ml-8 mt-12 h-0" bind:this={border} />
<Card class="flex gap-4 relative" on:click={onClick} {interactive} {invertColors}>
{#if !showParent}
<div class="absolute h-px w-3 bg-light z-10" style="left: 0px; top: 27px;" />

View File

@ -84,8 +84,6 @@
const {limit, until} = cursor
console.log('here')
return network.listenUntilEose(relays, {...filter, until, limit}, onChunk)
})

View File

@ -146,7 +146,7 @@
<Anchor type="button-circle" on:click={unfollow}>
<i class="fa fa-user-minus" />
</Anchor>
{:else}
{:else if $user?.pubkey !== pubkey}
<Anchor type="button-circle" on:click={follow}>
<i class="fa fa-user-plus" />
</Anchor>

View File

@ -35,6 +35,9 @@ export class Tags {
type(type) {
return new Tags(this.tags.filter(t => t[0] === type))
}
equals(value) {
return new Tags(this.tags.filter(t => t[1] === value))
}
mark(mark) {
return new Tags(this.tags.filter(t => last(t) === mark))
}