Skip to content

fix: presence not updating after app resumes from background#7120

Merged
Rohit3523 merged 33 commits intodevelopfrom
presence-fix
Apr 23, 2026
Merged

fix: presence not updating after app resumes from background#7120
Rohit3523 merged 33 commits intodevelopfrom
presence-fix

Conversation

@Rohit3523
Copy link
Copy Markdown
Member

@Rohit3523 Rohit3523 commented Apr 9, 2026

Proposed changes

The app fails to fetch the latest user presence after returning from the background, resulting in outdated status being displayed.

Issue(s)

https://rocketchat.atlassian.net/browse/PRES-13

How to test or reproduce

  1. Log in as User A on the web and set the status to Online
  2. Log in as User B on mobile
  3. Wait until the app syncs all the data
  4. Move the app to the background
  5. Wait 30 seconds, then change User A status to Busy
  6. Wait another 30 seconds
  7. Open the app from the background
  8. It should display User A status as Busy

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

  • New Features

    • Automatic refresh of presence for direct message conversations during user login.
  • Bug Fixes

    • Presence requests are skipped when server presence broadcasting is disabled.
  • Reliability

    • Improved error handling for DM presence refresh so failures are logged and won’t interrupt login flow.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 9, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds DM-specific presence refresh: queries local DB for open, unarchived direct-message subscriptions to collect user IDs, short-circuits presence requests when settings.Presence_broadcast_disabled is true, and triggers DM presence refresh during login.

Changes

Cohort / File(s) Summary
DM Presence logic
app/lib/methods/getUsersPresence.ts
Added getDirectMessageUserIds() (WatermelonDB query for open, unarchived DMs; collect, filter, de-duplicate user IDs; returns [] on error). Added refreshDmUsersPresence() (calls getDirectMessageUserIds() and invokes getUsersPresence() if IDs exist). getUsersPresence() now returns early when settings.Presence_broadcast_disabled is truthy. Exports updated accordingly.
Login saga integration
app/sagas/login.js
Imported refreshDmUsersPresence() and invoked it from fetchUsersPresenceFork after subscribeUsersPresence() within the same try/catch; errors remain logged.

Sequence Diagram(s)

sequenceDiagram
    participant LoginSaga as Login Saga
    participant PresenceLib as Presence Library
    participant DB as WatermelonDB
    participant SDK as Server SDK

    LoginSaga->>PresenceLib: subscribeUsersPresence()
    PresenceLib-->>LoginSaga: subscribed

    LoginSaga->>PresenceLib: refreshDmUsersPresence()
    PresenceLib->>DB: query subscriptions (t='d', open=true, archived=false)
    DB-->>PresenceLib: DM subscription records
    PresenceLib->>PresenceLib: extract, filter, dedupe user IDs
    alt user IDs non-empty
        PresenceLib->>SDK: getUsersPresence(ids)
        SDK-->>PresenceLib: presence data
    end
    PresenceLib-->>LoginSaga: refresh complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 fix: presence not updating after app resumes from background, which is directly addressed by the changes that refresh DM user presence when the app comes to the foreground.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • PRES-13: Request failed with status code 401

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_android_build April 9, 2026 20:49 — with GitHub Actions Waiting
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build April 9, 2026 20:49 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build April 9, 2026 20:49 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build April 9, 2026 23:27 — with GitHub Actions Error
@Rohit3523 Rohit3523 temporarily deployed to experimental_android_build April 9, 2026 23:27 — with GitHub Actions Inactive
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build April 9, 2026 23:27 — with GitHub Actions Error
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: 3

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

Inline comments:
In `@app/containers/Status/index.tsx`:
- Around line 23-28: The effect currently calls getUserPresence(id) on every
mount when connected which causes duplicate enqueues during virtualized
remounts; restore a guard that only fetches on actual reconnects (e.g., re-add
the statusState === 'loading' check used before) or add deduping inside
getUserPresence/batching logic so repeated id enqueues are ignored; update the
useEffect (referencing useEffect, connected, id, status/statusState) to only
call getUserPresence when connection state transitions to connected or
statusState indicates an initial load, or modify getUserPresence to check an
in-flight set and skip enqueueing duplicate ids.

In `@app/lib/methods/getUsersPresence.ts`:
- Around line 159-167: The helper refreshDmUsersPresence currently swallows all
errors, preventing callers in app/sagas/login.js and app/sagas/state.js from
seeing failures; change it to either rethrow the caught error or log it before
returning — specifically update refreshDmUsersPresence (which calls
getDirectMessageUserIds() and getUsersPresence(dmUserIds)) so that in the catch
block you either throw the error (allowing the saga callers to handle/log it) or
call the shared logger (e.g., processLogger or the project's logging utility)
with the error and contextual message, rather than silently ignoring it.
- Around line 145-153: getDirectMessageUserIds currently picks sub.uids?.[0]
which may be the logged-in user; change getDirectMessageUserIds so for each
subscription (subscriptions / sub.uids) you find the peer id by excluding the
current user's id (e.g. obtain currentUserId via Meteor.userId() or the existing
auth helper) and selecting the remaining uid (for DMs, the other participant),
then collect and dedupe those peer ids instead of using uids[0]; ensure to
handle cases where uids may have multiple entries or missing values by filtering
falsy values before deduping.
🪄 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: d76acab2-b30d-45c0-8569-84d7dad3fa1a

📥 Commits

Reviewing files that changed from the base of the PR and between cb0feee and fc95fa4.

📒 Files selected for processing (4)
  • app/containers/Status/index.tsx
  • app/lib/methods/getUsersPresence.ts
  • app/sagas/login.js
  • app/sagas/state.js
📜 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: ESLint and Test / run-eslint-and-test
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{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/containers/Status/index.tsx
  • app/sagas/login.js
  • app/sagas/state.js
  • app/lib/methods/getUsersPresence.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/containers/Status/index.tsx
  • app/sagas/login.js
  • app/sagas/state.js
  • app/lib/methods/getUsersPresence.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/containers/Status/index.tsx
  • app/lib/methods/getUsersPresence.ts
app/containers/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Place reusable UI components in app/containers/ directory

Files:

  • app/containers/Status/index.tsx
**/*.{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/containers/Status/index.tsx
  • app/sagas/login.js
  • app/sagas/state.js
  • app/lib/methods/getUsersPresence.ts
🧠 Learnings (5)
📚 Learning: 2026-04-07T17:49:17.538Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to app/AppContainer.tsx : Implement root navigation container logic in app/AppContainer.tsx to switch between authentication states

Applied to files:

  • app/containers/Status/index.tsx
📚 Learning: 2026-03-10T15:21:45.098Z
Learnt from: Rohit3523
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7046
File: app/containers/InAppNotification/NotifierComponent.stories.tsx:46-75
Timestamp: 2026-03-10T15:21:45.098Z
Learning: In `app/containers/InAppNotification/NotifierComponent.tsx` (React Native, Rocket.Chat), `NotifierComponent` is exported as a Redux-connected component via `connect(mapStateToProps)`. The `isMasterDetail` prop is automatically injected from `state.app.isMasterDetail` and does not need to be passed explicitly at call sites or in Storybook stories that use the default (connected) export.

Applied to files:

  • app/containers/Status/index.tsx
  • app/lib/methods/getUsersPresence.ts
📚 Learning: 2026-04-07T17:49:17.538Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to app/sagas/**/*.{ts,tsx} : Place Redux sagas in app/sagas/ directory with separate files for init, login, rooms, messages, encryption, deepLinking, and videoConf side effects

Applied to files:

  • app/sagas/login.js
  • app/sagas/state.js
📚 Learning: 2026-04-07T17:49:17.538Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to app/lib/store/**/*.{ts,tsx} : Configure Redux store in app/lib/store/ with middleware for saga, app state, and internet state

Applied to files:

  • app/sagas/state.js
📚 Learning: 2026-04-07T17:49:17.538Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to @(app/sagas/videoConf.ts|app/lib/methods/videoConf.ts) : Manage video conferencing via Redux actions/reducers/sagas in app/sagas/videoConf.ts and app/lib/methods/videoConf.ts using server-managed Jitsi integration; do not conflate with VoIP

Applied to files:

  • app/sagas/state.js
🔇 Additional comments (1)
app/sagas/state.js (1)

75-84: ⚠️ Potential issue | 🟠 Major

Guard the reconnect resubscribe path against duplicate subscriptions.

handleMeteorConnect() runs on every METEOR.SUCCESS (app/sagas/state.js:92) and unconditionally calls subscribeUsersPresence(), which issues multiple sdk.subscribe() calls without any guard or unsubscribe logic. Reconnect flaps will accumulate duplicate presence subscriptions. Add a flag to track subscription state or explicitly unsubscribe before resubscribing to prevent duplicate stream events.

⛔ Skipped due to learnings
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to app/lib/services/sdk.ts : Use Rocket.Chat JS SDK in app/lib/services/sdk.ts for WebSocket real-time subscriptions

Comment thread app/containers/Status/index.tsx Outdated
Comment thread app/lib/methods/getUsersPresence.ts
Comment thread app/lib/methods/getUsersPresence.ts
@Rohit3523
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 9, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

♻️ Duplicate comments (1)
app/lib/methods/getUsersPresence.ts (1)

158-160: ⚠️ Potential issue | 🟠 Major

Don’t silently swallow DB/query failures in DM ID lookup.

Line 159 returns [] on errors, which hides failures and bypasses the logging path in refreshDmUsersPresence (Line 170). Let the error bubble or log it here with context.

Suggested fix (bubble to caller logger)
 	} catch (e) {
-		return [];
+		throw e;
 	}
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/lib/methods/getUsersPresence.ts` around lines 158 - 160, In
getUsersPresence.ts the catch block that returns [] silently swallows DB/query
failures; change the catch in the async function (the block around "} catch (e)
{ return []; }") to either log the error with context (including the query/DM
id) and then rethrow, or simply rethrow the original error so
refreshDmUsersPresence can handle/log it; do not return an empty array on
exceptions—use throw e or throw new Error(`getUsersPresence failed for ${dmId}:
${e.message}`) so refreshDmUsersPresence's logger sees the failure.
🧹 Nitpick comments (1)
app/lib/methods/getUsersPresence.ts (1)

149-156: Guard early when loggedUserId is unavailable.

If loggedUserId is missing on Line 149, Line 155 can pick an arbitrary UID and request the wrong presence target. Consider short-circuiting before mapping subscriptions.

Suggested tweak
 export const getDirectMessageUserIds = async (): Promise<string[]> => {
 	try {
 		const db = database.active;
 		const loggedUserId = reduxStore.getState().login.user?.id;
+		if (!loggedUserId) {
+			return [];
+		}
 		const subscriptionsCollection = db.get('subscriptions');
 		const subscriptions = await subscriptionsCollection
 			.query(Q.where('t', 'd'), Q.where('open', true), Q.where('archived', false))
 			.fetch();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/lib/methods/getUsersPresence.ts` around lines 149 - 156, Guard against a
missing loggedUserId by short-circuiting before processing subscriptions: check
reduxStore.getState().login.user?.id (loggedUserId) and if undefined/null return
an empty userIds result or skip the mapping logic that builds userIds from
subscriptionsCollection/subscriptions; this prevents the map in
subscriptions.map(...).find(...) from selecting arbitrary UIDs when loggedUserId
is unavailable and ensures functions that consume userIds receive a safe empty
array.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@app/lib/methods/getUsersPresence.ts`:
- Around line 158-160: In getUsersPresence.ts the catch block that returns []
silently swallows DB/query failures; change the catch in the async function (the
block around "} catch (e) { return []; }") to either log the error with context
(including the query/DM id) and then rethrow, or simply rethrow the original
error so refreshDmUsersPresence can handle/log it; do not return an empty array
on exceptions—use throw e or throw new Error(`getUsersPresence failed for
${dmId}: ${e.message}`) so refreshDmUsersPresence's logger sees the failure.

---

Nitpick comments:
In `@app/lib/methods/getUsersPresence.ts`:
- Around line 149-156: Guard against a missing loggedUserId by short-circuiting
before processing subscriptions: check reduxStore.getState().login.user?.id
(loggedUserId) and if undefined/null return an empty userIds result or skip the
mapping logic that builds userIds from subscriptionsCollection/subscriptions;
this prevents the map in subscriptions.map(...).find(...) from selecting
arbitrary UIDs when loggedUserId is unavailable and ensures functions that
consume userIds receive a safe empty array.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 09aa515c-81ae-4e56-a0ec-afde1f01e8b1

📥 Commits

Reviewing files that changed from the base of the PR and between fc95fa4 and baed9ed.

📒 Files selected for processing (1)
  • app/lib/methods/getUsersPresence.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/getUsersPresence.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/getUsersPresence.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/getUsersPresence.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/getUsersPresence.ts
🧠 Learnings (1)
📚 Learning: 2026-03-10T15:21:45.098Z
Learnt from: Rohit3523
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7046
File: app/containers/InAppNotification/NotifierComponent.stories.tsx:46-75
Timestamp: 2026-03-10T15:21:45.098Z
Learning: In `app/containers/InAppNotification/NotifierComponent.tsx` (React Native, Rocket.Chat), `NotifierComponent` is exported as a Redux-connected component via `connect(mapStateToProps)`. The `isMasterDetail` prop is automatically injected from `state.app.isMasterDetail` and does not need to be passed explicitly at call sites or in Storybook stories that use the default (connected) export.

Applied to files:

  • app/lib/methods/getUsersPresence.ts
🔇 Additional comments (2)
app/lib/methods/getUsersPresence.ts (2)

60-61: Good cache-busting addition for on-demand presence refresh.

Adding _t: Date.now() on Line 61 is a solid way to avoid stale users.presence responses for supported server versions.


163-171: Nice improvement adding error logging in foreground/login refresh flow.

The log(e) on Line 170 makes refresh failures diagnosable instead of fully silent.

@Rohit3523 Rohit3523 temporarily deployed to experimental_android_build April 10, 2026 00:12 — with GitHub Actions Inactive
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build April 10, 2026 00:12 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build April 16, 2026 21:49 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_android_build April 16, 2026 21:49 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build April 16, 2026 21:56 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_android_build April 16, 2026 21:56 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to experimental_ios_build April 16, 2026 21:56 — with GitHub Actions Error
@Rohit3523 Rohit3523 changed the title fix: fetch user presence when app come to foreground fix: presence not updating after app resumes from background Apr 16, 2026
@Rohit3523 Rohit3523 marked this pull request as ready for review April 21, 2026 12:19
Comment thread app/sagas/login.js
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.

♻️ Duplicate comments (2)
app/lib/methods/getUsersPresence.ts (2)

160-163: ⚠️ Potential issue | 🟡 Minor

Collect all non-self DM user IDs, not just the first one.

find drops additional non-self uids, so multi-user direct rooms can still show stale presence for skipped peers after resume.

Suggested fix
 		const userIds = subscriptions
-			.map((sub: { uids?: string[] }) => sub.uids?.find(uid => uid && uid !== loggedUserId))
-			.filter((uid): uid is string => Boolean(uid));
+			.flatMap((sub: { uids?: string[] }) => sub.uids ?? [])
+			.filter((uid): uid is string => Boolean(uid) && uid !== loggedUserId);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/lib/methods/getUsersPresence.ts` around lines 160 - 163, The current
mapping in getUsersPresence.ts uses .map(... .find(...)) which picks only the
first non-self uid per subscription, dropping other peers in multi-user DMs;
replace that logic so each subscription's uids array is iterated to collect all
uids !== loggedUserId (e.g., use .flatMap or map+flat and .filter(uid => uid &&
uid !== loggedUserId)) and then dedupe with new Set before returning; update the
userIds creation (the variable named userIds and the mapping over subscriptions)
to collect all non-self ids rather than the first match.

164-166: ⚠️ Potential issue | 🟡 Minor

Don’t hide subscription query failures from the refresh logger.

Returning [] here makes refreshDmUsersPresence look successful, so DB/query failures become invisible and the presence refresh silently does nothing.

Suggested fix
 	} catch (e) {
-		return [];
+		log(e);
+		return [];
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/lib/methods/getUsersPresence.ts` around lines 164 - 166, The catch in
getUsersPresence currently swallows all errors by returning [], which hides
subscription/query failures from refreshDmUsersPresence; instead, update
getUsersPresence's catch to log the caught error with context using the module's
logger (e.g., refreshLogger or the existing logger) and then rethrow the error
(or propagate it) so refreshDmUsersPresence can observe the failure and
handle/retry accordingly; ensure the log message includes the function name
"getUsersPresence" and the caught error details.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@app/lib/methods/getUsersPresence.ts`:
- Around line 160-163: The current mapping in getUsersPresence.ts uses .map(...
.find(...)) which picks only the first non-self uid per subscription, dropping
other peers in multi-user DMs; replace that logic so each subscription's uids
array is iterated to collect all uids !== loggedUserId (e.g., use .flatMap or
map+flat and .filter(uid => uid && uid !== loggedUserId)) and then dedupe with
new Set before returning; update the userIds creation (the variable named
userIds and the mapping over subscriptions) to collect all non-self ids rather
than the first match.
- Around line 164-166: The catch in getUsersPresence currently swallows all
errors by returning [], which hides subscription/query failures from
refreshDmUsersPresence; instead, update getUsersPresence's catch to log the
caught error with context using the module's logger (e.g., refreshLogger or the
existing logger) and then rethrow the error (or propagate it) so
refreshDmUsersPresence can observe the failure and handle/retry accordingly;
ensure the log message includes the function name "getUsersPresence" and the
caught error details.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59606381-d5e6-48ae-89ed-8bcf51444af4

📥 Commits

Reviewing files that changed from the base of the PR and between 1e19282 and a1d7cf4.

📒 Files selected for processing (1)
  • app/lib/methods/getUsersPresence.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). (2)
  • GitHub Check: ESLint and Test / run-eslint-and-test
  • GitHub Check: format
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{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/getUsersPresence.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{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

**/*.{ts,tsx}: Use TypeScript with strict mode enabled and baseUrl set to app/ for module imports
Support iOS 13.4+ and Android 6.0+ as minimum target platforms

Files:

  • app/lib/methods/getUsersPresence.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Use tabs for indentation with single quotes, 130 character line width, no trailing commas, and avoid arrow function parentheses when possible
Use ESLint with @rocket.chat/eslint-config base including React, React Native, TypeScript, and Jest plugins

Files:

  • app/lib/methods/getUsersPresence.ts
🧠 Learnings (1)
📚 Learning: 2026-03-10T15:21:45.098Z
Learnt from: Rohit3523
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7046
File: app/containers/InAppNotification/NotifierComponent.stories.tsx:46-75
Timestamp: 2026-03-10T15:21:45.098Z
Learning: In `app/containers/InAppNotification/NotifierComponent.tsx` (React Native, Rocket.Chat), `NotifierComponent` is exported as a Redux-connected component via `connect(mapStateToProps)`. The `isMasterDetail` prop is automatically injected from `state.app.isMasterDetail` and does not need to be passed explicitly at call sites or in Storybook stories that use the default (connected) export.

Applied to files:

  • app/lib/methods/getUsersPresence.ts

@Rohit3523 Rohit3523 had a problem deploying to experimental_android_build April 22, 2026 23:15 — with GitHub Actions Error
@Rohit3523 Rohit3523 had a problem deploying to official_android_build April 22, 2026 23:15 — with GitHub Actions Error
Comment thread app/lib/methods/getUsersPresence.ts Outdated
Copy link
Copy Markdown
Contributor

@OtavioStasiak OtavioStasiak left a comment

Choose a reason for hiding this comment

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

LGTM!
Run e2e tests and you can merge

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.

2 participants