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 /lib/Chat/ChatManager.php
parent3d273aa6e8e18d4b096e74221eaf52b30b49e366 (diff)
Post a system message when deleting a message
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Chat/ChatManager.php')
-rw-r--r--lib/Chat/ChatManager.php39
1 files changed, 38 insertions, 1 deletions
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