forked from coracle/flotilla
Fix chat list responsiveness
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
import {goto} from "$app/navigation"
|
import {goto} from "$app/navigation"
|
||||||
import {tryCatch, uniq} from "@welshman/lib"
|
import {tryCatch, uniq} from "@welshman/lib"
|
||||||
import {fromNostrURI} from "@welshman/util"
|
import {fromNostrURI} from "@welshman/util"
|
||||||
import {pubkey} from "@welshman/app"
|
|
||||||
import {preventDefault} from "@lib/html"
|
import {preventDefault} from "@lib/html"
|
||||||
import Field from "@lib/components/Field.svelte"
|
import Field from "@lib/components/Field.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
@@ -19,7 +18,7 @@
|
|||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
const onSubmit = () => goto(makeChatPath([...pubkeys, $pubkey!]))
|
const onSubmit = () => goto(makeChatPath(pubkeys))
|
||||||
|
|
||||||
const addPubkey = (pubkey: string) => {
|
const addPubkey = (pubkey: string) => {
|
||||||
pubkeys = uniq([...pubkeys, pubkey])
|
pubkeys = uniq([...pubkeys, pubkey])
|
||||||
|
|||||||
+17
-5
@@ -25,6 +25,7 @@ import {
|
|||||||
always,
|
always,
|
||||||
tryCatch,
|
tryCatch,
|
||||||
fromPairs,
|
fromPairs,
|
||||||
|
remove,
|
||||||
} from "@welshman/lib"
|
} from "@welshman/lib"
|
||||||
import type {Override} from "@welshman/lib"
|
import type {Override} from "@welshman/lib"
|
||||||
import type {RepositoryUpdate} from "@welshman/net"
|
import type {RepositoryUpdate} from "@welshman/net"
|
||||||
@@ -393,9 +394,20 @@ export type Chat = {
|
|||||||
search_text: string
|
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(() => {
|
export const chatsById = call(() => {
|
||||||
const chatsById = new Map<string, Chat>()
|
const chatsById = new Map<string, Chat>()
|
||||||
@@ -405,7 +417,7 @@ export const chatsById = call(() => {
|
|||||||
chat.search_text =
|
chat.search_text =
|
||||||
chat.pubkeys.length === 1
|
chat.pubkeys.length === 1
|
||||||
? displayProfileByPubkey(chat.pubkeys[0]) + " note to self"
|
? displayProfileByPubkey(chat.pubkeys[0]) + " note to self"
|
||||||
: chat.pubkeys.map(displayProfileByPubkey).join(" ")
|
: remove(pubkey.get()!, chat.pubkeys).map(displayProfileByPubkey).join(" ")
|
||||||
|
|
||||||
return chat as Chat
|
return chat as Chat
|
||||||
}
|
}
|
||||||
@@ -415,10 +427,10 @@ export const chatsById = call(() => {
|
|||||||
let dirty = false
|
let dirty = false
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
if ([DIRECT_MESSAGE, DIRECT_MESSAGE_FILE].includes(event.kind)) {
|
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 id = makeChatId(pubkeys)
|
||||||
const chat = chatsById.get(id)
|
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 last_activity = Math.max(chat?.last_activity || 0, event.created_at)
|
||||||
const updatedChat = addSearchText({id, pubkeys, messages, last_activity})
|
const updatedChat = addSearchText({id, pubkeys, messages, last_activity})
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import type {Page} from "@sveltejs/kit"
|
|||||||
import {get} from "svelte/store"
|
import {get} from "svelte/store"
|
||||||
import * as nip19 from "nostr-tools/nip19"
|
import * as nip19 from "nostr-tools/nip19"
|
||||||
import {goto} from "$app/navigation"
|
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 type {TrustedEvent} from "@welshman/util"
|
||||||
import {pubkey, tracker, loadRelay} from "@welshman/app"
|
import {tracker, loadRelay} from "@welshman/app"
|
||||||
import {scrollToEvent} from "@lib/html"
|
import {scrollToEvent} from "@lib/html"
|
||||||
import {identity} from "@welshman/lib"
|
import {identity} from "@welshman/lib"
|
||||||
import {
|
import {
|
||||||
@@ -55,11 +55,7 @@ export const goToSpace = async (url: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const makeChatPath = (pubkeys: string[]) => {
|
export const makeChatPath = (pubkeys: string[]) => `/chat/${makeChatId(pubkeys)}`
|
||||||
const id = makeChatId(remove(pubkey.get()!, pubkeys))
|
|
||||||
|
|
||||||
return `/chat/${id}`
|
|
||||||
}
|
|
||||||
|
|
||||||
export const makeRoomPath = (url: string, h: string) => `/spaces/${encodeRelay(url)}/${h}`
|
export const makeRoomPath = (url: string, h: string) => `/spaces/${encodeRelay(url)}/${h}`
|
||||||
|
|
||||||
|
|||||||
@@ -146,9 +146,8 @@
|
|||||||
const recent = $log.slice(-10)
|
const recent = $log.slice(-10)
|
||||||
const success = recent.filter(spec({status: SignerLogEntryStatus.Success}))
|
const success = recent.filter(spec({status: SignerLogEntryStatus.Success}))
|
||||||
const failure = recent.filter(spec({status: SignerLogEntryStatus.Failure}))
|
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({
|
pushToast({
|
||||||
theme: "error",
|
theme: "error",
|
||||||
timeout: 60_000,
|
timeout: 60_000,
|
||||||
|
|||||||
Reference in New Issue
Block a user