Improve hints a bit

This commit is contained in:
Jonathan Staab 2023-05-04 20:16:47 -07:00
parent ce19810762
commit 31b9f1ffde
4 changed files with 24 additions and 23 deletions

View File

@ -1,7 +1,7 @@
# Current
- [ ] Add search for topics
- [ ] Fix relay recommendations
- [ ] Preview note1
- [ ] Pagination is slow. Maybe load with no window first, then add since?
- [ ] Add coupon code registration for relay
- [ ] Repurpose chat as groups
@ -47,6 +47,9 @@
# UI/Features
- [ ] Combine search and scan
- [ ] Search for topics using nostr.band
- [ ] Include notes in search results
- [ ] Use real links so cmd+click or right click work
- [ ] Allow sharing of lists/following other people's lists
- [ ] Add suggestion list for topics on compose

View File

@ -1,8 +1,8 @@
import {map, pick, last, uniqBy} from "ramda"
import {get} from "svelte/store"
import {doPipe} from "hurdak/lib/hurdak"
import {parseContent, Tags, roomAttrs, displayPerson, findReplyId, findRootId} from "src/util/nostr"
import {getRelayForPersonHint} from "src/agent/relays"
import {parseContent, Tags, roomAttrs, displayPerson, findRoot, findReply} from "src/util/nostr"
import {getRelayForPersonHint, getRelayForEventHint} from "src/agent/relays"
import {getPersonWithFallback} from "src/agent/db"
import pool from "src/agent/pool"
import sync from "src/agent/sync"
@ -106,9 +106,9 @@ const deleteEvent = ids => new PublishableEvent(5, {tags: ids.map(id => ["e", id
const processMentions = map(pubkey => {
const name = displayPerson(getPersonWithFallback(pubkey))
const relay = getRelayForPersonHint(pubkey)
const pHint = getRelayForPersonHint(pubkey)
return ["p", pubkey, relay?.url || "", name]
return ["p", pubkey, pHint?.url || "", name]
})
const tagsFromContent = (content, tags) => {
@ -122,9 +122,9 @@ const tagsFromContent = (content, tags) => {
if (type.match(/nostr:(nprofile|npub)/) && !seen.has(value.pubkey)) {
const name = displayPerson(getPersonWithFallback(value.pubkey))
const relay = getRelayForPersonHint(value.pubkey)
const pHint = getRelayForPersonHint(value.pubkey)
tags = tags.concat([["p", value.pubkey, relay?.url || "", name]])
tags = tags.concat([["p", value.pubkey, pHint?.url || "", name]])
seen.add(value.pubkey)
}
}
@ -133,14 +133,15 @@ const tagsFromContent = (content, tags) => {
}
const getReplyTags = n => {
const {url} = getRelayForPersonHint(n.pubkey, n)
const rootId = findRootId(n) || findReplyId(n) || n.id
const pHint = getRelayForPersonHint(n.pubkey)
const eHint = getRelayForEventHint(n) || pHint
const reply = ["e", n.id, eHint?.url || "", "reply"]
const root = doPipe(findRoot(n) || findReply(n) || reply, [
t => (t.length < 3 ? t.concat(eHint?.url || "") : t),
t => t.slice(0, 3).concat("root"),
])
return [
["p", n.pubkey, url],
["e", n.id, url, "reply"],
["e", rootId, url, "root"],
]
return [["p", n.pubkey, pHint?.url || ""], root, reply]
}
const tagsFromParent = (n, newTags = []) => {
@ -188,7 +189,7 @@ class PublishableEvent {
}
async publish(relays, onProgress = null, verb = "EVENT") {
const event = await this.getSignedEvent()
//console.log(event); return
// console.log(event); return
const promise = pool.publish({relays, event, onProgress, verb})
// Copy the event since loki mutates it to add metadata

View File

@ -210,7 +210,7 @@ async function getExecutor(urls, {bypassBoot = false} = {}) {
onAuth(url, challenge) {
Meta.errors[url] = "unauthorized"
return Config.authHandler(url, challenge)
return Config.authHandler?.(url, challenge)
},
onOk(url, id, ok, message) {
Meta.errors[url] = ok ? null : "forbidden"

View File

@ -120,15 +120,9 @@ export const getRelaysForEventChildren = event => {
)
}
export const getRelayForEventHint = event => ({url: event.seen_on[0], score: 1})
export const getRelayForPersonHint = (pubkey, event = null) => {
export const getRelayForPersonHint = pubkey => {
let relays = getPubkeyWriteRelays(pubkey)
if (relays.length === 0 && event) {
relays = [getRelayForEventHint(event)]
}
if (relays.length === 0) {
relays = getPubkeyReadRelays(pubkey)
}
@ -136,6 +130,9 @@ export const getRelayForPersonHint = (pubkey, event = null) => {
return first(relays)
}
export const getRelayForEventHint = ({pubkey, seen_on: [url]}) =>
getRelayForPersonHint(pubkey) || {url, score: 1}
// If we're replying or reacting to an event, we want the author to know, as well as
// anyone else who is tagged in the original event or the reply. Get everyone's read
// relays. Limit how many per pubkey we publish to though. We also want to advertise