mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-18 19:23:40 +00:00
Fix key parsing, null people
This commit is contained in:
parent
1582ef4a5c
commit
419a57b7f7
@ -1,8 +1,6 @@
|
||||
# Current
|
||||
|
||||
- [ ] Await publish, show error if it fails or times out
|
||||
- [ ] Fix initial relay loading, don't nuke people's relay lists
|
||||
- [ ] Add a nuclear bypass with a warning, after we fail to find anything
|
||||
|
||||
# Next
|
||||
|
||||
@ -24,6 +22,8 @@
|
||||
|
||||
# More
|
||||
|
||||
- [ ] Hover badge to view profile like twitter
|
||||
- [ ] Show created date as bitcoin block height (add a setting?)
|
||||
- [ ] Support relay auth
|
||||
- [ ] Following indicator on person info
|
||||
- [ ] Share button for notes, shows qr code and nevent
|
||||
|
@ -3,7 +3,7 @@ import {prop, pick, join, uniqBy, last} from 'ramda'
|
||||
import {get} from 'svelte/store'
|
||||
import {first} from "hurdak/lib/hurdak"
|
||||
import {roomAttrs, displayPerson} from 'src/util/nostr'
|
||||
import {getPubkeyWriteRelays, getRelayForPersonHint, getUserReadRelays} from 'src/agent/relays'
|
||||
import {getPubkeyWriteRelays, getRelayForPersonHint, sampleRelays} from 'src/agent/relays'
|
||||
import database from 'src/agent/database'
|
||||
import network from 'src/agent/network'
|
||||
import keys from 'src/agent/keys'
|
||||
@ -45,7 +45,7 @@ const createDirectMessage = (relays, pubkey, content) =>
|
||||
const createNote = (relays, content, mentions = [], topics = []) => {
|
||||
mentions = mentions.map(pubkey => {
|
||||
const name = displayPerson(database.getPersonWithFallback(pubkey))
|
||||
const [{url}] = getPubkeyWriteRelays(pubkey) || getUserReadRelays()
|
||||
const [{url}] = sampleRelays(getPubkeyWriteRelays(pubkey))
|
||||
|
||||
return ["p", pubkey, url, name]
|
||||
})
|
||||
|
@ -199,7 +199,8 @@ const subscribe = async (
|
||||
if (!seen.has(e.id)) {
|
||||
seen.add(e.id)
|
||||
|
||||
onEvent({...e, seen_on: relay.url})
|
||||
// Normalize events here, annotate with relay url
|
||||
onEvent({...e, seen_on: relay.url, content: e.content || ''})
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import type {DisplayEvent} from 'src/util/types'
|
||||
import {navigate} from 'svelte-routing'
|
||||
import {omit, sortBy, identity} from 'ramda'
|
||||
import {omit, sortBy} from 'ramda'
|
||||
import {createMap, ellipsize} from 'hurdak/lib/hurdak'
|
||||
import {renderContent} from 'src/util/html'
|
||||
import {Tags, displayPerson, findReplyId} from 'src/util/nostr'
|
||||
import {displayPerson, findReplyId} from 'src/util/nostr'
|
||||
import {getUserFollows} from 'src/agent/social'
|
||||
import {getUserReadRelays} from 'src/agent/relays'
|
||||
import database from 'src/agent/database'
|
||||
@ -40,16 +40,12 @@ export const signup = privkey => {
|
||||
}
|
||||
|
||||
export const renderNote = (note, {showEntire = false}) => {
|
||||
const shouldEllipsize = note.content.length > 500 && !showEntire
|
||||
const peopleByPubkey = createMap(
|
||||
'pubkey',
|
||||
Tags.from(note).type("p").values().all().map(k => database.people.get(k)).filter(identity)
|
||||
)
|
||||
|
||||
let content
|
||||
|
||||
// Ellipsize
|
||||
content = shouldEllipsize ? ellipsize(note.content, 500) : note.content
|
||||
content = note.content.length > 500 && !showEntire
|
||||
? ellipsize(note.content, 500)
|
||||
: note.content
|
||||
|
||||
// Escape html, replace urls
|
||||
content = renderContent(content)
|
||||
@ -62,7 +58,7 @@ export const renderNote = (note, {showEntire = false}) => {
|
||||
}
|
||||
|
||||
const pubkey = note.tags[parseInt(i)][1]
|
||||
const person = peopleByPubkey[pubkey] || {pubkey}
|
||||
const person = database.getPersonWithFallback(pubkey)
|
||||
const name = displayPerson(person)
|
||||
const path = routes.person(pubkey)
|
||||
|
||||
|
@ -64,7 +64,7 @@
|
||||
<h1 class="text-2xl">Your Follows</h1>
|
||||
{/if}
|
||||
{#each $petnamePubkeys as pubkey (pubkey)}
|
||||
<PersonInfo person={database.people.get(pubkey)} />
|
||||
<PersonInfo person={database.getPersonWithFallback(pubkey)} />
|
||||
{:else}
|
||||
<div class="flex flex-col items-center gap-4 my-8">
|
||||
<div class="text-xl flex gap-2 items-center">
|
||||
|
@ -1,11 +1,14 @@
|
||||
<script lang="ts">
|
||||
import keys from 'src/agent/keys'
|
||||
import user from 'src/agent/user'
|
||||
import {modal} from "src/app/ui"
|
||||
|
||||
export let pubkey = null
|
||||
|
||||
const {relays} = user
|
||||
</script>
|
||||
|
||||
{#if keys.canSign()}
|
||||
{#if keys.canSign() && $relays.length > 0}
|
||||
<div class="fixed bottom-0 right-0 m-8">
|
||||
<button
|
||||
class="rounded-full bg-accent color-white w-16 h-16 flex justify-center
|
||||
|
@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {pluck} from 'ramda'
|
||||
import {nip19} from 'nostr-tools'
|
||||
import {now} from 'src/util/misc'
|
||||
import {toHex} from 'src/util/nostr'
|
||||
import Channel from 'src/partials/Channel.svelte'
|
||||
import user from 'src/agent/user'
|
||||
import {getRelaysForEventChildren} from 'src/agent/relays'
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
export let entity
|
||||
|
||||
const {data: roomId} = nip19.decode(entity) as {data: string}
|
||||
const roomId = toHex(entity)
|
||||
const room = database.watch('rooms', rooms => rooms.get(roomId))
|
||||
|
||||
const listenForMessages = async cb => {
|
||||
|
@ -1,8 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {nip19} from 'nostr-tools'
|
||||
import {sortBy, pluck} from 'ramda'
|
||||
import {renameProp} from 'hurdak/lib/hurdak'
|
||||
import {personKinds, displayPerson} from 'src/util/nostr'
|
||||
import {personKinds, toHex, displayPerson} from 'src/util/nostr'
|
||||
import {now} from 'src/util/misc'
|
||||
import Channel from 'src/partials/Channel.svelte'
|
||||
import user from 'src/agent/user'
|
||||
@ -17,7 +16,7 @@
|
||||
export let entity
|
||||
|
||||
let crypt = keys.getCrypt()
|
||||
let {data: pubkey} = nip19.decode(entity) as {data: string}
|
||||
let pubkey = toHex(entity)
|
||||
let person = database.watch('people', () => database.getPersonWithFallback(pubkey))
|
||||
|
||||
messages.lastCheckedByPubkey.update($obj => ({...$obj, [pubkey]: now()}))
|
||||
|
@ -2,13 +2,12 @@
|
||||
import {last, prop} from 'ramda'
|
||||
import {onMount} from 'svelte'
|
||||
import {tweened} from 'svelte/motion'
|
||||
import {nip19} from 'nostr-tools'
|
||||
import {fly} from 'svelte/transition'
|
||||
import {navigate} from 'svelte-routing'
|
||||
import {first} from 'hurdak/lib/hurdak'
|
||||
import {log} from 'src/util/logger'
|
||||
import {renderContent} from 'src/util/html'
|
||||
import {displayPerson, Tags} from 'src/util/nostr'
|
||||
import {displayPerson, Tags, toHex} from 'src/util/nostr'
|
||||
import Tabs from "src/partials/Tabs.svelte"
|
||||
import Content from "src/partials/Content.svelte"
|
||||
import NewNoteButton from "src/partials/NewNoteButton.svelte"
|
||||
@ -31,7 +30,7 @@
|
||||
const interpolate = (a, b) => t => a + Math.round((b - a) * t)
|
||||
const {petnamePubkeys} = user
|
||||
|
||||
let pubkey = nip19.decode(npub).data as string
|
||||
let pubkey = toHex(npub)
|
||||
let following = false
|
||||
let followers = new Set()
|
||||
let followersCount = tweened(0, {interpolate, duration: 1000})
|
||||
|
@ -102,3 +102,11 @@ export const roomAttrs = ['name', 'about', 'picture']
|
||||
|
||||
export const asDisplayEvent = event =>
|
||||
({replies: [], reactions: [], ...event}) as DisplayEvent
|
||||
|
||||
export const toHex = (data: string): string | null => {
|
||||
try {
|
||||
return nip19.decode(data).data as string
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {nip19} from 'nostr-tools'
|
||||
import {toHex} from 'src/util/nostr'
|
||||
import Input from 'src/partials/Input.svelte'
|
||||
import Anchor from 'src/partials/Anchor.svelte'
|
||||
import Content from 'src/partials/Content.svelte'
|
||||
@ -11,14 +11,9 @@
|
||||
const nip07 = "https://github.com/nostr-protocol/nips/blob/master/07.md"
|
||||
|
||||
const logIn = () => {
|
||||
let privkey = ''
|
||||
try {
|
||||
privkey = (nsec.startsWith('nsec') ? nip19.decode(nsec).data : nsec) as string
|
||||
} catch (e) {
|
||||
// pass
|
||||
}
|
||||
const privkey = nsec.startsWith('nsec') ? toHex(nsec) : nsec
|
||||
|
||||
if (!privkey.match(/[a-z0-9]{64}/)) {
|
||||
if (!privkey?.match(/[a-z0-9]{64}/)) {
|
||||
toast.show("error", "Sorry, but that's an invalid private key.")
|
||||
} else {
|
||||
login({privkey})
|
||||
|
@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {nip19} from 'nostr-tools'
|
||||
import {toHex} from 'src/util/nostr'
|
||||
import Input from 'src/partials/Input.svelte'
|
||||
import Anchor from 'src/partials/Anchor.svelte'
|
||||
import Content from 'src/partials/Content.svelte'
|
||||
@ -10,14 +10,9 @@
|
||||
let npub = ''
|
||||
|
||||
const logIn = () => {
|
||||
let pubkey = ''
|
||||
try {
|
||||
pubkey = (npub.startsWith('npub') ? nip19.decode(npub).data : npub) as string
|
||||
} catch (e) {
|
||||
// pass
|
||||
}
|
||||
const pubkey = npub.startsWith('npub') ? toHex(npub) : npub
|
||||
|
||||
if (!pubkey.match(/[a-z0-9]{64}/)) {
|
||||
if (!pubkey?.match(/[a-z0-9]{64}/)) {
|
||||
toast.show("error", "Sorry, but that's an invalid public key.")
|
||||
} else {
|
||||
login({pubkey})
|
||||
|
@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {nip19, generatePrivateKey} from 'nostr-tools'
|
||||
import {copyToClipboard} from "src/util/html"
|
||||
import {toHex} from "src/util/nostr"
|
||||
import Input from 'src/partials/Input.svelte'
|
||||
import Anchor from 'src/partials/Anchor.svelte'
|
||||
import Content from 'src/partials/Content.svelte'
|
||||
@ -11,9 +12,7 @@
|
||||
const nsec = nip19.nsecEncode(generatePrivateKey())
|
||||
const nip07 = "https://github.com/nostr-protocol/nips/blob/master/07.md"
|
||||
|
||||
const logIn = () => {
|
||||
signup(nip19.decode(nsec).data as string)
|
||||
}
|
||||
const logIn = () => signup(toHex(nsec))
|
||||
|
||||
const copyKey = () => {
|
||||
copyToClipboard(nsec)
|
||||
|
Loading…
Reference in New Issue
Block a user