Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(scheduled): Fix response format
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and miaulalala committed Dec 9, 2025
commit ae0c19981c3d198e9832ad3bb7a77b55650c04ff
5 changes: 3 additions & 2 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public function getScheduledMessages(): DataResponse {
$scheduledMessages = $this->scheduledMessageManager->getMessages(
$this->room,
$this->participant,
$this->getResponseFormat(),
);

return new DataResponse($scheduledMessages, Http::STATUS_OK);
Expand Down Expand Up @@ -465,7 +466,7 @@ public function scheduleMessage(
return new DataResponse(['error' => 'message'], Http::STATUS_REQUEST_ENTITY_TOO_LARGE);
}

$data = $this->scheduledMessageManager->parseScheduledMessage($scheduledMessage, $parentMessage);
$data = $this->scheduledMessageManager->parseScheduledMessage($this->getResponseFormat(), $scheduledMessage, $parentMessage);
return new DataResponse($data, Http::STATUS_CREATED);
}

Expand Down Expand Up @@ -545,7 +546,7 @@ public function editScheduledMessage(
}
}

$data = $this->scheduledMessageManager->parseScheduledMessage($scheduledMessage, $parentMessage);
$data = $this->scheduledMessageManager->parseScheduledMessage($this->getResponseFormat(), $scheduledMessage, $parentMessage);
return new DataResponse($data, Http::STATUS_ACCEPTED);
}

Expand Down
20 changes: 2 additions & 18 deletions lib/Model/ScheduledMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* @psalm-import-type TalkScheduledMessage from ResponseDefinitions
*/
class ScheduledMessage extends Entity implements \JsonSerializable {
class ScheduledMessage extends Entity {
public const METADATA_THREAD_TITLE = 'threadTitle';
public const METADATA_THREAD_ID = 'threadId';
public const METADATA_SILENT = 'silent';
Expand Down Expand Up @@ -95,22 +95,6 @@ public function setMessage(string $message): void {
$this->markFieldUpdated('message');
}

#[\Override]
public function jsonSerialize(): array {
return [
'roomId' => $this->getRoomId(),
'actorId' => $this->getActorId(),
'actorType' => $this->getActorType(),
'threadId' => $this->getThreadId(),
'parentId' => $this->getParentId(),
'message' => $this->getMessage(),
'messageType' => $this->getMessageType(),
'createdAt' => $this->getCreatedAt()->getTimestamp(),
'sendAt' => $this->getSendAt()?->getTimestamp(),
'metaData' => $this->getDecodedMetaData(),
];
}

/**
* @param string $format
* @psalm-param 'json'|'xml' $format
Expand All @@ -131,7 +115,7 @@ public function toArray(string $format, ?Message $parent, ?Thread $thread) : arr
];

if ($parent !== null) {
$data['parent'] = $parent->toArray('json', $thread);
$data['parent'] = $parent->toArray($format, $thread);
}

if ($thread !== null) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/ScheduledMessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function deleteByActor(string $actorType, string $actorId): void {
/**
* @return list<TalkScheduledMessage>
*/
public function getMessages(Room $chat, Participant $participant): array {
public function getMessages(Room $chat, Participant $participant, string $format): array {
$result = $this->scheduledMessageMapper->findByRoomAndActor(
$chat,
$participant->getAttendee()->getActorType(),
Expand Down Expand Up @@ -166,13 +166,13 @@ public function getMessages(Room $chat, Participant $participant): array {
} else {
$thread = Thread::fromRow($thread);
}
$messages[] = $this->parseScheduledMessage($scheduleMessage, $parent, $thread);
$messages[] = $this->parseScheduledMessage($format, $scheduleMessage, $parent, $thread);
}

return $messages;
}

public function parseScheduledMessage(ScheduledMessage $message, ?Message $parentMessage, ?Thread $thread = null): array {
public function parseScheduledMessage(string $format, ScheduledMessage $message, ?Message $parentMessage, ?Thread $thread = null): array {
if ($thread === null
&& $message->getThreadId() !== Thread::THREAD_NONE
&& $message->getThreadId() !== Thread::THREAD_CREATE
Expand All @@ -187,7 +187,7 @@ public function parseScheduledMessage(ScheduledMessage $message, ?Message $paren
$thread = null;
}
}
return $message->toArray($parentMessage, $thread ?? null);
return $message->toArray($format, $parentMessage, $thread ?? null);
}

public function getScheduledMessageCount(Room $chat, Participant $participant): int {
Expand Down