fix: deeplinking fails to open group when group id is provided in link#7111
fix: deeplinking fails to open group when group id is provided in link#7111
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
app/lib/methods/canOpenRoom.ts (2)
45-54: Potential redundant API call for GROUP type.For
ERoomTypes.GROUPwithoutrid, the code now:
- Calls
getRoomByTypeAndName('p', name)at line 32- Then calls
groups.infowith{ roomName: name }at line 48This results in two API calls to fetch room information. Since you already have
result._idfrom line 32, consider reusing that data or passingroomIdto the info endpoint to avoid the redundant call.♻️ Suggested approach
// if it's a group we need to check if you can open if (type === ERoomTypes.GROUP) { try { const result = await getRoomByTypeAndName('p', name); // RC 0.61.0 // `@ts-ignore` await sdk.post(`${restTypes[type]}.open`, { roomId: result._id }); + // Return room info directly since we already have it + if (!rid) { + return { + ...result, + rid: result._id + }; + } } catch (e: any) { if (!(e.data && /is already open/.test(e.data.error))) { return false; } + // Room is already open, still need to fetch info if no rid } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/lib/methods/canOpenRoom.ts` around lines 45 - 54, The GROUP branch is making a redundant API call: you already fetch the group via getRoomByTypeAndName('p', name) (result._id) earlier, then call groups.info when rid is missing; update canOpenRoom to reuse the previously obtained room object or pass the roomId to the info endpoint instead of calling groups.info with roomName—specifically, modify the logic around getRoomByTypeAndName and the block handling ERoomTypes.GROUP so that if you have result._id (or a room object), you set room.rid = result._id and return that room directly (or call groups.info with { roomId: result._id } if more details are required), eliminating the extra groups.info call.
36-40: Error handling may mask failures fromgetRoomByTypeAndName.If
getRoomByTypeAndNamefails for reasons other than "room is already open" (e.g., room not found, network error), the code returnsfalseat line 38. This is likely correct behavior, but the error condition at line 37 only checks for the "already open" case fromsdk.post, not fromgetRoomByTypeAndName.If
getRoomByTypeAndNamethrows an error (e.g., room not found by name/ID), it will hit this catch block and returnfalse. This may be intentional, but consider whether a more specific error should be propagated or logged for debugging deeplink failures.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/lib/methods/canOpenRoom.ts` around lines 36 - 40, The catch currently around both getRoomByTypeAndName and sdk.post can swallow errors from getRoomByTypeAndName; split the error handling so getRoomByTypeAndName failures are not mistaken for the "already open" sdk.post case. Specifically, call getRoomByTypeAndName (the function) in its own try/catch and either propagate or log/return a distinct error for failures, then wrap only the sdk.post call in a try/catch that checks e.data && /is already open/ to return false; rethrow or surface other unexpected errors instead of returning false.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/lib/methods/canOpenRoom.ts`:
- Around line 45-54: The GROUP branch is making a redundant API call: you
already fetch the group via getRoomByTypeAndName('p', name) (result._id)
earlier, then call groups.info when rid is missing; update canOpenRoom to reuse
the previously obtained room object or pass the roomId to the info endpoint
instead of calling groups.info with roomName—specifically, modify the logic
around getRoomByTypeAndName and the block handling ERoomTypes.GROUP so that if
you have result._id (or a room object), you set room.rid = result._id and return
that room directly (or call groups.info with { roomId: result._id } if more
details are required), eliminating the extra groups.info call.
- Around line 36-40: The catch currently around both getRoomByTypeAndName and
sdk.post can swallow errors from getRoomByTypeAndName; split the error handling
so getRoomByTypeAndName failures are not mistaken for the "already open"
sdk.post case. Specifically, call getRoomByTypeAndName (the function) in its own
try/catch and either propagate or log/return a distinct error for failures, then
wrap only the sdk.post call in a try/catch that checks e.data && /is already
open/ to return false; rethrow or surface other unexpected errors instead of
returning false.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 43a644fe-331b-49fc-b446-7d4e57c30d05
📒 Files selected for processing (1)
app/lib/methods/canOpenRoom.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx,json}
📄 CodeRabbit inference engine (CLAUDE.md)
Configure Prettier with tabs, single quotes, 130 character width, no trailing commas, arrow parens avoid, and bracket same line
Files:
app/lib/methods/canOpenRoom.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use ESLint with
@rocket.chat/eslint-configbase configuration including React, React Native, TypeScript, and Jest plugins
Files:
app/lib/methods/canOpenRoom.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use TypeScript with strict mode enabled and configure baseUrl to app/ for import resolution
**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Prefer interfaces over type aliases for defining object shapes in TypeScript
Use enums for sets of related constants rather than magic strings or numbers
Files:
app/lib/methods/canOpenRoom.ts
**/*.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions
Files:
app/lib/methods/canOpenRoom.ts
🧠 Learnings (1)
📚 Learning: 2026-04-07T17:49:17.519Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.519Z
Learning: Applies to app/lib/database/model/**/*.{ts,tsx} : Place database models in app/lib/database/model/ for entities like Message, Room, Subscription, User, Thread, Upload, Server, CustomEmoji, Permission, and Role
Applied to files:
app/lib/methods/canOpenRoom.ts
🔇 Additional comments (1)
app/lib/methods/canOpenRoom.ts (1)
30-41: The fix may not fully address the PR objective whennameis actually a group ID.According to the PR objectives, the deeplink can contain either a group name or a group ID. The current implementation still passes
namedirectly togetRoomByTypeAndName('p', name). Ifnameis actually an ID (not a room name), this call might fail depending on how the API handles the parameter.Additionally, the magic string
'p'for the room type could benefit from a brief comment or constant.[raise_major_issue, request_verification]
#!/bin/bash # Description: Check how getRoomByTypeAndName is implemented and whether it can accept both IDs and names # Find the implementation of getRoomByTypeAndName ast-grep --pattern 'export function getRoomByTypeAndName($$$) { $$$ }' # Also search for its definition in restApi rg -n -A 20 'getRoomByTypeAndName' --type ts
Proposed changes
Issue(s)
https://rocketchat.atlassian.net/browse/CORE-1857
How to test or reproduce
Screenshots
Types of changes
Checklist
Further comments
Summary by CodeRabbit