Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions files/lib/data/conversation/message/ConversationMessage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,26 @@ public function getUserProfile(): UserProfile
{
return $this->getCollection()->getUserProfile($this);
}

/**
* Checks if the current user can read this particular message.
*/
public function canRead(): bool
{
$conversation = $this->getConversation();
if ($conversation === null) {
return false;
}

$participant = $conversation->getParticipant();
if ($participant === null) {
return false;
}

if ($participant->hasJoinedAfter($this->time) || $participant->hasLeftBefore($this->time)) {
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ class ConversationParticipant extends DatabaseObject
*/
protected static $databaseTableIndexName = 'conversationParticipantID';

/**
* Returns true if the user has joined the conversation after the provided
* timestamp.
*/
public function hasJoinedAfter(int $timestamp): bool
{
if ($this->joinedAt === 0) {
return false;
}

return $this->joinedAt > $timestamp;
}

/**
* Returns true if the user has left the conversation before the provided
* timestamp.
*/
public function hasLeftBefore(int $timestamp): bool
{
if ($this->leftAt === 0) {
return false;
}

return $this->leftAt < $timestamp;
}

public static function getParticipant(int $conversationID, int $userID): ?static
{
$sql = "SELECT * FROM wcf1_conversation_to_user WHERE conversationID = ? AND userID = ?";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace wcf\system\message\quote;

use wcf\data\conversation\message\ConversationMessage;
use wcf\data\IMessage;

/**
* IMessageQuoteHandler implementation for conversation messages.
*
* @author Alexander Ebert
* @copyright 2001-2025 WoltLab GmbH
* @license WoltLab License <http://www.woltlab.com/license-agreement.html>
*/
final class ConversationMessageQuoteHandler extends AbstractMessageQuoteHandler
{
#[\Override]
public function getMessage(int $objectID): ?IMessage
{
$message = new ConversationMessage($objectID);
if (!$message->messageID) {
return null;
}

if (!$message->canRead()) {
return null;
}

if ($message->hasEmbeddedObjects) {
$message->getCollection()->loadEmbeddedObjects();
}

return $message;
}
}
1 change: 1 addition & 0 deletions objectType.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<type>
<name>com.woltlab.wcf.conversation.message</name>
<definitionname>com.woltlab.wcf.message.quote</definitionname>
<classname>wcf\system\message\quote\ConversationMessageQuoteHandler</classname>
</type>
<type>
<name>com.woltlab.wcf.conversation.message</name>
Expand Down
2 changes: 1 addition & 1 deletion templates/conversation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
], ({ UiConversationMessageInlineEditor }, { registerContainer }, { getParticipantList }) => {
new UiConversationMessageInlineEditor({$conversation->conversationID});

registerContainer(".message", ".messageBody", "wcf\\data\\conversation\\message\\ConversationMessage", "com.woltlab.wcf.conversation.message");
registerContainer(".message", ".messageBody", "com.woltlab.wcf.conversation.message");

const contextMenu = document.getElementById('{unsafe:$interactionContextMenu->getContainerID()|encodeJS}')
console.log(contextMenu);
Expand Down