Fix mutes, improve performance

This commit is contained in:
Jonathan Staab 2023-07-20 10:46:06 -07:00
parent c5b11be1bb
commit 7a73f443a9
8 changed files with 23 additions and 15 deletions

View File

@ -13,7 +13,7 @@
import NoteReply from "src/app/shared/NoteReply.svelte"
import NoteActions from "src/app/shared/NoteActions.svelte"
import Card from "src/partials/Card.svelte"
import {nip05, user, directory, nip65, nip02} from "src/app/engine"
import {Nip05, Keys, User, directory, Nip65, Nip02} from "src/app/engine"
import NoteContent from "src/app/shared/NoteContent.svelte"
export let note
@ -36,8 +36,8 @@
const showEntire = anchorId === note.id
const interactive = !anchorId || !showEntire
const author = directory.profiles.key(note.pubkey).derived(defaultTo({pubkey: note.pubkey}))
const muted = nip02.graph.derived(() => user.isIgnoring(note.id))
const handle = nip05.handles.key(note.pubkey)
const muted = Nip02.graph.key(Keys.pubkey.get()).derived(() => User.isIgnoring(note.id))
const handle = Nip05.handles.key(note.pubkey)
let border, childrenContainer, noteContainer
@ -60,13 +60,13 @@
}
const goToParent = async () => {
const relays = nip65.getParentHints(3, note)
const relays = Nip65.getParentHints(3, note)
goToNote({note: {id: findReplyId(note)}, relays})
}
const goToRoot = async () => {
const relays = nip65.getParentHints(3, note)
const relays = Nip65.getParentHints(3, note)
goToNote({note: {id: findRootId(note)}, relays})
}

View File

@ -43,9 +43,9 @@
const quote = () => modal.push({type: "note/create", quote: note})
const unmute = () => user.unmute(note.pubkey)
const unmute = () => user.unmute(note.id)
const mute = () => user.mute("p", note.pubkey)
const mute = () => user.mute("e", note.id)
const react = async content => {
const relays = nip65.getPublishHints(3, note, user.getRelayUrls("write"))

View File

@ -18,7 +18,7 @@
const feed = network.feed({
limit: 1,
depth: 6,
relays: nip65.selectHints(3, relays),
relays: nip65.selectHints(10, relays),
filter: {ids: [note.id]},
})
@ -42,7 +42,7 @@
await feed.loadAll()
console.log('NoteDetail', $displayNote)
console.log("NoteDetail", $displayNote)
loading = false
})

View File

@ -91,7 +91,8 @@
document.title = "Notifications"
const pubkey = Keys.pubkey.get()
const since = lastChecked - seconds(30, "day")
const since = Math.max(lastChecked - seconds(1, "hour"), now() - seconds(30, "day"))
const reactionKinds = ENABLE_ZAPS ? [7, 9735] : [7]
const eventIds = doPipe(Events.cache.get(), [
filter(e => noteKinds.includes(e.kind)),

View File

@ -14,6 +14,7 @@ export type SubscribeOpts = {
filter: Filter[] | Filter
onEvent?: (event: Event) => void
onEose?: (url: string) => void
onClose?: () => void
timeout?: number
shouldProcess?: boolean
}
@ -185,6 +186,7 @@ export class Network {
filter,
onEose,
onEvent,
onClose,
timeout,
shouldProcess = true,
}: SubscribeOpts) => {
@ -204,6 +206,7 @@ export class Network {
sub.unsubscribe()
executor.target.cleanup()
Network.emitter.emit("sub:close", urls)
onClose?.()
})
if (timeout) {

View File

@ -102,7 +102,7 @@ export class Nip02 {
Nip02.graph.key(e.pubkey).merge({
updated_at: now(),
mutes_updated_at: e.created_at,
mutes: Tags.from(e).type("p").all(),
mutes: Tags.from(e).type(["e", "p"]).all(),
})
})
}

View File

@ -39,7 +39,7 @@ export class Cursor {
let count = 0
return this.opts.subscribe({
timeout: 10_000,
timeout: 4000,
relays: [relay],
filter: ensurePlural(filter).map(mergeLeft({until, limit})),
onEvent: event => {
@ -54,6 +54,10 @@ export class Cursor {
this.loading = false
this.done = count < limit
},
onClose: () => {
this.loading = false
this.done = true
},
})
}

View File

@ -189,7 +189,7 @@ export class Feed {
loadParents = events => {
const {Network, Nip65} = this.opts.engine
const parentsInfo = events
.map(e => ({id: findReplyId(e), hints: Nip65.getParentHints(3, e)}))
.map(e => ({id: findReplyId(e), hints: Nip65.getParentHints(10, e)}))
.filter(({id}) => id && !this.seen.has(id))
if (parentsInfo.length > 0) {
@ -220,7 +220,7 @@ export class Feed {
for (const c of chunk(256, events)) {
Network.subscribe({
timeout: 3000,
relays: this.mergeHints(c.map(e => Nip65.getReplyHints(3, e))),
relays: this.mergeHints(c.map(e => Nip65.getReplyHints(10, e))),
filter: {kinds: this.getReplyKinds(), "#e": pluck("id", c)},
onEvent: batch(100, context => this.addContext(context, {depth: depth - 1})),
})
@ -247,7 +247,7 @@ export class Feed {
for (const c of chunk(256, findNotes(this.feed.get()))) {
this.addSubs("listeners", [
Network.subscribe({
relays: this.mergeHints(c.map(e => Nip65.getReplyHints(3, e))),
relays: this.mergeHints(c.map(e => Nip65.getReplyHints(10, e))),
filter: {kinds: this.getReplyKinds(), "#e": pluck("id", c), since: now()},
onEvent: batch(100, context => this.addContext(context, {depth: 2})),
}),