From 63fee653e879b8fe7dcb3cea03072b67eec22575 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Thu, 22 Jan 2026 12:37:30 -0800 Subject: [PATCH] Add muted rooms, rework alert settings --- src/app/components/SpaceMenu.svelte | 11 +- ...omItem.svelte => SpaceMenuRoomItem.svelte} | 7 ++ src/app/core/state.ts | 23 ++-- src/app/util/notifications.ts | 39 +++++-- src/lib/components/Link.svelte | 1 + src/routes/settings/alerts/+page.svelte | 108 +++++++++--------- src/routes/spaces/[relay]/[h]/+page.svelte | 64 +++++++++-- 7 files changed, 162 insertions(+), 91 deletions(-) rename src/app/components/{MenuSpaceRoomItem.svelte => SpaceMenuRoomItem.svelte} (66%) diff --git a/src/app/components/SpaceMenu.svelte b/src/app/components/SpaceMenu.svelte index 25a2ab9c..a4c755be 100644 --- a/src/app/components/SpaceMenu.svelte +++ b/src/app/components/SpaceMenu.svelte @@ -18,7 +18,6 @@ import CalendarMinimalistic from "@assets/icons/calendar-minimalistic.svg?dataurl" import AddCircle from "@assets/icons/add-circle.svg?dataurl" import ChatRound from "@assets/icons/chat-round.svg?dataurl" - import Bell from "@assets/icons/bell.svg?dataurl" import Icon from "@lib/components/Icon.svelte" import Link from "@lib/components/Link.svelte" import Button from "@lib/components/Button.svelte" @@ -34,7 +33,7 @@ import SpaceMembers from "@app/components/SpaceMembers.svelte" import SpaceReports from "@app/components/SpaceReports.svelte" import RoomCreate from "@app/components/RoomCreate.svelte" - import MenuSpaceRoomItem from "@app/components/MenuSpaceRoomItem.svelte" + import SpaceMenuRoomItem from "@app/components/SpaceMenuRoomItem.svelte" import SocketStatusIndicator from "@app/components/SocketStatusIndicator.svelte" import { ENABLE_ZAPS, @@ -216,7 +215,7 @@ Your Rooms {/if} {#each $userRooms as h, i (h)} - + {/each} {#if $otherRooms.length > 0}
@@ -229,7 +228,7 @@ {/if} {#each $otherRooms as h, i (h)} - + {/each} {#if $canCreateRoom} @@ -244,9 +243,5 @@ - - - Manage Alerts - diff --git a/src/app/components/MenuSpaceRoomItem.svelte b/src/app/components/SpaceMenuRoomItem.svelte similarity index 66% rename from src/app/components/MenuSpaceRoomItem.svelte rename to src/app/components/SpaceMenuRoomItem.svelte index c392f8da..c34a6e88 100644 --- a/src/app/components/MenuSpaceRoomItem.svelte +++ b/src/app/components/SpaceMenuRoomItem.svelte @@ -1,8 +1,11 @@ @@ -21,4 +25,7 @@ {replaceState} notification={notify ? $notifications.has(path) : false}> + {#if $userSettingsValues.muted_rooms.includes(id)} + + {/if} diff --git a/src/app/core/state.ts b/src/app/core/state.ts index 717562cb..5d366bf9 100644 --- a/src/app/core/state.ts +++ b/src/app/core/state.ts @@ -279,11 +279,12 @@ export type SettingsValues = { send_delay: number font_size: number alerts_push: boolean + alerts_sound: boolean + alerts_badge: boolean alerts_spaces: boolean alerts_mentions: boolean alerts_messages: boolean - alerts_sound: boolean - alerts_badge: boolean + muted_rooms: string[] } export type Settings = { @@ -300,12 +301,13 @@ export const defaultSettings: SettingsValues = { relay_auth: RelayAuthMode.Conservative, send_delay: 0, font_size: 1.1, - alerts_push: true, - alerts_spaces: false, - alerts_mentions: false, - alerts_messages: false, - alerts_sound: true, - alerts_badge: true, + alerts_push: false, + alerts_sound: false, + alerts_badge: false, + alerts_spaces: true, + alerts_mentions: true, + alerts_messages: true, + muted_rooms: [], } export const settingsByPubkey = deriveItemsByKey({ @@ -536,7 +538,10 @@ export const deriveRoom = call(() => { const _deriveRoom = makeDeriveItem(roomsById, loadRoom) return (url: string, h: string) => - derived(_deriveRoom(makeRoomId(url, h)), room => room || makeRoomMeta({h})) + derived( + _deriveRoom(makeRoomId(url, h)), + room => room || {url, id: makeRoomId(url, h), ...makeRoomMeta({h})}, + ) }) export const displayRoom = (url: string, h: string) => getRoom(makeRoomId(url, h))?.name || h diff --git a/src/app/util/notifications.ts b/src/app/util/notifications.ts index f8e41237..40fc17a8 100644 --- a/src/app/util/notifications.ts +++ b/src/app/util/notifications.ts @@ -5,7 +5,16 @@ import {Badge} from "@capawesome/capacitor-badge" import {PushNotifications} from "@capacitor/push-notifications" import type {ActionPerformed, RegistrationError, Token} from "@capacitor/push-notifications" import {synced, throttled} from "@welshman/store" -import {pubkey, tracker, repository, relaysByUrl, signer, publishThunk, getPubkeyRelays, loadRelay} from "@welshman/app" +import { + pubkey, + tracker, + repository, + relaysByUrl, + signer, + publishThunk, + getPubkeyRelays, + loadRelay, +} from "@welshman/app" import { poll, prop, @@ -278,7 +287,11 @@ export const handleBadgeCountChanges = async (count: number) => { } export const clearBadges = async () => { - await Badge.clear() + try { + await Badge.clear() + } catch (e) { + // Pass - firefox doesn't support this + } } // Local notifications @@ -354,14 +367,15 @@ class CapacitorNotifications implements IAlertsAdapter { publishThunk({ relays: [stuff.url], event: makeEvent(30390, { - content: await signer - .get() - .nip44.encrypt(stuff.pubkey, JSON.stringify([ + content: await signer.get().nip44.encrypt( + stuff.pubkey, + JSON.stringify([ ["relay", url], ["callback", info.callback], // ...ignore.map(filter => ["ignore", JSON.stringify(filter)]), ...filters.map(filter => ["filter", JSON.stringify(filter)]), - ])), + ]), + ), tags: [ ["d", await sha256(textEncoder.encode(info.callback + url + "spaces"))], ["p", stuff.pubkey], @@ -383,13 +397,14 @@ class CapacitorNotifications implements IAlertsAdapter { publishThunk({ relays: [stuff.url], event: makeEvent(30390, { - content: await signer - .get() - .nip44.encrypt(stuff.pubkey, JSON.stringify([ + content: await signer.get().nip44.encrypt( + stuff.pubkey, + JSON.stringify([ ["relay", url], ["callback", info.callback], - ["filter", JSON.stringify({kinds: DM_KINDS, '#p': [$pubkey]})], - ])), + ["filter", JSON.stringify({kinds: DM_KINDS, "#p": [$pubkey]})], + ]), + ), tags: [ ["d", await sha256(textEncoder.encode(info.callback + url + "messages"))], ["p", stuff.pubkey], @@ -449,7 +464,7 @@ class CapacitorNotifications implements IAlertsAdapter { const relays = [action.notification.data.relay] goto(await getEventPath(event, relays)) - } + }, ) }) diff --git a/src/lib/components/Link.svelte b/src/lib/components/Link.svelte index 40ae50ff..61e18bb0 100644 --- a/src/lib/components/Link.svelte +++ b/src/lib/components/Link.svelte @@ -16,6 +16,7 @@ replaceState?: boolean disabled?: boolean class?: string + 'data-tip'?: string } = $props() const go = (e: Event) => { diff --git a/src/routes/settings/alerts/+page.svelte b/src/routes/settings/alerts/+page.svelte index 24932a84..6a753e13 100644 --- a/src/routes/settings/alerts/+page.svelte +++ b/src/routes/settings/alerts/+page.svelte @@ -1,14 +1,15 @@