From d416fe913e56b840e1c3fcbe30d063b0b7617350 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Tue, 6 Jan 2026 16:52:15 -0800 Subject: [PATCH] Fix memory leak, notification badge not showing --- src/app/components/NewNotificationSound.svelte | 16 ++++++++-------- src/app/util/notifications.ts | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/app/components/NewNotificationSound.svelte b/src/app/components/NewNotificationSound.svelte index d6a13ee4..f654f96f 100644 --- a/src/app/components/NewNotificationSound.svelte +++ b/src/app/components/NewNotificationSound.svelte @@ -23,16 +23,16 @@ } } + $effect(() => { + if ($notifications.size > notificationCount) { + playSound() + } + + notificationCount = $notifications.size + }) + onMount(() => { audioElement.load() - - notifications.subscribe(notifications => { - if (notifications.size > notificationCount) { - playSound() - } - - notificationCount = notifications.size - }) }) diff --git a/src/app/util/notifications.ts b/src/app/util/notifications.ts index 258ab4ce..fa8c420b 100644 --- a/src/app/util/notifications.ts +++ b/src/app/util/notifications.ts @@ -5,7 +5,15 @@ import {pubkey, tracker, repository, relaysByUrl} from "@welshman/app" import {prop, find, call, spec, first, identity, now, groupBy} from "@welshman/lib" import type {TrustedEvent} from "@welshman/util" import {deriveEventsByIdByUrl} from "@welshman/store" -import {ZAP_GOAL, EVENT_TIME, MESSAGE, THREAD, COMMENT, getTagValue} from "@welshman/util" +import { + ZAP_GOAL, + EVENT_TIME, + MESSAGE, + THREAD, + COMMENT, + getTagValue, + sortEventsDesc, +} from "@welshman/util" import { makeSpacePath, makeChatPath, @@ -111,10 +119,10 @@ export const notifications = call(() => { const threadPath = makeThreadPath(url) const calendarPath = makeCalendarPath(url) const messagesPath = makeSpaceChatPath(url) - const goalComments = goalCommentsByUrl.get(url)?.values() || [] - const threadComments = threadCommentsByUrl.get(url)?.values() || [] - const calendarComments = calendarCommentsByUrl.get(url)?.values() || [] - const messages = messagesByUrl.get(url)?.values() || [] + const goalComments = sortEventsDesc(goalCommentsByUrl.get(url)?.values() || []) + const threadComments = sortEventsDesc(threadCommentsByUrl.get(url)?.values() || []) + const calendarComments = sortEventsDesc(calendarCommentsByUrl.get(url)?.values() || []) + const messages = sortEventsDesc(messagesByUrl.get(url)?.values() || []) const commentsByGoalId = groupBy( e => getTagValue("E", e.tags),