From e5d1b82a9d6f4dff6d8a397261d98bbf994319ed Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Tue, 6 Jan 2026 14:52:13 -0800 Subject: [PATCH] Fix chat list responsiveness --- src/app/components/ChatStart.svelte | 3 +-- src/app/core/state.ts | 22 +++++++++++++++++----- src/app/util/routes.ts | 10 +++------- src/routes/+layout.svelte | 3 +-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/app/components/ChatStart.svelte b/src/app/components/ChatStart.svelte index c62031ef..6764be74 100644 --- a/src/app/components/ChatStart.svelte +++ b/src/app/components/ChatStart.svelte @@ -5,7 +5,6 @@ import {goto} from "$app/navigation" import {tryCatch, uniq} from "@welshman/lib" import {fromNostrURI} from "@welshman/util" - import {pubkey} from "@welshman/app" import {preventDefault} from "@lib/html" import Field from "@lib/components/Field.svelte" import Button from "@lib/components/Button.svelte" @@ -19,7 +18,7 @@ const back = () => history.back() - const onSubmit = () => goto(makeChatPath([...pubkeys, $pubkey!])) + const onSubmit = () => goto(makeChatPath(pubkeys)) const addPubkey = (pubkey: string) => { pubkeys = uniq([...pubkeys, pubkey]) diff --git a/src/app/core/state.ts b/src/app/core/state.ts index 25307a28..d1d87f7a 100644 --- a/src/app/core/state.ts +++ b/src/app/core/state.ts @@ -25,6 +25,7 @@ import { always, tryCatch, fromPairs, + remove, } from "@welshman/lib" import type {Override} from "@welshman/lib" import type {RepositoryUpdate} from "@welshman/net" @@ -393,9 +394,20 @@ export type Chat = { search_text: string } -export const makeChatId = (pubkeys: string[]) => sort(uniq(pubkeys)).join(",") +export const getChatPubkeys = (pubkeys: string[]) => sort(uniq(append(pubkey.get()!, pubkeys))) -export const splitChatId = (id: string) => id.split(",") +export const getChatPubkeysFromEvent = (event: TrustedEvent) => + getChatPubkeys(getPubkeyTagValues(event.tags).concat(event.pubkey)) + +export const makeChatId = (pubkeys: string[]) => { + const userPubkey = pubkey.get()! + const otherPubkeys = remove(userPubkey, uniq(pubkeys)) + const visiblePubkeys = otherPubkeys.length === 0 ? [userPubkey] : otherPubkeys + + return sort(visiblePubkeys).join(",") +} + +export const splitChatId = (id: string) => getChatPubkeys(id.split(",")) export const chatsById = call(() => { const chatsById = new Map() @@ -405,7 +417,7 @@ export const chatsById = call(() => { chat.search_text = chat.pubkeys.length === 1 ? displayProfileByPubkey(chat.pubkeys[0]) + " note to self" - : chat.pubkeys.map(displayProfileByPubkey).join(" ") + : remove(pubkey.get()!, chat.pubkeys).map(displayProfileByPubkey).join(" ") return chat as Chat } @@ -415,10 +427,10 @@ export const chatsById = call(() => { let dirty = false for (const event of events) { if ([DIRECT_MESSAGE, DIRECT_MESSAGE_FILE].includes(event.kind)) { - const pubkeys = getPubkeyTagValues(event.tags).concat(event.pubkey) + const pubkeys = getChatPubkeysFromEvent(event) const id = makeChatId(pubkeys) const chat = chatsById.get(id) - const messages = append(event, chat?.messages || []) + const messages = sortBy(e => -e.created_at, append(event, chat?.messages || [])) const last_activity = Math.max(chat?.last_activity || 0, event.created_at) const updatedChat = addSearchText({id, pubkeys, messages, last_activity}) diff --git a/src/app/util/routes.ts b/src/app/util/routes.ts index 70d4d405..898dba93 100644 --- a/src/app/util/routes.ts +++ b/src/app/util/routes.ts @@ -2,9 +2,9 @@ import type {Page} from "@sveltejs/kit" import {get} from "svelte/store" import * as nip19 from "nostr-tools/nip19" import {goto} from "$app/navigation" -import {nthEq, remove, sleep} from "@welshman/lib" +import {nthEq, sleep} from "@welshman/lib" import type {TrustedEvent} from "@welshman/util" -import {pubkey, tracker, loadRelay} from "@welshman/app" +import {tracker, loadRelay} from "@welshman/app" import {scrollToEvent} from "@lib/html" import {identity} from "@welshman/lib" import { @@ -55,11 +55,7 @@ export const goToSpace = async (url: string) => { } } -export const makeChatPath = (pubkeys: string[]) => { - const id = makeChatId(remove(pubkey.get()!, pubkeys)) - - return `/chat/${id}` -} +export const makeChatPath = (pubkeys: string[]) => `/chat/${makeChatId(pubkeys)}` export const makeRoomPath = (url: string, h: string) => `/spaces/${encodeRelay(url)}/${h}` diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index ffe6bf8d..f354e6b3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -146,9 +146,8 @@ const recent = $log.slice(-10) const success = recent.filter(spec({status: SignerLogEntryStatus.Success})) const failure = recent.filter(spec({status: SignerLogEntryStatus.Failure})) - const pending = recent.filter(spec({status: SignerLogEntryStatus.Pending})) - if (!$toast && (failure.length > 5 || pending.length > 5) && success.length === 0) { + if (!$toast && failure.length > 5 && success.length === 0) { pushToast({ theme: "error", timeout: 60_000,