Fix conversation sync

This commit is contained in:
Jon Staab
2024-11-13 16:14:05 -08:00
parent da3db67aa6
commit 2d89c152b1
6 changed files with 64 additions and 47 deletions

View File

@@ -283,7 +283,7 @@ export const checkRelayAccess = async (url: string, claim = "") => {
result[url].message?.replace(/^.*: /, "") || result[url].message?.replace(/^.*: /, "") ||
"join request rejected" "join request rejected"
return `Failed to join relay: ${message}` return `Failed to join relay (${message})`
} }
} }
@@ -309,11 +309,12 @@ export const checkRelayAuth = async (url: string) => {
const connection = ctx.net.pool.get(url) const connection = ctx.net.pool.get(url)
const okStatuses = [AuthStatus.None, AuthStatus.Ok] const okStatuses = [AuthStatus.None, AuthStatus.Ok]
await connection.auth.attempt(5000) await connection.auth.attempt(30_000)
if (!okStatuses.includes(connection.auth.status)) { // Only raise an error if it's not a timeout.
console.log(connection.auth.status, connection) // If it is, odds are the problem is with our signer, not the relay
return `Failed to authenticate: "${connection.auth.message}"` if (!okStatuses.includes(connection.auth.status) && connection.auth.message) {
return `Failed to authenticate (${connection.auth.message})`
} }
} }

View File

@@ -1,12 +1,10 @@
<script lang="ts"> <script lang="ts">
import {onMount} from "svelte" import {onMount} from "svelte"
import {derived} from "svelte/store"
import {page} from "$app/stores" import {page} from "$app/stores"
import {remove} from "@welshman/lib" import {remove} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util" import type {TrustedEvent} from "@welshman/util"
import {pubkey, inboxRelaySelectionsByPubkey, loadInboxRelaySelections} from "@welshman/app" import {pubkey, loadInboxRelaySelections} from "@welshman/app"
import Link from "@lib/components/Link.svelte" import Link from "@lib/components/Link.svelte"
import Icon from "@lib/components/Icon.svelte"
import ProfileName from "@app/components/ProfileName.svelte" import ProfileName from "@app/components/ProfileName.svelte"
import ProfileCircle from "@app/components/ProfileCircle.svelte" import ProfileCircle from "@app/components/ProfileCircle.svelte"
import ProfileCircles from "@app/components/ProfileCircles.svelte" import ProfileCircles from "@app/components/ProfileCircles.svelte"
@@ -19,7 +17,6 @@
const message = messages[0] const message = messages[0]
const others = remove($pubkey!, pubkeys) const others = remove($pubkey!, pubkeys)
const active = $page.params.chat === id const active = $page.params.chat === id
const missingInbox = derived(inboxRelaySelectionsByPubkey, $m => others.some(pk => !$m.has(pk)))
onMount(() => { onMount(() => {
for (const pk of others) { for (const pk of others) {
@@ -47,9 +44,6 @@
</p> </p>
{/if} {/if}
</div> </div>
{#if $missingInbox}
<Icon icon="danger" class="text-error" />
{/if}
</div> </div>
<p class="overflow-hidden text-ellipsis whitespace-nowrap text-sm"> <p class="overflow-hidden text-ellipsis whitespace-nowrap text-sm">
{message.content} {message.content}

View File

@@ -88,13 +88,21 @@
</p> </p>
{#if getNip07()} {#if getNip07()}
<Button disabled={loading} on:click={loginWithNip07} class="btn btn-primary"> <Button disabled={loading} on:click={loginWithNip07} class="btn btn-primary">
<Icon icon="widget" /> {#if loading}
<span class="loading loading-spinner mr-3" />
{:else}
<Icon icon="widget" />
{/if}
Log in with Extension Log in with Extension
</Button> </Button>
{/if} {/if}
{#each signers as app} {#each signers as app}
<Button disabled={loading} class="btn btn-neutral" on:click={() => loginWithSigner(app)}> <Button disabled={loading} class="btn btn-neutral" on:click={() => loginWithSigner(app)}>
<img src={app.iconUrl} alt={app.name} width="48" height="48" /> {#if loading}
<span class="loading loading-spinner mr-3" />
{:else}
<img src={app.iconUrl} alt={app.name} width="48" height="48" />
{/if}
Log in with {app.name} Log in with {app.name}
</Button> </Button>
{/each} {/each}
@@ -107,6 +115,7 @@
</Button> </Button>
<Link <Link
external external
disabled={loading}
href="https://nostrapps.com#signers" href="https://nostrapps.com#signers"
class="btn {hasNativeSigner ? '' : 'btn-neutral'}"> class="btn {hasNativeSigner ? '' : 'btn-neutral'}">
<Icon icon="compass" /> <Icon icon="compass" />

View File

@@ -26,8 +26,9 @@
<form class="column gap-4" on:submit|preventDefault={logout}> <form class="column gap-4" on:submit|preventDefault={logout}>
<ModalHeader> <ModalHeader>
<div slot="title">Are you sure you want to log out?</div> <div slot="title">Are you sure you<br />want to log out?</div>
</ModalHeader> </ModalHeader>
<p>Your local database will be cleared.</p>
<ModalFooter> <ModalFooter>
<Button class="btn btn-link" on:click={back}> <Button class="btn btn-link" on:click={back}>
<Icon icon="alt-arrow-left" /> <Icon icon="alt-arrow-left" />

View File

@@ -1,9 +1,9 @@
<script lang="ts"> <script lang="ts">
import "@src/app.css" import "@src/app.css"
import {onMount} from "svelte" import {onMount} from "svelte"
import {get} from "svelte/store" import {get, derived} from "svelte/store"
import {dev} from "$app/environment" import {dev} from "$app/environment"
import {ctx, uniq, sleep, take, sortBy, ago, now, HOUR, WEEK} from "@welshman/lib" import {identity, uniq, sleep, take, sortBy, ago, now, HOUR, WEEK, Worker} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util" import type {TrustedEvent} from "@welshman/util"
import { import {
PROFILE, PROFILE,
@@ -33,9 +33,12 @@
session, session,
signer, signer,
dropSession, dropSession,
getRelayUrls,
userInboxRelaySelections,
} from "@welshman/app" } from "@welshman/app"
import * as lib from "@welshman/lib" import * as lib from "@welshman/lib"
import * as util from "@welshman/util" import * as util from "@welshman/util"
import * as net from "@welshman/net"
import * as app from "@welshman/app" import * as app from "@welshman/app"
import AppContainer from "@app/components/AppContainer.svelte" import AppContainer from "@app/components/AppContainer.svelte"
import ModalContainer from "@app/components/ModalContainer.svelte" import ModalContainer from "@app/components/ModalContainer.svelte"
@@ -47,6 +50,7 @@
getMembershipUrls, getMembershipUrls,
getMembershipRooms, getMembershipRooms,
userMembership, userMembership,
ensureUnwrapped,
MEMBERSHIPS, MEMBERSHIPS,
MESSAGE, MESSAGE,
COMMENT, COMMENT,
@@ -62,8 +66,8 @@
let ready: Promise<unknown> = Promise.resolve() let ready: Promise<unknown> = Promise.resolve()
onMount(() => { onMount(async () => {
Object.assign(window, {get, ...lib, ...util, ...app, ...state}) Object.assign(window, {get, ...lib, ...util, ...net, ...app, ...state})
const getScoreEvent = () => { const getScoreEvent = () => {
const ALWAYS_KEEP = Infinity const ALWAYS_KEEP = Infinity
@@ -140,6 +144,29 @@
tracker: storageAdapters.fromTracker(tracker, {throttle: 1000}), tracker: storageAdapters.fromTracker(tracker, {throttle: 1000}),
}).then(() => sleep(300)) }).then(() => sleep(300))
// Unwrap gift wraps as they come in, but throttled
const unwrapper = new Worker<TrustedEvent>({chunkSize: 10})
unwrapper.addGlobalHandler(ensureUnwrapped)
repository.on("update", ({added}) => {
for (const event of added) {
if (event.kind === WRAP) {
unwrapper.push(event)
}
}
})
// Load relay info
for (const url of INDEXER_RELAYS) {
loadRelay(url)
}
// Load user data
if ($pubkey) {
await loadUserData($pubkey)
}
let unsubRooms: any let unsubRooms: any
userMembership.subscribe($membership => { userMembership.subscribe($membership => {
@@ -165,33 +192,18 @@
let unsubChats: any let unsubChats: any
pubkey.subscribe($pubkey => { derived([pubkey, userInboxRelaySelections], identity).subscribe(
unsubChats?.() ([$pubkey, $userInboxRelaySelections]) => {
unsubChats?.()
if ($pubkey) { if ($pubkey) {
unsubChats = subscribePersistent({ unsubChats = subscribePersistent({
filters: [{kinds: [WRAP], "#p": [$pubkey], since: ago(WEEK)}], filters: [{kinds: [WRAP], "#p": [$pubkey], since: ago(WEEK, 2)}],
relays: ctx.app.router.UserInbox().getUrls(), relays: getRelayUrls($userInboxRelaySelections),
}) })
} }
}) },
)
// Unwrap gift wraps as they come in
repository.on("update", ({added}) => {
for (const event of added) {
state.ensureUnwrapped(event)
}
})
// Load relay info
for (const url of INDEXER_RELAYS) {
loadRelay(url)
}
// Load user data
if ($pubkey) {
loadUserData($pubkey)
}
} }
}) })
</script> </script>

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import {onMount} from "svelte" import {onMount} from "svelte"
import {page} from "$app/stores" import {page} from "$app/stores"
import {WEEK, ctx, ago} from "@welshman/lib" import {ctx} from "@welshman/lib"
import {WRAP} from "@welshman/util" import {WRAP} from "@welshman/util"
import type {TrustedEvent} from "@welshman/util" import type {TrustedEvent} from "@welshman/util"
import {pubkey, repository} from "@welshman/app" import {pubkey, repository} from "@welshman/app"
@@ -20,7 +20,7 @@
const startChat = () => pushModal(ChatStart) const startChat = () => pushModal(ChatStart)
const promise = pullConservatively({ const promise = pullConservatively({
filters: [{kinds: [WRAP], "#p": [$pubkey!], until: ago(WEEK)}], filters: [{kinds: [WRAP], "#p": [$pubkey!]}],
relays: ctx.app.router.UserInbox().getUrls(), relays: ctx.app.router.UserInbox().getUrls(),
}) })