-
Notifications
You must be signed in to change notification settings - Fork 13k
feat: Realtime user presence updates when starting/transfering a voice call #37616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: cf92ee8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 40 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughExtracts the peer-autocomplete hook into a new module, reworks context exports, adds realtime presence tracking for selected peers, and adds typed query keys; includes a changeset bumping Changes
Sequence Diagram(s)sequenceDiagram
participant UI as Component
participant Hook as usePeerAutocomplete
participant Context as MediaCallContext
participant Presence as useUserPresence
participant App as onSelectPeer
UI->>Hook: mount(onSelectPeer)
UI->>Hook: user types filter
Hook->>Hook: debounce input
Hook->>Context: getAutocompleteOptions(filter)
Context-->>Hook: returns options
Hook->>Presence: subscribe to selected user's presence
Presence-->>Hook: presence update
UI->>Hook: onChangeValue(selection)
Hook->>Hook: map selection → PeerInfo (apply presence/status)
Hook->>App: invoke onSelectPeer(PeerInfo)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this 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
🧹 Nitpick comments (2)
packages/ui-voip/src/context/usePeerAutocomplete.ts (2)
20-39: Presence sync behavior matches requirements; consider a clearer internal-peer guardThe hook correctly:
- Debounces the filter before querying autocomplete options.
- Subscribes to
useUserPresencefor the currently selected internal peer.- Calls
onSelectPeerwith an updatedstatusonly when the presence actually changes, avoiding loops.To make the intent of the presence guard clearer and more robust, you might prefer discriminating internal peers by
userIdinstead ofstatus:- useEffect(() => { - if (!peerInfo || !('status' in peerInfo) || !status?.status) { + useEffect(() => { + if (!peerInfo || !('userId' in peerInfo) || !status?.status) { return; } - - if (status.status === peerInfo?.status) { + if (status.status === peerInfo.status) { return; } - onSelectPeer({ ...peerInfo, status: status.status, }); }, [status, peerInfo, onSelectPeer]);This keeps the behavior the same for internal peers while making the type discrimination more explicit.
Also applies to: 41-57
61-75: Avoid throwing fromonChangeValuewhen option lookup fails
onChangeValuecurrently throws iflocalInfois not found:if (!localInfo) { throw new Error(`Peer info not found for value: ${value}`); }This will surface as a runtime error from a user interaction path; it’s likely safer to no-op (or log) instead, since this situation should already be impossible if the UI and options are in sync. For example:
- if (!localInfo) { - throw new Error(`Peer info not found for value: ${value}`); - } + if (!localInfo) { + // Option not found – ignore stale selection. + return; + }This keeps the UI resilient to any transient mismatch between the selected value and the options list.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
.changeset/purple-jobs-swim.md(1 hunks)packages/ui-voip/src/context/MediaCallContext.ts(1 hunks)packages/ui-voip/src/context/index.ts(1 hunks)packages/ui-voip/src/context/usePeerAutocomplete.ts(1 hunks)
🧰 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:
packages/ui-voip/src/context/index.tspackages/ui-voip/src/context/MediaCallContext.tspackages/ui-voip/src/context/usePeerAutocomplete.ts
🧠 Learnings (1)
📚 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:
.changeset/purple-jobs-swim.md
🧬 Code graph analysis (1)
packages/ui-voip/src/context/usePeerAutocomplete.ts (3)
packages/ui-voip/src/context/index.ts (4)
isFirstPeerAutocompleteOption(2-2)usePeerAutocomplete(2-2)PeerInfo(3-3)useMediaCallContext(1-1)packages/ui-voip/src/context/MediaCallContext.ts (2)
PeerInfo(22-22)useMediaCallContext(121-130)packages/ui-contexts/src/index.ts (1)
useUserPresence(97-97)
⏰ 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). (3)
- GitHub Check: 📦 Build Packages
- GitHub Check: CodeQL-Build
- GitHub Check: CodeQL-Build
🔇 Additional comments (2)
packages/ui-voip/src/context/MediaCallContext.ts (1)
3-3: React context import change looks goodUsing
createContextanduseContextdirectly fromreactis standard and consistent with the hooks below; no behavioral changes introduced here.packages/ui-voip/src/context/index.ts (1)
1-2: Re-export changes preserve the public API surfaceRe-exporting
usePeerAutocompleteandisFirstPeerAutocompleteOptionfrom./usePeerAutocompletewhile keeping the existing index entry points maintains backward compatibility for consumers ofpackages/ui-voip/src/context. This aligns well with the internal refactor of moving autocomplete logic out ofMediaCallContext.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #37616 +/- ##
===========================================
- Coverage 70.70% 70.69% -0.01%
===========================================
Files 3139 3141 +2
Lines 108744 108799 +55
Branches 19594 19579 -15
===========================================
+ Hits 76890 76920 +30
- Misses 29851 29881 +30
+ Partials 2003 1998 -5
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 6 files
There was a problem hiding this 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
🤖 Fix all issues with AI agents
In `@packages/ui-voip/src/context/usePeerAutocomplete.ts`:
- Around line 72-76: Replace the thrown Error when a matching option isn’t found
(the localInfo check in usePeerAutocomplete’s onChangeValue handler) with
graceful handling: log a warning (e.g., console.warn or use the existing logger)
that the selected value no longer exists and return early (or call the existing
selection callback with null/undefined if the rest of the flow expects a cleared
selection) instead of throwing, so the UI won’t crash when options change
between click and handler execution.
🧹 Nitpick comments (1)
packages/ui-voip/src/context/usePeerAutocomplete.ts (1)
44-57: EnsureonSelectPeeris stable to avoid unnecessary effect runs.The effect depends on
onSelectPeer. While the status equality check on line 49-51 prevents infinite loops, ifonSelectPeeris recreated on every render, this effect will still run unnecessarily each time. Consider documenting that callers should wraponSelectPeerinuseCallback, or accept a ref-based callback pattern.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/ui-voip/src/context/usePeerAutocomplete.tspackages/ui-voip/src/utils/queryKeys.ts
🧰 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:
packages/ui-voip/src/utils/queryKeys.tspackages/ui-voip/src/context/usePeerAutocomplete.ts
🧠 Learnings (1)
📓 Common learnings
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.
🧬 Code graph analysis (1)
packages/ui-voip/src/context/usePeerAutocomplete.ts (5)
packages/ui-voip/src/context/index.ts (4)
isFirstPeerAutocompleteOption(2-2)usePeerAutocomplete(2-2)PeerInfo(3-3)useMediaCallContext(1-1)packages/ui-voip/src/components/PeerAutocomplete.tsx (1)
PeerAutocompleteOptions(8-14)packages/ui-voip/src/context/MediaCallContext.ts (2)
PeerInfo(22-22)useMediaCallContext(121-130)packages/ui-voip/src/utils/queryKeys.ts (1)
mediaCallQueryKeys(1-4)packages/ui-contexts/src/index.ts (1)
useUserPresence(99-99)
⏰ 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: CodeQL-Build
🔇 Additional comments (4)
packages/ui-voip/src/utils/queryKeys.ts (1)
1-4: LGTM!Clean query-key factory following react-query best practices. The
as constassertions ensure proper tuple typing for cache key matching, and the self-referential spread pattern maintains key hierarchy correctly.packages/ui-voip/src/context/usePeerAutocomplete.ts (3)
1-19: LGTM!Clean utility functions for handling synthetic first-option detection. The prefix-based approach is straightforward and the helper functions are well-scoped.
21-40: LGTM!The query setup with debouncing and
keepPreviousDataprovides good UX during typing. The synthetic first-option prepending for non-empty filters enables direct number dialing.
85-88: LGTM!Clean return API with proper functional update pattern for
onKeypadPressavoiding stale closure issues.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
ddaaf57 to
72d962f
Compare
72d962f to
2eb9658
Compare
Proposed changes (including videos or screenshots)
Improves the call widget (when creating a new call) and transfer modal to update selected user's presence in real time.
Issue(s)
VGA-83
Steps to test or reproduce
Further comments
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.