Misc fixes

This commit is contained in:
Jonathan Staab 2023-08-14 10:43:57 -07:00
parent 5984807cd7
commit 6a81314dc3
8 changed files with 65 additions and 32 deletions

View File

@ -4,6 +4,10 @@
- [x] Add ability to start a chat from the messages list page (NIP 24 only) - [x] Add ability to start a chat from the messages list page (NIP 24 only)
- [x] Move notification info to modal - [x] Move notification info to modal
- [x] Fix relay selection sorting
- [x] Limit concurrent subscriptions
- [x] Re-introduce shuffle+slice of authors
- [x] Re-connect to sockets with an error after a while
# 0.3.2 # 0.3.2

View File

@ -49,7 +49,7 @@
})}> })}>
<a class="block px-4 py-2 transition-all hover:bg-accent hover:text-white" href="/channels"> <a class="block px-4 py-2 transition-all hover:bg-accent hover:text-white" href="/channels">
<i class="fa fa-envelope mr-2" /> Messages <i class="fa fa-envelope mr-2" /> Messages
{#if $hasNewDirectMessagesNip24} {#if $hasNewDirectMessagesNip24 || $hasNewDirectMessagesNip04}
<div <div
class="absolute left-7 top-2 h-2 w-2 rounded border border-solid border-white bg-accent" /> class="absolute left-7 top-2 h-2 w-2 rounded border border-solid border-white bg-accent" />
{/if} {/if}

View File

@ -17,15 +17,28 @@
import PersonSummary from "src/app/shared/PersonSummary.svelte" import PersonSummary from "src/app/shared/PersonSummary.svelte"
import TopNavMenu from "src/app/TopNavMenu.svelte" import TopNavMenu from "src/app/TopNavMenu.svelte"
import {menuIsOpen} from "src/app/state" import {menuIsOpen} from "src/app/state"
import engine, {Alerts, Nip28, Nip04, Keys, Directory, Network, Nip65, user} from "src/app/engine" import engine, {
Alerts,
Nip28,
Nip04,
Nip24,
Keys,
Directory,
Network,
Nip65,
user,
} from "src/app/engine"
const {keyState} = Keys const {keyState, canUseGiftWrap} = Keys
const logoUrl = import.meta.env.VITE_LOGO_URL || "/images/logo.png" const logoUrl = import.meta.env.VITE_LOGO_URL || "/images/logo.png"
const {hasNewNotfications} = Alerts const {hasNewNotfications} = Alerts
const {hasNewMessages: hasNewChatMessages} = Nip28 const {hasNewMessages: hasNewChatMessages} = Nip28
const {hasNewMessages: hasNewDirectMessages} = Nip04 const {hasNewMessages: hasNewDirectMessages} = Nip04
const {hasNewMessages: hasNewNip24DirectMessages} = Nip24
const toggleMenu = () => menuIsOpen.update(x => !x) const toggleMenu = () => menuIsOpen.update(x => !x)
$: hasNewMessages = $hasNewDirectMessages || ($canUseGiftWrap && $hasNewNip24DirectMessages)
let term = "" let term = ""
let searchIsOpen = false let searchIsOpen = false
let options = [] let options = []
@ -172,9 +185,9 @@
<div class="app-logo flex cursor-pointer items-center gap-2" on:click={toggleMenu}> <div class="app-logo flex cursor-pointer items-center gap-2" on:click={toggleMenu}>
<img alt="App Logo" src={logoUrl} class="w-10" /> <img alt="App Logo" src={logoUrl} class="w-10" />
<h1 class="staatliches pt-1 text-3xl">{appName}</h1> <h1 class="staatliches pt-1 text-3xl">{appName}</h1>
{#if $hasNewNotfications || $hasNewChatMessages || $hasNewDirectMessages} {#if $hasNewNotfications || $hasNewChatMessages || hasNewMessages}
<div <div
class="absolute left-8 top-4 h-2 w-2 rounded border border-solid border-white bg-accent sm:hidden" /> class="absolute left-8 top-4 h-2 w-2 rounded border border-solid border-white bg-accent" />
{/if} {/if}
</div> </div>
</div> </div>

View File

@ -5,7 +5,7 @@ import {nip19} from "nostr-tools"
import {navigate} from "svelte-routing" import {navigate} from "svelte-routing"
import {writable} from "svelte/store" import {writable} from "svelte/store"
import {whereEq, omit, filter, pluck, sortBy, slice} from "ramda" import {whereEq, omit, filter, pluck, sortBy, slice} from "ramda"
import {hash, sleep, doPipe} from "hurdak" import {hash, sleep, doPipe, shuffle} from "hurdak"
import {warn} from "src/util/logger" import {warn} from "src/util/logger"
import {now} from "src/util/misc" import {now} from "src/util/misc"
import {userKinds, noteKinds} from "src/util/nostr" import {userKinds, noteKinds} from "src/util/nostr"
@ -92,10 +92,13 @@ setInterval(() => {
const userRelays = new Set(user.getRelayUrls()) const userRelays = new Set(user.getRelayUrls())
const $slowConnections = [] const $slowConnections = []
// Prune connections we haven't used in a while // Prune connections we haven't used in a while, clear errors periodically,
// and keep track of slow connections
for (const [url, socket] of Network.pool.data.entries()) { for (const [url, socket] of Network.pool.data.entries()) {
if (socket.meta.last_activity < now() - 60) { if (socket.meta.last_activity < now() - 60) {
Network.pool.get(url).disconnect() socket.disconnect()
} else if (socket.lastError < Date.now() - 10_000) {
socket.clearError()
} else if (userRelays.has(url) && socket.meta.quality < 0.3) { } else if (userRelays.has(url) && socket.meta.quality < 0.3) {
$slowConnections.push(url) $slowConnections.push(url)
} }
@ -230,7 +233,8 @@ export const publishWithToast = async (
// Feeds // Feeds
export const compileFilter = (filter: DynamicFilter): Filter => { export const compileFilter = (filter: DynamicFilter): Filter => {
const getAuthors = (pubkeys: string[]) => (pubkeys.length > 0 ? pubkeys : Env.DEFAULT_FOLLOWS) const getAuthors = (pubkeys: string[]) =>
shuffle(pubkeys.length > 0 ? pubkeys : (Env.DEFAULT_FOLLOWS as string[])).slice(0, 1024)
if (filter.authors === "global") { if (filter.authors === "global") {
filter = omit(["authors"], filter) filter = omit(["authors"], filter)

View File

@ -4,10 +4,10 @@
import {onMount} from "svelte" import {onMount} from "svelte"
import {generatePrivateKey} from "nostr-tools" import {generatePrivateKey} from "nostr-tools"
import {formatTimestamp} from "src/util/misc" import {formatTimestamp} from "src/util/misc"
import {modal} from "src/partials/state"
import Channel from "src/partials/Channel.svelte" import Channel from "src/partials/Channel.svelte"
import Anchor from "src/partials/Anchor.svelte" import Anchor from "src/partials/Anchor.svelte"
import {wrap} from "src/engine/util/nip59" import {wrap} from "src/engine/util/nip59"
import {routes} from "src/app/state"
import PersonCircle from "src/app/shared/PersonCircle.svelte" import PersonCircle from "src/app/shared/PersonCircle.svelte"
import PersonAbout from "src/app/shared/PersonAbout.svelte" import PersonAbout from "src/app/shared/PersonAbout.svelte"
import NoteContent from "src/app/shared/NoteContent.svelte" import NoteContent from "src/app/shared/NoteContent.svelte"
@ -58,6 +58,8 @@
} }
} }
const showPerson = pubkey => modal.push({type: "person/detail", pubkey})
onMount(() => { onMount(() => {
return Network.subscribe({ return Network.subscribe({
relays: getRelays(), relays: getRelays(),
@ -71,11 +73,8 @@
<Channel {messages} {sendMessage}> <Channel {messages} {sendMessage}>
<div slot="header" class="flex h-16 items-start gap-4 overflow-hidden p-2"> <div slot="header" class="flex h-16 items-start gap-4 overflow-hidden p-2">
<div class="flex items-center gap-4 pt-1"> <div class="flex items-center gap-4 pt-1">
<Anchor <Anchor type="unstyled" class="fa fa-arrow-left cursor-pointer text-2xl" href="/channels" />
type="unstyled" <div class="mr-3 flex pt-1">
class="fa fa-arrow-left cursor-pointer text-2xl"
on:click={() => history.back()} />
<div class="mr-3 flex">
{#each pubkeys as pubkey (pubkey)} {#each pubkeys as pubkey (pubkey)}
<div class="-mr-3 inline-block"> <div class="-mr-3 inline-block">
<PersonCircle size={10} class="h-8 w-8" {pubkey} /> <PersonCircle size={10} class="h-8 w-8" {pubkey} />
@ -83,11 +82,11 @@
{/each} {/each}
</div> </div>
</div> </div>
<div class="flex h-12 w-full flex-col overflow-hidden pt-px"> <div class="flex h-12 w-full flex-col overflow-hidden pt-1">
<div class="w-full"> <div class="w-full">
{#each pubkeys as pubkey, i (pubkey)} {#each pubkeys as pubkey, i (pubkey)}
{#if i > 0}&bullet;{/if} {#if i > 0}&bullet;{/if}
<Anchor href={routes.person(pubkey)} class="font-bold"> <Anchor on:click={() => showPerson(pubkey)} class="font-bold">
{Directory.displayPubkey(pubkey)} {Directory.displayPubkey(pubkey)}
</Anchor> </Anchor>
{/each} {/each}
@ -105,10 +104,15 @@
"mr-12": message.profile.pubkey !== userPubkey, "mr-12": message.profile.pubkey !== userPubkey,
})}> })}>
<div <div
class={cx("inline-block max-w-xl rounded-2xl px-4 py-2", { class={cx("inline-block flex max-w-xl flex-col rounded-2xl px-4 py-2", {
"rounded-br-none bg-gray-1 text-gray-8": message.profile.pubkey === userPubkey, "rounded-br-none bg-gray-1 text-gray-8": message.profile.pubkey === userPubkey,
"rounded-bl-none bg-gray-7": message.profile.pubkey !== userPubkey, "rounded-bl-none bg-gray-7": message.profile.pubkey !== userPubkey,
})}> })}>
{#if message.showProfile && message.profile.pubkey !== userPubkey}
<Anchor class="mb-1" on:click={() => showPerson(message.profile.pubkey)}>
<strong>{Directory.displayProfile(message.profile)}</strong>
</Anchor>
{/if}
<div class="break-words"> <div class="break-words">
{#if typeof message.content === "string"} {#if typeof message.content === "string"}
<NoteContent showEntire note={message} /> <NoteContent showEntire note={message} />

View File

@ -193,7 +193,7 @@ export class Nip65 {
score.score = weight + Math.log1p(Math.exp(score.score - score.count)) score.score = weight + Math.log1p(Math.exp(score.score - score.count))
} }
return sortBy(([hint, {score}]) => -score, Object.entries(scores)) return sortBy(([hint, {score}]) => score, Object.entries(scores))
.map(nth(0)) .map(nth(0))
.slice(0, limit) .slice(0, limit)
} }

View File

@ -131,21 +131,29 @@ export class RelayStats {
socket.off("send", onSend) socket.off("send", onSend)
socket.off("receive", onReceive) socket.off("receive", onReceive)
// If we didn't purposely remove the socket and it's healthy, restart info(`Closed connection to ${socket.url}`)
// and re-send active subcriptions
if (
this.engine.Network.pool.has(socket.url) &&
socket.status !== Socket.STATUS.ERROR &&
!socket.meta.error
) {
if (subs.size > 0) {
info(`Resuming ${subs.size} subscriptions on ${socket.url}`)
}
for (const payload of subs.values()) { const resumableSubs = Array.from(subs.values())
socket.send(["REQ", ...payload])
subs.clear()
setTimeout(() => {
// If we didn't purposely remove the socket and it's healthy, restart
// and re-send active subcriptions
if (
this.engine.Network.pool.has(socket.url) &&
socket.status !== Socket.STATUS.ERROR &&
!socket.meta.error
) {
if (resumableSubs.length > 0) {
info(`Resuming ${resumableSubs.length} subscriptions on ${socket.url}`)
}
for (const payload of resumableSubs) {
socket.send(["REQ", ...payload])
}
} }
} }, 1000)
}) })
}) })
} }

BIN
yarn.lock

Binary file not shown.