Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async _selectFileForUser(
file: AuxObject,
user: AuxObject,
multiSelect: boolean
) {
if (SelectionManager._debug) {
console.log('[SelectionManager] Select File:', file.id);
}
const mode = getSelectionMode(user);
if (mode === 'multi') {
const { id, newId } = selectionIdForUser(user);
if (newId) {
const update = updateUserSelection(newId, file.id);
await this._helper.updateFile(user, update);
}
if (id) {
const update = toggleFileSelection(file, id, user.id);
await this._helper.updateFile(file, update);
}
} else {
if (multiSelect) {
const newId = newSelectionId();
const current = user.tags['aux._selection'];
const update = updateUserSelection(newId, file.id);
await this._helper.updateFile(user, {
tags: {
...update.tags,
['aux._selectionMode']: 'multi',
},
private async _clearSelectionForUser(user: AuxObject) {
if (SelectionManager._debug) {
console.log('[SelectionManager] Clear selection for', user.id);
}
const update = updateUserSelection(null, null);
await this._helper.updateFile(user, {
tags: {
...update.tags,
'aux._selectionMode': 'single',
},
});
}
if (mode === 'multi') {
const { id, newId } = selectionIdForUser(user);
if (newId) {
const update = updateUserSelection(newId, file.id);
await this._helper.updateFile(user, update);
}
if (id) {
const update = toggleFileSelection(file, id, user.id);
await this._helper.updateFile(file, update);
}
} else {
if (multiSelect) {
const newId = newSelectionId();
const current = user.tags['aux._selection'];
const update = updateUserSelection(newId, file.id);
await this._helper.updateFile(user, {
tags: {
...update.tags,
['aux._selectionMode']: 'multi',
},
});
if (current) {
const currentFile = this._helper.filesState[current];
if (currentFile) {
await this._helper.updateFile(currentFile, {
tags: {
[newId]: true,
},
});
}
tags: {
[newId]: true,
},
});
}
}
await this._helper.updateFile(file, {
tags: {
[newId]: true,
},
});
} else {
const selection = file.id;
const update = updateUserSelection(selection, file.id);
await this._helper.updateFile(user, update);
await this._helper.updateFile(file, { tags: {} });
}
}
this._userChangedSelection.next();
}
}