Skip to content

Commit 3b44247

Browse files
authored
Merge pull request #414 from smartdevicelink/bugfix/duplicate_voice_command_strings
Bugfix/duplicate voice command strings
2 parents ade0742 + 666dbc7 commit 3b44247

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/js/src/manager/screen/utils/_VoiceCommandUpdateOperation.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,25 @@ class _VoiceCommandUpdateOperation extends _Task {
144144
return true; // nothing to delete
145145
}
146146

147-
// make an AddCommand request for every voice command
148-
const addCommands = this._pendingVoiceCommands.map(voiceCommand => {
147+
// filter the voice command list of any voice commands with duplicate items
148+
const addCommands = this._pendingVoiceCommands.filter(voiceCommand => {
149+
// Sets can only hold unique values. The size will be different if there are duplicates
150+
const uniqueList = new Set(voiceCommand.getVoiceCommands());
151+
if (voiceCommand.getVoiceCommands().length !== uniqueList.size) {
152+
return false;
153+
}
154+
return true;
155+
}).map(voiceCommand => {
156+
// make an AddCommand request for every voice command
149157
return new AddCommand()
150158
.setCmdID(voiceCommand._getCommandId())
151159
.setVrCommands(voiceCommand.getVoiceCommands());
152160
});
153161

162+
if (addCommands.length !== this._pendingVoiceCommands.length) {
163+
console.log('One or more VoiceCommands contained duplicate items and will not be sent.');
164+
}
165+
154166
const addCommandPromises = addCommands.map(addCommand => {
155167
return this._lifecycleManager.sendRpcResolve(addCommand);
156168
});

0 commit comments

Comments
 (0)