diff --git a/src/app/components/LogOut.svelte b/src/app/components/LogOut.svelte index f735b69b..330815db 100644 --- a/src/app/components/LogOut.svelte +++ b/src/app/components/LogOut.svelte @@ -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) diff --git a/src/app/components/ProfileDelete.svelte b/src/app/components/ProfileDelete.svelte index ff12810e..ac4728f7 100644 --- a/src/app/components/ProfileDelete.svelte +++ b/src/app/components/ProfileDelete.svelte @@ -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 = "/" } diff --git a/src/app/core/commands.ts b/src/app/core/commands.ts index a16c5b7d..b3cb0fb8 100644 --- a/src/app/core/commands.ts +++ b/src/app/core/commands.ts @@ -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[]) => { diff --git a/src/app/core/state.ts b/src/app/core/state.ts index ab7646e1..bb144c99 100644 --- a/src/app/core/state.ts +++ b/src/app/core/state.ts @@ -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 diff --git a/src/app/util/notifications.ts b/src/app/util/notifications.ts index 6701c0a0..c631b842 100644 --- a/src/app/util/notifications.ts +++ b/src/app/util/notifications.ts @@ -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)) } } diff --git a/src/lib/util.ts b/src/lib/util.ts index 75e971be..ab23de01 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -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() } diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 8661fbac..d51b5977 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,7 +1,6 @@