Mutate seen_on to show all relays a given note was found on

This commit is contained in:
Jonathan Staab 2023-04-05 15:19:22 -05:00
parent dadc93b28a
commit 5e9c9cfef1
5 changed files with 34 additions and 19 deletions

View File

@ -9,6 +9,7 @@
- [x] Remove flag reactions, since they're somewhat redundant with mutes
- [x] Generally improve UI consistency and feel
- [x] Add event id, likers, and zappers to note info popover
- [x] Mutate seen_on to show all relays a given note was found on
## 0.2.21

View File

@ -268,7 +268,7 @@ async function subscribe({relays, filter, onEvent, onEose}: SubscribeOpts) {
const executor = getExecutor(urls)
const filters = ensurePlural(filter)
const now = Date.now()
const seen = new Set()
const seen = new Map()
const eose = new Set()
log(`Starting subscription with ${relays.length} relays`, filters, relays)
@ -280,15 +280,26 @@ async function subscribe({relays, filter, onEvent, onEose}: SubscribeOpts) {
Meta.onSubscriptionStart(urls)
executor.subscribe(filters, {
onEvent: (url, e) => {
if (seen.has(e.id)) {
onEvent: (url, event) => {
const seen_on = seen.get(event.id)
if (seen_on) {
if (!seen_on.includes(url)) {
seen_on.push(url)
}
return
}
seen.add(e.id)
Object.assign(event, {
seen_on: [url],
content: event.content || "",
})
seen.set(event.id, event.seen_on)
try {
if (!verifySignature(e)) {
if (!verifySignature(event)) {
return
}
} catch (e) {
@ -299,7 +310,7 @@ async function subscribe({relays, filter, onEvent, onEose}: SubscribeOpts) {
Meta.onEvent(url)
onEvent({...e, seen_on: url, content: e.content || ""})
onEvent(event)
},
onEose: url => {
onEose?.(url)

View File

@ -109,7 +109,7 @@ export const getRelaysForEventParent = event => {
const relayHints = Tags.from(event).equals(parentId).relays()
const pubkeyRelays = getPubkeyReadRelays(event.pubkey)
return uniqByUrl(relayHints.concat({url: event.seen_on}).concat(pubkeyRelays))
return uniqByUrl(relayHints.concat(event.seen_on.map(objOf("url"))).concat(pubkeyRelays))
}
// If we're looking for an event's children, the read relays the author has
@ -117,10 +117,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, score: 1}))
return uniqByUrl(
getPubkeyReadRelays(event.pubkey).concat(event.seen_on.map(url => ({url, score: 1})))
)
}
export const getRelayForEventHint = event => ({url: event.seen_on, score: 1})
export const getRelayForEventHint = event => ({url: event.seen_on[0], score: 1})
export const getRelayForPersonHint = (pubkey, event = null) => {
let relays = getPubkeyWriteRelays(pubkey)

View File

@ -1,4 +1,4 @@
import type {Event} from 'nostr-tools'
import type {Event} from "nostr-tools"
export type Relay = {
url: string
@ -17,12 +17,11 @@ export type Person = {
about?: string
nip05?: string
picture?: string
},
}
}
export type MyEvent = Event & {
seen_on: string
seen_on: string[]
}
export type DisplayEvent = MyEvent & {
@ -32,7 +31,7 @@ export type DisplayEvent = MyEvent & {
}
export type Room = {
id: string,
id: string
pubkey: string
name?: string
about?: string

View File

@ -303,14 +303,14 @@
}
const copyLink = () => {
const nevent = nip19.neventEncode({id: note.id, relays: [note.seen_on]})
const nevent = nip19.neventEncode({id: note.id, relays: note.seen_on})
copyToClipboard("nostr:" + nevent)
toast.show("info", "Note link copied to clipboard!")
}
const quote = () => {
const nevent = nip19.neventEncode({id: note.id, relays: [note.seen_on]})
const nevent = nip19.neventEncode({id: note.id, relays: note.seen_on})
modal.set({type: "note/create", nevent})
}
@ -388,7 +388,7 @@
</div>
</Popover>
<Anchor
href={"/" + nip19.neventEncode({id: note.id, relays: [note.seen_on]})}
href={"/" + nip19.neventEncode({id: note.id, relays: note.seen_on})}
class="text-sm text-gray-1"
type="unstyled">
{timestamp}
@ -592,8 +592,10 @@
</div>
{/if}
<h1 class="staatliches text-2xl">Relays</h1>
<p>This note was found on the relay below.</p>
<RelayCard theme="black" showControls relay={{url: note.seen_on}} />
<p>This note was found on the {quantify(note.seen_on.length, "relay")} below.</p>
{#each note.seen_on as url}
<RelayCard theme="black" showControls relay={{url}} />
{/each}
<h1 class="staatliches text-2xl">Details</h1>
<CopyValue label="Identifier" value={nevent} />
<CopyValue label="Event ID (note)" value={bech32Note} />