From 57fbe3d3e9502c8b9b29617cd63aaccea8cf4bb8 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Thu, 4 Feb 2021 22:45:02 +0100 Subject: [PATCH 1/2] Add preview for non-images in attachment dialog --- .../Bastelstu.be/Chat/Ui/Attachment/Upload.js | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) 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 e9d929b..75dbbc1 100644 --- a/files_wcf/js/Bastelstu.be/Chat/Ui/Attachment/Upload.js +++ b/files_wcf/js/Bastelstu.be/Chat/Ui/Attachment/Upload.js @@ -48,7 +48,6 @@ define([ super(buttonContainerId, previewContainerId, { className: 'wcf\\data\\attachment\\AttachmentAction', - acceptableFiles: ['.png', '.gif', '.jpg', '.jpeg'], }) this.input = input @@ -209,8 +208,11 @@ define([ * @see WoltLabSuite/Core/Upload#_success */ _success(uploadId, data, responseText, xhr, requestOptions) { - if (data.returnValues.errors && data.returnValues.errors[0]) { - const error = data.returnValues.errors[0] + const target = this._fileElements[uploadId][0] + const progress = target.querySelector(':scope > progress') + + if (data.returnValues.errors && data.returnValues.errors[uploadId]) { + const error = data.returnValues.errors[uploadId] elInnerError( this._button, @@ -219,6 +221,8 @@ define([ }) ) + progress.remove() + return } else { elInnerError(this._button, '') @@ -237,31 +241,37 @@ define([ elHide(this.uploadDescription) const attachment = data.returnValues.attachments[uploadId] - const url = - attachment.thumbnailURL || attachment.tinyURL || attachment.url - if (!url) { - throw new Error('Missing image URL') - } + if (attachment.isImage) { + const url = + attachment.thumbnailURL || attachment.tinyURL || attachment.url - const target = this._fileElements[uploadId][0] - const progress = target.querySelector(':scope > progress') + if (!url) { + throw new Error('Missing image URL') + } - const img = document.createElement('img') - img.setAttribute('src', url) - img.setAttribute('alt', '') + const img = document.createElement('img') + img.setAttribute('src', url) + img.setAttribute('alt', '') - if (url === attachment.tinyURL) { - img.classList.add('attachmentTinyThumbnail') + if (url === attachment.tinyURL) { + img.classList.add('attachmentTinyThumbnail') + } else { + img.classList.add('attachmentThumbnail') + } + + img.dataset.width = attachment.width + img.dataset.height = attachment.height + + DomUtil.replaceElement(progress, img) } else { - img.classList.add('attachmentThumbnail') + const anchor = document.createElement('a') + anchor.setAttribute('href', attachment.url) + anchor.innerText = attachment.filename + + DomUtil.replaceElement(progress, anchor) } - img.dataset.width = attachment.width - img.dataset.height = attachment.height - - DomUtil.replaceElement(progress, img) - this.createButtons(uploadId, attachment.attachmentID, this.tmpHash) Dialog.rebuild(DIALOG_CONTAINER_ID) From b3194b65c028b7f11347acf62b5368e23b0647e5 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Thu, 4 Feb 2021 22:46:23 +0100 Subject: [PATCH 2/2] Add user group options for message attachments --- .../MessageAttachmentObjectType.class.php | 13 ++++++++----- language/de.xml | 3 +++ language/en.xml | 3 +++ userGroupOption.xml | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/files/lib/system/attachment/MessageAttachmentObjectType.class.php b/files/lib/system/attachment/MessageAttachmentObjectType.class.php index 2ad4745..19a2158 100644 --- a/files/lib/system/attachment/MessageAttachmentObjectType.class.php +++ b/files/lib/system/attachment/MessageAttachmentObjectType.class.php @@ -79,15 +79,18 @@ class MessageAttachmentObjectType extends \wcf\system\attachment\AbstractAttachm return 1; } + /** + * @inheritDoc + */ + public function getMaxSize() { + return WCF::getSession()->getPermission('user.chat.attachment.maxSize'); + } + /** * @inheritDoc */ public function getAllowedExtensions() { - return [ 'png' - , 'gif' - , 'jpg' - , 'jpeg' - ]; + return \wcf\util\ArrayUtil::trim(\explode("\n", WCF::getSession()->getPermission('user.chat.attachment.allowedExtensions'))); } /** diff --git a/language/de.xml b/language/de.xml index 71582bf..8f61782 100644 --- a/language/de.xml +++ b/language/de.xml @@ -199,6 +199,9 @@ + + + diff --git a/language/en.xml b/language/en.xml index 7fb900f..3506f61 100644 --- a/language/en.xml +++ b/language/en.xml @@ -199,6 +199,9 @@ + + + diff --git a/userGroupOption.xml b/userGroupOption.xml index e0a99c2..4288524 100644 --- a/userGroupOption.xml +++ b/userGroupOption.xml @@ -55,6 +55,21 @@ 1 1 + +