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
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-06-28 15:37:31 +0300
committerJoas Schilling <coding@schilljs.com>2021-07-07 16:37:16 +0300
commitd76631499a5764178d1fdad81d296fe3c967962a (patch)
treecc2347413522efe4321c7e1c69086a01b49319f1 /lib
parent2144b606228aa40b2fc21f298a3e17ad9a754152 (diff)
Clear history
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Chat/ChatManager.php15
-rw-r--r--lib/Controller/ChatController.php38
2 files changed, 52 insertions, 1 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index 63a0b3ab6..f0ff88fea 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -279,6 +279,21 @@ class ChatManager {
);
}
+ public function clearHistory(Room $chat, string $actorType, string $actorId): IComment {
+ $this->commentsManager->deleteCommentsAtObject('chat', (string) $chat->getId());
+
+ // TODO reset read markers so they don't error when being used as offset
+
+ return $this->addSystemMessage(
+ $chat,
+ $actorType,
+ $actorId,
+ json_encode(['message' => 'cleared_history', 'parameters' => []]),
+ $this->timeFactory->getDateTime(),
+ false
+ );
+ }
+
/**
* @param Room $chat
* @param string $parentId
diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php
index 62db43832..af9e13b31 100644
--- a/lib/Controller/ChatController.php
+++ b/lib/Controller/ChatController.php
@@ -592,7 +592,43 @@ class ChatController extends AEnvironmentAwareController {
$bridge = $this->matterbridgeManager->getBridgeOfRoom($this->room);
- $response = new DataResponse($data, $bridge['enabled'] ? Http::STATUS_ACCEPTED: Http::STATUS_OK);
+ $response = new DataResponse($data, $bridge['enabled'] ? Http::STATUS_ACCEPTED : Http::STATUS_OK);
+ if ($this->participant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
+ $response->addHeader('X-Chat-Last-Common-Read', $this->chatManager->getLastCommonReadMessage($this->room));
+ }
+ return $response;
+ }
+
+ /**
+ * @NoAdminRequired
+ * @RequireModeratorParticipant
+ * @RequireReadWriteConversation
+ *
+ * @return DataResponse
+ */
+ public function clearHistory(): DataResponse {
+ $attendee = $this->participant->getAttendee();
+ if (!$this->participant->hasModeratorPermissions(false)
+ || $this->room->getType() === Room::ONE_TO_ONE_CALL) {
+ // Actor is not a moderator or not the owner of the message
+ return new DataResponse([], Http::STATUS_FORBIDDEN);
+ }
+
+ $systemMessageComment = $this->chatManager->clearHistory(
+ $this->room,
+ $attendee->getActorType(),
+ $attendee->getActorId()
+ );
+
+ $systemMessage = $this->messageParser->createMessage($this->room, $this->participant, $systemMessageComment, $this->l);
+ $this->messageParser->parseMessage($systemMessage);
+
+
+ $data = $systemMessage->toArray();
+
+ $bridge = $this->matterbridgeManager->getBridgeOfRoom($this->room);
+
+ $response = new DataResponse($data, $bridge['enabled'] ? Http::STATUS_ACCEPTED : Http::STATUS_OK);
if ($this->participant->getAttendee()->getReadPrivacy() === Participant::PRIVACY_PUBLIC) {
$response->addHeader('X-Chat-Last-Common-Read', $this->chatManager->getLastCommonReadMessage($this->room));
}