1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-21 21:30:08 +00:00

Fix rendering of attachment message types

This commit is contained in:
Tim Düsterhus 2020-11-01 13:15:18 +01:00
parent 8856cfcd8e
commit 885cfe6f31
Signed by: TimWolla
GPG Key ID: 8FF75566094168AF
3 changed files with 59 additions and 2 deletions

View File

@ -337,19 +337,34 @@ public function pushAttachment() {
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
$attachmentIDs[] = $attachment->attachmentID; $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 */ /** @var Message $message */
$message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID $message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID
, 'userID' => WCF::getUser()->userID , 'userID' => WCF::getUser()->userID
, 'username' => WCF::getUser()->username , 'username' => WCF::getUser()->username
, 'time' => TIME_NOW , 'time' => TIME_NOW
, 'objectTypeID' => $objectTypeID , 'objectTypeID' => $objectTypeID
, 'payload' => serialize([ 'attachmentIDs' => $attachmentIDs ]) , 'payload' => serialize([ 'attachmentIDs' => $attachmentIDs
, 'message' => $processor->getHtml()
])
] ]
] ]
) )
)->executeAction()['returnValues']; )->executeAction()['returnValues'];
$attachmentHandler->updateObjectID($message->messageID); $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();
} }
} }

View File

@ -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()); if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser());
$payload = $message->payload; $payload = $message->payload;
$payload['formattedMessage'] = null;
$payload['plaintextMessage'] = null;
$parameters = [ 'message' => $message $parameters = [ 'message' => $message
, 'user' => $user , '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); \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']; return $parameters['payload'];
} }

View File

@ -433,6 +433,37 @@
</div> </div>
</script> </script>
<script type="x-text/template" data-application="be.bastelstu.chat" data-template-name="be-bastelstu-chat-messageType-attachment" data-template-includes="DeleteButton">
<div class="chatMessageContainer">
<div class="chatMessageSide">
<div class="chatUserAvatar jsUserActionDropdown" data-user-id="{$author.userID}">
<a href="{$author.link}">{@$author.image32}</a>
</div>
<time><a href="{$message.link}">{$message.formattedTime}</a></time>
</div>
<div class="chatMessageContent">
<div class="chatMessageHeader">
<span class="username">
<a href="{$author.link}" class="jsUserActionDropdown" data-user-id="{$author.userID}">
{@$author.coloredUsername}
</a>
</span>
<small class="separatorLeft">
<time><a href="{$message.link}">{$message.formattedTime}</a></time>
</small>
</div>
<div class="chatMessage htmlContent">{@$message.payload.formattedMessage}</div>
</div>
<ul class="buttonGroup buttonList smallButtons">
{/literal}
{if $__wcf->session->getPermission('mod.chat.canDelete')}
{ldelim}include file=$t.DeleteButton}
{/if}
{literal}
</ul>
</div>
</script>
<script type="x-text/template" data-application="be.bastelstu.chat" data-template-name="be-bastelstu-chat-messageType-color"> <script type="x-text/template" data-application="be.bastelstu.chat" data-template-name="be-bastelstu-chat-messageType-color">
<div class="chatMessageContainer inline"> <div class="chatMessageContainer inline">
<div class="chatMessageSide"> <div class="chatMessageSide">