@@ -64,6 +64,29 @@ async function createIfNotExists (doc, contentType = 'text/turtle', data = '') {
6464 return response
6565}
6666
67+ function desktopNotification ( str ) {
68+ // Let's check if the browser supports notifications
69+ if ( ! ( 'Notification' in window ) ) {
70+ console . warn ( 'This browser does not support desktop notification' )
71+ } else if ( Notification . permission === 'granted' ) {
72+ // Let's check whether notification permissions have already been granted
73+ // eslint-disable-next-line no-new
74+ new Notification ( str )
75+ } else if ( Notification . permission !== 'denied' ) {
76+ // Otherwise, we need to ask the user for permission
77+ Notification . requestPermission ( ) . then ( function ( permission ) {
78+ // If the user accepts, let's create a notification
79+ if ( permission === 'granted' ) {
80+ // eslint-disable-next-line no-new
81+ new Notification ( str )
82+ }
83+ } )
84+ }
85+
86+ // At last, if the user has denied notifications, and you
87+ // want to be respectful there is no need to bother them any more.
88+ }
89+
6790export function infiniteMessageArea ( dom , kb , chatChannel , options ) {
6891 kb = kb || UI . store
6992 const ns = UI . ns
@@ -711,6 +734,7 @@ export function infiniteMessageArea (dom, kb, chatChannel, options) {
711734 // only the last messageTable is live
712735 addNewTableIfNewDay ( new Date ( ) ) . then ( ( ) => {
713736 syncMessages ( chatChannel , messageTable )
737+ desktopNotification ( chatChannel )
714738 } )
715739 } // The short chat version fors live update in the pane but we do it in the widget
716740 kb . updater . addDownstreamChangeListener ( chatDocument , div . refresh ) // Live update
0 commit comments