Skip to content

fix: deeplinking fails to open group when group id is provided in link#7111

Draft
Rohit3523 wants to merge 1 commit intodevelopfrom
private-channel-deeplink-fail
Draft

fix: deeplinking fails to open group when group id is provided in link#7111
Rohit3523 wants to merge 1 commit intodevelopfrom
private-channel-deeplink-fail

Conversation

@Rohit3523
Copy link
Copy Markdown
Member

@Rohit3523 Rohit3523 commented Apr 7, 2026

Proposed changes

Issue(s)

https://rocketchat.atlassian.net/browse/CORE-1857

How to test or reproduce

Screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced group room opening to ensure correct room identification and more reliable access.

@Rohit3523 Rohit3523 requested a deployment to approve_e2e_testing April 7, 2026 22:39 — with GitHub Actions Waiting
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fe528220-b5ca-4df2-9fc3-d9ff289991f7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

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.

@Rohit3523 Rohit3523 requested a deployment to experimental_ios_build April 7, 2026 22:42 — with GitHub Actions Waiting
@Rohit3523 Rohit3523 requested a deployment to experimental_android_build April 7, 2026 22:42 — with GitHub Actions Waiting
@Rohit3523 Rohit3523 requested a deployment to official_android_build April 7, 2026 22:42 — with GitHub Actions Waiting
@Rohit3523 Rohit3523 requested a deployment to official_ios_build April 7, 2026 22:42 — with GitHub Actions Waiting
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.

🧹 Nitpick comments (2)
app/lib/methods/canOpenRoom.ts (2)

45-54: Potential redundant API call for GROUP type.

For ERoomTypes.GROUP without rid, the code now:

  1. Calls getRoomByTypeAndName('p', name) at line 32
  2. Then calls groups.info with { roomName: name } at line 48

This results in two API calls to fetch room information. Since you already have result._id from line 32, consider reusing that data or passing roomId to 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 from getRoomByTypeAndName.

If getRoomByTypeAndName fails for reasons other than "room is already open" (e.g., room not found, network error), the code returns false at line 38. This is likely correct behavior, but the error condition at line 37 only checks for the "already open" case from sdk.post, not from getRoomByTypeAndName.

If getRoomByTypeAndName throws an error (e.g., room not found by name/ID), it will hit this catch block and return false. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 87229ae and b0c8994.

📒 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-config base 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 when name is 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 name directly to getRoomByTypeAndName('p', name). If name is 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

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.

1 participant