Always return the full message object on create

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-10-01 13:43:20 +02:00
Родитель 3878b0c7f3
Коммит 028b12e584
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
2 изменённых файлов: 24 добавлений и 2 удалений

Просмотреть файл

@ -548,6 +548,9 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
+ `404 Not Found` When the room could not be found for the participant
+ `413 Payload Too Large` When the message was longer than the allowed limit of 1000 characters
- Data:
The full message array of the new message, as defined in [Receive chat messages of a room](#receive-chat-messages-of-a-room)
### Get mention autocomplete suggestions
* Method: `GET`

Просмотреть файл

@ -184,6 +184,8 @@ class ChatController extends OCSController {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$currentUser = null;
$displayName = '';
if ($this->userId === null) {
$actorType = 'guests';
$sessionId = $this->session->getSessionForRoom($token);
@ -196,10 +198,15 @@ class ChatController extends OCSController {
if ($sessionId && $actorDisplayName) {
$this->guestManager->updateName($room, $sessionId, $actorDisplayName);
$displayName = $actorDisplayName;
} else if ($sessionId) {
$displayName = $this->guestManager->getNameBySessionHash($actorId);
}
} else {
$actorType = 'users';
$actorId = $this->userId;
$currentUser = $this->userManager->get($this->userId);
$displayName = $currentUser instanceof IUser ? $currentUser->getDisplayName() : '';
}
if (!$actorId) {
@ -209,14 +216,26 @@ class ChatController extends OCSController {
$creationDateTime = new \DateTime('now', new \DateTimeZone('UTC'));
try {
$this->chatManager->sendMessage($room, $actorType, $actorId, $message, $creationDateTime);
$comment = $this->chatManager->sendMessage($room, $actorType, $actorId, $message, $creationDateTime);
} catch (MessageTooLongException $e) {
return new DataResponse([], Http::STATUS_REQUEST_ENTITY_TOO_LARGE);
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
return new DataResponse([], Http::STATUS_CREATED);
list($message, $messageParameters) = $this->messageParser->parseMessage($comment, $this->l, $currentUser);
return new DataResponse([
'id' => (int) $comment->getId(),
'token' => $token,
'actorType' => $comment->getActorType(),
'actorId' => $comment->getActorId(),
'actorDisplayName' => $displayName,
'timestamp' => $comment->getCreationDateTime()->getTimestamp(),
'message' => $message,
'messageParameters' => $messageParameters,
'systemMessage' => $comment->getVerb() === 'system' ? $comment->getMessage() : '',
], Http::STATUS_CREATED);
}
/**