From 31ff0fec7e7aff0a404ee308bb7a485c0d259ebb Mon Sep 17 00:00:00 2001 From: juliajforesti Date: Tue, 23 Sep 2025 14:37:19 -0300 Subject: [PATCH 1/4] fix: keep formated volume between limits of 0 and 1 --- .../meteor/client/providers/CustomSoundProvider/lib/helpers.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts b/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts index a81e0bdb85115..c003a12d153ee 100644 --- a/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts +++ b/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts @@ -47,5 +47,6 @@ export const defaultSounds: ICustomSound[] = [ ]; export const formatVolume = (volume: number) => { - return Number((volume / 100).toPrecision(2)); + const clamped = Math.max(0, Math.min(volume, 100)); + return Number((clamped / 100).toPrecision(2)); }; From 39240362d6d83790ff09178a3a9823f6096d9e35 Mon Sep 17 00:00:00 2001 From: juliajforesti Date: Tue, 23 Sep 2025 14:47:10 -0300 Subject: [PATCH 2/4] chore: changeset --- .changeset/spicy-crabs-complain.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/spicy-crabs-complain.md diff --git a/.changeset/spicy-crabs-complain.md b/.changeset/spicy-crabs-complain.md new file mode 100644 index 0000000000000..11e6729cd3a53 --- /dev/null +++ b/.changeset/spicy-crabs-complain.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Ensures the formatted volume value is kept between 0 and 1 From e3a53f18ad5c9367969d1d9468ee9244932ee652 Mon Sep 17 00:00:00 2001 From: juliajforesti Date: Tue, 30 Sep 2025 18:39:08 -0300 Subject: [PATCH 3/4] chore: reorg files --- .../providers/CustomSoundProvider/CustomSoundProvider.tsx | 2 +- .../client/providers/CustomSoundProvider/lib/formatVolume.ts | 4 ++++ .../client/providers/CustomSoundProvider/lib/helpers.ts | 5 ----- .../meteor/client/providers/CustomSoundProvider/lib/index.ts | 2 ++ 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts create mode 100644 apps/meteor/client/providers/CustomSoundProvider/lib/index.ts diff --git a/apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx b/apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx index e06dd7a354a19..2d116f61012da 100644 --- a/apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx +++ b/apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx @@ -4,7 +4,7 @@ import { CustomSoundContext, useStream, useUserPreference } from '@rocket.chat/u import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useEffect, useMemo, useRef, type ReactNode } from 'react'; -import { defaultSounds, formatVolume, getCustomSoundURL } from './lib/helpers'; +import { defaultSounds, getCustomSoundURL, formatVolume } from './lib'; import { sdk } from '../../../app/utils/client/lib/SDKClient'; import { useUserSoundPreferences } from '../../hooks/useUserSoundPreferences'; diff --git a/apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts b/apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts new file mode 100644 index 0000000000000..2c5d77b3a5e8e --- /dev/null +++ b/apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts @@ -0,0 +1,4 @@ +export const formatVolume = (volume: number) => { + const clamped = Math.max(0, Math.min(volume, 100)); + return Number((clamped / 100).toPrecision(2)); +}; diff --git a/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts b/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts index c003a12d153ee..49cc0a14b6c81 100644 --- a/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts +++ b/apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts @@ -45,8 +45,3 @@ export const defaultSounds: ICustomSound[] = [ { _id: 'dialtone', name: 'Sound_Dialtone', extension: 'mp3', src: getAssetUrl('sounds/dialtone.mp3') }, { _id: 'ringtone', name: 'Sound_Ringtone', extension: 'mp3', src: getAssetUrl('sounds/ringtone.mp3') }, ]; - -export const formatVolume = (volume: number) => { - const clamped = Math.max(0, Math.min(volume, 100)); - return Number((clamped / 100).toPrecision(2)); -}; diff --git a/apps/meteor/client/providers/CustomSoundProvider/lib/index.ts b/apps/meteor/client/providers/CustomSoundProvider/lib/index.ts new file mode 100644 index 0000000000000..a0b17e56d8b1b --- /dev/null +++ b/apps/meteor/client/providers/CustomSoundProvider/lib/index.ts @@ -0,0 +1,2 @@ +export * from './helpers'; +export * from './formatVolume'; From 25e054c07b02b2dc5ca0d9ad206c80c010681e2e Mon Sep 17 00:00:00 2001 From: juliajforesti Date: Tue, 30 Sep 2025 18:39:23 -0300 Subject: [PATCH 4/4] test: add formatVolume tests --- .../lib/formatVolume.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts diff --git a/apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts b/apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts new file mode 100644 index 0000000000000..e437ac545bf19 --- /dev/null +++ b/apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts @@ -0,0 +1,19 @@ +import { formatVolume } from './formatVolume'; + +describe('formatVolume', () => { + it('returns 1 if volume is 100', () => { + expect(formatVolume(100)).toBe(1); + }); + + it('returns 1 if volume is 200', () => { + expect(formatVolume(200)).toBe(1); + }); + + it('returns 0.5 if volume is 50', () => { + expect(formatVolume(50)).toBe(0.5); + }); + + it('returns 0 if volume is -10', () => { + expect(formatVolume(-10)).toBe(0); + }); +});