mirror of
https://github.com/coracle-social/coracle.git
synced 2024-10-06 11:43:30 +00:00
Upgrade nostr tools, fix initial user/network loading, fix unnecessary dm alerts
This commit is contained in:
parent
9ad897adef
commit
7dbb69e54a
@ -11,6 +11,8 @@
|
|||||||
- [x] Show relay status based on stats not current connection status
|
- [x] Show relay status based on stats not current connection status
|
||||||
- [x] Auto-mention person when creating a note from their profile page
|
- [x] Auto-mention person when creating a note from their profile page
|
||||||
- [x] Make chat header overlap main header to save space
|
- [x] Make chat header overlap main header to save space
|
||||||
|
- [x] Strip formatting when pasting into Compose
|
||||||
|
- [x] Upgraded nostr-tools to 1.4.1
|
||||||
|
|
||||||
## 0.2.11
|
## 0.2.11
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@
|
|||||||
- [ ] Fix anon/new user experience
|
- [ ] Fix anon/new user experience
|
||||||
- [ ] Initial user load doesn't have any relays, cache user or wait for people db to be loaded
|
- [ ] Initial user load doesn't have any relays, cache user or wait for people db to be loaded
|
||||||
- [ ] Fix bugs on bugsnag
|
- [ ] Fix bugs on bugsnag
|
||||||
- [ ] Fix bugs on github
|
|
||||||
|
|
||||||
# Snacks
|
# Snacks
|
||||||
|
|
||||||
|
- [ ] Relay recommendations based on follows/followers
|
||||||
- [ ] Pinned posts ala snort
|
- [ ] Pinned posts ala snort
|
||||||
- [ ] Likes list on note detail. Maybe a sidebar or header for note detail page?
|
- [ ] Likes list on note detail. Maybe a sidebar or header for note detail page?
|
||||||
- [ ] Support key delegation
|
- [ ] Support key delegation
|
||||||
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
# Maintenance
|
# Maintenance
|
||||||
|
|
||||||
- [ ] If the latest message in a dm was the user, don't show notification
|
- [ ] Don't waste space caching rooms, load those lazily
|
||||||
- [ ] Normalize relay urls (lowercase, strip trailing slash)
|
- [ ] Normalize relay urls (lowercase, strip trailing slash)
|
||||||
- [ ] Use nip 56 for reporting
|
- [ ] Use nip 56 for reporting
|
||||||
- https://github.com/nostr-protocol/nips/pull/205#issuecomment-1419234230
|
- https://github.com/nostr-protocol/nips/pull/205#issuecomment-1419234230
|
||||||
|
BIN
package-lock.json
generated
BIN
package-lock.json
generated
Binary file not shown.
@ -38,7 +38,7 @@
|
|||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"localforage-memoryStorageDriver": "^0.9.2",
|
"localforage-memoryStorageDriver": "^0.9.2",
|
||||||
"nostr-tools": "^1.2.1",
|
"nostr-tools": "^1.4.1",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"qr-scanner": "^1.4.2",
|
"qr-scanner": "^1.4.2",
|
||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
import "@fortawesome/fontawesome-free/css/solid.css"
|
import "@fortawesome/fontawesome-free/css/solid.css"
|
||||||
|
|
||||||
import {find, is, identity, nthArg, pluck} from 'ramda'
|
import {find, is, identity, nthArg, pluck} from 'ramda'
|
||||||
import {onMount} from "svelte"
|
|
||||||
import {createMap, first} from 'hurdak/lib/hurdak'
|
import {createMap, first} from 'hurdak/lib/hurdak'
|
||||||
import {writable, get} from "svelte/store"
|
import {writable, get} from "svelte/store"
|
||||||
import {fly, fade} from "svelte/transition"
|
import {fly, fade} from "svelte/transition"
|
||||||
@ -88,13 +87,12 @@
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
database.onReady(() => {
|
||||||
if ($user) {
|
if ($user) {
|
||||||
loadAppData($user.pubkey)
|
loadAppData($user.pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background work
|
// Background work
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
alertSlowConnections()
|
alertSlowConnections()
|
||||||
retrieveRelayMeta()
|
retrieveRelayMeta()
|
||||||
@ -168,6 +166,7 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Log usage on navigate
|
||||||
const unsubHistory = globalHistory.listen(({location}) => {
|
const unsubHistory = globalHistory.listen(({location}) => {
|
||||||
if (!location.hash) {
|
if (!location.hash) {
|
||||||
// Remove identifying information, e.g. pubkeys, event ids, etc
|
// Remove identifying information, e.g. pubkeys, event ids, etc
|
||||||
@ -178,8 +177,8 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Keep scroll position on body, but don't allow scrolling
|
||||||
const unsubModal = modal.subscribe($modal => {
|
const unsubModal = modal.subscribe($modal => {
|
||||||
// Keep scroll position on body, but don't allow scrolling
|
|
||||||
if ($modal) {
|
if ($modal) {
|
||||||
logUsage(btoa(['modal', $modal.type].join(':')))
|
logUsage(btoa(['modal', $modal.type].join(':')))
|
||||||
|
|
||||||
|
@ -304,8 +304,17 @@ const clearAll = () => Promise.all(Object.keys(registry).map(clear))
|
|||||||
|
|
||||||
const ready = derived(pluck('ready', Object.values(registry)), all(identity))
|
const ready = derived(pluck('ready', Object.values(registry)), all(identity))
|
||||||
|
|
||||||
|
const onReady = cb => {
|
||||||
|
const unsub = ready.subscribe($ready => {
|
||||||
|
if ($ready) {
|
||||||
|
cb()
|
||||||
|
unsub()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getItem, setItem, setItems, removeItem, removeItems, length, clear, keys,
|
getItem, setItem, setItems, removeItem, removeItems, length, clear, keys,
|
||||||
dump, iterate, watch, getPersonWithFallback, clearAll, people, rooms, messages,
|
dump, iterate, watch, getPersonWithFallback, clearAll, people, rooms, messages,
|
||||||
alerts, relays, routes, ready,
|
alerts, relays, routes, ready, onReady,
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,8 @@ export const getMuffle = () => {
|
|||||||
return Tags.wrap($user.muffle.filter(shouldMuffle)).values().all()
|
return Tags.wrap($user.muffle.filter(shouldMuffle)).values().all()
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getFollows = pubkey => {
|
export const getFollows = pubkey =>
|
||||||
const person = database.getPersonWithFallback(pubkey)
|
database.getPersonWithFallback(pubkey).petnames || defaults.petnames
|
||||||
|
|
||||||
return Tags.wrap(person.petnames || defaults.petnames).values().all()
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getPersonRelays = (person, mode = 'all') => {
|
export const getPersonRelays = (person, mode = 'all') => {
|
||||||
const relays = isEmpty(person?.relays || []) ? defaults.relays : person.relays
|
const relays = isEmpty(person?.relays || []) ? defaults.relays : person.relays
|
||||||
|
@ -2,7 +2,7 @@ import {uniq, uniqBy, prop, map, propEq, indexBy, pluck} from 'ramda'
|
|||||||
import {findReply, personKinds, findReplyId, Tags} from 'src/util/nostr'
|
import {findReply, personKinds, findReplyId, Tags} from 'src/util/nostr'
|
||||||
import {chunk} from 'hurdak/lib/hurdak'
|
import {chunk} from 'hurdak/lib/hurdak'
|
||||||
import {batch} from 'src/util/misc'
|
import {batch} from 'src/util/misc'
|
||||||
import {getFollows, getStalePubkeys, getTopEventRelays} from 'src/agent/helpers'
|
import {getStalePubkeys, getTopEventRelays} from 'src/agent/helpers'
|
||||||
import pool from 'src/agent/pool'
|
import pool from 'src/agent/pool'
|
||||||
import keys from 'src/agent/keys'
|
import keys from 'src/agent/keys'
|
||||||
import sync from 'src/agent/sync'
|
import sync from 'src/agent/sync'
|
||||||
@ -70,13 +70,6 @@ const loadPeople = (relays, pubkeys, {kinds = personKinds, force = false, ...opt
|
|||||||
: Promise.resolve([])
|
: Promise.resolve([])
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadNetwork = async (relays, pubkey) => {
|
|
||||||
const tags = Tags.wrap(getFollows(pubkey))
|
|
||||||
|
|
||||||
// Use nip-2 recommended relays to load our user's second-order follows
|
|
||||||
await loadPeople(tags.relays(), tags.values().all())
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadParents = (relays, notes) => {
|
const loadParents = (relays, notes) => {
|
||||||
const parentIds = new Set(Tags.wrap(notes.map(findReply)).values().all())
|
const parentIds = new Set(Tags.wrap(notes.map(findReply)).values().all())
|
||||||
|
|
||||||
@ -128,7 +121,7 @@ const streamContext = ({relays, notes, updateNotes, depth = 0}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
publish, load, listen, listenUntilEose, loadNetwork, loadPeople, personKinds,
|
publish, load, listen, listenUntilEose, loadPeople, personKinds,
|
||||||
loadParents, streamContext,
|
loadParents, streamContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import type {MyEvent} from 'src/util/types'
|
|||||||
import {relayInit} from 'nostr-tools'
|
import {relayInit} from 'nostr-tools'
|
||||||
import {uniqBy, without, prop, find, is} from 'ramda'
|
import {uniqBy, without, prop, find, is} from 'ramda'
|
||||||
import {ensurePlural} from 'hurdak/lib/hurdak'
|
import {ensurePlural} from 'hurdak/lib/hurdak'
|
||||||
import {warn, log} from 'src/util/logger'
|
import {warn, log, error} from 'src/util/logger'
|
||||||
import {isRelay} from 'src/util/nostr'
|
import {isRelay} from 'src/util/nostr'
|
||||||
import {sleep} from 'src/util/misc'
|
import {sleep} from 'src/util/misc'
|
||||||
import database from 'src/agent/database'
|
import database from 'src/agent/database'
|
||||||
@ -51,6 +51,14 @@ class Connection {
|
|||||||
if (shouldConnect) {
|
if (shouldConnect) {
|
||||||
this.status = CONNECTION_STATUS.PENDING
|
this.status = CONNECTION_STATUS.PENDING
|
||||||
this.promise = this.nostr.connect()
|
this.promise = this.nostr.connect()
|
||||||
|
|
||||||
|
this.nostr.on('connect', () => {
|
||||||
|
this.status = CONNECTION_STATUS.READY
|
||||||
|
})
|
||||||
|
|
||||||
|
this.nostr.on('error', () => {
|
||||||
|
this.status = CONNECTION_STATUS.ERROR
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.status === CONNECTION_STATUS.PENDING) {
|
if (this.status === CONNECTION_STATUS.PENDING) {
|
||||||
@ -170,7 +178,11 @@ const subscribe = async (relays, filters, {onEvent, onEose}: Record<string, (e:
|
|||||||
const seen = new Set()
|
const seen = new Set()
|
||||||
const eose = new Set()
|
const eose = new Set()
|
||||||
|
|
||||||
log(`Starting subscription ${id} with ${relays.length} relays`, filters)
|
if (relays.length === 0) {
|
||||||
|
error(`Attempted to start subscription ${id} with zero relays`, filters)
|
||||||
|
} else {
|
||||||
|
log(`Starting subscription ${id} with ${relays.length} relays`, filters)
|
||||||
|
}
|
||||||
|
|
||||||
// Don't await before returning so we're not blocking on slow connects
|
// Don't await before returning so we're not blocking on slow connects
|
||||||
const promises = relays.map(async relay => {
|
const promises = relays.map(async relay => {
|
||||||
@ -220,7 +232,10 @@ const subscribe = async (relays, filters, {onEvent, onEose}: Record<string, (e:
|
|||||||
return Object.assign(sub, {conn})
|
return Object.assign(sub, {conn})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let active = true
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isActive: () => active,
|
||||||
unsub: () => {
|
unsub: () => {
|
||||||
log(`Closing subscription ${id}`)
|
log(`Closing subscription ${id}`)
|
||||||
|
|
||||||
@ -232,6 +247,7 @@ const subscribe = async (relays, filters, {onEvent, onEose}: Record<string, (e:
|
|||||||
sub.unsub()
|
sub.unsub()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
active = false
|
||||||
sub.conn.stats.activeSubsCount -= 1
|
sub.conn.stats.activeSubsCount -= 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -254,7 +270,14 @@ const subscribeUntilEose = async (
|
|||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const eose = new Set()
|
const eose = new Set()
|
||||||
|
|
||||||
|
let closed = true
|
||||||
|
|
||||||
const attemptToComplete = () => {
|
const attemptToComplete = () => {
|
||||||
|
// If we've already unsubscribed we're good
|
||||||
|
if (!agg.isActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const isComplete = eose.size === relays.length
|
const isComplete = eose.size === relays.length
|
||||||
const isTimeout = Date.now() - now >= timeout
|
const isTimeout = Date.now() - now >= timeout
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import {createMap, ellipsize} from 'hurdak/lib/hurdak'
|
|||||||
import {get} from 'svelte/store'
|
import {get} from 'svelte/store'
|
||||||
import {renderContent} from 'src/util/html'
|
import {renderContent} from 'src/util/html'
|
||||||
import {Tags, displayPerson, findReplyId} from 'src/util/nostr'
|
import {Tags, displayPerson, findReplyId} from 'src/util/nostr'
|
||||||
import {user, getUserRelays} from 'src/agent/helpers'
|
import {user, getUserRelays, getFollows} from 'src/agent/helpers'
|
||||||
import defaults from 'src/agent/defaults'
|
import defaults from 'src/agent/defaults'
|
||||||
import database from 'src/agent/database'
|
import database from 'src/agent/database'
|
||||||
import network from 'src/agent/network'
|
import network from 'src/agent/network'
|
||||||
@ -19,12 +19,13 @@ export {toast, modal, settings, alerts, messages, logUsage}
|
|||||||
|
|
||||||
export const loadAppData = pubkey => {
|
export const loadAppData = pubkey => {
|
||||||
const relays = getUserRelays('read')
|
const relays = getUserRelays('read')
|
||||||
|
const follows = Tags.wrap(getFollows(pubkey))
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
network.loadNetwork(relays, pubkey),
|
|
||||||
alerts.load(relays, pubkey),
|
alerts.load(relays, pubkey),
|
||||||
alerts.listen(relays, pubkey),
|
alerts.listen(relays, pubkey),
|
||||||
messages.listen(relays, pubkey),
|
messages.listen(relays, pubkey),
|
||||||
|
network.loadPeople(follows.relays(), follows.values().all()),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ const listen = async (relays, pubkey) => {
|
|||||||
await network.loadPeople(relays, pluck('pubkey', messages))
|
await network.loadPeople(relays, pluck('pubkey', messages))
|
||||||
|
|
||||||
mostRecentByPubkey.update(o => {
|
mostRecentByPubkey.update(o => {
|
||||||
for (const {pubkey, recipient, created_at} of messages) {
|
for (const {pubkey, created_at} of messages) {
|
||||||
const k = pubkey === $user.pubkey ? recipient : pubkey
|
if (pubkey !== $user.pubkey) {
|
||||||
|
o[pubkey] = Math.max(created_at, o[pubkey] || 0)
|
||||||
o[k] = Math.max(created_at, o[k] || 0)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return o
|
return o
|
||||||
|
@ -31,8 +31,6 @@
|
|||||||
quality = null
|
quality = null
|
||||||
message = "Not connected"
|
message = "Not connected"
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(quality, message)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
import {uniq} from 'ramda'
|
import {uniq} from 'ramda'
|
||||||
import Notes from "src/partials/Notes.svelte"
|
import Notes from "src/partials/Notes.svelte"
|
||||||
import {shuffle} from 'src/util/misc'
|
import {shuffle} from 'src/util/misc'
|
||||||
|
import {Tags} from 'src/util/nostr'
|
||||||
import {user, getTopRelays, getFollows} from 'src/agent/helpers'
|
import {user, getTopRelays, getFollows} from 'src/agent/helpers'
|
||||||
|
|
||||||
// Get first- and second-order follows. shuffle and slice network so we're not
|
// Get first- and second-order follows. shuffle and slice network so we're not
|
||||||
// sending too many pubkeys. This will also result in some variety.
|
// sending too many pubkeys. This will also result in some variety.
|
||||||
const follows = shuffle(getFollows($user?.pubkey))
|
const follows = shuffle(Tags.wrap(getFollows($user?.pubkey)).values().all())
|
||||||
const others = shuffle(follows.flatMap(getFollows)).slice(0, 50)
|
const others = shuffle(Tags.wrap(follows.flatMap(getFollows)).values().all()).slice(0, 50)
|
||||||
const authors = uniq(follows.concat(others)).slice(0, 100)
|
const authors = uniq(follows.concat(others)).slice(0, 100)
|
||||||
const relays = getTopRelays(authors, 'write')
|
const relays = getTopRelays(authors, 'write')
|
||||||
const filter = {kinds: [1, 7], authors}
|
const filter = {kinds: [1, 7], authors}
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
import {uniq} from 'ramda'
|
import {uniq} from 'ramda'
|
||||||
import Notes from "src/partials/Notes.svelte"
|
import Notes from "src/partials/Notes.svelte"
|
||||||
import {shuffle} from 'src/util/misc'
|
import {shuffle} from 'src/util/misc'
|
||||||
import {isLike} from 'src/util/nostr'
|
import {isLike, Tags} from 'src/util/nostr'
|
||||||
import {user, getTopRelays, getFollows} from 'src/agent/helpers'
|
import {user, getTopRelays, getFollows} from 'src/agent/helpers'
|
||||||
|
|
||||||
// Get first- and second-order follows. shuffle and slice network so we're not
|
// Get first- and second-order follows. shuffle and slice network so we're not
|
||||||
// sending too many pubkeys. This will also result in some variety.
|
// sending too many pubkeys. This will also result in some variety.
|
||||||
const follows = shuffle(getFollows($user?.pubkey))
|
const follows = shuffle(Tags.wrap(getFollows($user?.pubkey)).values().all())
|
||||||
const others = shuffle(follows.flatMap(getFollows)).slice(0, 50)
|
const others = shuffle(Tags.wrap(follows.flatMap(getFollows)).values().all()).slice(0, 50)
|
||||||
const authors = uniq(follows.concat(others)).slice(0, 100)
|
const authors = uniq(follows.concat(others)).slice(0, 100)
|
||||||
const relays = getTopRelays(authors, 'write')
|
const relays = getTopRelays(authors, 'write')
|
||||||
const filter = {kinds: [1, 7], authors}
|
const filter = {kinds: [1, 7], authors}
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
import {uniq} from 'ramda'
|
import {uniq} from 'ramda'
|
||||||
import Notes from "src/partials/Notes.svelte"
|
import Notes from "src/partials/Notes.svelte"
|
||||||
import {shuffle} from 'src/util/misc'
|
import {shuffle} from 'src/util/misc'
|
||||||
import {isLike} from 'src/util/nostr'
|
import {isLike, Tags} from 'src/util/nostr'
|
||||||
import {user, getTopRelays, getFollows} from 'src/agent/helpers'
|
import {user, getTopRelays, getFollows} from 'src/agent/helpers'
|
||||||
|
|
||||||
// Get first- and second-order follows. shuffle and slice network so we're not
|
// Get first- and second-order follows. shuffle and slice network so we're not
|
||||||
// sending too many pubkeys. This will also result in some variety.
|
// sending too many pubkeys. This will also result in some variety.
|
||||||
const follows = shuffle(getFollows($user?.pubkey))
|
const follows = shuffle(Tags.wrap(getFollows($user?.pubkey)).values().all())
|
||||||
const others = shuffle(follows.flatMap(getFollows)).slice(0, 50)
|
const others = shuffle(Tags.wrap(follows.flatMap(getFollows)).values().all()).slice(0, 50)
|
||||||
const authors = uniq(follows.concat(others)).slice(0, 100)
|
const authors = uniq(follows.concat(others)).slice(0, 100)
|
||||||
const relays = getTopRelays(authors, 'write')
|
const relays = getTopRelays(authors, 'write')
|
||||||
const filter = {kinds: [1, 7], authors}
|
const filter = {kinds: [1, 7], authors}
|
||||||
|
Loading…
Reference in New Issue
Block a user