Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-01-15 11:45:21 +0300
committerJoas Schilling <coding@schilljs.com>2021-02-02 15:52:24 +0300
commit9608867be3d01a9aa34aceb1a1ba454fc2e0f8b6 (patch)
treec66bdbf3595d78fb12a4fad7a657e1dbc5d60096
parent3d273aa6e8e18d4b096e74221eaf52b30b49e366 (diff)
Post a system message when deleting a message
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--docs/chat.md3
-rw-r--r--lib/Chat/ChatManager.php39
-rw-r--r--lib/Controller/ChatController.php19
-rw-r--r--lib/Model/Message.php8
4 files changed, 61 insertions, 8 deletions
diff --git a/docs/chat.md b/docs/chat.md
index f9b336ff6..78a2840aa 100644
--- a/docs/chat.md
+++ b/docs/chat.md
@@ -44,7 +44,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
`actorDisplayName` | string | Display name of the message author
`timestamp` | int | Timestamp in seconds and UTC time zone
`systemMessage` | string | empty for normal chat message or the type of the system message (untranslated)
- `messageType` | string | Currently known types are `comment`, `system` and `command`
+ `messageType` | string | Currently known types are `comment`, `comment_deleted`, `system` and `command`
`isReplyable` | bool | True if the user can post a reply to this message (only available with `chat-replies` capability)
`referenceId` | string | A reference string that was given while posting the message to be able to identify a sent message again (only available with `chat-reference-id` capability)
`message` | string | Message string with placeholders (see [Rich Object String](https://github.com/nextcloud/server/issues/1706))
@@ -177,3 +177,4 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
* `moderator_demoted` - {actor} demoted {user} from moderator
* `guest_moderator_promoted` - {actor} promoted {user} to moderator
* `guest_moderator_demoted` - {actor} demoted {user} from moderator
+* `message_deleted` - Message deleted by {actor} (Should not be shown to the user)
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index b63fa0f79..4202a3a46 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -106,15 +106,28 @@ class ChatManager {
* @param \DateTime $creationDateTime
* @param bool $sendNotifications
* @param string|null $referenceId
+ * @param int|null $parentId
* @return IComment
*/
- public function addSystemMessage(Room $chat, string $actorType, string $actorId, string $message, \DateTime $creationDateTime, bool $sendNotifications, ?string $referenceId = null): IComment {
+ public function addSystemMessage(
+ Room $chat,
+ string $actorType,
+ string $actorId,
+ string $message,
+ \DateTime $creationDateTime,
+ bool $sendNotifications,
+ ?string $referenceId = null,
+ ?int $parentId = null
+ ): IComment {
$comment = $this->commentsManager->create($actorType, $actorId, 'chat', (string) $chat->getId());
$comment->setMessage($message, self::MAX_CHAT_LENGTH);
$comment->setCreationDateTime($creationDateTime);
if ($referenceId !== null) {
$comment->setReferenceId($referenceId);
}
+ if ($parentId !== null) {
+ $comment->setParentId((string) $parentId);
+ }
$comment->setVerb('system');
$event = new ChatEvent($chat, $comment);
@@ -231,6 +244,30 @@ class ChatManager {
return $comment;
}
+ public function deleteMessage(Room $chat, int $messageId, string $actorType, string $actorId, \DateTime $deletionTime): IComment {
+ $comment = $this->getComment($chat, (string) $messageId);
+ $comment->setMessage(
+ json_encode([
+ 'deleted_by_type' => $actorType,
+ 'deleted_by_id' => $actorId,
+ 'deleted_on' => $deletionTime->getTimestamp(),
+ ])
+ );
+ $comment->setVerb('comment_deleted');
+ $this->commentsManager->save($comment);
+
+ return $this->addSystemMessage(
+ $chat,
+ $actorType,
+ $actorId,
+ json_encode(['message' => 'message_deleted', 'parameters' => ['message' => $messageId]]),
+ $this->timeFactory->getDateTime(),
+ false,
+ null,
+ $messageId
+ );
+ }
+
/**
* @param Room $chat
* @param string $parentId
diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php
index 3516388da..bc0dcb277 100644
--- a/lib/Controller/ChatController.php
+++ b/lib/Controller/ChatController.php
@@ -484,16 +484,25 @@ class ChatController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
- $this->chatManager->addSystemMessage(
+ $systemMessageComment = $this->chatManager->deleteMessage(
$this->room,
+ $messageId,
$attendee->getActorType(),
$attendee->getActorId(),
- json_encode(['message' => 'message_deleted', 'parameters' => ['message' => $messageId]]),
- $this->timeFactory->getDateTime(),
- false
+ $this->timeFactory->getDateTime()
);
- return new DataResponse();
+ $systemMessage = $this->messageParser->createMessage($this->room, $this->participant, $systemMessageComment, $this->l);
+ $this->messageParser->parseMessage($systemMessage);
+
+ $comment = $this->chatManager->getComment($this->room, (string) $messageId);
+ $message = $this->messageParser->createMessage($this->room, $this->participant, $comment, $this->l);
+ $this->messageParser->parseMessage($message);
+
+ $data = $systemMessage->toArray();
+ $data['parent'] = $message->toArray();
+
+ return new DataResponse($data);
}
/**
diff --git a/lib/Model/Message.php b/lib/Model/Message.php
index 97d578c18..97e63e8de 100644
--- a/lib/Model/Message.php
+++ b/lib/Model/Message.php
@@ -162,7 +162,7 @@ class Message {
}
public function toArray(): array {
- return [
+ $data = [
'id' => (int) $this->getComment()->getId(),
'token' => $this->getRoom()->getToken(),
'actorType' => $this->getActorType(),
@@ -176,5 +176,11 @@ class Message {
'isReplyable' => $this->isReplyable(),
'referenceId' => (string) $this->getComment()->getReferenceId(),
];
+
+ if ($this->getMessageType() === 'comment_deleted') {
+ $data['deleted'] = true;
+ }
+
+ return $data;
}
}