Skip to content

Conversation

@MarcosSpessatto
Copy link
Contributor

@MarcosSpessatto MarcosSpessatto commented Apr 17, 2025

https://rocketchat.atlassian.net/browse/ARCH-1581

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments


This pull request refactors the Rocket.Chat server code by removing direct Meteor method calls from the 'spotlight' and 'browseChannels' functionalities. Instead, it introduces server-side method imports to enhance code modularity and maintainability. Specifically, the browseChannels method is refactored into a separate function named browseChannelsMethod, with the addition of a new type BrowseChannelsParams for improved type safety. Similarly, the spotlight method is extracted into a separate function, with a new type definition SpotlightType introduced. These changes aim to streamline the codebase by reducing reliance on Meteor's method call system.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Apr 17, 2025

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

  • This PR is targeting the wrong base branch. It should target 7.7.0, but it targets 7.6.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Apr 17, 2025

⚠️ No Changeset found

Latest commit: 63a33cf

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

@kody-ai
Copy link

kody-ai bot commented Apr 17, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

Comment on lines +370 to +372
if (!user) {
return;
}
Copy link

Choose a reason for hiding this comment

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

kody code-review Error Handling high

if (!user) {
    throw new Error('User is not authenticated');
}

The browseChannelsMethod function returns undefined for invalid inputs or unauthenticated users, which is not explicit and can hinder debugging.

This issue appears in multiple locations:

  • apps/meteor/server/methods/browseChannels.ts: Lines 370-372
  • apps/meteor/server/methods/browseChannels.ts: Lines 344-349
    Please throw descriptive errors instead of returning undefined to improve error handling and debugging.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Comment on lines +47 to +55
if (text.startsWith('#')) {
type.users = false;
text = text.slice(1);
}

if (text.startsWith('@')) {
type.rooms = false;
text = text.slice(1);
}
if (text.startsWith('@')) {
type.rooms = false;
text = text.slice(1);
}
Copy link

Choose a reason for hiding this comment

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

kody code-review Maintainability high

const modifiedType = { ...type };

if (text.startsWith('#')) {
    modifiedType.users = false;
    text = text.slice(1);
}

if (text.startsWith('@')) {
    modifiedType.rooms = false;
    text = text.slice(1);
}

return {
    users: modifiedType.users ? await spotlight.searchUsers({ userId, rid, text, usernames, mentions }) : [],
    rooms: modifiedType.rooms ? await spotlight.searchRooms({ userId, text, includeFederatedRooms }) : []
};

The spotlightMethod function directly modifies the type object passed as an argument, which can lead to unintended side effects.

This issue appears in multiple locations:

  • apps/meteor/server/publications/spotlight.ts: Lines 47-55
  • apps/meteor/server/publications/spotlight.ts: Lines 57-60
    Please create a copy of the type object before modifying it to prevent unintended side effects.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Comment on lines 335 to 337
const result = await spotlightMethod(this.userId, query);

return API.v1.success(result);
Copy link

Choose a reason for hiding this comment

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

kody code-review Error Handling high

try {
    const result = await spotlightMethod(this.userId, query);
    return API.v1.success(result);
} catch (error) {
    SystemLogger.error({ msg: 'Error executing spotlightMethod', error });
    return API.v1.failure('An error occurred while processing your request.');
}

Consider adding error handling for the 'spotlightMethod' call to manage potential exceptions that might occur during its execution. This will ensure that any unexpected errors are caught and handled gracefully, providing a better user experience and more robust API behavior.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 17, 2025

PR Preview Action v1.6.1

🚀 View preview at
https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-35836/

Built to branch gh-pages at 2025-04-23 14:11 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov
Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.17%. Comparing base (8ba005e) to head (63a33cf).
Report is 33 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #35836      +/-   ##
===========================================
- Coverage    61.17%   61.17%   -0.01%     
===========================================
  Files         3005     3005              
  Lines        71387    71382       -5     
  Branches     16342    16341       -1     
===========================================
- Hits         43669    43665       -4     
+ Misses       24750    24749       -1     
  Partials      2968     2968              
Flag Coverage Δ
e2e 57.87% <ø> (+<0.01%) ⬆️
unit 75.01% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MarcosSpessatto MarcosSpessatto marked this pull request as ready for review April 22, 2025 17:13
@MarcosSpessatto MarcosSpessatto requested a review from a team as a code owner April 22, 2025 17:13
@ggazzo ggazzo added this to the 7.7.0 milestone Apr 29, 2025
@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Apr 29, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Apr 29, 2025
@ggazzo ggazzo merged commit 50acc7a into develop Apr 29, 2025
50 checks passed
@ggazzo ggazzo deleted the refactor/remove-meteor-calls-misc branch April 29, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants