Skip to content

chore: correctly return server default notification preference when value is false#39142

Merged
dionisio-bot[bot] merged 2 commits intoRocketChat:developfrom
sahillllllllll-bit:fix-user-notification-preference-default
Mar 3, 2026
Merged

chore: correctly return server default notification preference when value is false#39142
dionisio-bot[bot] merged 2 commits intoRocketChat:developfrom
sahillllllllll-bit:fix-user-notification-preference-default

Conversation

@sahillllllllll-bit
Copy link
Copy Markdown
Contributor

@sahillllllllll-bit sahillllllllll-bit commented Feb 27, 2026

Problem

getUserNotificationPreference checks server defaults using:

if (serverValue)

This ignores valid falsy values such as false and 0.
As a result, when an admin sets Desktop Notifications default to Disabled, the API returns null/undefined instead of the configured default.

Reproduction

  1. Administration → Accounts → Default User Preferences
  2. Set Desktop Notifications = Disabled
  3. Call /api/v1/users.getPreferences

Solution

Check for undefined instead of truthiness:

typeof serverValue !== 'undefined'

This preserves valid falsy configuration values.

Impact

Ensures server default notification settings are respected and correctly returned by the API.

COMM-144

Summary by CodeRabbit

  • Bug Fixes
    • Fixed notification preference handling to properly recognize and apply certain preference settings that were previously being disregarded due to how values were evaluated.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Feb 27, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 27, 2026

⚠️ No Changeset found

Latest commit: fb253d5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 27, 2026

Walkthrough

The change replaces a truthy check with an explicit undefined check in a notification preference utility function. This allows falsy server values (0, '', false) to be returned as valid server-derived preferences instead of being treated as absent.

Changes

Cohort / File(s) Summary
Notification Preference Logic
apps/meteor/app/utils/server/getUserNotificationPreference.ts
Changed conditional from truthy check to explicit undefined check for serverValue, allowing falsy values like 0, empty string, and false to be recognized as valid server-provided preferences.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: replacing a truthy check with an explicit undefined check to properly return false as a valid server default notification preference.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 27, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the actual file to see the complete implementation
cat apps/meteor/app/utils/server/getUserNotificationPreference.ts

Length of output: 1217


🏁 Script executed:

#!/bin/bash
# Look at the git diff to see exactly what changed
git diff develop..HEAD -- apps/meteor/app/utils/server/getUserNotificationPreference.ts

Length of output: 631


🏁 Script executed:

#!/bin/bash
# Find where this function is used to understand the context
rg -n "getUserNotificationPreference" --type=ts -C 2

Length of output: 1768


🏁 Script executed:

#!/bin/bash
# Check if there are tests for this function
fd -e ts -e js getUserNotificationPreference test

Length of output: 91


🏁 Script executed:

#!/bin/bash
# Search for test files more broadly
fd -e spec.ts -e test.ts getUserNotificationPreference

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check what values the settings can have for notification preferences
rg -n "Accounts_Default_User_Preferences" --type=ts -C 2

Length of output: 25266


🏁 Script executed:

#!/bin/bash
# Look for any related tests in the push-notifications area
fd -e spec.ts -e test.ts . apps/meteor/app/push-notifications

Length of output: 0


@sahillllllllll-bit Yes, the fix is valid and good! Here's my analysis:

✅ The Fix is Correct

What Changed:

// Before
if (serverValue)

// After  
if (typeof serverValue !== 'undefined')

Why It's Better:

  1. Handles Falsy Values Correctly: The old truthy check (if (serverValue)) incorrectly rejected valid falsy values like:

    • false - which represents "Disabled" notifications
    • 0 - valid for numeric settings
    • '' - potentially valid for string settings
  2. Consistent with Existing Pattern: Your fix matches how user preferences are already checked on line 35:

    typeof user.settings.preferences[preferenceKey] !== 'undefined'
  3. Solves the Reported Bug: When an admin sets "Desktop Notifications = Disabled", the setting has a value (likely false or 'nothing'), but the old code treated it as absent, returning null instead of the configured default.

  4. Proper Undefined Handling: The new check correctly distinguishes between:

    • No setting configured (undefined) → returns null
    • Setting explicitly set to falsy value → returns the value ✓

Settings Context

From the codebase, notification preferences can be:

  • desktopNotifications: 'all', 'mentions', 'nothing'
  • pushNotifications: 'all', 'mentions', 'nothing'
  • Boolean flags: true / false

All of these are now properly handled. Great catch on this bug! 🎯

@KevLehman KevLehman added the valid A valid contribution where maintainers will review based on priority label Feb 27, 2026
@sahillllllllll-bit
Copy link
Copy Markdown
Contributor Author

@KevLehman please take a look at this if you have time , thankyou :)

@KevLehman KevLehman changed the title fix(utils): correctly return server default notification preference when value is false chore: correctly return server default notification preference when value is false Mar 2, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.72%. Comparing base (d8baf39) to head (fb253d5).
⚠️ Report is 51 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #39142      +/-   ##
===========================================
+ Coverage    70.71%   70.72%   +0.01%     
===========================================
  Files         3195     3195              
  Lines       113095   113095              
  Branches     20498    20489       -9     
===========================================
+ Hits         79970    79986      +16     
+ Misses       31082    31059      -23     
- Partials      2043     2050       +7     
Flag Coverage Δ
e2e 60.35% <ø> (-0.03%) ⬇️
e2e-api 48.87% <ø> (+1.10%) ⬆️
unit 71.35% <ø> (-0.03%) ⬇️

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.

@KevLehman KevLehman added this to the 8.3.0 milestone Mar 2, 2026
@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Mar 2, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Mar 2, 2026
@dionisio-bot dionisio-bot bot enabled auto-merge March 2, 2026 19:13
@dionisio-bot dionisio-bot bot added this pull request to the merge queue Mar 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 2, 2026
@KevLehman KevLehman removed the stat: QA assured Means it has been tested and approved by a company insider label Mar 2, 2026
@dionisio-bot dionisio-bot bot removed the stat: ready to merge PR tested and approved waiting for merge label Mar 2, 2026
@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Mar 2, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Mar 2, 2026
@dionisio-bot dionisio-bot bot added this pull request to the merge queue Mar 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 2, 2026
@KevLehman KevLehman removed the stat: QA assured Means it has been tested and approved by a company insider label Mar 3, 2026
@dionisio-bot dionisio-bot bot removed the stat: ready to merge PR tested and approved waiting for merge label Mar 3, 2026
@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Mar 3, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Mar 3, 2026
@dionisio-bot dionisio-bot bot added this pull request to the merge queue Mar 3, 2026
Merged via the queue into RocketChat:develop with commit 7c796b8 Mar 3, 2026
55 checks passed
ggazzo pushed a commit that referenced this pull request Mar 3, 2026
TheRazorbill pushed a commit to TheRazorbill/Rocket.Chat that referenced this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community 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 type: bug valid A valid contribution where maintainers will review based on priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants