diff options
author | Marco Ambrosini <marcoambrosini@pm.me> | 2020-07-06 12:44:48 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2020-07-24 11:52:33 +0300 |
commit | afc09339913e682fecba60fbe6c2c9c9c04c4c1d (patch) | |
tree | 7de083fb91990e0d935fc61723e0aa34d9e322fb /src | |
parent | 0e284583a783f9a4b7e36b859bdfe07be178355e (diff) |
Add temporary message while a file is being uploaded
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
Diffstat (limited to 'src')
-rw-r--r-- | src/store/fileUploadStore.js | 8 | ||||
-rw-r--r-- | src/utils/temporaryMessage.js | 14 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index 38e81c406..0c53e28c0 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -25,6 +25,7 @@ import client from '../services/DavClient' import { showError } from '@nextcloud/dialogs' import { loadState } from '@nextcloud/initial-state' import { findUniquePath } from '../utils/fileUpload' +import createTemporaryMessage from '../utils/temporaryMessage' const state = { attachmentFolder: loadState('talk', 'attachment_folder'), @@ -129,7 +130,7 @@ const actions = { * @param {object} param1 The unique uploadId, the conversation token and the * files array */ - async uploadFiles({ commit, state, getters }, { uploadId, token, files }) { + async uploadFiles({ commit, dispatch, state, getters }, { uploadId, token, files }) { files.forEach(file => { commit('addFileToBeUploaded', { uploadId, token, file }) }) @@ -140,6 +141,9 @@ const actions = { commit('markFileAsUploading', { uploadId, index }) // currentFile to be uploaded const currentFile = state.uploads[uploadId].files[index].file + // Create temporary message for the file and add it to the message list + const temporaryMessage = createTemporaryMessage('{file}', token, currentFile) + dispatch('addTemporaryMessage', temporaryMessage) // userRoot path const userRoot = '/files/' + getters.getUserId() // Candidate rest of the path @@ -160,6 +164,8 @@ const actions = { const sharePath = '/' + uniquePath // Mark the file as uploaded in the store commit('markFileAsSuccessUpload', { uploadId, index, sharePath }) + // Delete temporary message + dispatch('deleteMessage', temporaryMessage) } catch (exception) { console.debug('Error while uploading file:' + exception) showError(t('spreed', 'Error while uploading file')) diff --git a/src/utils/temporaryMessage.js b/src/utils/temporaryMessage.js index 52351c460..dfd3b9ac4 100644 --- a/src/utils/temporaryMessage.js +++ b/src/utils/temporaryMessage.js @@ -24,10 +24,20 @@ import store from '../store/index' import SHA1 from 'crypto-js/sha1' import Hex from 'crypto-js/enc-hex' -const createTemporaryMessage = (text, token) => { +const createTemporaryMessage = (text, token, file) => { const messageToBeReplied = store.getters.getMessageToBeReplied(token) const date = new Date() const tempId = 'temp-' + date.getTime() + const messageParameters = {} + if (file) { + messageParameters.file = { + 'type': 'file', + 'file': file, + 'mimetype': file.type, + 'id': tempId, + 'name': file.name, + } + } const message = Object.assign({}, { id: tempId, actorId: store.getters.getActorId(), @@ -37,7 +47,7 @@ const createTemporaryMessage = (text, token) => { systemMessage: '', messageType: '', message: text, - messageParameters: {}, + messageParameters, token: token, isReplyable: false, referenceId: Hex.stringify(SHA1(tempId)), |