chore(rest): migrate /api/v1/users.getPresence to OpenAPI endpoint definition#39503
chore(rest): migrate /api/v1/users.getPresence to OpenAPI endpoint definition#39503Yashika-code wants to merge 6 commits intoRocketChat:developfrom
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
WalkthroughMigrates the users.getPresence REST endpoint into the chained API.v1.get() routes with AJV/OpenAPI response validation; returns presence for other users and presence + connectionStatus + optional ISO lastLogin for the current user; removes the endpoint from rest-typings and adds a changeset. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ 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. Comment |
| .get( | ||
| 'users.getPresence', | ||
| { | ||
| authRequired: true, | ||
| response: { | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, |
There was a problem hiding this comment.
the query are missing. where it's?
| return API.v1.success({ | ||
| presence: (user?.status || 'offline') as 'online' | 'offline' | 'away' | 'busy', | ||
| connectionStatus: (user?.statusConnection || 'offline') as 'online' | 'offline' | 'away' | 'busy', | ||
| ...(user?.lastLogin && { lastLogin: user.lastLogin.toISOString() }), | ||
| }); | ||
| } |
There was a problem hiding this comment.
why did you change this?
There was a problem hiding this comment.
Thanks for the review!
- Added the missing query schema since the endpoint relies on getUserFromParams(this.queryParams).
- Reverted the lastLogin change to keep the original behavior and avoid modifying the response during the OpenAPI migration.
Please let me know if anything else should be adjusted.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "@rocket.chat/meteor": patch | |||
There was a problem hiding this comment.
Thank you for this , I updated this in new commit.
🦋 Changeset detectedLatest commit: 1ff98b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
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 |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/meteor/app/api/server/v1/users.ts">
<violation number="1" location="apps/meteor/app/api/server/v1/users.ts:893">
P2: `users.getPresence` query schema is stricter than route helper semantics and now rejects the legacy `user` identifier, causing a breaking API behavior change.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
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/app/api/server/v1/users.ts`:
- Around line 922-925: The response currently returns a Date object in the
API.v1.success payload (see API.v1.success and the user?.lastLogin usage), which
violates the schema expecting a date-time string; change the spread expression
so that when user?.lastLogin exists it is converted to an ISO string (e.g.,
guard with user.lastLogin instanceof Date and use user.lastLogin.toISOString())
before returning so AJV validation receives a string.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e11c39f3-347b-4fac-9d67-fa98510a5cd0
📒 Files selected for processing (1)
apps/meteor/app/api/server/v1/users.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/app/api/server/v1/users.ts
🧠 Learnings (12)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
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:44.506Z
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-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: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-03-10T08:13:44.506Z
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:44.506Z
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.
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-02-24T19:09:01.522Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:01.522Z
Learning: In Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1, avoid introducing logic changes. Only perform scope-tight changes that preserve behavior; style-only cleanups (e.g., removing inline comments) may be deferred to follow-ups to keep the migration PR focused.
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2025-09-19T15:15:04.642Z
Learnt from: rodrigok
Repo: RocketChat/Rocket.Chat PR: 36991
File: apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts:219-221
Timestamp: 2025-09-19T15:15:04.642Z
Learning: The Federation_Matrix_homeserver_domain setting in apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts is part of the old federation system and is being deprecated/removed, so configuration issues with this setting should not be flagged for improvement.
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-03-03T11:11:48.541Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.
Applied to files:
apps/meteor/app/api/server/v1/users.ts
📚 Learning: 2026-02-23T17:53:06.802Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:06.802Z
Learning: During PR reviews that touch endpoint files under apps/meteor/app/api/server/v1, enforce strict scope: if a PR targets a specific endpoint (e.g., rooms.favorite), do not propose changes to unrelated endpoints (e.g., rooms.invite) unless maintainers explicitly request them. Focus feedback on the touched endpoint's behavior, API surface, and related tests; avoid broad cross-endpoint changes in the same PR unless requested.
Applied to files:
apps/meteor/app/api/server/v1/users.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/app/api/server/v1/users.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/app/api/server/v1/users.ts
| return API.v1.success({ | ||
| presence: (user?.status || 'offline') as 'online' | 'offline' | 'away' | 'busy', | ||
| connectionStatus: (user?.statusConnection || 'offline') as 'online' | 'offline' | 'away' | 'busy', | ||
| ...(user?.lastLogin && { lastLogin: user.lastLogin }), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Verify that lastLogin is stored as a Date-like field and inspect the migrated handler.
rg -n -C2 '\blastLogin\b.*\bDate\b' packages apps
sed -n '902,926p' apps/meteor/app/api/server/v1/users.ts
# Inspect the REST route infrastructure for response validation on returned handler payloads.
fd 'ApiClass.ts$|api.ts$|index.ts$' apps packages
rg -n -C4 'validate.*response|response.*validator|ajv\.compile|schema.*response' apps/meteor/app/api/server packagesRepository: RocketChat/Rocket.Chat
Length of output: 50379
Serialize lastLogin to ISO string before returning the validated response.
Line 925 returns a Date object, but the 200 schema declares lastLogin as a date-time string. AJV response validation would fail for requests that include lastLogin before JSON serialization occurs.
🛠️ Proposed fix
return API.v1.success({
presence: (user?.status || 'offline') as 'online' | 'offline' | 'away' | 'busy',
connectionStatus: (user?.statusConnection || 'offline') as 'online' | 'offline' | 'away' | 'busy',
- ...(user?.lastLogin && { lastLogin: user.lastLogin }),
+ ...(user?.lastLogin && { lastLogin: user.lastLogin.toISOString() }),
});📝 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.
| return API.v1.success({ | |
| presence: (user?.status || 'offline') as 'online' | 'offline' | 'away' | 'busy', | |
| connectionStatus: (user?.statusConnection || 'offline') as 'online' | 'offline' | 'away' | 'busy', | |
| ...(user?.lastLogin && { lastLogin: user.lastLogin }), | |
| return API.v1.success({ | |
| presence: (user?.status || 'offline') as 'online' | 'offline' | 'away' | 'busy', | |
| connectionStatus: (user?.statusConnection || 'offline') as 'online' | 'offline' | 'away' | 'busy', | |
| ...(user?.lastLogin && { lastLogin: user.lastLogin.toISOString() }), |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@apps/meteor/app/api/server/v1/users.ts` around lines 922 - 925, The response
currently returns a Date object in the API.v1.success payload (see
API.v1.success and the user?.lastLogin usage), which violates the schema
expecting a date-time string; change the spread expression so that when
user?.lastLogin exists it is converted to an ISO string (e.g., guard with
user.lastLogin instanceof Date and use user.lastLogin.toISOString()) before
returning so AJV validation receives a string.
|
@ahmed-n-abdeltwab I initially changed this because the new AJV response schema defines Would you prefer keeping the original behavior ( |
Migrates the
users.getPresenceREST API endpoint from the legacyAPI.v1.addRoutepattern to the new chainedAPI.v1.get()pattern with AJV response schema validation and OpenAPI documentation support.Endpoints migrated
users.getPresenceaddRoute.get()chainedArchitectural changes
API.v1.addRoute('users.getPresence', ...)with the new chained.get('users.getPresence', ...)method400,401error response schemas usingvalidateBadRequestErrorResponseandvalidateUnauthorizedErrorResponsepresence,connectionStatus, andlastLoginfieldsquery: undefinedexplicitly as per new pattern guidelinesconnectionStatusandlastLoginare optional — only returned for own user requestslastLoginserialized as ISO string for JSON compatibilityFiles changed
apps/meteor/app/api/server/v1/users.ts— Main migration.changeset/migrate-users-getPresence-openapi.md— Changeset entrypackages\rest-typings\src\v1\users.ts— Remove old manual typingRelated project
This continues the REST API migration effort described in the GSoC 2026 project: Replace old REST API definitions over the new API.
cc @diego-sampaio @ggazzo
This PR is part of the ongoing REST API migration effort tracked in RocketChat/Rocket.Chat-Open-API#150
Summary by CodeRabbit
API Updates
Documentation