Skip to content

fix: coerce boolean parameter in loadSurroundingMessages check#40162

Open
Kgupta62 wants to merge 2 commits into
RocketChat:developfrom
Kgupta62:fix/load-surrounding-messages-type
Open

fix: coerce boolean parameter in loadSurroundingMessages check#40162
Kgupta62 wants to merge 2 commits into
RocketChat:developfrom
Kgupta62:fix/load-surrounding-messages-type

Conversation

@Kgupta62
Copy link
Copy Markdown

@Kgupta62 Kgupta62 commented Apr 15, 2026

Fixes #40119

Problem

loadSurroundingMessages method throws Match error: Expected boolean, got string at line 32 because the showThreadMessages parameter arrives as a string instead of a boolean via DDP.

Changes

In apps/meteor/server/methods/loadSurroundingMessages.ts, added a type coercion before the check() call:

if (typeof showThreadMessages === 'string') {
    showThreadMessages = showThreadMessages === 'true';
}

This converts the string "true"/"false" to a proper boolean before Meteor's check(showThreadMessages, Boolean) runs.

AI Disclosure

  • I used an AI tool to help with this PR
    • Tool: Claude — used to find the file location. Fix was written by me.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of input formats when loading surrounding messages so the thread-display option is correctly interpreted (e.g., when provided as text), ensuring consistent behavior and accurate message context display.

@Kgupta62 Kgupta62 requested a review from a team as a code owner April 15, 2026 05:37
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Apr 15, 2026

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

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: c488033

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

This PR includes changesets to release 41 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/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/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac 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/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch 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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 15, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2936a94-5acf-468f-94ce-d8653470cf87

📥 Commits

Reviewing files that changed from the base of the PR and between e6d83d4 and c488033.

📒 Files selected for processing (1)
  • .changeset/fix-load-surrounding-type.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-load-surrounding-type.md

Walkthrough

The method loadSurroundingMessages now coerces the showThreadMessages parameter from a string to a boolean (treating the string 'true' as true) before performing the Boolean validation, preventing a Match error when clients send the value as a string.

Changes

Cohort / File(s) Summary
Parameter Type Coercion
apps/meteor/server/methods/loadSurroundingMessages.ts
Normalize showThreadMessages when it's a string by converting 'true' to true before check(..., Boolean), preventing type validation errors.
Release Notes / Changeset
.changeset/fix-load-surrounding-type.md
Add changeset entry marking a patch for @rocket.chat/meteor and documenting the fix for coercing showThreadMessages from string to boolean.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ 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 accurately describes the main change: coercing the showThreadMessages parameter to boolean before the Meteor check call.
Linked Issues check ✅ Passed The PR directly addresses issue #40119 by fixing the 'Match error: Expected boolean, got string' by coercing string values to boolean before validation.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the loadSurroundingMessages parameter validation issue; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/server/methods/loadSurroundingMessages.ts`:
- Around line 33-37: The code currently coerces any string to false which hides
malformed inputs; instead, in the loadSurroundingMessages logic handle only
explicit 'true' and 'false' strings: if showThreadMessages === 'true' set it to
true, else if showThreadMessages === 'false' set it to false, otherwise leave it
unchanged so the subsequent check(showThreadMessages, Boolean) will throw for
invalid values; update the conditional around the showThreadMessages variable
(the existing typeof showThreadMessages === 'string' branch) to implement this
explicit two-value coercion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dfb2b40f-992d-4973-8656-557e83119cf7

📥 Commits

Reviewing files that changed from the base of the PR and between 41f6662 and e6d83d4.

📒 Files selected for processing (1)
  • apps/meteor/server/methods/loadSurroundingMessages.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/server/methods/loadSurroundingMessages.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/methods/loadSurroundingMessages.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/methods/loadSurroundingMessages.ts
📚 Learning: 2026-03-09T18:39:14.020Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:14.020Z
Learning: When implementing batch processing in server methods, favor a single data pass to collect both the items and any derived fields needed for validation. Use the same dataset for both validation and processing to avoid races between validation and execution, and document the approach in code comments. Apply this pattern to similar Meteor Rocket.Chat server methods under apps/meteor/server/methods to prevent race conditions and ensure consistent batch behavior.

Applied to files:

  • apps/meteor/server/methods/loadSurroundingMessages.ts

Comment on lines +33 to 37
if (typeof showThreadMessages === 'string') {
showThreadMessages = showThreadMessages === 'true';
}

check(showThreadMessages, Boolean);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Do not coerce arbitrary strings to false.

Line 34 currently turns any non-'true' string into false, so malformed inputs (e.g., 'foo') silently pass validation on Line 37. Coerce only 'true'/'false' and let check reject anything else.

Suggested fix
-		if (typeof showThreadMessages === 'string') {
-			showThreadMessages = showThreadMessages === 'true';
-		}
+		if (typeof showThreadMessages === 'string') {
+			if (showThreadMessages === 'true') {
+				showThreadMessages = true;
+			} else if (showThreadMessages === 'false') {
+				showThreadMessages = false;
+			}
+		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (typeof showThreadMessages === 'string') {
showThreadMessages = showThreadMessages === 'true';
}
check(showThreadMessages, Boolean);
if (typeof showThreadMessages === 'string') {
if (showThreadMessages === 'true') {
showThreadMessages = true;
} else if (showThreadMessages === 'false') {
showThreadMessages = false;
}
}
check(showThreadMessages, Boolean);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/server/methods/loadSurroundingMessages.ts` around lines 33 - 37,
The code currently coerces any string to false which hides malformed inputs;
instead, in the loadSurroundingMessages logic handle only explicit 'true' and
'false' strings: if showThreadMessages === 'true' set it to true, else if
showThreadMessages === 'false' set it to false, otherwise leave it unchanged so
the subsequent check(showThreadMessages, Boolean) will throw for invalid values;
update the conditional around the showThreadMessages variable (the existing
typeof showThreadMessages === 'string' branch) to implement this explicit
two-value coercion.

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 coderabbitai Bot removed the type: bug label Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception while invoking method 'loadSurroundingMessages'

2 participants