Improve loading and notifications

This commit is contained in:
Jon Staab
2025-01-02 16:58:04 -08:00
parent f618e4e1f3
commit b6defe59a8
3 changed files with 20 additions and 7 deletions

View File

@@ -1,9 +1,9 @@
import {derived} from "svelte/store"
import {synced, throttled} from "@welshman/store"
import {pubkey} from "@welshman/app"
import {prop, identity, now} from "@welshman/lib"
import {prop, spec, identity, now, groupBy} from "@welshman/lib"
import type {TrustedEvent} from "@welshman/util"
import {MESSAGE} from "@welshman/util"
import {MESSAGE, COMMENT, getTagValue} from "@welshman/util"
import {makeSpacePath, makeChatPath, makeThreadPath, makeRoomPath} from "@app/routes"
import {
THREAD_FILTER,
@@ -63,13 +63,26 @@ export const notifications = derived(
for (const [url, rooms] of $userRoomsByUrl.entries()) {
const spacePath = makeSpacePath(url)
const threadPath = makeThreadPath(url)
const latestEvent = allThreadEvents.find(e => $getUrlsForEvent(e.id).includes(url))
const threadEvents = allThreadEvents.filter(e => $getUrlsForEvent(e.id).includes(url))
if (hasNotification(threadPath, latestEvent)) {
if (hasNotification(threadPath, threadEvents[0])) {
paths.add(spacePath)
paths.add(threadPath)
}
const commentsByThreadId = groupBy(
e => getTagValue("E", e.tags),
threadEvents.filter(spec({kind: COMMENT})),
)
for (const [threadId, [comment]] of commentsByThreadId.entries()) {
const threadItemPath = makeThreadPath(url, threadId)
if (hasNotification(threadItemPath, comment)) {
paths.add(threadItemPath)
}
}
for (const room of rooms) {
const roomPath = makeRoomPath(url, room)
const latestEvent = allMessageEvents.find(

View File

@@ -50,7 +50,7 @@ export const listenForNotifications = () => {
filters: [
{kinds: [THREAD], since: now()},
{kinds: [COMMENT], "#K": [String(THREAD)], since: now()},
{kinds: [MESSAGE], "#h": Array.from(rooms), since: now()},
...Array.from(rooms).map(room => ({kinds: [MESSAGE], "#h": [room], since: now()})),
],
}),
)

View File

@@ -64,8 +64,8 @@
// Load recent messages for user rooms to help with a quick page transition
pullConservatively({relays, filters: rooms.map(r => ({kinds: [MESSAGE], "#h": [r], since}))})
// Listen for deletes that would apply to messages we already have
const sub = subscribe({relays, filters: [{kinds: [DELETE], since}]})
// Listen for deletes that would apply to messages we already have, and new groups
const sub = subscribe({relays, filters: [{kinds: [DELETE, GROUPS], since}]})
return () => {
sub.close()