зеркало из https://github.com/nextcloud/spreed.git
Add an endpoint to delete a message
For now it only creates a system message Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
bfbce8d714
Коммит
dd06f39ee5
|
@ -153,6 +153,16 @@ return [
|
|||
'token' => '^[a-z0-9]{4,30}$',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'Chat#deleteMessage',
|
||||
'url' => '/api/{apiVersion}/chat/{token}/{messageId}',
|
||||
'verb' => 'DELETE',
|
||||
'requirements' => [
|
||||
'apiVersion' => 'v1',
|
||||
'token' => '^[a-z0-9]{4,30}$',
|
||||
'messageId' => '^[0-9]+$',
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'Chat#setReadMarker',
|
||||
'url' => '/api/{apiVersion}/chat/{token}/read',
|
||||
|
|
|
@ -247,6 +247,22 @@ class ChatManager {
|
|||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $chat
|
||||
* @param string $messageId
|
||||
* @return IComment
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getComment(Room $chat, string $messageId): IComment {
|
||||
$comment = $this->commentsManager->get($messageId);
|
||||
|
||||
if ($comment->getObjectType() !== 'chat' || $comment->getObjectId() !== (string) $chat->getId()) {
|
||||
throw new NotFoundException('Message not found in the right context');
|
||||
}
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
public function getLastReadMessageFromLegacy(Room $chat, IUser $user): int {
|
||||
$marker = $this->commentsManager->getReadMark('chat', $chat->getId(), $user);
|
||||
if ($marker === null) {
|
||||
|
|
|
@ -354,6 +354,11 @@ class SystemMessage {
|
|||
if ($currentUserIsActor) {
|
||||
$parsedMessage = $this->l->t('You stopped Matterbridge.');
|
||||
}
|
||||
} elseif ($message === 'message_deleted') {
|
||||
$parsedMessage = $this->l->t('{actor} deleted a message');
|
||||
if ($currentUserIsActor) {
|
||||
$parsedMessage = $this->l->t('You deleted a message');
|
||||
}
|
||||
} else {
|
||||
throw new \OutOfBoundsException('Unknown subject');
|
||||
}
|
||||
|
|
|
@ -462,6 +462,40 @@ class ChatController extends AEnvironmentAwareController {
|
|||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireParticipant
|
||||
*
|
||||
* @param int $messageId
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function deleteMessage(int $messageId): DataResponse {
|
||||
try {
|
||||
$message = $this->chatManager->getComment($this->room, (string) $messageId);
|
||||
} catch (NotFoundException $e) {
|
||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
$attendee = $this->participant->getAttendee();
|
||||
if (!$this->participant->hasModeratorPermissions(false)
|
||||
&& ($message->getActorType() !== $attendee->getActorType()
|
||||
|| $message->getActorId() !== $attendee->getActorId())) {
|
||||
// Actor is not a moderator or not the owner of the message
|
||||
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
$this->chatManager->addSystemMessage(
|
||||
$this->room,
|
||||
$attendee->getActorType(),
|
||||
$attendee->getActorId(),
|
||||
json_encode(['message' => 'message_deleted', 'parameters' => ['message' => $messageId]]),
|
||||
$this->timeFactory->getDateTime(),
|
||||
false
|
||||
);
|
||||
|
||||
return new DataResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @RequireParticipant
|
||||
|
|
Загрузка…
Ссылка в новой задаче