From 5fce0c092c38d599cbd7c646438717f236c3a0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 1 Nov 2020 12:15:06 +0100 Subject: [PATCH] Send the tmpHash instead of the attachmentId All the PHP goodies reside inside the AttachmentHandler which expects the tmpHash. --- files_wcf/js/Bastelstu.be/Chat.js | 2 +- files_wcf/js/Bastelstu.be/Chat/Messenger.js | 4 ++-- .../Bastelstu.be/Chat/Ui/Attachment/Upload.js | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/files_wcf/js/Bastelstu.be/Chat.js b/files_wcf/js/Bastelstu.be/Chat.js index 0737743..12fe7f8 100644 --- a/files_wcf/js/Bastelstu.be/Chat.js +++ b/files_wcf/js/Bastelstu.be/Chat.js @@ -334,7 +334,7 @@ define([ './Chat/console' } async onSendAttachment(event) { - return this.bottle.container.Messenger.pushAttachment(event.detail.attachmentId) + return this.bottle.container.Messenger.pushAttachment(event.detail.tmpHash) } onAutocomplete(event) { diff --git a/files_wcf/js/Bastelstu.be/Chat/Messenger.js b/files_wcf/js/Bastelstu.be/Chat/Messenger.js index 2ae817c..a1a1696 100644 --- a/files_wcf/js/Bastelstu.be/Chat/Messenger.js +++ b/files_wcf/js/Bastelstu.be/Chat/Messenger.js @@ -56,9 +56,9 @@ define([ './console' return Ajax.api(this, payload) } - async pushAttachment(attachmentId) { + async pushAttachment(tmpHash) { const payload = { actionName: 'pushAttachment' - , parameters: { attachmentId } + , parameters: { tmpHash } } return Ajax.api(this, payload) diff --git a/files_wcf/js/Bastelstu.be/Chat/Ui/Attachment/Upload.js b/files_wcf/js/Bastelstu.be/Chat/Ui/Attachment/Upload.js index efbbfd7..58740b4 100644 --- a/files_wcf/js/Bastelstu.be/Chat/Ui/Attachment/Upload.js +++ b/files_wcf/js/Bastelstu.be/Chat/Ui/Attachment/Upload.js @@ -39,6 +39,7 @@ define([ 'WoltLabSuite/Core/Language' this.room = room this.previewContainer = previewContainer + this.tmpHash = undefined } bootstrap() { @@ -82,10 +83,10 @@ define([ 'WoltLabSuite/Core/Language' elShow(this.uploadDescription) } - async send(attachmentId, event) { + async send(tmpHash, event) { event.preventDefault() const parameters = { promise: Promise.resolve() - , attachmentId + , tmpHash } this.emit('send', parameters) @@ -99,14 +100,14 @@ define([ 'WoltLabSuite/Core/Language' } } - createButtonGroup(uploadId, objectID) { + createButtonGroup(uploadId, objectId, tmpHash) { const buttonGroup = document.createElement('ul') buttonGroup.classList.add('buttonGroup') let li = document.createElement('li') const cancelButton = document.createElement('span') cancelButton.classList.add('button', 'jsDeleteButton') - cancelButton.dataset.objectId = objectID + cancelButton.dataset.objectId = objectId cancelButton.dataset.eventName = 'attachment' cancelButton.innerText = Language.get('wcf.global.button.cancel') li.appendChild(cancelButton) @@ -115,9 +116,8 @@ define([ 'WoltLabSuite/Core/Language' li = document.createElement('li') const sendButton = document.createElement('span') sendButton.classList.add('button') - sendButton.dataset.objectId = objectID sendButton.innerText = Language.get('wcf.global.button.submit') - sendButton.addEventListener('click', (e) => this.send(objectID, e)) + sendButton.addEventListener('click', (e) => this.send(tmpHash, e)) li.appendChild(sendButton) buttonGroup.appendChild(li) @@ -131,13 +131,13 @@ define([ 'WoltLabSuite/Core/Language' * @see WoltLabSuite/Core/Upload#_getParameters */ _getParameters() { - const hash = [ ...crypto.getRandomValues(new Uint8Array(20)) ] + this.tmpHash = [ ...crypto.getRandomValues(new Uint8Array(20)) ] .map(m => ('0' + m.toString(16)).slice(-2)) .join('') return { objectType: "be.bastelstu.chat.message" , parentObjectID: this.room.roomID - , tmpHash: hash + , tmpHash: this.tmpHash } } @@ -186,7 +186,7 @@ define([ 'WoltLabSuite/Core/Language' DomUtil.replaceElement(progress, img) - this.createButtonGroup(uploadId, attachment.attachmentID) + this.createButtonGroup(uploadId, attachment.attachmentID, this.tmpHash) } } }