refactor: call history search queries#40784
Conversation
|
Looks like this PR is ready to merge! 🎉 |
|
WalkthroughThis PR refactors the ChangesCall History Search Service
🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #40784 +/- ##
===========================================
- Coverage 69.75% 69.74% -0.01%
===========================================
Files 3330 3331 +1
Lines 123158 123168 +10
Branches 21972 21965 -7
===========================================
- Hits 85911 85909 -2
- Misses 33892 33896 +4
- Partials 3355 3363 +8
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core-services/src/types/ICallHistoryService.ts (1)
3-17: ⚖️ Poor tradeoffInline
filters/paginationshapes are duplicated across layers.The same structural types are redeclared in
ICallHistoryService,CallHistoryService.search,ICallHistoryModel.findAllByUserIdAndSearchFilters, andCallHistoryRaw. Extracting named types (e.g.CallHistorySearchFilters,CallHistoryPagination) would keep these in sync as the shape evolves.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/core-services/src/types/ICallHistoryService.ts` around lines 3 - 17, Extract the duplicated inline shapes into shared named types (e.g., declare CallHistorySearchFilters and CallHistoryPagination) and replace the inline definitions used in ICallHistoryService.search with those types; also update the matching signatures/usages in CallHistoryService.search, ICallHistoryModel.findAllByUserIdAndSearchFilters, and the CallHistoryRaw type to reference the new shared types so the shapes stay consistent across layers as they evolve.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/core-services/src/types/ICallHistoryService.ts`:
- Around line 3-17: Extract the duplicated inline shapes into shared named types
(e.g., declare CallHistorySearchFilters and CallHistoryPagination) and replace
the inline definitions used in ICallHistoryService.search with those types; also
update the matching signatures/usages in CallHistoryService.search,
ICallHistoryModel.findAllByUserIdAndSearchFilters, and the CallHistoryRaw type
to reference the new shared types so the shapes stay consistent across layers as
they evolve.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a6c0b4de-36f1-4aeb-87f9-1004a6870823
📒 Files selected for processing (7)
apps/meteor/app/api/server/v1/call-history.tsapps/meteor/server/services/call-history/service.tsapps/meteor/server/services/startup.tspackages/core-services/src/index.tspackages/core-services/src/types/ICallHistoryService.tspackages/model-typings/src/models/ICallHistoryModel.tspackages/models/src/models/CallHistory.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: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
🧰 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/services/startup.tspackages/core-services/src/types/ICallHistoryService.tspackages/model-typings/src/models/ICallHistoryModel.tspackages/core-services/src/index.tsapps/meteor/server/services/call-history/service.tsapps/meteor/app/api/server/v1/call-history.tspackages/models/src/models/CallHistory.ts
🧠 Learnings (17)
📓 Common learnings
Learnt from: pierre-lehnen-rc
Repo: RocketChat/Rocket.Chat PR: 36718
File: packages/media-signaling/src/lib/Call.ts:633-642
Timestamp: 2025-09-23T00:27:05.438Z
Learning: In PR `#36718`, pierre-lehnen-rc prefers to maintain consistency with the old architecture patterns for DTMF handling rather than implementing immediate validation improvements, deferring enhancements to future work.
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: apps/meteor/server/services/media-call/service.ts:141-141
Timestamp: 2025-11-19T18:20:37.116Z
Learning: In apps/meteor/server/services/media-call/service.ts, the sendHistoryMessage method should use call.caller.id or call.createdBy?.id as the message author, not call.transferredBy?.id. Even for transferred calls, the message should appear in the DM between the two users who are calling each other, not sent by the person who transferred the call.
📚 Learning: 2025-11-19T18:20:37.116Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: apps/meteor/server/services/media-call/service.ts:141-141
Timestamp: 2025-11-19T18:20:37.116Z
Learning: In apps/meteor/server/services/media-call/service.ts, the sendHistoryMessage method should use call.caller.id or call.createdBy?.id as the message author, not call.transferredBy?.id. Even for transferred calls, the message should appear in the DM between the two users who are calling each other, not sent by the person who transferred the call.
Applied to files:
apps/meteor/server/services/startup.tsapps/meteor/server/services/call-history/service.tsapps/meteor/app/api/server/v1/call-history.tspackages/models/src/models/CallHistory.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/services/startup.tspackages/core-services/src/types/ICallHistoryService.tspackages/model-typings/src/models/ICallHistoryModel.tspackages/core-services/src/index.tsapps/meteor/server/services/call-history/service.tsapps/meteor/app/api/server/v1/call-history.tspackages/models/src/models/CallHistory.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/services/startup.tspackages/core-services/src/types/ICallHistoryService.tspackages/model-typings/src/models/ICallHistoryModel.tspackages/core-services/src/index.tsapps/meteor/server/services/call-history/service.tsapps/meteor/app/api/server/v1/call-history.tspackages/models/src/models/CallHistory.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/server/services/startup.tspackages/core-services/src/types/ICallHistoryService.tspackages/model-typings/src/models/ICallHistoryModel.tspackages/core-services/src/index.tsapps/meteor/server/services/call-history/service.tsapps/meteor/app/api/server/v1/call-history.tspackages/models/src/models/CallHistory.ts
📚 Learning: 2025-12-18T15:18:31.688Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37773
File: apps/meteor/client/views/mediaCallHistory/MediaCallHistoryInternal.tsx:24-34
Timestamp: 2025-12-18T15:18:31.688Z
Learning: In apps/meteor/client/views/mediaCallHistory/MediaCallHistoryInternal.tsx, for internal call history items, the item.contactId is guaranteed to always match either the caller.id or callee.id in the call data, so the contact resolution in getContact will never result in undefined.
Applied to files:
packages/core-services/src/types/ICallHistoryService.tspackages/model-typings/src/models/ICallHistoryModel.tspackages/core-services/src/index.tsapps/meteor/server/services/call-history/service.tsapps/meteor/app/api/server/v1/call-history.tspackages/models/src/models/CallHistory.ts
📚 Learning: 2026-05-09T13:18:06.264Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 40274
File: packages/models/src/models/Users.ts:1104-1107
Timestamp: 2026-05-09T13:18:06.264Z
Learning: In `packages/models/src/models/Users.ts` (RocketChat/Rocket.Chat), `updatePresenceAndStatus` intentionally uses the `BaseRaw.findOneAndUpdate` wrapper (which updates `_updatedAt`) because the method performs real document mutations (status claims, previousState, statusExpiresAt, etc.). Only `updateStatusById` deliberately bypasses `_updatedAt` via `this.col.updateOne` — specifically to use `_updatedAt` as a change-detection sentinel, not as a general "avoid churn" policy. Do not flag `updatePresenceAndStatus` for using the wrapper.
Applied to files:
packages/model-typings/src/models/ICallHistoryModel.tspackages/models/src/models/CallHistory.ts
📚 Learning: 2026-02-26T19:22:36.646Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/views/CallHistoryContextualbar/CallHistoryActions.tsx:40-40
Timestamp: 2026-02-26T19:22:36.646Z
Learning: In packages/ui-voip/src/views/CallHistoryContextualbar/CallHistoryActions.tsx, when the media session state is 'unavailable', the voiceCall action is not included in the actions object passed to CallHistoryActions, so it won't appear in the menu at all. The action filtering happens upstream before getItems is called, preventing any tooltip confusion for the unavailable state.
Applied to files:
apps/meteor/server/services/call-history/service.tsapps/meteor/app/api/server/v1/call-history.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/call-history.ts
📚 Learning: 2026-04-23T18:10:55.887Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 39857
File: apps/meteor/app/api/server/middlewares/metrics.ts:25-57
Timestamp: 2026-04-23T18:10:55.887Z
Learning: In RocketChat/Rocket.Chat, the route handler action wrapper in `apps/meteor/app/api/server/ApiClass.ts` (around line 892) contains a `catch` block that intercepts all route-handler errors and converts them into proper HTTP API response objects (e.g., `api.failure`, `api.unauthorized`, `api.tooManyRequests`). As a result, `next()` in Hono middleware (such as `metricsMiddleware` in `apps/meteor/app/api/server/middlewares/metrics.ts`) will never throw. Do not flag missing try/finally guards around `await next()` calls in this middleware for gauge/counter decrement safety, as the execution flow is never disrupted by route-level errors.
Applied to files:
apps/meteor/app/api/server/v1/call-history.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/call-history.ts
📚 Learning: 2026-05-11T23:15:03.372Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 40469
File: packages/rest-typings/src/v1/users.ts:337-337
Timestamp: 2026-05-11T23:15:03.372Z
Learning: In RocketChat/Rocket.Chat, REST endpoint typings in `packages/rest-typings/src/v1/users.ts` (and broadly across the codebase) reference `IUser` field types directly (e.g. `IUser['statusExpiresAt']`) rather than serialized equivalents like `string`. Suggesting a change to serialized types (e.g. `string`) for a single field is inconsistent with this pattern; any such refactor should be done codebase-wide.
Applied to files:
packages/models/src/models/CallHistory.ts
📚 Learning: 2025-11-19T18:20:07.720Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: packages/i18n/src/locales/en.i18n.json:918-921
Timestamp: 2025-11-19T18:20:07.720Z
Learning: Repo: RocketChat/Rocket.Chat — i18n/formatting
Learning: This repository uses a custom message formatting parser in UI blocks/messages; do not assume standard Markdown rules. For keys like Call_ended_bold, Call_not_answered_bold, Call_failed_bold, and Call_transferred_bold in packages/i18n/src/locales/en.i18n.json, retain the existing single-asterisk emphasis unless maintainers request otherwise.
Applied to files:
packages/models/src/models/CallHistory.ts
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
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:
packages/models/src/models/CallHistory.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.
Applied to files:
packages/models/src/models/CallHistory.ts
📚 Learning: 2026-03-15T14:31:28.969Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39647
File: apps/meteor/app/api/server/v1/users.ts:710-757
Timestamp: 2026-03-15T14:31:28.969Z
Learning: In RocketChat/Rocket.Chat, the `UserCreateParamsPOST` type in `apps/meteor/app/api/server/v1/users.ts` (migrated from `packages/rest-typings/src/v1/users/UserCreateParamsPOST.ts`) intentionally has `fields: string` (non-optional) and `settings?: IUserSettings` without a corresponding AJV schema entry. This is a pre-existing divergence carried over verbatim from the original rest-typings source (PR `#39647`). Do not flag this type/schema misalignment during the OpenAPI migration review — it is tracked as a separate follow-up fix.
Applied to files:
packages/models/src/models/CallHistory.ts
📚 Learning: 2026-03-16T21:50:42.118Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:42.118Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs, removing endpoint types and validators from `rocket.chat/rest-typings` (e.g., `UserRegisterParamsPOST`, `/v1/users.register` entry) is the *required* migration pattern per RocketChat/Rocket.Chat-Open-API#150 Rule 7 ("No More rest-typings or Manual Typings"). The endpoint type is re-exposed via a module augmentation `.d.ts` file in the consuming package (e.g., `packages/web-ui-registration/src/users-register.d.ts`). This is NOT a breaking change — the correct changeset bump for `rocket.chat/rest-typings` in this scenario is `minor`, not `major`. Do not flag this as a breaking change during OpenAPI migration reviews.
Applied to files:
packages/models/src/models/CallHistory.ts
🔇 Additional comments (6)
packages/model-typings/src/models/ICallHistoryModel.ts (1)
19-28: LGTM!packages/core-services/src/index.ts (1)
11-11: LGTM!Also applies to: 147-147, 183-183
apps/meteor/server/services/call-history/service.ts (1)
5-39: LGTM!apps/meteor/app/api/server/v1/call-history.ts (1)
107-117: LGTM!apps/meteor/server/services/startup.ts (1)
12-12: LGTM!Also applies to: 63-63
packages/models/src/models/CallHistory.ts (1)
51-88:CallHistory.ts$orfields matchCallHistoryItemtypings
packages/core-typings/src/ICallHistoryItem.tsmodelsexternalas the discriminant: forexternal: falseit defines optionalcontactName/contactUsername, and forexternal: trueit definescontactExtension: string. The query branches infindAllByUserIdAndSearchFiltersusingexternal,contactUsername,contactExtension, andcontactNamealign withFilter<CallHistoryItem>typing.
Proposed changes (including videos or screenshots)
Issue(s)
Derived from DMV-7
Steps to test or reproduce
Further comments
Summary by CodeRabbit