forked from coracle/flotilla
fix: turn on notification defaults and prompt on first DM visit
This commit is contained in:
@@ -23,8 +23,8 @@
|
|||||||
import SpaceJoinSettings from "@app/components/SpaceJoinSettings.svelte"
|
import SpaceJoinSettings from "@app/components/SpaceJoinSettings.svelte"
|
||||||
import {pushToast} from "@app/util/toast"
|
import {pushToast} from "@app/util/toast"
|
||||||
import {makeSpacePath} from "@app/util/routes"
|
import {makeSpacePath} from "@app/util/routes"
|
||||||
import {Push} from "@app/util/notifications"
|
|
||||||
import {relaysMostlyRestricted, notificationSettings, parseInviteLink} from "@app/core/state"
|
import {relaysMostlyRestricted, notificationSettings, parseInviteLink} from "@app/core/state"
|
||||||
|
import {Push} from "@app/util/push"
|
||||||
import {
|
import {
|
||||||
attemptRelayAccess,
|
attemptRelayAccess,
|
||||||
addSpaceMembership,
|
addSpaceMembership,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
import {pushModal} from "@app/util/modal"
|
import {pushModal} from "@app/util/modal"
|
||||||
import {pushToast} from "@app/util/toast"
|
import {pushToast} from "@app/util/toast"
|
||||||
import {makeSpacePath} from "@app/util/routes"
|
import {makeSpacePath} from "@app/util/routes"
|
||||||
import {Push} from "@app/util/notifications"
|
import {Push} from "@app/util/push"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
url: string
|
url: string
|
||||||
|
|||||||
@@ -417,9 +417,9 @@ export const device = withGetter(writable(randomId()))
|
|||||||
|
|
||||||
export const notificationSettings = withGetter(
|
export const notificationSettings = withGetter(
|
||||||
writable({
|
writable({
|
||||||
push: false,
|
push: true,
|
||||||
sound: false,
|
sound: true,
|
||||||
badge: false,
|
badge: true,
|
||||||
spaces: true,
|
spaces: true,
|
||||||
mentions: true,
|
mentions: true,
|
||||||
messages: true,
|
messages: true,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {db, kv, ss} from "@app/core/storage"
|
import {db, kv, ss} from "@app/core/storage"
|
||||||
import {Push} from "@app/util/notifications"
|
|
||||||
import {deactivateCurrentPomadeSession} from "@app/util/pomade"
|
import {deactivateCurrentPomadeSession} from "@app/util/pomade"
|
||||||
|
import {Push} from "@app/util/push"
|
||||||
|
|
||||||
export const logout = async () => {
|
export const logout = async () => {
|
||||||
await deactivateCurrentPomadeSession()
|
await deactivateCurrentPomadeSession()
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import {
|
|||||||
} from "@app/core/state"
|
} from "@app/core/state"
|
||||||
import {kv} from "@app/core/storage"
|
import {kv} from "@app/core/storage"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
export {Push} from "@app/util/push"
|
|
||||||
|
|
||||||
// Checked state
|
// Checked state
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
import {theme} from "@app/util/theme"
|
import {theme} from "@app/util/theme"
|
||||||
import {toast, pushToast} from "@app/util/toast"
|
import {toast, pushToast} from "@app/util/toast"
|
||||||
import * as notifications from "@app/util/notifications"
|
import * as notifications from "@app/util/notifications"
|
||||||
|
import {Push} from "@app/util/push"
|
||||||
import {onPushNotificationAction} from "@app/util/push/adapters/common"
|
import {onPushNotificationAction} from "@app/util/push/adapters/common"
|
||||||
import * as storage from "@app/util/storage"
|
import * as storage from "@app/util/storage"
|
||||||
import {syncKeyboard} from "@app/util/keyboard"
|
import {syncKeyboard} from "@app/util/keyboard"
|
||||||
@@ -175,7 +176,7 @@
|
|||||||
unsubscribers.push(notifications.syncChecked())
|
unsubscribers.push(notifications.syncChecked())
|
||||||
|
|
||||||
// Initialize background notifications
|
// Initialize background notifications
|
||||||
unsubscribers.push(notifications.Push.sync())
|
unsubscribers.push(Push.sync())
|
||||||
|
|
||||||
// Listen for signer errors, report to user via toast
|
// Listen for signer errors, report to user via toast
|
||||||
unsubscribers.push(
|
unsubscribers.push(
|
||||||
|
|||||||
@@ -1,13 +1,71 @@
|
|||||||
|
<script context="module" lang="ts">
|
||||||
|
import {synced} from "@welshman/store"
|
||||||
|
import {kv} from "@app/core/storage"
|
||||||
|
|
||||||
|
const dmNotificationsPrompted = synced({
|
||||||
|
key: "dmNotificationsPrompted",
|
||||||
|
defaultValue: false,
|
||||||
|
storage: kv,
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {onMount} from "svelte"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
|
import {get} from "svelte/store"
|
||||||
import type {MakeNonOptional} from "@welshman/lib"
|
import type {MakeNonOptional} from "@welshman/lib"
|
||||||
import {append, uniq} from "@welshman/lib"
|
import {append, uniq} from "@welshman/lib"
|
||||||
|
import {Capacitor} from "@capacitor/core"
|
||||||
import {pubkey} from "@welshman/app"
|
import {pubkey} from "@welshman/app"
|
||||||
import Chat from "@app/components/Chat.svelte"
|
import Chat from "@app/components/Chat.svelte"
|
||||||
import {splitChatId} from "@app/core/state"
|
import {splitChatId} from "@app/core/state"
|
||||||
|
import {notificationSettings, pushState} from "@app/core/state"
|
||||||
|
import {pushToast} from "@app/util/toast"
|
||||||
|
import {Push} from "@app/util/push"
|
||||||
|
|
||||||
const {chat} = $page.params as MakeNonOptional<typeof $page.params>
|
const {chat} = $page.params as MakeNonOptional<typeof $page.params>
|
||||||
const pubkeys = uniq(append($pubkey!, splitChatId(chat)))
|
const pubkeys = uniq(append($pubkey!, splitChatId(chat)))
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (!get(dmNotificationsPrompted)) {
|
||||||
|
dmNotificationsPrompted.set(true)
|
||||||
|
|
||||||
|
const enableDMNotificationsAndShowToast = async () => {
|
||||||
|
const {push, messages} = notificationSettings.get()
|
||||||
|
|
||||||
|
if (push && messages) {
|
||||||
|
if (Capacitor.isNativePlatform()) {
|
||||||
|
if (pushState.get().token) return
|
||||||
|
} else {
|
||||||
|
if (Notification?.permission === "granted") return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const permission = await Push.request()
|
||||||
|
|
||||||
|
if (!permission.startsWith("granted")) {
|
||||||
|
return pushToast({
|
||||||
|
theme: "error",
|
||||||
|
message: `Failed to request notification permissions (${permission}).`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = notificationSettings.get()
|
||||||
|
|
||||||
|
notificationSettings.set({
|
||||||
|
...current,
|
||||||
|
push: true,
|
||||||
|
badge: true,
|
||||||
|
sound: Capacitor.isNativePlatform() ? current.sound : true,
|
||||||
|
messages: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
pushToast({message: "Notifications enabled!"})
|
||||||
|
}
|
||||||
|
|
||||||
|
enableDMNotificationsAndShowToast()
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Chat {pubkeys} />
|
<Chat {pubkeys} />
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import {pushToast} from "@app/util/toast"
|
import {pushToast} from "@app/util/toast"
|
||||||
import {Push, clearBadges} from "@app/util/notifications"
|
import {clearBadges} from "@app/util/notifications"
|
||||||
|
import {Push} from "@app/util/push"
|
||||||
import {notificationSettings} from "@app/core/state"
|
import {notificationSettings} from "@app/core/state"
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user