FEATURE: Add support for desktop push notifications in core (#19375)

* FEATURE: Add support for desktop push notifications in core

Default to push for live notifications on desktop if available and
`enable_desktop_push_notifications` site setting set to true.

This removes the need for desktop-push-notifications plugin.

* DEV: Ensure live notifications are enabled explicitly

Allow a user with push notification access who has directly
enabled notifications via the browser settings to trigger push subscription
flow.
This commit is contained in:
Selase Krakani 2022-12-16 03:35:33 +00:00 committed by GitHub
parent 4edeb7d9eb
commit 382757d1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 4 deletions

View File

@ -55,6 +55,7 @@ export default Component.extend({
return isGrantedPermission ? !notificationsDisabled : false;
},
// TODO: (selase) getter should consistently return a boolean
@discourseComputed
isEnabledPush: {
set(value) {
@ -82,11 +83,25 @@ export default Component.extend({
isEnabled: or("isEnabledDesktop", "isEnabledPush"),
isPushNotificationsPreferred() {
if (!this.site.mobileView) {
@discourseComputed("isEnabled", "isEnabledPush", "notificationsDisabled")
isSubscribed(isEnabled, isEnabledPush, notificationsDisabled) {
if (!isEnabled) {
return false;
}
return isPushNotificationsSupported();
if (this.isPushNotificationsPreferred()) {
return isEnabledPush === "subscribed";
} else {
return notificationsDisabled === "";
}
},
isPushNotificationsPreferred() {
return (
(this.site.mobileView ||
this.siteSettings.enable_desktop_push_notifications) &&
isPushNotificationsSupported()
);
},
actions: {

View File

@ -5,7 +5,7 @@
<DButton @icon="bell-slash" @class="btn-default" @label="user.desktop_notifications.perm_denied_btn" @action={{action "recheckPermission"}} @disabled="true" />
{{i18n "user.desktop_notifications.perm_denied_expl"}}
{{else}}
{{#if this.isEnabled}}
{{#if this.isSubscribed}}
<DButton @icon="far-bell-slash" @class="btn-default" @label="user.desktop_notifications.disable" @action={{action "turnoff"}} />
{{else}}
<DButton @icon="far-bell" @class="btn-default" @label="user.desktop_notifications.enable" @action={{action "turnon"}} />

View File

@ -2357,6 +2357,7 @@ en:
push_notifications_prompt: "Display user consent prompt."
push_notifications_icon: "The badge icon that appears in the notification corner. A 96×96 monochromatic PNG with transparency is recommended."
enable_desktop_push_notifications: "Enable desktop push notifications"
base_font: "Base font to use for most text on the site. Themes can override via the `--font-family` CSS custom property."
heading_font: "Font to use for headings on the site. Themes can override via the `--heading-font-family` CSS custom property."

View File

@ -348,6 +348,9 @@ basic:
push_notifications_icon:
default: ""
type: upload
enable_desktop_push_notifications:
default: true
client: true
short_title:
default: ""
max: 12