-
Notifications
You must be signed in to change notification settings - Fork 386
fix: selfutils - small refactor #4272
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
fix: selfutils - small refactor #4272
Conversation
📝 WalkthroughWalkthroughThe code refactors the Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
yarn install v1.22.22 (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
8815a27 to
024b0c0
Compare
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: 3
🧹 Nitpick comments (3)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts (3)
216-229: Leverage optional chaining to simplifygetLastModifiedThe current verbose guard blocks readability and prompted a Biome lint warning.
It can be reduced to one safe line without changing behaviour:- if ( - !self || - !self.controls || - !self.controls.audio || - !self.controls.audio.meta || - !self.controls.audio.meta.lastModified - ) { - return null; - } - - return self.controls.audio.meta.lastModified; + return self?.controls?.audio?.meta?.lastModified ?? null;The same pattern applies to
getModifiedBy.
380-390: Doc-block promises an error that the code never throwsThe comment states
@throws {Error} if changed self was undefined, yetisDeviceObservingsimply returns a boolean thanks to short-circuit evaluation and never raises. Either drop the@throwsline or add the explicit check/throw for consistency with sibling helpers (isUserAdmitted, etc.).- * @throws {Error} if changed self was undefined + * @remarks does not throw; returns `false` when `changedSelf` is undefined
168-176: Optional: simplify nested null checks inisMediaInactiveThe explicit multi-line guard is correct but verbose and was flagged by Biome.
You can replace it with optional chaining without changing semantics:- previous && - previous.joinedWith && - previous.joinedWith.mediaSessions && - current && - current.joinedWith && - current.joinedWith.mediaSessions + previous?.joinedWith?.mediaSessions && + current?.joinedWith?.mediaSessions(Not critical, but keeps the codebase concise and passes the linter.)
🧰 Tools
🪛 Biome (1.9.4)
[error] 170-172: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts
[error] 170-172: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Initialize Project
- GitHub Check: AWS Amplify Console Web Preview
chrisadubois
left a 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.
this is a great improvement
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: 0
♻️ Duplicate comments (2)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts (2)
81-82: Prevent potential TypeError when accessinglayouts[0].typeThe current implementation doesn't check if
layoutsarray is empty before accessing the first element, which can cause a runtime error.Apply this change:
- getLayout: (self) => - Array.isArray(self?.controls?.layouts) ? self.controls.layouts[0].type : undefined, + getLayout: (self) => { + const layouts = self?.controls?.layouts; + return Array.isArray(layouts) && layouts.length > 0 ? layouts[0].type : undefined; + },
29-32:⚠️ Potential issueAdd array check for self.devices to prevent runtime errors
The
parsemethod accesses properties ofself.deviceswithout first verifying it's an array, which could cause runtime errors ifdevicesis undefined or not an array (e.g. during unit tests or with malformed payloads).Apply this change:
parse: (self: any, deviceId: string) => { if (self) { - const joinedWith = self.devices.find((device) => deviceId === device.url); - const pstnDevices = self.devices.filter((device) => PSTN_DEVICE_TYPE === device.deviceType); + const devices = Array.isArray(self.devices) ? self.devices : []; + const joinedWith = devices.find((device) => deviceId === device.url); + const pstnDevices = devices.filter((device) => PSTN_DEVICE_TYPE === device.deviceType);
🧹 Nitpick comments (3)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts (3)
27-27: Update JSDoc return typeThe JSDoc comment incorrectly states the return type is
{undefined}when the function actually returns an object or null.- * @returns {undefined} + * @returns {Object|null}
169-176: Simplify conditional with optional chainingThe complex condition checking for existence of properties could be simplified using optional chaining for better readability.
if ( - previous && - previous.joinedWith && - previous.joinedWith.mediaSessions && - current && - current.joinedWith && - current.joinedWith.mediaSessions + previous?.joinedWith?.mediaSessions && + current?.joinedWith?.mediaSessions ) {🧰 Tools
🪛 Biome (1.9.4)
[error] 170-172: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
522-526: Add explicit length check for the arrayWhen checking for breakout replaces, consider adding an explicit length check to avoid accessing an empty array.
if (self && Array.isArray(self.devices)) { const joinedDevice = self.devices.find((device) => deviceId === device.url); - if (Array.isArray(joinedDevice?.replaces)) { + if (Array.isArray(joinedDevice?.replaces) && joinedDevice.replaces.length > 0) { return joinedDevice.replaces[0]?.breakoutMoveId; } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts
[error] 170-172: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build Packages
- GitHub Check: AWS Amplify Console Web Preview
🔇 Additional comments (6)
packages/@webex/plugin-meetings/src/locus-info/selfUtils.ts (6)
249-252: Fixed previous issue with null-guard logic ingetSelfIdentityGreat job fixing the null-guard logic by using the correct logical OR operator. This now correctly returns null when either
selforself.personis missing.
97-139: Improved structure in getSelves methodThe refactored structure with consistent formatting for computing updates makes the code more maintainable and easier to read. The transition to an object literal with defined methods has also improved the organization overall.
492-499: New getSipUrl method implements robust partner handlingThe new method correctly extracts SIP URLs conditionally based on partner and call type, with appropriate fallback to the provided sipUri when needed.
168-214: Enhanced media inactivity detectionThis implementation now correctly checks multiple media types (audio, video, share) individually for inactive state transitions. The check for
direction !== MEDIA_STATE.inactiveis particularly important to prevent false positives.🧰 Tools
🪛 Biome (1.9.4)
[error] 170-172: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
437-449: Robust check for muted status changesAdded logic to avoid false positives when the user mutes themselves and to prevent sending unnecessary unmute notifications on meeting join. This is a valuable improvement.
22-73: Well-structured object literal refactoringExcellent job converting to an object literal structure. This refactoring makes the code more maintainable and enables VSCode to correctly jump to function definitions as intended by the PR.
Fixed it so that vscode can now jump to function definitions.
Make sure to tick the "hide whitespace" box when looking at the diff