RocketChat / RocketChat/Rocket.Chat

refactor: Convert spotlight.js to TypeScript and remove object mutations

Open
#39,233 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: feature
Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

Background

The module apps/meteor/server/lib/spotlight.js powers the user and room autocomplete search functionality.

It appears to be one of the remaining plain JavaScript files in server/lib/, which is otherwise TypeScript-based.

Observations
  • The file is ~280 lines of untyped JavaScript.
  • processLimitAndUsernames() mutates options.limit and the usernames array in-place.
  • fetchRooms() uses delete room.lastMessage, which mutates returned MongoDB documents.
  • There are currently no unit tests covering this module.
Proposal

I would like to prepare a refactor PR that:

  1. Renames spotlight.jsspotlight.ts
  2. Introduces explicit TypeScript interfaces for search parameters and return types
  3. Replaces in-place mutations with pure transformations
  4. Avoids delete on return objects by using object destructuring
  5. Preserves all existing behavior (no functional changes)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading apps/meteor/server/lib/spotlight.js, focusing on processLimitAndUsernames() and fetchRooms(). Confirm the current user and room autocomplete behavior before renaming it to spotlight.ts. Done means explicit TypeScript interfaces, pure transformations instead of object or array mutations, no delete on returned documents, and preserved behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
backend, search
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.