diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue index 81167c027ef..69c082a00de 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.vue @@ -214,9 +214,6 @@ export default { }, fallbackLocalUrl() { - if (!this.file.mimetype.startsWith('image/') && !this.file.mimetype.startsWith('video/')) { - return undefined - } return this.$store.getters.getLocalUrl(this.referenceId) }, @@ -238,6 +235,7 @@ export default { name: this.file.name, path: this.file.path, link: this.file.link, + localUrl: this.fallbackLocalUrl, messageId: Number(this.messageId), nextMessageId: Number(this.nextMessageId), } diff --git a/src/components/NewMessage/NewMessageAudioRecorder.vue b/src/components/NewMessage/NewMessageAudioRecorder.vue index 977e287b887..b78f5f44004 100644 --- a/src/components/NewMessage/NewMessageAudioRecorder.vue +++ b/src/components/NewMessage/NewMessageAudioRecorder.vue @@ -247,7 +247,6 @@ export default { const fileName = this.generateFileName() // Convert blob to file const audioFile = new File([this.blob], fileName) - audioFile.localURL = window.URL.createObjectURL(this.blob) this.$emit('audio-file', audioFile) this.$emit('recording', false) } diff --git a/src/components/NewMessage/NewMessageUploadEditor.vue b/src/components/NewMessage/NewMessageUploadEditor.vue index 1f0ca98c472..2da4e82a4a7 100644 --- a/src/components/NewMessage/NewMessageUploadEditor.vue +++ b/src/components/NewMessage/NewMessageUploadEditor.vue @@ -164,10 +164,7 @@ export default { }, voiceMessageLocalURL() { - if (!this.firstFile?.file?.localURL) { - return '' - } - return this.firstFile.file.localURL + return this.$store.getters.getLocalUrl(this.firstFile.temporaryMessage.referenceId) }, }, diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index ceec240c8f3..e68f1c85d27 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -127,7 +127,9 @@ const mutations = { totalSize: file.size, temporaryMessage, }) - Vue.set(state.localUrls, temporaryMessage.referenceId, localUrl) + if (localUrl) { + Vue.set(state.localUrls, temporaryMessage.referenceId, localUrl) + } }, // Marks a given file as initialized (for retry) @@ -238,15 +240,11 @@ const actions = { + getFileExtension(file.name) } - // Get localurl for some image previews - let localUrl = '' - if (SHARED_ITEM.MEDIA_ALLOWED_PREVIEW.includes(file.type)) { - localUrl = URL.createObjectURL(file) - } else if (isVoiceMessage) { - localUrl = file.localUrl - } else { - localUrl = OC.MimeType.getIconUrl(file.type) - } + // Get localUrl for allowed image previews and voice messages uploads + const localUrl = (isVoiceMessage || SHARED_ITEM.MEDIA_ALLOWED_PREVIEW.includes(file.type)) + ? URL.createObjectURL(file) + : undefined + // Create a unique index for each file const date = new Date() const index = 'temp_' + date.getTime() + Math.random() diff --git a/src/store/fileUploadStore.spec.js b/src/store/fileUploadStore.spec.js index ffebfc972de..6dcf8fb1929 100644 --- a/src/store/fileUploadStore.spec.js +++ b/src/store/fileUploadStore.spec.js @@ -74,9 +74,6 @@ describe('fileUploadStore', () => { } global.URL.createObjectURL = jest.fn().mockImplementation((file) => 'local-url:' + file.name) - global.OC.MimeType = { - getIconUrl: jest.fn().mockImplementation((type) => 'icon-url:' + type), - } storeConfig = cloneDeep(fileUploadStore) storeConfig.actions = Object.assign(storeConfig.actions, mockedActions) @@ -127,7 +124,7 @@ describe('fileUploadStore', () => { lastModified: Date.UTC(2021, 3, 25, 15, 30, 0), }, ] - const localUrls = ['local-url:pngimage.png', 'local-url:jpgimage.jpg', 'icon-url:text/plain'] + const localUrls = ['local-url:pngimage.png', 'local-url:jpgimage.jpg', undefined] await store.dispatch('initialiseUpload', { uploadId: 'upload-id1',