Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/Controller/AEnvironmentAwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace OCA\Talk\Controller;

use OC\AppFramework\Http\Dispatcher;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -59,4 +60,25 @@ public function setParticipant(Participant $participant): void {
public function getParticipant(): ?Participant {
return $this->participant;
}

/**
* Following the logic of {@see Dispatcher::executeController}
* @return string Either 'json' or 'xml'
*/
public function getResponseFormat(): string {
// get format from the url format or request format parameter
$format = $this->request->getParam('format');

// if none is given try the first Accept header
if ($format === null) {
$headers = $this->request->getHeader('Accept');
/**
* Default value of
* @see OCSController::buildResponse()
*/
$format = $this->getResponderByHTTPHeader($headers, 'xml');
}

return $format;
}
}
18 changes: 9 additions & 9 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ public function parseCommentToResponse(IComment $comment, Message $parentMessage

$this->participantService->updateLastReadMessage($this->participant, (int) $comment->getId());

$data = $chatMessage->toArray();
$data = $chatMessage->toArray($this->getResponseFormat());
if ($parentMessage instanceof Message) {
$data['parent'] = $parentMessage->toArray();
$data['parent'] = $parentMessage->toArray($this->getResponseFormat());
}

$response = new DataResponse($data, Http::STATUS_CREATED);
Expand Down Expand Up @@ -481,7 +481,7 @@ public function receiveMessages(int $lookIntoFuture,
$parentIds[$id] = $comment->getParentId();
}

$messages[] = $message->toArray();
$messages[] = $message->toArray($this->getResponseFormat());
$commentIdToIndex[$id] = $i;
$i++;
}
Expand Down Expand Up @@ -517,7 +517,7 @@ public function receiveMessages(int $lookIntoFuture,
$this->messageParser->parseMessage($message);

if ($message->getVisibility()) {
$loadedParents[$parentId] = $message->toArray();
$loadedParents[$parentId] = $message->toArray($this->getResponseFormat());
$messages[$commentKey]['parent'] = $loadedParents[$parentId];
continue;
}
Expand Down Expand Up @@ -667,8 +667,8 @@ public function deleteMessage(int $messageId): DataResponse {
$message = $this->messageParser->createMessage($this->room, $this->participant, $comment, $this->l);
$this->messageParser->parseMessage($message);

$data = $systemMessage->toArray();
$data['parent'] = $message->toArray();
$data = $systemMessage->toArray($this->getResponseFormat());
$data['parent'] = $message->toArray($this->getResponseFormat());

$bridge = $this->matterbridgeManager->getBridgeOfRoom($this->room);

Expand Down Expand Up @@ -704,7 +704,7 @@ public function clearHistory(): DataResponse {
$this->messageParser->parseMessage($systemMessage);


$data = $systemMessage->toArray();
$data = $systemMessage->toArray($this->getResponseFormat());

$bridge = $this->matterbridgeManager->getBridgeOfRoom($this->room);

Expand Down Expand Up @@ -797,7 +797,7 @@ public function getObjectsSharedInRoomOverview(int $limit = 7): DataResponse {
continue;
}

$messages[(int) $comment->getId()] = $message->toArray();
$messages[(int) $comment->getId()] = $message->toArray($this->getResponseFormat());
}

$messagesByType = [];
Expand Down Expand Up @@ -853,7 +853,7 @@ protected function getMessagesForRoom(Room $room, array $messageIds): array {
continue;
}

$messages[(int) $comment->getId()] = $message->toArray();
$messages[(int) $comment->getId()] = $message->toArray($this->getResponseFormat());
}

return $messages;
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ protected function formatLastMessage(Room $room, Participant $participant, IComm
return [];
}

return $message->toArray();
return $message->toArray($this->getResponseFormat());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public function isReplyable(): bool {
\in_array($this->getActorType(), [Attendee::ACTOR_USERS, Attendee::ACTOR_GUESTS]);
}

public function toArray(): array {
public function toArray(string $format): array {
$expireDate = $this->getComment()->getExpireDate();

$reactions = $this->getComment()->getReactions();
if (empty($reactions)) {
if ($format === 'json' && empty($reactions)) {
// Cheating here to make sure the reactions array is always a
// JSON object on the API, even when there is no reaction at all.
$reactions = new \StdClass();
Expand Down