Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

chore: Refactor/migrate insertMessage to service layer

Open krishiekrashie opened this issue 5 months ago • 5 comments

Proposed changes (including videos or screenshots)

Adds insertMessage to the IMessageService interface in @rocket.chat/core-services Implements the method on MessageService, delegating to the existing insertMessage function Removes the direct file import in MessageConverter in favour of consuming Message.insertMessage from @rocket.chat/core-services Updates the unit test stub to target the new @rocket.chat/core-services import path

Currently, MessageConverter was importing insertMessage directly from an internal function file, bypassing the service layer. This change routes the call through the IMessageService interface, consistent with how the rest of the codebase accesses message operations (e.g. Message.sendMessageWithValidation, Message.deleteMessage). It also fulfils the // TODO: remove and move to Message.Service note on the original function.

Issue(s)

#40943

Steps to test or reproduce

Existing unit tests in messageConverter.spec.ts pass with the updated stub path No TypeScript errors in the affected packages (core-services, apps/meteor)

Further comments

Review in cubic

Summary by CodeRabbit

  • Refactor
    • Routed imported message persistence through core services for more consistent message handling across the app.
    • Added a server-side message insertion method to the message service (supports optional upsert), used by the importer.
  • Tests
    • Updated unit test setup to stub the new core-service-based insertion flow.
  • Chores
    • Removed an obsolete TODO comment related to message insertion handling.

krishiekrashie avatar Jun 16 '26 01:06 krishiekrashie

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

dionisio-bot[bot] avatar Jun 16 '26 01:06 dionisio-bot[bot]

⚠️ No Changeset found

Latest commit: 98f42b4b03a88edb0802906a033f5048c9986791

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jun 16 '26 01:06 changeset-bot[bot]

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 16 '26 01:06 CLAassistant

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1d7cd346-9993-446c-9e43-46aad057a4b6

📥 Commits

Reviewing files that changed from the base of the PR and between 7d024295fd43282c0de938143f1b15fe0497c717 and 37c3aefad29179dc1d32af6b037b3e8ab5803922.

📒 Files selected for processing (5)
  • apps/meteor/app/importer/server/classes/converters/MessageConverter.ts
  • apps/meteor/app/lib/server/functions/insertMessage.ts
  • apps/meteor/server/services/messages/service.ts
  • apps/meteor/tests/unit/app/importer/server/messageConverter.spec.ts
  • packages/core-services/src/types/IMessageService.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/meteor/app/lib/server/functions/insertMessage.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/meteor/app/importer/server/classes/converters/MessageConverter.ts
  • apps/meteor/server/services/messages/service.ts
  • packages/core-services/src/types/IMessageService.ts
  • apps/meteor/tests/unit/app/importer/server/messageConverter.spec.ts
📜 Recent 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

Walkthrough

insertMessage is added to the IMessageService interface and implemented in MessageService as a delegating wrapper around the existing local helper. MessageConverter is then updated to call Message.insertMessage(...) from @rocket.chat/core-services instead of the local import, the unit test stub is updated to match, and the corresponding TODO comment is removed.

Changes

insertMessage service layer and MessageConverter migration

Layer / File(s) Summary
IMessageService contract and MessageService implementation
packages/core-services/src/types/IMessageService.ts, apps/meteor/server/services/messages/service.ts
Adds insertMessage(user, message, rid, upsert?) to IMessageService, imports the local insertMessage helper in MessageService, and exposes a public method that delegates to it.
MessageConverter call-site migration and test stub update
apps/meteor/app/importer/server/classes/converters/MessageConverter.ts, apps/meteor/tests/unit/app/importer/server/messageConverter.spec.ts, apps/meteor/app/lib/server/functions/insertMessage.ts
Removes the local insertMessage import from MessageConverter and replaces the call with Message.insertMessage(...) from @rocket.chat/core-services; updates the proxyquire stub to inject the mock via Message.insertMessage instead of the old path; removes the TODO comment documenting the completed migration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • RocketChat/Rocket.Chat#40943: This PR implements the refactoring described in the issue by migrating insertMessage from a direct local import in MessageConverter to the service layer via Message.insertMessage(...) from @rocket.chat/core-services, while adding the method to both the IMessageService interface and MessageService implementation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main refactoring: migrating insertMessage to the service layer, which aligns with the core changes across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.


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.

coderabbitai[bot] avatar Jun 16 '26 01:06 coderabbitai[bot]

Could maintainer please add required label or milestone. I don't have permission.

krishiekrashie avatar Jun 16 '26 01:06 krishiekrashie