Skip to content

Conversation

@juliajforesti
Copy link
Contributor

@juliajforesti juliajforesti commented Sep 23, 2025

Proposed changes (including videos or screenshots)

Ensures the formatted volume value is kept between 0 and 1

Issue(s)

Steps to test or reproduce

Further comments

CORE-1393

Summary by CodeRabbit

  • Bug Fixes
    • Volume values are clamped to 0–100 and normalized to a 0–1 scale to prevent overly loud or negative levels.
  • New Features
    • Exposed a dedicated volume-formatting utility for consistent use across the app.
  • Refactor
    • Consolidated sound-related utilities behind a single import surface for simpler consumption.
  • Tests
    • Added unit tests covering boundary and negative volume inputs.
  • Chores
    • Added a changeset for a patch release documenting the volume formatting behavior.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Sep 23, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is targeting the wrong base branch. It should target 7.12.0, but it targets 7.11.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Sep 23, 2025

🦋 Changeset detected

Latest commit: ed5567f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 42 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/federation-service Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

Extracts formatVolume into its own utility with clamping and normalization (0–100 → 0–1), adds unit tests, introduces a lib index that re-exports helpers and formatVolume, updates CustomSoundProvider imports to ./lib, and adds a changeset noting the patch and clamped volume behavior.

Changes

Cohort / File(s) Summary of Changes
Lib: formatVolume & tests
apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts, apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts
Add formatVolume utility that clamps input to [0,100], converts to 0–1 with two significant digits, and unit tests covering bounds and negative inputs.
Lib: helpers & index
apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts, apps/meteor/client/providers/CustomSoundProvider/lib/index.ts
Remove formatVolume export from helpers.ts; add index.ts re-exporting ./helpers and ./formatVolume as a consolidated entry point.
Provider import update
apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx
Change imports from ./lib/helpers to ./lib to consume the consolidated re-exports (defaultSounds, getCustomSoundURL, formatVolume).
Changeset
.changeset/spicy-crabs-complain.md
Add patch changeset for @rocket.chat/meteor noting that formatted volume is constrained between 0 and 1.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I nibble bytes and tidy sound,
Clamp the peaks so none confound;
From zero up to one they flow,
Two crisp digits, soft and low.
Hop hop—tests pass, the bundle’s bound. 🐇🔊

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit's high-level summary is enabled.
Title Check ✅ Passed The title clearly states the primary change of clamping the formatted volume within the 0 to 1 range, accurately summarizing the main fix in a concise and specific manner.
Linked Issues Check ✅ Passed The implementation of formatVolume clamps input to [0,100] before scaling to [0,1] and tests verify negative and over-limit inputs, directly fulfilling CORE-1393’s requirement to prevent values outside the allowable range.
Out of Scope Changes Check ✅ Passed All modifications relate solely to introducing and exposing the formatVolume utility, updating its import path, adding tests, and documenting the change, with no unrelated functionality added.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/custom-sound-volume

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 25e054c and ed5567f.

📒 Files selected for processing (1)
  • apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: 🔎 Code Check / TypeScript
  • GitHub Check: 🔎 Code Check / Code Lint
  • GitHub Check: 🔨 Test Storybook / Test Storybook
  • GitHub Check: 🔨 Test Unit / Unit Tests
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@juliajforesti juliajforesti force-pushed the fix/custom-sound-volume branch from 22b52f5 to 3924036 Compare September 23, 2025 17:47
@juliajforesti juliajforesti added this to the 7.12.0 milestone Sep 23, 2025
@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.41%. Comparing base (a25e88c) to head (ed5567f).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #37041      +/-   ##
===========================================
+ Coverage    67.37%   67.41%   +0.03%     
===========================================
  Files         3331     3330       -1     
  Lines       113519   113381     -138     
  Branches     20599    20710     +111     
===========================================
- Hits         76488    76434      -54     
+ Misses       34424    34345      -79     
+ Partials      2607     2602       -5     
Flag Coverage Δ
e2e 57.34% <100.00%> (+0.03%) ⬆️
unit 71.15% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@dougfabris dougfabris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some unit test

@juliajforesti juliajforesti marked this pull request as ready for review September 30, 2025 21:40
@juliajforesti juliajforesti requested a review from a team as a code owner September 30, 2025 21:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
.changeset/spicy-crabs-complain.md (1)

5-5: Tighten the note for clarity.

Spell out both the clamp and normalize, and punctuate.

-Ensures the formatted volume value is kept between 0 and 1
+Clamp volume preference to 0–100% and normalize to 0–1 when applying to audio elements.
apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts (1)

1-19: Exercise the public API and broaden edge‑case coverage.

  • Import via the lib entry point to test the public surface.
  • Add boundary and typical decimal cases; Infinity cases already behave well with current code.
  • If you adopt the non‑finite guard, add a NaN test (optional snippet below).
-import { formatVolume } from './formatVolume';
+import { formatVolume } from '.';
@@
 describe('formatVolume', () => {
@@
   it('returns 0 if volume is -10', () => {
     expect(formatVolume(-10)).toBe(0);
   });
+
+  it('returns 0 if volume is 0', () => {
+    expect(formatVolume(0)).toBe(0);
+  });
+
+  it('normalizes common decimals (percent inputs)', () => {
+    expect(formatVolume(33)).toBe(0.33);
+    expect(formatVolume(66)).toBe(0.66);
+  });
+
+  it('handles Infinity and -Infinity', () => {
+    expect(formatVolume(Number.POSITIVE_INFINITY)).toBe(1);
+    expect(formatVolume(Number.NEGATIVE_INFINITY)).toBe(0);
+  });
 });

Optional (only if you implement the non‑finite guard suggested in formatVolume.ts):

it('defaults to 1 when volume is NaN', () => {
  // @ts-expect-error intentional invalid input for runtime guard
  expect(formatVolume(NaN)).toBe(1);
});
apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx (1)

7-7: Import path change LGTM.

Re-export consolidation via ./lib is fine. Two small, optional follow-ups:

  • Precompute normalized volumes to avoid repeated calls and ensure consistent rounding (if any):
const normalizedNotificationsVolume = useMemo(() => formatVolume(notificationsSoundVolume), [notificationsSoundVolume]);
const normalizedVoipVolume = useMemo(() => formatVolume(voipRingerVolume), [voipRingerVolume]);

Then use normalizedNotificationsVolume/normalizedVoipVolume in contextValue.

  • Harden the play API against external misuse by clamping the provided volume (in case other callers pass arbitrary values):
const play = useEffectEvent((soundId: ICustomSound['_id'], { volume = 1, loop = false } = {}) => {
  // ...
  const vol = Math.max(0, Math.min(volume, 1));
  audio.volume = vol;
  // ...
});

Please confirm no external consumer calls play(...) with raw percentages; if they do, the clamp above becomes important.

apps/meteor/client/providers/CustomSoundProvider/lib/index.ts (1)

1-2: Consolidated public API looks good.

Star re-exports from helpers and formatVolume are fine. Consider updating nearby tests to import from '.' (see spec suggestion) to lock in this entry point.

apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts (1)

1-4: Simplify formatVolume: drop toPrecision, return full-resolution volume

  • In apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts, change:
-export const formatVolume = (volume: number) => {
-	const clamped = Math.max(0, Math.min(volume, 100));
-	return Number((clamped / 100).toPrecision(2));
-};
+export const formatVolume = (volume: number): number => {
+	const clamped = Math.max(0, Math.min(volume, 100));
+	return clamped / 100;
+};
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 411f130 and 25e054c.

📒 Files selected for processing (6)
  • .changeset/spicy-crabs-complain.md (1 hunks)
  • apps/meteor/client/providers/CustomSoundProvider/CustomSoundProvider.tsx (1 hunks)
  • apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts (1 hunks)
  • apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts (1 hunks)
  • apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts (0 hunks)
  • apps/meteor/client/providers/CustomSoundProvider/lib/index.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/meteor/client/providers/CustomSoundProvider/lib/helpers.ts
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.spec.ts (1)
apps/meteor/client/providers/CustomSoundProvider/lib/formatVolume.ts (1)
  • formatVolume (1-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: 🔨 Test Unit / Unit Tests
  • GitHub Check: 🔎 Code Check / Code Lint
  • GitHub Check: 🔨 Test Storybook / Test Storybook
  • GitHub Check: 🔎 Code Check / TypeScript
  • GitHub Check: 📦 Meteor Build - coverage
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build

Copy link
Member

@dougfabris dougfabris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dougfabris dougfabris added the stat: QA assured Means it has been tested and approved by a company insider label Oct 2, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Oct 2, 2025
@kodiakhq kodiakhq bot merged commit ae632f7 into develop Oct 3, 2025
50 checks passed
@kodiakhq kodiakhq bot deleted the fix/custom-sound-volume branch October 3, 2025 00:55
@coderabbitai coderabbitai bot mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants