mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-28 16:00:52 +00:00
Parse relays for kind 3, show relays on network tab
This commit is contained in:
parent
7cc9ebc080
commit
18b950af0a
@ -41,7 +41,8 @@ If you like Coracle and want to support its development, you can donate sats via
|
||||
- [ ] Attachments (a tag w/content type and url)
|
||||
- [ ] Add Labs tab with cards for non-standard features
|
||||
- Time travel - see events as of a date/time
|
||||
- [ ] Linkify bech32 entities
|
||||
- [ ] Linkify bech32 entities w/ NIP 21 https://github.com/nostr-protocol/nips/blob/master/21.md
|
||||
- [ ] Sign in as user with one click to view things from their pubkey's perspective - do this with multiple accounts
|
||||
|
||||
# Bugs
|
||||
|
||||
|
@ -4,7 +4,7 @@ import {nip05} from 'nostr-tools'
|
||||
import {writable} from 'svelte/store'
|
||||
import {noop, ensurePlural, createMap, switcherFn} from 'hurdak/lib/hurdak'
|
||||
import {now} from 'src/util/misc'
|
||||
import {personKinds, Tags, roomAttrs} from 'src/util/nostr'
|
||||
import {personKinds, Tags, roomAttrs, isRelay} from 'src/util/nostr'
|
||||
|
||||
export const lq = cb => liveQuery(async () => {
|
||||
try {
|
||||
@ -87,7 +87,7 @@ const processProfileEvents = async events => {
|
||||
|
||||
return content
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.warn(e)
|
||||
}
|
||||
},
|
||||
2: () => {
|
||||
@ -98,7 +98,24 @@ const processProfileEvents = async events => {
|
||||
}
|
||||
}
|
||||
},
|
||||
3: () => ({petnames: e.tags}),
|
||||
3: () => {
|
||||
const data = {petnames: e.tags}
|
||||
|
||||
if (e.created_at > (person.relays_updated_at || 0)) {
|
||||
try {
|
||||
Object.assign(data, {
|
||||
relays_updated_at: e.created_at,
|
||||
relays: Object.entries(JSON.parse(e.content))
|
||||
.map(([url, {write, read}]) => ({url, write: write ? '' : '!', read: read ? '' : '!'}))
|
||||
.filter(r => isRelay(r.url)),
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn(e)
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
},
|
||||
12165: () => ({muffle: e.tags}),
|
||||
10001: () => {
|
||||
if (e.created_at > (person.relays_updated_at || 0)) {
|
||||
|
@ -130,7 +130,7 @@
|
||||
<div class="flex gap-4 items-center justify-between">
|
||||
<Badge person={person} />
|
||||
<Anchor
|
||||
href={"/" + nip19.neventEncode({id: note.id, relays: pluck('url', relays)})}
|
||||
href={"/" + nip19.neventEncode({id: note.id, relays: pluck('url', relays.slice(0, 5))})}
|
||||
class="text-sm text-light"
|
||||
type="unstyled">
|
||||
{formatTimestamp(note.created_at)}
|
||||
|
@ -1,33 +1,46 @@
|
||||
<script>
|
||||
import Notes from "src/partials/Notes.svelte"
|
||||
import {now, shuffle, batch, Cursor} from 'src/util/misc'
|
||||
import {getRelays, getFollows, getMuffle, listen, load} from 'src/agent'
|
||||
import loaders from 'src/app/loaders'
|
||||
import {threadify} from 'src/app'
|
||||
import {last, find, whereEq} from 'ramda'
|
||||
import {fly} from 'svelte/transition'
|
||||
import Content from "src/partials/Content.svelte"
|
||||
import Anchor from "src/partials/Anchor.svelte"
|
||||
import {user} from 'src/agent'
|
||||
import {addRelay, removeRelay} from "src/app"
|
||||
|
||||
export let pubkey
|
||||
export let person
|
||||
|
||||
const relays = getRelays(pubkey)
|
||||
const follows = getFollows(pubkey)
|
||||
const network = shuffle(follows.flatMap(getFollows)).slice(0, 50)
|
||||
const authors = follows.concat(network)
|
||||
const filter = {kinds: [1, 7], authors}
|
||||
const cursor = new Cursor()
|
||||
const join = async url => {
|
||||
await addRelay({url})
|
||||
}
|
||||
|
||||
const listenForNotes = onNotes =>
|
||||
listen(relays, {...filter, since: now()}, batch(300, async notes => {
|
||||
const context = await loaders.loadContext(relays, notes)
|
||||
|
||||
onNotes(threadify(notes, context, {muffle: getMuffle()}))
|
||||
}))
|
||||
|
||||
const loadNotes = async () => {
|
||||
const {limit, until} = cursor
|
||||
const notes = await load(relays, {...filter, limit, until})
|
||||
const context = await loaders.loadContext(relays, notes)
|
||||
|
||||
return threadify(notes, context, {muffle: getMuffle()})
|
||||
const leave = async url => {
|
||||
await removeRelay(url)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Notes {listenForNotes} {loadNotes} />
|
||||
<div in:fly={{y: 20}}>
|
||||
<Content>
|
||||
<p>
|
||||
Below are the relays this user publishes to. Join one or more to make sure you never
|
||||
miss their updates.
|
||||
</p>
|
||||
{#if (person.relays || []).length === 0}
|
||||
<div class="pt-8 text-center">No relays found</div>
|
||||
{:else}
|
||||
{#each person.relays as {url, write}, i (url)}
|
||||
<div class="rounded border border-solid border-medium bg-dark shadow p-2 px-3">
|
||||
<div class="flex gap-2 items-center justify-between">
|
||||
<strong class="flex gap-2 items-center">
|
||||
<i class={url.startsWith('wss') ? "fa fa-lock" : "fa fa-unlock"} />
|
||||
{last(url.split('://'))}
|
||||
</strong>
|
||||
{#if find(whereEq({url}), $user.relays)}
|
||||
<Anchor type="button" on:click={() => leave(url)}>Leave</Anchor>
|
||||
{:else}
|
||||
<Anchor type="button" on:click={() => join(url)}>Join</Anchor>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
</Content>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user