Skip to content

Commit

Permalink
fix(notifications): disable sounds on DND
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
  • Loading branch information
ShGKme committed Jun 10, 2024
1 parent f6e7743 commit 11af9d0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/shared/setupWebPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function getInitialStateFromCapabilities(capabilities, userMetadata) {
circles_enabled: false, // TODO: Missed in Capabilities. Is it a problem?
guests_accounts_enabled: true, // TODO: Missed in Capabilities. It is a problem
read_status_privacy: capabilities?.spreed?.config?.chat?.['read-privacy'],
play_sounds: true, // TODO: Missed in Capabilities. Is it a problem?
play_sounds: true, // Consider playing sound enabled by default on desktop until we have settings
attachment_folder: capabilities?.spreed?.config?.attachments?.folder,
attachment_folder_free_space: userMetadata?.quota?.free ?? 0, // TODO: Is User's Quota free equal to attachment_folder_free_space
enable_matterbridge: false, // TODO: Missed in Capabilities. Is it a problem?
Expand Down
21 changes: 21 additions & 0 deletions src/talk/renderer/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import { loadServerCss } from '../../shared/resource.utils.js'
import { appData } from '../../app/AppData.js'
import { getCapabilities } from '../../shared/ocs.service.js'
import { setInitialState } from '../../shared/initialState.service.js'
import { subscribe } from '@nextcloud/event-bus'
import { getCurrentUser } from '@nextcloud/auth'

/**
* @return {Promise<void>}
Expand Down Expand Up @@ -156,3 +159,21 @@ export function initTalkHashIntegration(talkInstance) {
},
})
}

/**
* Enable or disable the sound for notifications and calls on DND user status change
*/
export function initPlaySoundManagementOnUserStatus() {
subscribe('user_status:status.updated', (userStatus) => {
if (userStatus.userId !== getCurrentUser().uid) {
return
}
// TODO: add setting to define the default value for playSound
const playSoundDefault = true
// Disable if DND
const playSound = userStatus.status === 'dnd' ? false : playSoundDefault
// Notification's sound in the Notifications app is controlled via initial state only
setInitialState('notifications', 'sound_notification', playSound)
setInitialState('notifications', 'sound_talk', playSound)
})
}
8 changes: 7 additions & 1 deletion src/talk/renderer/talk.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import '@talk/css/icons.css'
import './assets/styles.css'

import 'regenerator-runtime' // TODO: Why isn't it added on bundling
import { initLocalStyles, initServerStyles, initTalkHashIntegration } from './init.js'
import {
initLocalStyles,
initPlaySoundManagementOnUserStatus,
initServerStyles,
initTalkHashIntegration,
} from './init.js'
import { setupWebPage } from '../../shared/setupWebPage.js'
import { createViewer } from './Viewer/Viewer.js'
import { createDesktopApp } from './desktop.app.js'
Expand All @@ -21,6 +26,7 @@ await setupWebPage()

await initServerStyles()
await initLocalStyles()
initPlaySoundManagementOnUserStatus()

createDesktopApp()

Expand Down

0 comments on commit 11af9d0

Please sign in to comment.