From 1d77381225238fa262e5cba55421248bf8d77554 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 11 May 2020 23:40:27 -0300 Subject: [PATCH 1/3] Fix new message sound --- app/custom-sounds/client/lib/CustomSounds.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/custom-sounds/client/lib/CustomSounds.js b/app/custom-sounds/client/lib/CustomSounds.js index a0422581f6aa..ad6265751a30 100644 --- a/app/custom-sounds/client/lib/CustomSounds.js +++ b/app/custom-sounds/client/lib/CustomSounds.js @@ -9,6 +9,7 @@ const getCustomSoundId = (sound) => `custom-sound-${ sound }`; class CustomSoundsClass { constructor() { this.list = new ReactiveVar({}); + this.add({ _id: 'chime', name: 'Chime', extension: 'mp3', src: 'sounds/chime.mp3' }); this.add({ _id: 'beep', name: 'Beep', extension: 'mp3', src: 'sounds/beep.mp3' }); this.add({ _id: 'chelle', name: 'Chelle', extension: 'mp3', src: 'sounds/chelle.mp3' }); this.add({ _id: 'ding', name: 'Ding', extension: 'mp3', src: 'sounds/ding.mp3' }); From 5ac599ef02e34040b06fd600cc0687ccc9ba5bd1 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Mon, 11 May 2020 23:48:52 -0300 Subject: [PATCH 2/3] All da fixes --- app/custom-sounds/client/lib/CustomSounds.js | 34 +++++++++++++------ .../server/startup/custom-sounds.js | 13 ++++--- app/ui-master/client/main.html | 1 - app/ui/client/index.js | 1 - app/ui/client/lib/notification.js | 9 +---- .../client/views/app/audioNotification.html | 10 ------ client/admin/customSounds/EditCustomSound.js | 2 +- client/admin/customSounds/lib.js | 5 +-- packages/rocketchat-i18n/i18n/en.i18n.json | 1 + 9 files changed, 36 insertions(+), 40 deletions(-) delete mode 100644 app/ui/client/views/app/audioNotification.html diff --git a/app/custom-sounds/client/lib/CustomSounds.js b/app/custom-sounds/client/lib/CustomSounds.js index ad6265751a30..27b09ca5a50d 100644 --- a/app/custom-sounds/client/lib/CustomSounds.js +++ b/app/custom-sounds/client/lib/CustomSounds.js @@ -3,19 +3,21 @@ import { ReactiveVar } from 'meteor/reactive-var'; import _ from 'underscore'; import { CachedCollectionManager } from '../../../ui-cached-collection'; +import { getURL } from '../../../utils/client'; const getCustomSoundId = (sound) => `custom-sound-${ sound }`; class CustomSoundsClass { constructor() { this.list = new ReactiveVar({}); - this.add({ _id: 'chime', name: 'Chime', extension: 'mp3', src: 'sounds/chime.mp3' }); - this.add({ _id: 'beep', name: 'Beep', extension: 'mp3', src: 'sounds/beep.mp3' }); - this.add({ _id: 'chelle', name: 'Chelle', extension: 'mp3', src: 'sounds/chelle.mp3' }); - this.add({ _id: 'ding', name: 'Ding', extension: 'mp3', src: 'sounds/ding.mp3' }); - this.add({ _id: 'droplet', name: 'Droplet', extension: 'mp3', src: 'sounds/droplet.mp3' }); - this.add({ _id: 'highbell', name: 'Highbell', extension: 'mp3', src: 'sounds/highbell.mp3' }); - this.add({ _id: 'seasons', name: 'Seasons', extension: 'mp3', src: 'sounds/seasons.mp3' }); + this.add({ _id: 'chime', name: 'Chime', extension: 'mp3', src: getURL('sounds/chime.mp3') }); + this.add({ _id: 'door', name: 'Door', extension: 'mp3', src: getURL('sounds/door.mp3') }); + this.add({ _id: 'beep', name: 'Beep', extension: 'mp3', src: getURL('sounds/beep.mp3') }); + this.add({ _id: 'chelle', name: 'Chelle', extension: 'mp3', src: getURL('sounds/chelle.mp3') }); + this.add({ _id: 'ding', name: 'Ding', extension: 'mp3', src: getURL('sounds/ding.mp3') }); + this.add({ _id: 'droplet', name: 'Droplet', extension: 'mp3', src: getURL('sounds/droplet.mp3') }); + this.add({ _id: 'highbell', name: 'Highbell', extension: 'mp3', src: getURL('sounds/highbell.mp3') }); + this.add({ _id: 'seasons', name: 'Seasons', extension: 'mp3', src: getURL('sounds/seasons.mp3') }); } add(sound) { @@ -42,9 +44,12 @@ class CustomSoundsClass { const audio = $(`#${ sound._id }`); if (audio && audio[0]) { const list = this.list.get(); + if (!sound.src) { + sound.src = this.getURL(sound); + } list[sound._id] = sound; this.list.set(list); - $('source', audio).attr('src', this.getURL(sound)); + $('source', audio).attr('src', sound.src); audio[0].load(); } else { this.add(sound); @@ -52,8 +57,7 @@ class CustomSoundsClass { } getURL(sound) { - const path = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX || ''; - return `${ path }/custom-sounds/${ sound._id }.${ sound.extension }?_dc=${ sound.random || 0 }`; + return getURL(`/custom-sounds/${ sound._id }.${ sound.extension }?_dc=${ sound.random || 0 }`); } getList() { @@ -73,6 +77,16 @@ class CustomSoundsClass { return audio; } + + pause = (sound) => { + const audio = document.querySelector(`#${ getCustomSoundId(sound) }`); + if (!audio || !audio.pause) { + return; + } + + audio.pause(); + audio.currentTime = 0; + } } export const CustomSounds = new CustomSoundsClass(); diff --git a/app/custom-sounds/server/startup/custom-sounds.js b/app/custom-sounds/server/startup/custom-sounds.js index 7417d90e568f..77a0d2c52b38 100644 --- a/app/custom-sounds/server/startup/custom-sounds.js +++ b/app/custom-sounds/server/startup/custom-sounds.js @@ -1,9 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { WebApp } from 'meteor/webapp'; -import _ from 'underscore'; -import { RocketChatFile } from '../../../file'; -import { settings } from '../../../settings'; +import { RocketChatFile } from '../../../file/server'; +import { settings } from '../../../settings/server'; export let RocketChatFileCustomSoundsInstance; @@ -35,16 +34,16 @@ Meteor.startup(function() { }); return WebApp.connectHandlers.use('/custom-sounds/', Meteor.bindEnvironment(function(req, res/* , next*/) { - const params = { sound: decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, '')) }; + const fileId = decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, '')); - if (_.isEmpty(params.sound)) { + if (!fileId) { res.writeHead(403); res.write('Forbidden'); res.end(); return; } - const file = RocketChatFileCustomSoundsInstance.getFileWithReadStream(params.sound); + const file = RocketChatFileCustomSoundsInstance.getFileWithReadStream(fileId); if (!file) { return; } @@ -73,7 +72,7 @@ Meteor.startup(function() { } else { res.setHeader('Last-Modified', new Date().toUTCString()); } - res.setHeader('Content-Type', 'audio/mpeg'); + res.setHeader('Content-Type', file.contentType); res.setHeader('Content-Length', file.length); file.readStream.pipe(res); diff --git a/app/ui-master/client/main.html b/app/ui-master/client/main.html index fa1554c3c4b9..040c1eae7678 100644 --- a/app/ui-master/client/main.html +++ b/app/ui-master/client/main.html @@ -45,7 +45,6 @@
{{> status}}
- {{> audioNotification }} {{/if}} {{/if}} {{/unless}} diff --git a/app/ui/client/index.js b/app/ui/client/index.js index b7fa4c6840de..40e796da5d0a 100644 --- a/app/ui/client/index.js +++ b/app/ui/client/index.js @@ -12,7 +12,6 @@ import './views/cmsPage.html'; import './views/404/roomNotFound.html'; import './views/404/invalidSecretURL.html'; import './views/404/invalidInvite.html'; -import './views/app/audioNotification.html'; import './views/app/burger.html'; import './views/app/createChannel.html'; import './views/app/editStatus.html'; diff --git a/app/ui/client/lib/notification.js b/app/ui/client/lib/notification.js index 14e1bebc7381..2ad74e0a7dd1 100644 --- a/app/ui/client/lib/notification.js +++ b/app/ui/client/lib/notification.js @@ -165,14 +165,7 @@ Meteor.startup(() => { } }); } else { - const [room] = $(`audio#${ newRoomNotification }`); - if (!room) { - return; - } - if (room.pause) { - room.pause(); - room.currentTime = 0; - } + CustomSounds.pause(newRoomNotification); } }); }); diff --git a/app/ui/client/views/app/audioNotification.html b/app/ui/client/views/app/audioNotification.html deleted file mode 100644 index 88a0accde674..000000000000 --- a/app/ui/client/views/app/audioNotification.html +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/client/admin/customSounds/EditCustomSound.js b/client/admin/customSounds/EditCustomSound.js index 43170fb5ddef..5e24443c0fd9 100644 --- a/client/admin/customSounds/EditCustomSound.js +++ b/client/admin/customSounds/EditCustomSound.js @@ -19,7 +19,7 @@ const DeleteWarningModal = ({ onDelete, onCancel, ...props }) => { - {t('Custom_Sound_Status_Delete_Warning')} + {t('Custom_Sound_Delete_Warning')} diff --git a/client/admin/customSounds/lib.js b/client/admin/customSounds/lib.js index bff7ad4c15ed..44420855af54 100644 --- a/client/admin/customSounds/lib.js +++ b/client/admin/customSounds/lib.js @@ -22,13 +22,14 @@ export function validate(soundData, soundFile) { } export function createSoundData(soundFile, name = '', previousData) { - const soundData = {}; + const soundData = { + extension: soundFile.name.split('.').pop(), + }; if (previousData) { soundData._id = previousData._id; soundData.previousName = previousData.previousName; soundData.previousSound = previousData.previousSound; - soundData.extension = soundFile.name.split('.').pop(); soundData.previousExtension = previousData.previousSound.extension; soundData.name = name; soundData.newFile = false; diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 8cf17e9333ad..54bdd5e1bb26 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1069,6 +1069,7 @@ "Custom_Script_On_Logout_Description": "Custom Script that will run on execute logout flow ONLY", "Custom_Sound_Add": "Add Custom Sound", "Custom_Sound_Delete_Warning": "Deleting a sound cannot be undone.", + "Custom_Sound_Edit": "Edit Custom Sound", "Custom_Sound_Error_Invalid_Sound": "Invalid sound", "Custom_Sound_Error_Name_Already_In_Use": "The custom sound name is already in use.", "Custom_Sound_Has_Been_Deleted": "The custom sound has been deleted.", From 0a1fa7b64e14d84735a2ac0910f78e73d14395e2 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 12 May 2020 01:16:21 -0300 Subject: [PATCH 3/3] Fix edit route --- client/admin/customSounds/EditCustomSound.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client/admin/customSounds/EditCustomSound.js b/client/admin/customSounds/EditCustomSound.js index 5e24443c0fd9..d7938a96a589 100644 --- a/client/admin/customSounds/EditCustomSound.js +++ b/client/admin/customSounds/EditCustomSound.js @@ -49,8 +49,7 @@ const SuccessModal = ({ onClose, ...props }) => { ; }; -export function EditSound({ _id, cache, ...props }) { - const t = useTranslation(); +export function EditCustomSound({ _id, cache, ...props }) { const query = useMemo(() => ({ query: JSON.stringify({ _id }), }), [_id]); @@ -75,13 +74,13 @@ export function EditSound({ _id, cache, ...props }) { } if (error || !data || data.sounds.length < 1) { - return {t('Custom_User_Status_Error_Invalid_User_Status')}; + return {error}; } - return ; + return ; } -export function EditCustomSound({ close, onChange, data, ...props }) { +function EditSound({ close, onChange, data, ...props }) { const t = useTranslation(); const dispatchToastMessage = useToastMessageDispatch();