From 3d3ffaf4067bbaf90857926ab38152339b72bbd1 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 16 Dec 2024 11:24:10 -0800 Subject: [PATCH] Simplify and optimize notifications --- src/app/components/ChatItem.svelte | 7 +- src/app/components/MenuSpace.svelte | 5 +- src/app/components/MenuSpaceButton.svelte | 37 +---- src/app/components/MenuSpaceRoomItem.svelte | 8 +- src/app/components/MenuSpacesItem.svelte | 4 +- src/app/components/PrimaryNav.svelte | 26 ++-- src/app/components/PrimaryNavItemSpace.svelte | 4 +- src/app/components/ThreadActions.svelte | 5 +- src/app/notifications.ts | 138 ++++++++---------- src/app/state.ts | 18 ++- src/routes/spaces/[relay]/+layout.svelte | 4 +- .../spaces/[relay]/threads/+page.svelte | 15 +- 12 files changed, 120 insertions(+), 151 deletions(-) diff --git a/src/app/components/ChatItem.svelte b/src/app/components/ChatItem.svelte index 0c9dff59..877c3dc3 100644 --- a/src/app/components/ChatItem.svelte +++ b/src/app/components/ChatItem.svelte @@ -1,7 +1,7 @@ diff --git a/src/app/components/MenuSpaceRoomItem.svelte b/src/app/components/MenuSpaceRoomItem.svelte index fd35fbcb..982752eb 100644 --- a/src/app/components/MenuSpaceRoomItem.svelte +++ b/src/app/components/MenuSpaceRoomItem.svelte @@ -1,11 +1,10 @@ - + {#if channelIsLocked($channel)} {:else} diff --git a/src/app/components/MenuSpacesItem.svelte b/src/app/components/MenuSpacesItem.svelte index ab845f26..9eba280f 100644 --- a/src/app/components/MenuSpacesItem.svelte +++ b/src/app/components/MenuSpacesItem.svelte @@ -5,7 +5,7 @@ import RelayName from "@app/components/RelayName.svelte" import RelayDescription from "@app/components/RelayDescription.svelte" import {makeSpacePath} from "@app/routes" - import {inactiveSpacesNotifications} from "@app/notifications" + import {inactiveNotifications} from "@app/notifications" export let url @@ -17,7 +17,7 @@
- {#if $inactiveSpacesNotifications.includes(path)} + {#if $inactiveNotifications.has(path)}
{/if}
diff --git a/src/app/components/PrimaryNav.svelte b/src/app/components/PrimaryNav.svelte index c88481a2..8dcab4c0 100644 --- a/src/app/components/PrimaryNav.svelte +++ b/src/app/components/PrimaryNav.svelte @@ -17,20 +17,22 @@ PLATFORM_LOGO, } from "@app/state" import {pushModal} from "@app/modal" - import {deriveNotification, inactiveSpacesNotifications, CHAT_FILTERS} from "@app/notifications" - - const chatNotification = deriveNotification("/chat", CHAT_FILTERS) + import {makeSpacePath} from "@app/routes" + import {notifications, inactiveNotifications} from "@app/notifications" const addSpace = () => pushModal(SpaceAdd) - const showSpacesMenu = () => - getMembershipUrls($userMembership).length > 0 ? pushModal(MenuSpaces) : pushModal(SpaceAdd) + const showSpacesMenu = () => (spacePaths.length > 0 ? pushModal(MenuSpaces) : pushModal(SpaceAdd)) const showSettingsMenu = () => pushModal(MenuSettings) const openNotes = () => ($canDecrypt ? goto("/notes") : pushModal(ChatEnable, {next: "/notes"})) const openChat = () => ($canDecrypt ? goto("/chat") : pushModal(ChatEnable, {next: "/chat"})) + + $: spaceUrls = getMembershipUrls($userMembership) + $: spacePaths = spaceUrls.map(url => makeSpacePath(url)) + $: anySpaceNotifications = spacePaths.some(path => $inactiveNotifications.has(path)) diff --git a/src/app/components/PrimaryNavItemSpace.svelte b/src/app/components/PrimaryNavItemSpace.svelte index b3866fcc..a0a90b5d 100644 --- a/src/app/components/PrimaryNavItemSpace.svelte +++ b/src/app/components/PrimaryNavItemSpace.svelte @@ -3,7 +3,7 @@ import PrimaryNavItem from "@lib/components/PrimaryNavItem.svelte" import SpaceAvatar from "@app/components/SpaceAvatar.svelte" import {makeSpacePath} from "@app/routes" - import {spacesNotifications} from "@app/notifications" + import {notifications} from "@app/notifications" export let url @@ -14,6 +14,6 @@ title={displayRelayUrl(url)} href={path} class="tooltip-right" - notification={$spacesNotifications.includes(path)}> + notification={$notifications.has(path)}> diff --git a/src/app/components/ThreadActions.svelte b/src/app/components/ThreadActions.svelte index 01e36a50..c35d9868 100644 --- a/src/app/components/ThreadActions.svelte +++ b/src/app/components/ThreadActions.svelte @@ -15,7 +15,7 @@ import ThunkStatus from "@app/components/ThunkStatus.svelte" import ThreadMenu from "@app/components/ThreadMenu.svelte" import {publishDelete, publishReaction} from "@app/commands" - import {deriveNotification} from "@app/notifications" + import {notifications} from "@app/notifications" import {makeSpacePath} from "@app/routes" import {PROTECTED} from "@app/state" @@ -28,7 +28,6 @@ const path = makeSpacePath(url, "threads", event.id) const filters = [{kinds: [COMMENT], "#E": [event.id]}] const replies = deriveEvents(repository, {filters}) - const notification = deriveNotification(path, filters, url) const showPopover = () => popover.show() @@ -70,7 +69,7 @@ {$replies.length} {$replies.length === 1 ? "reply" : "replies"}