fix: turn on notification defaults and prompt on first DM visit #284
@@ -23,8 +23,8 @@
|
||||
import SpaceJoinSettings from "@app/components/SpaceJoinSettings.svelte"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {makeSpacePath} from "@app/util/routes"
|
||||
import {Push} from "@app/util/notifications"
|
||||
import {relaysMostlyRestricted, notificationSettings, parseInviteLink} from "@app/core/state"
|
||||
import {Push} from "@app/util/push"
|
||||
import {
|
||||
attemptRelayAccess,
|
||||
addSpaceMembership,
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
import {pushModal} from "@app/util/modal"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {makeSpacePath} from "@app/util/routes"
|
||||
import {Push} from "@app/util/notifications"
|
||||
import {Push} from "@app/util/push"
|
||||
|
||||
type Props = {
|
||||
url: string
|
||||
|
||||
@@ -418,7 +418,7 @@ export const device = withGetter(writable(randomId()))
|
||||
export const notificationSettings = withGetter(
|
||||
writable({
|
||||
push: false,
|
||||
sound: false,
|
||||
sound: true,
|
||||
badge: false,
|
||||
|
hodlbod marked this conversation as resolved
|
||||
spaces: true,
|
||||
mentions: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {db, kv, ss} from "@app/core/storage"
|
||||
import {Push} from "@app/util/notifications"
|
||||
import {deactivateCurrentPomadeSession} from "@app/util/pomade"
|
||||
import {Push} from "@app/util/push"
|
||||
|
||||
export const logout = async () => {
|
||||
await deactivateCurrentPomadeSession()
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
} from "@app/core/state"
|
||||
import {kv} from "@app/core/storage"
|
||||
import {page} from "$app/stores"
|
||||
export {Push} from "@app/util/push"
|
||||
|
||||
// Checked state
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
import {theme} from "@app/util/theme"
|
||||
import {toast, pushToast} from "@app/util/toast"
|
||||
import * as notifications from "@app/util/notifications"
|
||||
import {Push} from "@app/util/push"
|
||||
import {onPushNotificationAction} from "@app/util/push/adapters/common"
|
||||
import * as storage from "@app/util/storage"
|
||||
import {syncKeyboard} from "@app/util/keyboard"
|
||||
@@ -175,7 +176,7 @@
|
||||
unsubscribers.push(notifications.syncChecked())
|
||||
|
||||
// Initialize background notifications
|
||||
unsubscribers.push(notifications.Push.sync())
|
||||
unsubscribers.push(Push.sync())
|
||||
|
||||
// Listen for signer errors, report to user via toast
|
||||
unsubscribers.push(
|
||||
|
||||
@@ -1,13 +1,51 @@
|
||||
<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">
|
||||
import {onMount} from "svelte"
|
||||
import {page} from "$app/stores"
|
||||
import type {MakeNonOptional} from "@welshman/lib"
|
||||
import {append, uniq} from "@welshman/lib"
|
||||
import {pubkey} from "@welshman/app"
|
||||
import Chat from "@app/components/Chat.svelte"
|
||||
import {splitChatId} from "@app/core/state"
|
||||
import {notificationSettings} from "@app/core/state"
|
||||
|
hodlbod marked this conversation as resolved
Outdated
hodlbod
commented
I don't think we need the modal component, just do: I don't think we need the modal component, just do:
```
if (!$dmNotificationsPrompted) {
dmNotificationsPrompted.set(true)
enableDMNotificationsAndShowToast() // inline the logic
}
```
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {Push} from "@app/util/push"
|
||||
|
||||
const {chat} = $page.params as MakeNonOptional<typeof $page.params>
|
||||
const pubkeys = uniq(append($pubkey!, splitChatId(chat)))
|
||||
|
||||
onMount(async () => {
|
||||
if (!$dmNotificationsPrompted) {
|
||||
dmNotificationsPrompted.set(true)
|
||||
|
||||
|
hodlbod marked this conversation as resolved
Outdated
hodlbod
commented
This can be This can be `$dmNotificationsPrompted` if it's in a svelte component
|
||||
const permission = await Push.request()
|
||||
|
||||
if (!permission.startsWith("granted")) {
|
||||
return pushToast({
|
||||
|
hodlbod marked this conversation as resolved
hodlbod
commented
`$notificationSettings`. But don't actually check this, we want to turn these on here; this guard will make this function a no-op.
|
||||
theme: "error",
|
||||
message: `Failed to request notification permissions (${permission}).`,
|
||||
})
|
||||
}
|
||||
|
||||
notificationSettings.update(current => ({
|
||||
...current,
|
||||
push: true,
|
||||
|
hodlbod marked this conversation as resolved
hodlbod
commented
All of this should be handled by the push adapters. This should be as simple as calling All of this should be handled by the push adapters. This should be as simple as calling `Push.request()` below.
|
||||
messages: true,
|
||||
}))
|
||||
|
||||
|
hodlbod marked this conversation as resolved
hodlbod
commented
Leave badge and sound alone I think, push is enough. Leave badge and sound alone I think, push is enough.
|
||||
pushToast({message: "Notifications enabled!"})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Chat {pubkeys} />
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
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"
|
||||
|
||||
const reset = () => {
|
||||
|
||||
Reference in New Issue
Block a user
This can't default to true, because push is only true if we've successfully requested permissions.
Let's keep sound off too, that's an optional add on. Web users will still be notified about push