Repository navigation
fix(whiteboard): Use the pres_annotation_history_curr for annotation updates - #21571
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/queries.ts (1)
132-146: Add documentation and TypeScript interfaces for the new subscription.The subscription implementation looks good and aligns with the backend changes. However, consider these improvements:
- Add documentation explaining the subscription's purpose and relationship with the backend changes.
- Define TypeScript interfaces for the subscription response.
+// Interface for annotation history stream response +export interface AnnotationHistoryResponse { + pres_annotation_history_curr_stream: { + annotationId: string; + annotationInfo: string; + pageId: string; + presentationId: string; + updatedAt: string; + userId: string; + }[]; +} + +/** + * Subscription for real-time annotation updates using the history-based diff tracking. + * This replaced the previous CURRENT_PAGE_ANNOTATIONS_STREAM to align with backend changes + * that track annotation changes as diffs in the pres_annotation_history_curr table. + */ export const ANNOTATION_HISTORY_STREAM = gql` subscription annotationHistoryStream($updatedAt: timestamptz) { pres_annotation_history_curr_stream(bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx (1)
823-829: Consider renamingformattedLookupto improve clarityThe variable
formattedLookupcould be renamed toshapesByIdfor better clarity, as it represents a mapping of shape IDs to their respective shape objects.Apply this diff to rename the variable:
- const formattedLookup = createLookup(prevShapesRef.current); + const shapesById = createLookup(prevShapesRef.current);And update all usages of
formattedLookupaccordingly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx(7 hunks)bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx(6 hunks)bigbluebutton-html5/imports/ui/components/whiteboard/queries.ts(1 hunks)bigbluebutton-html5/imports/ui/components/whiteboard/service.js(1 hunks)
🔇 Additional comments (8)
bigbluebutton-html5/imports/ui/components/whiteboard/queries.ts (1)
134-136: Verify the impact of reduced batch size.
The batch size has been reduced from 1000 (in CURRENT_PAGE_ANNOTATIONS_STREAM) to 100. While this is generally better for performance, we should verify that it doesn't affect the user experience when loading large whiteboards with many annotations.
Let's check the typical annotation batch sizes in the codebase:
✅ Verification successful
Let me analyze the findings from the shell script results to make a decision about the batch size reduction concern.
From the search results, I can see:
- The original
pres_annotation_curr_streamuses batch_size: 1000 - The new
pres_annotation_history_curr_streamuses batch_size: 100 - Most other GraphQL subscriptions in the codebase use much smaller batch sizes (10) for various features like notifications, chat, emoji reactions, etc.
Let me verify if there are any performance-related configurations or comments about annotation batch sizes.
Let me check the actual usage of these annotation streams to understand the context better.
Based on the findings, I can now generate a final response:
Batch size reduction is appropriate and safe
The batch size reduction from 1000 to 100 in pres_annotation_history_curr_stream is well-justified because:
- The history stream uses
ordering: ASCand is used for initial loading of annotations, making smaller batches more efficient for progressive loading - The real-time
pres_annotation_curr_stream(1000 batch size) handles live updates, where larger batches are more appropriate - Other GraphQL subscriptions in the codebase typically use much smaller batch sizes (10) without issues
- The test client (
bbb-graphql-client-test) successfully operates with an even smaller batch size of 10
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check annotation batch sizes across different queries/subscriptions
# to understand typical usage patterns
echo "Searching for batch_size configurations in GraphQL queries:"
rg -A 2 'batch_size:' --type ts
Length of output: 3282
Script:
#!/bin/bash
# Search for any performance-related comments or configurations regarding annotations
echo "Searching for annotation-related performance comments:"
rg -i "annotation.*performance|performance.*annotation" --type ts
echo -e "\nSearching for annotation-related configuration settings:"
rg -i "annotation.*config|config.*annotation" --type ts
Length of output: 373
Script:
#!/bin/bash
# Search for the usage of annotation streams to understand their purpose
echo "Searching for annotation stream usage:"
rg -B 3 -A 3 "pres_annotation_history_curr_stream|pres_annotation_curr_stream" --type ts
echo -e "\nSearching for annotation-related comments:"
rg -B 2 -A 2 "annotation.*history|history.*annotation" --type ts --type js
Length of output: 3908
bigbluebutton-html5/imports/ui/components/whiteboard/service.js (2)
161-170: Improved error handling for annotation parsing.
The addition of type checking and error handling is a good improvement that prevents crashes from invalid JSON data.
161-170: Verify annotation parsing across the codebase.
Let's verify how annotation data is handled in other parts of the codebase to ensure consistent error handling.
✅ Verification successful
Error handling for annotation parsing is consistent and complete
The changes to add error handling for annotation parsing are appropriate and align with existing practices in the codebase:
- The whiteboard container already handles invalid annotations by checking for empty/null annotationInfo
- The export workers properly parse JSON annotations with implicit error handling
- The new error handling in service.js fills a gap by catching and logging JSON parse errors
- No other locations in the codebase perform direct JSON parsing of annotationInfo that would require similar error handling
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for other places handling annotation data parsing
# and verify consistent error handling
# Search for direct usage of annotation.annotationInfo
echo "Searching for direct usage of annotationInfo..."
rg -l "annotation.*annotationInfo" --type js --type jsx
# Search for JSON.parse calls on annotation data
echo "Searching for JSON.parse calls on annotation data..."
rg -l "JSON\.parse.*annotation" --type js --type jsx
# Search for formatAnnotations usage
echo "Searching for formatAnnotations usage..."
rg -l "formatAnnotations" --type js --type jsx
Length of output: 554
Script:
#!/bin/bash
# Let's try without the jsx type flag since it's not recognized
# Search for direct usage of annotationInfo
echo "Searching for direct usage of annotationInfo..."
rg -l "annotation.*annotationInfo" --type js
# Search for JSON.parse calls on annotation data
echo "Searching for JSON.parse calls on annotation data..."
rg -l "JSON\.parse.*annotation" --type js
# Search for formatAnnotations usage
echo "Searching for formatAnnotations usage..."
rg -l "formatAnnotations" --type js
# Let's also look for annotation-related error handling
echo "Searching for annotation error handling..."
rg "catch.*annotation" --type js -A 2
Length of output: 1136
Script:
#!/bin/bash
# Let's examine the specific implementations in the identified files
# Check the implementation in container.jsx
echo "=== Checking container.jsx implementation ==="
rg "annotation.*annotationInfo" bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx -B 2 -A 2
# Check the implementation in process.js
echo "=== Checking process.js implementation ==="
rg "JSON\.parse.*annotation" bbb-export-annotations/workers/process.js -B 2 -A 2
# Check the implementation in collector.js
echo "=== Checking collector.js implementation ==="
rg "JSON\.parse.*annotation" bbb-export-annotations/workers/collector.js -B 2 -A 2
# Let's also check for any console.error related to annotations
echo "=== Checking for annotation-related error logging ==="
rg "console\.error.*annotation" --type js -B 2 -A 2
Length of output: 2184
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx (5)
68-68: LGTM!
The addition of the removedShapes prop to the component's props looks good.
178-183: Ensure all sensitive properties are sanitized
The sanitizeShape function removes isModerator and questionType properties from shapes. Please verify that these are the only sensitive properties that need to be excluded. If there are other properties that shouldn't be exposed or persisted, consider adding them to the sanitization process.
226-229: LGTM!
The shapes are correctly sanitized and merged into the store when the shapes prop changes.
233-237: LGTM!
The effect hook properly removes shapes from the store when removedShapes is updated.
763-764: LGTM!
Shapes are sanitized and correctly loaded into the editor during mount.
| const handleTldrawMount = (editor) => { | ||
| setTlEditor(editor); | ||
| setTldrawAPI(editor); | ||
| setEditor(editor); |
There was a problem hiding this comment.
Add setEditor to propTypes
The setEditor prop is used but not declared in Whiteboard.propTypes. This might lead to warnings and can make the code less clear to other developers.
Apply this diff to include setEditor in propTypes:
Whiteboard.propTypes = {
// Other prop types...
+ setEditor: PropTypes.func.isRequired,
};Committable suggestion was skipped due to low confidence.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (2)
201-204: Consider adding error handling for subscription errorsThe subscription to
ANNOTATION_HISTORY_STREAMshould handle potential subscription errors to prevent silent failures.Add error handling:
const { data: annotationStreamData } = useSubscription(ANNOTATION_HISTORY_STREAM, { variables: { updatedAt: new Date(0).toISOString() }, skip: !curPageId, + onError: (error) => { + console.error('Annotation subscription error:', error); + }, onSubscriptionData: ({ subscriptionData }) => {
Line range hint
267-323: Optimize annotation processing logicThe current implementation has several areas for improvement:
- Duplicate JSON parsing logic
- Multiple array operations that could be combined
- Complex state updates that could be simplified
Consider refactoring the processAnnotations function:
const processAnnotations = (data) => { - let annotationsToBeRemoved = []; - const newAnnotations = []; - const updatedAnnotations = []; + const { toRemove, toUpdate, toAdd } = data.reduce((acc, item) => { + if (!item.annotationInfo || item.annotationInfo === '') { + acc.toRemove.push(item.annotationId); + return acc; + } + + let parsedInfo; + try { + parsedInfo = typeof item.annotationInfo === 'string' + ? JSON.parse(item.annotationInfo) + : item.annotationInfo; + } catch (err) { + console.error("Failed to parse annotationInfo:", err); + acc.toRemove.push(item.annotationId); + return acc; + } + + const shape = { ...parsedInfo, id: item.annotationId }; + editor?.getShape(item.annotationId) + ? acc.toUpdate.push(shape) + : acc.toAdd.push(shape); + + return acc; + }, { toRemove: [], toUpdate: [], toAdd: [] }); + setShapes([...toUpdate, ...toAdd]); + setRemovedShapes(toRemove); if (toUpdate.length > 0 || toAdd.length > 0) { const restoreOnUpdate = getFromUserSettings( FORCE_RESTORE_PRESENTATION_ON_NEW_EVENTS, window.meetingClientSettings.public.presentation.restoreOnUpdate, ); if (restoreOnUpdate) { MediaService.setPresentationIsOpen(layoutContextDispatch, true); } } };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx(7 hunks)
🔇 Additional comments (3)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (3)
65-68: LGTM: State management updates align with new annotation handling
The introduction of editor, shapes array, and removedShapes state provides better structure for managing whiteboard annotations. The change from object to array for shapes state is appropriate for the new annotation history tracking approach.
416-416: LGTM: Props updates are consistent
The addition of removedShapes and setEditor props to the Whiteboard component properly reflects the state management changes and enables the new annotation handling functionality.
Also applies to: 440-440
222-225:
Add error handling for JSON parsing
The JSON parsing operation could throw an error if annotationInfo contains invalid JSON.
Add try-catch block:
- const parsedInfo = typeof annotationInfo === "string"
- ? JSON.parse(annotationInfo)
- : annotationInfo;
+ let parsedInfo;
+ try {
+ parsedInfo = typeof annotationInfo === "string"
+ ? JSON.parse(annotationInfo)
+ : annotationInfo;
+ } catch (err) {
+ console.error("Failed to parse annotationInfo:", err);
+ annotationsToBeRemoved.add(annotationId);
+ return;
+ }Likely invalid or redundant comment.
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (1)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (1)
Line range hint
263-313: Refactor annotation processing for better maintainabilityThe annotation processing logic contains duplicate patterns and could benefit from refactoring:
- Similar JSON parsing concerns as the subscription handler
- Duplicate logic for handling annotations and shape updates
Consider extracting common logic into utility functions:
const processAnnotationInfo = (item) => { try { if (!item.annotationInfo) return { remove: true, id: item.annotationId }; const info = typeof item.annotationInfo === 'string' ? JSON.parse(item.annotationInfo) : item.annotationInfo; return { info, id: item.annotationId }; } catch (err) { console.error(`Failed to parse annotationInfo for ${item.annotationId}:`, err); return { remove: true, id: item.annotationId }; } }; const categorizeAnnotations = (data, editor) => { const result = { toRemove: new Set(), toUpdate: [], toAdd: [] }; data.forEach(item => { const processed = processAnnotationInfo(item); if (processed.remove) { result.toRemove.add(processed.id); } else { const list = editor?.getShape(processed.id) ? result.toUpdate : result.toAdd; list.push({ ...processed.info, id: processed.id }); } }); return result; };Then simplify the main function:
const processAnnotations = (data) => { const { toRemove, toUpdate, toAdd } = categorizeAnnotations(data, editor); setShapes(() => [...toUpdate, ...toAdd]); setRemovedShapes(Array.from(toRemove)); if (toUpdate.length > 0 || toAdd.length > 0) { const restoreOnUpdate = getFromUserSettings( FORCE_RESTORE_PRESENTATION_ON_NEW_EVENTS, window.meetingClientSettings.public.presentation.restoreOnUpdate, ); if (restoreOnUpdate) { MediaService.setPresentationIsOpen(layoutContextDispatch, true); } } };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx(7 hunks)bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx(7 hunks)bigbluebutton-html5/imports/ui/components/whiteboard/service.js(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- bigbluebutton-html5/imports/ui/components/whiteboard/service.js
🔇 Additional comments (5)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (2)
9-9: LGTM: Clean state management implementation
The new imports and state variables are well-structured and align with the PR's objective of switching to annotation history tracking.
Also applies to: 13-13, 16-16, 65-69
406-406: LGTM: Clean prop management
The new props removedShapes and setEditor are properly integrated into the component's prop list.
Also applies to: 430-430
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx (3)
180-185: LGTM: Clean implementation of shape sanitization.
The sanitizeShape function correctly removes unnecessary properties while maintaining immutability.
228-231: LGTM: Proper implementation of shape updates.
The code correctly:
- Uses
mergeRemoteChangesto batch update shapes - Sanitizes each shape before storing
- Updates the store atomically
235-240: LGTM: Clean implementation of shape removal.
The useEffect hook properly handles the removal of shapes when the removedShapes prop changes.
| const { data: annotationStreamData } = useSubscription(ANNOTATION_HISTORY_STREAM, { | ||
| variables: { updatedAt: new Date(0).toISOString() }, | ||
| skip: !curPageId, | ||
| onSubscriptionData: ({ subscriptionData }) => { | ||
| const annotationStream = subscriptionData.data?.pres_annotation_history_curr_stream || []; | ||
|
|
||
| const shapeMap = new Map(); | ||
|
|
||
| annotationStream.forEach((annotation) => { | ||
| const { annotationId, annotationInfo } = annotation; | ||
| shapeMap.set(annotationId, annotation); | ||
| }); | ||
|
|
||
| const validShapes = []; | ||
| const annotationsToBeRemoved = new Set(); | ||
|
|
||
| // Process only the latest occurrence of each shape | ||
| shapeMap.forEach(({ annotationId, annotationInfo }) => { | ||
| if (!annotationInfo) { | ||
| annotationsToBeRemoved.add(annotationId); | ||
| } else { | ||
| validShapes.push({ ...annotationInfo, id: annotationId }); | ||
| } | ||
| }); | ||
|
|
||
| setShapes(() => { | ||
| const finalShapes = validShapes.filter( | ||
| (shape) => !annotationsToBeRemoved.has(shape.id) | ||
| ); | ||
|
|
||
| if (finalShapes.length > 0) { | ||
| const restoreOnUpdate = getFromUserSettings( | ||
| FORCE_RESTORE_PRESENTATION_ON_NEW_EVENTS, | ||
| window.meetingClientSettings.public.presentation.restoreOnUpdate, | ||
| ); | ||
|
|
||
| if (restoreOnUpdate) { | ||
| MediaService.setPresentationIsOpen(layoutContextDispatch, true); | ||
| } | ||
| } | ||
|
|
||
| return finalShapes; | ||
| }); | ||
|
|
||
| setRemovedShapes(Array.from(annotationsToBeRemoved)); | ||
| }, | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Add error handling for annotation parsing
While the subscription implementation is robust, it's missing error handling for JSON parsing of annotationInfo. This could lead to runtime errors if malformed data is received.
Add try-catch block for parsing:
shapeMap.forEach(({ annotationId, annotationInfo }) => {
if (!annotationInfo) {
annotationsToBeRemoved.add(annotationId);
} else {
+ try {
+ const parsedInfo = typeof annotationInfo === 'string'
+ ? JSON.parse(annotationInfo)
+ : annotationInfo;
validShapes.push({ ...parsedInfo, id: annotationId });
+ } catch (err) {
+ console.error(`Failed to parse annotationInfo for ${annotationId}:`, err);
+ annotationsToBeRemoved.add(annotationId);
+ }
}
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const { data: annotationStreamData } = useSubscription(ANNOTATION_HISTORY_STREAM, { | |
| variables: { updatedAt: new Date(0).toISOString() }, | |
| skip: !curPageId, | |
| onSubscriptionData: ({ subscriptionData }) => { | |
| const annotationStream = subscriptionData.data?.pres_annotation_history_curr_stream || []; | |
| const shapeMap = new Map(); | |
| annotationStream.forEach((annotation) => { | |
| const { annotationId, annotationInfo } = annotation; | |
| shapeMap.set(annotationId, annotation); | |
| }); | |
| const validShapes = []; | |
| const annotationsToBeRemoved = new Set(); | |
| // Process only the latest occurrence of each shape | |
| shapeMap.forEach(({ annotationId, annotationInfo }) => { | |
| if (!annotationInfo) { | |
| annotationsToBeRemoved.add(annotationId); | |
| } else { | |
| validShapes.push({ ...annotationInfo, id: annotationId }); | |
| } | |
| }); | |
| setShapes(() => { | |
| const finalShapes = validShapes.filter( | |
| (shape) => !annotationsToBeRemoved.has(shape.id) | |
| ); | |
| if (finalShapes.length > 0) { | |
| const restoreOnUpdate = getFromUserSettings( | |
| FORCE_RESTORE_PRESENTATION_ON_NEW_EVENTS, | |
| window.meetingClientSettings.public.presentation.restoreOnUpdate, | |
| ); | |
| if (restoreOnUpdate) { | |
| MediaService.setPresentationIsOpen(layoutContextDispatch, true); | |
| } | |
| } | |
| return finalShapes; | |
| }); | |
| setRemovedShapes(Array.from(annotationsToBeRemoved)); | |
| }, | |
| ); | |
| }); | |
| const { data: annotationStreamData } = useSubscription(ANNOTATION_HISTORY_STREAM, { | |
| variables: { updatedAt: new Date(0).toISOString() }, | |
| skip: !curPageId, | |
| onSubscriptionData: ({ subscriptionData }) => { | |
| const annotationStream = subscriptionData.data?.pres_annotation_history_curr_stream || []; | |
| const shapeMap = new Map(); | |
| annotationStream.forEach((annotation) => { | |
| const { annotationId, annotationInfo } = annotation; | |
| shapeMap.set(annotationId, annotation); | |
| }); | |
| const validShapes = []; | |
| const annotationsToBeRemoved = new Set(); | |
| // Process only the latest occurrence of each shape | |
| shapeMap.forEach(({ annotationId, annotationInfo }) => { | |
| if (!annotationInfo) { | |
| annotationsToBeRemoved.add(annotationId); | |
| } else { | |
| try { | |
| const parsedInfo = typeof annotationInfo === 'string' | |
| ? JSON.parse(annotationInfo) | |
| : annotationInfo; | |
| validShapes.push({ ...parsedInfo, id: annotationId }); | |
| } catch (err) { | |
| console.error(`Failed to parse annotationInfo for ${annotationId}:`, err); | |
| annotationsToBeRemoved.add(annotationId); | |
| } | |
| } | |
| }); | |
| setShapes(() => { | |
| const finalShapes = validShapes.filter( | |
| (shape) => !annotationsToBeRemoved.has(shape.id) | |
| ); | |
| if (finalShapes.length > 0) { | |
| const restoreOnUpdate = getFromUserSettings( | |
| FORCE_RESTORE_PRESENTATION_ON_NEW_EVENTS, | |
| window.meetingClientSettings.public.presentation.restoreOnUpdate, | |
| ); | |
| if (restoreOnUpdate) { | |
| MediaService.setPresentationIsOpen(layoutContextDispatch, true); | |
| } | |
| } | |
| return finalShapes; | |
| }); | |
| setRemovedShapes(Array.from(annotationsToBeRemoved)); | |
| }, | |
| }); |
| removeShapes, | ||
| persistShapeWrapper, | ||
| shapes, | ||
| removedShapes, |
There was a problem hiding this comment.
Add missing prop types for new props.
The new props removedShapes and setEditor are used but not declared in Whiteboard.propTypes. This should be fixed to ensure proper prop validation.
Apply this diff to add the missing prop types:
Whiteboard.propTypes = {
// ... other prop types
+ removedShapes: PropTypes.arrayOf(PropTypes.string),
+ setEditor: PropTypes.func.isRequired,
};Also applies to: 114-114
| const createLookup = (arr) => | ||
| arr.reduce((acc, entry) => { | ||
| acc[entry.id] = entry; | ||
| return acc; | ||
| }, {}); | ||
|
|
||
| const formattedLookup = createLookup(prevShapesRef.current); |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Improve code readability for shape filtering.
While the logic is correct, we can improve readability:
- The
createLookupfunction can be simplified as suggested in the past review. - The shape filtering logic could be more explicit.
Apply these improvements:
-const createLookup = (arr) =>
- arr.reduce((acc, entry) => {
- acc[entry.id] = entry;
- return acc;
- }, {});
+const createLookup = (arr) =>
+ Object.fromEntries(arr.map(entry => [entry.id, entry]));
-const formattedLookup = createLookup(prevShapesRef.current);
+// Create a lookup of shapes by their IDs for efficient access
+const shapesByIdLookup = createLookup(prevShapesRef.current);
-newNext.selectedShapeIds = next.selectedShapeIds.filter((shapeId) => {
- const shapeOwner = formattedLookup[shapeId]?.meta?.createdBy;
- return !shapeOwner || shapeOwner === currentUser?.userId;
-});
+// Filter selected shapes to only include those created by the current user
+newNext.selectedShapeIds = next.selectedShapeIds.filter((shapeId) => {
+ const shapeOwner = shapesByIdLookup[shapeId]?.meta?.createdBy;
+ return !shapeOwner || shapeOwner === currentUser?.userId;
+});
-const hoveredShapeOwner = formattedLookup[next.hoveredShapeId]?.meta?.createdBy;
+// Check if the hovered shape belongs to the current user
+const hoveredShapeOwner = shapesByIdLookup[next.hoveredShapeId]?.meta?.createdBy;Also applies to: 841-841, 847-847
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (2)
201-247: Consider optimizing the subscription's time rangeThe subscription uses epoch time (
new Date(0)), which could fetch unnecessary historical data. Consider using a more recent timestamp or implementing pagination to optimize data transfer.- variables: { updatedAt: new Date(0).toISOString() }, + variables: { + // Consider using a more recent timestamp, e.g., 24 hours ago + updatedAt: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString() + },The annotation history processing logic itself looks solid, effectively handling shape updates and removals.
Line range hint
263-313: Address potential race conditions and optimize shape processingSeveral issues to consider:
- The editor state check could lead to race conditions as the editor might be null when accessed.
- The shape mapping contains redundant spread operations.
- The presentation restore logic is duplicated between the subscription and processing functions.
Consider these improvements:
- const existingShape = editor?.getShape(item.annotationId); + const existingShape = editor && editor.getShape(item.annotationId); - ...updatedAnnotations.map(({ annotationInfo, annotationId }) => ({ - ...annotationInfo, - id: annotationId, - })), + ...updatedAnnotations.map(({ annotationInfo, annotationId }) => + Object.assign({ id: annotationId }, annotationInfo) + ),Consider extracting the presentation restore logic into a shared function:
const handlePresentationRestore = () => { const restoreOnUpdate = getFromUserSettings( FORCE_RESTORE_PRESENTATION_ON_NEW_EVENTS, window.meetingClientSettings.public.presentation.restoreOnUpdate, ); if (restoreOnUpdate) { MediaService.setPresentationIsOpen(layoutContextDispatch, true); } };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx(7 hunks)
🔇 Additional comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (2)
9-9: LGTM: State management updates align with new annotation history handling
The new imports and state variables are well-structured to support the transition to using annotation history for tracking changes.
Also applies to: 16-16, 65-69
406-406: LGTM: Props updates are well-integrated
The new props removedShapes and setEditor are properly passed to the Whiteboard component, maintaining good component composition.
Also applies to: 430-430
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (2)
201-247: Consider optimizing shape processing logicWhile the subscription implementation is functionally correct, the shape processing could be optimized:
- The Map usage effectively handles latest occurrences
- However, the double iteration (Map.forEach + filter) could be combined
Consider this optimization:
- shapeMap.forEach(({ annotationId, annotationInfo }) => { - if (!annotationInfo) { - annotationsToBeRemoved.add(annotationId); - } else { - validShapes.push({ ...annotationInfo, id: annotationId }); - } - }); - - setShapes(() => { - const finalShapes = validShapes.filter( - (shape) => !annotationsToBeRemoved.has(shape.id) - ); + const finalShapes = []; + shapeMap.forEach(({ annotationId, annotationInfo }) => { + if (annotationInfo) { + finalShapes.push({ ...annotationInfo, id: annotationId }); + } else { + annotationsToBeRemoved.add(annotationId); + } + }); + + setShapes(() => {
Line range hint
271-321: Refactor duplicate restore logic and add error handlingThe annotation processing logic has two issues:
The presentation restore logic is duplicated across multiple places
Missing error handling for annotationInfo parsing
Extract the restore logic to a utility function:
const handlePresentationRestore = () => { const restoreOnUpdate = getFromUserSettings( FORCE_RESTORE_PRESENTATION_ON_NEW_EVENTS, window.meetingClientSettings.public.presentation.restoreOnUpdate, ); if (restoreOnUpdate) { MediaService.setPresentationIsOpen(layoutContextDispatch, true); } };
- Add error handling for annotationInfo:
data.forEach((item) => { if (!item.annotationInfo) { annotationsToBeRemoved.push(item.annotationId); } else { + let parsedInfo = item.annotationInfo; + if (typeof parsedInfo === 'string') { + try { + parsedInfo = JSON.parse(parsedInfo); + } catch (err) { + console.error(`Failed to parse annotationInfo for ${item.annotationId}:`, err); + annotationsToBeRemoved.push(item.annotationId); + return; + } + } const existingShape = editor?.getShape(item.annotationId);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx(7 hunks)
🔇 Additional comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx (2)
65-68: LGTM: State management changes align with annotation history requirements
The new state variables and structure changes effectively support the transition to using annotation history:
editorstate manages the whiteboard editor instanceshapesas an array aligns with the new data structureremovedShapestracking enables proper cleanup of removed annotations
414-414: LGTM: Props updates are consistent with state changes
The new props removedShapes and setEditor are correctly passed to the Whiteboard component, maintaining consistency with the state management changes.
Also applies to: 438-438
34bf9fd to
69aa126
Compare
|
Automated tests Summary✅ All the CI tests have passed! |



What does this PR do?
This PR updates the handling of annotation updates on the whiteboard to align with backend changes. It switches the source from the pres_annotation_curr table to the pres_annotation_history_curr table.
Motivation
The backend now uses pres_annotation_history_curr to track every change as a diff. #21509