Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Filter out VoiceCommands that have a duplicate string
  • Loading branch information
renonick87 committed Mar 25, 2021
commit 666dbc75048b3f877ff1ddbd52cbec441a9e81d9
16 changes: 14 additions & 2 deletions lib/js/src/manager/screen/utils/_VoiceCommandUpdateOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,25 @@ class _VoiceCommandUpdateOperation extends _Task {
return true; // nothing to delete
}

// make an AddCommand request for every voice command
const addCommands = this._pendingVoiceCommands.map(voiceCommand => {
// filter the voice command list of any voice commands with duplicate items
const addCommands = this._pendingVoiceCommands.filter(voiceCommand => {
// Sets can only hold unique values. The size will be different if there are duplicates
const uniqueList = new Set(voiceCommand.getVoiceCommands());
if (voiceCommand.getVoiceCommands().length !== uniqueList.size) {
return false;
}
return true;
}).map(voiceCommand => {
// make an AddCommand request for every voice command
return new AddCommand()
.setCmdID(voiceCommand._getCommandId())
.setVrCommands(voiceCommand.getVoiceCommands());
});

if (addCommands.length !== this._pendingVoiceCommands.length) {
console.log('One or more VoiceCommands contained duplicate items and will not be sent.');
}

const addCommandPromises = addCommands.map(addCommand => {
return this._lifecycleManager.sendRpcResolve(addCommand);
});
Expand Down