Skip to content

fix: Handle string boolean parameter in loadSurroundingMessages (#40119)#40193

Open
manaswi-siripurapu wants to merge 2 commits intoRocketChat:developfrom
manaswi-siripurapu:fix/40119
Open

fix: Handle string boolean parameter in loadSurroundingMessages (#40119)#40193
manaswi-siripurapu wants to merge 2 commits intoRocketChat:developfrom
manaswi-siripurapu:fix/40119

Conversation

@manaswi-siripurapu
Copy link
Copy Markdown

@manaswi-siripurapu manaswi-siripurapu commented Apr 17, 2026

Proposed changes

Fixes #40119

Users on Android app v4.71.2 and Desktop app v4.14 experience crashes when loading surrounding messages due to showThreadMessages parameter being sent as a string instead of boolean.

Problem

Error: Match error: Expected boolean, got string

Solution

Added automatic coercion of string boolean values to proper booleans before validation:

  • Trims whitespace
  • Converts to lowercase
  • Parses "true" or "1" as true and anything else as false
  • Validates with strict type checking

Testing

  • Handles string inputs: "true", "false", "TRUE", "1", "0"
  • Backward compatible with boolean inputs
  • No regression in existing functionality

Closes #40119

Summary by CodeRabbit

  • Bug Fixes
    • Improved input handling for message loading parameters to accept and properly validate both string and boolean input formats.

@manaswi-siripurapu manaswi-siripurapu requested a review from a team as a code owner April 17, 2026 12:52
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Apr 17, 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 17, 2026

⚠️ No Changeset found

Latest commit: b37bcfb

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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 17, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ manaswi-siripurapu
❌ 23f2002791
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 17, 2026

Walkthrough

The change adds string-to-boolean coercion for the showThreadMessages parameter in the loadSurroundingMessages method before validation, handling cases where the client sends a string instead of boolean.

Changes

Cohort / File(s) Summary
String-to-Boolean Coercion
apps/meteor/server/methods/loadSurroundingMessages.ts
Added coercion logic to convert string values ('true', '1') to boolean for showThreadMessages parameter before validation check to resolve validation errors when clients send string values.

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 fix: handling string boolean parameters in loadSurroundingMessages, which is the main change in the pull request.
Linked Issues check ✅ Passed The pull request successfully implements the required fix for issue #40119 by adding string-to-boolean coercion for the showThreadMessages parameter, directly addressing the reported Match error.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the showThreadMessages parameter handling in loadSurroundingMessages, with no unrelated modifications introduced.
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

@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

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

🧹 Nitpick comments (1)
apps/meteor/server/methods/loadSurroundingMessages.ts (1)

14-17: Consider widening the declared showThreadMessages type to reflect accepted inputs.

The interface still advertises showThreadMessages?: boolean, yet the method now intentionally accepts string inputs from mobile/REST clients. If you intend to keep coercing strings, widen the DDP-client typing (e.g. showThreadMessages?: boolean | string) so typed callers aren't misled and the server contract matches the runtime behavior. Otherwise, if the canonical contract is truly boolean-only, the coercion is patching around a client bug — in that case a clearer server-side error (or fixing the offending client) may be preferable to silent coercion of arbitrary strings to false.

🤖 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 14 - 17,
The declared parameter type for showThreadMessages on loadSurroundingMessages is
too narrow (boolean) while the runtime accepts string inputs; update the method
signature to widen the type to showThreadMessages?: boolean | string (or another
union that reflects accepted inputs) so TypeScript callers match runtime
behavior, and ensure any existing internal coercion still handles string values
(e.g., in loadSurroundingMessages) or replace the coercion with a clear
validation error if you prefer enforcing boolean-only inputs.
🤖 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 32-37: Remove the inline comment and extract the string-to-boolean
coercion into a local variable (e.g. normalizedShowThreadMessages): detect if
showThreadMessages is a string, normalize/trim/lowercase it and set
normalizedShowThreadMessages to the boolean result, then use
normalizedShowThreadMessages in place of showThreadMessages for the subsequent
check(showThreadMessages, Boolean) and wherever showThreadMessages is referenced
later (e.g. the usages formerly at lines 73 and 90) to improve type clarity and
readability; leave the original showThreadMessages parameter unchanged.

---

Nitpick comments:
In `@apps/meteor/server/methods/loadSurroundingMessages.ts`:
- Around line 14-17: The declared parameter type for showThreadMessages on
loadSurroundingMessages is too narrow (boolean) while the runtime accepts string
inputs; update the method signature to widen the type to showThreadMessages?:
boolean | string (or another union that reflects accepted inputs) so TypeScript
callers match runtime behavior, and ensure any existing internal coercion still
handles string values (e.g., in loadSurroundingMessages) or replace the coercion
with a clear validation error if you prefer enforcing boolean-only inputs.
🪄 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: c0a8b54f-68da-4fda-8b41-89cb7ecab696

📥 Commits

Reviewing files that changed from the base of the PR and between df36a85 and a0f18bc.

📒 Files selected for processing (1)
  • apps/meteor/server/methods/loadSurroundingMessages.ts
📜 Review details
⏰ 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). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 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)
📚 Learning: 2026-03-20T13:51:23.302Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 39553
File: apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts:179-181
Timestamp: 2026-03-20T13:51:23.302Z
Learning: In `apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts`, the truthiness guards `...(integration.avatar && { avatar })`, `...(integration.emoji && { emoji })`, `...(integration.alias && { alias })`, and `...(integration.script && { script })` in the `$set` payload of `updateIncomingIntegration` are intentional. Empty-string values for these fields should NOT overwrite the stored value — only truthy values are persisted. Do not flag these as bugs preventing explicit clears.

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 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 +32 to 37
// Coerce string to boolean (common when parameters come from mobile/REST clients)
if (typeof showThreadMessages === 'string') {
showThreadMessages = showThreadMessages.trim().toLowerCase();
showThreadMessages = showThreadMessages === 'true' || showThreadMessages === '1';
}
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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm strict/noImplicitAny settings that would surface the narrowing-to-never issue.
fd -t f 'tsconfig*.json' apps/meteor | head -20 | xargs -I {} sh -c 'echo "=== {} ==="; cat {}'

Repository: RocketChat/Rocket.Chat

Length of output: 1448


🏁 Script executed:

cat -n apps/meteor/server/methods/loadSurroundingMessages.ts | head -100

Repository: RocketChat/Rocket.Chat

Length of output: 3381


🏁 Script executed:

rg "typeof.*===.*'string'" apps/meteor/server/methods --type ts -A 3 | head -50

Repository: RocketChat/Rocket.Chat

Length of output: 1045


🏁 Script executed:

rg "showThreadMessages" apps/meteor --type ts -B 2 -A 2 | head -60

Repository: RocketChat/Rocket.Chat

Length of output: 3852


🏁 Script executed:

cat -n apps/meteor/server/methods/loadHistory.ts | head -80

Repository: RocketChat/Rocket.Chat

Length of output: 2699


🏁 Script executed:

rg -A 30 "export.*loadMessageHistory\|function loadMessageHistory" apps/meteor/app/lib/server/functions/loadMessageHistory.ts | head -80

Repository: RocketChat/Rocket.Chat

Length of output: 48


🏁 Script executed:

find apps/meteor -name "*loadMessageHistory*" -type f

Repository: RocketChat/Rocket.Chat

Length of output: 124


🏁 Script executed:

cat -n apps/meteor/app/lib/server/functions/loadMessageHistory.ts | head -150

Repository: RocketChat/Rocket.Chat

Length of output: 3071


🏁 Script executed:

rg "findVisibleByRoomIdBeforeTimestamp|findVisibleByRoomIdAfterTimestamp" apps/meteor --type ts -B 2 -A 8 | grep -A 10 "showThreadMessages"

Repository: RocketChat/Rocket.Chat

Length of output: 2923


🏁 Script executed:

git log --oneline apps/meteor/server/methods/loadSurroundingMessages.ts | head -10

Repository: RocketChat/Rocket.Chat

Length of output: 137


🏁 Script executed:

git show a0f18bc623 --stat

Repository: RocketChat/Rocket.Chat

Length of output: 50379


🏁 Script executed:

git show a0f18bc623 -- apps/meteor/server/methods/loadSurroundingMessages.ts

Repository: RocketChat/Rocket.Chat

Length of output: 3283


🏁 Script executed:

cd apps/meteor && npx tsc --noEmit --skipLibCheck server/methods/loadSurroundingMessages.ts 2>&1 | head -30

Repository: RocketChat/Rocket.Chat

Length of output: 207


🏁 Script executed:

cd apps/meteor && npx tsc --noEmit 2>&1 | grep -A 5 "loadSurroundingMessages"

Repository: RocketChat/Rocket.Chat

Length of output: 48


🏁 Script executed:

rg "showThreadMessages" apps/meteor/server/methods --type ts -B 5 -A 10 | grep -A 15 "loadSurroundingMessages(message"

Repository: RocketChat/Rocket.Chat

Length of output: 1529


Remove inline comment; consider using a local variable for type clarity.

The inline comment on line 32 violates coding guidelines ("Avoid code comments in the implementation"). While the string-to-boolean coercion pattern is intentional and handles REST/mobile client inputs that send strings instead of booleans, extracting the normalization into a local variable would improve type safety and readability:

♻️ Optional refactor
-	async loadSurroundingMessages(message, limit = 50, showThreadMessages = true) {
+	async loadSurroundingMessages(message, limit = 50, showThreadMessages: unknown = true) {
 		check(message, Object);
 		check(limit, Number);
-		// Coerce string to boolean (common when parameters come from mobile/REST clients)
-		if (typeof showThreadMessages === 'string') {
-			showThreadMessages = showThreadMessages.trim().toLowerCase();
-			showThreadMessages = showThreadMessages === 'true' || showThreadMessages === '1';
-		}
-		check(showThreadMessages, Boolean);
+		const normalizedShowThreadMessages =
+			typeof showThreadMessages === 'string'
+				? ['true', '1'].includes(showThreadMessages.trim().toLowerCase())
+				: showThreadMessages;
+		check(normalizedShowThreadMessages, Boolean);

Then reference normalizedShowThreadMessages on lines 73 and 90.

🤖 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 32 - 37,
Remove the inline comment and extract the string-to-boolean coercion into a
local variable (e.g. normalizedShowThreadMessages): detect if showThreadMessages
is a string, normalize/trim/lowercase it and set normalizedShowThreadMessages to
the boolean result, then use normalizedShowThreadMessages in place of
showThreadMessages for the subsequent check(showThreadMessages, Boolean) and
wherever showThreadMessages is referenced later (e.g. the usages formerly at
lines 73 and 90) to improve type clarity and readability; leave the original
showThreadMessages parameter unchanged.

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'

3 participants