From 885cfe6f31985fb4f8e4a2795096a66a36775cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 1 Nov 2020 13:15:18 +0100 Subject: [PATCH] Fix rendering of attachment message types --- .../lib/data/message/MessageAction.class.php | 17 +++++++++- .../type/AttachmentMessageType.class.php | 13 +++++++- templates/messageTypes.tpl | 31 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/files/lib/data/message/MessageAction.class.php b/files/lib/data/message/MessageAction.class.php index d5e9b93..795240a 100644 --- a/files/lib/data/message/MessageAction.class.php +++ b/files/lib/data/message/MessageAction.class.php @@ -337,19 +337,34 @@ public function pushAttachment() { foreach ($attachments as $attachment) { $attachmentIDs[] = $attachment->attachmentID; } + + $processor = new \wcf\system\html\input\HtmlInputProcessor(); + $processor->process(implode(' ', array_map(function ($attachmentID) { + return '[attach='.$attachmentID.',none,true][/attach]'; + }, $attachmentIDs)), 'be.bastelstu.chat.message', 0); + WCF::getDB()->beginTransaction(); /** @var Message $message */ $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID , 'userID' => WCF::getUser()->userID , 'username' => WCF::getUser()->username , 'time' => TIME_NOW , 'objectTypeID' => $objectTypeID - , 'payload' => serialize([ 'attachmentIDs' => $attachmentIDs ]) + , 'payload' => serialize([ 'attachmentIDs' => $attachmentIDs + , 'message' => $processor->getHtml() + ]) ] ] ) )->executeAction()['returnValues']; $attachmentHandler->updateObjectID($message->messageID); + $processor->setObjectID($message->messageID); + if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($processor)) { + (new MessageEditor($message))->update([ + 'hasEmbeddedObjects' => 1 + ]); + } + WCF::getDB()->commitTransaction(); } } diff --git a/files/lib/system/message/type/AttachmentMessageType.class.php b/files/lib/system/message/type/AttachmentMessageType.class.php index eb7176d..38b5b42 100644 --- a/files/lib/system/message/type/AttachmentMessageType.class.php +++ b/files/lib/system/message/type/AttachmentMessageType.class.php @@ -53,6 +53,8 @@ public function getPayload(\chat\data\message\Message $message, \wcf\data\user\U if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); $payload = $message->payload; + $payload['formattedMessage'] = null; + $payload['plaintextMessage'] = null; $parameters = [ 'message' => $message , 'user' => $user @@ -60,7 +62,16 @@ public function getPayload(\chat\data\message\Message $message, \wcf\data\user\U ]; \wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); - // TODO + if ($parameters['payload']['formattedMessage'] === null) { + $this->processor->setOutputType('text/html'); + $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); + $parameters['payload']['formattedMessage'] = $this->processor->getHtml(); + } + if ($parameters['payload']['plaintextMessage'] === null) { + $this->processor->setOutputType('text/plain'); + $this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); + $parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); + } return $parameters['payload']; } diff --git a/templates/messageTypes.tpl b/templates/messageTypes.tpl index 12f0ab2..6641b43 100644 --- a/templates/messageTypes.tpl +++ b/templates/messageTypes.tpl @@ -433,6 +433,37 @@ + +