fix: turn on notification defaults and prompt on first DM visit #284

Merged
hodlbod merged 1 commits from userAdityaa/flotilla:fix/notification-defaults-dm-prompt into dev 2026-05-29 15:13:11 +00:00
8 changed files with 46 additions and 7 deletions
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
Review

This can't default to true, because push is only true if we've successfully requested permissions.

This can't default to true, because push is only true if we've successfully requested permissions.
Review

Let's keep sound off too, that's an optional add on. Web users will still be notified about push

Let's keep sound off too, that's an optional add on. Web users will still be notified about push
spaces: true,
mentions: true,
+1 -1
View File
@@ -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()
-1
View File
@@ -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
4
+2 -1
View File
@@ -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(
+38
View File
@@ -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
Outdated
Review

I don't think we need the modal component, just do:

if (!$dmNotificationsPrompted) {
  dmNotificationsPrompted.set(true)
  enableDMNotificationsAndShowToast() // inline the logic
}
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
Outdated
Review

This can be $dmNotificationsPrompted if it's in a svelte component

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
Review

$notificationSettings. But don't actually check this, we want to turn these on here; this guard will make this function a no-op.

`$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
Review

All of this should be handled by the push adapters. This should be as simple as calling Push.request() below.

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
Review

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} />
+2 -1
View File
@@ -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 = () => {