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 # Current
- [ ] Add search for topics
- [ ] Fix relay recommendations - [ ] Fix relay recommendations
- [ ] Preview note1
- [ ] Pagination is slow. Maybe load with no window first, then add since? - [ ] Pagination is slow. Maybe load with no window first, then add since?
- [ ] Add coupon code registration for relay - [ ] Add coupon code registration for relay
- [ ] Repurpose chat as groups - [ ] Repurpose chat as groups
@ -47,6 +47,9 @@
# UI/Features # 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 - [ ] Use real links so cmd+click or right click work
- [ ] Allow sharing of lists/following other people's lists - [ ] Allow sharing of lists/following other people's lists
- [ ] Add suggestion list for topics on compose - [ ] Add suggestion list for topics on compose

View File

@ -1,8 +1,8 @@
import {map, pick, last, uniqBy} from "ramda" import {map, pick, last, uniqBy} from "ramda"
import {get} from "svelte/store" import {get} from "svelte/store"
import {doPipe} from "hurdak/lib/hurdak" import {doPipe} from "hurdak/lib/hurdak"
import {parseContent, Tags, roomAttrs, displayPerson, findReplyId, findRootId} from "src/util/nostr" import {parseContent, Tags, roomAttrs, displayPerson, findRoot, findReply} from "src/util/nostr"
import {getRelayForPersonHint} from "src/agent/relays" import {getRelayForPersonHint, getRelayForEventHint} from "src/agent/relays"
import {getPersonWithFallback} from "src/agent/db" import {getPersonWithFallback} from "src/agent/db"
import pool from "src/agent/pool" import pool from "src/agent/pool"
import sync from "src/agent/sync" 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 processMentions = map(pubkey => {
const name = displayPerson(getPersonWithFallback(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) => { const tagsFromContent = (content, tags) => {
@ -122,9 +122,9 @@ const tagsFromContent = (content, tags) => {
if (type.match(/nostr:(nprofile|npub)/) && !seen.has(value.pubkey)) { if (type.match(/nostr:(nprofile|npub)/) && !seen.has(value.pubkey)) {
const name = displayPerson(getPersonWithFallback(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) seen.add(value.pubkey)
} }
} }
@ -133,14 +133,15 @@ const tagsFromContent = (content, tags) => {
} }
const getReplyTags = n => { const getReplyTags = n => {
const {url} = getRelayForPersonHint(n.pubkey, n) const pHint = getRelayForPersonHint(n.pubkey)
const rootId = findRootId(n) || findReplyId(n) || n.id 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 [ return [["p", n.pubkey, pHint?.url || ""], root, reply]
["p", n.pubkey, url],
["e", n.id, url, "reply"],
["e", rootId, url, "root"],
]
} }
const tagsFromParent = (n, newTags = []) => { const tagsFromParent = (n, newTags = []) => {

View File

@ -210,7 +210,7 @@ async function getExecutor(urls, {bypassBoot = false} = {}) {
onAuth(url, challenge) { onAuth(url, challenge) {
Meta.errors[url] = "unauthorized" Meta.errors[url] = "unauthorized"
return Config.authHandler(url, challenge) return Config.authHandler?.(url, challenge)
}, },
onOk(url, id, ok, message) { onOk(url, id, ok, message) {
Meta.errors[url] = ok ? null : "forbidden" 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 => {
export const getRelayForPersonHint = (pubkey, event = null) => {
let relays = getPubkeyWriteRelays(pubkey) let relays = getPubkeyWriteRelays(pubkey)
if (relays.length === 0 && event) {
relays = [getRelayForEventHint(event)]
}
if (relays.length === 0) { if (relays.length === 0) {
relays = getPubkeyReadRelays(pubkey) relays = getPubkeyReadRelays(pubkey)
} }
@ -136,6 +130,9 @@ export const getRelayForPersonHint = (pubkey, event = null) => {
return first(relays) 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 // 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 // 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 // relays. Limit how many per pubkey we publish to though. We also want to advertise