fix: turn on notification defaults and prompt on first DM visit #284
Reference in New Issue
Block a user
Delete Branch "userAdityaa/flotilla:fix/notification-defaults-dm-prompt"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
push,sound,badge) are now enabled for new users; they can disable them under Settings → Alerts.Push.request()flow.Screen shot
closes #257
0bbff458bdto36b09eb8d5@@ -21,1 +23,3 @@export {Push} from "@app/util/push"import {Push} from "@app/util/push"export {Push}Never re-export, always update imports
@@ -22,0 +36,4 @@}return Notification?.permission === "granted"}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, notnotifications(which handles badges/checked state).@@ -22,0 +56,4 @@})return true}Also badly named, because this only enables messaging notifications. Just inline all this logic.
@@ -22,0 +62,4 @@key: "dmNotificationsPrompted",defaultValue: false,storage: kv,})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)I don't think we need the modal component, just do:
36b09eb8d5toa63734fa1d@@ -422,1 +420,3 @@badge: false,push: true,sound: true,badge: true,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
@@ -10,1 +27,4 @@const pubkeys = uniq(append($pubkey!, splitChatId(chat)))onMount(() => {if (!get(dmNotificationsPrompted)) {This can be
$dmNotificationsPromptedif it's in a svelte component@@ -11,0 +31,4 @@dmNotificationsPrompted.set(true)const enableDMNotificationsAndShowToast = async () => {const {push, messages} = notificationSettings.get()$notificationSettings. But don't actually check this, we want to turn these on here; this guard will make this function a no-op.@@ -11,0 +39,4 @@} else {if (Notification?.permission === "granted") return}}All of this should be handled by the push adapters. This should be as simple as calling
Push.request()below.@@ -11,0 +58,4 @@badge: true,sound: Capacitor.isNativePlatform() ? current.sound : true,messages: true,})notificationSettings.updatewould be more idiomatic here@@ -11,0 +63,4 @@pushToast({message: "Notifications enabled!"})}enableDMNotificationsAndShowToast()Unless we need to return an unsubscribe function from onMount, we can just make the closure
asyncand avoid the define/call function pattern.a63734fa1dtof3763eee7eLooks pretty good, just a couple small things.
@@ -11,0 +42,4 @@...current,push: true,badge: true,sound: Capacitor.isNativePlatform() ? current.sound : true,Leave badge and sound alone I think, push is enough.
f3763eee7etoddf9358703ddf9358703tocbe311262a