Skip to content

refactor: remove unsafe any cast in StreamPresence implementation#39377

Open
sahillllllllll-bit wants to merge 2 commits into
RocketChat:developfrom
sahillllllllll-bit:fix/remove-any-stream-presence
Open

refactor: remove unsafe any cast in StreamPresence implementation#39377
sahillllllllll-bit wants to merge 2 commits into
RocketChat:developfrom
sahillllllllll-bit:fix/remove-any-stream-presence

Conversation

@sahillllllllll-bit
Copy link
Copy Markdown
Contributor

@sahillllllllll-bit sahillllllllll-bit commented Mar 5, 2026

Summary

This change removes the unsafe as any cast used when instantiating the StreamPresence streamer.

Instead of bypassing TypeScript checks with any, the returned instance is now properly typed using the expected IStreamer<'user-presence'> interface.

Using any disables TypeScript's type safety and can hide potential type mismatches during refactoring or future changes. Since the streamer already conforms to the expected interface, we can safely replace the cast with a more explicit and type-safe assertion.

Changes

  • Removed the as any cast from the StreamPresence instantiation.
  • Added an explicit IStreamer<'user-presence'> type assertion for the returned instance.
  • No runtime behavior changes.

Impact

  • Improves type safety in the presence streaming implementation.
  • Prevents accidental type mismatches from being hidden by any.
  • Keeps behavior identical while aligning with TypeScript best practices.

.

Summary by CodeRabbit

  • Chores
    • No user-facing changes; internal type and signature adjustments to improve type safety and maintainability.
  • Refactor
    • Internal class and instantiation refinements to clarify implementation and reduce ambiguity.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Mar 5, 2026

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: b7e83e2

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 5, 2026

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: fe17390d-60a3-4694-a833-32cd30d06074

📥 Commits

Reviewing files that changed from the base of the PR and between 970ced2 and b7e83e2.

📒 Files selected for processing (1)
  • apps/meteor/app/notifications/server/lib/Presence.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/app/notifications/server/lib/Presence.ts

Walkthrough

Changed the getInstance signature to require the literal name 'user-presence', renamed the local streamer class to StreamPresenceImpl, narrowed a type assertion for options to UserPresenceStreamProps in _publish, and adjusted the final instantiation to pass the name parameter without an any cast.

Changes

Cohort / File(s) Summary
Presence stream implementation
apps/meteor/app/notifications/server/lib/Presence.ts
Updated getInstance signature to name: 'user-presence' = 'user-presence'; renamed anonymous streamer class to StreamPresenceImpl; tightened _publish options cast to UserPresenceStreamProps; removed as any from final instantiation, invoking the class with name.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

type: chore

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately reflects the main change: removing an unsafe any cast in the StreamPresence implementation while improving type safety.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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/notifications/server/lib/Presence.ts`:
- Around line 75-76: Change the signature of getInstance to constrain the name
parameter to the literal type 'user-presence' (e.g., name: 'user-presence' =
'user-presence') so the method returns IStreamer<'user-presence'> without
needing casts; update the getInstance declaration and any callers if necessary,
and then remove the redundant type assertion used when instantiating
StreamPresenceImpl inside getInstance (the assertion on the new (...)
expression). Target the getInstance function and the inner StreamPresenceImpl
class to ensure types line up.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 34334679-758c-434d-9155-b2f7775f7f36

📥 Commits

Reviewing files that changed from the base of the PR and between 819399c and 970ced2.

📒 Files selected for processing (1)
  • apps/meteor/app/notifications/server/lib/Presence.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/notifications/server/lib/Presence.ts
🧠 Learnings (4)
📚 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/notifications/server/lib/Presence.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:

  • apps/meteor/app/notifications/server/lib/Presence.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/notifications/server/lib/Presence.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/notifications/server/lib/Presence.ts
🔇 Additional comments (1)
apps/meteor/app/notifications/server/lib/Presence.ts (1)

77-83: Line 82 correctly handles the actual data structure; reconsider the unsafe type assertion.

The review's concern about options.args is unfounded. The client passes presence data directly as flat properties ({ added: [...], removed: [...] }), not nested under options.args. Line 82's extraction directly from the options object matches the actual usage pattern at apps/meteor/client/lib/presence.ts:58-60. The base Streamer pattern for options.args is not applicable here since this is an intentional override for a different data flow.

However, the type assertion as UserPresenceStreamProps remains unsafe—if options lacks added or removed properties, destructuring produces undefined silently. A guard check is prudent:

const parsed = typeof options !== 'boolean' ? options : {};
const added = Array.isArray(parsed.added) ? parsed.added : [];
const removed = Array.isArray(parsed.removed) ? parsed.removed : [];

The second issue at line 98—name as 'user-presence'—is a legitimate type safety concern: casting a string parameter to a literal type is unsound, though likely intentional given the class generic constraint.

Comment thread apps/meteor/app/notifications/server/lib/Presence.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant