Disable alerts on logout

This commit is contained in:
Jon Staab
2026-01-26 10:08:43 -08:00
parent 646b8f8736
commit 9b3a8258ce
8 changed files with 52 additions and 71 deletions
+8 -2
View File
@@ -6,7 +6,8 @@
import Spinner from "@lib/components/Spinner.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import {logout} from "@app/core/commands"
import {Push} from "@app/util/notifications"
import {kv, db} from "@app/core/storage"
const back = () => history.back()
@@ -14,7 +15,12 @@
loading = true
try {
await logout()
await Push.disable()
await kv.clear()
await db.clear()
localStorage.clear()
window.location.href = "/"
} catch (e) {
console.error(e)
+8 -3
View File
@@ -18,9 +18,10 @@
import Spinner from "@lib/components/Spinner.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import {pushToast} from "@app/util/toast"
import {logout} from "@app/core/commands"
import {INDEXER_RELAYS, PLATFORM_NAME, userSpaceUrls} from "@app/core/state"
import {kv, db} from "@app/core/storage"
import {pushToast} from "@app/util/toast"
import {Push} from "@app/util/notifications"
let progress: number | undefined = $state(undefined)
let confirmText = $state("")
@@ -83,7 +84,11 @@
await sleep(2000)
// Goodbye forever!
await logout()
await Push.disable()
await kv.clear()
await db.clear()
localStorage.clear()
window.location.href = "/"
}
-17
View File
@@ -64,7 +64,6 @@ import {
tagEvent,
tagEventForReaction,
nip44EncryptToSelf,
dropSession,
tagEventForComment,
tagEventForQuote,
waitForThunkError,
@@ -73,7 +72,6 @@ import {
getThunkError,
} from "@welshman/app"
import {compressFile} from "@lib/html"
import {kv, db} from "@app/core/storage"
import type {SettingsValues} from "@app/core/state"
import {
SETTINGS,
@@ -115,21 +113,6 @@ export const prependParent = (parent: TrustedEvent | undefined, {content, tags}:
return {content, tags}
}
// Log out
export const logout = async () => {
const $pubkey = pubkey.get()
if ($pubkey) {
dropSession($pubkey)
}
localStorage.clear()
await kv.clear()
await db.clear()
}
// Synchronization
export const broadcastUserData = async (relays: string[]) => {
+11 -8
View File
@@ -342,9 +342,9 @@ export const notificationSettings = withGetter(
push: boolean
sound: boolean
badge: boolean
spaces: boolean,
mentions: boolean,
messages: boolean,
spaces: boolean
mentions: boolean
messages: boolean
token?: string
subscription?: {
key: string
@@ -357,7 +357,7 @@ export const notificationSettings = withGetter(
spaces: true,
mentions: true,
messages: true,
})
}),
)
// Chats
@@ -452,10 +452,13 @@ export const deriveChat = call(() => {
})
export const chatSearch = derived(throttled(800, chatsById), $chatsByPubkey => {
return createSearch(Array.from($chatsByPubkey.values()), {
getValue: (chat: Chat) => chat.id,
fuseOptions: {keys: ["search_text"]},
})
return createSearch(
sortBy(c => -c.last_activity, Array.from($chatsByPubkey.values())),
{
getValue: (chat: Chat) => chat.id,
fuseOptions: {keys: ["search_text"]},
},
)
})
// Rooms
+19 -23
View File
@@ -16,7 +16,6 @@ import {
loadRelay,
waitForThunkError,
} from "@welshman/app"
import type {Maybe} from "@welshman/lib"
import {
on,
call,
@@ -24,7 +23,6 @@ import {
poll,
prop,
hash,
textEncoder,
parseJson,
flatten,
find,
@@ -33,9 +31,7 @@ import {
identity,
now,
groupBy,
tryCatch,
postJson,
fetchJson,
} from "@welshman/lib"
import type {TrustedEvent, RelayProfile, Filter} from "@welshman/util"
import {deriveEventsByIdByUrl} from "@welshman/store"
@@ -51,7 +47,7 @@ import {
makeEvent,
RelayMode,
} from "@welshman/util"
import {buildUrl} from '@lib/util'
import {buildUrl} from "@lib/util"
import {
makeSpacePath,
makeChatPath,
@@ -73,7 +69,6 @@ import {
chatsById,
hasNip29,
getSettings,
userSettings,
userSettingsValues,
userGroupList,
getSpaceUrlsFromGroupList,
@@ -343,16 +338,17 @@ interface IPushAdapter {
start: () => Unsubscriber
}
PushNotifications.addListener(
"pushNotificationActionPerformed",
async (action: ActionPerformed) => {
console.log('====== action', JSON.stringify(action))
const event = parseJson(action.notification.data.event)
const relays = [action.notification.data.relay]
if (Capacitor.isNativePlatform()) {
PushNotifications.addListener(
"pushNotificationActionPerformed",
async (action: ActionPerformed) => {
const event = parseJson(action.notification.data.event)
const relays = [action.notification.data.relay]
goto(await getEventPath(event, relays))
},
)
goto(await getEventPath(event, relays))
},
)
}
class CapacitorNotifications implements IPushAdapter {
async request(prompt = true) {
@@ -385,7 +381,7 @@ class CapacitorNotifications implements IPushAdapter {
}),
])
notificationSettings.update(assoc('token', token))
notificationSettings.update(assoc("token", token))
}
return token ? "granted" : "denied"
@@ -403,7 +399,7 @@ class CapacitorNotifications implements IPushAdapter {
const json = await postJson(url, {token}, {signal})
if (json?.callback && json?.id) {
notificationSettings.update(assoc('subscription', json))
notificationSettings.update(assoc("subscription", json))
} else {
console.warn("Failed to register with push server")
}
@@ -523,17 +519,17 @@ class CapacitorNotifications implements IPushAdapter {
}
async enable() {
notificationSettings.update(assoc('push', true))
notificationSettings.update(assoc("push", true))
}
async disable() {
const {token, subscription, ...settings} = notificationSettings.get()
const {subscription, ...settings} = notificationSettings.get()
await PushNotifications.unregister()
if (subscription) {
const res = await fetch(buildUrl(PUSH_SERVER, 'subscription', subscription.key), {
method: 'delete',
const res = await fetch(buildUrl(PUSH_SERVER, "subscription", subscription.key), {
method: "delete",
})
if (!res.ok) {
@@ -599,11 +595,11 @@ class WebNotifications implements IPushAdapter {
}
async enable() {
notificationSettings.update(assoc('push', true))
notificationSettings.update(assoc("push", true))
}
async disable() {
notificationSettings.update(assoc('push', false))
notificationSettings.update(assoc("push", false))
}
}
+1 -1
View File
@@ -20,7 +20,7 @@ export const ucFirst = (s: string) => s.slice(0, 1).toUpperCase() + s.slice(1)
export const buildUrl = (base: string | URL, ...pathname: string[]) => {
const url = new URL(base)
url.pathname = '/' + pathname.join('/')
url.pathname = "/" + pathname.join("/")
return url.toString()
}
-1
View File
@@ -1,7 +1,6 @@
<script lang="ts">
import "@src/app.css"
import "@capacitor-community/safe-area"
import {PushNotifications} from "@capacitor/push-notifications"
import * as nip19 from "nostr-tools/nip19"
import type {Unsubscriber} from "svelte/store"
import {get} from "svelte/store"
+5 -16
View File
@@ -79,10 +79,7 @@
{#if isSupported}
<div class="flex justify-between">
<p>Show badge for unread alerts</p>
<input
type="checkbox"
class="toggle toggle-primary"
bind:checked={settings.badge} />
<input type="checkbox" class="toggle toggle-primary" bind:checked={settings.badge} />
</div>
{/if}
{/await}
@@ -94,16 +91,12 @@
{/if}
<div class="flex justify-between">
<p>Enable push notifications</p>
<input
type="checkbox"
class="toggle toggle-primary"
bind:checked={settings.push} />
<input type="checkbox" class="toggle toggle-primary" bind:checked={settings.push} />
</div>
</div>
<div
class={cx("card2 bg-alt col-4 shadow-md", {
"pointer-events-none opacity-50":
!settings.badge && !settings.sound && !settings.push,
"pointer-events-none opacity-50": !settings.badge && !settings.sound && !settings.push,
})}>
<strong class="text-lg">Alert Types</strong>
<div class="flex justify-between">
@@ -116,16 +109,12 @@
</div>
<div class="flex justify-between">
<p>Notify me about new messages</p>
<input
type="checkbox"
class="toggle toggle-primary"
bind:checked={settings.messages} />
<input type="checkbox" class="toggle toggle-primary" bind:checked={settings.messages} />
</div>
</div>
<div
class={cx("card2 bg-alt col-4 shadow-md", {
"pointer-events-none opacity-50":
!settings.badge && !settings.sound && !settings.push,
"pointer-events-none opacity-50": !settings.badge && !settings.sound && !settings.push,
})}>
<strong class="text-lg">Muted Rooms</strong>
{#each muted_rooms as id (id)}