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
Collaborator

Summary

  • Default notification settings (push, sound, badge) are now enabled for new users; they can disable them under Settings → Alerts.
  • On the first visit to a direct message conversation, if notifications are not actually working (settings off or OS permission/token missing), show a modal to enable notifications via the existing Push.request() flow.

Screen shot

  • First time dming someone, if notification not enabled
Screenshot 2026-05-26 at 11.39.49 AM.png

closes #257

### Summary - Default notification settings (`push`, `sound`, `badge`) are now enabled for new users; they can disable them under Settings → Alerts. - On the first visit to a direct message conversation, if notifications are not actually working (settings off or OS permission/token missing), show a modal to enable notifications via the existing `Push.request()` flow. ### Screen shot * First time dming someone, if notification not enabled <img width="1439" alt="Screenshot 2026-05-26 at 11.39.49 AM.png" src="attachments/0a6a8133-e59b-413d-a2d9-e27809031112"> closes #257
userAdityaa force-pushed fix/notification-defaults-dm-prompt from 0bbff458bd to 36b09eb8d5 2026-05-26 06:14:14 +00:00 Compare
hodlbod reviewed 2026-05-26 15:49:32 +00:00
@@ -21,1 +23,3 @@
export {Push} from "@app/util/push"
import {Push} from "@app/util/push"
export {Push}
Owner

Never re-export, always update imports

Never re-export, always update imports
@@ -22,0 +36,4 @@
}
return Notification?.permission === "granted"
}
Owner

This is very badly named, because it checks messages specifically. That logic should be inlined, this should only check push/token/permission. This should also live in push, not notifications (which handles badges/checked state).

This is very badly named, because it checks messages specifically. That logic should be inlined, this should only check push/token/permission. This should also live in `push`, not `notifications` (which handles badges/checked state).
@@ -22,0 +56,4 @@
})
return true
}
Owner

Also badly named, because this only enables messaging notifications. Just inline all this logic.

Also badly named, because this only enables messaging notifications. Just inline all this logic.
@@ -22,0 +62,4 @@
key: "dmNotificationsPrompted",
defaultValue: false,
storage: kv,
})
Owner

Put this in a script context="module" in the component where it's used.

Put this in a `script context="module"` in the component where it's used.
@@ -11,0 +17,4 @@
onMount(() => {
if (!areNotificationsEnabled() && !get(dmNotificationsPrompted)) {
dmNotificationsPrompted.set(true)
pushModal(EnableNotificationsPrompt)
Owner

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 } ```
hodlbod marked this conversation as resolved
userAdityaa force-pushed fix/notification-defaults-dm-prompt from 36b09eb8d5 to a63734fa1d 2026-05-27 15:02:29 +00:00 Compare
hodlbod reviewed 2026-05-27 17:41:23 +00:00
@@ -422,1 +420,3 @@
badge: false,
push: true,
sound: true,
badge: true,
Owner

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.
Owner

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
hodlbod marked this conversation as resolved
@@ -10,1 +27,4 @@
const pubkeys = uniq(append($pubkey!, splitChatId(chat)))
onMount(() => {
if (!get(dmNotificationsPrompted)) {
Owner

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

This can be `$dmNotificationsPrompted` if it's in a svelte component
hodlbod marked this conversation as resolved
@@ -11,0 +31,4 @@
dmNotificationsPrompted.set(true)
const enableDMNotificationsAndShowToast = async () => {
const {push, messages} = notificationSettings.get()
Owner

$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.
hodlbod marked this conversation as resolved
@@ -11,0 +39,4 @@
} else {
if (Notification?.permission === "granted") return
}
}
Owner

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.
hodlbod marked this conversation as resolved
@@ -11,0 +58,4 @@
badge: true,
sound: Capacitor.isNativePlatform() ? current.sound : true,
messages: true,
})
Owner

notificationSettings.update would be more idiomatic here

`notificationSettings.update` would be more idiomatic here
@@ -11,0 +63,4 @@
pushToast({message: "Notifications enabled!"})
}
enableDMNotificationsAndShowToast()
Owner

Unless we need to return an unsubscribe function from onMount, we can just make the closure async and avoid the define/call function pattern.

Unless we need to return an unsubscribe function from onMount, we can just make the closure `async` and avoid the define/call function pattern.
userAdityaa force-pushed fix/notification-defaults-dm-prompt from a63734fa1d to f3763eee7e 2026-05-28 06:43:24 +00:00 Compare
hodlbod reviewed 2026-05-28 22:26:55 +00:00
hodlbod left a comment
Owner

Looks pretty good, just a couple small things.

Looks pretty good, just a couple small things.
@@ -11,0 +42,4 @@
...current,
push: true,
badge: true,
sound: Capacitor.isNativePlatform() ? current.sound : true,
Owner

Leave badge and sound alone I think, push is enough.

Leave badge and sound alone I think, push is enough.
hodlbod marked this conversation as resolved
userAdityaa force-pushed fix/notification-defaults-dm-prompt from f3763eee7e to ddf9358703 2026-05-29 05:05:33 +00:00 Compare
hodlbod added 1 commit 2026-05-29 15:12:50 +00:00
hodlbod force-pushed fix/notification-defaults-dm-prompt from ddf9358703 to cbe311262a 2026-05-29 15:12:50 +00:00 Compare
hodlbod merged commit 8dd278f47c into dev 2026-05-29 15:13:11 +00:00
hodlbod deleted branch fix/notification-defaults-dm-prompt 2026-05-29 15:13:11 +00:00
Sign in to join this conversation.