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