-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1949 from nextcloud/backport/1947/stable28
[stable28] fix: separate creation of browser notifications and sounds from Vue rendering
- Loading branch information
Showing
7 changed files
with
110 additions
and
91 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...oment_locale_sync_recursive_-src_NotificationsApp_vue-data_image_svg_xml_base64-ab95a3.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...t_locale_sync_recursive_-src_NotificationsApp_vue-data_image_svg_xml_base64-ab95a3.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { emit } from '@nextcloud/event-bus' | ||
import { loadState } from '@nextcloud/initial-state' | ||
import { generateFilePath } from '@nextcloud/router' | ||
import { Howl } from 'howler' | ||
|
||
/** | ||
* Create a browser notification | ||
* | ||
* @param {object} notification notification object | ||
* @see https://developer.mozilla.org/en/docs/Web/API/notification | ||
*/ | ||
const createWebNotification = (notification) => { | ||
if (!notification.shouldNotify) { | ||
return | ||
} | ||
|
||
const n = new Notification(notification.subject, { | ||
title: notification.subject, | ||
lang: OC.getLocale(), | ||
body: notification.message, | ||
icon: notification.icon, | ||
tag: notification.notificationId, | ||
}) | ||
|
||
if (notification.link) { | ||
n.onclick = async function(e) { | ||
const event = { | ||
cancelAction: false, | ||
notification, | ||
action: { | ||
url: notification.link, | ||
type: 'WEB', | ||
}, | ||
} | ||
await emit('notifications:action:execute', event) | ||
|
||
if (!event.cancelAction) { | ||
console.debug('Redirecting because of a click onto a notification', notification.link) | ||
window.location.href = notification.link | ||
} | ||
|
||
// Best effort try to bring the tab to the foreground (works at least in Chrome, not in Firefox) | ||
window.focus() | ||
} | ||
} | ||
|
||
playNotificationSound(notification) | ||
} | ||
|
||
/** | ||
* Play a notification sound (if enabled on instance) | ||
* @param {object} notification notification object | ||
*/ | ||
const playNotificationSound = (notification) => { | ||
if (notification.app === 'spreed' && notification.objectType === 'call') { | ||
if (loadState('notifications', 'sound_talk')) { | ||
const sound = new Howl({ | ||
src: [ | ||
generateFilePath('notifications', 'img', 'talk.ogg'), | ||
], | ||
volume: 0.5, | ||
}) | ||
|
||
sound.play() | ||
} | ||
} else if (loadState('notifications', 'sound_notification')) { | ||
const sound = new Howl({ | ||
src: [ | ||
generateFilePath('notifications', 'img', 'notification.ogg'), | ||
], | ||
volume: 0.5, | ||
}) | ||
|
||
sound.play() | ||
} | ||
} | ||
|
||
export { | ||
createWebNotification, | ||
} |