diff --git a/src/app/state.ts b/src/app/state.ts index 9234871d2..21dad6943 100644 --- a/src/app/state.ts +++ b/src/app/state.ts @@ -103,5 +103,5 @@ export const loadUserData = async (hints: string[] = []) => { export const boot = () => { router.at("login/connect").open({noEscape: true, mini: true}) - setChecked(["*", "channels/*"]) + setChecked("*") } diff --git a/src/app/views/ChannelsDetail.svelte b/src/app/views/ChannelsDetail.svelte index 733206b07..03312e187 100644 --- a/src/app/views/ChannelsDetail.svelte +++ b/src/app/views/ChannelsDetail.svelte @@ -32,7 +32,7 @@ onMount(() => { isAccepted = $messages.some(m => m.pubkey === $session.pubkey) - setChecked(["channels/" + channelId]) + setChecked("channels/" + channelId) for (const pubkey of pubkeys) { loadInboxRelaySelections(pubkey) @@ -42,7 +42,7 @@ }) onDestroy(() => { - setChecked(["channels/" + channelId]) + setChecked("channels/" + channelId) }) document.title = `Direct Messages` diff --git a/src/app/views/ChannelsList.svelte b/src/app/views/ChannelsList.svelte index 1b5ecc8ab..1f3d20ebe 100644 --- a/src/app/views/ChannelsList.svelte +++ b/src/app/views/ChannelsList.svelte @@ -40,7 +40,7 @@ } }) - const markAllChannelsRead = () => setChecked(["channels/*"], now()) + const markAllChannelsRead = () => setChecked("channels/*", now()) document.title = "Direct Messages" diff --git a/src/app/views/NotificationSectionMain.svelte b/src/app/views/NotificationSectionMain.svelte index d3aabb33c..901367a7b 100644 --- a/src/app/views/NotificationSectionMain.svelte +++ b/src/app/views/NotificationSectionMain.svelte @@ -35,10 +35,10 @@ }) onMount(() => { - setChecked(["replies", "mentions"]) + setChecked("notes/*") return () => { - setChecked(["replies", "mentions"]) + setChecked("notes/*") } }) diff --git a/src/app/views/NotificationSectionReactions.svelte b/src/app/views/NotificationSectionReactions.svelte index ece553a8a..9ca887e22 100644 --- a/src/app/views/NotificationSectionReactions.svelte +++ b/src/app/views/NotificationSectionReactions.svelte @@ -33,10 +33,10 @@ }) onMount(() => { - setChecked(["reactions", "zaps"]) + setChecked("reactions/*") return () => { - setChecked(["reactions", "zaps"]) + setChecked("reactions/*") } }) diff --git a/src/app/views/Onboarding.svelte b/src/app/views/Onboarding.svelte index 8cee15d56..767794a25 100644 --- a/src/app/views/Onboarding.svelte +++ b/src/app/views/Onboarding.svelte @@ -69,7 +69,7 @@ // Start our notifications listener listenForNotifications() - setChecked(["*", "channels/*"]) + setChecked("*") } onMount(async () => { diff --git a/src/engine/notifications.ts b/src/engine/notifications.ts index f2b361b4e..373790ff6 100644 --- a/src/engine/notifications.ts +++ b/src/engine/notifications.ts @@ -13,13 +13,8 @@ export const isSeen = derived( $getSeenAt => (key: string, event: TrustedEvent) => $getSeenAt(key, event) > 0, ) -export const setChecked = (keys: string[], ts = now()) => - checked.update(state => { - keys.forEach(key => { - state = {...state, [key]: ts} - }) - return state - }) +export const setChecked = (path: string, ts = now()) => + checked.update(state => ({...state, [path]: ts})) // Notifications @@ -37,7 +32,7 @@ export const mainNotifications = derived( ) export const unreadMainNotifications = derived([isSeen, mainNotifications], ([$isSeen, events]) => - events.filter(e => !$isSeen("replies", e) && !$isSeen("mentions", e)), + events.filter(e => !$isSeen("notes/*", e)), ) export const hasNewNotifications = derived( @@ -78,5 +73,5 @@ export const reactionNotifications = derived( export const unreadReactionNotifications = derived( [isSeen, reactionNotifications], - ([$isSeen, events]) => events.filter(e => !$isSeen("reactions", e) && !$isSeen("zaps", e)), + ([$isSeen, events]) => events.filter(e => !$isSeen("reactions/*", e)), ) diff --git a/src/engine/state.ts b/src/engine/state.ts index 7b4c9d22e..a08c1a67a 100644 --- a/src/engine/state.ts +++ b/src/engine/state.ts @@ -371,10 +371,8 @@ export const checked = writable>({}) export const deriveChecked = (key: string) => derived(checked, prop(key)) -export const getSeenAt = derived([checked], ([$checked]) => (key: string, event: TrustedEvent) => { - const match = $checked[key] - const fallback = $checked[key.includes("channels") ? "channels/*" : "*"] - const ts = max([match, fallback]) +export const getSeenAt = derived([checked], ([$checked]) => (path: string, event: TrustedEvent) => { + const ts = max([$checked[path], $checked[path.split("/")[0] + "/*"], $checked["*"]]) if (ts >= event.created_at) return ts