if (matchingResults.length > 0) {
			throw new Meteor.Error('Custom_Sound_Error_Name_Already_In_Use', 'The custom sound name is already in use', { method: 'insertOrUpdateSound' });
		}

		if (!soundData._id) {
			// insert sound
			const createSound = {
				name: soundData.name,
				extension: soundData.extension,
			};

			const _id = CustomSounds.create(createSound);
			createSound._id = _id;

			return _id;
		} else {
			// update sound
			if (soundData.newFile) {
				RocketChatFileCustomSoundsInstance.deleteFile(`${ soundData._id }.${ soundData.previousExtension }`);
			}

			if (soundData.name !== soundData.previousName) {
				CustomSounds.setName(soundData._id, soundData.name);
				Notifications.notifyAll('updateCustomSound', { soundData });
			}

			return soundData._id;
		}
	},
});