Skip to content

Commit

Permalink
fix: 🐛 Mute volume being translated to max volume
Browse files Browse the repository at this point in the history
Fixed a bug in the volume control logic where setting a volume to 0 would incorrectly reset it to 100. This happened because the original code used the logical OR operator (||), which treats 0 as a falsy value. The fix replaces || with the nullish coalescing operator (??), which only falls back to the default value when the input is null or undefined, not when it's 0.
  • Loading branch information
rique223 committed Jan 9, 2025
1 parent 8acddb1 commit 00da4b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
10 changes: 4 additions & 6 deletions apps/meteor/client/hooks/useUserSoundPreferences.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { useUserPreference } from '@rocket.chat/ui-contexts';

const relativeVolume = (volume: number, masterVolume: number) => {
return (volume * masterVolume) / 100;
};
const relativeVolume = (volume: number, masterVolume: number) => (volume * masterVolume) / 100;

export const useUserSoundPreferences = () => {
const masterVolume = useUserPreference<number>('masterVolume', 100) || 100;
const notificationsSoundVolume = useUserPreference<number>('notificationsSoundVolume', 100) || 100;
const callRingerVolume = useUserPreference<number>('callRingerVolume', 100) || 100;
const masterVolume = useUserPreference<number>('masterVolume', 100) ?? 100;
const notificationsSoundVolume = useUserPreference<number>('notificationsSoundVolume', 100) ?? 100;
const callRingerVolume = useUserPreference<number>('callRingerVolume', 100) ?? 100;

return {
masterVolume,
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7894,18 +7894,18 @@ __metadata:
storybook-dark-mode: "npm:^4.0.2"
typescript: "npm:~5.7.2"
peerDependencies:
"@rocket.chat/apps-engine": 1.48.1-rc.1
"@rocket.chat/apps-engine": 1.48.1
"@rocket.chat/eslint-config": 0.7.0
"@rocket.chat/fuselage": "*"
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/fuselage-polyfills": "*"
"@rocket.chat/icons": "*"
"@rocket.chat/prettier-config": "*"
"@rocket.chat/styled": "*"
"@rocket.chat/ui-avatar": 10.0.0-rc.3
"@rocket.chat/ui-contexts": 14.0.0-rc.3
"@rocket.chat/ui-avatar": 10.0.0
"@rocket.chat/ui-contexts": 14.0.0
"@rocket.chat/ui-kit": 0.37.0
"@rocket.chat/ui-video-conf": 14.0.0-rc.3
"@rocket.chat/ui-video-conf": 14.0.0
"@tanstack/react-query": "*"
react: ~17.0.2
react-dom: "*"
Expand Down Expand Up @@ -7990,8 +7990,8 @@ __metadata:
"@rocket.chat/fuselage-tokens": "*"
"@rocket.chat/message-parser": 0.31.31
"@rocket.chat/styled": "*"
"@rocket.chat/ui-client": 14.0.0-rc.3
"@rocket.chat/ui-contexts": 14.0.0-rc.3
"@rocket.chat/ui-client": 14.0.0
"@rocket.chat/ui-contexts": 14.0.0
katex: "*"
react: "*"
languageName: unknown
Expand Down Expand Up @@ -9234,7 +9234,7 @@ __metadata:
typescript: "npm:~5.7.2"
peerDependencies:
"@rocket.chat/fuselage": "*"
"@rocket.chat/ui-contexts": 14.0.0-rc.3
"@rocket.chat/ui-contexts": 14.0.0
react: ~17.0.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -9284,8 +9284,8 @@ __metadata:
"@rocket.chat/fuselage": "*"
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/icons": "*"
"@rocket.chat/ui-avatar": 10.0.0-rc.3
"@rocket.chat/ui-contexts": 14.0.0-rc.3
"@rocket.chat/ui-avatar": 10.0.0
"@rocket.chat/ui-contexts": 14.0.0
react: "*"
react-i18next: "*"
languageName: unknown
Expand Down Expand Up @@ -9455,8 +9455,8 @@ __metadata:
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/icons": "*"
"@rocket.chat/styled": "*"
"@rocket.chat/ui-avatar": 10.0.0-rc.3
"@rocket.chat/ui-contexts": 14.0.0-rc.3
"@rocket.chat/ui-avatar": 10.0.0
"@rocket.chat/ui-contexts": 14.0.0
react: ~17.0.2
react-dom: ^17.0.2
languageName: unknown
Expand Down Expand Up @@ -9512,9 +9512,9 @@ __metadata:
"@rocket.chat/fuselage-hooks": "*"
"@rocket.chat/icons": "*"
"@rocket.chat/styled": "*"
"@rocket.chat/ui-avatar": 10.0.0-rc.3
"@rocket.chat/ui-client": 14.0.0-rc.3
"@rocket.chat/ui-contexts": 14.0.0-rc.3
"@rocket.chat/ui-avatar": 10.0.0
"@rocket.chat/ui-client": 14.0.0
"@rocket.chat/ui-contexts": 14.0.0
react: ~17.0.2
react-aria: ~3.23.1
react-dom: ^17.0.2
Expand Down Expand Up @@ -9602,7 +9602,7 @@ __metadata:
peerDependencies:
"@rocket.chat/layout": "*"
"@rocket.chat/tools": 0.2.2
"@rocket.chat/ui-contexts": 14.0.0-rc.3
"@rocket.chat/ui-contexts": 14.0.0
"@tanstack/react-query": "*"
react: "*"
react-hook-form: "*"
Expand Down

0 comments on commit 00da4b2

Please sign in to comment.